diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f433b08..2868c27 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,3 +20,20 @@ jobs: - uses: leanprover/lean-action@v1.7.0 - name: No sorries run: "! grep -rn 'sorry' Marches/ Marches.lean" + + agda: + # PROOF-POLICY §2.1: the Agda source of truth (proofs/agda), checked cold + # with the checksum-pinned compiler; the import cone scanned for + # postulates; the fixtures under tests/reject-agda refused. The last lines + # of the log are the receipt fields. Local run: scripts/setup-agda.sh, + # then scripts/check-agda.sh. + runs-on: ubuntu-24.04 + timeout-minutes: 15 + steps: + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: Install the checksum-pinned Agda + run: bash scripts/setup-agda.sh + - name: Agda gate + run: bash scripts/check-agda.sh diff --git a/.gitignore b/.gitignore index 8859dd2..380cb9b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.lake/ /_build/ +*.agdai diff --git a/PROOF-STATUS.adoc b/PROOF-STATUS.adoc index 62dbe1b..8cbf5d7 100644 --- a/PROOF-STATUS.adoc +++ b/PROOF-STATUS.adoc @@ -22,15 +22,22 @@ marches was written in Lean 4 from 2026-07, before the 2026-10-26 ruling. By §3 its Lean files keep their value but are *target-only evidence*: they count as the Lean leg only once an Agda proof of the same statement is `PROVEN` and the two statements have been compared and the comparison -recorded (`RECONCILED`). Until then every Agda row is `OPEN`. +recorded (`RECONCILED`). The Agda source is in `proofs/agda`, ported group by +group in ROADMAP order. A group with no Agda proof yet stays `OPEN`. == Grades -Every theorem below is *`ungraded`*: no Agda witness exists, so not even -`PWG-3` applies (§8.2). `foundation_diverse` is false throughout. +The four theorems of the Kernel group are *`PWG-2i`*. The Agda leg is +`PROVEN` under the §2.1 invocation, which is `PWG-3`. The Lean leg is `PROVEN` +with no axioms, and its statements are `RECONCILED` with the Agda ones in +`docs/agda-lean-correspondence.adoc`. Their Rocq leg is `OPEN`, so they still +owe §2's second recheck (§8.4: a grade is not a discharge). Every other theorem +is *`ungraded`*, because no Agda witness exists for it yet. `foundation_diverse` +is false throughout. Grade census (§8.4), denominator 211 theorems in the `Marches` namespace: -`PWG-1` 0, `PWG-2ii` 0, `PWG-2i` 0, `PWG-3` 0, `ungraded` 211. The 235 +`PWG-1` 0, `PWG-2ii` 0, `PWG-2i` 4, `PWG-3` 0, `ungraded` 207. None of the four +rests on an axiom. The 235 definitions in the same namespace are not proof obligations and are not counted; the axiom census below covers both kinds. @@ -39,14 +46,17 @@ counted; the axiom census below covers both kinds. |Leg |Route |Status token |§2.2 state |Agda (source) -|— -|`OPEN` (no Agda development yet) +|`source` (`proofs/agda`) +|`PROVEN` for the Kernel group (receipt below); `OPEN` for every other group |— |Lean -|`re-proved` (written directly in Lean; no Agda to transport from) -|`PROVEN` or `PROVEN-WITH-AXIOMS`, per group below; target-only evidence (§3) -|not `RECONCILED`: no Agda statement to compare against +|`re-proved` (written by hand in Lean from 2026-07, before the Agda; not +transported) +|`PROVEN` or `PROVEN-WITH-AXIOMS`, per group below +|`RECONCILED` for the Kernel group (`docs/agda-lean-correspondence.adoc`); +for every other group, target-only evidence (§3) with no Agda statement to +compare against |Rocq |— @@ -54,6 +64,48 @@ counted; the axiom census below covers both kinds. |— |=== +== Agda leg receipt + +Taken 2026-11-16 at `660e1c61cfdc138452d9a9b4e9bd550cbfebe8fc`, the commit +that added `proofs/agda`, with `scripts/check-agda.sh` (cold: no interface +files are read). Checker: Agda `2.7.0.1`, the release archive accepted at +SHA-256 `975b515a14877ab6bce5bfc641e16c4a3ee52ca5d7f846577dee80aa2145db8a` +(`scripts/setup-agda.sh`). There is no standard library or other Agda +library. The same script runs in CI as the `agda` job of `ci.yml`. + +---- +$ agda --safe --without-K --cubical-compatible --no-libraries --ignore-interfaces -i proofs/agda proofs/agda/All.agda +import cone: Agda.Builtin.Equality Agda.Builtin.List Agda.Primitive All Marches.Basic Marches.Kernel Marches.Prelude +postulate scan: 4 files, 0 postulate(s) +prover-supplied: Agda.Primitive postulates exactly Level _⊔_ lsuc lzero, each bound by its BUILTIN pragma; no other postulate +[PASS] postulate scan: cone clean, both controls behave +[PASS] refused as expected: a postulate, by the command-line --safe +[PASS] refused as expected: tests/reject-agda/FreewheelReturns.agda (should be empty) +[PASS] refused as expected: tests/reject-agda/UsesK.agda (because K has been disabled) +inputs-manifest: + 6d72ba84f01be6ee0f1eb968c24211ef4ff6a2f9b709b5ac68f841362595c917 proofs/agda/All.agda + 6d11fd6646fe9c4e974f2ad86a0c273f071f4a4502dead8535b31a7a2e57ce96 proofs/agda/Marches/Basic.agda + 19980896daff2a787ef2b91f584e7d3568d80316f6bc31c2454de7b609bb663b proofs/agda/Marches/Kernel.agda + ecfec1a4105f5f6cf36272fa278774ebfb6c88e11f9bf3c662d7326f0ab3039c proofs/agda/Marches/Prelude.agda +inputs-sha256: 4f589dfe6d2719a058dd182b52cf7cccfeb4817c542831df6a9b963348821567 +[check-agda] OK +---- + +The digest is the §8.5.1 one. The policy's shell line +(`printf '%s\n' PATH… | LC_ALL=C sort | xargs -d '\n' sha256sum -- | sha256sum`) +gives the same value. Axioms: none. The trusted base is the four +`Agda.Primitive` primitives named above. + +*Scope of this receipt.* It is a local run at the commit named. CI runs the +same gate on every commit and prints the same fields, but no job yet +records them. The machine-readable proof receipt of §8.5.1 +(`verification/receipts/*_praxis.deed`, read by `deed_lint.js`) is `OPEN`. +Until it exists, the grades here are derived by hand from these records, +and none of them is `PWG-1`. A squash merge will replace `660e1c6` on `main`. The receipt still describes +the merge commit while the four input files are unchanged there: an echo +(§8.5.2) with an `inputs-sha256` witness, to be written into the +machine-readable receipt when it exists. + == Lean leg receipt Taken 2026-11-09 on `main` at `abe636aaba3f36eebee7f40b0707ef6bb090715e`, @@ -96,6 +148,15 @@ A CI job that emits a full §8.2 receipt per commit is `OPEN` (see the plan below). When the Lean inputs change, this receipt is superseded and must be retaken. +The Kernel group's Lean leg was re-checked on 2026-11-16 at `660e1c6`, whose +`Marches/` tree is the same `7ef83e4` as above. Lean `v4.35.0` (release +archive accepted at SHA-256 +`7289597a44543246c9227b8cae501767e095ce17f6d448b95fc4a8dc97268f6d`): +`lake build` completed (19 jobs), there is no `sorry`, the BadGadget `#eval` +prints the same orbit, and `#print axioms` reports "does not depend on any +axioms" for `strict_implies_inflationary`, `run_le`, `run_worsens` and +`no_return`. + == Theorem groups `PROVEN` here means the Lean kernel accepted the term with no axioms. @@ -112,9 +173,10 @@ are not headline theorems and no row below depends on them. |Group (module) |Headline theorems |Lean leg |Agda |Kernel: single-region loop-freedom (`Kernel`, `Basic`) -|`run_worsens`, `no_return`, `strict_implies_inflationary` -|`PROVEN` -|`OPEN` +|`run_worsens`, `no_return`, `strict_implies_inflationary`, `run_le` +|`PROVEN`, `RECONCILED` +|`PROVEN` (`run-worsens`, `no-return`, `strict-implies-inflationary`, +`run-le`): `PWG-2i` |Two-region composition (`Compose`) |`trace_worsens`, `wt_cycles_are_empty`, `no_back_cross`, `no_a_label_in_B` @@ -191,7 +253,7 @@ import, checked by `lake build`, but it inherits the same `OPEN` Agda status. == Plan: closing the Agda gap Owner decision 2026-11-09: record the gap here now; the Agda port is the -next body of work. +next body of work. Progress: Kernel group done 2026-11-16 (steps 1 and 2). . *Agda source.* Port the groups above to Agda in this repository (`--safe --without-K`, no postulates, the §2.1 canonical invocation), group @@ -213,7 +275,7 @@ recording the fields §8.2 lists (checker and version, invocation, input digest, result, axioms, full commit): `PWG-1`. For the Lean leg this is a CI job around `lake build` and the axiom census; it is `OPEN`. -Until step 1 lands for a group, nothing in this repository may be called +Until step 1 lands for a group, nothing in that group may be called graded. `PROVEN` and `PROVEN-WITH-AXIOMS` in `README.adoc` mean "accepted by the Lean kernel", without or with the named axioms, not "discharged under the estate policy". diff --git a/README.adoc b/README.adoc index a0f0184..493436e 100644 --- a/README.adoc +++ b/README.adoc @@ -53,9 +53,11 @@ graded machinery (see `ROADMAP.adoc`). `PROVEN` in this table means the Lean kernel accepted the proof and it uses no axioms. `PROVEN-WITH-AXIOMS` means the kernel accepted it and it rests on the Lean built-in axioms named in the row. Under the estate proof policy -marches is theory, so Agda is the source of truth and no theorem here is -graded yet. `PROOF-STATUS.adoc` records each witness leg, the axiom census, -the scope of the Lean receipt, and the plan for the Agda port. +marches is theory, so Agda is the source of truth (`proofs/agda`). The port +goes group by group. So far only the Kernel group is graded: its four +theorems are `PWG-2i` (Agda `PROVEN`, Lean leg reconciled, Rocq leg `OPEN`). +Every other theorem is ungraded. `PROOF-STATUS.adoc` records each witness +leg, the receipts, the axiom census and the plan for the rest of the port. [cols="3,1,2"] |=== diff --git a/ROADMAP.adoc b/ROADMAP.adoc index 29bfce3..6ff58b6 100644 --- a/ROADMAP.adoc +++ b/ROADMAP.adoc @@ -102,6 +102,23 @@ it `PWG-2ii`. Gate per group: the Agda check passes under the canonical invocation and the statement comparison is written down. Takes precedence over rung 4. +[cols="3,3,1",options="header"] +|=== +|Group |Artefact |Status + +|Kernel (`Basic`, `Kernel`) +|`proofs/agda/Marches/` (`Prelude`, `Basic`, `Kernel`); `scripts/check-agda.sh` in +CI; `docs/agda-lean-correspondence.adoc` +|met 2026-11-16 (`PWG-2i`) + +|Two-region composition (`Compose`) +|— +|next +|=== + +After all groups: the machine-readable proof receipt +(`verification/receipts/*_praxis.deed`, PROOF-POLICY §8.5.1). + == Rung 4 — attestation (A2ML bridge) * Announcements as attested claims: RPKI attests origin; this layer diff --git a/STATE.adoc b/STATE.adoc index 79c88d4..7c1fae7 100644 --- a/STATE.adoc +++ b/STATE.adoc @@ -1,5 +1,35 @@ = STATE — cross-session log +== 2026-11-16 — Agda source, Kernel group (Agda-source session) + +* `proofs/agda` holds the Agda source for the Kernel group: `PathAlgebra`, + `StrictlyInflationary`, `Inflationary`, `run`, `strict-implies-inflationary`, + `run-le`, `run-worsens` and `no-return`. A small local `Prelude` replaces + the standard library, so the import cone is four files here plus + `Agda.Primitive`, `Agda.Builtin.Equality` and `Agda.Builtin.List`. This + matches the Lean side (core only, no Mathlib), and later groups will prove + the lemmas they need by hand, as the Lean side does. +* `scripts/check-agda.sh` checks `proofs/agda/All.agda` cold under the §2.1 + invocation. It scans the import cone with januskey's reference postulate + scanner, ported verbatim (`b503488`): no postulate here, and in the + prover's modules only `Agda.Primitive`'s four level primitives. It + requires refusals: a `--safe` control, `FreewheelReturns` (strictness is + load-bearing, as with F2) and `UsesK` (`--without-K` is in force on the + command line). It then prints the receipt fields and the §8.5.1 inputs + digest. `scripts/setup-agda.sh` installs Agda 2.7.0.1 at echo-types' + checksum. A new `agda` job in `ci.yml` runs both. +* Receipt at `660e1c6`: PASS, inputs digest `4f589df…`, which the policy's + shell line reproduces. Lean leg re-checked at the same commit with v4.35.0 + (archive checksum OK): `lake build` 19 jobs, no `sorry`, the orbit + unchanged, and no axioms for the four theorems. +* `docs/agda-lean-correspondence.adoc` is the §2.2 comparison, made by + reading, with residuals: Agda `Set` against Lean `Prop`, equality without + K, and two trusted kernels. The Kernel group is `RECONCILED`, so its four + theorems are `PWG-2i`. The census is now `PWG-2i` 4 and `ungraded` 207 of + 211. +* Open: the Rocq leg; the machine-readable receipt (§8.5.1); the next + group, `Compose`. + == 2026-11-16 — estate audit repointed after the suite rename (not a rung) * `hyperpolymath/cicd-suite` was renamed to diff --git a/docs/agda-lean-correspondence.adoc b/docs/agda-lean-correspondence.adoc new file mode 100644 index 0000000..da0792d --- /dev/null +++ b/docs/agda-lean-correspondence.adoc @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 +// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell += Agda–Lean statement correspondence +:revdate: 2026-11-16 + +The record that `hyperpolymath/standards` `3-practice/PROOF-POLICY.adoc` §2.2 +asks for, group by group. It covers each theorem whose Agda source is in +`proofs/agda` and whose Lean leg is in `Marches/`. For each pair it gives the +exact propositions, their assumptions, their type and universe discipline and +how they were compared. Revisions, checkers, invocations and results are in +`PROOF-STATUS.adoc`. A successful check in each prover does not on its own +show that both proved the same proposition. This page is that separate +argument. + +*Method.* The comparison was made by reading. Definitions were compared field +by field and theorems binder by binder, against the Lean files at the commit +named in `PROOF-STATUS.adoc`. No mechanical bridge links the two: there is no +Dedukti round trip, and the Lean leg was not transported. Lean's names are in +snake case and Agda's in kebab case, because an underscore in an Agda name +marks a mixfix argument. + +*Route of the Lean leg:* `re-proved`. The Lean development was written by hand +from 2026-07, before the Agda source existed. It was not transported from the +Agda proof. + +== Kernel group (`Basic`, `Kernel`) + +State: `RECONCILED`, 2026-11-16, with the residual assumptions listed below. + +=== Definitions + +[cols="2,2,3",options="header"] +|=== +|Agda (`proofs/agda/Marches/`) |Lean (`Marches/`) |Comparison + +|`Basic.PathAlgebra : Set₁`, a record with fields `Carrier Label : Set`, +`better : Carrier → Carrier → Set`, `ext : Label → Carrier → Carrier`, +`trans : ∀ {a b c} → better a b → better b c → better a c`, +`irrefl : ∀ a → ¬ better a a` +|`Basic.PathAlgebra`, a structure with fields `Carrier Label : Type`, +`better : Carrier → Carrier → Prop`, `ext`, `trans`, `irrefl` of the same +shapes +|Same fields in the same order, with the same arities and the same +implicit and explicit binders. Carriers sit at the lowest universe in both +(`Set` = `Set₀`, `Type` = `Type 0`), so the record is in `Set₁` and the +structure in `Type 1`. *Difference:* `better` is `Set`-valued in Agda and +`Prop`-valued in Lean (residual R1). + +|`Basic.StrictlyInflationary A` +|`Marches.StrictlyInflationary A` +|Both are `∀ l a, better A a (ext A l a)`. + +|`Basic.Inflationary A` +|`Marches.Inflationary A` +|Both are `∀ l a, ¬ better A (ext A l a) a`. + +|`Basic.run A` +|`Marches.run A` +|The same two equations: `run A [] a = a` and +`run A (l ∷ ls) a = run A ls (ext A l a)`. The word is read left to right. +Agda uses `Agda.Builtin.List` and Lean uses core `List`. + +|`Prelude.¬_`, `Prelude.⊥` +|`Not`, `False` +|`¬ P = P → ⊥`, where `⊥` is a data type with no constructors. Lean's +`¬ P` is `P → False`. They are the same. + +|`Prelude._⊎_` +|`Or` +|A sum with two injections. In Agda it is a type, so it is proof-relevant; +Lean's `Or` is a `Prop`. Only `run-le` uses it (residual R1). + +|`_≡_` (`Agda.Builtin.Equality`) +|`Eq` +|The identity type. Agda uses it without K (§2.1) and these proofs use +only `subst` and `sym`, which J gives. Lean's `Eq` is a `Prop` +(residual R2). +|=== + +=== Theorems + +[cols="2,2,3",options="header"] +|=== +|Agda |Lean |Proposition (both), in the binder order of both + +|`Basic.strict-implies-inflationary` +|`Marches.strict_implies_inflationary` +|`∀ (A : PathAlgebra), StrictlyInflationary A → Inflationary A` + +|`Kernel.run-le` +|`Marches.run_le` +|`∀ A, StrictlyInflationary A → ∀ ls a, +better A a (run A ls a) ∨ run A ls a = a` + +|`Kernel.run-worsens` +|`Marches.run_worsens` +|`∀ A, StrictlyInflationary A → ∀ l ls a, better A a (run A (l :: ls) a)` + +|`Kernel.no-return` +|`Marches.no_return` +|`∀ A, StrictlyInflationary A → ∀ l ls a, ¬ (run A (l :: ls) a = a)`. Lean +writes `≠`, which unfolds to `a = b → False`. +|=== + +The hypotheses are the same in both: one path algebra and its strictness. +Neither side adds an assumption, a typeclass or a section variable. Lean +reports no axioms for any of the four theorems (`#print axioms`), and the Agda +gate finds no postulate in the import cone outside the prover's own level +primitives. + +=== Residual assumptions + +R1. *Propositions as types.* Agda's `better` and `_⊎_` are `Set`-valued and +proof-relevant. Lean's are `Prop`-valued and proof-irrelevant. A Lean path +algebra gives an Agda one when each proposition is read as a type, and read +at that algebra each Agda statement is the Lean statement. So the Agda +statements quantify over at least the Lean algebras. No statement here +compares two proofs of `better`, or quantifies over `Prop`, so the +difference cannot change the truth of a statement. This is an argument made +by reading. It is not a checked bridge. + +R2. *Equality.* Lean's `Eq` has proof irrelevance by definition. Agda is run +without K, so its `_≡_` does not. The statements use equality only in +`run-le` (as a disjunct) and in `no-return` (under a negation), and never +compare two equality proofs, so K is not needed to state them. The Agda +proofs use only J. Neither side needs the other's equality principles. + +R3. *Kernels.* The legs are independent kernel results: Agda 2.7.0.1 checked +the Agda source and Lean 4.35.0 checked the Lean source. Each prover's own +kernel is trusted. Agda's trusted base in this cone is `Agda.Primitive`'s +`Level`, `lzero`, `lsuc` and `_⊔_`, each bound by its `BUILTIN` pragma. + +=== Negative controls + +`tests/reject-agda/FreewheelReturns.agda` gives the free-wheeling algebra: +one signature, extension the identity, no preference. It claims `no-return` +for that algebra, and the gate requires Agda to refuse it. So the strictness +hypothesis of `no-return` is load-bearing, as falsifier F2 is on the Lean side +(`Marches/Freewheel.lean`). `tests/reject-agda/UsesK.agda` has no `OPTIONS` +pragma and proves K. Its refusal shows that the gate's own command line runs +with `--without-K`. diff --git a/proofs/agda/All.agda b/proofs/agda/All.agda new file mode 100644 index 0000000..97472de --- /dev/null +++ b/proofs/agda/All.agda @@ -0,0 +1,8 @@ +{-# OPTIONS --safe --without-K --cubical-compatible #-} +-- The graded root: every module whose theorems PROOF-STATUS.adoc grades. +-- Checked by scripts/check-agda.sh under the canonical invocation. +module All where + +import Marches.Prelude +import Marches.Basic +import Marches.Kernel diff --git a/proofs/agda/Marches/Basic.agda b/proofs/agda/Marches/Basic.agda new file mode 100644 index 0000000..bd74e3a --- /dev/null +++ b/proofs/agda/Marches/Basic.agda @@ -0,0 +1,47 @@ +{-# OPTIONS --safe --without-K --cubical-compatible #-} +{- + Marches — Basic definitions (Agda source of `Marches/Basic.lean`). + + A *path algebra*: route signatures with a strict preference order, + policy labels, and an extension action (applying an arc's policy to + a route). `better a b` reads "a is strictly preferred to b" + (min-selection convention: lower is better). + + Everything here is a definition except `strict-implies-inflationary`. + The statement comparison with the Lean file is in + `docs/agda-lean-correspondence.adoc`. +-} +module Marches.Basic where + +open import Marches.Prelude + +record PathAlgebra : Set₁ where + field + Carrier : Set + Label : Set + -- Strict preference: `better a b` means `a` strictly preferred to `b`. + better : Carrier → Carrier → Set + -- Policy extension: apply arc label `l` to route signature `a`. + ext : Label → Carrier → Carrier + trans : ∀ {a b c} → better a b → better b c → better a c + irrefl : ∀ a → ¬ better a a + +open PathAlgebra public + +-- Sobrinho-style strictness: extension strictly worsens every route +-- (in Sobrinho's notation, a ≺ l ⊕ a). +StrictlyInflationary : PathAlgebra → Set +StrictlyInflationary A = ∀ (l : Label A) (a : Carrier A) → better A a (ext A l a) + +-- Non-strict variant: extension never improves a route. +Inflationary : PathAlgebra → Set +Inflationary A = ∀ (l : Label A) (a : Carrier A) → ¬ better A (ext A l a) a + +-- Run a word of labels left to right from a starting signature. +run : (A : PathAlgebra) → List (Label A) → Carrier A → Carrier A +run A [] a = a +run A (l ∷ ls) a = run A ls (ext A l a) + +strict-implies-inflationary : (A : PathAlgebra) → + StrictlyInflationary A → Inflationary A +strict-implies-inflationary A h l a hbad = irrefl A a (trans A (h l a) hbad) diff --git a/proofs/agda/Marches/Kernel.agda b/proofs/agda/Marches/Kernel.agda new file mode 100644 index 0000000..ac72d1b --- /dev/null +++ b/proofs/agda/Marches/Kernel.agda @@ -0,0 +1,38 @@ +{-# OPTIONS --safe --without-K --cubical-compatible #-} +{- + Marches — Kernel theorem, single region (Agda source of + `Marches/Kernel.lean`). + + If a path algebra is strictly inflationary, then running any + non-empty word of labels strictly worsens the starting signature; + in particular no non-empty word can return to its start. + This is the algebraic core of loop-freedom. +-} +module Marches.Kernel where + +open import Marches.Prelude +open import Marches.Basic + +-- Helper: running any word either strictly worsens or is the identity. +run-le : (A : PathAlgebra) → StrictlyInflationary A → + ∀ (ls : List (Label A)) (a : Carrier A) → + better A a (run A ls a) ⊎ run A ls a ≡ a +run-le A h [] a = inj₂ refl +run-le A h (l ∷ ls) a with run-le A h ls (ext A l a) +... | inj₁ w = inj₁ (trans A (h l a) w) +... | inj₂ e = inj₁ (subst (better A a) (sym e) (h l a)) + +-- Kernel theorem: a non-empty word strictly worsens. +run-worsens : (A : PathAlgebra) → StrictlyInflationary A → + ∀ (l : Label A) (ls : List (Label A)) (a : Carrier A) → + better A a (run A (l ∷ ls) a) +run-worsens A h l ls a with run-le A h ls (ext A l a) +... | inj₁ w = trans A (h l a) w +... | inj₂ e = subst (better A a) (sym e) (h l a) + +-- No non-empty word returns to its start: loop-freedom. +no-return : (A : PathAlgebra) → StrictlyInflationary A → + ∀ (l : Label A) (ls : List (Label A)) (a : Carrier A) → + ¬ (run A (l ∷ ls) a ≡ a) +no-return A h l ls a he = + irrefl A a (subst (better A a) he (run-worsens A h l ls a)) diff --git a/proofs/agda/Marches/Prelude.agda b/proofs/agda/Marches/Prelude.agda new file mode 100644 index 0000000..557c014 --- /dev/null +++ b/proofs/agda/Marches/Prelude.agda @@ -0,0 +1,33 @@ +{-# OPTIONS --safe --without-K --cubical-compatible #-} +{- + Marches — the little logic the Agda development needs. + + No standard library: the import cone is this repository plus the + modules Agda ships (Agda.Primitive, Agda.Builtin.*), in step with the + Lean development, which uses core Lean and no Mathlib. Every + definition here is the textbook one. +-} +module Marches.Prelude where + +open import Agda.Builtin.Equality public using (_≡_; refl) +open import Agda.Builtin.List public using (List; []; _∷_) + +infix 3 ¬_ +infixr 1 _⊎_ + +-- The empty type, and negation as a map into it. +data ⊥ : Set where + +¬_ : Set → Set +¬ P = P → ⊥ + +-- Disjunction (Lean's `Or`). +data _⊎_ (P Q : Set) : Set where + inj₁ : P → P ⊎ Q + inj₂ : Q → P ⊎ Q + +sym : {X : Set} {x y : X} → x ≡ y → y ≡ x +sym refl = refl + +subst : {X : Set} (P : X → Set) {x y : X} → x ≡ y → P x → P y +subst P refl px = px diff --git a/scripts/check-agda.sh b/scripts/check-agda.sh new file mode 100755 index 0000000..81bf07e --- /dev/null +++ b/scripts/check-agda.sh @@ -0,0 +1,159 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +# Agda gate for proofs/agda (hyperpolymath/standards PROOF-POLICY §2.1, §8.4). +# Adapted from hyperpolymath/januskey scripts/check-agda.sh at b5034884. +# +# 1. The graded root proofs/agda/All.agda checks cold under the §2.1 +# canonical invocation, with the pinned compiler. +# 2. Its import cone, as Agda reports it, is scanned for postulates: none in +# this repository's modules; in the modules shipped with Agda, exactly +# Agda.Primitive's four level primitives, each bound by its BUILTIN. +# 3. Controls show each part can fail: the scanner finds planted postulates +# and ignores commented ones; the command line refuses a postulate in a +# file with no OPTIONS pragma; every fixture under tests/reject-agda is +# refused, for the reason its `-- expect:` line names. +# 4. The receipt fields of §8.2 are printed: checker, invocation, import cone +# and the §8.5.1 inputs manifest and digest at HEAD. +# +# Run scripts/setup-agda.sh first (or put the pinned agda on PATH). +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +export LC_ALL="${LC_ALL:-C.UTF-8}" +prover="${AGDA:-agda}" + +pin="$(sed -n 's/^AGDA_VERSION=//p' scripts/setup-agda.sh)" +version="$("$prover" --version)" +[ "$version" = "Agda version $pin" ] || { + echo "ERROR: expected Agda version $pin (scripts/setup-agda.sh), got '$version'" >&2; exit 1; } + +# §2.1 canonical flags. --no-libraries: there is no library dependency, so no +# .agda-lib or libraries file is read. --ignore-interfaces: every run is cold. +canonical=(--safe --without-K --cubical-compatible) +flags=("${canonical[@]}" --no-libraries --ignore-interfaces -i proofs/agda) +root=proofs/agda/All.agda + +work="$(mktemp -d)" +trap 'rm -rf -- "$work"' EXIT + +"$prover" "${flags[@]}" --dependency-graph="$work/cone.dot" "$root" + +# PROOF-POLICY §8.4: the import cone is the module set Agda reports for the +# root, prover-supplied modules included. Each module is resolved to a source +# file; an unresolved one fails. +agda_prim="$("$prover" --print-agda-dir)/lib/prim" +own=(); prover_lib=(); cone=() +while IFS= read -r name; do + cone+=("$name") + if [ -f "proofs/agda/${name//.//}.agda" ]; then own+=("proofs/agda/${name//.//}.agda") + elif [ -f "$agda_prim/${name//.//}.agda" ]; then prover_lib+=("$agda_prim/${name//.//}.agda") + else echo "ERROR: cannot resolve module $name of the import cone to a source file" >&2; exit 1 + fi +done < <(sed -n 's/.*label="\([^"]*\)".*/\1/p' "$work/cone.dot" | LC_ALL=C sort -u) +[ "${#own[@]}" -gt 0 ] || { echo "ERROR: Agda reported no first-party module in the import cone" >&2; exit 1; } +echo "import cone: ${#own[@]} first-party modules, ${#prover_lib[@]} supplied with the prover" + +# This repository's modules: no postulate at all. +bash scripts/scan-postulates.sh "${own[@]}" + +# Modules supplied with the prover are its trusted base. The only postulates +# allowed there are Agda.Primitive's level primitives: exactly Level, lzero, +# lsuc and _⊔_, each bound by its BUILTIN pragma. The names and bindings are +# checked, not the file name, so a prover pin that adds a postulate fails here. +prim="$agda_prim/Agda/Primitive.agda" +status=0; bash scripts/scan-postulates.sh "${prover_lib[@]}" >"$work/prover.log" 2>&1 || status=$? +[ "$status" -le 1 ] || { cat "$work/prover.log"; exit 1; } +grep -E '^[^ ]+:[0-9]+: ' "$work/prover.log" >"$work/prover.hits" || true +if grep -vqE -- "^$prim:[0-9]+: postulate[[:space:]]*\$" "$work/prover.hits"; then + cat "$work/prover.log"; echo "ERROR: a prover-supplied postulate outside the Agda.Primitive level blocks" >&2; exit 1 +fi +declared="$(LC_ALL=C awk ' + { sub(/--.*/, "") } + /^postulate[ \t]*$/ { inblock = 1; next } + inblock && /^[ \t]*$/ { next } + inblock && /^[ \t]/ { split($0, lhs, ":"); n = split(lhs[1], names, /[ \t]+/) + for (k = 1; k <= n; k++) if (names[k] != "") print names[k]; next } + { inblock = 0 } +' "$prim" | LC_ALL=C sort | tr '\n' ' ')" +expected="Level _⊔_ lsuc lzero " +[ "$declared" = "$expected" ] || { + echo "ERROR: Agda.Primitive postulates '$declared', expected exactly '$expected'" >&2; exit 1; } +for binding in "LEVEL Level" "LEVELZERO lzero" "LEVELSUC lsuc" "LEVELMAX _⊔_"; do + LC_ALL=C grep -qE -- "^\{-#[[:space:]]+BUILTIN[[:space:]]+${binding% *}[[:space:]]+${binding#* }[[:space:]]+#-\}" "$prim" || { + echo "ERROR: Agda.Primitive does not bind ${binding#* } with BUILTIN ${binding% *}" >&2; exit 1; } +done +echo "prover-supplied: Agda.Primitive postulates exactly ${expected% }, each bound by its BUILTIN pragma; no other postulate" + +# Scanner controls, written at run time so no file in the tree carries a real +# postulate for another scanner to count (as in januskey). +printf '%s\n' 'module CommentsOnly where' '-- postulate in a line comment' \ + '--postulate postulate: no space after the dashes' \ + '{- postulate {- nested postulate -} postulate -}' \ + 'x--postulate : Set₁' 'x--postulate = Set' \ + 's : String' 's = "a postulate in a string \" still the string"' \ + '{-# FOREIGN GHC postulate = () #-}' "c = 'x'-- postulate after a character literal" \ + > "$work/CommentsOnly.agda" +printf '%s\n' 'module Planted where' '{- c -} postulate X : Set' \ + $'\302\240postulate\302\240Y : Set' 'postulate{- c -}Z : Set' \ + '{-# FOREIGN GHC {- {- #-} postulate W : Set' > "$work/Planted.agda" +status=0; bash scripts/scan-postulates.sh "$work/CommentsOnly.agda" >"$work/neg.log" 2>&1 || status=$? +[ "$status" -eq 0 ] || { cat "$work/neg.log"; echo "ERROR: the comments-only control did not exit 0 (got $status)" >&2; exit 1; } +status=0; bash scripts/scan-postulates.sh "$work/Planted.agda" >"$work/pos.log" 2>&1 || status=$? +missed="" +for line in 2 3 4 5; do grep -qF -- "Planted.agda:$line:" "$work/pos.log" || missed="$missed $line"; done +if [ "$status" -ne 1 ] || [ -n "$missed" ]; then + cat "$work/pos.log"; echo "ERROR: the planted control did not exit 1 naming lines 2-5 (got $status; missed:${missed:- none})" >&2; exit 1 +fi +echo "[PASS] postulate scan: cone clean, both controls behave" + +# --safe on the command line: a postulate in a file with no OPTIONS pragma. +printf '%s\n' 'module SafeFlag where' 'postulate X : Set' > "$work/SafeFlag.agda" +if "$prover" "${flags[@]}" -i "$work" "$work/SafeFlag.agda" >"$work/safe.log" 2>&1 \ + || ! grep -qF 'Cannot postulate X with safe flag' "$work/safe.log"; then + cat "$work/safe.log"; echo "ERROR: the command line did not refuse a postulate under --safe" >&2; exit 1 +fi +echo "[PASS] refused as expected: a postulate, by the command-line --safe" + +# Fixtures: each must be refused for the reason its `-- expect:` line names. +# One refused for another reason (a broken import, a parse error) has stopped +# testing its claim, so it fails the gate too. +shopt -s nullglob +rejects=(tests/reject-agda/*.agda) +shopt -u nullglob +[ "${#rejects[@]}" -gt 0 ] || { echo "ERROR: no fixtures under tests/reject-agda" >&2; exit 1; } +for file in "${rejects[@]}"; do + want="$(sed -n 's/^-- expect: //p' "$file" | head -1)" + [ -n "$want" ] || { echo "ERROR: $file has no '-- expect: ' line" >&2; exit 1; } + log="$work/$(basename -- "$file" .agda).log" + if "$prover" "${flags[@]}" -i tests/reject-agda "$file" >"$log" 2>&1; then + cat "$log"; echo "ERROR: $file was accepted but must be refused" >&2; exit 1 + fi + # Agda wraps its messages at the terminal width: compare with line breaks + # and runs of spaces folded to one space. + tr -s ' \n' ' ' <"$log" | grep -qF -- "$want" || { cat "$log"; echo "ERROR: $file was refused, but not with '$want'" >&2; exit 1; } + echo "[PASS] refused as expected: $file ($want)" +done + +# Receipt fields (PROOF-POLICY §8.2, §8.5.1). The input set is the +# first-party modules of the cone; no .agda-lib or libraries file is read. +# The manifest is taken from the git blobs at HEAD, so it describes a commit. +commit="$(git rev-parse HEAD)" +clean=1; manifest="" +while IFS= read -r f; do + # A file not committed, or changed since, has no blob at HEAD to digest. + if ! git cat-file -e "HEAD:$f" 2>/dev/null || ! git diff --quiet HEAD -- "$f"; then clean=0; break; fi + manifest+="$(git cat-file blob "HEAD:$f" | sha256sum | cut -d" " -f1) $f"$'\n' +done < <(printf '%s\n' "${own[@]}" | LC_ALL=C sort) +echo "--- receipt ---" +echo "checker: $version" +echo "invocation: agda ${flags[*]} $root" +echo "import cone: ${cone[*]}" +echo "commit: $commit" +if [ "$clean" -eq 1 ]; then + echo "inputs-manifest:"; printf '%s' "$manifest" | sed 's/^/ /' + echo "inputs-sha256: $(printf '%s' "$manifest" | sha256sum | cut -d" " -f1)" +else + echo "inputs-sha256: none (the working tree differs from HEAD in the input set)" +fi +echo "axioms: none (no postulate outside the prover's trusted base)" +echo "[check-agda] OK" diff --git a/scripts/scan-postulates.sh b/scripts/scan-postulates.sh new file mode 100755 index 0000000..7586514 --- /dev/null +++ b/scripts/scan-postulates.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +# Ported verbatim from hyperpolymath/januskey scripts/scan-postulates.sh at +# b5034884dbe945139d03b38fe80cfdf1106a77e1, the reference implementation that +# PROOF-POLICY §8.4 names. Fix it there first, then re-port. +# Comment-aware postulate scan of Agda source files (PROOF-POLICY §8.4, +# "Axioms travel with the grade"): --safe already refuses `postulate`, and this +# scan is the second of the three parts that make the absence of axioms visible +# on a receipt. check-agda.sh passes it the exact import cone that Agda itself +# reports, so the files scanned are the files checked. +# +# Lexing follows Agda closely enough for one keyword: text inside nested +# {- -} comments, after a `--` that starts a token (with or without a space +# after it), and inside string or character literals is ignored. A `--` inside +# a name such as `x--y` is part of the name. A comment separates tokens, as it +# does for Agda, so `postulate{- c -}X` is a postulate. +# A pragma ({-# … #-}) is skipped to the first `#-}`: its contents are pragma +# tokens or, for FOREIGN and COMPILE, another language's text, never an Agda +# declaration, and Agda does not nest comments inside it (Lexer.x). Agda closes +# a pragma at a `#-}` token, never before the first `#-}` in the text, so this +# rule can end a pragma early (an extra report) but never late (a missed one). +# Whitespace is Agda's: its lexer reads every character Haskell's isSpace accepts, +# other than tab and newline, as a space (Agda.Syntax.Parser.Alex, toASCII), so +# CR, FF, VT, NO-BREAK SPACE and the Unicode space separators (category Zs) are +# turned into spaces before the line is lexed. +# +# Usage: scan-postulates.sh FILE... Prints each hit as path:line: text and the +# count; exits 1 if there is any hit, 2 on a usage error or an unreadable file. +set -euo pipefail +[ "$#" -gt 0 ] || { echo "usage: $0 FILE..." >&2; exit 2; } +for f in "$@"; do + [[ -f $f && -r $f ]] || { echo "ERROR: not a readable file: $f" >&2; exit 2; } +done +# The non-ASCII spaces as UTF-8 byte sequences: U+00A0, U+1680, U+2000-U+200A, +# U+202F, U+205F, U+3000. awk runs in the C locale, so it matches bytes the same +# way whichever awk is installed. +ws="$(printf '\302\240|\341\232\200|\342\200[\200-\212]|\342\200\257|\342\201\237|\343\200\200')" +hits="$(LC_ALL=C awk -v ws="$ws" ' + # Agda name characters are everything except whitespace and .;{}()@" + function namechar(c) { return c != "" && c !~ /[ \t.;{}()@"]/ } + FNR == 1 { depth = 0; pragma = 0 } + { + line = $0; gsub(/[\r\f\v]/, " ", line); gsub(ws, " ", line) + code = ""; i = 1; n = length(line) + while (i <= n) { + c = substr(line, i, 1); two = substr(line, i, 2) + # The last character emitted as code, not the raw one before i: a skipped + # literal, comment or pragma leaves a space, so a token may start after it. + prev = (code == "") ? "" : substr(code, length(code), 1) + if (pragma) { # inside {-# … #-}: skip to the first #-} + if (substr(line, i, 3) == "#-}") { pragma = 0; i += 3; code = code " " } else i++ + continue + } + if (depth == 0 && two == "{-" && substr(line, i + 2, 1) == "#") { + pragma = 1; i += 3; code = code " "; continue + } + if (two == "{-") { if (depth == 0) code = code " "; depth++; i += 2; continue } + if (depth > 0 && two == "-}") { depth--; i += 2; continue } + if (depth > 0) { i++; continue } + if (c == "\"") { # string literal: skip to the closing quote + i++ + while (i <= n && substr(line, i, 1) != "\"") i += (substr(line, i, 1) == "\\") ? 2 : 1 + i++; code = code " "; continue + } + if (c == "'\''" && !namechar(prev)) { # character literal at a token start + i++ + while (i <= n && substr(line, i, 1) != "'\''") i += (substr(line, i, 1) == "\\") ? 2 : 1 + i++; code = code " "; continue + } + if (two == "--" && !namechar(prev)) break + code = code c; i++ + } + if (code ~ /(^|[ \t.;{}()@])postulate([ \t.;{}()@]|$)/) + printf "%s:%d: %s\n", FILENAME, FNR, $0 + } +' "$@")" +count=0 +[ -n "$hits" ] && count="$(printf '%s\n' "$hits" | wc -l | tr -d ' ')" +[ -n "$hits" ] && printf '%s\n' "$hits" +echo "postulate scan: $# files, $count postulate(s)" +[ "$count" -eq 0 ] || exit 1 diff --git a/scripts/setup-agda.sh b/scripts/setup-agda.sh new file mode 100755 index 0000000..f6710e3 --- /dev/null +++ b/scripts/setup-agda.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +# Linux x86-64 Agda toolchain for scripts/check-agda.sh. The release archive +# is accepted only at the checked-in checksum, and a version mismatch fails +# before any proof is checked. Pinned as in hyperpolymath/echo-types +# scripts/setup-agda.sh (5549185), the estate's checksum-pinned Agda 2.7.0.1. +# marches needs no Agda library: no standard library is fetched. +# +# CI: RUNNER_TEMP is set and the toolchain is put on PATH for later steps. +# Locally: AGDA_TOOLS_DIR= bash scripts/setup-agda.sh, then +# source /env.sh. AGDA_ARCHIVE_PATH reuses an archive already fetched. +set -euo pipefail + +AGDA_VERSION=2.7.0.1 +AGDA_SHA256=975b515a14877ab6bce5bfc641e16c4a3ee52ca5d7f846577dee80aa2145db8a + +test "$(uname -s)-$(uname -m)" = Linux-x86_64 +tool_dir="${AGDA_TOOLS_DIR:-${RUNNER_TEMP:?RUNNER_TEMP or AGDA_TOOLS_DIR is required}/marches-agda}" +mkdir -p "$tool_dir" +tool_dir="$(cd "$tool_dir" && pwd)" +archive="${AGDA_ARCHIVE_PATH:-$tool_dir/Agda-v$AGDA_VERSION-linux.tar.xz}" +if [ ! -f "$archive" ]; then + curl --fail --location --retry 3 --proto '=https' --tlsv1.2 \ + --output "$archive" \ + "https://github.com/agda/agda/releases/download/v$AGDA_VERSION/Agda-v$AGDA_VERSION-linux.tar.xz" +fi +printf '%s %s\n' "$AGDA_SHA256" "$archive" | sha256sum --check --strict - +tar -xf "$archive" -C "$tool_dir" +agda_root="$tool_dir/Agda-v$AGDA_VERSION" +export Agda_datadir="$agda_root/data" +actual_version="$("$agda_root/bin/agda" --version)" +if [ "$actual_version" != "Agda version $AGDA_VERSION" ]; then + printf 'Compiler mismatch: expected Agda version %s, got %s\n' "$AGDA_VERSION" "$actual_version" >&2 + exit 1 +fi + +{ + printf 'export AGDA=%q\n' "$agda_root/bin/agda" + printf 'export Agda_datadir=%q\n' "$Agda_datadir" + printf 'export PATH=%q:"$PATH"\n' "$agda_root/bin" +} > "$tool_dir/env.sh" +if [ -n "${GITHUB_PATH:-}" ]; then + printf '%s\n' "$agda_root/bin" >> "$GITHUB_PATH" +fi +if [ -n "${GITHUB_ENV:-}" ]; then + printf 'AGDA=%s\nAgda_datadir=%s\n' "$agda_root/bin/agda" "$Agda_datadir" >> "$GITHUB_ENV" +fi +printf '%s\ncompiler-sha256=%s\n' "$actual_version" "$AGDA_SHA256" diff --git a/tests/reject-agda/FreewheelReturns.agda b/tests/reject-agda/FreewheelReturns.agda new file mode 100644 index 0000000..73e3f3a --- /dev/null +++ b/tests/reject-agda/FreewheelReturns.agda @@ -0,0 +1,23 @@ +{-# OPTIONS --safe --without-K --cubical-compatible #-} +-- Expected rejection: loop-freedom does not hold without strictness. +-- The free-wheeling algebra (one signature, one label, extension the +-- identity, no preference) is not strictly inflationary, and the one-label +-- word returns to its start. Claiming `no-return` for it must be refused; +-- this fixture shows the hypothesis of `Marches.Kernel.no-return` is +-- load-bearing (falsifier F2, `Marches/Freewheel.lean` on the Lean side). +-- expect: should be empty +module FreewheelReturns where + +open import Marches.Prelude +open import Marches.Basic + +data ⊤ : Set where + tt : ⊤ + +freewheel : PathAlgebra +freewheel = record + { Carrier = ⊤ ; Label = ⊤ ; better = λ _ _ → ⊥ ; ext = λ _ a → a + ; trans = λ b _ → b ; irrefl = λ _ b → b } + +returns-anyway : ¬ (run freewheel (tt ∷ []) tt ≡ tt) +returns-anyway () diff --git a/tests/reject-agda/UsesK.agda b/tests/reject-agda/UsesK.agda new file mode 100644 index 0000000..aa91f71 --- /dev/null +++ b/tests/reject-agda/UsesK.agda @@ -0,0 +1,11 @@ +-- Expected rejection: axiom K (every self-equality is refl) is not +-- provable without K. This file deliberately has no OPTIONS pragma, so the +-- refusal comes from the gate's own command line: it shows that +-- scripts/check-agda.sh runs with --without-K in force. +-- expect: because K has been disabled +module UsesK where + +open import Marches.Prelude + +K : {X : Set} {x : X} (p : x ≡ x) → p ≡ refl +K refl = refl