Guide · 10

Solver

Push an equation the way you’d push a number. Tap it. A live solver card opens, with the equation rendered in publication-quality LaTeX and a picker for which variable you want to solve for. Type the known values into the other rows and the answer appears in the headline as you scrub — no separate “compute” step. When you like what you see, one tap commits the answer back to the stack.

MathExpr detail card, live solver mid-scrub
Tap an equation on the stack. Pick the target. Scrub the knowns. Push the answer.

This is the biggest new thing in RP42. Equations are first-class stack values — a mathexpr type sitting between double and matrix in the type system. Twelve canned formulas ship built-in; you can lift your own from a string. The engine treats them symbolically, LaTeX-renders them for the card, and hands them to a real closed-form-then-numerical solver pipeline.

What is a MathExpr?

A MathExpr is a symbolic equation stored on the stack. The engine keeps it as a tree of nodes (add, multiply, power, function calls, comparisons), not as a string — so it renders as LaTeX on its card, deparses back to the original source, and supports arithmetic operations that build up larger expressions.

Constructing one

From a string. ->EXPR takes a String and parses it into a MathExpr. The parser understands standard infix notation with + - * / ^, function calls, and both = (assignment/equation) and grouping parens:

"a*x^2 + b*x + c = 0" ->EXPR
"y = m*x + b"        ->EXPR
"F = m*a"            ->EXPR
1: a·x² + b·x + c = 0

Constants like pi and e resolve to their numeric values at parse time; everything else stays as an unbound name.

From a canned formula. A dozen famous equations ship as no-arg push words under the Formulas category:

WordEquationDomain
QUAD-EQa x² + b x + c = 0Algebra
PYTHAGa² + b² = c²Geometry
LINEy = m x + bAlgebra
DIST-2Dd² = (x₂−x₁)² + (y₂−y₁)²Geometry
CIRCLE-AA = π r²Geometry
SPHERE-VV = (4/3) π r³Geometry
NEWTON-2F = m aPhysics
OHMV = I RPhysics
KEKE = (1/2) m v²Physics
WAVE-Vv = f λPhysics
KINEM-Vv = v₀ + a tKinematics
KINEM-Xx = x₀ + v₀ t + (1/2) a t²Kinematics

Tap one and the equation lands on the stack, ready to solve.

Formulas keyword grid with a MathExpr card just pushed
The Formulas category holds twelve equations; each is a one-tap push.

Inspecting an equation

Four extractor words tell you what a MathExpr contains:

WordPushesNotes
SYMBOLSArray of free namesFilters out resolved constants (pi, e, phi, i)
DEGREEInteger polynomial degree in the given targetInteger(-1) if not polynomial
LHSLeft-hand side as a MathExprWhole expression if not an equation
RHSRight-hand side as a MathExprValue(Integer(0)) if not an equation
QUAD-EQ SYMBOLS               # → ['a, 'b, 'c, 'x]
QUAD-EQ 'x DEGREE             # → 2
LINE LHS                      # → y
LINE RHS                      # → m*x + b

Solving

The solver comes in three shapes, distinguished by what you want back:

  • SOLVE — pushes the bare result value (or an array for multi-root).
  • SOLVE-EQ — pushes a MathExpr of the form target = value so the answer is self-documenting.
  • SOLUTION — pushes an Object with the bindings and the answer, useful when you want to record a whole scenario.

Each accepts up to four argument shapes:

<expr>              SOLVE          # arity-1: solve for the sole free symbol
<expr> <target>     SOLVE          # arity-2: target explicit, no other bindings
<expr> <bindings>   SOLVE          # arity-2: bindings given, target auto-detected
<expr> <target> <bindings>  SOLVE  # arity-3: everything explicit

Bindings are an Object mapping name → value. Build one with the literal { } marker syntax:

OHM 'V { "I" 2 "R" 10 } SOLVE            # → 20
QUAD-EQ 'x { "a" 1 "b" -5 "c" 6 } SOLVE  # → [2, 3]

The solver runs a dispatch pipeline internally: it tries the closed-form polynomial path first (linear, quadratic, cubic, quartic — the CUBIC and QUARTIC words are exposed separately if you want them), then symbolic isolation with linear and unary-function inversion, then a numerical Newton-Raphson fallback for the transcendental cases (x + cos(x) = 0 and friends). Multi-root polynomial degrees ≥5 route through Aberth-Ehrlich for stability.

When no real root exists — x² + 1 = 0 — the solver auto-promotes to Complex and returns [i, -i]. When all names are bound the arity-2-bindings shape auto-degrades to a Boolean equality check.

The MathExpr detail card

Tap a MathExpr card and the detail sheet gives you a live-preview solver:

  • The equation renders large as LaTeX up top.
  • Below that, a Solve section: pick the target from a segmented picker, fill in the other bindings, and the answer appears in a headline row that updates as you change the numbers.
  • Two push buttons — Push equation (fires SOLVE-EQ) and Push value (fires SOLVE) — commit the answer back to the stack, leaving the original equation preserved just below.
MathExpr detail card mid-scrub with multi-root live result
Multi-root problems land as an Array in the live headline; both roots push together.

SOLVE-RESID for validation

SOLVE-RESID takes an equation, a target name, and a candidate value, and pushes the residual f(target = value). Zero means the value is a root; non-zero means it isn’t. Useful when you’re testing a hypothesis or verifying a hand-computed answer:

QUAD-EQ 'x 2 { "a" 1 "b" -5 "c" 6 } SOLVE-RESID    # → 0  (2 is a root)
QUAD-EQ 'x 4 { "a" 1 "b" -5 "c" 6 } SOLVE-RESID    # → -2 (4 is not)

What’s not here yet

The solver is not a CAS. It doesn’t do partial-fraction decomposition, doesn’t integrate or differentiate for you (though the internals do differentiate for Newton’s method), and doesn’t simplify algebraically the way Mathematica would. It handles:

  • Linear equations, always
  • Polynomials up to degree 4 in closed form
  • Polynomials degree 5+ numerically (Aberth-Ehrlich)
  • Transcendentals with a single free variable via Newton-Raphson
  • Real→Complex auto-promotion when no real root exists
  • Equations or bare expressions (implicit = 0) — anything except inequalities

That covers most everyday physics, algebra, geometry, and kinematics. If your problem is genuinely CAS-shaped — trigonometric identities, closed-form integrals — the solver will punt.

Contact

Send us a message — we'll reply by email.