Skip to content
Getting Started & Language · Overview

Overview & Design Philosophy

A compiled, declarative domain-specific language for theoretical and mathematical physics whose type system is built on representation theory, with an end-to-end Z2 toric code walkthrough.

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 O(x15)O(x^{15}), a critical point xcx_c 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 Z2\mathbb{Z}_2 toric code on a rough–smooth cylinder in two stages. In Stage A (κ1=κ2=0\kappa_1 = \kappa_2 = 0, the J→∞J \to \infty projected limit), the compiler infers the boundary effective algebra from the topological-order types, runs pCUT to order 14 (remainder O(x15)O(x^{15})), and verifies every rational coefficient against the exact Jordan–Wigner free-fermion solution. In Stage B (finite bulk gap J∈{1,2}J \in \{1, 2\}), it executes multi-particle pCUT in (x,κ1,κ2)(x, \kappa_1, \kappa_2) through total order 10, cross-checks against an independent double-double ED oracle, and extrapolates (xc,zν)(x_c, z\nu) 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 Hom(1,ρ)=0\mathrm{Hom}(\mathbf{1}, \rho) = 0, 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:

bash
# 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.jsonl

Inspecting 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 Λ\Lambda on a cylinder of circumference LL and height WW, hosting (2W+2)L(2W+2)L qubits. The bottom boundary y=0y = 0 has dangling edges did_i (rough termination), while the top boundary y=Wy = W terminates smoothly with three-edge truncated stars. The microscopic Hamiltonian is:

H=−J∑vAv−J∑p∈bulkBp−∑iPi−x∑iσdix−κ1∑iσdiz−κ2∑iσhizH = -J \sum_v A_v - J \sum_{p \in \mathrm{bulk}} B_p - \sum_i P_i - x \sum_i \sigma^x_{d_i} - \kappa_1 \sum_i \sigma^z_{d_i} - \kappa_2 \sum_i \sigma^z_{h_i}

where Pi=σdizσhizσdi+1zP_i = \sigma^z_{d_i}\sigma^z_{h_i}\sigma^z_{d_{i+1}}. When κ1=κ2=0\kappa_1 = \kappa_2 = 0, the boundary operators commute with all bulk stabilizers and map onto the 1D transverse-field Ising chain H∂=−∑τx−x∑τzτzH_\partial = -\sum \tau^x - x \sum \tau^z \tau^z with dispersion ω(k)=21+x2−2xcos⁡k\omega(k) = 2\sqrt{1 + x^2 - 2x\cos k} and self-dual transition xc=1x_c = 1. Turning on κ1,κ2\kappa_1, \kappa_2 creates virtual bulk ee-anyons (costing 2J2J per star flip), renormalizing the effective boundary coupling starting at order xκ12x\kappa_1^2.

The entire model, its static claims, multi-parameter pCUT expansion, and dual oracle checks fit in 40 lines of .weyl (examples/toric_boundary.weyl):

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.7

If line 7 is accidentally declared as given J : real number, weylc rejects the program statically before touching the perturbation engine:

bash
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:

weyl
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 equivalence

Global Engineering Assumptions (A1–A7) ​

To keep Phase 1 tractable and verifiable from day one, Weyl v0.1 locks down seven explicit engineering assumptions:

IDAssumptionScope
A1Rust Edition 2024; MSRV tracks latest stable minus two releasesAll 18 crates
A2Phase 1 supports qubit degrees of freedom (Pauli algebra) and abelian D(G)D(G)Type system, canonicalizer
A3pCUT requires an equidistant unperturbed spectrum, so Stage B restricts JJ to positive integersTarget scope & E0412
A4Coefficient field is Q\mathbb{Q} or Q(λ1,…,λk)\mathbb{Q}(\lambda_1,\dots,\lambda_k), computed over 63-bit primes and reconstructedCAS, weyl-num, oracles
A5Single-node target (64 cores, 256 GB RAM, local NVMe spill); distributed execution deferredExternal-memory reducer
A6LLMs connect via replaceable MCP; offline runs use the built-in heuristic schedulerweyl-mcp, weylc
A7Never link GPL (FORM/GAP) or proprietary (Symbolica) libraries; use algorithms or process isolationLicensing & 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:

DimensionWeylMathematica / SymPyLean 4Julia (ITensor / QuantumClifford)
Core abstractionsLattice operators, symmetries, topological orders, error latticeGeneric expression trees & pattern rulesDependent types & constructive proofsHigh-performance arrays, tensor networks, multiple dispatch
Physical rule checkingStatic, lattice-size-polymorphic, polynomial-timeNone (runtime assertions or manual checks)Expressible, but high proof-engineering overheadBasic unit packages; no fusion rings or selection rules
Approximation semanticsError tags (monomial ideals + error sources)Manual SeriesData or raw floatsExact logic only; no extrapolation trackingFloating-point or interval arithmetic; no truncation/epistemic split
High-order non-commutative CASStreaming KIR + 63-bit prime-field CRT reconstructionHeap-heavy generic objects bottleneck at 107+10^7+ termsUnsuited for multi-million-term streamsHand-rolled per-project code without a symbolic middle end
Ecosystem interopExports to ITensor/TeNPy; delegates theorem to Lean 4Proprietary runtime or Python glueServes as Weyl's universal-theorem backendDownstream 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.

Weyl v0.1 · MIT License