Expand description
Kanonak expression runtime (expressionRuntimeVersion “1”).
A small, deterministic tree-walker that folds a kanonak.org/transformations
(tx) + kanonak.org/math expression tree to a single number. A faithful
port of the reference TypeScript kernel, verified against the shared parity
vectors — including the determinism traps (Round half-away-from-zero, floored
Modulo, Sign(0)=0, comparisons as 1/0).
Three layers, exactly as the reference establishes:
- DISPATCH —
operator_arityderives an operator’s operand shape from itstxsuperclass: UnaryNumericOp -> unaryvalue; BinaryArithmetic / BinaryComparison -> binary; BooleanLogic -> n-aryoperands; plus the two structural shapes the hierarchy can’t imply (Not’soperand,Clip’s ternary). - PRIMITIVES — the authored, determinism-bearing folds (
unary/binary). - THE FOLD —
evaluate: operators recurse + apply a primitive; literals yield their numeric value; EVERYTHING ELSE (a typed VarRef, a domainStep/Time/Smooth, any future leaf) is handed to the caller’sresolve. The runtime never privilegestx.VarRef— it is just one leaf a domain may resolve.
Value domain: uniform f64. Booleans and comparison results are 1.0/0.0.
Operator/literal type tags are matched against &'static str literals (the
frozen canonical URIs) — no allocation in the evaluation hot path, which
matters for the per-step integrators (e.g. RK4) that re-evaluate an equation
thousands of times.
Structs§
- Eval
Options - Optional evaluation context for the ordered comparisons (
IsAtLeast,Dominates). Absent (or missing a needed entry), an ordered comparison fails loudly — never a silent false from a missing table. - Expression
Error - An evaluation error. Determinism traps (Divide/Modulo by zero, Ln/Log10 of
<=0, Sqrt of <0) and structural problems raise this — never
NaN/Inf. - Trace
Node - One node of an evaluation trace — the verdict tree
explainreturns. Mirrors the expression:typis the node’s type URI,valueits result (1.0/0.0for booleans),childrenthe operand traces in evaluation order. A short-circuited operand is simply ABSENT fromchildren— the trace is truthful about what ran. Ordered comparisons carry their resolved operand identities asleft_ref/right_refinstead of children. This is a runtime return shape, not an ontology class.
Constants§
- EXPRESSION_
RUNTIME_ VERSION - The frozen expression-runtime version (determinism contract). Not hashed.
Functions§
- evaluate
- Evaluate an expression tree to a number. Operators fold via the frozen
dispatch + primitive tables; literals yield their numeric value; any other
node is delegated to
resolve. - evaluate_
with_ options evaluatewith the ordered-comparison evaluation context (closures + identity-leaf resolution).optionsis only consulted when anIsAtLeast/Dominatesnode is reached;Noneis valid for trees without them.- explain
- Evaluate an expression tree and return the verdict tree — the regex-debugger
view: every evaluated node, its own result, and (for ordered comparisons)
the identities it compared. The root’s
valueis exactly whatevaluatereturns for the same inputs; the conformance suite runs every vector through both and requires agreement, so the two entry points cannot drift. Kept separate fromevaluateso the hot path never pays for trace allocation. Errors propagate exactly as inevaluate— a failed evaluation yields an error, not a partial trace.
Type Aliases§
- Closure
Table - The transitive closures ordered comparisons consult, keyed by the ordering
property’s canonical URI, then by member:
closures[property][from]is the set of membersfromreaches. Flat, already-closed data — typically the SDK reasoner’sprp-trpsaturation emitted at code-generation time. The kernel does set membership only; it never computes a closure, resolves a package, or reasons. - Resolve
- Resolve any node the kernel does not recognise as an operator or literal — a
binding (
tx.VarRef, a domain’s typedrefersToVarRef) or a domain leaf (Step,Time,Smooth…) — to a number.ctxis opaque caller state.recurseis handed back so a domain leaf containing sub-expressions can recurse into the kernel. - Resolve
Ref - Resolve an identity leaf inside an ordered comparison — any operand node
that is not a
tx.UriLiteral— to a member’s canonical versionless URI (publisher/package/name). The identity-domain mirror ofResolve: the kernel owns the constant leaf, the caller owns bindings.