Skip to main content

Module symbolic_algebra

Module symbolic_algebra 

Source
Expand description

Symbolic algebra — a small computer-algebra system (CAS).

Expression trees over rationals/reals + variables, with simplify, differentiate, numeric eval, and symbolic equation solving. This is the ALGEBRA_MANIFOLD_PLAN.md Phase 3 module and is DELIBERATELY distinct from solvers/symbolic_logic (which is SAT / defeasible LOGIC, not computer algebra).

The CAS is an authoring / tooling path and may allocate (Box, String); it must NOT be used on an NQuin/SlgArena hot path. Results can be bridged back into the graph via expr_citation_hash for provenance.

Enums§

Expr
A symbolic expression over real constants and named variables.

Functions§

add
c
cos
differentiate
Symbolic derivative of expr with respect to variable wrt. The result is NOT auto-simplified — call simplify on it for a compact form.
div
exp
expand
Distribute every product over sums and expand small positive integer powers, so the result contains no Mul/Pow node with an additive child. Semantically equal to the input (verify by evaluation). Powers above 8 are left unexpanded to bound blow-up.
expr_citation_hash
A stable provenance hash of an expression’s canonical form, for citing symbolic results back into the graph (Phase 3.8 bridge). Two structurally-equal expressions hash equally; this is q_hash over the canonical Display string.
factor_quadratic
Factor a real quadratic a·x² + b·x + c into a·(x − r₁)·(x − r₂) when it has real roots. Returns None when the discriminant is negative (no real factorisation) or a = 0. Root constants are snapped to integers/halves when numerically close, so the common rational case factors cleanly.
from_quins
Reconstruct an expression from a post-order Vec<NQuin> produced by to_quins.
ln
mul
neg
parse
Parse a textual expression like "x^3 - 2*x^2 + 5" or "sqrt(b^2 - 4*a*c)" into an Expr. Supports + - * / ^, parentheses, sqrt(...), numbers and identifiers.
pow
simplify
Simplify an expression: constant folding, identity elimination (x+0, x·1, x·0, x⁰, , −(−x), x/1, x−x, x/x) and collection of an identical x+x → 2·x. Applied to a fixpoint (bounded).
sin
solve_quadratic_symbolic
Symbolic roots of a·x² + b·x + c = 0 with real coefficients, as exact Exprs (-b ± √(b²−4ac)) / (2a). Returns the two root expressions (simplified). For a = 0 returns the single linear root -c/b.
sqrt
sub
tan
to_quins
Serialise an expression into a post-order Vec<NQuin> (the root is the last element).
var