Skip to content
PL & Formal Methods · Type Systems

Type System & Core Calculus λ_Weyl

The precise position, signature, syntax, judgments, typing rules and error grades of λ_Weyl, with the implementation status of every item and the proof status of the metatheory.

This page defines Weyl's core type system λWeyl\lambda_{\mathrm{Weyl}} 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. λWeyl\lambda_{\mathrm{Weyl}} 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.

ClaimHolds?Reason
λWeyl\lambda_{\mathrm{Weyl}} is a (typed) λ-calculusNoThe term syntax has no λ-abstraction λx. e\lambda x.\,e, no first-class functions, no β-reduction. The "λ" in the name is only a naming convention.
λWeyl\lambda_{\mathrm{Weyl}} is a dependent type theoryNo (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 (Π α:κ. τ\Pi\,\alpha{:}\kappa.\,\tau)In the spec, not in the implementationAll indices in the implementation are concrete. LL-independence is not obtained via Π\Pi; it holds because LL never appears in a type (§5.6).
It is a graded monadNot strictlyThere are no return / bind terms; grades are just attached to the judgment e⇒τ@εe \Rightarrow \tau \mathbin{@} \varepsilon. "Graded typing judgment" is the accurate term.
It is a proof assistantNoIt cannot express arbitrary propositions; universally quantified statements are routed to Lean (§7).
The metatheorems are provenNoSee §8.

Relation to existing systems:

SourceBorrowedNot borrowed
Kennedy's units-of-measure typesDimensions as indices in the free abelian group Z4\mathbb{Z}^4, compared on additionDimension variables and polymorphism (not implemented)
Dependent ML / ATSSeparation of an index layer from the term layer; constraints discharged by decision proceduresIndex variables, Π\Pi, existentials (not implemented)
Refinement types (DML, Liquid Types){v:τ∣φ}\{v : \tau \mid \varphi\} in the specThe 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 rulesMonadic term formers
Bidirectional typingSynthesis (⇒\Rightarrow) separated from checking (⇐\Leftarrow)The implementation only synthesizes; checking appears only at claim, as "synthesize, then compare"

2. Signature Σ\Sigma ​

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 Λ\Lambda 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 A\mathfrak{A} declare generators, their grades, and the commutation bicharacter ϵ:Γ×Γ→U(1)\epsilon : \Gamma \times \Gamma \to U(1) (the Pauli algebra with grading group F22n\mathbb{F}_2^{2n} 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 C\mathcal{C} supplies anyon labels and fusion rules (abelian theories in the type checker; non-abelian D(G)D(G) through the gauge-model checks). Finally, the signature records the symmetry group GG 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 ⊢Σ sig\vdash \Sigma\ \mathsf{sig} (ε 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 ​

text
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 σ=(d,v,t,p)\sigma = (d, v, t, p) are the strict indices: dimension d∈Z4d \in \mathbb{Z}^4 (exponents of energy, length, time, charge), O(3)O(3) character v∈{Scalar,Polar,Axial,PseudoScalar}v \in \{\mathrm{Scalar}, \mathrm{Polar}, \mathrm{Axial}, \mathrm{PseudoScalar}\}, and time-reversal / inversion parities tt, pp (each Even\mathrm{Even}, Odd\mathrm{Odd} or unknown). f∈Z2f \in \mathbb{Z}_2 is the fermion parity.

Three remarks on the grammar. There is no function type τ→τ\tau \to \tau: the term syntax has no introduction form for one (no λ-abstraction), so functions such as cos and exp are first-order primitives in Σ\Sigma that may only be applied saturated. Scalar multiplication is written c⋅ec \cdot e. And although the operator type is often abbreviated to five components, OpA[γ;q;ρ;h;S]\mathrm{Op}_{\mathfrak{A}}[\gamma; q; \rho; h; S], the typing rules (strict indices in Add and the fermion-parity check in T-Ham) also rely on σ\sigma and ff, 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: Σs∈D\Sigma_{s\in D} and ∏s∈D\prod_{s\in D} bind a site variable over a finite domain DD, while Λα\Lambda\alpha 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:

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

ComponentImplementation status
Representation component ρ\rhoAbsent. Symmetry information appears only as the parities and O(3)O(3) character in σ\sigma; irreps in Sel are strings (§5.7)
Scalar[σ]\mathrm{Scalar}[\sigma]Ty::Scalar carries no σ\sigma; strict indices of scalars are tracked separately by the elaborator (weyl-hir/src/elaborate/strict.rs)
State[q;ρ]\mathrm{State}[q; \rho]Absent
Refinement types {v:τ∣φ}\{v : \tau \mid \varphi\}Absent. Refinements such as Hermiticity are fixed fields (e.g. herm)
Π α:κ. τ\Pi\,\alpha{:}\kappa.\,\tau, Λα. e\Lambda\alpha.\,e, e[i]e[i]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 ​

JudgmentReadingImplementation status
⊢Σ sig\vdash \Sigma\ \mathsf{sig}signature is well-formedspread out (§2)
Δ⊢i:κ\Delta \vdash i : \kappaindex ii has sort κ\kappaensured by Rust types; no explicit judgment
Δ;Φ⊨φ\Delta; \Phi \models \varphiconstraint φ\varphi holds under assumptions Φ\Phino Δ\Delta, Φ\Phi; every constraint is closed and decided by direct computation
Δ;Φ⊢τ<:τ′\Delta; \Phi \vdash \tau <: \tau', ε⊑ε′\varepsilon \sqsubseteq \varepsilon'subtyping and grade order⊑\sqsubseteq implemented (Err::leq); no general subtyping relation
Δ;Φ;Γ⊢e⇒τ@ε\Delta; \Phi; \Gamma \vdash e \Rightarrow \tau \mathbin{@} \varepsilonsynthesisimplemented: the synth_* functions
Δ;Φ;Γ⊢e⇐τ@ε\Delta; \Phi; \Gamma \vdash e \Leftarrow \tau \mathbin{@} \varepsiloncheckingonly at claim, as synthesize-then-compare (the check_* functions)
Δ;Φ;Γ⊢P ok\Delta; \Phi; \Gamma \vdash P\ \mathsf{ok}proposition holds§7

Δ\Delta is the index-variable context, Φ\Phi the constraint assumptions, Γ\Gamma the term-variable context. In the implementation Δ=Φ=∅\Delta = \Phi = \varnothing; the rules below omit them.

5. Typing rules ​

Notation: ⊕\oplus and ⊛\circledast are addition and multiplication of grades, ⊥\bot is Exact (§6). All rules are syntax-directed: each term form has exactly one synthesis rule.

5.1 Generators: Gen ​

(g:GenA(γg,qg,hg,fg))∈Σs∈Site(Λ)Γ⊢gs⇒OpA[γg@s; qg@s; ρg; hg; {s}; σ0; fg]@⊥  (Gen)\frac{(g : \mathrm{Gen}_{\mathfrak{A}}(\gamma_g, q_g, h_g, f_g)) \in \Sigma \qquad s \in \mathrm{Site}(\Lambda)}{\Gamma \vdash g_s \Rightarrow \mathrm{Op}_{\mathfrak{A}}[\gamma_g@s;\ q_g@s;\ \rho_g;\ h_g;\ \{s\};\ \sigma_0;\ f_g] \mathbin{@} \bot}\;(\textsc{Gen})

σ0\sigma_0 means dimensionless, O(3)O(3) scalar, parities unknown.

In the implementation (synth_gen and synth_fermion_gen), Pauli generators σsx,y,z\sigma^{x,y,z}_s receive a single-site Pauli grade γ\gamma, h=Hermh = \mathrm{Herm}, f=Evenf = \mathrm{Even}, and charge qq from the signature. Fermion modes csc_s and cs†c^\dagger_s, by contrast, receive the identity grade for γ\gamma, h=Genh = \mathrm{Gen}, and f=Oddf = \mathrm{Odd} (see §8.2 on fermion commutators for the consequence). Boson modes a : boson are even with h=Genh = \mathrm{Gen}, and Majorana modes γ : Majorana are odd with h=Hermh = \mathrm{Herm}. 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 ​

Γ⊢a⇒OpA[γ1;q1;ρ1;h1;S1;σ1;f1]@ε1Γ⊢b⇒OpA[γ2;q2;ρ2;h2;S2;σ2;f2]@ε2Γ⊢a b⇒OpA[γ1γ2; q1⊗q2; ρ1⊗ρ2; h1⋆ϵ(γ1,γ2)h2; S1∪S2; σ1⋅σ2; f1+f2]@ε1⊛ε2  (Mul)\frac{\Gamma \vdash a \Rightarrow \mathrm{Op}_{\mathfrak{A}}[\gamma_1; q_1; \rho_1; h_1; S_1; \sigma_1; f_1] \mathbin{@} \varepsilon_1 \qquad \Gamma \vdash b \Rightarrow \mathrm{Op}_{\mathfrak{A}}[\gamma_2; q_2; \rho_2; h_2; S_2; \sigma_2; f_2] \mathbin{@} \varepsilon_2}{\Gamma \vdash a\,b \Rightarrow \mathrm{Op}_{\mathfrak{A}}[\gamma_1 \gamma_2;\ q_1 \otimes q_2;\ \rho_1 \otimes \rho_2;\ h_1 \star_{\epsilon(\gamma_1,\gamma_2)} h_2;\ S_1 \cup S_2;\ \sigma_1 \cdot \sigma_2;\ f_1 + f_2] \mathbin{@} \varepsilon_1 \circledast \varepsilon_2}\;(\textsc{Mul})

Here σ1⋅σ2\sigma_1 \cdot \sigma_2 adds dimensions, multiplies O(3)O(3) characters by the usual table, and multiplies parities when both are known (otherwise the result is unknown).

The Hermiticity operation ⋆ϵ\star_\epsilon. Let aa and bb be homogeneous with ab=ϵ baab = \epsilon\, ba. When ϵ=±1\epsilon = \pm 1, we have ϵ−1=ϵ\epsilon^{-1} = \epsilon: if both factors are Hermitian (a†=aa^\dagger = a, b†=bb^\dagger = b) or both are anti-Hermitian (a†=−aa^\dagger = -a, b†=−bb^\dagger = -b), then (ab)†=ba=ϵ ab(ab)^\dagger = ba = \epsilon\, ab, whereas if one is Hermitian and the other anti-Hermitian (a†=aa^\dagger = a, b†=−bb^\dagger = -b), then (ab)†=−ba=−ϵ ab(ab)^\dagger = -ba = -\epsilon\, ab.

This gives the table (herm_product):

h1h_1h2h_2ϵ=+1\epsilon = +1ϵ=−1\epsilon = -1ϵ∉{±1}\epsilon \notin \{\pm 1\}
HermHermHermAntiHermGen
HermAntiHermAntiHermHermGen
AntiHermHermAntiHermHermGen
AntiHermAntiHermHermAntiHermGen
either GenanyGenGenGen

The table presupposes that ab=ϵ baab = \epsilon\, ba 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 (A1≠A2\mathfrak{A}_1 \neq \mathfrak{A}_2) is rejected with E0101. When either γ1\gamma_1 or γ2\gamma_2 is Mixed (an inhomogeneous sum), the resulting grade is the set of pairwise products, and hh is taken from the table above only if all pairwise bicharacters ϵ\epsilon 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 Z2k\mathbb{Z}_2^k with bitwise-encoded labels such as D(Z2)D(\mathbb{Z}_2) (see §8.2 on charge fusion for other theories), while if either side is Mixed their union is taken. Finally, ⊛\circledast is always invoked with valuation 00 for both factors, so by §6 error-grade multiplication degenerates to ⊕\oplus.

5.3 Addition (Add) and scaling (Scale) ​

Γ⊢a⇒τ1@ε1Γ⊢b⇒τ2@ε2σ(τ1)≡Uσ(τ2)Γ⊢a+b⇒τ1⊔τ2@ε1⊕ε2  (Add)\frac{\Gamma \vdash a \Rightarrow \tau_1 \mathbin{@} \varepsilon_1 \qquad \Gamma \vdash b \Rightarrow \tau_2 \mathbin{@} \varepsilon_2 \qquad \sigma(\tau_1) \equiv_U \sigma(\tau_2)}{\Gamma \vdash a + b \Rightarrow \tau_1 \sqcup \tau_2 \mathbin{@} \varepsilon_1 \oplus \varepsilon_2}\;(\textsc{Add})

Equivalence of strict indices ≡U\equiv_U (check_strict_add). Let U⊆Z4U \subseteq \mathbb{Z}^4 be the sublattice generated by the units declarations; units ℏ = 1, for example, adds (1,0,1,0)(1, 0, 1, 0). Addition requires that d1−d2∈Ud_1 - d_2 \in U (decided via integer Hermite normal form, failing with E0510), that the O(3)O(3) characters match (v1=v2v_1 = v_2, failing with E0521), and that t1=t2t_1 = t_2 whenever both time-reversal parities are known and likewise p1=p2p_1 = p_2 for spatial-inversion parities (failing with E0520).

Merging the mixable indices, τ1⊔τ2\tau_1 \sqcup \tau_2:

ComponentMerge
γ\gamma, qqunion (may become Mixed)
SSunion
hhkept if h1=h2h_1 = h_2, otherwise Gen. So AntiHerm + AntiHerm stays AntiHerm
ffkept if f1=f2f_1 = f_2, otherwise Odd, meaning "may contain an odd part". A sound over-approximation for the evenness check, but lossy
tt, ppkept if both known and equal, otherwise unknown

Γ⊢e⇒Op[…;h;…;(d,v,t,p);f]@εc:cls∈{R, iR, C}Γ⊢c⋅e⇒Op[…;h′;…;(d,v,t′,p);f]@εc⊛ε  (Scale)\frac{\Gamma \vdash e \Rightarrow \mathrm{Op}[\ldots; h; \ldots; (d, v, t, p); f] \mathbin{@} \varepsilon \qquad c : \mathrm{cls} \in \{\mathbb{R},\ i\mathbb{R},\ \mathbb{C}\}}{\Gamma \vdash c \cdot e \Rightarrow \mathrm{Op}[\ldots; h'; \ldots; (d, v, t', p); f] \mathbin{@} \varepsilon_c \circledast \varepsilon}\;(\textsc{Scale})

Class of cch′h't′t'
realhhtt
purely imaginaryflipped (Herm ↔ AntiHerm, Gen unchanged)flipped
general complexGenunknown

5.4 Commutators: Comm ​

Γ⊢a⇒OpA[γ1;…]@ε1Γ⊢b⇒OpA[γ2;…]@ε2ϵ(γ1,γ2)=+1Γ⊢[a,b]⇒Zero@ε1⊛ε2  (Comm−Zero)\frac{\Gamma \vdash a \Rightarrow \mathrm{Op}_{\mathfrak{A}}[\gamma_1; \ldots] \mathbin{@} \varepsilon_1 \qquad \Gamma \vdash b \Rightarrow \mathrm{Op}_{\mathfrak{A}}[\gamma_2; \ldots] \mathbin{@} \varepsilon_2 \qquad \epsilon(\gamma_1, \gamma_2) = +1}{\Gamma \vdash [a, b] \Rightarrow \mathrm{Zero} \mathbin{@} \varepsilon_1 \circledast \varepsilon_2}\;(\textsc{Comm-Zero})

The rule for the anticommutator [a,b]+[a, b]_+ is the same with the condition ϵ=−1\epsilon = -1.

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 a ba\,b (the conclusion of Mul), which is exact for homogeneous grades because ϵ=−1\epsilon = -1 implies [a,b]=2ab[a, b] = 2ab. 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:

Γ⊢H⇒Op[γ;q;ρ;h;S;σ;f]@εh=Hermf=Evendiam(S)≤Rmax⁡Γ⊢claim H:Hermitian,local  ok  (T−Ham)\frac{\Gamma \vdash H \Rightarrow \mathrm{Op}[\gamma; q; \rho; h; S; \sigma; f] \mathbin{@} \varepsilon \qquad h = \mathrm{Herm} \qquad f = \mathrm{Even} \qquad \mathrm{diam}(S) \le R_{\max}}{\Gamma \vdash \mathtt{claim}\ H : \mathrm{Hermitian, local}\ \ \mathsf{ok}}\;(\textsc{T-Ham})

The three premises correspond to E0301, E0305 and E0303. diam(S)\mathrm{diam}(S) 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 LL-independence ​

The rule as stated; what the compiler does differently follows it:

D=⨆c∈CDc∀c∈C.  Γ, s:Dc⊢e⇒τc@εcΓ⊢∑s∈De⇒⨆cτc@⨁cεc  (Sum)\frac{D = \bigsqcup_{c \in \mathcal{C}} D_c \qquad \forall c \in \mathcal{C}.\ \ \Gamma,\ s : D_c \vdash e \Rightarrow \tau_c \mathbin{@} \varepsilon_c}{\Gamma \vdash \sum_{s \in D} e \Rightarrow \bigsqcup_c \tau_c \mathbin{@} \bigoplus_c \varepsilon_c}\;(\textsc{Sum})

C\mathcal{C} 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 Rmax⁡R_{\max} to an open end forms its own class, while all remaining rows collapse into BULK, giving a reference strip of height max⁡(2Rmax⁡+1,3)\max(2R_{\max} + 1, 3). However, the generic Sum rule does not type each region class separately; instead, ∑s∈De\sum_{s\in D} e simply takes the type of ee on the representative, and region classes are consulted only by boundary checks (bdy.rs, for conserved quantities and boundary condensation) and by lowering. Meanwhile, ∏\prod is hard-coded for just two domains—the square-lattice star {l∋v}\{l \ni v\} and the plaquette boundary {l∈∂p}\{l \in \partial p\}—by folding over their four edges with synth_gen and synth_mul.

What LL-independence means precisely. Supports SS and grades γ\gamma are stored as "cell offset relative to the representative + sublattice label". They never contain absolute coordinates or LL, so "the result of type checking does not depend on LL" holds by construction. The statement "a program that type-checks is semantically correct for all L≥L0L \ge L_0" is Conjecture 1 and is unproven.

5.7 Selection rules: Sel ​

Specification:

Γ⊢ψ⇒State[q1;ρ1]Γ⊢O⇒Op[γ;q;ρ;…]Γ⊢ψ′⇒State[q2;ρ2]1∉ρˉ1⊗ρ⊗ρ2 ∨ q1≠q⊗q2Γ⊢⟨ψ∣O∣ψ′⟩⇒Zero@⊥  (Sel)\frac{\Gamma \vdash \psi \Rightarrow \mathrm{State}[q_1; \rho_1] \quad \Gamma \vdash O \Rightarrow \mathrm{Op}[\gamma; q; \rho; \ldots] \quad \Gamma \vdash \psi' \Rightarrow \mathrm{State}[q_2; \rho_2] \quad 1 \notin \bar\rho_1 \otimes \rho \otimes \rho_2 \ \lor\ q_1 \neq q \otimes q_2}{\Gamma \vdash \langle \psi | O | \psi' \rangle \Rightarrow \mathrm{Zero} \mathbin{@} \bot}\;(\textsc{Sel})

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 State\mathrm{State} type and no computation in the representation ring R(G)R(G). Instead, an expectation value ⟨O⟩\langle O \rangle is typed Zero whenever OO carries a non-trivial charge, has a non-trivial irrep, is P\mathcal{P}-odd (or Polar / PseudoScalar) under a symmetry group containing spatial inversion, or is T\mathcal{T}-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:

Γ⊢H0⇐{v:Op[…;Herm;…]∣Pcut(v)}@⊥Γ⊢V⇒Op[…;Herm;S]@εvalx⃗(V)≥1Γ⊢expandpCUT(H0;V;I)⇒Seriesx⃗[0]({v:Op[…;Herm;…]∣[v,Q]=0})@ε⊕(I,∅,Exact)  (Expand)\frac{\Gamma \vdash H_0 \Leftarrow \{v : \mathrm{Op}[\ldots; \mathrm{Herm}; \ldots] \mid \mathrm{Pcut}(v)\} \mathbin{@} \bot \qquad \Gamma \vdash V \Rightarrow \mathrm{Op}[\ldots; \mathrm{Herm}; S] \mathbin{@} \varepsilon \qquad \mathrm{val}_{\vec{x}}(V) \ge 1}{\Gamma \vdash \mathrm{expand}_{\mathrm{pCUT}}(H_0; V; I) \Rightarrow \mathrm{Series}_{\vec{x}}[0](\{v : \mathrm{Op}[\ldots; \mathrm{Herm}; \ldots] \mid [v, Q] = 0\}) \mathbin{@} \varepsilon \oplus (I, \varnothing, \mathrm{Exact})}\;(\textsc{Expand})

Pcut(v)\mathrm{Pcut}(v) means: the terms of H0H_0 commute pairwise, square to 11, 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 11, since that holds automatically for Hermitian Pauli words. Moreover, because the implementation lacks refinement types, the quasi-particle conservation refinement [v,Q]=0[v, Q] = 0 in the conclusion is not recorded in the type.

Γ⊢e⇒Seriesx[v](Scalar[σ])@(I,E,m)Γ⊢estimateM(e)⇒Scalar[σ′]@(0, E∪{M}, m∨mM)  (Est)\frac{\Gamma \vdash e \Rightarrow \mathrm{Series}_{x}[v](\mathrm{Scalar}[\sigma]) \mathbin{@} (I, E, m)}{\Gamma \vdash \mathrm{estimate}_M(e) \Rightarrow \mathrm{Scalar}[\sigma'] \mathbin{@} (0,\ E \cup \{M\},\ m \vee m_M)}\;(\textsc{Est})

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 {M}\{M\} instead of being joined with EE. If ee 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 ⊥\bot, 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 k(…)k(\ldots) has an expansion ⌊k(…)⌋\lfloor k(\ldots) \rfloor, which is a core term. Their typing rules are admissible rules and derive no new judgments. The spec also stipulates Model[Λ;A;G;C@θ]<:OpA[…;Herm;…]\mathrm{Model}[\Lambda; \mathfrak{A}; G; \mathcal{C}@\theta] <: \mathrm{Op}_{\mathfrak{A}}[\ldots; \mathrm{Herm}; \ldots], with the topological-order index valid only at the parameter point θ\theta.

Γ⊢M1⇒Model[Λ;A1;G1;C1@θ1]Γ⊢M2⇒Model[Λ;A2;G2;C2@θ2]Γ⊢stack(M1,M2)⇒Model[Λ;A1⊗^A2;G1×G2;C1⊠C2@(θ1,θ2)]  (Stack)\frac{\Gamma \vdash M_1 \Rightarrow \mathrm{Model}[\Lambda; \mathfrak{A}_1; G_1; \mathcal{C}_1 @ \theta_1] \qquad \Gamma \vdash M_2 \Rightarrow \mathrm{Model}[\Lambda; \mathfrak{A}_2; G_2; \mathcal{C}_2 @ \theta_2]}{\Gamma \vdash \mathrm{stack}(M_1, M_2) \Rightarrow \mathrm{Model}[\Lambda; \mathfrak{A}_1 \hat{\otimes} \mathfrak{A}_2; G_1 \times G_2; \mathcal{C}_1 \boxtimes \mathcal{C}_2 @ (\theta_1, \theta_2)]}\;(\textsc{Stack})

Γ⊢M⇒Model[Λ;A;G;C@θ]Γ⊢V⇒OpA[…;Herm;S]@εK=StabG(V)diam(S)≤Rmax⁡Γ⊢couple(M;V)⇒Model[Λ;A;K;C@(θ,V=0)]@ε  (Couple)\frac{\Gamma \vdash M \Rightarrow \mathrm{Model}[\Lambda; \mathfrak{A}; G; \mathcal{C} @ \theta] \qquad \Gamma \vdash V \Rightarrow \mathrm{Op}_{\mathfrak{A}}[\ldots; \mathrm{Herm}; S] \mathbin{@} \varepsilon \qquad K = \mathrm{Stab}_G(V) \qquad \mathrm{diam}(S) \le R_{\max}}{\Gamma \vdash \mathrm{couple}(M; V) \Rightarrow \mathrm{Model}[\Lambda; \mathfrak{A}; K; \mathcal{C} @ (\theta, V = 0)] \mathbin{@} \varepsilon}\;(\textsc{Couple})

Γ⊢M⇒Model[Λ;A;G;C@θ]N⊴G on-site[ωM]∣N=1∈Hd+1(N,U(1))Γ⊢gaugeN(M)⇒Model[Λ;A⊗Qudit⟨N⟩edges;G/N×N^(d−2);(C/ ⁣/N)@θ]  (Gauge)\frac{\Gamma \vdash M \Rightarrow \mathrm{Model}[\Lambda; \mathfrak{A}; G; \mathcal{C} @ \theta] \qquad N \trianglelefteq G\ \text{on-site} \qquad [\omega_M]\big|_N = 1 \in H^{d+1}(N, U(1))}{\Gamma \vdash \mathrm{gauge}_N(M) \Rightarrow \mathrm{Model}[\Lambda; \mathfrak{A} \otimes \mathrm{Qudit}\langle N \rangle_{\mathrm{edges}}; G/N \times \widehat{N}^{(d-2)}; (\mathcal{C} /\!/ N) @ \theta]}\;(\textsc{Gauge})

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 hh, ff, A\mathfrak{A}, σ\sigma and γ\gamma; qq and SS are not compared.

6. Error grades ​

Definition. The set of grades is

E=I×Pfin(Src)×M,\mathbb{E} = \mathcal{I} \times \mathcal{P}_{\mathrm{fin}}(\mathrm{Src}) \times \mathcal{M},

where I\mathcal{I} consists of monomial ideals (truncation remainders) over a fixed variable set x⃗\vec{x}, represented uniquely by their Dickson basis—the antichain of minimal generators (Trunc). The set Src\mathrm{Src} holds epistemic source tags (EpiSource), drawn from PadeSpread, TruncationAt, MonteCarlo, NeuralPotential, and External. Finally, M\mathcal{M} tracks the propagation method (EpiMethod), totally ordered as Exact<JointEnsemble<LinearizedDelta<ConservativeBound\mathrm{Exact} < \mathrm{JointEnsemble} < \mathrm{LinearizedDelta} < \mathrm{ConservativeBound}; a grade is therefore a triple, not the pair (I,E)(I, E) that the informal notation suggests.

Order and operations (err.rs):

(I,E,m)⊑(J,F,n)  ⟺  I⊆J ∧ E⊆F ∧ m≤n(I, E, m) \sqsubseteq (J, F, n) \iff I \subseteq J \ \wedge\ E \subseteq F \ \wedge\ m \le n

(I,E,m)⊕(J,F,n)=(I+J, E∪F, μ),μ={ExactE∪F=∅max⁡(m,n)otherwise(I, E, m) \oplus (J, F, n) = \big(I + J,\ E \cup F,\ \mu\big), \qquad \mu = \begin{cases} \mathrm{Exact} & E \cup F = \varnothing \\ \max(m, n) & \text{otherwise} \end{cases}

(I,E,m)⊛va,vb(J,F,n)=(I⋅⟨x⃗vb⟩+J⋅⟨x⃗va⟩+IJ, E∪F, μ)(I, E, m) \circledast_{v_a, v_b} (J, F, n) = \big(I \cdot \langle \vec{x}^{v_b} \rangle + J \cdot \langle \vec{x}^{v_a} \rangle + I J,\ E \cup F,\ \mu\big)

where vav_a and vbv_b are the factors' valuation lower bounds and ⊥=(0,∅,Exact)\bot = (0, \varnothing, \mathrm{Exact}). Convention: if a factor is an exact zero (grade ⊥\bot and value identically 00), the product has grade ⊥\bot.

Properties that can be checked directly. The ideal component (I,⊆)(\mathcal{I}, \subseteq) forms a distributive lattice with join I+JI + J and meet I∩JI \cap J; 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, ⊕\oplus is the join of ⊑\sqsubseteq with identity element ⊥\bot, and both ⊕\oplus and ⊛\circledast are monotone in ⊑\sqsubseteq because ideal sum and product are monotone under inclusion and ∪\cup and max⁡\max are likewise monotone. Notably, whenever va=vb=0v_a = v_b = 0, the ideal ⟨x⃗0⟩=⟨1⟩\langle \vec{x}^0 \rangle = \langle 1 \rangle is the whole ring and IJ⊆IIJ \subseteq I, so the truncation part of ⊛\circledast collapses to I+JI + J and multiplication degenerates to ⊕\oplus.

⊛\circledast depends on valuations, which distinguishes this system from ordinary graded effects: grade composition is parameterised by the type index vv (Series[v]). In the current implementation, however, synth_mul, synth_scale and the elaborator always pass valuation 00, so as just noted multiplication currently propagates truncation exactly like ⊕\oplus. 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 ​

λWeyl\lambda_{\mathrm{Weyl}} strictly separates types (which can only express constraints φ\varphi) from propositions PP (arbitrary statements written in claim). Deciding Γ⊢P ok\Gamma \vdash P\ \mathsf{ok} 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 ⟦τ⟧L\llbracket \tau \rrbracket_L for the denotation of a type on a lattice of size LL. For an operator type, ⟦OpA[γ;q;ρ;h;S;σ;f]⟧L\llbracket \mathrm{Op}_{\mathfrak{A}}[\gamma; q; \rho; h; S; \sigma; f] \rrbracket_L denotes the set of elements of A(ΛL)\mathfrak{A}(\Lambda_L) whose grade lies in γ\gamma, whose charge lies in qq, that transform as ρ\rho, belong to Hermiticity class hh, have support inside the translates of SS, carry strict indices σ\sigma, and have fermion parity ff. For a graded type, ⟦τ@(I,E,m)⟧L\llbracket \tau \mathbin{@} (I, E, m) \rrbracket_L denotes the set of pairs of (true value, computed value) whose difference lies in the formal-series ideal generated by II and whose computed value depends only on the epistemic sources in EE.

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.StatementStatusExisting evidence
Conjecture 1 (soundness, uniform in LL)If Γ⊢e⇒τ@ε\Gamma \vdash e \Rightarrow \tau \mathbin{@} \varepsilon and environment η\eta satisfies Γ\Gamma, then there is an L0L_0 depending only on the program such that ⟦e⟧η,L∈⟦τ@ε⟧L\llbracket e \rrbracket_{\eta, L} \in \llbracket \tau \mathbin{@} \varepsilon \rrbracket_L for all L≥L0L \ge L_0Unproven, and the current implementation is known to violate it (§8.2)Unit tests, e.g. σxσz\sigma^x \sigma^z typed anti-Hermitian
Conjecture 2 (preservation under rewriting)If e↦e′e \mapsto e' is one kernel rewrite step and Γ⊢e⇒τ@ε\Gamma \vdash e \Rightarrow \tau \mathbin{@} \varepsilon, then Γ⊢e′⇐τ@ε\Gamma \vdash e' \Leftarrow \tau \mathbin{@} \varepsilonUnprovenThe 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 gateUnproven, 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 LL; principal types exist for some fragmentsDecidability 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 Γ⊢e⇒τ@(I,∅,Exact)\Gamma \vdash e \Rightarrow \tau \mathbin{@} (I, \varnothing, \mathrm{Exact}), the value of ee depends on no epistemic sourceUnproven; 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 typeUnproven; 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 λWeyl\lambda_{\mathrm{Weyl}}.

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 +1+1; because synth_comm ignores ff, it types [ci,cj][c_i, c_j] as Zero even though cicj=−cjcic_i c_j = -c_j c_i gives [ci,cj]=2cicj≠0[c_i, c_j] = 2 c_i c_j \neq 0, and the pairwise-commutation check in check_pcut suffers from the same flaw. Folding ff into the bicharacter via ϵtot=ϵPauli⋅(−1)f1f2\epsilon_{\mathrm{tot}} = \epsilon_{\mathrm{Pauli}} \cdot (-1)^{f_1 f_2} resolves both. Second, on charge fusion, synth_mul fuses Single charges by bitwise XOR, which fails for abelian theories whose fusion group is not Z2k\mathbb{Z}_2^k (such as D(Z3)D(\mathbb{Z}_3)); 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 {M}\{M\} instead of forming E∪{M}E \cup \{M\} (§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 hh, ff, A\mathfrak{A}, σ\sigma, and γ\gamma, omitting both qq and SS.

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 θ\theta, since topological order and condensation types hold only at θ\theta and are not inherited under perturbations. Likewise, a remainder + O(xn)+\,O(x^n) 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 σ\sigma is trustworthy.

9. Worked derivation ​

Consider the toric-code boundary perturbation V=−x∑iσdixσdizV = -x \sum_i \sigma^x_{d_i} \sigma^z_{d_i}. By Gen, both σdix\sigma^x_{d_i} and σdiz\sigma^z_{d_i} are typed as Herm with support {di}\{d_i\}. Their Pauli grades at did_i are XX and ZZ, whose symplectic product is 11, yielding ϵ=−1\epsilon = -1; Mul and its Hermiticity table therefore produce Herm⋆−1Herm=AntiHerm\mathrm{Herm} \star_{-1} \mathrm{Herm} = \mathrm{AntiHerm}. Scaling by the real coefficient −x-x under Scale leaves hh as AntiHerm, and Sum propagates that summand type to the sum. When Add combines this perturbation with the remaining terms of HH, the resulting Hermiticity class becomes Gen if the other terms differ in hh or remains AntiHerm if they are also AntiHerm—in either case, not Herm. Consequently, claim H : Hermitian, local fails the T-Ham premise h=Hermh = \mathrm{Herm} and emits E0301:

text
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 ​

CodeRuleMeaning
E0101Mul, Add, Comm, T-Hamoperand is not an operator, or algebras differ
E0201affine index reductionindex crosses an open boundary, or a template overlaps itself
E0301T-Hamclaimed Hermitian, but the synthesized class is not Herm
E0303T-Hamsupport diameter exceeds Rmax⁡R_{\max}
E0305T-Hamcontains a fermion-parity-odd term
E0330ClaimEqa non-Exact value appears in an exact equality
E0331requiretruncation order insufficient, or the required epistemic component is missing
E0412T-Pcutnon-integer coefficient; equidistant spectrum not guaranteed
E0413T-Pcutterms of H0H_0 do not commute pairwise
E0510Add, primitivesdimension mismatch (modulo units relations)
E0520Add, T-SymT\mathcal{T} / P\mathcal{P} parity mismatch, or a term breaks a declared symmetry
E0521Add, primitivesO(3)O(3) character mismatch (polar vs axial, etc.)
E0530division, logargument has type Zero
E0001admissibility checkinternal 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.

Weyl v0.1 · MIT License