RootReduce¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
RootReduce[expr] canonicalises an algebraic expression: a constant algebraic number becomes a rational, a quadratic radical, or a Root object; a rational function over a radical tower has its denominator rationalised; a polynomial/rational function in a free variable has its constant-algebraic coefficients canonicalised. Threads over lists, rules (Solve results), equations, inequalities and logic. Option: Method -> "Automatic" | "Recursive" | "NumberField".
Examples (9)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (9)¶
In[1]:= RootReduce[Sqrt[2] + Sqrt[3]]
Out[1]= Root[1 - 10 #1^2 + #1^4 &, 4]
In[2]:= RootReduce[(Sqrt[18] + Sqrt[27]) / Sqrt[5 + 2 Sqrt[6]]]
Out[2]= 3
In[3]:= RootReduce[1/(1 + Sqrt[2])]
Out[3]= -1 + Sqrt[2]
In[4]:= RootReduce[1/(1 + 2^(1/3) + 2^(2/3))]
Out[4]= Root[-1 + 3 #1 + 3 #1^2 + #1^3 &, 1]
In[5]:= RootReduce[Sqrt[2] + Sqrt[3] + Sqrt[5] == Sqrt[10 + 2 Sqrt[15] + 4 Sqrt[4 + Sqrt[15]]]]
Out[5]= True
Parametric tower
Thread over coefficients
Thread over Solve rules
In[9]:= RootReduce[{u -> Sqrt[8], v -> 1/(1 + Sqrt[2])}]
Out[9]= {u -> 2 Sqrt[2], v -> -1 + Sqrt[2]}
Algorithm¶
Mathilda — RootReduce implementation.
RootReduce[expr] canonicalises an algebraic expression. It dispatches between two rigorous FLINT engines depending on the shape of expr:
(1) Constant algebraic NUMBERS (no free symbol) — integers, rationals,
radicals, roots of unity, the imaginary unit and Root[] objects
combined by +,-,*,/,^ — are canonicalised via FLINT `qqbar`
(src/poly/flint_qqbar.c) to a single representative: a rational, a
quadratic radical expression, or a Root[Function[minpoly&], k] object.
This is WL's central RootReduce behaviour.
(2) Algebraic FUNCTIONS over a tower Q(params)(radicals) — radicals whose
radicand carries a free variable (e.g. the Goursat k^(1/3) towers) —
are rationalised by flint_algebraic_field_canonical (src/poly/
flint_bridge.c): the denominator is inverted in the field by an exact
linear solve, no numeric oracle.
(3) POLYNOMIALS / RATIONAL FUNCTIONS in a free variable whose coefficients
are constant algebraic numbers — threaded over via rr_thread_coeffs:
each maximal constant-algebraic subexpression (a coefficient) is
canonicalised via qqbar and the free-variable structure is left intact,
so a vanishing radical coefficient reduces to 0 and its monomial drops
out. Plain polynomial cancellation is NOT performed (that is Cancel).
RootReduce also threads over equations, inequalities and logic functions (Equal, Less, And, ...), and for equations/inequalities of constant algebraic numbers it decides the (in)equality exactly via qqbar. It threads over an (immediate) Rule too, so a Solve result {u -> value, ...} reduces the same way the corresponding Reduce result does. It is Listable, so it threads over lists elementwise.
Options: Method -> "Automatic" | "Recursive" | "NumberField" (see flint_qqbar).
When expr carries no algebraic content (or the case is out of scope) it is returned unchanged, matching WL. Ownership follows the builtin contract: return a new tree or steal from res; never expr_free(res).
Implementation notes¶
Protected,Listable. Threads over lists, over equations, inequalities and logic functions (Equal,Unequal,Less,And, ...), and over an (immediate)Rule— soSolve[...] // RootReducereduces the right-hand side of eachu -> valueentry the same wayReduce[...] // RootReducereduces eachu == value, leaving the free-variable left-hand side intact. For (in)equalities of constant algebraic numbers it decides the relation exactly viaqqbar. ARulewhose left-hand side is the option nameMethodis a trailing option; any other symbol left-hand side (e.g.u -> value) is a positional argument threaded over, not an option.Method:"Recursive"/"Automatic"foldqqbararithmetic bottom-up;"NumberField"re-expresses the value through a single primitive element of a common number field (qqbar_express_in_field). All three yield the identical canonical result. ARoot[]object of degree ≤ 2 (or degree 1) auto-reduces to a quadratic radical / rational.- One positional argument is required; other arg counts emit
RootReduce::argx. An unknownMethodemitsRootReduce::mtd. Idempotent.
Attributes: Listable, Protected.
References¶
See also: Power, Root, Re, Im, Cancel, Equal, Unequal, Less
- Source:
src/rootreduce.c - Specification:
docs/spec/builtins/algebra.md - Tests:
tests/test_rootreduce.c