Dimension expressions are finite-support exponent maps 𝑑:B∪𝐷→ℤ. Multiplication, inverse, and integer power are pointwise addition, negation, and scalar multiplication. Compound units and source types are 𝑢::=𝑢0∣𝑢𝑢∣𝑢−1∣𝑢𝑛,𝜏::=𝛼∣𝖭𝗎𝗆[𝑑]∣𝜏→𝜏,𝜎::=∀¯𝛼¯𝛿.𝜏. The unit environment gives primitive units positive rational scales and closed dimensions and extends homomorphically to all four unit forms.
Ordinary and dimension variables are disjoint sorts. Formation is
𝛼∈A
A;𝐷⊢𝛼𝗍𝗒𝗉𝖾
F-TVar
𝑑:B∪𝐷→ℤfinitelysupported
A;𝐷⊢𝖭𝗎𝗆[𝑑]𝗍𝗒𝗉𝖾
F-Num
A;𝐷⊢𝜏1𝗍𝗒𝗉𝖾A;𝐷⊢𝜏2𝗍𝗒𝗉𝖾
A;𝐷⊢𝜏1→𝜏2𝗍𝗒𝗉𝖾
F-Arrow
Type equivalence extends dimension equality structurally, and conversion is Γ⊢𝑒:𝜏𝜏=𝐷𝜏′Γ⊢𝑒:𝜏′D−Conv. The source terms and arithmetic rules are 𝑒::=𝑥∣𝑞@𝑢∣𝜆𝑥.𝑒∣𝑒𝑒∣𝗅𝖾𝗍𝑥=𝑒𝗂𝗇𝑒∣𝑒+𝑒∣𝑒∗𝑒∣𝑒/𝑒∣𝑒⟨𝑛⟩,
U∗(𝑢)=(𝑠𝑢,𝑑𝑢)
Γ⊢U𝑞@𝑢:𝖭𝗎𝗆[𝑑𝑢]
D-Lit
Γ⊢U𝑒1:𝖭𝗎𝗆[𝑑]Γ⊢U𝑒2:𝖭𝗎𝗆[𝑑]
Γ⊢U𝑒1+𝑒2:𝖭𝗎𝗆[𝑑]
D-Add
Γ⊢U𝑒1:𝖭𝗎𝗆[𝑑1]Γ⊢U𝑒2:𝖭𝗎𝗆[𝑑2]
Γ⊢U𝑒1∗𝑒2:𝖭𝗎𝗆[𝑑1𝑑2]
D-Mul
Γ⊢U𝑒1:𝖭𝗎𝗆[𝑑1]Γ⊢U𝑒2:𝖭𝗎𝗆[𝑑2]
Γ⊢U𝑒1/𝑒2:𝖭𝗎𝗆[𝑑1𝑑−12]
D-Div
Γ⊢U𝑒:𝖭𝗎𝗆[𝑑]
Γ⊢U𝑒⟨𝑛⟩:𝖭𝗎𝗆[𝑑𝑛]
D-Pow
For 𝐸=(𝑑𝑖=𝐷𝑒𝑖)𝑚𝑖=1, list unknowns ¯𝛿=(𝛿1,…,𝛿𝑛), put 𝑀𝑖𝑗=𝑑𝑖(𝛿𝑗)−𝑒𝑖(𝛿𝑗),𝑐𝑖=∏𝑏∈B∪𝐺𝑟𝑏𝑒𝑖(𝑏)−𝑑𝑖(𝑏), and compute a Smith form 𝑈𝑀𝑉=𝑆. With 𝑧=𝑉𝑧′ and 𝑐′=𝑈𝑐, each pivot equation is (𝑧′𝑖)𝑠𝑖=𝑐′𝑖. It succeeds exactly when 𝑠𝑖 divides every generator exponent in 𝑐′𝑖; a zero row requires 𝑐′𝑖=1. Free columns become fresh dimension parameters, and back-substitution gives the principal substitution 𝜌𝐸. The deterministic policy chooses the first nonzero row-major pivot, uses canonical extended-Euclidean coefficients, repairs the first offending entry, makes pivots positive, and names free columns left to right from a globally fresh dimension supply.
The sorted type unifier 𝗆𝗎𝗇𝗂𝖿𝗒 decomposes arrows and ordinary variables as in HM and accumulates every 𝖭𝗎𝗆[𝑑]≐𝖭𝗎𝗆[𝑒] of one call into one dimension store. The dimension-aware inference judgment is IU(Γ,𝑒)=(𝑆,𝜏). Besides inherited W, its exact binary clauses first compute (𝑆1,𝜏1)=I(Γ,𝑒1) and (𝑆2,𝜏2)=I(Γ[𝑆1],𝑒2). Addition chooses fresh 𝛿, computes 𝑈=𝗆𝗎𝗇𝗂𝖿𝗒(𝜏1[𝑆2]≐𝖭𝗎𝗆[𝛿],𝜏2≐𝖭𝗎𝗆[𝛿]), and returns (𝑆1;𝑆2;𝑈,𝖭𝗎𝗆[𝛿[𝑈]]). Multiplication and division choose fresh 𝛿1,𝛿2, solve the corresponding two numeric equations, and return 𝑆1;𝑆2;𝑈 together with 𝖭𝗎𝗆[𝛿1[𝑈]𝛿2[𝑈]]or𝖭𝗎𝗆[𝛿1[𝑈]𝛿2[𝑈]−1]. Power computes (𝑆,𝜏)=I(Γ,𝑒), solves 𝑈=𝗆𝗎𝗇𝗂𝖿𝗒(𝜏≐𝖭𝗎𝗆[𝛿]), and returns (𝑆;𝑈,𝖭𝗎𝗆[𝛿[𝑈]𝑛]).
The complete canonical core is 𝑎::=𝑥∣――𝑞𝑑∣𝜆(𝑥:𝜏).𝑎∣𝑎𝑎∣𝗅𝖾𝗍𝑥=𝑎𝗂𝗇𝑎∣𝑎⊙𝑎∣𝑎⟨𝑛⟩∣𝖺𝗋𝗂𝗍𝗁𝖾𝗋𝗋,𝑣::=――𝑞𝑑∣𝜆(𝑥:𝜏).𝑎,𝐸::=[]∣𝐸𝑎∣𝑣𝐸∣𝗅𝖾𝗍𝑥=𝐸𝗂𝗇𝑎∣𝐸⊙𝑎∣𝑣⊙𝐸∣𝐸⟨𝑛⟩, where ⊙∈{+,∗,/}. Core contexts contain monotypes only; C-Var and C-Let are monomorphic:
Δ(𝑥)=𝜏
Δ⊢𝑥:𝜏
C-Var
Δ,𝑥:𝜏⊢𝑎:𝜐
Δ⊢𝜆(𝑥:𝜏).𝑎:𝜏→𝜐
C-Lam
Δ⊢𝑎1:𝜏→𝜐Δ⊢𝑎2:𝜏
Δ⊢𝑎1𝑎2:𝜐
C-App
Δ⊢𝑎1:𝜏Δ,𝑥:𝜏⊢𝑎2:𝜐
Δ⊢𝗅𝖾𝗍𝑥=𝑎1𝗂𝗇𝑎2:𝜐
C-Let
The core numeric rules are
Δ⊢――𝑞𝑑:𝖭𝗎𝗆[𝑑]
C-Lit
Δ⊢𝑎1:𝖭𝗎𝗆[𝑑]Δ⊢𝑎2:𝖭𝗎𝗆[𝑑]
Δ⊢𝑎1+𝑎2:𝖭𝗎𝗆[𝑑]
C-Add
Δ⊢𝑎1:𝖭𝗎𝗆[𝑑1]Δ⊢𝑎2:𝖭𝗎𝗆[𝑑2]
Δ⊢𝑎1∗𝑎2:𝖭𝗎𝗆[𝑑1𝑑2]
C-Mul
Δ⊢𝑎1:𝖭𝗎𝗆[𝑑1]Δ⊢𝑎2:𝖭𝗎𝗆[𝑑2]
Δ⊢𝑎1/𝑎2:𝖭𝗎𝗆[𝑑1𝑑−12]
C-Div
Δ⊢𝑎:𝖭𝗎𝗆[𝑑]
Δ⊢𝑎⟨𝑛⟩:𝖭𝗎𝗆[𝑑𝑛]
C-Pow
Δ⊢𝖺𝗋𝗂𝗍𝗁𝖾𝗋𝗋:𝜏
C-ArithErr
The functional roots are (𝜆(𝑥:𝜏).𝑏)𝑣⟶𝑏[𝑣/𝑥],𝗅𝖾𝗍𝑥=𝑣𝗂𝗇𝑏⟶𝑏[𝑣/𝑥], with capture-avoiding substitution. Compatibility decomposes 𝐸 into one-hole frames 𝐹: 𝐹⟨𝑟⟩⟶𝐹⟨𝑟′⟩ for a root step, and only 𝐹⟨𝖺𝗋𝗂𝗍𝗁𝖾𝗋𝗋⟩ propagates in one step. Source elaboration is derivation directed. It inserts inferred lambda annotations and maps a generalized source-let declaration to a template 𝜃↦𝑎[𝜃]; each variable instance emits the specialized template, so no polymorphic value reaches the runtime core. Literal elaboration is 𝑞@𝑢↦―――𝑞𝑠𝑢𝑑𝑢; the arithmetic and zero-domain roots are exactly those displayed in the owning chapter.