Optionalvalue: InputValue<Root | Fraction>ASCIIMath rendering of the current state (terminal output, not chainable).
Fraction multiplying the radical. Never an invalid (NaN) fraction.
Index of the root: 2 for a square root, 3 for a cube root...
The index as a fractional exponent: 1 / index (e.g. index 3 → 1/3).
Fraction under the root sign. Never an invalid (NaN) fraction.
LaTeX rendering of the current state (terminal output, not chainable).
Numeric value of the root. Returns NaN for an even root of a negative radical (not real); an odd root of a negative is real and negative.
Display option (chainable, returns this): remove the forced leading '+'.
Display option (chainable, returns this): force a leading '+' on a positive factor.
Add another root. Both operands are reduced to a common radical first.
Copy the mathematical state of another instance into this (display
state is NOT transferred — the receiver keeps its own formatting). Entry
point used when constructing/parsing from a same-type input. Distinct from
clone. Classes without a real implementation throw
NotImplementedError.
Explicit builder: index, radical and optional factor (defaults to 1).
Optionalfactor: InputValue<Fraction>convert to root(index)(radical), without factor
True when both roots have the same real value, compared exactly (no floating point):
sqrt(8) equals 2sqrt(2). An even root of a negative radical is not real and equals nothing.
True when factor and radical are both 1. Reduce the root first to detect sqrt(4).
True when the value is a rational number once reduced (sqrt(9), root(3)(-8)), false for sqrt(2).
True when the factor or the radical is zero.
Multiply by another root. Computed on a clone and committed on success (atomicity).
Set the value to 1.
Change the sign of the root (the sign is carried by the factor).
Router: inspect the input type and delegate to the matching builder. A same-type (Root) input goes through copy(); every other form has its own from*** / #fromScalar. Construction logic is never inlined here.
Put the root in simplified form: no root in the denominator, and the greatest perfect power extracted
from the radical (sqrt(12) becomes 2sqrt(3)).
For an odd index, the sign always ends up on the factor and the radical becomes positive
(root(3)(-40) becomes -2root(3)(5)). For an even index, a negative radical is left unchanged.
Square root of the root, same as root(2).
Subtract another root (see add for the shared-radical requirement).
Set the value to 0.
StaticfromStaticfromBuild a new Root by delegating a string to the sqrt / root parser, or to the scalar builder for a plain fraction string.
A real root
factor · ⁿ√radical, where the factor and the radical are Fractions and the indexnis a strictly positive integer (2 by default). Built from a string ("3sqrt(5)","root(3)(10)"), a number or a fraction.Rootis strict: a malformed input throws aParseError.Example