Skip to content

Square an equation in two different square roots away twice - #2335

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
two-square-roots-are-squared-away-twice
Nov 2, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
two-square-roots-are-squared-away-twice

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Found by a radical-equation cross-check at a seed not used before. No issue was filed.

m_1 sqrt(A) + m_2 sqrt(B) + P = 0, with two different square roots, was not raised at all. It went to Newton's method, which cannot reach a root where a radicand is 0.

2.6.0 master this PR
sqrt(-4 - 4x) + sqrt(2 + x) = -3 - 4x { -1.19517…, -1 } { -1.19517… } { -1, … }, the other root in radicals
sqrt(2x + 3) - sqrt(x + 1) = 1 { -1, 3 } { 3 } { -1, 3 }
sqrt(-4 - 4x) + sqrt(2 + x) = 1 { -1 } unsolved { -1 }

The middle column is a regression since 2.6.0, bisected to #2231. 2.6.0 found these roots only because a compiled 0^(-1/2) was 0, so Newton's step from the domain's edge was 0. #2231 made it NaN, which is right, and from then on the root was missed.

The equation is now squared twice, 4 P^2 m_2^2 B = (m_1^2 A - P^2 - m_2^2 B)^2. That keeps every root, and each root of the polynomial is put back into the equation, as for one radical. This happens only for an equation in x alone. With a parameter left in, putting a root back cannot be decided: sqrt(x + 1) + sqrt(x + 2) + a + x = 0 kept all four roots of its square, and at a = 2 none of them is a root.

The same parametric problem exists on master, and in 2.6.0, for one radical: sqrt(x + 1) + a + x = 0 is answered with both roots of its square, and for each a one of them is not a root. That gets its own PR.

radcheck (random radical equations against mpmath), unsolved on master and here:

seed master this PR
61 26 / 400 5
51 31 / 400 7
22 24 / 400 3
62, pow 0 / 600 0

No answer is unsound. The one root reported missed, at seed 61, is a harness false positive and is reported against master too: 1 - 1.732i isn't a root of x·sqrt(x² - 2x + 1) = x - 4.

Tests: all eight cases in TwoSquareRootsTest fail on master. There is a BREAKING entry, An equation in two different square roots is solved exactly.

🤖 Generated with Claude Code

m_1 sqrt(A) + m_2 sqrt(B) + P = 0 with two different square roots was
not raised at all, and went to Newton's method, which cannot reach a root
where a radicand is 0. sqrt(-4 - 4x) + sqrt(2 + x) = -3 - 4x was answered
without its root -1. 2.6.0 found that root only because a compiled
0^(-1/2) was 0, so Newton's step from -1 was 0; since #2231 made it NaN,
the root has been missed, and sqrt(2x + 3) - sqrt(x + 1) = 1 lost its
root -1 with it.

It is now squared twice, 4 P^2 m_2^2 B = (m_1^2 A - P^2 - m_2^2 B)^2,
which keeps every root, and each root of that polynomial is put back into
the equation as for one radical. Only for an equation in x alone: with a
parameter left in, a root put back cannot be decided, and
sqrt(x + 1) + sqrt(x + 2) + a + x = 0 kept all four roots of its square.

radcheck, random radical equations, unsolved on master and here:
seed 61, 26 and 5 of 400; seed 51, 31 and 7; seed 22, 24 and 3; seed 62
(pow), 0 and 0 of 600. No root is unsound and none missed but one that
is not a root.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.7.0 milestone Nov 2, 2026
@Rafael-SOWNet Rafael-SOWNet moved this from Todo to In review in AngouriMath Nov 2, 2026
@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.77%. Comparing base (a7785bc) to head (f1af2ee).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2335   +/-   ##
=======================================
  Coverage   86.76%   86.77%           
=======================================
  Files         312      312           
  Lines       68526    68540   +14     
  Branches    19935    19938    +3     
=======================================
+ Hits        59458    59473   +15     
  Misses       4907     4907           
+ Partials     4161     4160    -1     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.31% <100.00%> (+<0.01%) ⬆️
fsharp 32.97% <ø> (ø)
interactive 40.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...nuous/Solvers/EquationSolver/FractionedPolynoms.cs 85.50% <100.00%> (+3.68%) ⬆️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet
Rafael-SOWNet merged commit 0a58c74 into master Nov 2, 2026
37 of 38 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Nov 2, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the two-square-roots-are-squared-away-twice branch November 2, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant