Skip to content

proofs(lean4): promote ET-2 to main — L1 conversion is decidable - #27

Merged
hyperpolymath merged 8 commits into
mainfrom
proofs/lean4-l1-l2
Jul 27, 2026
Merged

proofs(lean4): promote ET-2 to main — L1 conversion is decidable#27
hyperpolymath merged 8 commits into
mainfrom
proofs/lean4-l1-l2

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Promotes the ET-2 closure (decidability of L1 conversion) onto main.

Why this PR exists

ET-2 was proven and merged in PR #24 — but into proofs/lean4-l1-l2, not main. PR #17 had squash-merged that branch to main before ET-2 existed, so main holds the L1/L2 mechanization content while the ET-2 work sits only on the branch. No second PR to main was ever opened.

Measured before this PR: main...proofs/lean4-l1-l2 was diverged, 4 ahead / 14 behind, and all four ET-2 proof files returned 404 on main. Anything reading main today correctly concludes ET-2 is still open.

What lands on main

File Contents
Systemet/L1/SubstLemmas.lean substitution/weakening exchange family, incl. nf_substTy — normalization commutes with hereditary substitution (the whole content of the β case)
Systemet/L1/Soundness.lean soundness : DefEq t (embNf (nf t))
Systemet/L1/Completeness.lean completeness : DefEq t u → nf t = nf u; defEq_iff_nf : DefEq t u ↔ nf t = nf u
Systemet/L1/Decidable.lean decEqNf / decEqSp (hand-rolled mutual DecidableEqderiving does not work across the Nf/Sp pair); decDefEq : (t u : Ty Γ k) → Decidable (DefEq t u)

Plus the PROOF-STATUS.adoc truth pass (gated 11 → 15, ET-2 row proven, MECH-1 row landed, the satisfied ET-2 (finish) OPEN row removed) and append-only MANIFEST / Systemet.lean / Audit.lean entries.

Conflict resolution — read this bit

The pre-PR sync merge (0104c9c) hit five conflicts. Four were add/add artefacts of the squash in #17, which makes git treat both sides as independent additions. None were resolved by a blanket --ours/--theirs:

  • MANIFEST, Systemet.lean, Audit.lean — verified main's content is byte-identical to the branch's and the branch is a strict superset (adds exactly the four ET-2 entries). Branch side taken.
  • PROOF-STATUS.adoc — every difference is this branch's ET-2 update; main carried no independent edits. Branch side taken.
  • .github/workflows/proofs.yml — a genuine two-sided merge. The sides differed in opposite directions: main had the newer actions/checkout@3d3c42e (v7.0.1, from dependabot chore(deps): bump the actions group with 6 updates #26) while the branch had curl --proto '=https' --tlsv1.2 (the Sonar S6506 fix). Took main's newer pin and re-applied the branch's https hardening, so neither is regressed. Both confirmed present post-resolution.

Evidence (measured on the merged tree, not inherited from #24)

  • Cold rebuild after rm -rf .lake/buildBuild completed successfully (16 jobs)
  • scripts/check-proofs.sh lean4PASS (real exit 0); audit reports 20/20 headline items within the trusted base
  • scripts/scan-dangerous.shPASS (real exit 0)
  • scripts/check-proof-status.shPASS (real exit 0) — 15 gated, document agrees
  • Forbidden-token scan on the four new proof files → clean
  • #print axioms on soundness, completeness, defEq_iff_nf, decDefEq, decEqNf, decEqSp, nf_substTy[propext, Quot.sound] only; no sorryAx, no user axioms, not even Classical.choice

Real exit codes were checked directly — piping a gate through tail and reading $? reports tail's status, which is how a red gate can look green.

Scope — what this does not claim

DefEq here is β + equivalence + congruence. η is not included and remains an OPEN row. ET-3 is unaffected — its η and model directions stay open. PROOF-STATUS.adoc marks ET-2 proven for the L1 core calculus, under the core-vs-full-theory caveat that file already carries.

ET-14 (TEA erasure) is untouched and remains the headline open problem, gated on the owner's ET-16 / L0-lowering ADR.

Merge notes

Per the base ruleset, squash is the only merge that works here (rebase merges cannot be signed by GitHub bots), and the phantom required Dependabot context means this will need --admin. Not merged by me — that call is yours.

🤖 Generated with Claude Code

hyperpolymath and others added 8 commits July 21, 2026 13:49
…ade algebras, hard gates

MECH-2 (complete): GradeAlgebra as the ET-4 ordered-semiring law set
(16 laws as proof fields) with instances Affine {0,1,w}, tropical Cost
(min/+), the generic bounded-distributive-lattice theorem instantiated
at Level (Low<=High), and the componentwise product R x S (ET-5:
composite disciplines are composition of algebras, proven once).

MECH-1 (totality core + stability): intrinsically-kinded type-level
STLC with the Keller-Altenkirch rem/wkv/eqv toolkit; beta-normal forms
with LEFT-NESTED spines (append is cons, the spine fold is structural);
hereditary substitution + normalizer total by a (kindSize, tag, size)
lexicographic measure — the Totality Gate (ET-1) discharged by
construction. DefEq stated; stability nf_emb : nf (embNf n) = n proven.
Soundness/completeness (defEq_iff_nf, decDefEq) recorded OPEN in
PROOF-STATUS — stated, never stubbed.

Gates (wire-first, watched to fail before trusted):
- scripts/check-proofs.sh: MANIFEST-driven; absent prover = FAIL;
  per-module lake build; whole-package build; mandatory axiom audit
  pinned to Lean's three-axiom trusted base (a smuggled user axiom
  fails the gate even though it compiles green).
- scripts/scan-dangerous.sh: comment-aware scan incl. axiom/admit/
  native_decide; FIXED Lean block-comment stripping ({- -} -> /- -/).
- scripts/check-proof-status.sh: drift gate — PROOF-STATUS.adoc must
  match MANIFEST ground truth or CI fails.
- .github/workflows/proofs.yml: sha-pinned actions, elan 4.2.3 from a
  checksum-verified release tarball, toolchain from lean-toolchain,
  cache keyed on the toolchain pin. No floating setup actions.

All 11 modules gated; audit 12/12 within the trusted base; zero sorry,
zero user axioms. Verified failure modes: broken proof, smuggled axiom,
absent prover, unlisted file, status drift.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…S6506)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Completes the MECH-1 milestone that Conversion.lean recorded as open.
Purely additive: four new modules under Systemet/L1/, plus append-only
entries in Systemet.lean, MANIFEST and Audit.lean. Syntax/Normal/Hsub/
Conversion.lean are untouched.

Landed (all statements verbatim from the ET-2 ledger entry):
  SubstLemmas.lean  substitution/weakening exchange family, incl.
                    nf_substTy — normalization commutes with hereditary
                    substitution (the beta case's whole content)
  Soundness.lean    soundness : DefEq t (embNf (nf t))
  Completeness.lean completeness : DefEq t u -> nf t = nf u
                    defEq_iff_nf : DefEq t u <-> nf t = nf u
  Decidable.lean    decEqNf / decEqSp (hand-rolled mutual DecidableEq --
                    `deriving` does not work across the Nf/Sp pair)
                    decDefEq : (t u : Ty G k) -> Decidable (DefEq t u)

Method: exchange coordinates (swp/remSwap) with an Eq.rec cast toolkit
whose push lemmas are all `by subst h; rfl`, so definitional proof
irrelevance makes diagonal casts vanish. The subst/subst exchange needs a
SUM measure (kindSize k + kindSize b, tag, size) because the miss-then-hit
case folds appSp at the second kind.

Evidence (measured, not asserted):
  clean rebuild from scratch  Build completed successfully (16 jobs)
  scripts/check-proofs.sh     PASS, 20/20 headline items in trusted base
  scripts/scan-dangerous.sh   PASS
  scripts/check-proof-status  PASS after the doc update below
  #print axioms on soundness, completeness, defEq_iff_nf, decDefEq,
  decEqNf, decEqSp, nf_substTy -> [propext, Quot.sound] only; no
  sorryAx, no user axioms, no Classical.choice.

Scope, stated honestly: DefEq here is beta + equivalence + congruence.
eta is NOT included and remains an OPEN row, so ET-3 is unaffected --
its eta and model directions stay open. PROOF-STATUS.adoc moves ET-2 to
proven *for the L1 core calculus* under the file's existing core-vs-full-
theory caveat, and the now-satisfied "ET-2 (finish)" OPEN row is removed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Closes obligation **ET-2** (decidability of L1 conversion) for the
mechanized core calculus. This was the upstream blocker sitting under
ET-14 / Phase 6.

## Stacking and provenance

- **Base is `proofs/lean4-l1-l2`, not `main`.** That branch is pushed
but has no PR of its own; this stacks on it so the mechanization lands
as one reviewable lineage. Retarget to `main` if `proofs/lean4-l1-l2`
merges first.
- Produced by a parallel proof campaign (four independent max-effort
attempts, `lake build` as the judge). Two attempts reached full closure;
this is the stronger one (38 theorems, faithful Keller–Altenkirch
decomposition). Attempt artefacts were written to a scratch directory
and applied here by hand — the campaign's own verify and
adversarial-review stages were cut short by a monthly spend limit, so
**every check below was re-run manually rather than taken on an agent's
word.**

## What landed

Purely additive — `Syntax/Normal/Hsub/Conversion.lean` are
byte-identical; the only edits to existing files are append-only
registry entries (18 insertions, 0 deletions).

| File | Contents |
|---|---|
| `Systemet/L1/SubstLemmas.lean` | substitution/weakening exchange
family, incl. `nf_substTy` — normalization commutes with hereditary
substitution (the whole content of the beta case) |
| `Systemet/L1/Soundness.lean` | `soundness : DefEq t (embNf (nf t))` |
| `Systemet/L1/Completeness.lean` | `completeness : DefEq t u → nf t =
nf u`; `defEq_iff_nf : DefEq t u ↔ nf t = nf u` |
| `Systemet/L1/Decidable.lean` | `decEqNf` / `decEqSp` (hand-rolled
mutual `DecidableEq` — `deriving` does not work across the `Nf`/`Sp`
pair); `decDefEq : (t u : Ty Γ k) → Decidable (DefEq t u)` |

File layout matches the slots the ET-2 ledger entry already named.

## Evidence (measured)

- Clean rebuild after `rm -rf .lake/build`: **Build completed
successfully (16 jobs)**
- `scripts/check-proofs.sh lean4` — **PASS**, audit reports 20/20
headline items within the trusted base
- `scripts/scan-dangerous.sh` — **PASS**
- `scripts/check-proof-status.sh` — **PASS** (exit 0) after the
`PROOF-STATUS.adoc` update
- `#print axioms` on `soundness`, `completeness`, `defEq_iff_nf`,
`decDefEq`, `decEqNf`, `decEqSp`, `nf_substTy` → `[propext, Quot.sound]`
only. No `sorryAx`, no user axioms, and not even `Classical.choice`.
- Checked for a shadowed `DefEq`/`nf`: none — the new theorems quantify
over the originals from `Conversion.lean`, with general `Γ` and `k` and
no added hypotheses.

## Scope — what this does *not* claim

`DefEq` here is **β + equivalence + congruence. η is not included**, and
remains an OPEN row. **ET-3 is unaffected** — its η and model directions
stay open. `PROOF-STATUS.adoc` marks ET-2 proven *for the L1 core
calculus*, under the caveat that file already carries about
core-vs-full-theory claims, and drops the now-satisfied "ET-2 (finish)"
OPEN row.

**ET-14 (TEA erasure) is untouched and remains the headline open
problem.** The campaign's TEA design track produced nothing — all three
panelists and the judge died on the spend limit — so the ET-16 / L0
lowering ADR is still owner-gated and unstarted.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Brings the branch up to date with main (was 14 behind) so the ET-2 proof can
be promoted to main with a green check roster.

Five conflicts, all resolved by inspection rather than a blanket --ours/--theirs.
Four were add/add artefacts of main having received a SQUASHED copy of this
branch via PR #17, which makes git see both sides as independent additions:

  MANIFEST, Systemet.lean, Systemet/Audit.lean
    Verified main's content is byte-identical to the branch's and the branch
    is a strict superset (adds exactly the four ET-2 entries/imports/audit
    lines). Took the branch side.

  docs/status/PROOF-STATUS.adoc
    Every difference is this branch's ET-2 update (gated 11 -> 15, ET-2 row
    proven, MECH-1 row landed, stale "ET-2 (finish)" OPEN row dropped); main
    carried no independent edits. Took the branch side.

  .github/workflows/proofs.yml
    Genuine two-sided merge -- the two sides differ in OPPOSITE directions:
      main   has actions/checkout@3d3c42e (v7.0.1, from dependabot #26)
      branch has curl --proto '=https' --tlsv1.2 (Sonar S6506 fix, 1f2a81a)
    Took main's newer pin and re-applied the branch's https hardening on top,
    so neither is regressed. Both verified present after resolution.

Verified on the merged tree (measured, not assumed):
  cold rebuild (rm -rf .lake/build)  Build completed successfully (16 jobs)
  scripts/check-proofs.sh lean4      PASS, real exit 0
                                     audit 20/20 in the trusted base
  scripts/scan-dangerous.sh          PASS, real exit 0
  scripts/check-proof-status.sh      PASS, real exit 0 (15 gated, doc agrees)
  forbidden-token scan on the four new proof files: clean

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The proof gate was failing before it ever reached a proof:

  $ elan toolchain install "$(cat .../lean-toolchain)"
  error: 'leanprover/lean4:v4.32.0' is already installed
  Process completed with exit code 1

`elan toolchain install` exits 1 when the toolchain is already present, and
the runner image now ships the pinned toolchain -- so the gate went red for a
reason with nothing to do with the proofs. This is pre-existing on this branch,
not introduced by the merge, but it gates the very content this branch is
promoting, so fix it here.

Install only when absent, so a GENUINE install failure still fails the gate --
deliberately not `|| true`, which would mask one. Matching is on the first
whitespace field of `elan toolchain list` so an annotated listing (e.g. a
trailing "(default)" from a different elan version) still matches; verified
against real `elan toolchain list` output locally. Also echoes the resulting
toolchain list, so a future mismatch is visible in the log rather than silent.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Two pre-existing red checks, fixed at the cause rather than silenced.

1) Guix Package Policy -- "Nix is banned estate-wide (Guix only). Remove
   flake.nix/*.nix and use guix.scm: ./flake.nix"

   flake.nix was shipped here by the 2026-07-21 estate sweep, which ran
   contrary to the 2026-05-18 ruling (Guix primary, no Nix mirror). This repo
   has no Nix-dependent tooling and nothing referenced the file -- verified no
   remaining references in Justfile, .envrc or README.adoc. Deleting it is the
   ruling applied, not a workaround. It was the only *.nix file in the repo.

2) governance / Trusted-base reduction policy -- FALSE POSITIVE, now cleared

   standards/scripts/check-trusted-base.sh reported:
     [INFO] Found 1 soundness-relevant escape hatch(es).
     [ERROR] No docs/proof-debt.md ... but 1 escape hatches exist.

   The "escape hatch" was PROSE IN A DOCSTRING -- Audit.lean:10, the sentence
   documenting that the gate catches smuggled axioms and sorries. There is no
   escape hatch: the axiom audit reports [propext, Quot.sound] for all 20
   headline items, and scan-dangerous.sh passes.

   Deliberately NOT "fixed" by adding docs/proof-debt.md -- declaring proof debt
   that does not exist would be a lie in the one file the estate most needs to
   trust. Instead the docstring now says `sorryAx` (the actual axiom a `sorry`
   elaborates to) rather than a bare `sorry`, which is strictly more precise AND
   does not trip a line-grep. Confirmed locally: the script now reports
   "[OK] No soundness-relevant escape hatches detected."

   UPSTREAM DEFECT, still open: check-trusted-base.sh strips only "string
   literals" before matching, so it cannot see Lean block comments (`/-! -/`).
   Any repo documenting its own sorry/axiom policy in a docstring trips it.
   This is the same comment-awareness bug scan-dangerous.sh already had fixed
   for Lean. Worth fixing once in standards rather than reworded per repo.

Re-verified after both edits (Audit.lean is compiled by the gate):
  cold rebuild                  Build completed successfully (16 jobs)
  check-proofs.sh lean4         real exit 0 (audit 20/20 trusted base)
  scan-dangerous.sh             real exit 0
  check-proof-status.sh         real exit 0
  check-trusted-base.sh         [OK] no escape hatches

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Removes `scripts/check-no-vlang.sh` and its `estate-rules` step, which were
failing CI on dead template residue. Answers issue #19.

The check was corrupted by a rename sweep that rewrote "V"/"vlang" -> "zig"
inside the script body and the PLAYBOOK block, inverting the rule: it banned
Zig, which directly contradicts the estate's Zig-first ABI/FFI directive.
Three independent tells:

  * the FILENAME survived the sweep -- check-no-**vlang**.sh -- while the body
    says "ziguage is banned" / "zig (vlang.io) is banned"; vlang.io is V's site
  * the PLAYBOOK block still contains the original sentence verbatim:
    "V (vlang.io) is banned estate-wide"
  * its own caveat warns that "Coq theorem files use the same `.v` extension"
    -- `.v` is V's extension; Zig uses `.zig`

What it was flagging in this repo was therefore never a real violation: a
`.zig-cache/` line in .gitignore, commented-out `zig build` examples in the
Justfile, and template test/bench harnesses referencing a `src/` this repo
does not have (PR #16 removed runnable code -- systemet is a theory repo).

The V ban itself is left standing as policy in the PLAYBOOK, with the prose
corrected back to V and enforcement explicitly marked WITHDRAWN/UNENFORCED, so
the next reader is not misled either way. Re-enforcing needs a newly written
checker: the old one cannot be salvaged by renaming, because its content
patterns were corrupted along with its prose.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@hyperpolymath
hyperpolymath merged commit eed2092 into main Jul 27, 2026
42 of 46 checks passed
@hyperpolymath
hyperpolymath deleted the proofs/lean4-l1-l2 branch July 27, 2026 13:03
hyperpolymath added a commit that referenced this pull request Jul 27, 2026
…ure (prospective ET-16) (#28)

**Draft for a ruling, not an implementation.** Status is `Proposed`; the
ADR decides nothing until you accept it.

## Why this exists

ET-14 (TEA erasure) can't be *stated* until item (3) — the observational
equivalence used at L0 — is fixed. That gates items (1), (2), (4), and
through them anytype Phase 6. It has stayed open because it isn't merely
a definition:

- `01-l0-runtime.adoc`: *"L0 deliberately has no independent semantics
within systemet. No typing judgement is defined at L0."*
- but an observational equivalence **is** a semantics.

Hence `OBLIGATIONS.adoc` parks *"ET-16 (candidate — L0 lowering
correctness) … deliberately not numbered into the ledger"* pending an
ADR. **This is that ADR.**

The tension in one line: **ET-14 needs an L0 observation; L0 is defined
by having no semantics of its own.**

## The three alternatives

| | Approach | Verdict |
|---|---|---|
| **A** | Adopt a concrete L0 semantics + contextual equivalence |
Strongest and most conventional, but systemet acquires a semantics to
maintain against two moving backends — and the model L0 won't be
anytype's or AffineScript's real target, so proofs risk being *about a
fiction* |
| **B** | **Parametric** — an `L0Observation` interface (carrier, `≈`,
laws); ET-14 quantified over every instantiation; anytype/AffineScript
instantiate for real targets | **Recommended** |
| **C** | Syntactic image identity (lowering of handled ≡ lowering of
pure residue) | Smallest, closest to the literal wording, but almost
certainly too strong for any realistic lowering (ordering, regalloc).
Retained as an optional *strengthening lemma*, not the definition |

## Why B

It **preserves** the architectural commitment instead of reversing it —
the semantics becomes a *parameter*, never a commitment — and it reuses
an idiom already mechanized and green in this repo: ET-4 is discharged
as `Systemet.L2.GradeAlgebra`, *"the law set as a class whose fields are
the proof obligations"*, with four instances and a generic product
construction. The same shape applied to observation is the house
pattern.

It also puts the WASM/C commitment where the real targets live, which is
what the authority chain already says.

**Stated with its failure mode:** a too-weak interface makes ET-14 true
and *vacuous*. So the sequencing puts a vacuity check (one instance, one
non-instance) and the three dropped-letter counterexamples **early** —
they're the cheapest test that the interface is fine enough to be worth
proving anything about.

## What it does *not* decide

ET-14 items (1) L4 handler syntax, (2) the T/E/A predicates, (4) the
erasure translation — plus the **L2 join law** and **L3 guardedness**.
All remain owner-only and separately ADR-gated. ET-16, if adopted,
enters the ledger *narrower* than the parked candidate implied.

## Note on numbering

`docs/decisions/` holds `0000-template` and `0001` only → this is
**0002**. Earlier session notes called it "ADR-006", which was wrong for
this repo.

Branched from `main`, independent of #27 (ET-2 promotion), so the two
can be ruled on separately.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant