This page defines Weyl's core type system precisely. The rules are implemented in weyl/crates/weyl-types (rules and type representations) and weyl/crates/weyl-hir (the elaborator that calls the rules). Where the compiler checks less than a rule states, this page says so explicitly.
How to read this page
Unless marked otherwise, everything on this page is checked by the current compiler, and the text notes where the implementation is narrower than the rule. Parts of the calculus that the compiler does not yet implement carry a Draft badge. The metatheoretic statements of §8 are conjectures: none of them currently has a complete paper proof or has been machine-checked.
1. Position
Definition. is a first-order type system with indexed types, a small number of decidable refinement classes, and error grades attached to typing judgments. Its term language is an expression language for lattice operator algebras.
| Claim | Holds? | Reason |
|---|---|---|
| is a (typed) λ-calculus | No | The term syntax has no λ-abstraction , no first-class functions, no β-reduction. The "λ" in the name is only a naming convention. |
| is a dependent type theory | No (only in a restricted sense) | Types depend on indices only, never on terms, and there is no definitional equality by term reduction. It belongs to the Dependent ML (Xi–Pfenning) family of indexed type systems. |
| Types can be polymorphic in indices () | In the spec, not in the implementation | All indices in the implementation are concrete. -independence is not obtained via ; it holds because never appears in a type (§5.6). |
| It is a graded monad | Not strictly | There are no return / bind terms; grades are just attached to the judgment . "Graded typing judgment" is the accurate term. |
| It is a proof assistant | No | It cannot express arbitrary propositions; universally quantified statements are routed to Lean (§7). |
| The metatheorems are proven | No | See §8. |
Relation to existing systems:
| Source | Borrowed | Not borrowed |
|---|---|---|
| Kennedy's units-of-measure types | Dimensions as indices in the free abelian group , compared on addition | Dimension variables and polymorphism (not implemented) |
| Dependent ML / ATS | Separation of an index layer from the term layer; constraints discharged by decision procedures | Index variables, , existentials (not implemented) |
| Refinement types (DML, Liquid Types) | in the spec | The implementation has no general refinement types, only fixed "class" fields (Hermiticity, parities) |
| Graded effects (graded monads / coeffects) | Grades from an ordered algebraic structure, composed along the rules | Monadic term formers |
| Bidirectional typing | Synthesis () separated from checking () | The implementation only synthesizes; checking appears only at claim, as "synthesize, then compare" |
2. Signature
The signature is a globally fixed context built from the given and units declarations and left implicit in the typing rules. It comprises four components. First, the lattice specifies the unit cell, sublattices (such as d, h, and u), topology (Cylinder, Torus, or Plane), and open-end terminations (weyl-hir/src/lattice.rs; square lattices and finite chains only). Second, the operator algebra families declare generators, their grades, and the commutation bicharacter (the Pauli algebra with grading group is typed by its bicharacter; fermion, boson and Majorana modes are typed by exact normal ordering, see §5.1 and §5.4). Third, the topological theory supplies anyon labels and fusion rules (abelian theories in the type checker; non-abelian through the gauge-model checks). Finally, the signature records the symmetry group together with natural-unit relations (units ℏ = 1, ...) (for operator types a symmetry group records only whether it contains spatial inversion / time reversal, plus generator names; spin groups written [R_spin ‖ R_space] are kept as explicit finite groups and used for selection rules, see Spintronics).
Signature well-formedness (ε is a bicharacter, pentagon and hexagon equations hold, ...) has no single entry point in the implementation; it is spread across data validation in crates such as weyl-topo.
3. Syntax
3.1 Specified syntax
index sorts κ ::= Dim | Vec | Par | Grade(𝔄) | Charge(𝒞) | Rep(G) | Herm | Supp(Λ) | Val | FPar
indices i ::= α | c | i · i | i⁻¹ | i ⊔ i | i ⊗ i | supp(i)
constraints φ ::= i = i | i ≤ i | 1 ∉ i | φ ∧ φ | ∀α:κ. φ
grades ε ::= (I, E, m) -- defined in §6
types τ ::= Scalar[σ]
| Op_𝔄[γ; q; ρ; h; S; σ; f]
| State[q; ρ]
| Series_x⃗[v](τ)
| Zero
| {v : τ | φ}
| Π α:κ. τ
| Model[Λ; 𝔄; G; 𝒞@θ] -- high-level constructs, §5.9
terms e ::= x | n | c -- variable, integer, scalar constant
| g_s -- signature generator g at site s
| e e | e + e | e − e | c · e | e†
| [e, e] | [e, e]₊
| Σ_{s ∈ D} e | ∏_{s ∈ D} e -- D a finite site domain
| ⟨ψ| e |ψ′⟩
| f(e, …, e) -- saturated application of a signature primitive (cos, exp, log, ...)
| expand_M(e; e; I) | estimate_M(e)
| Λα. e | e[i] -- index abstraction and index application
declarations d ::= units … | given x : τ | define x ≔ e | claim P | require … | expand … | estimate …Here are the strict indices: dimension (exponents of energy, length, time, charge), character , and time-reversal / inversion parities , (each , or unknown). is the fermion parity.
Three remarks on the grammar. There is no function type : the term syntax has no introduction form for one (no λ-abstraction), so functions such as cos and exp are first-order primitives in that may only be applied saturated. Scalar multiplication is written . And although the operator type is often abbreviated to five components, , the typing rules (strict indices in Add and the fermion-parity check in T-Ham) also rely on and , so both components are part of the type here.
3.2 Structural facts
Several structural consequences follow directly from the syntax, independently of any theorem. The language has only two term-level binders: and bind a site variable over a finite domain , while binds an index variable (Draft); nothing ever abstracts over a term variable. Consequently, there are no higher-order functions, no β-reduction, and no recursion—a define declaration merely names an expression. Furthermore, because only indices and never terms appear inside types, type equality reduces entirely to equality in the index theories and never requires evaluating terms.
3.3 Type representation in the implementation
The implementation covers a subset of the specified syntax. From weyl-types/src/ty.rs:
pub enum Ty {
Scalar(ScalarTy), // Nat | Int | Real | Complex | Bool
Series { base: ScalarTy, vars: VarSet, val: Valuation },
Op(OpTyId), // interned in TypeInterner
Zero,
Model(Box<ModelTy>),
}
pub struct OpTy {
pub alg: AlgId, // 𝔄
pub grade: GradeSet, // γ: Single(PauliGrade) | Mixed(SmallVec<PauliGrade>)
pub charge: ChargeSet, // q: formal sum of anyons, Single | Mixed
pub herm: Herm, // h: Herm | AntiHerm | Gen
pub supp: SuppTemplate, // S: region class + finite set of (cell offset, sublattice label)
pub strict: StrictIndices, // σ = (dim: [i8; 4], vector_kind, t_parity, p_parity)
pub fermion_grade: Grade, // f: Even | Odd
}
pub struct Typed { pub ty: Ty, pub err: Err } // τ @ εWhere the implementation is narrower than the rule:
| Component | Implementation status |
|---|---|
| Representation component | Absent. Symmetry information appears only as the parities and character in ; irreps in Sel are strings (§5.7) |
Ty::Scalar carries no ; strict indices of scalars are tracked separately by the elaborator (weyl-hir/src/elaborate/strict.rs) | |
| Absent | |
| Refinement types | Absent. Refinements such as Hermiticity are fixed fields (e.g. herm) |
| , , | Absent. There are no index variables |
Index sorts κ | No uniform representation; each sort is a dedicated Rust type. The enum Kind in ty.rs (Nat, Group, Lattice, ...) is a namespace classification unused by the rules; do not confuse it with index sorts |
TypeInterner hash-conses OpTy, so comparing operator types is a single integer comparison.
4. Judgments
| Judgment | Reading | Implementation status |
|---|---|---|
| signature is well-formed | spread out (§2) | |
| index has sort | ensured by Rust types; no explicit judgment | |
| constraint holds under assumptions | no , ; every constraint is closed and decided by direct computation | |
| , | subtyping and grade order | implemented (Err::leq); no general subtyping relation |
| synthesis | implemented: the synth_* functions | |
| checking | only at claim, as synthesize-then-compare (the check_* functions) | |
| proposition holds | §7 |
is the index-variable context, the constraint assumptions, the term-variable context. In the implementation ; the rules below omit them.
5. Typing rules
Notation: and are addition and multiplication of grades, is Exact (§6). All rules are syntax-directed: each term form has exactly one synthesis rule.
5.1 Generators: Gen
means dimensionless, scalar, parities unknown.
In the implementation (synth_gen and synth_fermion_gen), Pauli generators receive a single-site Pauli grade , , , and charge from the signature. Fermion modes and , by contrast, receive the identity grade for , , and (see §8.2 on fermion commutators for the consequence). Boson modes a : boson are even with , and Majorana modes γ : Majorana are odd with . For every expression built from such modes the elaborator also computes the exact normal-ordered polynomial in the graded tensor product CAR ⊗ CCR, with symbolic real couplings kept as commuting indeterminates, and the define takes its Hermiticity class and parity from that normal form rather than from the grade.
5.2 Multiplication: Mul
Here adds dimensions, multiplies characters by the usual table, and multiplies parities when both are known (otherwise the result is unknown).
The Hermiticity operation . Let and be homogeneous with . When , we have : if both factors are Hermitian (, ) or both are anti-Hermitian (, ), then , whereas if one is Hermitian and the other anti-Hermitian (, ), then .
This gives the table (herm_product):
Herm | Herm | Herm | AntiHerm | Gen |
Herm | AntiHerm | AntiHerm | Herm | Gen |
AntiHerm | Herm | AntiHerm | Herm | Gen |
AntiHerm | AntiHerm | Herm | AntiHerm | Gen |
either Gen | any | Gen | Gen | Gen |
The table presupposes that holds exactly for the operators involved. Pauli words satisfy this. Canonical anticommutation (CAR) or commutation (CCR) relations on overlapping supports do not (swapping produces contraction terms), and neither do group qudits. For those algebras the spec computes Hermiticity from a normal form and falls back to Gen; the implementation has no such fallback, because the Pauli algebra is the only implemented algebra with non-trivial grades.
In the implementation (synth_mul), multiplying operators from different algebras () is rejected with E0101. When either or is Mixed (an inhomogeneous sum), the resulting grade is the set of pairwise products, and is taken from the table above only if all pairwise bicharacters agree, falling back to Gen otherwise. For charges, two Single charges are fused position-wise by bitwise XOR (fuse_z2), which is valid only for theories whose fusion group is with bitwise-encoded labels such as (see §8.2 on charge fusion for other theories), while if either side is Mixed their union is taken. Finally, is always invoked with valuation for both factors, so by §6 error-grade multiplication degenerates to .
5.3 Addition (Add) and scaling (Scale)
Equivalence of strict indices (check_strict_add). Let be the sublattice generated by the units declarations; units ℏ = 1, for example, adds . Addition requires that (decided via integer Hermite normal form, failing with E0510), that the characters match (, failing with E0521), and that whenever both time-reversal parities are known and likewise for spatial-inversion parities (failing with E0520).
Merging the mixable indices, :
| Component | Merge |
|---|---|
| , | union (may become Mixed) |
| union | |
kept if , otherwise Gen. So AntiHerm + AntiHerm stays AntiHerm | |
kept if , otherwise Odd, meaning "may contain an odd part". A sound over-approximation for the evenness check, but lossy | |
| , | kept if both known and equal, otherwise unknown |
| Class of | ||
|---|---|---|
| real | ||
| purely imaginary | flipped (Herm ↔ AntiHerm, Gen unchanged) | flipped |
| general complex | Gen | unknown |
5.4 Commutators: Comm
The rule for the anticommutator is the same with the condition .
In the implementation (synth_comm), Mixed grades yield Zero only when every pair of constituent grades satisfies the commutation condition—a sufficient, not necessary, check. Whenever Zero cannot be derived, the rule assigns the type of (the conclusion of Mul), which is exact for homogeneous grades because implies . A claim [a, b] = n or [a, b]₊ = n between fermion, boson or Majorana expressions is not decided by this rule at all: the bracket is normal-ordered with the canonical (anti)commutation relations and compared with the claimed number (E0340 on a mismatch).
5.5 Hamiltonian claims: T-Ham
claim H : Hermitian, local is checked by check_hermitian_local:
The three premises correspond to E0301, E0305 and E0303. is the maximal Manhattan distance between cell offsets in the support template.
The rule gives a sufficient condition only: Hermiticity synthesis loses information (e.g. the Gen fallback in Add), so some physically Hermitian Hamiltonians are rejected.
5.6 Finite sums (Sum) and -independence
The rule as stated; what the compiler does differently follows it:
is the set of translation-equivalent region classes; each class is typed once, on a symbolic representative.
In the implementation, region classes are constructed in lattice.rs: along an open direction, every row closer than to an open end forms its own class, while all remaining rows collapse into BULK, giving a reference strip of height . However, the generic Sum rule does not type each region class separately; instead, simply takes the type of on the representative, and region classes are consulted only by boundary checks (bdy.rs, for conserved quantities and boundary condensation) and by lowering. Meanwhile, is hard-coded for just two domains—the square-lattice star and the plaquette boundary —by folding over their four edges with synth_gen and synth_mul.
What -independence means precisely. Supports and grades are stored as "cell offset relative to the representative + sublattice label". They never contain absolute coordinates or , so "the result of type checking does not depend on " holds by construction. The statement "a program that type-checks is semantically correct for all " is Conjecture 1 and is unproven.
5.7 Selection rules: Sel
Specification:
Sel is the only introduction rule for a scalar Zero (Comm-Zero concerns operators). Division and log reject arguments of type Zero (E0530).
The implementation (synth_select_expectation and synth_select_braket) does not implement this rule: there is no type and no computation in the representation ring . Instead, an expectation value is typed Zero whenever carries a non-trivial charge, has a non-trivial irrep, is -odd (or Polar / PseudoScalar) under a symmetry group containing spatial inversion, or is -odd under a symmetry group containing time reversal. Irreps are represented merely as strings, with only "1", "A1", and "A1g" recognised as trivial.
5.8 Perturbative expansion (Expand) and extrapolation (Est)
Specification:
means: the terms of commute pairwise, square to , and have integer coefficients (so the spectrum is equidistant).
In the implementation, check_pcut verifies integer coefficients (E0412) via an elaborator flag recording whether the coupling was declared positive integer, and checks pairwise commutation (E0413) using the Pauli bicharacter. It does not separately check that terms square to , since that holds automatically for Hermitian Pauli words. Moreover, because the implementation lacks refinement types, the quasi-particle conservation refinement in the conclusion is not recorded in the type.
Est is the only rule that clears the truncation component and introduces an epistemic source. That makes "an extrapolated value is no longer a theorem" visible in the type.
Implementation (elaborate_estimate): the result is Scalar(Real) @ (0, {PadeSpread(method)}, JointEnsemble). The source set is overwritten by instead of being joined with . If already carried epistemic sources, they are lost, which directly contradicts the proof idea of Conjecture 5 (§8.2).
Exact equality: ClaimEq. claim a = b requires both sides to have grade , otherwise E0330. Operator equalities are deferred to the normal-form stage (weyl-canonical). Comparisons with error must be written ≈ … within k.
5.9 High-level constructs and admissibility
The spec defines constructs such as stack, couple, gauge and dual as derived forms: each construct has an expansion , which is a core term. Their typing rules are admissible rules and derive no new judgments. The spec also stipulates , with the topological-order index valid only at the parameter point .
Implementation (combinators.rs, expand_model.rs): rule_stack, rule_couple, rule_gauge and rule_dual are implemented for the abelian case. Admissibility is not proven; it is checked on every run: check_admissible erases the construct's type to an OpTy, compares it with the type of the expansion, and reports internal error E0001 on mismatch. The compared components are , , , and ; and are not compared.
6. Error grades
Definition. The set of grades is
where consists of monomial ideals (truncation remainders) over a fixed variable set , represented uniquely by their Dickson basis—the antichain of minimal generators (Trunc). The set holds epistemic source tags (EpiSource), drawn from PadeSpread, TruncationAt, MonteCarlo, NeuralPotential, and External. Finally, tracks the propagation method (EpiMethod), totally ordered as ; a grade is therefore a triple, not the pair that the informal notation suggests.
Order and operations (err.rs):
where and are the factors' valuation lower bounds and . Convention: if a factor is an exact zero (grade and value identically ), the product has grade .
Properties that can be checked directly. The ideal component forms a distributive lattice with join and meet ; unit tests (trunc_monomial_ideal_lattice_axioms) exercise commutativity, associativity, absorption, and distributivity, though as tests rather than formal proofs of these standard facts. On the full grade set, is the join of with identity element , and both and are monotone in because ideal sum and product are monotone under inclusion and and are likewise monotone. Notably, whenever , the ideal is the whole ring and , so the truncation part of collapses to and multiplication degenerates to .
depends on valuations, which distinguishes this system from ordinary graded effects: grade composition is parameterised by the type index (Series[v]). In the current implementation, however, synth_mul, synth_scale and the elaborator always pass valuation , so as just noted multiplication currently propagates truncation exactly like . That errs on the safe side but is coarser than the spec.
Numeric epistemic data (variances, ensemble samples) is not part of the type. It travels only at run time (RuntimeUncertainty) and takes no part in type interning or hashing.
7. Three levels of deciding propositions
strictly separates types (which can only express constraints ) from propositions (arbitrary statements written in claim). Deciding proceeds through three levels in order. At the first level, weyl-types directly discharges type-level constraints: Hermiticity class, fermion parity, locality, strict indices, pCUT preconditions, E0330 / E0331 grade checks, and bounded enumeration of Lagrangian subgroups for abelian theories. At the second level, exact closed equalities and finite instances are decided without theorem proving—quantifier-free operator equalities by weyl-canonical normal forms, and statements over finite groups by direct enumeration. At the third level, universally quantified propositions containing for all are lowered by weyl-lean into Lean 4 proof obligations and certified by the Lean kernel (see Lean Theorem Proving).
What level 3 proves are statements about physical objects, such as group cohomology or ribbon operator identities, not statements about the type system itself.
8. Metatheory
8.1 Statements and status
Denotation. Write for the denotation of a type on a lattice of size . For an operator type, denotes the set of elements of whose grade lies in , whose charge lies in , that transform as , belong to Hermiticity class , have support inside the translates of , carry strict indices , and have fermion parity . For a graded type, denotes the set of pairs of (true value, computed value) whose difference lies in the formal-series ideal generated by and whose computed value depends only on the epistemic sources in .
Under this denotation the calculus is designed to satisfy the statements below. They are design goals with proof sketches, not completed proofs, and this page calls them conjectures.
| No. | Statement | Status | Existing evidence |
|---|---|---|---|
| Conjecture 1 (soundness, uniform in ) | If and environment satisfies , then there is an depending only on the program such that for all | Unproven, and the current implementation is known to violate it (§8.2) | Unit tests, e.g. typed anti-Hermitian |
| Conjecture 2 (preservation under rewriting) | If is one kernel rewrite step and , then | Unproven | The e-graph checker verifies, for every rewrite at run time, that the normal-form difference is zero, and re-checks type tags (E-Graph Rewriting). A run-time check, not a theorem |
| Conjecture 3 (totality) | Evaluating a well-typed closed program yields a graded value or stops at an explicit run-time gate | Unproven, though by the structural facts of §3.2 a proof should be routine | — |
| Conjecture 4 (decidability and complexity) | Type checking is decidable, polynomial in program size and independent of ; principal types exist for some fragments | Decidability holds for the implementation: each rule is a finite computation with no fixpoint iteration. The polynomial bound is unproven. Principal types are moot in the implementation, which has no index variables | — |
| Conjecture 5 (Exact non-interference) | If , the value of depends on no epistemic source | Unproven; the current Est implementation violates a premise of the proof idea (§8.2) | — |
| Conjecture 6 (admissibility) | The type of a high-level construct equals the erasure of its expansion's type | Unproven; partially checked at run time (§5.9) | check_admissible |
State of Lean formalization. The plan is to formalize in Lean 4 the algebraic laws of the index theories, the Pauli fragment of Conjecture 1, Sel, and Conjecture 5. Today weyl/lean/WeylLib/ contains seven files, Boundary, DoubleCoset, Duality, Gauge, Modular, Ribbon and Twisted, all with lemmas about physical models. None of them formalizes typing judgments of .
8.2 Known deviations in the current implementation
Read directly from the code, five gaps make Conjecture 1 or Conjecture 5 false for the current implementation, or force them to rely on unstated assumptions. First, on fermion commutators, fermion-mode generators are assigned the identity grade (§5.1), so the bicharacter between two fermion operators evaluates to ; because synth_comm ignores , it types as Zero even though gives , and the pairwise-commutation check in check_pcut suffers from the same flaw. Folding into the bicharacter via resolves both. Second, on charge fusion, synth_mul fuses Single charges by bitwise XOR, which fails for abelian theories whose fusion group is not (such as ); AnyonCharge::fuse_in already implements theory-aware fusion, but synth_mul does not yet call it.
Three further deviations affect selection rules, extrapolation, and admissibility. Because selection rules compare irreps purely as strings (§5.7) without computing in the representation ring, soundness rests on the user supplying accurate irrep names. In Est, the implementation overwrites the epistemic source set with instead of forming (§5.8), so chained extrapolations under-record their sources and violate the premise of Conjecture 5. Finally, the run-time admissibility check in §5.9 compares only , , , , and , omitting both and .
8.3 Properties not claimed
The type system deliberately makes no claim to completeness: some physically valid programs are rejected, for instance when Hermiticity degrades to Gen under Add. Nor does it guarantee phase correctness away from the declared fixed point , since topological order and condensation types hold only at and are not inherited under perturbations. Likewise, a remainder is strictly a statement about formal power series and says nothing about analytic convergence. Finally, the type system does not vouch for the numerical accuracy of epistemic uncertainty estimates; once the Est source-dropping bug in §8.2 is fixed, the type guarantees only that epistemic sources are recorded faithfully, not that the magnitude of is trustworthy.
9. Worked derivation
Consider the toric-code boundary perturbation . By Gen, both and are typed as Herm with support . Their Pauli grades at are and , whose symplectic product is , yielding ; Mul and its Hermiticity table therefore produce . Scaling by the real coefficient under Scale leaves as AntiHerm, and Sum propagates that summand type to the sum. When Add combines this perturbation with the remaining terms of , the resulting Hermiticity class becomes Gen if the other terms differ in or remains AntiHerm if they are also AntiHerm—in either case, not Herm. Consequently, claim H : Hermitian, local fails the T-Ham premise and emits E0301:
error[E0301]: `H` is claimed Hermitian but inferred as anti-Hermitian
= reasoning (T-Ham): hermiticity synthesis yielded `anti-Hermitian`
(note: product of anticommuting Hermitian generators is anti-Hermitian under T-Mul)
= help: ensure every term is Hermitian (e.g. multiply anticommuting Pauli products by i
or replace σˣ σᶻ with -i σʸ)The generator, multiplication, and T-Ham steps of this derivation correspond directly to the weyl-types unit test type_rules_hermiticity_and_pcut_diagnostics.
10. Diagnostic catalogue
| Code | Rule | Meaning |
|---|---|---|
E0101 | Mul, Add, Comm, T-Ham | operand is not an operator, or algebras differ |
E0201 | affine index reduction | index crosses an open boundary, or a template overlaps itself |
E0301 | T-Ham | claimed Hermitian, but the synthesized class is not Herm |
E0303 | T-Ham | support diameter exceeds |
E0305 | T-Ham | contains a fermion-parity-odd term |
E0330 | ClaimEq | a non-Exact value appears in an exact equality |
E0331 | require | truncation order insufficient, or the required epistemic component is missing |
E0412 | T-Pcut | non-integer coefficient; equidistant spectrum not guaranteed |
E0413 | T-Pcut | terms of do not commute pairwise |
E0510 | Add, primitives | dimension mismatch (modulo units relations) |
E0520 | Add, T-Sym | / parity mismatch, or a term breaks a declared symmetry |
E0521 | Add, primitives | character mismatch (polar vs axial, etc.) |
E0530 | division, log | argument has type Zero |
E0001 | admissibility check | internal error: a high-level construct's type disagrees with its expansion |
The complexity figures below for each checking stage are design estimates: neither proven nor systematically measured.