Expand description
Nested square roots: values in a tower of adjoined radicals.
crate::Root2 holds one square root over plain numbers. Arc
constructions need more: a hit on a circle is a + b*sqrt(D), and a
distance or a second construction from that hit takes another square
root of an expression that already contains sqrt(D). This module
represents such values exactly.
§Representation
A Tower is a list of radicands r_1, ..., r_k, each built only
from the radicals before it. A Nested value at level k is
a + b*sqrt(r_k) with a and b at level k - 1, stored flat as a
coefficient vector of length 2^k (low half a, high half b).
§Why no canonical form is needed
Radicals need not be independent: sqrt(8) and sqrt(2) may both be
adjoined, and then sqrt(8) - 2*sqrt(2) has non-zero coefficients but
value zero. That is fine. Both the product rule
(a + b√r)(c + d√r) = (ac + bd·r) + (ad + bc)√r and the sign rule below
are identities about real numbers, true whatever the coefficients are.
So signs are exact, including exact zeros, without ever reducing to a
basis, which is what keeps this module small.
§Sign
sign(a + b*sqrt(r)), recursively by level: if a and b*sqrt(r)
agree in sign (or one is zero) that is the answer; otherwise it is
sign(a) * sign(a^2 - b^2*r), a value one level down. Level 0 asks the
arithmetic T directly, so the same code runs as the interval filter
and as the exact fallback (see crate::certify()).
§Cost
Each level squares once, so the polynomial degree in the inputs, and
with it exact-tier mantissa length, doubles per level; a product costs
five products one level down. Depth is capped at MAX_DEPTH.
Structs§
Constants§
- MAX_
DEPTH - Most radicals one tower may hold. A product at depth
kcosts5^kbase products, and exact mantissas grow2^k-fold in degree.