Weyl's surface syntax follows a single guiding principle: source code should read like the "Model" section of a theoretical physics paper. There are no fn keywords, :: paths, angle-bracket generics, or mutable loops. Sums, adjoints, commutators, bra-ket matrix elements, and topological-order combinators use standard physics notation, while the type system compiles every exact physical law into a static check.
Top-Level Declarations
Every .weyl file is a sequence of top-level statements introduced by 12 English verbs. Phrase-shaped derivations (such as pCUT of H around H₀ to O(x¹⁵)) correspond to fixed, unambiguous grammar productions rather than free-form natural language.
| Verb | Semantic Role | Representative Example |
|---|---|---|
model | Names the module and physical system | model Z₂ toric code with a rough boundary |
units | Sets natural units (quotienting the dimension group ) | units ℏ = k_B = 1 |
given | Introduces lattices, Hilbert-space degrees of freedom, parameters, symmetries, or topological orders | given σ : qubit on edges(Λ) |
define | Defines operators, Hamiltonians, dispersions, or combinator models | define A_v ≔ ∏_{l ∋ v} σˣ_l for v ∈ vertices(Λ) |
claim | Asserts a physical proposition (3-tier decision: typer → kernel → Lean) | claim H : Hermitian, local |
check | Triggers exact kernel verification on concrete finite instances | check all claims for G = S₃, K ∈ subgroups(S₃) |
require | Declares static/runtime error-gating thresholds and fallback clauses | require uncertainty of x_c < 10⁻³ otherwise ... |
expand | Requests a canonical perturbative expansion (pCUT / SW) in a sector | expand H_eff ≔ pCUT of H around H₀ to O(x¹⁵) |
solve | Solves algebraic consistency equations for unknown operator coefficients (Phase 2, modular Gröbner bases in weyl-num) | solve for a such that a a = a, S[a] = a modulo G |
estimate | Extrapolates a truncated series (output tagged Epistemic) | estimate (x_c, zν) from Δ by dlog-Padé in x |
compare | Invokes an independent analytical or numerical oracle | compare H_eff with free fermions at κ₁ = κ₂ = 0 |
theorem | States a universally quantified theorem (falsify first, then Lean 4) | theorem for all G, K : [A_v^K, T_l^K] = 0 |
Syntactic Separation of Finite Checks and Universal Theorems
Weyl strictly separates check … for G = S₃ (exact finite-instance verification in the kernel) from theorem for all G, K (universal mathematical statement routed to Lean 4). The type checker never conflates passing a finite check with proving a universal theorem.
Unicode Math Notation & ASCII Equivalents
Unicode is the canonical representation, and every mathematical symbol has a LaTeX-style ASCII fallback. weylc fmt normalizes ASCII into Unicode and warns about confusable homoglyphs (such as Greek ν vs. Latin v).
| Canonical Unicode | Meaning | ASCII Fallback |
|---|---|---|
A ≔ … | Declarative definition | := |
Σ_{v ∈ V}, Σ_⟨i,j⟩, ∏_{l ∋ v} | Domain sum, nearest-neighbor sum, product | \sum_{v \in V}, \sum_<i,j>, \prod |
σˣ_l, S^a_i, c†_{kσ} | Superscript component, subscript site/momentum, adjoint | sigma^x_l, c^\dagger_{k sigma} |
[A, B], [A, B]₊ | Commutator, anticommutator ({…} is reserved for sets) | [A, B], [A, B]_+ |
|ψ⟩, ⟨φ|, ⟨φ|O|ψ⟩ | Ket, bra, matrix element / expectation value | |psi>, <phi|, <phi|O|psi> |
A ⊗ B, M₁ ⊠ M₂, Γ₁ ⊕ Γ₂ | Tensor product, stacking systems, direct sum of irreps | \otimes, \boxtimes, \oplus |
g ▷ O, 𝒯 ▷ O | Group or anti-unitary symmetry action on operators | act(g, O) |
… + O(x¹⁵) | Truncation remainder monomial ideal tag | O(x^15) |
a = b, a ≈ b within … | Exact equality (Exact only), approximate equality within bound | ~= |
Six Disambiguation Rules
Six conventions keep mathematical notation unambiguous without heavy punctuation. Juxtaposition always denotes multiplication—J A_v B_p is the product of three factors, while function application is restricted to identifiers declared as functions such as ε(k). Index roles are resolved from given declarations during type-directed elaboration rather than guessed lexically, distinguishing component indices like x in σˣ_l from exponents like 2 in x². Sums and products (Σ and ∏) follow blackboard convention by binding tighter than +/− and looser than juxtaposition, so their body extends to the next top-level + or −.
Index binding and brackets follow equally strict rules. Einstein summation applies only to repeated component indices such as S^a_i S^a_j; repeating an unbound lattice or momentum index triggers E0210 so accidentally dropped sums do not slip through. Free indices are universally quantified over their enclosing definition, as with v in define A_v ≔ … for v ∈ vertices(Λ). Finally, anticommutators never use braces: [A, B]₊ denotes the anticommutator, leaving {1, e} unambiguously for sets and subgroups.
Lattices, Hilbert Spaces & Operator Algebra
The physical identity on the right-hand side of given determines the algebra, type indices, and legal operations for every derived expression:
-- Lattice geometry and boundary terminations
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
-- Local Hilbert-space degrees of freedom
given σ : qubit on edges(Λ) -- Pauli algebra, Herm generators
given c↑, c↓ : fermion on vertices(Λ) -- CAR; also `boson` (CCR) and `Majorana`
given |g⟩ : basis of ℂ[G] on edges(Λ) for g ∈ G -- Finite-group algebra basis
-- Parameter identities
given J : positive integer -- Compile-time symbolic integer (pCUT A3)
given x, κ₁, κ₂ : small parameter -- Expansion variables introducing TruncSymmetry statements are written as in a paper and decided by representation theory. Spin groups act on spin and real space separately, [R_spin ‖ R_space]; a state and the tensors measured in it are declared, and each claim is checked exactly: the irrep of a Brillouin-zone function by projection with the character table, a nodal line by restricting the function to it, a vanishing or allowed tensor component from the invariant subspace of the tensor under the group.
model d-wave altermagnet on the square lattice
units ℏ = 1
given Λ : square lattice (lattice constant a : length)
given t, t_J : energy
given 𝒢 : spin group generated by [E ‖ mmm], [C₂⊥ ‖ C₄z], [𝒯_s C₂⊥ ‖ 𝒯_r], spin rotations about z
given ρ : equilibrium state invariant under 𝒢
given M : magnetization in ρ
given σ_ij : charge conductivity, response of electric current to electric field in ρ
given σˢ_ij : z-spin conductivity, response of z-spin current to electric field in ρ
define ε(k) ≔ − 2 t (cos(k_x a) + cos(k_y a))
define J(k) ≔ 2 t_J (cos(k_x a) − cos(k_y a))
define Δ(k) ≔ 2 J(k)
claim Δ : B₁g of 4/mmm
claim Δ(k) = 0 on k_x = ± k_y
claim M_z = 0
claim σ_[xy] = 0
claim σ_(xy) = 0
claim σ_xy = 0
claim σˢ_xx − σˢ_yy : allowedChanging B₁g to A₁g, the nodal line to k_x = 0, or M_z = 0 to M_z : allowed is rejected with E0520 or E0530. Replacing [C₂⊥ ‖ C₄z] by [E ‖ C₄z] describes a ferromagnet, and both the moment and the -wave spin conductivity claims flip.
units ℏ = 1
given Λ : square lattice (lattice constant a : length)
given c_{kσ} : fermion, k ∈ BZ(Λ), σ ∈ {↑, ↓}
given t, t_J : energy
given 𝒢 : spin group generated by [E ‖ mmm], [C₂⊥ ‖ C₄z], [𝒯_s C₂⊥ ‖ 𝒯_r], spin rotations about z
define ε(k) ≔ − 2 t (cos(k_x a) + cos(k_y a))
define J(k) ≔ 2 t_J (cos(k_x a) − cos(k_y a))
define H ≔ Σ_k Σ_σ (ε(k) + σ J(k)) c†_{kσ} c_{kσ}
claim H : Hermitian, invariant under 𝒢, conserves N and Sᶻ
define Δ(k) ≔ E_↑(k) − E_↓(k)
define Mᶻ ≔ Σ_k ⟨c†_{k↑} c_{k↑} − c†_{k↓} c_{k↓}⟩
claim Δ(k) = 2 J(k) -- computed by the kernel, exact
claim Δ : B₁g of 4/mmm
claim Mᶻ = 0 -- Selection rule: odd under [C₂⊥ ‖ C₄z], type ZeroBy design, adding a Rashba term, which breaks inversion , should be rejected during type checking with:
error[E0520]: term is not invariant under the declared symmetry 𝒢
| + α Σ_k (k_x σʸ − k_y σˣ)_{σσ′} c†_{kσ} c_{kσ′}
| k is a polar vector (𝒫-odd), σ is an axial vector (𝒫-even): the term is 𝒫-odd,
| but 𝒫 ∈ mmm ⊂ 𝒢; it also breaks spin rotations about zHigh-Level Physics Combinators
Weyl provides seven orthogonal, nestable combinators, each with a canonical microscopic expansion inspectable via weylc explain --expand:
define TC ≔ gauge ℤ₂ in (paramagnet on vertices(Λ)) -- infers topological order D(ℤ₂)
define 𝒟 ≔ condense {1, e₁e₂} in D(ℤ₂) ⊠ D(ℤ₂) -- type checker derives 𝒟 ≅ D(ℤ₂)
define ∂ ≔ boundary terms of TC at ∂Λ condensing {1, e} -- synthesizes rough boundary terms
claim dual of (R + x S) under KW(∂Λ) = S + x R -- Kramers–Wannier self-dualityTypes as Physical Rules
Weyl models every physical quantity's type as a base type × tuple of algebraic indices. Multiplication acts homomorphically on indices (dimensions add, parities multiply, group representations tensor), while addition requires strict indices (dimensions, parity, polar/axial character) to match identically and joins mixable indices (grading, conserved charges, irreps):
| Physical Law | Type Mechanism | Static Decision Procedure | Diagnostic |
|---|---|---|---|
| Dimensions & natural units | Index: free abelian group (quotient) | Smith normal form linear solver | E0510 |
| Statistics & graded commutation | Index: grading group & bicharacter | Bicharacter lookup & even-fermion check | E0305 / E0306 |
| Hermiticity, unitarity, projectors | Refinement: Herm / Unitary / Projector | Compositional rules (e.g., group average → projector) | E0301 / E0302 |
| Group irreps & selection rules | Restricted dependent: Irrep(G) & singleton Zero | Character-table inner product, | E0520 / E0530 |
| Topological boundary condensation | Refinement + dependent: Lagrangian | Fixed-point centralizer quotient space | E0311 / E0360 |
Quantum Double Boundaries & Three-Tier claim Decision
For Kitaev's quantum double with a gapped boundary specified by a subgroup (examples/quantum_double_boundary.weyl), the syntax demonstrates both group-average projector inference and the boundary between finite check and universal theorem:
model quantum double D(G) with a gapped boundary of type K
given G : finite group
given K : subgroup of G
given Λ : oriented square lattice on a half-plane, ∂Λ : boundary of Λ at y = 0
given |g⟩ : basis of ℂ[G] on edges(Λ) for g ∈ G
define L₊^g ≔ Σ_{h ∈ G} |g h⟩⟨h|
define L₋^g ≔ Σ_{h ∈ G} |h g⁻¹⟩⟨h|
define T^h ≔ |h⟩⟨h|
define A_v^g ≔ ∏_{l out of v} L₊^g_l · ∏_{l into v} L₋^g_l
define A_v ≔ 1/|G| Σ_{g ∈ G} A_v^g
define B_p ≔ projector onto holonomy(∂p) = 1
define A_v^K ≔ 1/|K| Σ_{k ∈ K} A_v^k for v ∈ vertices(∂Λ)
define T_l^K ≔ Σ_{k ∈ K} T^k_l for l ∈ edges(∂Λ)
define H ≔ − Σ_{v ∉ ∂Λ} A_v − Σ_p B_p − Σ_{v ∈ ∂Λ} A_v^K − Σ_{l ∈ ∂Λ} T_l^K
claim A_v^g : unitary, and g ↦ A_v^g : representation of G
claim A_v, A_v^K, T_l^K : projector -- inferred from unitary group average
given 𝒞 : topological order D(G)
claim ∂Λ condenses 𝒜(K) : Lagrangian algebra of 𝒞
check all claims for G = S₃, K ∈ subgroups(S₃) -- Tier 2: exact finite-instance kernel
theorem for all G, K : [A_v^K, T_l^K] = 0 -- Tier 3: falsify, then Lean 4
falsify on G ∈ {ℤ₂, S₃, D₄}To preserve decidability while supporting full mathematical expressiveness, every claim runs through a strict three-tier decision pipeline with zero silent acceptance. First, the polynomial-time type checker decides dimensions, parities, abelian charges, character-table selection rules (Mᶻ = 0), and compositional Hermiticity or projector refinements. Claims that require explicit algebraic evaluation pass to the deterministic kernel (Exact layer), which verifies concrete identities and finite instances such as Δ(k) = 2 J(k), check … for G = S₃, and H = H_explicit exactly. Finally, universally quantified for all statements go to the Lean 4 sandbox, which first runs quick counterexample falsification (falsify on …) on small groups before exporting the proof obligation to Lean 4; if all three tiers fail, compilation reports an unproven diagnostic.
Elaboration into HIR and Core Type System λ_Weyl
Surface syntax lowers into the core type system via a two-stage frontend (for the full specification and implementation gaps, see Type System). In the first stage (weyl-syntax), a hand-written recursive-descent parser builds a lossless rowan concrete syntax tree (CST) that preserves all whitespace, comments, and source spans for LSP tooling and weylc fmt, leaving ambiguous superscripts and juxtapositions unresolved. In the second stage (weyl-types + weyl-hir), type-directed elaboration resolves names and scopes, maps physical vocabulary onto the internal first-order operator type OpTy (algebra, grade, anyon charge, Hermiticity class, symbolic support template, strict physical indices, and fermion parity) paired with the error grade Err = Trunc × EpiKind, and emits a typed HirModule.
In , types depend only on indices—never on terms—and there is no λ-abstraction or general dependent typing. Supports and grades are represented as offsets relative to a region-class representative and never mention the lattice size , so the result of type checking is -independent by construction:
// Actual core value types in weyl-types (spec forms State, {v:τ|φ}, Π α:κ.τ are not implemented)
enum Ty {
Scalar(ScalarTy), // Nat | Int | Real | Complex | Bool
Series { base: ScalarTy, vars: VarSet, val: Valuation },
Op(OpTyId), // interned OpTy (grade, charge, herm, supp, strict, fermion_grade)
Zero, // selection-rule or commutator zero type
Model(Box<ModelTy>), // high-level model constructor
}
struct Typed { ty: Ty, err: Err } // τ @ (I, E, m)Run-Time Admissibility Check for High-Level Combinators
After combinators like stack, couple, gauge, and dual expand into microscopic HIR terms, check_admissible erases the synthesized ModelTy to OpTy and compares it with the expansion's type (currently checking Hermiticity, fermion parity, algebra, strict indices, and grade, not charge or support). Any mismatch triggers internal compiler error E0001.