Skip to content

Compute engine sibling for math nodes: units-typed evaluation, numeric solve-for, worked-example verification #573

Description

@Mearman

Proposes the computation half of the math work (schemas in ExaDev/document-schema.js#15, lowering in #572): a sibling package — compute.js, say — exposing pure functions over serialisable data, per the platform's contracts doctrine:

  • evaluate(expression, bindings, context) -> Quantity | interval | error as a tree-walking interpreter over MathExpression, with optional compile-to-JS for hot paths. FormulaBindings and Quantity schemas land in document-schema.js beside the math value itself so evaluation inputs are typed contracts like everything else.
  • Units as the type system: inputs carry units, results derive units, and adding quantities of incompatible dimensions is a hard error rather than a silent wrong number. Exact rationals for unit-conversion chains.
  • Interval arithmetic over the same evaluator for the bounded-values case: compliance regions over min/max bounds (0.87 <= cos φ <= 1) almost for free once points work.
  • Numeric solve-for via root-finding over our own evaluator (bisection/Newton on one unknown) — covers most rearrangement needs with no symbolic engine.
  • Symbolic work (exact rearrangement emitted as LaTeX, simplification, integration) behind an evaluator interface with a SymPy sidecar as the first adapter; in-house selective algebra (linear-in-target rearrangement) can migrate in later if usage justifies it.

Scope line: this is deliberately not a CAS in the Mathematica sense — units-typed evaluation and numeric solving are the 90% of "compute the result of a formula from a document" and are buildable natively now.

The test harness is the differentiator: worked examples — documents that state a formula and then compute it with numbers — give input-to-expected-output pairs for free. Coverage becomes a measured number: the fraction of parsed formulae whose evaluation reproduces the document's own stated answer, with every miss pointing at a specific gap (missing symbol binding, units convention, unsupported construct).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions