Skip to content

Commit 7b9becf

Browse files
hyperpolymathclaude
andcommitted
feat(tg-8): virtual-knot dialect as a conservative extension of core (template)
TG-8 template. compiler/lib/dialect_vk.ml models the virtual-knot dialect (the virtual braid monoid VBn, braids plus involutive virtual crossings v_i) as a CONSERVATIVE EXTENSION of the core braid language: a vgen is a real crossing or a virtual crossing; the real fragment embeds via `embed`, and every decision on it is DELEGATED to Braid_equiv (TG-7). Conservativity therefore holds BY CONSTRUCTION -- the dialect cannot change core typing/semantics. compiler/test/tg8/tg8_conservativity.ml (2311 assertions) verifies: faithful embedding (project . embed = id); the dialect decides core terms exactly as the core procedure (decide_trivial (embed w) = Some (is_trivial w); equiv likewise); permutation/writhe invariants agree on the real fragment; proper extension (a virtual crossing is a genuinely-new non-real element, v_i v_i = e); and an honest partial-decision frontier (irreducible mixed virtual content -> None, never guessed). Built as a SEPARATE module: no core-AST or Lean-oracle edits, avoiding the Warning 8 exhaustiveness cascade and keeping the proof oracle safe. Honest scope: this is the dialect's semantic core + conservativity bridge, not a surface-syntax parser integration, and VBn equivalence is a sound partial decider. Surface syntax, the other four dialects (replicate the template), and a Lean conservativity proof are the next rungs (PROOF-NEEDS.md TG-8). dune runtest green (existing 597 + tg3 1008 + tg5 189 + tg7 2220 + tg8 2311). Docs: PROOF-NEEDS, CHANGELOG, STATE.a2ml. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent db0fdcf commit 7b9becf

7 files changed

Lines changed: 291 additions & 21 deletions

File tree

.machine_readable/6a2/STATE.a2ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ milestones = [
3636
"DONE (TG-9): LSP diagnostics ⊆ HasType failures — tangle-lsp delegates to `tanglec --check` (compiler/lib/check.ml); hand-rolled LSP-only diagnostics removed; subset by construction",
3737
"DONE (TG-3): OCaml typecheck.ml refines Lean HasType (translation validation) — closure proof + proofs/TG3Differential.lean (496 by-decide obligations generated from infer_expr) + compiler/test/tg3 (1008 --check assertions) + proofs/check-tg3-differential.sh wired into lean-proofs.yml; divergences D1 close / D2 bool-eq; proofs/TG3-REFINEMENT.md",
3838
"DONE (TG-5): compositional PD-lowering preserves structural invariants + verbatim echo residue — compiler/test/tg5/tg5_invariants.ml (189 assertions in dune runtest)",
39-
"BLOCKED (TG-8): dialects are README-only — need one dialect implemented (AST+parser+HasType/Step+eval) before conservativity is even stateable",
39+
"TEMPLATE-DONE (TG-8): virtual-knot conservative-extension template — compiler/lib/dialect_vk.ml (VBn = core + virtual layer delegating to Braid_equiv on the real fragment; conservativity by construction) + compiler/test/tg8 (2311 assertions). Remaining: surface syntax, other 4 dialects, Lean conservativity proof.",
4040
"RUNG-DONE (TG-7): out-of-band braid_equiv (Dehornoy handle reduction) in compiler/lib/braid_equiv.ml — decides braid-group equivalence WITHOUT changing == (compiler/test/tg7, 2220 assertions). Routing == through it stays an owner decision; Lean correctness research-grade.",
4141
"RUNG-DONE (TG-6): wasm differential — compiler/tangle-wasm/tests/differential.rs executes generated wasm via wasmi (dev-dep) and checks strand permutation == reference model (trefoil, non-commuting, braid-relation, 5-strand). Codegen-vs-semantics; not a cross-binary eval.ml diff; full bisimulation research-grade.",
4242
]
@@ -47,12 +47,12 @@ issues = []
4747
[critical-next-actions]
4848
actions = [
4949
"TG-7 OWNER DECISION (rung done): out-of-band braid_equiv now exists (compiler/lib/braid_equiv.ml). Decide whether to route `==`/Step.eqBraids through it (semantics change to eval.ml + Lean + proofs) or keep them list-equality and use braid_equiv only as a tool.",
50-
"TG-8 prerequisite: implement one dialect end-to-end (virtual-knot suggested) as the conservativity template; dialects are currently README-only.",
50+
"TG-8 (template done): replicate the virtual-knot conservative-extension template to the other 4 dialects; add surface syntax; mechanise the Lean conservativity proof.",
5151
"TG-6 (rung done): optional next rungs = cross-binary differential vs eval.ml; Markov-helper coverage; Lean/WasmCert bisimulation (research-grade).",
5252
"TangleIR Julia: implement EchoClosed node in KRLAdapter.jl per contract (quandledb session)",
5353
]
5454

5555
[maintenance-status]
56-
last-run-utc = "2026-06-14T17:00:00Z"
56+
last-run-utc = "2026-06-14T18:00:00Z"
5757
last-result = "pass" # unknown | pass | warn | fail
58-
notes = "dune build + dune test GREEN (tg3 1008 + tg5 189 + tg7 2220); cargo test tangle-wasm GREEN (10 unit + 2 differential via wasmi); lean Tangle.lean 0 errors; proofs/check-tg3-differential.sh GREEN (496); LANDED: TG-1/2/3/5/9/10 + TG-6 differential rung + TG-7 non-semantic rung; remaining: TG-8 blocked (dialects README-only), TG-7 semantics change owner-gated, full WASM bisimulation research-grade; echo-types f7a965f grade semiring experimental (firewalled)"
58+
notes = "dune build + dune test GREEN (tg3 1008 + tg5 189 + tg7 2220 + tg8 2311); cargo test tangle-wasm GREEN (10 unit + 2 differential via wasmi); lean Tangle.lean 0 errors; proofs/check-tg3-differential.sh GREEN (496); LANDED: TG-1/2/3/5/9/10 + TG-6 differential rung + TG-7 non-semantic rung + TG-8 conservativity template (virtual-knot); remaining owner-gated/research-grade: TG-7 semantics change, TG-8 surface+other-dialects+Lean, full WASM bisimulation; echo-types f7a965f grade semiring experimental (firewalled)"

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1313

1414
## [Unreleased]
1515

16+
### TG-8 (template): virtual-knot dialect as a conservative extension of core
17+
18+
- **`compiler/lib/dialect_vk.ml`** models the virtual-knot dialect (the virtual
19+
braid monoid VBₙ ⊃ Bₙ — braids plus involutive virtual crossings vᵢ) as a
20+
*conservative extension* of the core braid language: a real crossing or a
21+
virtual crossing, with the core (real) fragment embedding via `embed` and every
22+
decision on it DELEGATED to `Braid_equiv` (TG-7). Conservativity therefore
23+
holds by construction — the dialect cannot change core typing/semantics.
24+
- **`compiler/test/tg8/tg8_conservativity.ml`** (2311 assertions) verifies:
25+
faithful embedding (`project ∘ embed = id`); the dialect decides core terms
26+
exactly as the core procedure; permutation/writhe invariants agree on the real
27+
fragment; proper extension (a virtual crossing is a genuinely-new non-real
28+
element, `vᵢ vᵢ = ε`); and an honest partial-decision frontier (irreducible
29+
mixed virtual content → `None`, never guessed).
30+
- Built as a separate module — no core-AST or Lean-oracle edits (avoids the
31+
`Warning 8` exhaustiveness cascade). Surface-syntax integration, the other four
32+
dialects, and a Lean conservativity proof are the next rungs (PROOF-NEEDS TG-8).
33+
1634
### TG-6 (differential rung): execute generated wasm and check it preserves semantics
1735

1836
- **`compiler/tangle-wasm/tests/differential.rs`** adds `wasmi` (a pure-Rust wasm

PROOF-NEEDS.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Cross-referenced to [PROOF-NARRATIVE.md §3](PROOF-NARRATIVE.md#3-remaining-obli
6060
| TG-5 | `compositional.ml` (418 LoC) rewriter preserves types | TP | OCaml property test | P2 || **LANDED** (`compiler/test/tg5/tg5_invariants.ml`, 189 assertions in `dune runtest`). compositional is below the Ty layer, so "preserves types" = preserves the PD-lowering structural invariants + echo residue-recovery: `OpenWord`/`ClosedDiagram`/`EchoClosed` each pinned (closedness, `\|crossings\|`=unit-length, source unit-expanded, **verbatim residue** for `EchoClose` with `expand(residue)=diagram word` and echo-diagram pdv1-identical to plain `close`), error paths, count pins. Lean IR model = optional later rung |
6161
| TG-6 | WASM compilation preserves semantics (source eval ≡ wasm exec) | TP / ALG | differential + Lean bisimulation | P1 || **RUNG LANDED (differential)**: `compiler/tangle-wasm/tests/differential.rs` EXECUTES the generated wasm with the `wasmi` interpreter (dev-dep) and checks the braid strand-permutation equals an independent reference model (trefoil, non-commuting pairs, braid-relation pairs, 5-strand weave). Validates codegen vs the permutation semantics; not a cross-binary diff against `eval.ml`, and Markov helpers untested. Full source↔wasm bisimulation (WasmCert) remains research-grade |
6262
| TG-7 | `Step.eqBraids` decides braid-group equivalence (not list equality) | ALG / DOM | OCaml + Lean 4 | P2 || **RUNG LANDED (non-semantic)**: `compiler/lib/braid_equiv.ml` decides braid-group equivalence via Dehornoy handle reduction, out-of-band (leaves `==`/`Step.eqBraids` as list equality). Tested (`compiler/test/tg7`, 2220 assertions: defining relations + 400 constructed-equivalent pairs + invariant-distinguished negatives). **Still OWNER-GATED**: whether to route `==` through it (a semantics change to eval.ml + Lean Step + proofs) is a language-design decision; Lean correctness (Garside/Dehornoy) remains research-grade |
63-
| 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 |
63+
| TG-8 | Each dialect (braid-calculus, quantum-circuit, skein-algebra, string-diagram, virtual-knot) is a conservative extension of core | TP | OCaml model + Lean per-dialect | P3 | | **TEMPLATE LANDED (virtual-knot)**: `compiler/lib/dialect_vk.ml` models VBₙ ⊃ Bₙ as core + a virtual layer that DELEGATES to `Braid_equiv` on the real fragment, so conservativity holds by construction; `compiler/test/tg8` (2311 assertions) verifies faithful embedding, core-delegation, invariant agreement, proper extension, virtual involution, honest undecided-frontier. Remaining: surface-syntax parser integration, the other 4 dialects (replicate the template), and a Lean conservativity proof |
6464
| TG-9 | LSP diagnostics are a subset of `HasType` failures (no LSP-only diagnostics) | INV | Audit + refactor | P2 || **LANDED** (`tangle-lsp` delegates all diagnostics to `tanglec --check``compiler/lib/check.ml`; hand-rolled LSP-only false positives removed. Subset holds by construction. Tests: `test_check.ml` + tangle-lsp unit/delegation tests) |
6565
| TG-10 | Echo-types integrated into the type system: `Echo[ρ,τ]` former + `echoClose`/`lower`/`residue`/`echoAdd`/`echoEq` + product type (`pair`/`fst`/`snd`), 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) |
6666

@@ -70,12 +70,13 @@ assumptions each rests on, see PROOF-NARRATIVE.md.
7070
## Scoping of the remaining obligations (2026-06-14)
7171

7272
Concrete approach, effort, risk, and dependencies for what is left after
73-
TG-0/1/2/3/4/5/9/10 landed. **Landable rungs of TG-6 and TG-7 also landed**
74-
(2026-06-14): TG-6 now has a `wasmi` differential test executing the generated
75-
wasm; TG-7 has an out-of-band `braid_equiv` checker. What genuinely remains is
76-
**prerequisite-gated, not effort-gated**: TG-8 needs a dialect to exist as code;
77-
TG-7's *semantics change* needs an owner decision; TG-6's *full bisimulation*
78-
and TG-7's *Lean correctness proof* are research-grade.
73+
TG-0/1/2/3/4/5/9/10 landed. **Landable rungs of TG-6, TG-7, and TG-8 also
74+
landed** (2026-06-14): TG-6 a `wasmi` differential test; TG-7 an out-of-band
75+
`braid_equiv` checker; TG-8 a virtual-knot conservative-extension template. What
76+
genuinely remains is **owner-gated or research-grade**: TG-7's *semantics
77+
change* (decision); TG-8's *surface-syntax integration + other 4 dialects +
78+
Lean conservativity proof*; TG-6's *full source↔wasm bisimulation* and TG-7's
79+
*Lean correctness proof*.
7980

8081
### TG-3 — OCaml `typecheck.ml` refines Lean `HasType` — ✅ **LANDED 2026-06-14**
8182
- **Key lever (used):** TG-2 proves Lean `infer ≡ HasType`, so refinement
@@ -132,16 +133,24 @@ and TG-7's *Lean correctness proof* are research-grade.
132133
with tests, no semantic change. Lean correctness (Garside/Dehornoy) remains
133134
research-grade either way.
134135

135-
### TG-8 — each dialect is a conservative extension of core — ⛔ **BLOCKED (no implementation)**
136-
- All five dialects (`dialects/{braid-calculus,quantum-circuit,skein-algebra,
137-
string-diagram,virtual-knot}/`) are **prose + EBNF READMEs only** — zero
138-
parser, typing, or evaluation code. Conservativity is a property of a formal
139-
type system; there is no extended judgment/rules to state it over.
140-
- **Prerequisite:** implement ONE dialect end-to-end as the template — e.g.
141-
virtual-knot: AST constructors (`ast.ml`), parser productions (`parser.mly`),
142-
`HasType`+`Step` rules (`Tangle.lean`), eval (`eval.ml`), then a conservativity
143-
test (core typed-in-core iff typed-in-dialect) mirroring the tg3/tg5 harness.
144-
Only then can conservativity be proven; replicate per dialect (~1w each).
136+
### TG-8 — each dialect is a conservative extension of core — 🟡 **TEMPLATE LANDED (virtual-knot)**
137+
-**Conservativity template landed 2026-06-14**: `compiler/lib/dialect_vk.ml`
138+
models the virtual-knot dialect (VBₙ ⊃ Bₙ — braids plus involutive virtual
139+
crossings) as **core + a virtual layer that delegates to `Braid_equiv` (TG-7)
140+
on the real fragment**, so conservativity holds *by construction* (the dialect
141+
cannot change core typing/semantics). `compiler/test/tg8/tg8_conservativity.ml`
142+
(2311 assertions) verifies: faithful embedding (`project∘embed=id`); the dialect
143+
decides core terms exactly as the core procedure; invariant agreement
144+
(permutation/writhe); proper extension (a virtual crossing is a genuinely-new
145+
non-real element; vᵢvᵢ=ε); and an honest undecided-frontier (irreducible mixed
146+
virtual content is reported `None`, never guessed).
147+
- **Honest scope:** this is the dialect's semantic core + conservativity bridge,
148+
built as a separate module (no core-AST/Lean-oracle edits, avoiding the
149+
`Warning 8` cascade). It is NOT yet a surface-syntax parser integration, and
150+
VBₙ equivalence is a sound *partial* decider (full VBₙ word problem is
151+
research-grade).
152+
- **Remaining:** surface syntax (`lexer`/`parser`/`ast`/`eval`); replicate the
153+
template to the other four dialects; a mechanised Lean conservativity proof.
145154

146155
### TG-6 — WASM compilation preserves semantics — 🟡 **RUNG LANDED (differential)**
147156
-**Differential rung landed 2026-06-14**: `compiler/tangle-wasm/tests/differential.rs`

compiler/lib/dialect_vk.ml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
(* SPDX-License-Identifier: MPL-2.0 *)
2+
(* dialect_vk.ml — the virtual-knot dialect as a CONSERVATIVE EXTENSION of the
3+
* core braid language. TG-8 template (OCaml conservativity rung).
4+
*
5+
* The virtual braid monoid VBₙ extends the braid group Bₙ with *virtual*
6+
* crossings vᵢ: involutions (vᵢ vᵢ = ε) with no over/under information and no
7+
* writhe. The classical embedding Bₙ ↪ VBₙ is known to be faithful, so VBₙ is a
8+
* conservative extension of Bₙ.
9+
*
10+
* This module realises that extension so that conservativity holds BY
11+
* CONSTRUCTION at the implementation level: the core (real) braid language
12+
* embeds via [embed], and every decision on the real fragment is DELEGATED to
13+
* the core decision procedure [Braid_equiv] (TG-7). The dialect therefore
14+
* cannot change core typing/semantics; virtual crossings are handled by new
15+
* rules (involution, virtual permutation) that fire only on virtual syntax.
16+
* `compiler/test/tg8` verifies this (delegation, faithful embedding, invariant
17+
* agreement, proper extension, virtual involution).
18+
*
19+
* SCOPE (honest). This is the dialect's semantic core + conservativity bridge,
20+
* NOT a surface-syntax parser integration, and equivalence is a SOUND, PARTIAL
21+
* decision procedure for VBₙ: real Dehornoy handle reduction (via Braid_equiv) +
22+
* virtual involution + free reduction. Words with irreducible mixed virtual
23+
* content are reported UNDECIDED (`None`) rather than guessed. A complete VBₙ
24+
* word problem and a mechanised Lean conservativity proof are the next rungs.
25+
*)
26+
27+
module BE = Braid_equiv
28+
29+
(* A virtual braid generator: a real crossing σᵢ^{±k} or a virtual crossing vᵢ. *)
30+
type vgen =
31+
| Real of Ast.generator (* real crossing (carries index + exponent) *)
32+
| Virt of int (* virtual crossing vᵢ at index i (involution) *)
33+
34+
type vword = vgen list
35+
36+
(* ---- embedding / projection (faithfulness) ---- *)
37+
38+
(** Embed a core braid word into the dialect (all crossings real). *)
39+
let embed (gs : Ast.generator list) : vword = List.map (fun g -> Real g) gs
40+
41+
(** Recover the core braid word iff the vword has no virtual crossings. *)
42+
let project (w : vword) : Ast.generator list option =
43+
let rec go acc = function
44+
| [] -> Some (List.rev acc)
45+
| Real g :: r -> go (g :: acc) r
46+
| Virt _ :: _ -> None
47+
in
48+
go [] w
49+
50+
let is_real (w : vword) : bool = project w <> None
51+
let has_virtual (w : vword) : bool = List.exists (function Virt _ -> true | _ -> false) w
52+
53+
(* ---- invariants ---- *)
54+
55+
(** Underlying permutation on [1..strands]: BOTH real and virtual crossings
56+
transpose adjacent strands (σᵢ^k acts as the transposition (i,i+1) repeated
57+
|k| times; vᵢ once). *)
58+
let permutation ~(strands : int) (w : vword) : int array =
59+
let p = Array.init strands (fun k -> k + 1) in
60+
let swap i = if i >= 1 && i < strands then (let t = p.(i-1) in p.(i-1) <- p.(i); p.(i) <- t) in
61+
List.iter (function
62+
| Real g -> for _ = 1 to abs g.gen_exponent do swap g.gen_index done
63+
| Virt i -> swap i) w;
64+
p
65+
66+
(** Writhe counts REAL crossings only (virtual crossings carry no sign). *)
67+
let writhe (w : vword) : int =
68+
List.fold_left (fun a -> function Real g -> a + g.gen_exponent | Virt _ -> a) 0 w
69+
70+
(* ---- reduction ---- *)
71+
72+
let vinverse (w : vword) : vword =
73+
List.rev_map (function
74+
| Real g -> Real { g with gen_exponent = - g.gen_exponent }
75+
| Virt i -> Virt i) w
76+
77+
(* one pass of free + involution cancellation: σᵢ^a σᵢ^{-a} and vᵢ vᵢ. *)
78+
let cancel (a : vgen) (b : vgen) : bool =
79+
match a, b with
80+
| Virt i, Virt j -> i = j
81+
| Real g, Real h -> g.gen_index = h.gen_index && g.gen_exponent = - h.gen_exponent
82+
| _ -> false
83+
84+
let free_reduce (w : vword) : vword =
85+
List.fold_right (fun x acc ->
86+
match acc with y :: rest when cancel x y -> rest | _ -> x :: acc) w []
87+
88+
(** Decide whether a vword is the trivial braid.
89+
[Some true]/[Some false] when decided; [None] when the word still has
90+
irreducible mixed virtual content (the partial-decision frontier — honest,
91+
never guessed). On the REAL fragment this is the core decision procedure. *)
92+
let decide_trivial (w : vword) : bool option =
93+
let r = free_reduce w in
94+
if r = [] then Some true
95+
else match project r with
96+
| Some real -> Some (BE.is_trivial real) (* real fragment → core decides (complete) *)
97+
| None -> None (* mixed virtual residue → research-grade *)
98+
99+
(** Equivalence in the dialect: [decide_trivial (u · v⁻¹)]. *)
100+
let equiv (u : vword) (v : vword) : bool option =
101+
decide_trivial (u @ vinverse v)

compiler/lib/dialect_vk.mli

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
(* SPDX-License-Identifier: MPL-2.0 *)
2+
(* dialect_vk.mli — virtual-knot dialect as a conservative extension of core
3+
* braids (TG-8 template). See dialect_vk.ml for scope and method. *)
4+
5+
(** A virtual braid generator: a real crossing or a virtual crossing vᵢ. *)
6+
type vgen =
7+
| Real of Ast.generator
8+
| Virt of int
9+
10+
type vword = vgen list
11+
12+
(** Embed a core braid word (all crossings real). [project (embed w) = Some w]. *)
13+
val embed : Ast.generator list -> vword
14+
15+
(** Recover the core braid word iff there are no virtual crossings. *)
16+
val project : vword -> Ast.generator list option
17+
18+
val is_real : vword -> bool
19+
val has_virtual : vword -> bool
20+
21+
(** Underlying permutation on [1..strands] (real and virtual both transpose). *)
22+
val permutation : strands:int -> vword -> int array
23+
24+
(** Writhe (real crossings only). *)
25+
val writhe : vword -> int
26+
27+
(** Inverse virtual braid word. *)
28+
val vinverse : vword -> vword
29+
30+
(** Free + involution reduction (σσ⁻¹ and vᵢvᵢ cancellation). *)
31+
val free_reduce : vword -> vword
32+
33+
(** Decide triviality. [Some _] when decided; on the real fragment this is the
34+
core decision procedure (complete). [None] iff irreducible mixed virtual
35+
content remains (the honest partial-decision frontier). *)
36+
val decide_trivial : vword -> bool option
37+
38+
(** Dialect equivalence = [decide_trivial (u · v⁻¹)]. *)
39+
val equiv : vword -> vword -> bool option

compiler/test/tg8/dune

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; SPDX-License-Identifier: MPL-2.0
2+
; TG-8 virtual-knot dialect conservativity template (Dialect_vk).
3+
; dune runtest -> runs ./tg8_conservativity.exe --check.
4+
5+
(executable
6+
(name tg8_conservativity)
7+
(modules tg8_conservativity)
8+
(libraries tangle))
9+
10+
(rule
11+
(alias runtest)
12+
(deps tg8_conservativity.exe)
13+
(action (run ./tg8_conservativity.exe --check)))

0 commit comments

Comments
 (0)