Skip to content

Commit 442e04c

Browse files
author
Jonathan D.A. Jewell
committed
feat(echo-types): integrate structured-loss echo types into the type system (TG-10)
Echo types are now a first-class feature of the Tangle core type system, not an external reference. `close : Word[n] -> Word[0]` is Tangle's canonical lossy map; the echo layer makes that loss recoverable at the type level, mirroring echo-types' fibre definition Echo f y := Σ(x:A), f x ≡ y (hyperpolymath/echo-types, Echo.agda) in the simply-typed setting. Type system: - Ty.echo ρ τ — structured-loss type former (ρ = residue/witness, τ = result) - Expr: echoClose (echo-intro for close), lower (project to result), residue (recover the witness braid) - HasType: T-Echo-Close, T-Lower, T-Residue - Step: echoCloseStep, lowerStep, lowerEcho, residueStep, residueEcho Metatheory (all green under lean4 v4.14.0, no sorry/axiom/admit): - Progress, Preservation, Determinism, Type Safety extended to cover the echo fragment - new canonical_echo lemma; value_no_step made structurally recursive (a formed echo is a value iff its residue is) Capstone theorems (the echo-types content, realized in Tangle): - echo_lower_collapses — every closed braid lowers to identity (the loss) - echo_residue_recovers — residue recovers the original braid (reversibility) - echo_distinguishes_collapsed — distinct braids collapse to the same identity but keep distinct residues (Tangle form of no-section / sigma-distinguishes) - echo_roundtrip_typed — the round-trip is well-typed Docs: PROOF-NARRATIVE §2.5 (echo-types feature), audit note updated from NOT-RELEVANT to integrated; PROOF-NEEDS TG-10 row (LANDED). https://claude.ai/code/session_01PgHpCFzwYB7Qy9L6kmR8CE
1 parent 01c19a4 commit 442e04c

3 files changed

Lines changed: 239 additions & 22 deletions

File tree

PROOF-NARRATIVE.md

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,24 @@ returns **0 errors**, verified locally on v4.10/4.11/4.12/4.13/4.14/4.15/4.16,
6363
with CI gating both `lean Tangle.lean` and a `sorry`/`axiom`/`admit`
6464
slippage check. Future drift will fail CI rather than land silently.
6565

66-
**Echo-types audit.** Per [[proofs-must-check-and-cross-doc-echo-types]]:
67-
echo-types is fibre-based loss-with-residue semantics — it has zero
68-
lambda-calculus / progress / preservation content. Verdict:
69-
**NOT-RELEVANT** for all four theorems below. Recorded once at
70-
`feedback_echo_types_audit_krl_tangle_quandledb_not_relevant.md`.
66+
**Echo-types — now integrated as a type-system feature (2026-06-03).**
67+
The earlier audit (`feedback_echo_types_audit_krl_tangle_quandledb_not_relevant.md`)
68+
correctly found that the *external* echo-types Agda library
69+
(hyperpolymath/echo-types) carries no lambda-calculus / progress /
70+
preservation content of its own, so it does not perturb the four base
71+
theorems. That verdict stands for the external library. **Tangle now
72+
ships its own simply-typed shadow of echo-types as a first-class feature
73+
of the type system** (`Ty.echo ρ τ`, constructors `echoClose`/`lower`/
74+
`residue`, rules `T-Echo-Close`/`T-Lower`/`T-Residue`). The motivation is
75+
intrinsic to Tangle: `close : Word[n] → Word[0]` is the canonical lossy
76+
map (the analogue of echo-types' `collapse : Bool → ⊤`), and the echo
77+
layer makes that loss recoverable at the type level — the residue
78+
`Word[n]` is retained and projected back out. Progress, Preservation,
79+
Determinism, and Type Safety in `proofs/Tangle.lean` now **cover the echo
80+
fragment**, and three capstone theorems (`echo_lower_collapses`,
81+
`echo_residue_recovers`, `echo_distinguishes_collapsed`) reproduce
82+
echo-types' `no-section` / `sigma-distinguishes` barrier inside Tangle.
83+
See PROOF-NARRATIVE §2.5.
7184

7285
### Theorems (the main results)
7386

@@ -103,14 +116,57 @@ themselves proofs of the form "these are the rules"):
103116
- **`Expr`** — the AST (mirrors `compiler/lib/ast.ml`)
104117
- **`Ty`**`num`, `str`, `bool`, `word n`
105118
- **`IsValue`** — value predicate
106-
- **`HasType`** — typing judgment, 13 rules (`tNum`, `tStr`, `tBool`,
119+
- **`HasType`** — typing judgment, 16 rules (`tNum`, `tStr`, `tBool`,
107120
`tIdentity`, `tBraid`, `tComposeWord`, `tTensorWord`, `tPipeline`,
108-
`tCloseWord`, `tAddNum`, `tEqWord`, `tEqNum`, `tEqStr`)
109-
- **`Step`** — small-step semantics, 26 rules
121+
`tCloseWord`, `tAddNum`, `tEqWord`, `tEqNum`, `tEqStr`, plus the echo
122+
rules `tEchoClose`, `tLower`, `tResidue`)
123+
- **`Step`** — small-step semantics, 31 rules (26 base + 5 echo)
110124

111125
These are the formal spec the OCaml implementation is meant to refine
112126
(see TG-3 below).
113127

128+
## 2.5 Echo types — structured loss as a type-system feature
129+
130+
Echo types are integrated into the core type system (not a separate
131+
layer). The design mirrors echo-types' fibre definition
132+
`Echo f y := Σ (x : A), f x ≡ y` (hyperpolymath/echo-types,
133+
`Echo.agda`) in Tangle's simply-typed setting, motivated by Tangle's own
134+
canonical lossy operation.
135+
136+
**Why `close`.** `close : Word[n] → Word[0]` collapses every braid word
137+
to the identity, discarding the word — exactly the kind of
138+
information-destroying map echo-types is about (cf. `collapse : Bool → ⊤`
139+
in `EchoResidue.agda`). Echo types make that loss *recoverable in the
140+
type system*.
141+
142+
| Construct | Form | Echo-types analogue |
143+
|-----------|------|---------------------|
144+
| Type former | `Ty.echo ρ τ` — a `τ`-result carrying a `ρ`-residue | `Echo f y` (ρ = domain witness, τ = codomain point) |
145+
| `echoClose e` | `Word[n] → Echo (Word[n]) (Word[0])` | `echo-intro close` |
146+
| `lower e` | `Echo ρ τ → τ` — project to result (forget residue) | the collapse / `proj₂` |
147+
| `residue e` | `Echo ρ τ → ρ` — recover the witness braid | `proj₁` |
148+
149+
**Metatheory.** Progress, Preservation, Determinism, and Type Safety all
150+
cover `echoClose`/`lower`/`residue` (the inductions are exhaustive over
151+
the extended `Step`/`HasType`). A new canonical-forms lemma
152+
`canonical_echo` characterises echo values; `value_no_step` became
153+
structurally recursive because a formed echo `echoClose v` is a value iff
154+
its residue `v` is.
155+
156+
**Capstone theorems** (the echo-types *content*, `Tangle.lean` §ECHO-TYPES):
157+
- `echo_lower_collapses` — every closed braid lowers to `identity`
158+
(the lossy step, re-derived through the echo).
159+
- `echo_residue_recovers``residue (echoClose (braidLit gs)) ⟶ braidLit gs`
160+
(the witness is retained; `close` becomes reversible).
161+
- `echo_distinguishes_collapsed` — distinct braids collapse to the *same*
162+
identity under `lower`, yet their residues stay distinct. This is the
163+
Tangle instantiation of echo-types' non-injectivity barrier
164+
(`collapse-residue-same` + `no-section-collapse-to-residue`).
165+
- `echo_roundtrip_typed` — the round-trip is well-typed: `residue` returns
166+
a `Word[n]`, `lower` returns a `Word[0]`.
167+
168+
Tracked as obligation **TG-10** in PROOF-NEEDS.md (landed).
169+
114170
## 3. Remaining obligations (the narrative arc)
115171

116172
What's not yet proven, why it matters, and what assumption each rests on.

PROOF-NEEDS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ and `proofs/Tangle.lean`:
3939

4040
**Coverage:** the **let-free fragment** of core Tangle, comprising
4141
`Num`, `Str`, `Bool`, `Identity`, `BraidLit`, `Compose`, `Tensor`,
42-
`Pipeline`, `Close`, `Add`, `Eq`. 13 typing rules, 26 step rules.
42+
`Pipeline`, `Close`, `Add`, `Eq`, plus the **echo-types fragment**
43+
(`EchoClose`, `Lower`, `Residue` with type former `Echo[ρ,τ]`). 16 typing
44+
rules, 31 step rules. All four theorems cover the echo fragment (TG-10).
4345

4446
## What remains
4547

@@ -56,6 +58,7 @@ Cross-referenced to [PROOF-NARRATIVE.md §3](PROOF-NARRATIVE.md#3-remaining-obli
5658
| TG-7 | `Step.eqBraids` decides braid-group equivalence (not list equality) | ALG / DOM | OCaml + Lean 4 | P2 | 2w | NOT STARTED (current impl is soundness-floor, not completeness) |
5759
| TG-8 | Each dialect (braid-calculus, quantum-circuit, skein-algebra, string-diagram, virtual-knot) is a conservative extension of core | TP | Lean 4 per-dialect | P3 | 1w each | NOT STARTED |
5860
| TG-9 | LSP diagnostics are a subset of `HasType` failures (no LSP-only diagnostics) | INV | Audit + refactor | P2 | 1d | NOT STARTED |
61+
| TG-10 | Echo-types integrated into the type system: `Echo[ρ,τ]` former + `echoClose`/`lower`/`residue`, with Progress/Preservation/Determinism/TypeSafety extended to cover them and the non-injectivity / residue-recovery capstones proven | TP / DOM | Lean 4 | P1 || **LANDED** (`proofs/Tangle.lean` §ECHO-TYPES) |
5962

6063
For full per-obligation statements, _why valuable_, and the
6164
assumptions each rests on, see PROOF-NARRATIVE.md.

0 commit comments

Comments
 (0)