Papers
Topics
Authors
Recent
Search
2000 character limit reached

Dimensional Type System (DTS)

Updated 30 March 2026
  • Dimensional Type System (DTS) is a formal framework that internalizes dimension algebra via free abelian groups to guarantee unit correctness.
  • It extends Hindley–Milner type inference by solving dimension constraints using integer Gaussian elimination, ensuring statically verified operations.
  • DTS preserves dimension metadata throughout compilation, guiding numeric representations, memory management, and enabling advanced diagnostics like automatic differentiation.

A Dimensional Type System (DTS) is a formal type-theoretic framework that internalizes the algebra of dimensions within a programming language’s type system. Its principal aim is to statically guarantee dimensional correctness of numerical programs, provide machine-checked support for dimensional analysis—including Buckingham’s Pi theorem—and propagate dimension metadata across the entire compilation chain, driving representation choice, memory layout, and program diagnostics. DTS generalizes the concept of physical units as types via the construction of types indexed by elements of a free abelian group and leverages these invariants both at type checking and throughout all stages of compilation (Botta et al., 2023, Haynes, 17 Mar 2026).

1. Algebraic Foundations and Type-Level Modeling

The core of a DTS is the internalization of dimension exponents as elements of a free abelian group DD, typically represented as integer-valued vectors over a chosen primitive basis (such as [L,M,T][L, M, T] for mechanics). The set

D={LaMbTca,b,cZ}D = \{ L^a M^b T^c \mid a, b, c \in \mathbb{Z} \}

admits group operations of componentwise addition and inversion: d1d2=zipWith(+)(toVecd1)(toVecd2),d1/d2=d1d21.d_1 * d_2 = \mathrm{zipWith}(+)\,(\mathrm{toVec}\,d_1)\,(\mathrm{toVec}\,d_2), \qquad d_1 / d_2 = d_1 * d_2^{-1}. Special elements include DimLess=[0,0,0]\mathit{DimLess} = [0,0,0], which is the dimensionless unit, and generator dimensions such as Length=[1,0,0]\mathit{Length} = [1,0,0].

A physical quantity is encoded as a pair of a real value and a dimension tag: data  Quantity  :  D    Type  where spaceMkQ  :  {  d:D}    Units    R    Quantity  d\mathbf{data}\;\mathit{Quantity}\;:\;\mathit{D}\;\to\;\mathit{Type}\;\mathbf{where}\ \phantom{space}\mathit{MkQ}\;:\;\{\;d:D\}\;\to\;\mathit{Units}\;\to\;\mathbb{R}\;\to\;\mathit{Quantity}\;d ensuring that every scalar value is dimension-indexed. Concrete operations (addition, multiplication, exponentiation) are statically checked and restricted via these dimension indices, e.g., addition is only permitted between quantities sharing the same dimension.

2. Inference Algorithm and Decidability

DTS extends Hindley–Milner type inference with constraints derived from finitely generated abelian groups. Typing judgments are of the form

Γ;  C;  κ    e:τ\Gamma;\;C;\;\kappa \;\vdash\; e:\tau

where Γ\Gamma maps variables to dimension-indexed types, CC is a set of dimension constraints—homogeneous linear equations of the form inidi=0\sum_i n_i d_i = 0, niZn_i \in \mathbb{Z}—and κ\kappa is a coeffect context (discussed later).

Type inference proceeds by:

  1. Generating fresh type and dimension variables for each subterm.
  2. Accumulating constraints via program traversal: e.g., addition requires d(e1)=d(e2)d(e_1) = d(e_2), multiplication requires d(res)=d(e1)+d(e2)d(res) = d(e_1) + d(e_2).
  3. Solving the type constraints via conventional unification, and dimension constraints via integer Gaussian elimination.
  4. Generalizing over unconstrained type and dimension variables for polymorphism.

Because the number of base-dimensions kk is fixed, constraint solving is polynomial-time and, in practice, linear with respect to program size (Haynes, 17 Mar 2026). Principality and completeness are maintained: there exists a most general dimension assignment for every well-typed program.

3. Static Dimensional Guarantees and Dimensional Analysis

DTS statically enforces unit-correctness: violations such as adding length and mass produce compile-time errors. Arithmetic manipulations on dimensions utilize the group structure, supporting full automation for compound unit calculations.

DTS natively encodes Buckingham’s Pi theorem. Independence and dependence among dimension vectors are formalized as

AreIndep:Vect  k  DType, IsDep:DVect  k  DType\mathit{AreIndep} : \mathrm{Vect}\;k\;D \to \mathit{Type},\ \mathit{IsDep} : D \to \mathrm{Vect}\;k\;D \to \mathit{Type}

providing type-level proofs of Pi groups. The system verifies that dimensionless combinations and their exponents solve the necessary integer equations. For example, the period of a pendulum is shown to yield the Pi group Π=τ2g/\Pi = \tau^2 g / \ell, with type-level proofs establishing its dimensionlessness (Botta et al., 2023).

4. Compilation and Metadata Preservation

A distinctive property of DTS is the persistence of dimension annotations as codata throughout the entire compilation pipeline, particularly in multi-level IR lowering (e.g., MLIR) (Haynes, 17 Mar 2026). Each PSG (Program Semantic Graph) node carries dimension metadata, paired type, value range, chosen numeric representation (e.g., f64f64, posit<32,2>posit<32,2>), word width, memory footprint, coeffect (allocation/lifetime), and cache locality information.

At each compilation stage—AST, PSG, MLIR, target IR, codegen—dimensions are retained as metadata, influencing optimization passes such as numeric representation selection and memory layout, but never altering program semantics. At the binary level, dimensions survive as debug metadata (e.g., DWARF-style tags), enabling post hoc static and runtime diagnostics.

5. Numeric Representation, Memory Management, and Coeffects

The DTS metadata informs numeric representation selection by associating each value vv with its dimension d(v)d(v) and inferred value range [a,b][a, b]. Representation choices are optimized via error-minimization: r=argminrRmaxx[a,b]xroundr(x)x,r^* = \arg\min_{r \in R} \max_{x\in [a,b]} \frac{|x - \mathrm{round}_r(x)|}{|x|}, where RR is the set of available target formats. Word width, memory footprint, and, where applicable, quire size (for posits) are derived from this information.

Deterministic Memory Management (DMM) is formalized as a coeffect system. Each value is classified into one of four allocation/lifetime categories:

  • StackScoped\mathit{StackScoped}
  • ClosureCaptured(c)\mathit{ClosureCaptured}(c) (captured in closure at node cc)
  • ReturnEscapes\mathit{ReturnEscapes} (returned from function)
  • ByRefEscapes\mathit{ByRefEscapes} (passed by reference)

This classification propagates via coeffect-typing rules, culminating in allocation strategies that are target-specific but statically checked. The DMM framework enables verified, garbage collection–free lifetime management, essential for high-assurance and embedded targets (Haynes, 17 Mar 2026).

6. Support for Dimensional Differentiation and Automatic Differentiation

Dimensional algebra in DTS is closed under differentiation: for f:Rd1Rd2f: \mathbb{R}^{\langle d_1 \rangle} \to \mathbb{R}^{\langle d_2 \rangle},

fx:Rd2d11.\frac{\partial f}{\partial x} : \mathbb{R}^{\langle d_2 d_1^{-1} \rangle}.

The chain rule is dimensionally reflected by the group law: dim(D(gf))=dim(Dg)dim(Df).\dim(D(g \circ f)) = \dim(Dg) \cdot \dim(Df). Forward-mode automatic differentiation is supported as a coeffect: it requires no activation tape and only O(1)\mathcal{O}(1) auxiliary memory per layer, which is statically verified by the PSG coeffect analysis. Reverse-mode (requiring activations) is treated with explicit heap allocation tracking. The same constraint machinery is used to type the derivative graph as for the forward pass (Haynes, 17 Mar 2026).

7. Design-Time Diagnostics and Tooling

The PSG's codata enables powerful, immediate design-time diagnostics:

  • Escape diagnostics: Track and visualize escape paths, identify closure captures or returns, and propose refactorings.
  • Allocation strategies: Bindings are annotated with stack/arena/heap or hardware region.
  • Representation fidelity: Annotate cross-target transfers (e.g., "x86: float64; FPGA: posit32; fidelity=1.0, PCIe latency 100 ns").
  • Cache locality: Estimate cache line residency and contiguity for hot loops.
  • Automatic differentiation: Annotate memory requirements for forward vs. reverse mode.

These diagnostics are directly queryable from the PSG and require no separate analysis passes. The PSG thus serves as a unified substrate for both compilation and in-depth semantic feedback during development (Haynes, 17 Mar 2026).


DTS synthesizes a machine-checkable algebra of dimensions within the type system, extends classical type inference with abelian group constraints, and maintains dimension metadata as a first-class property throughout compilation. This infrastructure statically eliminates unit errors, automates dimensional analysis, bridges program semantics with numeric representation and memory management, and provides rich, design-time insight into numerical fidelity, allocation, and resource usage (Botta et al., 2023, Haynes, 17 Mar 2026).

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Dimensional Type System (DTS).