Skip to content

Commit dce1653

Browse files
Put each point where a radicand is zero back into an equation Newton's method answered (#2497)
A radical's derivative is infinite where its radicand is zero, and Newton's method does not converge to a root there: sin(sqrt(x)) = x was { 0.7686… } without its root 0, and cos(1 - sqrt(x)) - x = cos(1) { 0.3900… } without 0. Where Newton's method answers, each zero of a polynomial radicand is now put into the equation and kept where it simplifies to exactly 0, and a decimal within 1e-10 of one is dropped as its copy. sqrt(x) + x = cos(sqrt(x)) - 1, unsolved since #2496, is { 0 }. Of 21 radical equations, these three gain 0 and the rest are unchanged; radcheck and logcheck on the same 300 equations as master, seed 1116, have no findings. Full check: 21109 of 21122 unit tests pass, 13 skipped; BoundCheck, RootCheck (596/596), CasBench (0 wrong), SimpSweep, RuleCheck, PropCheck clean; CanonCheck, Confluence and ModenovCorpus match their baselines. Follows #2495 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c9c26b4 commit dce1653

4 files changed

Lines changed: 104 additions & 4 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,21 @@ route, with a decimal root that differs in its last digits
5454

5555
| Input | Was (2.8.0) | Now |
5656
|---|---|---|
57-
| `"sqrt(x) + x = cos(sqrt(x)) - 1".ToEntity().Solve("x")` | `{ }` | `{ x : sqrt(x) + x = cos(sqrt(x)) - 1 }` |
57+
| `"sqrt(x) + x = cos(sqrt(x)) - 1".ToEntity().Solve("x")` | `{ }` | `{ 0 }`, by the next entry; unsolved by this one alone |
5858
| `"x + sqrt(x) = e^(sqrt(x)) - 1".ToEntity().Solve("x")` | `{ 0, 3.21586080818110353… }`, 8.7e-16 from the root | `{ 0, 3.21586080818110264… }`, 1.7e-17 from it |
5959

60+
### A root where a radicand is zero is found beside Newton's
61+
62+
**Silent.** Newton's method does not converge to a root where a radicand is zero, since a radical's derivative is
63+
infinite there, and an equation it answered left such a root out. Each point where a radicand in the equation is zero
64+
is now put back in, and kept where the equation is exactly zero. The roots Newton's method finds are unchanged
65+
([#2495](https://github.com/asc-community/AngouriMath/issues/2495)).
66+
67+
| Input | Was (2.8.0) | Now |
68+
|---|---|---|
69+
| `"sin(sqrt(x)) = x".ToEntity().Solve("x")` | `{ 0.76864885676094940… }` | `{ 0, 0.76864885676094940… }` |
70+
| `"cos(1 - sqrt(x)) - x = cos(1)".ToEntity().Solve("x")` | `{ 0.39003113021627860… }` | `{ 0, 0.39003113021627860… }` |
71+
6072
## 2.8.0 — since 2.7.0
6173

6274
**Read these first.**

‎Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/AnalyticalEquationSolver.cs‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ bool ProductIsDefinedAt(Entity root)
485485
// `Solve`. https://github.com/asc-community/AngouriMath/issues/1603
486486
if (MathS.Settings.AllowNewton && expr.Vars.Count == 1)
487487
return NumericalSolving.NewtonSolver.TrySolveNt(expr, x, MathS.Settings.NewtonSolver) is { } roots
488-
&& roots.Select(ent => TryDowncast(expr, x, ent)).ToSet() is FiniteSet { IsSetEmpty: false } found
488+
&& WithRootsAtRadicandZeros(expr, x, roots.Select(ent => TryDowncast(expr, x, ent)).ToList()).ToSet() is FiniteSet { IsSetEmpty: false } found
489489
? found : Unsolved(expr, x);
490490

491491
return Unsolved(expr, x);
@@ -513,6 +513,44 @@ private static IEnumerable<Entity> SpellingsToSolveOver(Entity expr)
513513
yield return alt;
514514
}
515515

516+
/// <summary>
517+
/// <paramref name="found"/>, with each point where a radicand in <paramref name="expr"/> is zero
518+
/// and <paramref name="expr"/> is exactly zero, and without the decimals that are near copies of one.
519+
/// </summary>
520+
/// <remarks>
521+
/// A radical's derivative is infinite where its radicand is zero, and Newton's method does not
522+
/// converge to a root there: sin(sqrt(x)) = x was answered { 0.7686… } without its root 0, and
523+
/// cos(1 - sqrt(x)) - x = cos(1) { 0.3900… } without 0. Those points are finitely many and exact,
524+
/// so each is put into the equation, and kept only where it simplifies to 0.
525+
/// https://github.com/asc-community/AngouriMath/issues/2495
526+
/// </remarks>
527+
private static IEnumerable<Entity> WithRootsAtRadicandZeros(Entity expr, Variable x, List<Entity> found)
528+
{
529+
var atZeros = new List<Entity>();
530+
foreach (var radicand in expr.Nodes
531+
.OfType<Powf>()
532+
.Where(power => power.Base.ContainsNode(x) && power.Exponent.InnerSimplified is Rational and not Integer)
533+
.Select(power => power.Base)
534+
.Distinct())
535+
{
536+
if (!TreeAnalyzer.TryGetPolynomial(radicand, x, out _)
537+
|| PolynomialSolver.SolveAsPolynomial(radicand, x, out _) is not { } zeros)
538+
continue;
539+
foreach (var zero in zeros)
540+
if (!zero.Vars.Any()
541+
&& !atZeros.Contains(zero)
542+
&& expr.Substitute(x, zero).Simplify() is Integer { IsZero: true })
543+
atZeros.Add(zero);
544+
}
545+
if (atZeros.Count == 0)
546+
return found;
547+
bool IsACopyOfOneAtAZero(Entity root)
548+
=> root.Evaled is Complex value
549+
&& atZeros.Any(zero => zero.Evaled is Complex exact
550+
&& (value - exact).Abs().EDecimal.CompareTo(PeterO.Numbers.EDecimal.FromString("1e-10")) < 0);
551+
return atZeros.Concat(found.Where(root => !IsACopyOfOneAtAZero(root)));
552+
}
553+
516554
/// <summary>
517555
/// The answer when every solver above has declined: the equation itself, as the set
518556
/// of the <paramref name="x"/> that satisfy it.

‎Sources/Tests/UnitTests/Algebra/SolveTest/ARadicalTheRestStillHoldsTest.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) 2019-2026 Angouri.
33
// AngouriMath is licensed under MIT.
44
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
@@ -26,7 +26,8 @@ public void IsNotAnsweredWithNoRoots()
2626
{
2727
var answer = "sqrt(x) + x = cos(sqrt(x)) - 1".ToEntity().Solve("x");
2828
Assert.False(answer is Entity.Set.FiniteSet { Count: 0 }, $"{answer} claims no roots, and 0 is one");
29-
Assert.IsType<Entity.Set.ConditionalSet>(answer);
29+
// 0 is found where the radicand is zero, beside Newton's method; see ARootWhereARadicandIsZeroTest.
30+
Assert.Contains((Entity)0, Assert.IsType<Entity.Set.FiniteSet>(answer));
3031
}
3132

3233
[Fact]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using AngouriMath;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Algebra
13+
{
14+
/// <summary>
15+
/// A radical's derivative is infinite where its radicand is zero, and Newton's method does not converge to a root
16+
/// there. An equation answered by it has each point where a radicand is zero put back in, and kept where the
17+
/// equation is exactly zero: <c>sin(sqrt(x)) = x</c> was answered without its root 0.
18+
/// https://github.com/asc-community/AngouriMath/issues/2495
19+
/// </summary>
20+
[Trait("Area", "Algebra")]
21+
public sealed class ARootWhereARadicandIsZeroTest
22+
{
23+
[Theory]
24+
[InlineData("sin(sqrt(x)) = x", "0.7686488567609494")]
25+
[InlineData("cos(1 - sqrt(x)) - x = cos(1)", "0.3900311302162786")]
26+
public void HasTheRootAtZeroBesideTheOneNewtonFinds(string equation, string other)
27+
{
28+
var roots = Assert.IsType<Entity.Set.FiniteSet>(equation.ToEntity().Solve("x"));
29+
Assert.Contains((Entity)0, roots);
30+
Assert.Equal(2, roots.Count);
31+
Assert.Contains(roots, root => ((Entity.Number.Complex)(root - other.ToEntity()).EvalNumerical()).Abs().EDecimal
32+
.CompareTo(PeterO.Numbers.EDecimal.FromString("1e-12")) < 0);
33+
}
34+
35+
// A point where a radicand is zero and the equation is not stays out: sqrt(x) = sin(x) + 1 is 1 at 0.
36+
[Fact]
37+
public void AZeroOfARadicandThatIsNoRootStaysOut()
38+
{
39+
var answer = "sqrt(x) = sin(x) + 1".ToEntity().Solve("x");
40+
if (answer is Entity.Set.FiniteSet roots)
41+
Assert.DoesNotContain((Entity)0, roots);
42+
}
43+
44+
// An answer the analytical routes give is not touched: sqrt(x) = x is { 0, 1 } as it was.
45+
[Fact]
46+
public void AnAnalyticalAnswerIsUnchanged()
47+
=> Assert.Equal(new Entity.Set.FiniteSet((Entity)0, (Entity)1), "sqrt(x) = x".ToEntity().Solve("x"));
48+
}
49+
}

0 commit comments

Comments
 (0)