Skip to content

Commit 8da84d6

Browse files
hyperpolymathclaude
andcommitted
feat: add dialects/ scaffolds for 3 Tangle-hosted DSLs
Evidence that Tangle is a multi-DSL host, not a single-purpose language. Each scaffold is a grammar sketch + README — explicitly NOT an implementation. New scaffolds: - dialects/braid-calculus/: Artin braid group Bn calculus (σᵢ^k, multiplication, Markov equivalence) - dialects/quantum-circuit/: compositional quantum circuits (H/X/Y/Z/CNOT/ parameterised gates, sequential ; + tensor ⊗) - dialects/string-diagram/: monoidal category string diagrams (then / tensor / id / braiding / associator / unitor) Pattern established: sketches live here, graduate to own top-level repo when implementation begins (following krl/ precedent). KRL is cross-linked as the first graduated example. Addresses READINESS.md path-to-B: 'Build 5 more DSLs on top of Tangle (not just KRL)'. 3 sketches down, 2 more to go — plus upgrading these from sketch → alpha. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4337b23 commit 8da84d6

7 files changed

Lines changed: 258 additions & 0 deletions

File tree

dialects/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Tangle Dialects — hosted DSL scaffolds
2+
3+
Tangle is a Turing-complete topological programming language. It is NOT
4+
a DSL host by accident — it was designed to support compositional
5+
calculi grounded in knot theory, category theory, and related algebraic
6+
structures.
7+
8+
This directory holds *scaffolds* for DSLs that could be hosted on Tangle.
9+
Each scaffold is an EBNF grammar sketch — evidence that the idea is
10+
coherent and could be built out, not a complete implementation.
11+
12+
## The pattern
13+
14+
When a DSL matures from sketch → alpha implementation, it should follow
15+
the KRL precedent:
16+
17+
1. Start with an EBNF grammar sketch here (`grammar-sketch.ebnf`)
18+
2. Write 1-3 example programs
19+
3. When ready to implement: graduate to its own top-level repo (like `krl/`)
20+
4. Implement parser in Tangle OCaml or sibling language
21+
5. Wire through to TangleIR or its own IR type
22+
23+
Keeping sketches here demonstrates Tangle's claim to be a general
24+
multi-DSL host, not a single-purpose language.
25+
26+
## Current scaffolds
27+
28+
| Dialect | Status | Domain |
29+
|---|---|---|
30+
| [krl](../../krl/) (separate repo) | grade E | Knot resolution — construct, transform, resolve, retrieve |
31+
| [braid-calculus](braid-calculus/) | sketch | Artin braid group Bn calculus |
32+
| [quantum-circuit](quantum-circuit/) | sketch | Quantum circuit compositional calculus |
33+
| [string-diagram](string-diagram/) | sketch | Monoidal/braided category string diagrams |
34+
35+
## Relationship to KRL
36+
37+
KRL lives at `/var/mnt/eclipse/repos/krl` (sibling top-level repo), NOT
38+
here. This is intentional: KRL has graduated past the scaffold stage and
39+
earned its own repo. These scaffolds represent future candidates that
40+
may graduate similarly.
41+
42+
## Contribution
43+
44+
To propose a new DSL scaffold:
45+
46+
1. Create `dialects/<name>/` with at minimum `grammar-sketch.ebnf`
47+
2. Write `dialects/<name>/README.md` explaining the domain + 1-2 example programs
48+
3. Link from this README
49+
4. Keep it to a sketch — no implementation yet

dialects/braid-calculus/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Braid Calculus — Tangle DSL Sketch
2+
3+
**Status:** sketch. Grammar drafted; no parser or implementation yet.
4+
5+
## Domain
6+
7+
A direct surface language for working in Artin braid groups Bₙ.
8+
Distinct from KRL by being narrower: braids only, no closure, no knot
9+
classification. The quotient map Bₙ → Knots is explicit via a `close`
10+
primitive that hands off to KRL.
11+
12+
## What it supports
13+
14+
- Generators σᵢ (braid crossings) with exponent
15+
- Inverses σᵢ⁻¹
16+
- Multiplication of braid words
17+
- Conjugation
18+
- Markov moves (for knot invariant construction)
19+
20+
## What it does NOT do
21+
22+
- Closure to knots (that's KRL's job — use `as krl.close(b)`)
23+
- Invariant computation (that's KnotTheory.jl's job)
24+
- Persistence (that's Skein.jl's job)
25+
26+
## Example
27+
28+
```braid
29+
let s1 = sigma 1
30+
let s2 = sigma 2
31+
let trefoil_braid = s1 * s1 * s1
32+
let trefoil_conj = s2 * trefoil_braid * inverse s2
33+
is_markov_equivalent(trefoil_braid, trefoil_conj)
34+
```
35+
36+
## See also
37+
38+
- `grammar-sketch.ebnf` — formal grammar
39+
- `../../../krl/` — knot resolution language (consumes braid words via `close`)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(* SPDX-License-Identifier: PMPL-1.0-or-later *)
2+
(* Braid Calculus — Tangle DSL sketch *)
3+
4+
program = { statement } ;
5+
statement = binding | expression_stmt ;
6+
7+
binding = "let" , identifier , "=" , expression , ";" ;
8+
expression_stmt = expression , ";" ;
9+
10+
expression = mult_expr ;
11+
mult_expr = unary_expr , { "*" , unary_expr } ; (* braid multiplication *)
12+
unary_expr = "inverse" , unary_expr
13+
| atom ;
14+
15+
atom = generator
16+
| identifier
17+
| "(" , expression , ")" ;
18+
19+
generator = "sigma" , integer , [ "^" , integer ] ; (* σᵢ^k *)
20+
21+
predicate = "is_markov_equivalent" , "(" , expression , "," , expression , ")" ;
22+
23+
(* Reserved: let sigma inverse is_markov_equivalent *)

dialects/quantum-circuit/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Quantum Circuit Calculus — Tangle DSL Sketch
2+
3+
**Status:** sketch. Grammar drafted; no parser or implementation yet.
4+
5+
## Domain
6+
7+
Compositional quantum-circuit calculus. Quantum gates map naturally
8+
to Tangle's compositional operations (sequential = gate-in-time,
9+
parallel = gate-in-space via tensor product).
10+
11+
## What it supports
12+
13+
- Standard gates (H, X, Y, Z, CNOT, T, S, Swap)
14+
- Parameterised gates (Rx(θ), Ry(θ), Rz(θ), U3(θ, φ, λ))
15+
- Sequential composition (;)
16+
- Parallel composition (⊗) via tensor
17+
- Measurement operators
18+
19+
## What it does NOT do
20+
21+
- Classical simulation (defer to Yao.jl / Qiskit)
22+
- Hardware-specific calibration
23+
- Noise modelling
24+
25+
## Example
26+
27+
```qc
28+
-- Bell state preparation
29+
let bell = H on 0 ; CNOT (0, 1) ;
30+
31+
-- Grover iteration kernel
32+
let oracle = Z on 1 ;
33+
let diffuser = (H on 0) ⊗ (H on 1) ; Z on 0 ; (H on 0) ⊗ (H on 1) ;
34+
let grover_step = oracle ; diffuser ;
35+
```
36+
37+
## See also
38+
39+
- `grammar-sketch.ebnf` — formal grammar
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(* SPDX-License-Identifier: PMPL-1.0-or-later *)
2+
(* Quantum Circuit Calculus — Tangle DSL sketch *)
3+
4+
program = { statement } ;
5+
statement = binding | expression_stmt ;
6+
7+
binding = "let" , identifier , "=" , expression , ";" ;
8+
expression_stmt = expression , ";" ;
9+
10+
expression = seq_expr ;
11+
seq_expr = par_expr , { ";" , par_expr } ; (* time composition *)
12+
par_expr = atom , { "" , atom } ; (* space / tensor *)
13+
14+
atom = gate_app
15+
| identifier
16+
| "(" , expression , ")" ;
17+
18+
gate_app = fixed_gate , "on" , qubit_spec
19+
| param_gate , "(" , param_list , ")" , "on" , qubit_spec
20+
| "CNOT" , "(" , qubit_spec , "," , qubit_spec , ")"
21+
| "Swap" , "(" , qubit_spec , "," , qubit_spec , ")" ;
22+
23+
fixed_gate = "H" | "X" | "Y" | "Z" | "S" | "T" ;
24+
param_gate = "Rx" | "Ry" | "Rz" | "U3" ;
25+
26+
qubit_spec = integer ;
27+
param_list = expression , { "," , expression } ;
28+
29+
(* Reserved: let H X Y Z S T Rx Ry Rz U3 CNOT Swap on *)

dialects/string-diagram/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# String Diagram Calculus — Tangle DSL Sketch
2+
3+
**Status:** sketch. Grammar drafted; no parser or implementation yet.
4+
5+
## Domain
6+
7+
Monoidal/braided category string diagrams. Surface syntax for working
8+
with morphisms in a symmetric or braided monoidal category, with
9+
composition (∘), tensor (⊗), identity, and structural morphisms
10+
(associator, unitor, braiding).
11+
12+
## What it supports
13+
14+
- Object and morphism declarations
15+
- Sequential composition (∘, or `then`)
16+
- Tensor product (⊗, or `tensor`)
17+
- Identity morphism on an object
18+
- Braiding / symmetry
19+
- Unit object / unitor
20+
- Associator
21+
22+
## What it does NOT do
23+
24+
- Type checking beyond domain/codomain matching (would need TypeLL for that)
25+
- Categorical coherence proofs (would need Agda/Lean)
26+
- Graphical rendering
27+
28+
## Example
29+
30+
```sd
31+
object A, B, C ;
32+
morphism f : A -> B ;
33+
morphism g : B -> C ;
34+
morphism h : A -> A ;
35+
36+
let gf = f then g ; -- sequential composition A -> C
37+
let f_id = f tensor (id A) ; -- parallel with identity
38+
let braid = braiding A B ; -- symmetric structure
39+
```
40+
41+
## Connection to TangleIR
42+
43+
String diagrams generalise tangles: a tangle is a specific string
44+
diagram in a braided monoidal category where objects are "strands" and
45+
morphisms are crossings/caps/cups. KRL's `close`, `tensor`, `mirror`
46+
operations correspond to categorical operations on string diagrams.
47+
48+
## See also
49+
50+
- `grammar-sketch.ebnf` — formal grammar
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(* SPDX-License-Identifier: PMPL-1.0-or-later *)
2+
(* String Diagram Calculus — Tangle DSL sketch *)
3+
4+
program = { declaration } ;
5+
declaration = object_decl | morphism_decl | binding | expression_stmt ;
6+
7+
object_decl = "object" , identifier_list , ";" ;
8+
morphism_decl = "morphism" , identifier , ":" , type_expr , "->" , type_expr , ";" ;
9+
binding = "let" , identifier , "=" , expression , ";" ;
10+
expression_stmt = expression , ";" ;
11+
12+
type_expr = identifier
13+
| type_expr , "tensor" , type_expr
14+
| "unit" ;
15+
16+
expression = compose_expr ;
17+
compose_expr = tensor_expr , { "then" , tensor_expr } ; (**)
18+
tensor_expr = atom , { "tensor" , atom } ; (**)
19+
20+
atom = "id" , type_expr
21+
| "braiding" , type_expr , type_expr
22+
| "associator" , type_expr , type_expr , type_expr
23+
| "unitor" , type_expr
24+
| identifier
25+
| "(" , expression , ")" ;
26+
27+
identifier_list = identifier , { "," , identifier } ;
28+
29+
(* Reserved: object morphism let id tensor then braiding associator unitor unit *)

0 commit comments

Comments
 (0)