Skip to content

Commit c9c26b4

Browse files
Raise an equation to clear a radical only where the rest of it holds none (#2496)
sqrt(x) + x = cos(sqrt(x)) - 1 was answered { }, where 0 is a root. FractionedPolynoms squared it into (x - cos(sqrt(x)) + 1)^2 = x, which still has sqrt(x) inside the cosine; Newton's method answered the square with 0.4557, no root of the equation, and the empty set left after the check dropped it claimed there is none. Raising now declines where the rest of the equation, or a radical term's multiplier, holds a radical of x, and the equation goes to the routes after it: unsolved here, and x + sqrt(x) = e^(sqrt(x)) - 1 keeps both its roots, the decimal one now 1.7e-17 from the root rather than 8.7e-16. Full check: 21105 of 21118 unit tests pass, 13 skipped; BoundCheck, RootCheck (596/596), CasBench (0 wrong), SimpSweep, RuleCheck, PropCheck clean; CanonCheck, Confluence and ModenovCorpus match their baselines. Fixes #2495 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8aefdb3 commit c9c26b4

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ A not-equal written `<>` is read as `not (a = b)`, and printed that way.
4040

4141
---
4242

43+
## Unreleased — since 2.8.0
44+
45+
### An equation is not raised to clear a radical the rest of it still holds
46+
47+
**Silent.** `Solve` raised an equation to clear a radical even where the rest of it held one too, inside a function:
48+
`sqrt(x) + x = cos(sqrt(x)) - 1` was squared into `(x - cos(sqrt(x)) + 1)^2 = x`, which still has `sqrt(x)`. Newton's
49+
method answered the square with `0.4557…`, which is no root of the equation, and once that was dropped the answer was
50+
the empty set, a claim that there is no root, where `x = 0` is one. Such an equation is now left to the routes after
51+
raising, and is unsolved where none of them answers. An equation one of them does answer can come back by another
52+
route, with a decimal root that differs in its last digits
53+
([#2495](https://github.com/asc-community/AngouriMath/issues/2495)).
54+
55+
| Input | Was (2.8.0) | Now |
56+
|---|---|---|
57+
| `"sqrt(x) + x = cos(sqrt(x)) - 1".ToEntity().Solve("x")` | `{ }` | `{ x : sqrt(x) + x = cos(sqrt(x)) - 1 }` |
58+
| `"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 |
59+
4360
## 2.8.0 — since 2.7.0
4461

4562
**Read these first.**

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ internal static bool TrySolve(Entity expr, Variable x, out Set dst)
8181
if (fractioned.Count == 0)
8282
return false; // means that one can either be solved polynomially or unsolvable at all
8383

84+
// Raising clears a radical only where nothing else in the equation holds one. In
85+
// sqrt(x) + x - cos(sqrt(x)) + 1 = 0 the rest has sqrt(x) inside the cosine, so the
86+
// square (x - cos(sqrt(x)) + 1)^2 = x still holds it. Newton's method then answered the
87+
// square with 0.4557, which is no root of the equation, and the empty set left after it
88+
// was dropped claimed there is none -- where x = 0 is one. Left to the routes below.
89+
if (HasARadicalOf(normalPolynom, x) || fractioned.Any(term => HasARadicalOf(term.multiplier, x)))
90+
return false;
91+
8492
// starting from i = 1 check if all are equal to [0]
8593
static bool BasesAreEqual(List<(Entity main, Integer pow)> f1,
8694
List<(Entity main, Integer pow)> f2)
@@ -140,6 +148,11 @@ static bool BasesAreEqual(List<(Entity main, Integer pow)> f1,
140148
return true;
141149
}
142150

151+
/// <summary>Whether <paramref name="expr"/> has a power of something in <paramref name="x"/> to an exponent that is not whole.</summary>
152+
private static bool HasARadicalOf(Entity expr, Variable x)
153+
=> expr.Nodes.Any(node => node is Powf(var @base, var exponent)
154+
&& @base.ContainsNode(x) && exponent.InnerSimplified is not Integer);
155+
143156
/// <summary>
144157
/// <c>m_1 sqrt(A) + m_2 sqrt(B) + P = 0</c>, two different square roots and nothing else
145158
/// fractional, squared until neither is left: <c>m_1^2 A = (P + m_2 sqrt(B))^2</c>, so
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 is raised away only where nothing else in the equation holds one. In
16+
/// <c>sqrt(x) + x = cos(sqrt(x)) - 1</c> the rest has <c>sqrt(x)</c> inside the cosine, so squaring cleared
17+
/// nothing, Newton's method answered the square with a point that is no root, and the empty set left after it was
18+
/// dropped claimed the equation has none, where <c>x = 0</c> is one.
19+
/// https://github.com/asc-community/AngouriMath/issues/2495
20+
/// </summary>
21+
[Trait("Area", "Algebra")]
22+
public sealed class ARadicalTheRestStillHoldsTest
23+
{
24+
[Fact]
25+
public void IsNotAnsweredWithNoRoots()
26+
{
27+
var answer = "sqrt(x) + x = cos(sqrt(x)) - 1".ToEntity().Solve("x");
28+
Assert.False(answer is Entity.Set.FiniteSet { Count: 0 }, $"{answer} claims no roots, and 0 is one");
29+
Assert.IsType<Entity.Set.ConditionalSet>(answer);
30+
}
31+
32+
[Fact]
33+
public void ZeroIsARootOfIt()
34+
=> Assert.Equal(0, "sqrt(x) + x - (cos(sqrt(x)) - 1)".ToEntity().Substitute("x", 0).EvalNumerical());
35+
36+
// The same radical inside a function, where another route answers: both roots, 0 among them. The other is
37+
// found by Newton's method in doubles, 1.7e-17 from the root, so it is held to 1e-12.
38+
[Fact]
39+
public void AnotherRouteStillAnswersItsNeighbour()
40+
{
41+
var roots = Assert.IsType<Entity.Set.FiniteSet>("x + sqrt(x) = e^(sqrt(x)) - 1".ToEntity().Solve("x"));
42+
Assert.Equal(2, roots.Count);
43+
Assert.Contains((Entity)0, roots);
44+
foreach (var root in roots)
45+
Assert.True(((Entity.Number.Complex)"x + sqrt(x) - (e^(sqrt(x)) - 1)".ToEntity().Substitute("x", root).EvalNumerical()).Abs().EDecimal
46+
.CompareTo(PeterO.Numbers.EDecimal.FromString("1e-12")) < 0, $"{root} is not a root");
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)