Tangle is a Turing-complete topological programming language. This file tracks notable changes to the compiler, stdlib, tooling, and WASM runtime.
The format is based on Keep a Changelog.
compiler/lib/dialect_vk.mlmodels the virtual-knot dialect (the virtual braid monoid VBₙ ⊃ Bₙ — braids plus involutive virtual crossings vᵢ) as a conservative extension of the core braid language: a real crossing or a virtual crossing, with the core (real) fragment embedding viaembedand every decision on it DELEGATED toBraid_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; permutation/writhe invariants agree on the real fragment; proper extension (a virtual crossing is a genuinely-new non-real element,vᵢ vᵢ = ε); 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 (avoids the
Warning 8exhaustiveness cascade). Surface-syntax integration, the other four dialects, and a Lean conservativity proof are the next rungs (PROOF-NEEDS TG-8).
compiler/tangle-wasm/tests/differential.rsaddswasmi(a pure-Rust wasm interpreter) as a dev-dependency and EXECUTES the generated wasm modules, supplying reference host primitives (tangle_rt.alloc_strandsinitialises the identity strand array;tangle_rt.swap_strandsswaps two cells). It then checks the executed strand permutation equals an independent in-Rust reference model — over the trefoil, non-commuting pairs (s1 s2≠s2 s1), braid-relation pairs (s1 s2 s1=s2 s1 s2), and a 5-strand weave. Run viacargo testincompiler/tangle-wasm.- This validates the wasm codegen against the braid permutation semantics
(catches wrong crossing indices, call order, strand counts, or a
non-instantiable module). It is not a cross-binary diff against
eval.ml, and the Markov-move helpers are not yet exercised; full source↔wasm bisimulation remains research-grade (PROOF-NEEDS.md TG-6). The shipped backend keeps no runtime dependency (wasmiis dev-only).
compiler/lib/braid_equiv.mldecides braid-GROUP equivalence via Dehornoy handle reduction (equiv,is_trivial, pluswrithe/permutationinvariants). It is out-of-band: the language's==on braids (eval.mland the LeanStep.eqBraidsrule) is left as list equality — no semantics change. Routing==through it remains an owner decision (PROOF-NEEDS.md TG-7).- Tested in
compiler/test/tg7/tg7_braid_equiv.ml(2220 assertions): the defining relations (commutation, braid relation, cancellation), 400 randomly-constructed equivalent pairs (relation-preserving moves give ground truth; writhe/permutation invariants guard the generator), and invariant-distinguished negatives. Correctness is by-testing; a mechanised Garside/Dehornoy proof is the research-grade rung.
- TG-5 LANDED:
compiler/test/tg5/tg5_invariants.ml(189 assertions, indune runtest) — a structural-invariant property test for the compositional PD lowering (compiler/lib/compositional.ml). compositional sits below the type layer, so "the rewriter preserves types" is realised as preserving the lowering's structural invariants + the echo residue-recovery property:OpenWordunit-expanded;ClosedDiagramclosed /components=[]/ source unit-expanded /|crossings| = |source| = unit-count;EchoClosedresidue verbatim (echoClose(s1^3)keeps[s1^3]while the diagram is the 3-crossing unit closure),expand(residue) = diagram word, and echo-diagram pdv1-identical to plainclose; plus error-path and crossing-count pins. Asserts only invariants the lowering guarantees (no arc-balance/planarity). - Readiness map (TG-6/7/8): a parallel assessment found each remaining
obligation is blocked on a prerequisite, not effort — recorded in
PROOF-NEEDS.md. TG-8 blocked: the five dialects are prose READMEs with no
implementation. TG-7 needs an owner decision: braid-group equivalence
changes the observable semantics of
==on braids in both the evaluator and the LeanSteprelation. TG-6 blocked: no wasm runtime is wired in, so even differential testing has nothing to execute.
Proof obligation TG-3 — "compiler/lib/typecheck.ml refines the mechanised
HasType spec" — is discharged at the translation-validation level. Full
write-up, closure argument, type translation, divergence catalogue and
extra-core feature list: proofs/TG3-REFINEMENT.md.
- Reduction. TG-2 proves Lean
infer ≡ HasType, so TG-3 reduces to "OCamlinfer_expr≡ Leaninferon the shared core fragment". - Closure proof. The core fragment (literals, let/var, compose/tensor/
pipeline, add, eq, and the echo/product ops — excluding
closeand the whole Tangle layer) is closed underinfer_expr: it never produces aTTangle, under a strengthened entire-type-tree induction hypothesis (a Tangle must not hide inside aTProd/TEchoand leak out viafst/snd/lower/residue). - Machine-checked half.
proofs/TG3Differential.lean— 496 obligationsinfer [] <term> = <infer_expr result> := by decide, generated from the OCaml checker bycompiler/test/tg3/tg3_emit.mland kernel-verified by Lean's proveninfer. Newproofs/check-tg3-differential.sh(builds the Tangle.olean, checks the obligations); wired intolean-proofs.yml. - OCaml half.
compiler/test/tg3/runstg3_emit --checkunderdune runtest: 1008 assertions over a 490-term corpus — closure invariant, curated type pins, named→de Bruijn translation (incl.let-shadowing), and the OCaml side of every divergence. - Divergence catalogue (complete). D1
close(OCamlTangle[I,I]vs LeanWord[0]— the sole core boundary gateway) and its downstream vectors D1bpipeline(close,close), D1ccompose(braid,close)(OCaml rejects), D1dadd(close,close); D2bool == bool(OCaml accepts as extra-core, Lean rejects). Both sides of each are pinned. - Honest boundary. Translation validation over a broad corpus plus a
structural argument — not a single Lean theorem quantifying over all OCaml
runs (that would require reflecting
typecheck.ml). Refinement is OCaml→Lean.
Both TG-1 and TG-2 were already fully proved in proofs/Tangle.lean but not
reflected in PROOF-NEEDS.md / PROOF-NARRATIVE.md. This entry documents the
retrospective correction.
- TG-1 LANDED:
weakening+subst_preserves+ all four theorems (Progress, Preservation, Determinism, TypeSafety) extended tovar/let. The "let-free fragment" caveat in PROOF-NARRATIVE.md is retired. - TG-2 LANDED:
infer(structural recursion over all 26 HasType rules),infer_sound,infer_complete,infer_iff_hasType,type_unique,decidableHasType— all inproofs/Tangle.lean§TG-2. - echo-types grade semiring design note (§2.8 of PROOF-NARRATIVE.md): the
experimental ℕ∪{∞} min-plus grade semiring in
hyperpolymath/echo-types(f7a965f) uses the combining/monadic direction — the same direction as Tangle'sechoAdd/echoEq. The splitting/comonadic direction requires a full graded adjunction and is under experimental investigation (firewalled). No Tangle design change required now.
The compositional PD compiler (compositional.ml) now threads the echo
residue through the IR. This is the OCaml-side implementation of the
cross-repo contract at docs/spec/ECHO-TANGLEIR-THREADING.md.
EchoClose of expradded to theexprtype;echo_closebuilder.EchoClosed { residue; diagram }added tocompiled— carries the pre-closure braid word alongside the closed planar diagram (identical to the plain-Closeoutput so existing consumers are unaffected).compile_echo_and_send_to_skein— residue-carrying Skein hook that emitsecho_closed_payloadwith bothresidue_blob("s1,s2^-1,s1"format) and the PDv1 blob.word_of_compiled (EchoClosed _)returns the residue braid — the pre-closure word is recoverable at the IR level.- Parser adapter (
of_ast_expr) mapsAst.EchoCloseto the compositionalEchoClose, reachable via the new--compile-pdCLI flag (see below). - Validated against
EchoProvenance.agda(echoes distinguish tag-differing records) andEchoResidue.agda(no-sectiontheorem — the residue must be threaded, not recomputed after lowering).
Downstream: Julia KRLAdapter.jl and quandledb implement the
consumer side per §3–4 of the contract doc.
A multi-agent adversarial audit of the echo/TG work surfaced fixes, applied here:
- Residue is now verbatim.
compile (EchoClose b)retains the unexpanded pre-closure braid as the residue (via a newsource_word_of_expr), soechoClose(braid[s1^3])keeps residues1^3rather than the unit-expandeds1,s1,s1. This matches the Leanecho_residue_recoverstheorem and the eval interpreter (which were already exponent-faithful); only the planar diagram is unit-expanded. Eqtypecheck tightened to the spec. Word equality now requires equal width (Word[n] == Word[m]⇒n = m), matching the LeantEqWordrule; unequal-width comparisons are now rejected instead of silently evaluating tofalse.Bool == Boolis retained as an explicit extra-core convenience (used byexamples/braids_as_data).--compile-pd <file>CLI flag wires the compositional/Skein path (previously test-only) into the shipped binary: each closed/echo-closeddefis lowered to its PDv1 blob, with the residue blob forechoClose.- Test coverage for the surface echo pipeline. Added direct
typecheck (
test_typecheck.ml) and eval (test_eval.ml) tests pinning the residue/result ordering of all 8 echo/product forms against the LeanSteprules — previously only parse/pretty round-trip was tested. - Adds direct typecheck/eval coverage for the 8 echo forms (suite was 557 before this batch; see the running total below).
tangle-lsp previously computed diagnostics from a hand-rolled lexical
scan that diverged from the real parser/typechecker, emitting LSP-only
false positives (wrong comment syntax, delimiters counted inside string
literals, "unclosed block" on every multi-def file, params flagged as
undefined). None corresponded to a HasType failure — violating TG-9.
compiler/lib/check.ml(check_source) is now the single diagnostic source: parse-with-recovery +Typecheck.check_program.tanglec --check <file>exposes it asSEVERITY⇥LINE⇥COL⇥MESSAGE.tangle-lspshells out totanglec --checkand forwards exactly those diagnostics; the lexical scan now only extracts definitions / references for navigation. With the compiler absent it emits nothing (∅ ⊆ HasType failures). The subset relation holds by construction.- Built-in operations now appear in LSP completion (reusing the
previously diagnostic-only
TANGLE_BUILTINSlist). - Tests:
compiler/test/test_check.mlandtangle-lspRust unit tests (parse_check_line, navigation authors no diagnostics, gated end-to-end delegation against a realtanglec).
definitiongains adef_linefield (set from the parser's$startpos);Typecheck.diagnosticgainsdiag_line. Definition-scoped type errors now point at thedefline instead of the file top, so the LSP highlights the right line.- Removed a duplicate diagnostic:
check_programpass 2 no longer re-checks definitions (pass 1b already does), so one type error yields one diagnostic. Statement-level errors (assert/compute/weave) remain unlocated for now. - Test-suite total: 597/597 pass.
- Echo/product type system fully landed in the OCaml pipeline (PR #45 + #46):
ast.ml: 8 newexprconstructors (echoClose,lower,residue,pair,fst,snd,echoAdd,echoEq); 2 newtyconstructors (TProd,TEcho)typecheck.ml: 8 newinfer_exprrules mirroring LeanHasType(T-Echo-Close,T-Lower,T-Residue,T-Pair,T-Fst,T-Snd,T-Echo-Add,T-Echo-Eq);pp_tymadereceval.ml:VEcho/VPairvalue forms; 8 neweval_exprarms;pp_valuemadereclexer.mll+parser.mly+token.ml: keyword tokens and grammar productions for all 8 surface forms (echoClose(e),lower(e),residue(e),pair(a,b),fst(e),snd(e),echoAdd(a,b),echoEq(a,b))pretty.ml: pretty-printers for all 8 forms; round-trips through parser
- TG-4 (pretty-print/parse round-trip) discharged:
test_roundtrip.mlextended with 8 new echo/product corpus entries (16 round-trip runs) covering every echo/product constructor (PR #46) docs/spec/ECHO-TANGLEIR-THREADING.md: cross-repo contract for how echo residue threads through TangleIR to QuandleDB (PR #45)- Compositional PD compiler API (
compositional.ml/.mli):expr,planar_diagram,compiled,skein_payloadtypes pdv1_blob_of_pd: canonical text serialisation format (pdv1|x=a,b,c,d,s;...|c=arc,arc;...)compile_and_send_to_skein: direct Tangle → Skein integration entry point- Playground scaffold in
playground/(placeholder PWA + 2 example programs) - README rewrite introducing KRL architecture + visual map (docs/krl_map.html)
- CRG v2 READINESS.md (grade C)
- Tangle composition typecheck: correct permutation application
- WASM: fixed composed braid locals and helper expectations
- Zig ABI layer modernized
compiler/bin/main.mldebug token printer: add 8 missing echo keyword token arms (Warning 8 exhaustiveness, PR #46)compiler/lib/typecheck.mlstrand_type_of_ty: addTProd/TEchoarms (Warning 8 exhaustiveness, PR #46)- EXPLAINME.adoc section heading quotes
- Justfile with doctor, tour, help-me, assail recipes
- UX Manifesto deployment
- Agent instructions methodology layer
- Lean 4 proofs: progress, preservation, determinism
- TOPOLOGY.md documentation added
- A2ML migration of state files
- SPDX headers, license migration to MPL-2.0
- stapeln.toml container definition
- Standard workflow deployment (codeql, hypatia, scorecard, etc.)
- Compiler (OCaml/dune): parser, typechecker, evaluator, pretty-printer, REPL
- WASM backend (
tangle-wasm/) - LSP server (
tangle-lsp/) - Stdlib (
lib/stdlib.tangle)