Skip to content
Getting Started & Language · Error Semantics

Error Tags

The error tag Err = Trunc × EpiKind that Weyl attaches to every value. Truncation remainders are monomial ideals; extrapolation and sampling errors are recorded by source. This page covers the ordering, propagation through arithmetic, and require checks.

An exact rational, a series computed to some order, and a critical point obtained by Padé extrapolation may all end up as a single number, but they are not equally trustworthy. Weyl records which kind each value is in its type and propagates that through every operation, so an approximate result cannot be used downstream as if it were exact.

Two components ​

The error tag is part of the type, written τ @ ε, with

ε=(I,E)∈Trunc×EpiKind\varepsilon = (I, E) \in \mathrm{Trunc} \times \mathrm{EpiKind}

Here II is the truncation remainder—a monomial ideal signifying that the value represents f+O(I)f + O(I), with exact values carrying the zero ideal (0)(0)—while EE is the set of non-exact sources such as Padé extrapolation, Monte Carlo sampling, or a neural surrogate, which is empty (E=∅E = \varnothing) for exact values. The two components are independent. Exact is ((0),∅)((0), \varnothing), written ⊥\bot. A value with only I≠(0)I \neq (0) is usually called perturbative, one with only E≠∅E \neq \varnothing an estimate, and both can be non-trivial at once, for example an exact series multiplied by an extrapolated constant.

The order is componentwise inclusion:

(I1,E1)⊑(I2,E2)  ⟺  I1⊆I2  ∧  E1⊆E2(I_1, E_1) \sqsubseteq (I_2, E_2) \iff I_1 \subseteq I_2 \;\land\; E_1 \subseteq E_2

ε1⊑ε2\varepsilon_1 \sqsubseteq \varepsilon_2 means ε1\varepsilon_1 guarantees at least as much as ε2\varepsilon_2, so a value of type τ @ ε₁ can be used where τ @ ε₂ is required.

The lattice join is not an arithmetic rule

ε1⊔ε2=(I1+I2, E1∪E2)\varepsilon_1 \sqcup \varepsilon_2 = (I_1 + I_2,\, E_1 \cup E_2) is used only for subtyping and for merging control-flow branches such as if. Truncation under multiplication is computed by mul_err below; combining numerical variances must account for covariance and is not an idempotent join either.

Truncation: monomial ideals ​

In the formal power series ring Q[ ⁣[x1,…,xd] ⁣]\mathbb{Q}[\![x_1, \dots, x_d]\!], a truncation remainder is described by a monomial ideal II. By Dickson's lemma every monomial ideal has a unique minimal generating set: monomials none of which divides another. Weyl stores the exponent vectors of that set.

Convention: an order nn always means the first unknown order. A result computed up to and including order 10 has remainder O(x11)O(x^{11}).

NotationIdeal IIMinimal generators
Exact(0)(0)none
Box{x: n, y: m}⟨xn,ym⟩\langle x^n, y^m \rangle(n,0), (0,m)(n, 0),\ (0, m)
Total{(x, y): n}⟨xayn−a:0≤a≤n⟩\langle x^a y^{n-a} : 0 \le a \le n \rangle(n,0),(n−1,1),…,(0,n)(n, 0), (n-1, 1), \dots, (0, n)
General⟨xα1,…,xαr⟩\langle x^{\alpha_1}, \dots, x^{\alpha_r} \ranglereduced exponent vectors

The lattice operations work directly on these minimal generators: inclusion I⊆JI \subseteq J holds iff every generator of II is divisible by some generator of JJ, the sum I+JI + J takes the union of generators and drops any divisible by another, and the intersection I∩JI \cap J takes pairwise $\mathrm{lcm}$s and reduces the resulting set.

Why general ideals are not rounded to Box or Total ​

In multi-parameter expansions (e.g. in (x,κ1,κ2)(x, \kappa_1, \kappa_2)), multiplication readily produces ideals that are neither Box- nor Total-shaped. In the example below the remainder of the product is ⟨x4, x3κ12, κ13⟩\langle x^4,\ x^3\kappa_1^2,\ \kappa_1^3 \rangle. Replacing it by any containing Box or Total ideal (a weaker guarantee) inevitably discards known coefficients: ⟨x3,κ13⟩\langle x^3, \kappa_1^3 \rangle drops the known x3x^3 and x3κ1x^3\kappa_1 terms, ⟨x4,κ12⟩\langle x^4, \kappa_1^2 \rangle drops κ12\kappa_1^2, xκ12x\kappa_1^2, and x2κ12x^2\kappa_1^2, and Total: 3 drops every known cubic term. Replacing it by a smaller ideal is simply wrong, because unknown terms would be treated as zero. Weyl therefore always keeps the full minimal generating set, with no cap on its size.

Addition and multiplication ​

Let a=a0+O(I)a = a_0 + O(I) and b=b0+O(J)b = b_0 + O(J), where a0,b0a_0, b_0 are the known polynomial parts and Supp(a0)\mathrm{Supp}(a_0) is the ideal generated by the nonzero monomials of a0a_0. Then

add_err(a,b)=I+J\mathrm{add\_err}(a, b) = I + J

mul_err(a,b)=I⋅Supp(b0)+J⋅Supp(a0)+I⋅J\mathrm{mul\_err}(a, b) = I \cdot \mathrm{Supp}(b_0) + J \cdot \mathrm{Supp}(a_0) + I \cdot J

The I⋅JI \cdot J term cannot be dropped. When a0=0a_0 = 0 or b0=0b_0 = 0 (for example, when all low orders cancel), the first two terms vanish, and omitting IJIJ would wrongly give Exact. In one variable the formula reduces to the familiar

n(ab)=min⁡(n(a)+v(b),  n(b)+v(a))n(ab) = \min\big(n(a) + v(b),\; n(b) + v(a)\big)

where vv is the lowest nonzero order. For aa with nonzero constant term, the formal inverse a−1a^{-1}, a\sqrt{a} and ln⁡a\ln a keep the truncation ideal of aa. Every compiler pass computes its output tag through add_err and mul_err, never by hand.

A two-parameter example ​

Take

a=x+O(x4,κ12),b=κ1+O(x3,κ13)a = x + O(x^4, \kappa_1^2), \qquad b = \kappa_1 + O(x^3, \kappa_1^3)

so I=⟨x4,κ12⟩I = \langle x^4, \kappa_1^2 \rangle, J=⟨x3,κ13⟩J = \langle x^3, \kappa_1^3 \rangle, Supp(a0)=⟨x⟩\mathrm{Supp}(a_0) = \langle x \rangle, and Supp(b0)=⟨κ1⟩\mathrm{Supp}(b_0) = \langle \kappa_1 \rangle. Under addition, a+ba + b has remainder I+J=⟨x4,κ12,x3,κ13⟩I + J = \langle x^4, \kappa_1^2, x^3, \kappa_1^3 \rangle, which reduces to ⟨x3,κ12⟩\langle x^3, \kappa_1^2 \rangle. Under multiplication, the three contributions to a⋅ba \cdot b are I⋅Supp(b0)=⟨x4κ1, κ13⟩I \cdot \mathrm{Supp}(b_0) = \langle x^4\kappa_1,\ \kappa_1^3 \rangle, J⋅Supp(a0)=⟨x4, xκ13⟩J \cdot \mathrm{Supp}(a_0) = \langle x^4,\ x\kappa_1^3 \rangle, and I⋅J=⟨x7, x4κ13, x3κ12, κ15⟩I \cdot J = \langle x^7,\ x^4\kappa_1^3,\ x^3\kappa_1^2,\ \kappa_1^5 \rangle, whose reduced sum is ⟨x4, x3κ12, κ13⟩\langle x^4,\ x^3\kappa_1^2,\ \kappa_1^3 \rangle. By contrast, if a=O(x4)a = O(x^4) and b=O(x3)b = O(x^3), both known parts vanish and only I⋅J=⟨x7⟩I \cdot J = \langle x^7 \rangle survives, giving O(x7)O(x^7).

Typing rules for expansion and extrapolation ​

expand introduces a truncation ideal. estimate turns a series into a number, clearing the truncation component and adding the method MM to the source set. Below, ε⊕(I,∅)\varepsilon \oplus (I, \varnothing) combines the two tags as add_err does:

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

Γ⊢e⇒Seriesx[v](Scalar[d;p])@(I,E)Γ⊢estimateM(e)⇒Scalar[d′;p′]@((0),  E∪{M})  (Est)\frac{\Gamma \vdash e \Rightarrow \mathrm{Series}_x[v](\mathrm{Scalar}[d; p]) \mathbin{@} (I, E)}{\Gamma \vdash \mathrm{estimate}_M(e) \Rightarrow \mathrm{Scalar}[d'; p'] \mathbin{@} ((0),\; E \cup \{M\})}\;(\textsc{Est})

Sources and runtime uncertainty ​

The static EpiKind records only the source set and a propagation method, not numbers; otherwise type hashing and interning would depend on floating-point values. The current sources are:

SourceMeaning
PadeSpread{family}dlog-Padé extrapolation; the error is the spread across [L/M][L/M] approximants of one family. The tag stays even if the spread happens to be 0
MonteCarlo{samples}Sampling error
NeuralPotential{model}Prediction of a neural surrogate
External(name)Result from an external program, e.g. the fallback solver used when a surrogate is rejected

The numbers live in the runtime RuntimeUncertainty: a variance σ2\sigma^2 or a set of samples. The propagation method EpiMethod is one of: keep joint samples (JointEnsemble), first-order delta method (LinearizedDelta), or a conservative bound (ConservativeBound). When one batch of samples feeds several quantities, joint samples are preferred so correlations are kept. For example,

Var(a+b)=Var(a)+Var(b)+2 Cov(a,b)\mathrm{Var}(a + b) = \mathrm{Var}(a) + \mathrm{Var}(b) + 2\,\mathrm{Cov}(a, b)

so a+aa + a has variance 4 Var(a)4\,\mathrm{Var}(a). When the correlation is unknown, the result either stays "unknown" or gets a Cauchy–Schwarz bound marked ConservativeBound.

Rust definitions ​

From weyl-types/src/err.rs, with derives and methods omitted:

rust
pub struct Trunc {
    pub vars: VarSet,
    pub generators: Vec<ExponentVector>, // minimal generators
}

pub enum EpiSource {
    PadeSpread { family: String },
    TruncationAt { var: SmolStr, order: u32 },
    MonteCarlo { samples: u64 },
    NeuralPotential { model: String },
    External(String),
}

pub enum EpiMethod { Exact, JointEnsemble, LinearizedDelta, ConservativeBound }

pub struct EpiKind {
    pub sources: Vec<EpiSource>,
    pub method: EpiMethod,
}

pub struct Err {
    pub trunc: Trunc,
    pub epi: EpiKind,
}

pub struct RuntimeUncertainty {
    pub sigma2: Option<f64>,
    pub ensemble: Option<Vec<f64>>,
}

pub trait ErrLattice {
    fn join(&self, other: &Self) -> Self;
    fn leq(&self, other: &Self) -> bool;
}

pub fn add_err(a: &ValueInfo, b: &ValueInfo) -> Err;
pub fn mul_err(a: &ValueInfo, b: &ValueInfo) -> Err;

require: accuracy requirements and fallbacks ​

Source code can state accuracy requirements with require:

weyl
-- Checked during type checking: Δ's remainder must be contained in O(x¹¹), else E0331
require Δ known to O(x¹¹)

-- Checked at run time: if x_c's uncertainty is above the threshold, expand further
require uncertainty of x_c < 10⁻³
        otherwise expand to higher order

Truncation requirements are checked during type checking as the ideal inclusion I⊆IreqI \subseteq I_{\text{req}}, with failure reported as a compile error. Uncertainty requirements are checked at run time once the value is computed: if an otherwise clause is present, the fallback runs and the check repeats until it passes or hits a round limit; without one, failure raises error E0331. The neural runtime's confidence check uses the same mechanism, falling back to an exact solver whenever the predicted variance exceeds the threshold and tagging the resulting value's source as External(...).

Each check is written to a telemetry record (TelemetryRecord in weyl-mcp) with the node name, a status such as pass or not_needed, and the node's error tag, for replay and review.

What error tags do not cover ​

An error tag says how far off a value may be and why, not whether it was computed correctly; establishing correctness is the job of the independent oracles, and the boundary between the two is strict. Oracles return only Pass, Fail(OracleDiag), or Inconclusive, never producing certificate objects for downstream consumption. Likewise, a numerical comparison against finite-size ED establishes agreement only at the tested sizes—it does not prove a general symbolic identity and never promotes a truncated or estimated value to Exact. The double-double eigenvalues from ED feed solely into residual fits and are never written back as coefficients into H_eff or user expressions; similarly, rewrites proposed by an LLM take effect only after both the deterministic kernel and the oracles verify them, and they remain subject to error tags.

Weyl v0.1 · MIT License