Calculation engine (ORIXExpression)
flowchart LR
Text["Input text"] --> Lexer --> Parser --> AST["Expr tree"]
AST --> Eval["Evaluator<br/>typed values"]
AST --> Compile["CompiledExpression<br/>Double closures"]
AST --> Printer["Printer<br/>pretty · ASCII · LaTeX"]
Eval --> Value
Eval --> Steps["Explanation steps"]
Eval --> Notes["Verification notes"]
Value --> Formatter["NumberFormatting"]
Compile --> Graph["Graph sampler, quadrature, root finding"]
Parser
A hand-written tokenizer and recursive-descent parser. Text becomes an Expr tree and nothing else: there is no dynamic
code execution of any kind.
flowchart TD
S["statement"] -->|"name = …"| A["assignment"]
S -->|"f(x, y) = …"| D["function definition"]
S --> E["expression"]
E --> Or["or"] --> And["and"] --> Cmp["comparison = ≠ < ≤ > ≥ (chains: a < b < c)"]
Cmp --> Add["+ −"] --> Mul["× ÷ mod implicit ×"] --> Un["unary − + not"]
Un --> Pow["^ (right associative)"] --> Post["postfix ! % °"] --> Prim["number · name · call · ( ) · [ ] · | |"]
Supported syntax: decimal literals with exponents, Unicode operators (× ÷ − · √ π ∞ ≤ ≥ ≠), superscripts (x², x⁻¹),
implicit multiplication (2x, 2(3), (a)(b), 2 sin x), function calls, vectors [1, 2, 3], matrices [1, 2; 3, 4],
absolute-value bars, comparisons, and / or / not, a tolerated missing final parenthesis, locale decimal comma
(with ; as argument separator). Errors carry a character position and a plain-language message.
Typed values
flowchart LR
I["integer<br/>BigInt"] --> R["rational<br/>BigInt / BigInt"] --> D["real<br/>IEEE-754 double"] --> C["complex<br/>Complex<Double>"]
B["boolean"]
Vec["vector of scalars"]
Mat["matrix of scalars"]
Arithmetic promotes only as far as needed: integer ∘ integer stays an integer, a decimal literal is an exact rational,
a transcendental function produces a double, and a result leaves the real line only when complex mode is on.
Other value kinds live in their own engines: unit quantities (ORIXUnits), symbolic expressions (Expr, ORIXSymbolic),
cash-flow series (ORIXFinancial).
Evaluator
A tree-walking evaluator over Value with:
- special forms whose arguments are not evaluated eagerly:
sum,prod,deriv,integral,nsolve,if,piecewise; - about 100 built-in functions, user functions, and native functions registered by other packages (statistics distributions);
- guards: a NaN is a domain error, an unexpected infinity is an overflow error — an invalid number can never be shown as a result;
- step recording for ORIX Explain (each operation with its operand values and result);
- notes for ORIX Verified Results: loss of significance in a floating-point subtraction, an exact fraction that had to fall back to floating point, a large integer rounded on mixing with a double, residuals of linear solves and matrix inverses, error estimates of numerical integration and differentiation, the residual of a numerical root.
Compiled real functions
CompiledExpression turns an Expr into nested Double closures (no allocation per call) for plotting and numerical
methods. It never throws: an undefined point is NaN, which is exactly what a sampler needs to find gaps.
RPN
RPNMachine is a stack over the same Value arithmetic and function library, so algebraic and RPN entry cannot disagree.
A failed operation leaves the stack untouched.
Formatting
Display digits are produced by exact rational arithmetic on the stored value (a double is itself an exact rational), so the rounding shown is always correct, and the stored value is never modified by a display setting. Notations: automatic, fixed, scientific, engineering; significant digits or fixed decimals; locale separators; exact fractions; rectangular or polar complex form; a canonical machine format that parses back to the identical value.