AngouriMath

Navigation

← Back to list of members

CollapseToPerfectSquare​(AngouriMath.​Entity)

 Method (no overloads)

Summary

u + 2*sqrt(u)*sqrt(v) + v collapses to (sqrt(u) + sqrt(v))^2, which
is what 1 + sqrt(2x) + x/2 is.
https://github.com/asc-community/AngouriMath/issues/176

Remarks

The identity itself is unconditional: (sqrt(u) + sqrt(v))^2 expands to
u + 2*sqrt(u)*sqrt(v) + v because sqrt(u)^2 is u for every
complex u. It is the *square of a principal root*, not the root of a
square -- sqrt(u^2) = u is the false one, and holds only for a
non-negative u. https://github.com/asc-community/AngouriMath/issues/752
What cannot be trusted is the test for whether the cross term matches. Deciding
it needs Simplify(System.Int32), and the simplifier equates
sqrt(x)*sqrt(y) with sqrt(x*y), which is false on the branch cuts:
at x = y = -1, x + 2*sqrt(x*y) + y is 0 while
(sqrt(x) + sqrt(y))^2 is -4. Asked symbolically, this rule fired on that
sum and produced a wrong answer.
So the symbolic match only proposes, and a numeric check at sample points
disposes. The points include negative values, which is where a branch-cut error
shows and nowhere else, and every free variable is given a different one so that
x and y cannot coincide into a case that happens to hold. The rule
withdraws unless every sampled point agrees, so a variable it cannot evaluate at
simply means no collapse.
Restricted to sums that contain a radical, both because that is where the gap is
-- a polynomial trinomial is collapsed by the rules above -- and to keep the cost
of that Simplify off every three-term sum in every tree.

Returns

null when the sum is not a square, so the rule does not fire.

























Angouri © 2019-2023 · Project's repo · Site's repo · Octicons · Transparency · 1953 pages online