From 79ac4dacf64d4d7cb7125b858198b564873a70ec Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 04:26:38 +0000 Subject: [PATCH 1/3] Evidence: the status of a proof-ledger row, derived as a grade MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A proof-ledger row is only as strong as the weakest step it depends on (standards README-EXPLAINME, "Proof Ledger", rule 3). Until now that was a convention a reader had to take on trust. Here it is a theorem, stated as a resource algebra, so the estate's ledger reader can be checked against it. - Instances/Evidence.agda (E-1): the five statuses of PROOF-POLICY §5 as a chain, weakest first (owner ruling 2026-11-17): open-row < tested-only < argued < proven-with-postulates < proven. Alternatives are the join (unit open-row), sequence is the meet (unit proven). It is a ResourceAlgebra, a dioid, ordered and annihilating, and sequencing is the meet of Core's order (⊓e-lowerˡ, ⊓e-lowerʳ, ⊓e-greatest). - Ledger.agda: a ledger is a list of rows, each with its own evidence and the older rows it depends on, so no cycle can be written. eff derives a row's status. E-2 (soundness): eff is no stronger than the row's evidence, any row it depends on, or any row it reaches. E-3 (maximality): eff respects the ledger, and every respectful assignment is below it, so eff is the strongest status the ledger supports. - Prelude: min-≤-left, min-≤-right, min-glb, min-distribˡ-max, max-≡→≤. - Every relation is defined by recursion, not as an indexed family, so the gate's -W error profile raises no UnsupportedIndexedMatch. - Tests: tests/unit/EvidenceTest.agda (the algebra's units and a worked five-row ledger), and three expected rejections: a proven claim on a tested-only row, a model theorem through an argued link, and argued below tested-only. - PROOF-STATUS: E-1, E-2, E-3 are PROVEN in Agda and ungraded, with no Rocq or Lean leg and no receipt yet; the census is 32 rows, 5 ungraded. PROOF-NEEDS gains PN-6 for their recheck legs. scripts/check-agda.sh passes: 12 first-party modules, unit tests, and 12 expected rejections, each refused at its invalid declaration with its stated message. Making sequence the join instead of the meet fails the gate (max (rank s) (rank t) != min (rank s) (rank t)). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013CuBToxr5h9catptGiTsFX --- README.adoc | 3 +- docs/status/PROOF-NEEDS.adoc | 7 + docs/status/PROOF-STATUS.adoc | 81 +++++++-- resource-algebra_chora.deed | 2 +- src/ResourceAlgebra/All.agda | 2 + src/ResourceAlgebra/Instances/Evidence.agda | 190 ++++++++++++++++++++ src/ResourceAlgebra/Ledger.agda | 145 +++++++++++++++ src/ResourceAlgebra/Prelude.agda | 27 +++ tests/reject/EvidenceArguedBelowTested.agda | 13 ++ tests/reject/EvidenceArguedLinkIgnored.agda | 14 ++ tests/reject/EvidenceProvenOverTested.agda | 15 ++ tests/unit/AllTests.agda | 1 + tests/unit/EvidenceTest.agda | 60 +++++++ 13 files changed, 547 insertions(+), 13 deletions(-) create mode 100644 src/ResourceAlgebra/Instances/Evidence.agda create mode 100644 src/ResourceAlgebra/Ledger.agda create mode 100644 tests/reject/EvidenceArguedBelowTested.agda create mode 100644 tests/reject/EvidenceArguedLinkIgnored.agda create mode 100644 tests/reject/EvidenceProvenOverTested.agda create mode 100644 tests/unit/EvidenceTest.agda diff --git a/README.adoc b/README.adoc index 1491aa0..39236e3 100644 --- a/README.adoc +++ b/README.adoc @@ -86,7 +86,8 @@ only from its first green run. ---- src/ResourceAlgebra/Prelude.agda ℕ lemmas (+, max, min, ≤), proved here src/ResourceAlgebra/Core.agda the record and its layers -src/ResourceAlgebra/Instances/*.agda Loss, MaxPlus, HWM, MinMax, Questions +src/ResourceAlgebra/Instances/*.agda Loss, MaxPlus, HWM, MinMax, Questions, Evidence +src/ResourceAlgebra/Ledger.agda a proof-ledger row's status, derived from its dependencies src/ResourceAlgebra/Separation.agda checked separation witnesses src/ResourceAlgebra/Morphism.agda strict and lax morphisms, classifications tests/reject/*.agda expected rejections (must fail) diff --git a/docs/status/PROOF-NEEDS.adoc b/docs/status/PROOF-NEEDS.adoc index ee4f85b..deaeb3e 100644 --- a/docs/status/PROOF-NEEDS.adoc +++ b/docs/status/PROOF-NEEDS.adoc @@ -74,6 +74,13 @@ expected rejection fails with its stated message. algebra that is not a dioid) and M-2 (agreement with tropical-types' Lean semiring). | `PROOF-STATUS.adoc` + +| PN-6 +| Recheck E-1, E-2 and E-3 (the `Evidence` algebra and the ledger status +derivation, 2026-11-17) in Rocq and in Lean as PN-2 and PN-3 do, and record +their statement correspondence. Until then they have the Agda leg only and +no grade. +| `verification/proofs/coq/`, `verification/proofs/lean4/` |=== == Out of scope here diff --git a/docs/status/PROOF-STATUS.adoc b/docs/status/PROOF-STATUS.adoc index 214e242..93d4c1c 100644 --- a/docs/status/PROOF-STATUS.adoc +++ b/docs/status/PROOF-STATUS.adoc @@ -16,13 +16,16 @@ asserted. The values, weakest first, are `ungraded`, `3`, `2i`, `2ii` and == Census -Out of 29 theory rows: PWG-1: 27 · PWG-2ii: 0 · PWG-2i: 0 · PWG-3: 0 · -ungraded: 2. The grades hold at source commit +Out of 32 theory rows: PWG-1: 27 · PWG-2ii: 0 · PWG-2i: 0 · PWG-3: 0 · +ungraded: 5. The grades hold at source commit `f211fc1406d345fa6e972bcfc960c0acd57df1cd` only, the commit the proof receipt describes (`verification/receipts/resource-algebra-proofs_praxis.deed`). The standards reader (`deed_lint.js --proof-receipt-json`) derives every grade there from the legs and receipts, and refuses a recorded grade that -differs (§8.4). The two ungraded rows are `OPEN` (C-4b, M-2). No row rests +differs (§8.4). Of the five ungraded rows, two are `OPEN` (C-4b, M-2). +The other three (E-1, E-2, E-3) are `PROVEN` in Agda but postdate that +commit: they have no Rocq or Lean leg yet and no receipt, so no grade is +derived for them. No row rests on an axiom: the Agda leg is `--safe` with the trusted base below, the Rocq leg prints every theorem closed under the global context, and the Lean leg prints no axiom for any theorem. @@ -36,7 +39,7 @@ dependent type theories (§8.3). -W error -i src`, and every module also declares `--exact-split --no-sized-types --no-guardedness` (the estate strict flag set, from main #21) over `src/ResourceAlgebra/All.agda`, the unit tests -(`tests/unit/AllTests.agda`) and the nine expected rejections. A rejection +(`tests/unit/AllTests.agda`) and the twelve expected rejections. A rejection must fail at its invalid declaration with the message its `-- EXPECT:` line names. A refusal with any other message fails the gate, and so does any warning, `UnsupportedIndexedMatch` included. Until 2026-11-16 the gate @@ -47,8 +50,9 @@ an indexed match. other library. There is no `postulate` (refused by `--safe`), no hole and no `TERMINATING` or similar pragma. * *Trusted base (§8.4.7).* The cone Agda reports for `All.agda` also holds -six modules supplied with the prover: `Agda.Primitive` and -`Agda.Builtin.Bool`, `Equality`, `Nat`, `Sigma` and `Unit`. The gate scans +seven modules supplied with the prover: `Agda.Primitive` and +`Agda.Builtin.Bool`, `Equality`, `List`, `Nat`, `Sigma` and `Unit` +(`List` joined with `Ledger.agda`). The gate scans them and allows exactly four postulates, all in `Agda.Primitive`: `Level` (`BUILTIN LEVEL`), `lzero` (`BUILTIN LEVELZERO`), `lsuc` (`BUILTIN LEVELSUC`) and `_⊔_` (`BUILTIN LEVELMAX`). It checks the declared names and @@ -68,16 +72,19 @@ receipts for the canonical profile. On 2026-11-09, `_≤_` and the constructor-injectivity lemmas were restated so that the core checks under `--cubical-compatible` with no `UnsupportedIndexedMatch` warning. The statements of the theorems below did not change. -* *Expected rejections.* Nine claims must be refused, each with the message -its `-- EXPECT:` line names. In order, those messages are: +* *Expected rejections.* Twelve claims must be refused, each with the +message its `-- EXPECT:` line names. In order, those messages are: `min m n != max m n`, `p != zero`, `suc _ != zero`, `max m n != m + n`, -`max p₁ (n₁ + p₂) != p₁ + p₂`, `3 != 5`, `inf != fin 3`, `… != bot` and -`false != true`. +`max p₁ (n₁ + p₂) != p₁ + p₂`, `3 != 5`, `inf != fin 3`, `… != bot`, +`false != true`, and for the evidence ledger `tested-only != argued`, +`argued != proven` and `tested-only != proven`. These are controls for the PROVEN rows. They are not themselves theorems. == Recheck legs (every row) -Unless a row says otherwise, every theorem row carries this record: +Unless a row says otherwise, every theorem row carries this record. E-1, +E-2 and E-3 say otherwise: they have the Agda leg only. Their Rocq and Lean +legs are not yet written, so the §2 recheck obligation is open for them. [cols="1,1,1,1,2",options="header"] |=== @@ -376,7 +383,59 @@ and not "does one branch keep every question?". | `PROVEN` (`no-branch-achieves-meet`, with Q-2); control `tests/reject/QuestionsMeetIsABranch.agda` | 1 + +| E-1 +| `Evidence` (how strongly a proof-ledger row is supported) is a +`ResourceAlgebra`, `IsDioid`, `IsOrdered` and `IsAnnihilating`. The +carrier is the closed status vocabulary of standards PROOF-POLICY §5 as a +chain, weakest first: `open-row` < `tested-only` < `argued` < +`proven-with-postulates` < `proven` (owner ruling 2026-11-17). Its +operations are ⊕ = the stronger (join) and ⊗ = the weaker (meet), with +𝟘 = `open-row` and 𝟙 = `proven`. So `≼` reads "no stronger than", and ⊗ is +the meet of `≼` (`⊓e-lowerˡ`, `⊓e-lowerʳ`, `⊓e-greatest`). +| `PROVEN` (Instances/Evidence.agda); control +`tests/reject/EvidenceArguedBelowTested.agda` +| ungraded (no recheck legs, no receipt) +|=== + +== Evidence ledger (Ledger.agda) + +A proof ledger is a list of rows. Each row has its own evidence, the §5 +token of its artefact, and the earlier rows it depends on, so no dependency +cycle can be written. The derived status of a row, `eff`, is its own +evidence in sequence (⊗ of `Evidence`) with the derived statuses of the rows +it depends on. This is README-EXPLAINME's rule that a row is only as strong +as the weakest step it depends on, as a theorem rather than a convention. +A reference past the end of the ledger names no row: `eff` reads it as +`proven`, and a reader refuses such a reference first, as an unregistered +row ID. + +[cols="1,4,2,1",options="header"] |=== +| ID | Claim | Agda (§5) | pwg + +| E-2 +| Soundness: a row's derived status is no stronger than its own evidence, +than any row it depends on, or than the evidence of any row it reaches +through dependencies. +| `PROVEN` (`eff-≼-own`, `eff-≼-dep`, `eff-≼-reach`); controls +`tests/reject/EvidenceProvenOverTested.agda`, +`tests/reject/EvidenceArguedLinkIgnored.agda` +| ungraded (no recheck legs, no receipt) + +| E-3 +| Maximality: `eff` respects the ledger, and every assignment of statuses +that respects it is below `eff` row by row. So `eff` is the strongest +status the ledger supports, and a recorded status above it is an +overstatement. +| `PROVEN` (`eff-respects`, `eff-greatest`) +| ungraded (no recheck legs, no receipt) +|=== + +The worked ledger in `tests/unit/EvidenceTest.agda` closes the loop on +concrete rows. A theorem about a model, applied to the code through an +argued link, derives `argued`. A claim proved on top of a tested-only row +derives `tested-only`. A row with no dependencies keeps its own evidence. == Morphisms (Morphism.agda) diff --git a/resource-algebra_chora.deed b/resource-algebra_chora.deed index 67bf8c0..1636eb2 100644 --- a/resource-algebra_chora.deed +++ b/resource-algebra_chora.deed @@ -121,7 +121,7 @@ :project "resource-algebra" :ecosystem "hyperpolymath" :position-type "library" - :purpose "Parametric resource algebra in Agda, with Loss, MaxPlus, HWM, MinMax and Questions instances and strict/lax morphisms." + :purpose "Parametric resource algebra in Agda, with Loss, MaxPlus, HWM, MinMax, Questions and Evidence instances, strict/lax morphisms, and the derivation of a proof-ledger row's status from the rows it depends on." :not ("a repository template" "the K-CUT statement, which belongs in choreographic-types" "occupancy-types' own algebra, for which HWM is a proposal") diff --git a/src/ResourceAlgebra/All.agda b/src/ResourceAlgebra/All.agda index 54eecfc..3c19c8e 100644 --- a/src/ResourceAlgebra/All.agda +++ b/src/ResourceAlgebra/All.agda @@ -11,5 +11,7 @@ import ResourceAlgebra.Instances.MaxPlus import ResourceAlgebra.Instances.HWM import ResourceAlgebra.Instances.MinMax import ResourceAlgebra.Instances.Questions +import ResourceAlgebra.Instances.Evidence +import ResourceAlgebra.Ledger import ResourceAlgebra.Separation import ResourceAlgebra.Morphism diff --git a/src/ResourceAlgebra/Instances/Evidence.agda b/src/ResourceAlgebra/Instances/Evidence.agda new file mode 100644 index 0000000..df54c62 --- /dev/null +++ b/src/ResourceAlgebra/Instances/Evidence.agda @@ -0,0 +1,190 @@ +{-# OPTIONS --safe --without-K --cubical-compatible --exact-split --no-sized-types --no-guardedness #-} +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +-- +-- The evidence grade: how strongly a proof-ledger row is supported. The +-- carrier is the closed status vocabulary of standards PROOF-POLICY §5 (the +-- README-EXPLAINME proof ledger), as a chain, weakest first (owner ruling +-- 2026-11-17): +-- +-- open < tested-only < argued < proven-with-postulates < proven +-- +-- _⊔e_ = alternatives = the STRONGER (join): of two independent supports +-- for one claim, the better one counts; unit open +-- _⊓e_ = sequence = the WEAKER (meet): a claim that rests on steps is +-- only as strong as the weakest of them; unit proven +-- +-- So Core's order a ≼ b (a ⊕ b ≡ b) reads "a is no stronger than b", and +-- sequencing is the meet of that order (⊓e-lowerˡ, ⊓e-lowerʳ, ⊓e-greatest). +-- ResourceAlgebra.Ledger uses exactly that to derive a ledger row's status. +-- +-- The statuses are coded by their rank (0 to 4) and the operations are min +-- and max on ranks, so every law below is a law of min and max on ℕ. Every +-- case split is on a status or a ℕ, never on an indexed family, so the +-- canonical profile checks without a warning (see Prelude, _≤_). +module ResourceAlgebra.Instances.Evidence where + +open import ResourceAlgebra.Prelude +open import ResourceAlgebra.Core + +-- The closed vocabulary, weakest first. +data Status : Set where + open-row tested-only argued proven-with-postulates proven : Status + +rank : Status → Nat +rank open-row = 0 +rank tested-only = 1 +rank argued = 2 +rank proven-with-postulates = 3 +rank proven = 4 + +-- Every rank from 4 up names proven. +from-rank : Nat → Status +from-rank 0 = open-row +from-rank 1 = tested-only +from-rank 2 = argued +from-rank 3 = proven-with-postulates +from-rank (suc (suc (suc (suc _)))) = proven + +from-rank-rank : ∀ s → from-rank (rank s) ≡ s +from-rank-rank open-row = refl +from-rank-rank tested-only = refl +from-rank-rank argued = refl +from-rank-rank proven-with-postulates = refl +from-rank-rank proven = refl + +rank-≤-4 : ∀ s → rank s ≤ 4 +rank-≤-4 open-row = z≤n +rank-≤-4 tested-only = s≤s z≤n +rank-≤-4 argued = s≤s (s≤s z≤n) +rank-≤-4 proven-with-postulates = s≤s (s≤s (s≤s z≤n)) +rank-≤-4 proven = ≤-refl 4 + +rank-from-rank : ∀ {n} → n ≤ 4 → rank (from-rank n) ≡ n +rank-from-rank {0} _ = refl +rank-from-rank {1} _ = refl +rank-from-rank {2} _ = refl +rank-from-rank {3} _ = refl +rank-from-rank {4} _ = refl +rank-from-rank {suc (suc (suc (suc (suc _))))} (le ()) + +-- Two statuses with one rank are one status (through from-rank, so no match +-- on an equation between numerals is needed). +rank-injective : ∀ {s t} → rank s ≡ rank t → s ≡ t +rank-injective {s} {t} p = + trans (sym (from-rank-rank s)) (trans (cong from-rank p) (from-rank-rank t)) + +---------------------------------------------------------------------- +-- The two operations +infixl 6 _⊔e_ +infixl 7 _⊓e_ +_⊔e_ : Status → Status → Status +s ⊔e t = from-rank (max (rank s) (rank t)) + +_⊓e_ : Status → Status → Status +s ⊓e t = from-rank (min (rank s) (rank t)) + +rank-⊔e : ∀ s t → rank (s ⊔e t) ≡ max (rank s) (rank t) +rank-⊔e s t = rank-from-rank (max-lub (rank-≤-4 s) (rank-≤-4 t)) + +rank-⊓e : ∀ s t → rank (s ⊓e t) ≡ min (rank s) (rank t) +rank-⊓e s t = rank-from-rank (≤-trans (min-≤-left (rank s) (rank t)) (rank-≤-4 s)) + +---------------------------------------------------------------------- +-- Alternatives: (⊔e, open-row) is an idempotent commutative monoid +⊔e-assoc : ∀ a b c → (a ⊔e b) ⊔e c ≡ a ⊔e (b ⊔e c) +⊔e-assoc a b c = rank-injective + (trans (rank-⊔e (a ⊔e b) c) + (trans (cong (λ x → max x (rank c)) (rank-⊔e a b)) + (trans (max-assoc (rank a) (rank b) (rank c)) + (trans (cong (max (rank a)) (sym (rank-⊔e b c))) + (sym (rank-⊔e a (b ⊔e c))))))) + +⊔e-comm : ∀ a b → a ⊔e b ≡ b ⊔e a +⊔e-comm a b = cong from-rank (max-comm (rank a) (rank b)) + +⊔e-idem : ∀ a → a ⊔e a ≡ a +⊔e-idem a = trans (cong from-rank (max-idem (rank a))) (from-rank-rank a) + +⊔e-unitˡ : ∀ a → open-row ⊔e a ≡ a +⊔e-unitˡ a = from-rank-rank a + +---------------------------------------------------------------------- +-- Sequence: (⊓e, proven) is a monoid +⊓e-assoc : ∀ a b c → (a ⊓e b) ⊓e c ≡ a ⊓e (b ⊓e c) +⊓e-assoc a b c = rank-injective + (trans (rank-⊓e (a ⊓e b) c) + (trans (cong (λ x → min x (rank c)) (rank-⊓e a b)) + (trans (min-assoc (rank a) (rank b) (rank c)) + (trans (cong (min (rank a)) (sym (rank-⊓e b c))) + (sym (rank-⊓e a (b ⊓e c))))))) + +⊓e-comm : ∀ a b → a ⊓e b ≡ b ⊓e a +⊓e-comm a b = cong from-rank (min-comm (rank a) (rank b)) + +⊓e-unitˡ : ∀ a → proven ⊓e a ≡ a +⊓e-unitˡ a = trans (cong from-rank (min-≥ (rank-≤-4 a))) (from-rank-rank a) + +⊓e-unitʳ : ∀ a → a ⊓e proven ≡ a +⊓e-unitʳ a = trans (⊓e-comm a proven) (⊓e-unitˡ a) + +Evidence : ResourceAlgebra +Evidence = record + { Grade = Status + ; _⊕_ = _⊔e_ + ; _⊗_ = _⊓e_ + ; 𝟘 = open-row + ; 𝟙 = proven + ; alt = record { assoc = ⊔e-assoc ; comm = ⊔e-comm ; idem = ⊔e-idem ; unitˡ = ⊔e-unitˡ } + ; seq = record { assoc = ⊓e-assoc ; unitˡ = ⊓e-unitˡ ; unitʳ = ⊓e-unitʳ } + } + +open ResourceAlgebra Evidence using (_≼_) + +---------------------------------------------------------------------- +-- Dioid, ordered, annihilating +⊓e-distribˡ : ∀ a b c → a ⊓e (b ⊔e c) ≡ (a ⊓e b) ⊔e (a ⊓e c) +⊓e-distribˡ a b c = rank-injective + (trans (rank-⊓e a (b ⊔e c)) + (trans (cong (min (rank a)) (rank-⊔e b c)) + (trans (min-distribˡ-max (rank a) (rank b) (rank c)) + (trans (cong₂ max (sym (rank-⊓e a b)) (sym (rank-⊓e a c))) + (sym (rank-⊔e (a ⊓e b) (a ⊓e c))))))) + +⊓e-distribʳ : ∀ a b c → (a ⊔e b) ⊓e c ≡ (a ⊓e c) ⊔e (b ⊓e c) +⊓e-distribʳ a b c = + trans (⊓e-comm (a ⊔e b) c) + (trans (⊓e-distribˡ c a b) + (cong₂ _⊔e_ (⊓e-comm c a) (⊓e-comm c b))) + +Evidence-dioid : IsDioid Evidence +Evidence-dioid = record { distribˡ = ⊓e-distribˡ ; distribʳ = ⊓e-distribʳ } + +Evidence-ordered : IsOrdered Evidence +Evidence-ordered = IsDioid.ordered Evidence-dioid + +Evidence-annihilating : IsAnnihilating Evidence +Evidence-annihilating = record + { annihilˡ = λ _ → refl + ; annihilʳ = λ a → cong from-rank (min-zeroʳ (rank a)) } + +---------------------------------------------------------------------- +-- The order is the rank order, and sequencing is its meet +≼→≤ : ∀ {a b} → a ≼ b → rank a ≤ rank b +≼→≤ {a} {b} p = max-≡→≤ (trans (sym (rank-⊔e a b)) (cong rank p)) + +≤→≼ : ∀ {a b} → rank a ≤ rank b → a ≼ b +≤→≼ {a} {b} p = trans (cong from-rank (max-≤ p)) (from-rank-rank b) + +≼-proven : ∀ a → a ≼ proven +≼-proven a = ≤→≼ (rank-≤-4 a) + +⊓e-lowerˡ : ∀ a b → (a ⊓e b) ≼ a +⊓e-lowerˡ a b = ≤→≼ (subst (λ x → x ≤ rank a) (sym (rank-⊓e a b)) (min-≤-left (rank a) (rank b))) + +⊓e-lowerʳ : ∀ a b → (a ⊓e b) ≼ b +⊓e-lowerʳ a b = ≤→≼ (subst (λ x → x ≤ rank b) (sym (rank-⊓e a b)) (min-≤-right (rank a) (rank b))) + +⊓e-greatest : ∀ {a b c} → c ≼ a → c ≼ b → c ≼ (a ⊓e b) +⊓e-greatest {a} {b} {c} p q = + ≤→≼ (subst (λ x → rank c ≤ x) (sym (rank-⊓e a b)) (min-glb (≼→≤ p) (≼→≤ q))) diff --git a/src/ResourceAlgebra/Ledger.agda b/src/ResourceAlgebra/Ledger.agda new file mode 100644 index 0000000..fedf380 --- /dev/null +++ b/src/ResourceAlgebra/Ledger.agda @@ -0,0 +1,145 @@ +{-# OPTIONS --safe --without-K --cubical-compatible --exact-split --no-sized-types --no-guardedness #-} +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +-- +-- A proof-ledger row's status is derived, not asserted: a row is only as +-- strong as the weakest step it depends on (README-EXPLAINME "Proof Ledger", +-- rule 3). In the Evidence algebra that is sequencing: the derived status +-- of a row is its own evidence in sequence (⊓e) with the derived statuses +-- of the rows it depends on. +-- +-- A ledger is a list of rows, newest first. Row 0 is the head; row i + 1 +-- is row i of the tail. A row's dependencies are indices into the rows +-- after it, so a row can depend only on older rows and no dependency cycle +-- can be written. An index past the end names no row: the derivation reads +-- it as proven (𝟙), and a reader refuses such a dangling reference before +-- deriving anything (an unregistered row ID). +-- +-- Proved: +-- eff-≼-own the derived status is no stronger than the row's evidence; +-- eff-≼-dep nor than any row it depends on; +-- eff-≼-reach nor than the evidence of any row it reaches; +-- eff-respects the derived assignment respects the ledger; +-- eff-greatest every assignment that respects the ledger is below it. +-- So eff is the strongest status the ledger supports, and a recorded status +-- above it is an overstatement. +-- +-- Every relation is defined by recursion on lists and ℕ, not as an indexed +-- family, so the canonical profile checks without a warning. +module ResourceAlgebra.Ledger where + +open import Agda.Builtin.List public using (List; []; _∷_) +open import ResourceAlgebra.Prelude +open import ResourceAlgebra.Core +open import ResourceAlgebra.Instances.Evidence +open ResourceAlgebra Evidence using (_≼_; ≼-refl; ≼-trans) + +---------------------------------------------------------------------- +-- Lists +map : {A B : Set} → (A → B) → List A → List B +map f [] = [] +map f (x ∷ xs) = f x ∷ map f xs + +-- Membership, by recursion. +_∈_ : Nat → List Nat → Set +j ∈ [] = ⊥ +j ∈ (k ∷ ks) = (j ≡ k) ⊎ (j ∈ ks) + +-- The meet of a list of statuses; the empty meet is proven. +⨅ : List Status → Status +⨅ [] = proven +⨅ (s ∷ ss) = s ⊓e ⨅ ss + +⨅-lower : {f : Nat → Status} (js : List Nat) {j : Nat} → j ∈ js → ⨅ (map f js) ≼ f j +⨅-lower {f} (k ∷ ks) (inj₁ refl) = ⊓e-lowerˡ (f k) (⨅ (map f ks)) +⨅-lower {f} (k ∷ ks) (inj₂ p) = ≼-trans (⊓e-lowerʳ (f k) (⨅ (map f ks))) (⨅-lower ks p) + +⨅-greatest : {f : Nat → Status} {z : Status} (js : List Nat) + → (∀ {j} → j ∈ js → z ≼ f j) → z ≼ ⨅ (map f js) +⨅-greatest {z = z} [] _ = ≼-proven z +⨅-greatest (k ∷ ks) h = ⊓e-greatest (h (inj₁ refl)) (⨅-greatest ks (λ p → h (inj₂ p))) + +---------------------------------------------------------------------- +-- Ledgers +record Row : Set where + constructor row + field + own : Status -- the §5 token of the row's own artefact + deps : List Nat -- the rows it depends on, as indices into the rows after it +open Row + +Ledger : Set +Ledger = List Row + +own-of : Ledger → Nat → Status +own-of [] _ = proven +own-of (r ∷ L) zero = own r +own-of (r ∷ L) (suc i) = own-of L i + +-- Dep L i j: row i depends directly on row j. +Dep : Ledger → Nat → Nat → Set +Dep [] _ _ = ⊥ +Dep (r ∷ L) zero zero = ⊥ +Dep (r ∷ L) zero (suc j) = j ∈ deps r +Dep (r ∷ L) (suc i) zero = ⊥ +Dep (r ∷ L) (suc i) (suc j) = Dep L i j + +-- Reach L i j: row i depends on row j through zero or more steps. +data Reach (L : Ledger) (i : Nat) : Nat → Set where + stay : Reach L i i + step : ∀ {k j} → Dep L i k → Reach L k j → Reach L i j + +-- The derived status. +eff : Ledger → Nat → Status +eff [] _ = proven +eff (r ∷ L) zero = own r ⊓e ⨅ (map (eff L) (deps r)) +eff (r ∷ L) (suc i) = eff L i + +---------------------------------------------------------------------- +-- Soundness: never stronger than the evidence it rests on +eff-≼-own : ∀ L i → eff L i ≼ own-of L i +eff-≼-own [] i = ≼-refl proven +eff-≼-own (r ∷ L) zero = ⊓e-lowerˡ (own r) (⨅ (map (eff L) (deps r))) +eff-≼-own (r ∷ L) (suc i) = eff-≼-own L i + +eff-≼-dep : ∀ L i j → Dep L i j → eff L i ≼ eff L j +eff-≼-dep [] _ _ () +eff-≼-dep (r ∷ L) zero zero () +eff-≼-dep (r ∷ L) zero (suc j) p = + ≼-trans (⊓e-lowerʳ (own r) (⨅ (map (eff L) (deps r)))) (⨅-lower (deps r) p) +eff-≼-dep (r ∷ L) (suc i) zero () +eff-≼-dep (r ∷ L) (suc i) (suc j) d = eff-≼-dep L i j d + +-- A row is only as strong as the weakest step it depends on. +eff-≼-reach : ∀ L {i j} → Reach L i j → eff L i ≼ own-of L j +eff-≼-reach L {i} stay = eff-≼-own L i +eff-≼-reach L {i} (step {k} {j} d r) = ≼-trans (eff-≼-dep L i k d) (eff-≼-reach L r) + +---------------------------------------------------------------------- +-- Maximality: the strongest status the ledger supports + +-- An assignment respects a ledger when no row is stronger than its own +-- evidence or than a row it depends on. +record Respects (L : Ledger) (s : Nat → Status) : Set where + field + below-own : ∀ i → s i ≼ own-of L i + below-dep : ∀ i j → Dep L i j → s i ≼ s j +open Respects + +eff-respects : ∀ L → Respects L (eff L) +eff-respects L = record { below-own = eff-≼-own L ; below-dep = eff-≼-dep L } + +-- Restricting an assignment of r ∷ L to L keeps it respectful. +restrict : ∀ {r L s} → Respects (r ∷ L) s → Respects L (λ i → s (suc i)) +restrict ρ = record + { below-own = λ i → below-own ρ (suc i) + ; below-dep = λ i j d → below-dep ρ (suc i) (suc j) d } + +eff-greatest : ∀ L s → Respects L s → ∀ i → s i ≼ eff L i +eff-greatest [] s ρ i = ≼-proven (s i) +eff-greatest (r ∷ L) s ρ zero = + ⊓e-greatest (below-own ρ zero) + (⨅-greatest (deps r) + (λ {j} p → ≼-trans (below-dep ρ zero (suc j) p) + (eff-greatest L (λ k → s (suc k)) (restrict ρ) j))) +eff-greatest (r ∷ L) s ρ (suc i) = eff-greatest L (λ k → s (suc k)) (restrict ρ) i diff --git a/src/ResourceAlgebra/Prelude.agda b/src/ResourceAlgebra/Prelude.agda index 2f69bd5..8af859e 100644 --- a/src/ResourceAlgebra/Prelude.agda +++ b/src/ResourceAlgebra/Prelude.agda @@ -281,3 +281,30 @@ max-distribʳ-min a b c = trans (max-comm (min a b) c) (trans (max-distribˡ-min c a b) (cong₂ min (max-comm c a) (max-comm c b))) + +---------------------------------------------------------------------- +-- min as the meet of the usual order, for the evidence instance +min-≤-left : ∀ m n → min m n ≤ m +min-≤-left zero n = z≤n +min-≤-left (suc m) zero = z≤n +min-≤-left (suc m) (suc n) = s≤s (min-≤-left m n) + +min-≤-right : ∀ m n → min m n ≤ n +min-≤-right m n = subst (λ x → x ≤ n) (min-comm n m) (min-≤-left n m) + +min-glb : ∀ {k m n} → k ≤ m → k ≤ n → k ≤ min m n +min-glb {zero} _ _ = z≤n +min-glb {suc _} {zero} (le ()) _ +min-glb {suc _} {suc _} {zero} _ (le ()) +min-glb {suc _} {suc _} {suc _} p q = s≤s (min-glb (≤-pred p) (≤-pred q)) + +-- min distributes over max: the evidence instance is a dioid. +min-distribˡ-max : ∀ a b c → min a (max b c) ≡ max (min a b) (min a c) +min-distribˡ-max zero b c = refl +min-distribˡ-max (suc a) zero c = refl +min-distribˡ-max (suc a) (suc b) zero = sym (max-zeroʳ (suc (min a b))) +min-distribˡ-max (suc a) (suc b) (suc c) = cong suc (min-distribˡ-max a b c) + +-- From the join back to the order: max m n ≡ n means m ≤ n. +max-≡→≤ : ∀ {m n} → max m n ≡ n → m ≤ n +max-≡→≤ {m} {n} p = subst (λ x → m ≤ x) p (≤-max-left m n) diff --git a/tests/reject/EvidenceArguedBelowTested.agda b/tests/reject/EvidenceArguedBelowTested.agda new file mode 100644 index 0000000..3881bfe --- /dev/null +++ b/tests/reject/EvidenceArguedBelowTested.agda @@ -0,0 +1,13 @@ +{-# OPTIONS --safe --without-K --cubical-compatible --exact-split --no-sized-types --no-guardedness #-} +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +module EvidenceArguedBelowTested where +open import ResourceAlgebra.Prelude +open import ResourceAlgebra.Instances.Evidence + +-- Must fail: the chain puts argued above tested-only (owner ruling +-- 2026-11-17), so a claim resting on one of each is tested-only. Accepting +-- this would reverse the two in the order every ledger is derived in. +-- EXPECT: tested-only != argued of type Status +invalid : (argued ⊓e tested-only) ≡ argued +invalid = refl diff --git a/tests/reject/EvidenceArguedLinkIgnored.agda b/tests/reject/EvidenceArguedLinkIgnored.agda new file mode 100644 index 0000000..8a85d8a --- /dev/null +++ b/tests/reject/EvidenceArguedLinkIgnored.agda @@ -0,0 +1,14 @@ +{-# OPTIONS --safe --without-K --cubical-compatible --exact-split --no-sized-types --no-guardedness #-} +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +module EvidenceArguedLinkIgnored where +open import ResourceAlgebra.Prelude +open import ResourceAlgebra.Instances.Evidence +open import ResourceAlgebra.Ledger + +-- Must fail: a theorem proved about a model, applied to the code through an +-- argued link, is argued, not proven. A theorem about a model is proven for +-- the model only; the link from model to code is its own, weaker row. +-- EXPECT: argued != proven of type Status +invalid : eff (row proven (0 ∷ 1 ∷ []) ∷ row argued [] ∷ row proven [] ∷ []) 0 ≡ proven +invalid = refl diff --git a/tests/reject/EvidenceProvenOverTested.agda b/tests/reject/EvidenceProvenOverTested.agda new file mode 100644 index 0000000..8e683a2 --- /dev/null +++ b/tests/reject/EvidenceProvenOverTested.agda @@ -0,0 +1,15 @@ +{-# OPTIONS --safe --without-K --cubical-compatible --exact-split --no-sized-types --no-guardedness #-} +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +module EvidenceProvenOverTested where +open import ResourceAlgebra.Prelude +open import ResourceAlgebra.Instances.Evidence +open import ResourceAlgebra.Ledger + +-- Must fail: a claim proved on top of a property that is only tested is not +-- proven. Accepting this would let a ledger report a row as stronger than +-- the weakest step it rests on (README-EXPLAINME rule 3), which is the +-- overstatement Ledger.eff-greatest exists to rule out. +-- EXPECT: tested-only != proven of type Status +invalid : eff (row proven (0 ∷ []) ∷ row tested-only [] ∷ []) 0 ≡ proven +invalid = refl diff --git a/tests/unit/AllTests.agda b/tests/unit/AllTests.agda index 56b68eb..21ddb53 100644 --- a/tests/unit/AllTests.agda +++ b/tests/unit/AllTests.agda @@ -3,6 +3,7 @@ -- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell module AllTests where +import EvidenceTest import MinMaxTest import MorphismTest import PreludeTest diff --git a/tests/unit/EvidenceTest.agda b/tests/unit/EvidenceTest.agda new file mode 100644 index 0000000..86686b4 --- /dev/null +++ b/tests/unit/EvidenceTest.agda @@ -0,0 +1,60 @@ +{-# OPTIONS --safe --without-K --cubical-compatible --exact-split --no-sized-types --no-guardedness #-} +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +module EvidenceTest where + +open import ResourceAlgebra.Prelude +open import ResourceAlgebra.Core +open import ResourceAlgebra.Instances.Evidence +open import ResourceAlgebra.Ledger + +module EV = ResourceAlgebra Evidence + +-- The record's units and operations are part of the consumer contract. +zero-is-open : EV.𝟘 ≡ open-row +zero-is-open = refl + +one-is-proven : EV.𝟙 ≡ proven +one-is-proven = refl + +-- The owner's chain (2026-11-17): argued is above tested-only, so a step +-- that is argued and one that is tested-only together are tested-only, and +-- either one alone is the better support for a claim. +sequence-keeps-the-weaker : (argued EV.⊗ tested-only) ≡ tested-only +sequence-keeps-the-weaker = refl + +alternative-keeps-the-stronger : (argued EV.⊕ tested-only) ≡ argued +alternative-keeps-the-stronger = refl + +postulates-below-proven : (proven EV.⊗ proven-with-postulates) ≡ proven-with-postulates +postulates-below-proven = refl + +open-annihilates : (proven EV.⊗ open-row) ≡ open-row +open-annihilates = refl + +-- A worked ledger, newest first. Rows, oldest first: 0, a theorem proved +-- about a model; 1, the argued link from the model to the code; 2, a +-- code-level claim proved against the model, resting on rows 0 and 1; +-- 3, a property checked by tests; 4, a claim proved on top of rows 2 and 3. +-- Indices count back from each row: 0 is the row just before it. +example : Ledger +example = + row proven (0 ∷ 1 ∷ []) -- row 4: on row 3 and row 2 + ∷ row tested-only [] -- row 3 + ∷ row proven (0 ∷ 1 ∷ []) -- row 2: on row 1 and row 0 + ∷ row argued [] -- row 1 + ∷ row proven [] -- row 0 + ∷ [] + +-- Row 2 is argued: a proof about the model is only as good as the argued +-- link to the code (README-EXPLAINME rule 3). +row2-is-argued : eff example 2 ≡ argued +row2-is-argued = refl + +-- Row 4 is tested-only: the weakest step it rests on. +row4-is-tested-only : eff example 0 ≡ tested-only +row4-is-tested-only = refl + +-- Row 0 rests on nothing, so it keeps its own evidence. +row0-keeps-its-evidence : eff example 4 ≡ proven +row0-keeps-its-evidence = refl From fc819c354e6502aa89bfecf03ba670efed6212ec Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 12:05:56 +0000 Subject: [PATCH 2/3] Evidence: Rocq and Lean recheck legs for E-1, E-2 and E-3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both legs re-prove the evidence algebra and the ledger status derivation by hand (PROOF-POLICY §2), axiom-free, closing PN-6. - Lean (core only, no Mathlib): Status, rank/fromRank, eJoin/eMeet, Evidence with Evidence_dioid, Evidence_ordered, Evidence_annihilating, and le_to_rank, rank_to_le, le_proven, eMeet_lowerl, eMeet_lowerr, eMeet_greatest (E-1); Row, Ledger, ownOf, Mem, Dep, Reach, eff and eff_le_own, eff_le_dep, eff_le_reach (E-2); Respects, eff_respects, restrict, eff_greatest (E-3). The min/max lemmas are proved by structural recursion, as in Agda's Prelude. All 79 #print axioms lines report no axiom. - Rocq: the same statements in snake case (the statuses use the Lean spelling, since scan-dangerous.sh refuses a lowercase "postulate" in leg code). All 71 Print Assumptions lines report closed. - Both legs restate the worked ledger of tests/unit/EvidenceTest.agda. These pin the chain order, which the laws alone cannot see. - PROOF-STATUS: E-1..E-3 join the statement-correspondence table, with their residual differences (Prop-valued membership, Dep, Reach and Respects; Reach's start as an index). The rows stay ungraded: no receipt records a run of the new legs yet. - PROOF-NEEDS: PN-6 is done. - Ledger.agda header and PROOF-STATUS: refusing a dangling dependency reference is a precondition every ledger reader must enforce, not a guarantee of an existing reader. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013CuBToxr5h9catptGiTsFX --- docs/status/PROOF-NEEDS.adoc | 8 +- docs/status/PROOF-STATUS.adoc | 65 +++- src/ResourceAlgebra/Ledger.agda | 9 +- verification/proofs/coq/ResourceAlgebra.v | 366 ++++++++++++++++++ .../proofs/lean4/ResourceAlgebra.lean | 345 +++++++++++++++++ 5 files changed, 776 insertions(+), 17 deletions(-) diff --git a/docs/status/PROOF-NEEDS.adoc b/docs/status/PROOF-NEEDS.adoc index deaeb3e..5cf8034 100644 --- a/docs/status/PROOF-NEEDS.adoc +++ b/docs/status/PROOF-NEEDS.adoc @@ -1,7 +1,7 @@ // SPDX-License-Identifier: CC-BY-SA-4.0 // Copyright (c) Jonathan D.A. Jewell = Proof Requirements — resource-algebra -:revdate: 2026-11-09 +:revdate: 2026-11-17 What this repository owes, classified by the estate proof policy (`3-practice/PROOF-POLICY.adoc` in `hyperpolymath/standards`). What has been @@ -78,8 +78,10 @@ semiring). | PN-6 | Recheck E-1, E-2 and E-3 (the `Evidence` algebra and the ledger status derivation, 2026-11-17) in Rocq and in Lean as PN-2 and PN-3 do, and record -their statement correspondence. Until then they have the Agda leg only and -no grade. +their statement correspondence. *Done* in resource-algebra#45: both legs +re-prove the three rows by hand, axiom-free, and the statement +correspondence is recorded in `PROOF-STATUS.adoc`. The rows stay +`ungraded` until a receipt records a run of all three legs. | `verification/proofs/coq/`, `verification/proofs/lean4/` |=== diff --git a/docs/status/PROOF-STATUS.adoc b/docs/status/PROOF-STATUS.adoc index 93d4c1c..cef513e 100644 --- a/docs/status/PROOF-STATUS.adoc +++ b/docs/status/PROOF-STATUS.adoc @@ -23,8 +23,9 @@ receipt describes (`verification/receipts/resource-algebra-proofs_praxis.deed`). The standards reader (`deed_lint.js --proof-receipt-json`) derives every grade there from the legs and receipts, and refuses a recorded grade that differs (§8.4). Of the five ungraded rows, two are `OPEN` (C-4b, M-2). -The other three (E-1, E-2, E-3) are `PROVEN` in Agda but postdate that -commit: they have no Rocq or Lean leg yet and no receipt, so no grade is +The other three (E-1, E-2, E-3) postdate that commit. They are `PROVEN` in +Agda, and both recheck legs are re-proved for them with the statements +reconciled, but no receipt records a run of those legs, so no grade is derived for them. No row rests on an axiom: the Agda leg is `--safe` with the trusted base below, the Rocq leg prints every theorem closed under the global context, and the Lean leg @@ -82,9 +83,12 @@ These are controls for the PROVEN rows. They are not themselves theorems. == Recheck legs (every row) -Unless a row says otherwise, every theorem row carries this record. E-1, -E-2 and E-3 say otherwise: they have the Agda leg only. Their Rocq and Lean -legs are not yet written, so the §2 recheck obligation is open for them. +Every theorem row carries this record, except that the receipts below +predate E-1, E-2 and E-3. Their Rocq and Lean legs are re-proved by hand, +in the same files and by the same routes as every other row, and their +statements are reconciled (see Statement correspondence). No receipt yet +records a run of those legs, so the three rows stay `ungraded` until one +does. [cols="1,1,1,1,2",options="header"] |=== @@ -264,6 +268,9 @@ equations as Lean's `or`/`and` and Rocq's `orb`/`andb`. | S-2 | `alternatives-differ` | `alternatives_differ` | `alternatives_differ` | S-3 | `maxplus-order`, `loss-order-reversed` | `maxplus_order`, `loss_order_reversed` | `maxplus_order`, `loss_order_reversed` | S-4 | `bottleneck-is-not-sum` | `bottleneck_is_not_sum` | `bottleneck_is_not_sum` +| E-1 | `Evidence`, `Evidence-dioid`, `Evidence-ordered`, `Evidence-annihilating`, `≼→≤`, `≤→≼`, `≼-proven`, `⊓e-lowerˡ`, `⊓e-lowerʳ`, `⊓e-greatest` | `Evidence`, `Evidence_dioid`, `Evidence_ordered`, `Evidence_annihilating`, `le_to_rank`, `rank_to_le`, `le_proven`, `eMeet_lowerl`, `eMeet_lowerr`, `eMeet_greatest` | `Evidence`, `Evidence_dioid`, `Evidence_ordered`, `Evidence_annihilating`, `le_to_rank`, `rank_to_le`, `le_proven`, `emeet_lowerl`, `emeet_lowerr`, `emeet_greatest` +| E-2 | `eff-≼-own`, `eff-≼-dep`, `eff-≼-reach` | `eff_le_own`, `eff_le_dep`, `eff_le_reach` | the same names +| E-3 | `Respects`, `eff-respects`, `restrict`, `eff-greatest` | `Respects`, `eff_respects`, `restrict`, `eff_greatest` | the same names |=== F-5's classifier `Loss→MaxPlus` returns Agda's `_⊎_`, a sum in `Set` that @@ -274,6 +281,39 @@ only that a morphism is one of the two: a weaker statement, so the receipts at `9f175cc` do not recheck F-5's classifier either (see Receipts). No leg rests on an assumption beyond its prover's kernel. +E-1, E-2 and E-3 have these residual differences: + +* Names follow each prover's convention. The statuses are `openRow`, +`testedOnly`, `argued`, `provenWithPostulates` and `proven` in both legs. +Rocq uses the Lean spelling, not snake case, because +`scripts/scan-dangerous.sh` refuses any lowercase `postulate` in leg code, +even inside a longer name. For the same reason the test Agda calls +`postulates-below-proven` is `provenWithPostulates_below_proven` in both +legs. `_⊔e_` and `_⊓e_` are `eJoin` and `eMeet` in Lean and `ejoin` and +`emeet` in Rocq; `from-rank`, `own-of` and `⨅` are `fromRank`, `ownOf` and +`meetAll` in Lean and `from_rank`, `own_of` and `meet_all` in Rocq. Each is +defined by the same equations as in Agda, `rank` and `from-rank` included. +Ledger.agda's own `map` is `mapList` in Lean and `map_list` in Rocq, by the +same two equations. +* Membership (`_∈_`) and `Dep` are defined by the same recursion in all +three provers, but they are `Prop`-valued in the legs: Agda's `_⊎_` and `⊥` +in `Set` become `∨` and `False`. `Reach` is an inductive `Prop` in the legs +and `Respects` a `Prop` record. A proof-relevant membership witness in Agda +can be one of several when an index is repeated, and a propositional one +cannot. These types occur only as hypotheses, or, for `Respects`, as a +record whose fields conclude in equations, so no statement changes +strength. +* Agda's `Reach` takes the starting row as a parameter that `step` varies; +both legs take it as an index. The constructors and their types are the +same. +* The worked ledger and the expected values of +`tests/unit/EvidenceTest.agda` are restated in both legs +(`sequence_keeps_the_weaker`, `alternative_keeps_the_stronger`, +`provenWithPostulates_below_proven`, `open_annihilates`, `row2_is_argued`, +`row4_is_tested_only`, `row0_keeps_its_evidence`). They are tests, not +rows. They pin the chain order, which the laws of E-1..E-3 cannot see: a +relabelling of the chain satisfies every law. + == Core (Core.agda) [cols="1,4,2,1",options="header"] @@ -395,7 +435,7 @@ operations are ⊕ = the stronger (join) and ⊗ = the weaker (meet), with the meet of `≼` (`⊓e-lowerˡ`, `⊓e-lowerʳ`, `⊓e-greatest`). | `PROVEN` (Instances/Evidence.agda); control `tests/reject/EvidenceArguedBelowTested.agda` -| ungraded (no recheck legs, no receipt) +| ungraded (no receipt yet) |=== == Evidence ledger (Ledger.agda) @@ -406,9 +446,12 @@ cycle can be written. The derived status of a row, `eff`, is its own evidence in sequence (⊗ of `Evidence`) with the derived statuses of the rows it depends on. This is README-EXPLAINME's rule that a row is only as strong as the weakest step it depends on, as a theorem rather than a convention. -A reference past the end of the ledger names no row: `eff` reads it as -`proven`, and a reader refuses such a reference first, as an unregistered -row ID. +A reference past the end of the ledger names no row, and `eff` reads it as +`proven`. So any reader of a ledger must refuse such a reference, as an +unregistered row ID, before it derives a status. That is a precondition +every reader must enforce, not a guarantee this repository gives: no +reader exists yet (the standards ledger reader is planned), and the +theorems below hold for every ledger, dangling references included. [cols="1,4,2,1",options="header"] |=== @@ -421,7 +464,7 @@ through dependencies. | `PROVEN` (`eff-≼-own`, `eff-≼-dep`, `eff-≼-reach`); controls `tests/reject/EvidenceProvenOverTested.agda`, `tests/reject/EvidenceArguedLinkIgnored.agda` -| ungraded (no recheck legs, no receipt) +| ungraded (no receipt yet) | E-3 | Maximality: `eff` respects the ledger, and every assignment of statuses @@ -429,7 +472,7 @@ that respects it is below `eff` row by row. So `eff` is the strongest status the ledger supports, and a recorded status above it is an overstatement. | `PROVEN` (`eff-respects`, `eff-greatest`) -| ungraded (no recheck legs, no receipt) +| ungraded (no receipt yet) |=== The worked ledger in `tests/unit/EvidenceTest.agda` closes the loop on diff --git a/src/ResourceAlgebra/Ledger.agda b/src/ResourceAlgebra/Ledger.agda index fedf380..83462cf 100644 --- a/src/ResourceAlgebra/Ledger.agda +++ b/src/ResourceAlgebra/Ledger.agda @@ -11,9 +11,12 @@ -- A ledger is a list of rows, newest first. Row 0 is the head; row i + 1 -- is row i of the tail. A row's dependencies are indices into the rows -- after it, so a row can depend only on older rows and no dependency cycle --- can be written. An index past the end names no row: the derivation reads --- it as proven (𝟙), and a reader refuses such a dangling reference before --- deriving anything (an unregistered row ID). +-- can be written. An index past the end names no row, and the derivation +-- reads it as proven (𝟙). So any reader of a ledger must refuse such a +-- dangling reference, as an unregistered row ID, before it derives a +-- status. That is a precondition every reader must enforce, not a +-- guarantee given here: no reader exists yet, and the theorems below hold +-- for every ledger, dangling references included. -- -- Proved: -- eff-≼-own the derived status is no stronger than the row's evidence; diff --git a/verification/proofs/coq/ResourceAlgebra.v b/verification/proofs/coq/ResourceAlgebra.v index afe7c53..cee880f 100644 --- a/verification/proofs/coq/ResourceAlgebra.v +++ b/verification/proofs/coq/ResourceAlgebra.v @@ -774,6 +774,349 @@ Proof. intro f. pose proof (f collapse shuffle) as h. simpl in h. discriminate h. Qed. +(** * Evidence (E-1) *) + +(** The status of a proof-ledger row, as a chain, weakest first: + [openRow < testedOnly < argued < provenWithPostulates < proven]. + A status is coded by its rank (0 to 4); alternatives take the max of the + ranks and sequence the min, as in Agda's [Instances/Evidence.agda]. *) + +(** [min m n ≤ m] (Agda: [min-≤-left]). *) +Lemma rmin_le_left : forall m n, rmin m n <= m. +Proof. intros m n. rewrite rmin_eq. lia. Qed. + +(** [min m n ≤ n] (Agda: [min-≤-right]). *) +Lemma rmin_le_right : forall m n, rmin m n <= n. +Proof. intros m n. rewrite rmin_eq. lia. Qed. + +(** [k ≤ m → k ≤ n → k ≤ min m n] (Agda: [min-glb]). *) +Lemma rmin_glb : forall k m n, k <= m -> k <= n -> k <= rmin m n. +Proof. intros k m n p q. rewrite rmin_eq. lia. Qed. + +(** [min a (max b c) = max (min a b) (min a c)] (Agda: [min-distribˡ-max]). *) +Lemma rmin_rmax_l : forall a b c, rmin a (rmax b c) = rmax (rmin a b) (rmin a c). +Proof. intros a b c. unfold_rmm. lia. Qed. + +(** [max m n = n → m ≤ n] (Agda: [max-≡→≤]). *) +Lemma rmax_eq_le : forall m n, rmax m n = n -> m <= n. +Proof. intros m n p. rewrite rmax_eq in p. lia. Qed. + +(** The closed status vocabulary of PROOF-POLICY §5, weakest first. *) +Inductive Status : Type := + | openRow | testedOnly | argued | provenWithPostulates | proven. + +Definition rank (s : Status) : nat := + match s with + | openRow => 0 + | testedOnly => 1 + | argued => 2 + | provenWithPostulates => 3 + | proven => 4 + end. + +(** Every rank from 4 up names [proven]. *) +Definition from_rank (n : nat) : Status := + match n with + | 0 => openRow + | 1 => testedOnly + | 2 => argued + | 3 => provenWithPostulates + | S (S (S (S _))) => proven + end. + +Lemma from_rank_rank : forall s, from_rank (rank s) = s. +Proof. intros []; reflexivity. Qed. + +Lemma rank_le_4 : forall s, rank s <= 4. +Proof. intros []; simpl; lia. Qed. + +Lemma rank_from_rank : forall n, n <= 4 -> rank (from_rank n) = n. +Proof. + intros [|[|[|[|[|n]]]]] p; try reflexivity. lia. +Qed. + +(** Two statuses with one rank are one status. *) +Lemma rank_injective : forall s t, rank s = rank t -> s = t. +Proof. + intros s t p. rewrite <- (from_rank_rank s), <- (from_rank_rank t), p. + reflexivity. +Qed. + +(** [_⊔e_]: alternatives keep the stronger status. *) +Definition ejoin (s t : Status) : Status := from_rank (rmax (rank s) (rank t)). + +(** [_⊓e_]: sequence keeps the weaker status. *) +Definition emeet (s t : Status) : Status := from_rank (rmin (rank s) (rank t)). + +Lemma rank_ejoin : forall s t, rank (ejoin s t) = rmax (rank s) (rank t). +Proof. + intros s t. apply rank_from_rank. + pose proof (rank_le_4 s). pose proof (rank_le_4 t). rewrite rmax_eq. lia. +Qed. + +Lemma rank_emeet : forall s t, rank (emeet s t) = rmin (rank s) (rank t). +Proof. + intros s t. apply rank_from_rank. + pose proof (rank_le_4 s). rewrite rmin_eq. lia. +Qed. + +(** Rewrite both sides to ranks and close the arithmetic. *) +Ltac by_rank := + apply rank_injective; + repeat (first [rewrite rank_ejoin | rewrite rank_emeet]); + cbn [rank]; + unfold_rmm; lia. + +Lemma Evidence_alt : IsAltMonoid ejoin openRow. +Proof. + split. + - intros a b c. by_rank. + - intros a b. by_rank. + - intros a. by_rank. + - intros a. by_rank. +Qed. + +Lemma Evidence_seq : IsSeqMonoid emeet proven. +Proof. + split. + - intros a b c. by_rank. + - intros a. pose proof (rank_le_4 a). by_rank. + - intros a. pose proof (rank_le_4 a). by_rank. +Qed. + +(** E-1: ⊕ = the stronger, ⊗ = the weaker, 𝟘 = [openRow], 𝟙 = [proven]. *) +Definition Evidence : ResourceAlgebra := + {| Grade := Status; radd := ejoin; rmul := emeet; rzero := openRow; rone := proven; + ralt := Evidence_alt; rseq := Evidence_seq |}. + +Lemma Evidence_dioid : IsDioid Evidence. +Proof. split; cbn [rmul radd Evidence]; intros a b c; by_rank. Qed. + +Lemma Evidence_ordered : IsOrdered Evidence. +Proof. exact (dioid_ordered Evidence_dioid). Qed. + +Lemma Evidence_annihilating : IsAnnihilating Evidence. +Proof. split; cbn [rmul rzero Evidence]; intro a; by_rank. Qed. + +(** E-1: the order is the rank order, and sequence is its meet. *) + +(** Agda [≼→≤]. *) +Lemma le_to_rank : forall a b, Le Evidence a b -> rank a <= rank b. +Proof. + unfold Le; simpl; intros a b p. + apply rmax_eq_le. rewrite <- rank_ejoin, p. reflexivity. +Qed. + +(** Agda [≤→≼]. *) +Lemma rank_to_le : forall a b, rank a <= rank b -> Le Evidence a b. +Proof. + unfold Le; simpl; intros a b p. + apply rank_injective. rewrite rank_ejoin, rmax_eq. lia. +Qed. + +(** Agda [≼-proven]. *) +Lemma le_proven : forall a, Le Evidence a proven. +Proof. intro a. apply rank_to_le, rank_le_4. Qed. + +(** Agda [⊓e-lowerˡ]. *) +Lemma emeet_lowerl : forall a b, Le Evidence (emeet a b) a. +Proof. intros a b. apply rank_to_le. rewrite rank_emeet. apply rmin_le_left. Qed. + +(** Agda [⊓e-lowerʳ]. *) +Lemma emeet_lowerr : forall a b, Le Evidence (emeet a b) b. +Proof. intros a b. apply rank_to_le. rewrite rank_emeet. apply rmin_le_right. Qed. + +(** Agda [⊓e-greatest]. *) +Lemma emeet_greatest : forall a b c, + Le Evidence c a -> Le Evidence c b -> Le Evidence c (emeet a b). +Proof. + intros a b c p q. apply rank_to_le. rewrite rank_emeet. + apply rmin_glb; apply le_to_rank; assumption. +Qed. + +(** * Evidence ledger (E-2, E-3) *) + +(** A ledger is a list of rows, newest first. A row's dependencies index the + rows after it, so no dependency cycle can be written. + + [mem], [Dep], [Reach] and [Respects] are [Prop] here, where Agda's are + [Set] ([_⊎_] and [⊥] become [\/] and [False]). They occur only as + hypotheses, or, for [Respects], as a record whose fields conclude in + equations, so no statement changes strength. [Reach] takes its starting + row as an index, not a parameter. *) + +(** Agda's [map], by the same two equations. *) +Fixpoint map_list {A B : Type} (f : A -> B) (xs : list A) : list B := + match xs with + | nil => nil + | cons x xs => cons (f x) (map_list f xs) + end. + +(** [_∈_], by recursion on the list. *) +Fixpoint mem (j : nat) (ks : list nat) : Prop := + match ks with + | nil => False + | cons k ks => j = k \/ mem j ks + end. + +(** [⨅]: the meet of a list of statuses; the empty meet is [proven]. *) +Fixpoint meet_all (ss : list Status) : Status := + match ss with + | nil => proven + | cons s ss => emeet s (meet_all ss) + end. + +Lemma meet_all_lower : forall (f : nat -> Status) js j, + mem j js -> Le Evidence (meet_all (map_list f js)) (f j). +Proof. + intros f js; induction js as [|k ks IH]; intros j p; simpl in p. + - destruct p. + - destruct p as [e|p]. + + subst j. apply emeet_lowerl. + + eapply le_trans; [apply emeet_lowerr | exact (IH j p)]. +Qed. + +Lemma meet_all_greatest : forall (f : nat -> Status) z js, + (forall j, mem j js -> Le Evidence z (f j)) -> Le Evidence z (meet_all (map_list f js)). +Proof. + intros f z js; induction js as [|k ks IH]; intro h; simpl. + - apply le_proven. + - apply emeet_greatest. + + apply h. left. reflexivity. + + apply IH. intros j p. apply h. right. exact p. +Qed. + +Record Row : Type := row { + own : Status; (* the §5 token of the row's own artefact *) + deps : list nat (* the rows it depends on, as indices into the rows after it *) +}. + +Definition Ledger : Type := list Row. + +Fixpoint own_of (L : Ledger) (i : nat) : Status := + match L, i with + | nil, _ => proven + | cons r _, 0 => own r + | cons _ L, S i => own_of L i + end. + +(** [Dep L i j]: row [i] depends directly on row [j]. *) +Fixpoint Dep (L : Ledger) (i j : nat) : Prop := + match L, i, j with + | nil, _, _ => False + | cons _ _, 0, 0 => False + | cons r _, 0, S j => mem j (deps r) + | cons _ _, S _, 0 => False + | cons _ L, S i, S j => Dep L i j + end. + +(** [Reach L i j]: row [i] depends on row [j] through zero or more steps. *) +Inductive Reach (L : Ledger) : nat -> nat -> Prop := + | stay : forall i, Reach L i i + | step : forall i k j, Dep L i k -> Reach L k j -> Reach L i j. + +(** The derived status. *) +Fixpoint eff (L : Ledger) (i : nat) {struct L} : Status := + match L, i with + | nil, _ => proven + | cons r L', 0 => emeet (own r) (meet_all (map_list (eff L') (deps r))) + | cons _ L', S i => eff L' i + end. + +(** E-2: never stronger than the row's own evidence. *) +Lemma eff_le_own : forall L i, Le Evidence (eff L i) (own_of L i). +Proof. + induction L as [|r L IH]; intros [|i]; simpl. + - apply le_refl. + - apply le_refl. + - apply emeet_lowerl. + - apply IH. +Qed. + +(** E-2: nor than any row it depends on. *) +Lemma eff_le_dep : forall L i j, Dep L i j -> Le Evidence (eff L i) (eff L j). +Proof. + induction L as [|r L IH]; intros [|i] [|j] d; simpl in d |- *; try contradiction. + - eapply le_trans; [apply emeet_lowerr | exact (meet_all_lower (eff L) (deps r) j d)]. + - exact (IH i j d). +Qed. + +(** E-2: a row is only as strong as the weakest step it depends on. *) +Lemma eff_le_reach : forall L i j, Reach L i j -> Le Evidence (eff L i) (own_of L j). +Proof. + intros L i j r. induction r as [i|i k j d r IH]. + - apply eff_le_own. + - eapply le_trans; [exact (eff_le_dep L i k d) | exact IH]. +Qed. + +(** An assignment respects a ledger when no row is stronger than its own + evidence or than a row it depends on. *) +Record Respects (L : Ledger) (s : nat -> Status) : Prop := { + below_own : forall i, Le Evidence (s i) (own_of L i); + below_dep : forall i j, Dep L i j -> Le Evidence (s i) (s j) +}. + +(** E-3 *) +Lemma eff_respects : forall L, Respects L (eff L). +Proof. intro L. split; [apply eff_le_own | apply eff_le_dep]. Qed. + +(** Restricting an assignment of [r :: L] to [L] keeps it respectful. *) +Lemma restrict : forall r L s, Respects (cons r L) s -> Respects L (fun i => s (S i)). +Proof. + intros r L s rho. split. + - intro i. exact (below_own rho (S i)). + - intros i j d. exact (below_dep rho (S i) (S j) d). +Qed. + +(** E-3: every assignment that respects the ledger is below [eff]. *) +Lemma eff_greatest : forall L s, Respects L s -> forall i, Le Evidence (s i) (eff L i). +Proof. + induction L as [|r L IH]; intros s rho [|i]; simpl. + - apply le_proven. + - apply le_proven. + - apply emeet_greatest. + + exact (below_own rho 0). + + apply meet_all_greatest. intros j p. + eapply le_trans. + * exact (below_dep rho 0 (S j) p). + * exact (IH (fun k => s (S k)) (restrict rho) j). + - exact (IH (fun k => s (S k)) (restrict rho) i). +Qed. + +(** The worked ledger of [tests/unit/EvidenceTest.agda], with its expected + values. They pin the chain order, which the laws above cannot see. *) + +Lemma sequence_keeps_the_weaker : rmul Evidence argued testedOnly = testedOnly. +Proof. reflexivity. Qed. + +Lemma alternative_keeps_the_stronger : radd Evidence argued testedOnly = argued. +Proof. reflexivity. Qed. + +Lemma provenWithPostulates_below_proven : + rmul Evidence proven provenWithPostulates = provenWithPostulates. +Proof. reflexivity. Qed. + +Lemma open_annihilates : rmul Evidence proven openRow = openRow. +Proof. reflexivity. Qed. + +(** Newest first; indices count back from each row. *) +Definition example_ledger : Ledger := + cons (row proven (cons 0 (cons 1 nil))) (* row 4: on row 3 and row 2 *) + (cons (row testedOnly nil) (* row 3 *) + (cons (row proven (cons 0 (cons 1 nil))) (* row 2: on row 1 and row 0 *) + (cons (row argued nil) (* row 1 *) + (cons (row proven nil) (* row 0 *) + nil)))). + +Lemma row2_is_argued : eff example_ledger 2 = argued. +Proof. reflexivity. Qed. + +Lemma row4_is_tested_only : eff example_ledger 0 = testedOnly. +Proof. reflexivity. Qed. + +Lemma row0_keeps_its_evidence : eff example_ledger 4 = proven. +Proof. reflexivity. Qed. + (** * Assumptions (PROOF-POLICY §8.4): each must print "Closed under the global context". *) Print Assumptions alt_unitr. @@ -824,3 +1167,26 @@ Print Assumptions one_question_unique. Print Assumptions first_question. Print Assumptions later_questions. Print Assumptions count_not_add. +Print Assumptions Evidence. +Print Assumptions Evidence_dioid. +Print Assumptions Evidence_ordered. +Print Assumptions Evidence_annihilating. +Print Assumptions le_to_rank. +Print Assumptions rank_to_le. +Print Assumptions le_proven. +Print Assumptions emeet_lowerl. +Print Assumptions emeet_lowerr. +Print Assumptions emeet_greatest. +Print Assumptions eff_le_own. +Print Assumptions eff_le_dep. +Print Assumptions eff_le_reach. +Print Assumptions eff_respects. +Print Assumptions restrict. +Print Assumptions eff_greatest. +Print Assumptions sequence_keeps_the_weaker. +Print Assumptions alternative_keeps_the_stronger. +Print Assumptions provenWithPostulates_below_proven. +Print Assumptions open_annihilates. +Print Assumptions row2_is_argued. +Print Assumptions row4_is_tested_only. +Print Assumptions row0_keeps_its_evidence. diff --git a/verification/proofs/lean4/ResourceAlgebra.lean b/verification/proofs/lean4/ResourceAlgebra.lean index ee0e86b..00e6c10 100644 --- a/verification/proofs/lean4/ResourceAlgebra.lean +++ b/verification/proofs/lean4/ResourceAlgebra.lean @@ -910,6 +910,328 @@ theorem count_not_add : = lmin (fin (qcount 2 a)) (fin (qcount 2 b)) := fun f => absurd (fin_injective (f collapse shuffle) : (0 : Nat) = 1) (by decide) +/-! ## Evidence (E-1) + +The status of a proof-ledger row, as a chain, weakest first: +`openRow < testedOnly < argued < provenWithPostulates < proven`. A status +is coded by its rank (0 to 4); alternatives take the max of the ranks and +sequence the min, as in Agda's `Instances/Evidence.agda`. -/ + +/-- `min m n ≤ m` (Agda: `min-≤-left`). -/ +theorem rmin_le_left : ∀ m n, rmin m n ≤ m + | 0, _ => Nat.zero_le _ + | _ + 1, 0 => Nat.zero_le _ + | m + 1, n + 1 => Nat.succ_le_succ (rmin_le_left m n) + +/-- `min m n ≤ n` (Agda: `min-≤-right`). -/ +theorem rmin_le_right (m n : Nat) : rmin m n ≤ n := by + rw [rmin_comm] + exact rmin_le_left n m + +/-- `k ≤ m → k ≤ n → k ≤ min m n` (Agda: `min-glb`). -/ +theorem rmin_glb : ∀ {k m n : Nat}, k ≤ m → k ≤ n → k ≤ rmin m n + | 0, _, _, _, _ => Nat.zero_le _ + | _ + 1, 0, _, p, _ => absurd p (Nat.not_succ_le_zero _) + | _ + 1, _ + 1, 0, _, q => absurd q (Nat.not_succ_le_zero _) + | _ + 1, _ + 1, _ + 1, p, q => + Nat.succ_le_succ (rmin_glb (Nat.le_of_succ_le_succ p) (Nat.le_of_succ_le_succ q)) + +/-- `min a (max b c) = max (min a b) (min a c)` (Agda: `min-distribˡ-max`). -/ +theorem rmin_rmax_l : ∀ a b c, rmin a (rmax b c) = rmax (rmin a b) (rmin a c) + | 0, _, _ => rfl + | _ + 1, 0, _ => rfl + | a + 1, b + 1, 0 => (rmax_zero_r (rmin a b + 1)).symm + | a + 1, b + 1, c + 1 => congrArg (· + 1) (rmin_rmax_l a b c) + +/-- `max m n = n → m ≤ n` (Agda: `max-≡→≤`). -/ +theorem rmax_eq_le {m n : Nat} (p : rmax m n = n) : m ≤ n := by + rw [← p] + exact le_rmax_left m n + +/-- The closed status vocabulary of PROOF-POLICY §5, weakest first. -/ +inductive Status where + | openRow + | testedOnly + | argued + | provenWithPostulates + | proven + +open Status + +def rank : Status → Nat + | openRow => 0 + | testedOnly => 1 + | argued => 2 + | provenWithPostulates => 3 + | proven => 4 + +/-- Every rank from 4 up names `proven`. -/ +def fromRank : Nat → Status + | 0 => openRow + | 1 => testedOnly + | 2 => argued + | 3 => provenWithPostulates + | _ + 4 => proven + +theorem fromRank_rank : ∀ s, fromRank (rank s) = s + | openRow => rfl + | testedOnly => rfl + | argued => rfl + | provenWithPostulates => rfl + | proven => rfl + +theorem rank_le_four : ∀ s, rank s ≤ 4 + | openRow => Nat.zero_le 4 + | testedOnly => Nat.succ_le_succ (Nat.zero_le 3) + | argued => Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le 2)) + | provenWithPostulates => Nat.succ_le_succ (Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le 1))) + | proven => Nat.le_refl 4 + +theorem rank_fromRank : ∀ {n : Nat}, n ≤ 4 → rank (fromRank n) = n + | 0, _ => rfl + | 1, _ => rfl + | 2, _ => rfl + | 3, _ => rfl + | 4, _ => rfl + | _ + 5, p => absurd + (Nat.le_of_succ_le_succ (Nat.le_of_succ_le_succ (Nat.le_of_succ_le_succ + (Nat.le_of_succ_le_succ p)))) + (Nat.not_succ_le_zero _) + +/-- Two statuses with one rank are one status. -/ +theorem rank_injective {s t : Status} (p : rank s = rank t) : s = t := + (fromRank_rank s).symm.trans ((congrArg fromRank p).trans (fromRank_rank t)) + +/-- `_⊔e_`: alternatives keep the stronger status. -/ +def eJoin (s t : Status) : Status := fromRank (rmax (rank s) (rank t)) + +/-- `_⊓e_`: sequence keeps the weaker status. -/ +def eMeet (s t : Status) : Status := fromRank (rmin (rank s) (rank t)) + +theorem rank_eJoin (s t : Status) : rank (eJoin s t) = rmax (rank s) (rank t) := + rank_fromRank (rmax_lub (rank_le_four s) (rank_le_four t)) + +theorem rank_eMeet (s t : Status) : rank (eMeet s t) = rmin (rank s) (rank t) := + rank_fromRank (Nat.le_trans (rmin_le_left (rank s) (rank t)) (rank_le_four s)) + +theorem eJoin_assoc (a b c : Status) : eJoin (eJoin a b) c = eJoin a (eJoin b c) := + rank_injective (by rw [rank_eJoin, rank_eJoin, rank_eJoin, rank_eJoin, rmax_assoc]) + +theorem eJoin_comm (a b : Status) : eJoin a b = eJoin b a := + congrArg fromRank (rmax_comm (rank a) (rank b)) + +theorem eJoin_idem (a : Status) : eJoin a a = a := + (congrArg fromRank (rmax_idem (rank a))).trans (fromRank_rank a) + +theorem eJoin_unitl (a : Status) : eJoin openRow a = a := fromRank_rank a + +theorem eMeet_assoc (a b c : Status) : eMeet (eMeet a b) c = eMeet a (eMeet b c) := + rank_injective (by rw [rank_eMeet, rank_eMeet, rank_eMeet, rank_eMeet, rmin_assoc]) + +theorem eMeet_comm (a b : Status) : eMeet a b = eMeet b a := + congrArg fromRank (rmin_comm (rank a) (rank b)) + +theorem eMeet_unitl (a : Status) : eMeet proven a = a := + (congrArg fromRank (rmin_of_ge (rank_le_four a))).trans (fromRank_rank a) + +theorem eMeet_unitr (a : Status) : eMeet a proven = a := + (eMeet_comm a proven).trans (eMeet_unitl a) + +/-- E-1: ⊕ = the stronger, ⊗ = the weaker, 𝟘 = `openRow`, 𝟙 = `proven`. -/ +abbrev Evidence : ResourceAlgebra where + Grade := Status + add := eJoin + mul := eMeet + zero := openRow + one := proven + alt := { assoc := eJoin_assoc, comm := eJoin_comm, idem := eJoin_idem, unitl := eJoin_unitl } + seq := { assoc := eMeet_assoc, unitl := eMeet_unitl, unitr := eMeet_unitr } + +theorem eMeet_distribl (a b c : Status) : + eMeet a (eJoin b c) = eJoin (eMeet a b) (eMeet a c) := + rank_injective (by + rw [rank_eMeet, rank_eJoin, rmin_rmax_l, rank_eJoin, rank_eMeet, rank_eMeet]) + +theorem eMeet_distribr (a b c : Status) : + eMeet (eJoin a b) c = eJoin (eMeet a c) (eMeet b c) := by + rw [eMeet_comm, eMeet_distribl, eMeet_comm c a, eMeet_comm c b] + +/-- E-1 -/ +theorem Evidence_dioid : IsDioid Evidence where + distribl := eMeet_distribl + distribr := eMeet_distribr + +theorem Evidence_ordered : IsOrdered Evidence := Evidence_dioid.ordered + +theorem Evidence_annihilating : IsAnnihilating Evidence where + annihill _ := rfl + annihilr a := congrArg fromRank (rmin_zero_r (rank a)) + +/-! E-1: the order is the rank order, and sequence is its meet. -/ + +/-- Agda `≼→≤`. -/ +theorem le_to_rank {a b : Status} (p : Evidence.Le a b) : rank a ≤ rank b := + rmax_eq_le ((rank_eJoin a b).symm.trans (congrArg rank p)) + +/-- Agda `≤→≼`. -/ +theorem rank_to_le {a b : Status} (p : rank a ≤ rank b) : Evidence.Le a b := + (congrArg fromRank (rmax_of_le p)).trans (fromRank_rank b) + +/-- Agda `≼-proven`. -/ +theorem le_proven (a : Status) : Evidence.Le a proven := rank_to_le (rank_le_four a) + +/-- Agda `⊓e-lowerˡ`. -/ +theorem eMeet_lowerl (a b : Status) : Evidence.Le (eMeet a b) a := + rank_to_le (by rw [rank_eMeet]; exact rmin_le_left (rank a) (rank b)) + +/-- Agda `⊓e-lowerʳ`. -/ +theorem eMeet_lowerr (a b : Status) : Evidence.Le (eMeet a b) b := + rank_to_le (by rw [rank_eMeet]; exact rmin_le_right (rank a) (rank b)) + +/-- Agda `⊓e-greatest`. -/ +theorem eMeet_greatest {a b c : Status} (p : Evidence.Le c a) (q : Evidence.Le c b) : + Evidence.Le c (eMeet a b) := + rank_to_le (by rw [rank_eMeet]; exact rmin_glb (le_to_rank p) (le_to_rank q)) + +/-! ## Evidence ledger (E-2, E-3) + +A ledger is a list of rows, newest first. A row's dependencies index the +rows after it, so no dependency cycle can be written. + +`Mem`, `Dep`, `Reach` and `Respects` are `Prop` here, where Agda's are +`Set` (`_⊎_` and `⊥` become `∨` and `False`). They occur only as +hypotheses, or, for `Respects`, as a record whose fields conclude in +equations, so no statement changes strength. `Reach` takes its starting +row as an index, not a parameter. -/ + +/-- Agda's `map`, by the same two equations. -/ +def mapList {A B : Type} (f : A → B) : List A → List B + | [] => [] + | x :: xs => f x :: mapList f xs + +/-- `_∈_`, by recursion on the list. -/ +def Mem (j : Nat) : List Nat → Prop + | [] => False + | k :: ks => j = k ∨ Mem j ks + +/-- `⨅`: the meet of a list of statuses; the empty meet is `proven`. -/ +def meetAll : List Status → Status + | [] => proven + | s :: ss => eMeet s (meetAll ss) + +theorem meetAll_lower {f : Nat → Status} : + ∀ (js : List Nat) {j : Nat}, Mem j js → Evidence.Le (meetAll (mapList f js)) (f j) + | [], _, h => False.elim h + | k :: ks, _, Or.inl rfl => eMeet_lowerl (f k) (meetAll (mapList f ks)) + | k :: ks, _, Or.inr p => + Evidence.le_trans (eMeet_lowerr (f k) (meetAll (mapList f ks))) (meetAll_lower ks p) + +theorem meetAll_greatest {f : Nat → Status} {z : Status} : + ∀ (js : List Nat), (∀ {j}, Mem j js → Evidence.Le z (f j)) → + Evidence.Le z (meetAll (mapList f js)) + | [], _ => le_proven z + | _ :: ks, h => eMeet_greatest (h (Or.inl rfl)) (meetAll_greatest ks (fun p => h (Or.inr p))) + +structure Row where + row :: + own : Status -- the §5 token of the row's own artefact + deps : List Nat -- the rows it depends on, as indices into the rows after it + +abbrev Ledger := List Row + +def ownOf : Ledger → Nat → Status + | [], _ => proven + | r :: _, 0 => r.own + | _ :: L, i + 1 => ownOf L i + +/-- `Dep L i j`: row `i` depends directly on row `j`. -/ +def Dep : Ledger → Nat → Nat → Prop + | [], _, _ => False + | _ :: _, 0, 0 => False + | r :: _, 0, j + 1 => Mem j r.deps + | _ :: _, _ + 1, 0 => False + | _ :: L, i + 1, j + 1 => Dep L i j + +/-- `Reach L i j`: row `i` depends on row `j` through zero or more steps. -/ +inductive Reach (L : Ledger) : Nat → Nat → Prop where + | stay {i : Nat} : Reach L i i + | step {i k j : Nat} : Dep L i k → Reach L k j → Reach L i j + +/-- The derived status. -/ +def eff : Ledger → Nat → Status + | [], _ => proven + | r :: L, 0 => eMeet r.own (meetAll (mapList (eff L) r.deps)) + | _ :: L, i + 1 => eff L i + +/-- E-2: never stronger than the row's own evidence. -/ +theorem eff_le_own : ∀ L i, Evidence.Le (eff L i) (ownOf L i) + | [], _ => Evidence.le_refl proven + | r :: L, 0 => eMeet_lowerl r.own (meetAll (mapList (eff L) r.deps)) + | _ :: L, i + 1 => eff_le_own L i + +/-- E-2: nor than any row it depends on. -/ +theorem eff_le_dep : ∀ L i j, Dep L i j → Evidence.Le (eff L i) (eff L j) + | [], _, _, d => False.elim d + | _ :: _, 0, 0, d => False.elim d + | r :: L, 0, _ + 1, p => + Evidence.le_trans (eMeet_lowerr r.own (meetAll (mapList (eff L) r.deps))) + (meetAll_lower r.deps p) + | _ :: _, _ + 1, 0, d => False.elim d + | _ :: L, i + 1, j + 1, d => eff_le_dep L i j d + +/-- E-2: a row is only as strong as the weakest step it depends on. -/ +theorem eff_le_reach (L : Ledger) {i j : Nat} (r : Reach L i j) : + Evidence.Le (eff L i) (ownOf L j) := by + induction r with + | stay => exact eff_le_own L _ + | step d _ ih => exact Evidence.le_trans (eff_le_dep L _ _ d) ih + +/-- An assignment respects a ledger when no row is stronger than its own +evidence or than a row it depends on. -/ +structure Respects (L : Ledger) (s : Nat → Status) : Prop where + below_own : ∀ i, Evidence.Le (s i) (ownOf L i) + below_dep : ∀ i j, Dep L i j → Evidence.Le (s i) (s j) + +/-- E-3 -/ +theorem eff_respects (L : Ledger) : Respects L (eff L) := + ⟨eff_le_own L, eff_le_dep L⟩ + +/-- Restricting an assignment of `r :: L` to `L` keeps it respectful. -/ +theorem restrict {r : Row} {L : Ledger} {s : Nat → Status} (ρ : Respects (r :: L) s) : + Respects L (fun i => s (i + 1)) := + ⟨fun i => ρ.below_own (i + 1), fun i j d => ρ.below_dep (i + 1) (j + 1) d⟩ + +/-- E-3: every assignment that respects the ledger is below `eff`. -/ +theorem eff_greatest : ∀ L s, Respects L s → ∀ i, Evidence.Le (s i) (eff L i) + | [], s, _, i => le_proven (s i) + | r :: L, s, ρ, 0 => + eMeet_greatest (ρ.below_own 0) + (meetAll_greatest r.deps (fun {j} p => + Evidence.le_trans (ρ.below_dep 0 (j + 1) p) + (eff_greatest L (fun k => s (k + 1)) (restrict ρ) j))) + | _ :: L, s, ρ, i + 1 => eff_greatest L (fun k => s (k + 1)) (restrict ρ) i + +/-! The worked ledger of `tests/unit/EvidenceTest.agda`, with its expected +values. They pin the chain order, which the laws above cannot see. -/ + +theorem sequence_keeps_the_weaker : Evidence.mul argued testedOnly = testedOnly := rfl +theorem alternative_keeps_the_stronger : Evidence.add argued testedOnly = argued := rfl +theorem provenWithPostulates_below_proven : + Evidence.mul proven provenWithPostulates = provenWithPostulates := rfl +theorem open_annihilates : Evidence.mul proven openRow = openRow := rfl + +/-- Newest first; indices count back from each row. -/ +def exampleLedger : Ledger := + [ Row.row proven [0, 1] -- row 4: on row 3 and row 2 + , Row.row testedOnly [] -- row 3 + , Row.row proven [0, 1] -- row 2: on row 1 and row 0 + , Row.row argued [] -- row 1 + , Row.row proven [] ] -- row 0 + +theorem row2_is_argued : eff exampleLedger 2 = argued := rfl +theorem row4_is_tested_only : eff exampleLedger 0 = testedOnly := rfl +theorem row0_keeps_its_evidence : eff exampleLedger 4 = proven := rfl + end RA /-! ## Axioms (PROOF-POLICY §8.4) @@ -972,3 +1294,26 @@ other answer. -/ #print axioms RA.firstQuestion #print axioms RA.laterQuestions #print axioms RA.count_not_add +#print axioms RA.Evidence +#print axioms RA.Evidence_dioid +#print axioms RA.Evidence_ordered +#print axioms RA.Evidence_annihilating +#print axioms RA.le_to_rank +#print axioms RA.rank_to_le +#print axioms RA.le_proven +#print axioms RA.eMeet_lowerl +#print axioms RA.eMeet_lowerr +#print axioms RA.eMeet_greatest +#print axioms RA.eff_le_own +#print axioms RA.eff_le_dep +#print axioms RA.eff_le_reach +#print axioms RA.eff_respects +#print axioms RA.restrict +#print axioms RA.eff_greatest +#print axioms RA.sequence_keeps_the_weaker +#print axioms RA.alternative_keeps_the_stronger +#print axioms RA.provenWithPostulates_below_proven +#print axioms RA.open_annihilates +#print axioms RA.row2_is_argued +#print axioms RA.row4_is_tested_only +#print axioms RA.row0_keeps_its_evidence From c539c318d94451103dd0e053336be84c2b2b90c6 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 22:41:39 +0000 Subject: [PATCH 3/3] Ledger: a dependency is bounded by its row's tail, not by the ledger The dangling-reference precondition said 'past the end of the ledger'. A dependency index counts into the rows after its own row, so index 1 on the newer row of a two-row ledger is below the ledger's length and still names no row; eff reads it as proven. PROOF-STATUS and the header of Ledger.agda now say a reader must check each dependency against the length of that row's tail. Comment and prose only; no definition or proof changes. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_013CuBToxr5h9catptGiTsFX --- docs/status/PROOF-STATUS.adoc | 7 +++++-- src/ResourceAlgebra/Ledger.agda | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/status/PROOF-STATUS.adoc b/docs/status/PROOF-STATUS.adoc index 92bd7be..722f1ab 100644 --- a/docs/status/PROOF-STATUS.adoc +++ b/docs/status/PROOF-STATUS.adoc @@ -449,8 +449,11 @@ cycle can be written. The derived status of a row, `eff`, is its own evidence in sequence (⊗ of `Evidence`) with the derived statuses of the rows it depends on. This is README-EXPLAINME's rule that a row is only as strong as the weakest step it depends on, as a theorem rather than a convention. -A reference past the end of the ledger names no row, and `eff` reads it as -`proven`. So any reader of a ledger must refuse such a reference, as an +A dependency index counts into the rows after its own row. An index at or +past the number of those rows names no row, even when it is below the +ledger's length, and `eff` reads it as +`proven`. So any reader of a ledger must check each dependency against the +length of that row's tail and refuse one that fails, as an unregistered row ID, before it derives a status. That is a precondition every reader must enforce, not a guarantee this repository gives: no reader exists yet (the standards ledger reader is planned), and the diff --git a/src/ResourceAlgebra/Ledger.agda b/src/ResourceAlgebra/Ledger.agda index 83462cf..cffa3d6 100644 --- a/src/ResourceAlgebra/Ledger.agda +++ b/src/ResourceAlgebra/Ledger.agda @@ -11,8 +11,10 @@ -- A ledger is a list of rows, newest first. Row 0 is the head; row i + 1 -- is row i of the tail. A row's dependencies are indices into the rows -- after it, so a row can depend only on older rows and no dependency cycle --- can be written. An index past the end names no row, and the derivation --- reads it as proven (𝟙). So any reader of a ledger must refuse such a +-- can be written. An index at or past the number of rows after its own row +-- names no row, even when it is below the ledger's length, and the derivation +-- reads it as proven (𝟙). So any reader of a ledger must check each +-- dependency against the length of that row's tail and refuse a -- dangling reference, as an unregistered row ID, before it derives a -- status. That is a precondition every reader must enforce, not a -- guarantee given here: no reader exists yet, and the theorems below hold