Weyl is a compiled, declarative domain-specific language (DSL) for theoretical condensed-matter and mathematical physics. Physicists author lattice Hamiltonians, symmetries, topological orders, and perturbation workflows in .weyl source files; the weylc compiler executes all symbolic algebra, perturbative expansions, and rational reconstructions inside a deterministic kernel, then validates results through independent analytical or numerical oracles.
Rather than gluing together an untyped computer algebra system and ad-hoc numerical scripts, Weyl embeds exact physical laws into a static type system, records truncation orders and extrapolation uncertainty in error tags, and does not let an LLM modify algebraic results directly.
Not a general-purpose language
Unlike Lean 4, Weyl has no general standard library: no networking, IPC, or filesystem access. I/O is handled by weylc, not by Weyl code.
Why Weyl Exists
High-order theoretical calculations—such as multi-parameter pCUT expansions, gapped boundary condensation in topological phases, or multi-orbital Schrieffer–Wolff transformations—tend to break down in three recurring ways. Physical invariants usually live only in the author's head, so dimensional mismatches, non-anti-Hermitian generators, symmetry-breaking couplings, or non-equidistant unperturbed spectra passed to pCUT go undetected until hours of numerical post-processing yield nonsensical output. Meanwhile, general-purpose scripts collapse exact quantities and approximations into bare floating-point numbers or untagged polynomials, silently mixing a series truncated at , a critical point extrapolated via dlog-Padé, and a finite-size exact diagonalization (ED) eigenvalue. Worse still, derivation and verification routinely share code: checking an expansion script with the same stabilizer mapping or basis transformation catches typos, not systematic modeling bugs.
Phase 1 End-to-End Target
Weyl v0.1 targets the pure boundary phase transition of the toric code on a rough–smooth cylinder in two stages. In Stage A (, the projected limit), the compiler infers the boundary effective algebra from the topological-order types, runs pCUT to order 14 (remainder ), and verifies every rational coefficient against the exact Jordan–Wigner free-fermion solution. In Stage B (finite bulk gap ), it executes multi-particle pCUT in through total order 10, cross-checks against an independent double-double ED oracle, and extrapolates via dlog-Padé.
Types Are Representations
An operator's type is its representation content under the declared symmetry group, and the typing rules are operations in the representation ring: a product is a tensor-product decomposition, a sum is a direct sum, a selection rule is , and invariant under 𝒢 means the operator lies in the trivial isotypic component. A group is declared by how its generators act on modes (given 𝒢 : symmetry generated by P, S with P : … ↦ …); weylc closes it into a finite group, checks invariance exactly, and writes effective Hamiltonians in the basis of invariant operators, so an expansion only has to fix the reduced coefficients. See Representation Theory.
Algebra comes only from the deterministic kernel, every value carries an error tag, verification never shares code with derivation, and results are byte-for-byte reproducible.
Freedom & Elegance
At the language level, Weyl follows a philosophy of "freedom and elegance". Types check physical and mathematical correctness rather than style: every type error corresponds to a violated law, verbose term-by-term explicit Hamiltonians remain completely legal, and the compiler never emits style warnings or "elegance scores." At the same time, first-class abstractions match how physicists actually reason—symmetries, dualities (dual), anyon condensation (condense), gauging (gauge), stacking (stack / ⊠), coupling (couple), and integrating out high-energy modes (integrate out) are native constructs rather than index loops over matrices.
Because these high-level combinators are orthogonal and composable, a new theory often reduces to a single line such as define 𝒟 ≔ condense {1, e₁e₂} in D(ℤ₂) ⊠ D(ℤ₂), from which the type checker derives the fusion rules and resulting topological order automatically. Throughout, the compiler never rewrites user expressions: canonical forms are computed internally solely for verification, so diagnostics, weylc explain, and weylc fmt preserve the author's physical formulation instead of forcing a normal form back onto source code.
Quickstart with the weylc CLI
Although the Weyl workspace comprises 18 Rust crates, it ships a single executable binary, weylc. It includes a built-in heuristic scheduler so every compilation, expansion, and verification pipeline runs fully offline without an LLM:
# 1. Static type checking and physical rule verification (Hermiticity, locality, condensates)
$ weylc check examples/toric_boundary.weyl
ok: 4 claims verified statically (Hermitian, local, [A_v, B_p] = 0, [P_i, σˣ_{d_i}]₊ = 0)
ok: boundary condensates ∂Λ → {1, e}, ∂top → {1, m} verified at fixed point (x=0, κ₁=0, κ₂=0)
# 2. Run high-order pCUT expansion and inspect error-tagged observable series
$ weylc expand examples/toric_boundary.weyl --stage A
ok: H_eff expanded via pCUT to O(x¹⁵) [Exact rational coefficients reconstructed over 4 primes]
e₀ = -1 - 1/4 x² - 1/64 x⁴ - 1/256 x⁶ - 25/16384 x⁸ + ... + O(x¹⁵)
Δ = 2 - 2 x + O(x¹⁵)
# 3. Full pipeline: dlog-Padé extrapolation, exact free-fermion check, and ED oracle
$ weylc run examples/toric_boundary.weyl --seed 20261128
ok: compare H_eff with free fermions (κ₁=κ₂=0) -> PASS (14/14 orders exact rational match)
ok: estimate (x_c, zν) -> x_c = 1.0000(2) [Epi{PadeSpread(dlog-Padé)}], zν = 1.000(1) [Epi{PadeSpread(dlog-Padé)}]
# 4. Export universal theorems (`theorem for all G, K`) to the Lean 4 sandbox
$ weylc prove examples/quantum_double_boundary.weyl
# 5. Start the MCP server so an external LLM agent can schedule passes via JSON Schema
$ weylc mcp --replay-log run.jsonlInspecting Inferred Physics Types
Run weylc explain examples/toric_boundary.weyl to print the inferred physical type of every declaration (Hermiticity, anyon charge, support, and error tag). Pass --expand to view the microscopic lattice terms generated by high-level combinators like gauge and condense without altering the source file.
End-to-End Walkthrough: Z2 Toric Code Boundary
Consider a square lattice on a cylinder of circumference and height , hosting qubits. The bottom boundary has dangling edges (rough termination), while the top boundary terminates smoothly with three-edge truncated stars. The microscopic Hamiltonian is:
where . When , the boundary operators commute with all bulk stabilizers and map onto the 1D transverse-field Ising chain with dispersion and self-dual transition . Turning on creates virtual bulk -anyons (costing per star flip), renormalizing the effective boundary coupling starting at order .
The entire model, its static claims, multi-parameter pCUT expansion, and dual oracle checks fit in 40 lines of .weyl (examples/toric_boundary.weyl):
model Z₂ toric code with a rough boundary
given Λ : square lattice on a cylinder (circumference L, height W)
given ∂Λ : boundary of Λ at y = 0 with dangling edges d_i
given ∂top : smooth termination of Λ at y = W
given σ : qubit on edges(Λ)
given J : positive integer -- equidistant spectrum precondition (A3)
given x, κ₁, κ₂ : small parameter -- expansion variables tracked in Trunc
define A_v ≔ ∏_{l ∋ v} σˣ_l for v ∈ vertices(Λ)
define B_p ≔ ∏_{l ∈ ∂p} σᶻ_l for p ∈ plaquettes(Λ)
define P_i ≔ σᶻ_{d_i} σᶻ_{h_i} σᶻ_{d_{i+1}} for i ∈ cells(∂Λ)
given 𝒞 : topological order D(ℤ₂)
with e ↔ A_v = −1, m ↔ B_p = −1 or P_i = −1
define H₀ ≔ − J Σ_v A_v − J Σ_p B_p − Σ_i P_i
define V ≔ − x Σ_i σˣ_{d_i} − κ₁ Σ_i σᶻ_{d_i} − κ₂ Σ_i σᶻ_{h_i}
define H ≔ H₀ + V
claim H : Hermitian, local
claim [A_v, B_p] = 0 and [P_i, σˣ_{d_i}]₊ = 0
claim ∂Λ condenses {1, e} at x = 0, κ₁ = 0, κ₂ = 0
claim ∂top condenses {1, m} at x = 0, κ₁ = 0, κ₂ = 0
expand H_eff ≔ pCUT of H around H₀
to O(x¹⁵) at κ₁ = κ₂ = 0, to total order 10 in (x, κ₁, κ₂) otherwise
in the sector where every conserved A_v, B_p equals +1
define E_bulk ≔ −J (2W + 1) L
define e₀ ≔ (⟨vac| H_eff |vac⟩ − E_bulk) / L
define ω(k) ≔ one-particle dispersion of H_eff
define Δ ≔ ω(0)
estimate (x_c, zν) from Δ by dlog-Padé in x
compare H_eff with free fermions at κ₁ = κ₂ = 0
compare H_eff through total order 10 with exact diagonalization on L = 12, W = 2
by vacuum sector (k = 0, W_e^top = +1)
and one-particle sector (k, W_e^top = −1)
using double-double arithmetic, residual protocol of section 6.7If line 7 is accidentally declared as given J : real number, weylc rejects the program statically before touching the perturbation engine:
error[E0412]: pCUT requires a provably equidistant unperturbed spectrum
--> toric_boundary.weyl:7:8
| given J : real number
| excitation energies of H₀ are {2 (P_i), 2J (A_v), 2J (B_p)}: J is a continuous symbol,
| so no common energy quantum exists for all J
= help: write `given J : positive integer` (assumption A3), or use epCUT (planned for Phase 2)Alternatively, the exact same Hamiltonian can be expressed via high-level combinators (examples/toric_gauge_combinators.weyl), letting the type checker synthesize the topological order and boundary condensates automatically:
define bulk ≔ gauge ℤ₂ in (J · paramagnet on vertices(Λ)) with flux energy J
define R ≔ boundary terms of bulk at ∂Λ condensing {1, e}
define S ≔ boundary terms of bulk at ∂Λ condensing {1, m}
define H₀ ≔ bulk − R
define H ≔ H₀ − x S − κ₁ Σ_i σᶻ_{d_i} − κ₂ Σ_i σᶻ_{h_i}
claim dual of (R + x S) under KW(∂Λ) = S + x R -- self-dual boundary at x = 1
claim H = H_explicit -- kernel verifies exact equivalenceGlobal Engineering Assumptions (A1–A7)
To keep Phase 1 tractable and verifiable from day one, Weyl v0.1 locks down seven explicit engineering assumptions:
| ID | Assumption | Scope |
|---|---|---|
| A1 | Rust Edition 2024; MSRV tracks latest stable minus two releases | All 18 crates |
| A2 | Phase 1 supports qubit degrees of freedom (Pauli algebra) and abelian | Type system, canonicalizer |
| A3 | pCUT requires an equidistant unperturbed spectrum, so Stage B restricts to positive integers | Target scope & E0412 |
| A4 | Coefficient field is or , computed over 63-bit primes and reconstructed | CAS, weyl-num, oracles |
| A5 | Single-node target (64 cores, 256 GB RAM, local NVMe spill); distributed execution deferred | External-memory reducer |
| A6 | LLMs connect via replaceable MCP; offline runs use the built-in heuristic scheduler | weyl-mcp, weylc |
| A7 | Never link GPL (FORM/GAP) or proprietary (Symbolica) libraries; use algorithms or process isolation | Licensing & FFI |
How Weyl Compares to Existing Tools
Weyl does not aim to replace general-purpose languages such as Julia, Python, or Lean 4; it occupies the intersection of static physical type checking, streaming non-commutative perturbation algebra, and isolated oracle verification:
| Dimension | Weyl | Mathematica / SymPy | Lean 4 | Julia (ITensor / QuantumClifford) |
|---|---|---|---|---|
| Core abstractions | Lattice operators, symmetries, topological orders, error lattice | Generic expression trees & pattern rules | Dependent types & constructive proofs | High-performance arrays, tensor networks, multiple dispatch |
| Physical rule checking | Static, lattice-size-polymorphic, polynomial-time | None (runtime assertions or manual checks) | Expressible, but high proof-engineering overhead | Basic unit packages; no fusion rings or selection rules |
| Approximation semantics | Error tags (monomial ideals + error sources) | Manual SeriesData or raw floats | Exact logic only; no extrapolation tracking | Floating-point or interval arithmetic; no truncation/epistemic split |
| High-order non-commutative CAS | Streaming KIR + 63-bit prime-field CRT reconstruction | Heap-heavy generic objects bottleneck at terms | Unsuited for multi-million-term streams | Hand-rolled per-project code without a symbolic middle end |
| Ecosystem interop | Exports to ITensor/TeNPy; delegates theorem to Lean 4 | Proprietary runtime or Python glue | Serves as Weyl's universal-theorem backend | Downstream numerical execution target for Weyl TIR |
Scope & Reuse Policy
Weyl only builds what does not already exist elsewhere: Gröbner bases are meant to delegate to msolve and finite-group tables to offline GAP data re-verified on load (today both are computed in-process by weyl-num and weyl-topo), universal theorems go to Lean 4, and large-scale numerical solves export from TIR to mature ED or tensor-network libraries.