From 6f2752c46232344ebe2b6a06e15850ad99cb1c47 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 28 Sep 2026 20:47:11 +0000 Subject: [PATCH] An identity only the simplifier shows is solved to every value `sqrt(x)^2 = x` and `sin(x)^2 + cos(x)^2 = 1` reached Newton's method unread: their residual is zero wherever it is evaluated, so every start of its grid converged at once, and each was kept, 191 numbers for an equation every number satisfies. Where every analytical route has declined, the equation is simplified once before Newton's method is tried, and an unconditional zero is answered with CC, as `x + 1 = x + 1` already was. A zero with a condition goes on to Newton's method as before: `(x^2 - 1)/(x - 1) - x - 1` is zero for every x but 1. The unit tests pass (net10.0, 13333), every target builds, and the allocation gate passes. Part of #1420. Co-Authored-By: Claude Opus 5.5 --- BREAKING-CHANGES.md | 15 +++++++++++++++ .../EquationSolver/AnalyticalEquationSolver.cs | 10 ++++++++++ .../Algebra/SolveTest/IdentityEquationTest.cs | 11 +++++++++++ 3 files changed, 36 insertions(+) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 1d9746658..46edb02de 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -1647,6 +1647,21 @@ in 2.5.0. | `forall p in PP : forall a in ZZ : a^p mod p = a mod p` | `UnhandledParseException` | `True` | | `forall p in PP : forall a, b in ZZ : (a + b)^p = a^p + b^p (mod p)` | `UnhandledParseException` | `True` | +### An identity only the simplifier shows is solved to every value + +`sqrt(x)^2 = x` was answered with the whole starting grid of Newton's method, 191 numbers. Nothing +analytical read it, and its residual is zero wherever it is evaluated, so every start converged at +once and each was kept. Where every analytical route has declined, the equation is now simplified +once before Newton's method is tried, and an unconditional zero is answered with `CC`, as +`x + 1 = x + 1` already was. A zero with a condition is not taken, and goes on to Newton's method as +before: `(x^2 - 1)/(x - 1) - x - 1` is zero for every `x` but 1, where `CC` would be wrong +([#1420](https://github.com/asc-community/AngouriMath/issues/1420)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"sqrt(x)^2 = x".ToEntity().Solve("x")` | `{ -10, -49/5, -48/5, …, -8 - 8i, … }`, 191 numbers | `CC` | +| `"sin(x)^2 + cos(x)^2 = 1".ToEntity().Solve("x")` | the same 191 numbers | `CC` | + ### An equation the solver cannot invert is left unsolved, not answered with no roots `x! = 6` was answered `{ }`, a claim that it has no roots, and it has 3. The solver isolates `x` diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/AnalyticalEquationSolver.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/AnalyticalEquationSolver.cs index 6602dbce0..1f1cbc662 100644 --- a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/AnalyticalEquationSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/AnalyticalEquationSolver.cs @@ -357,6 +357,16 @@ bool ProductIsDefinedAt(Entity root) // TODO: Solve factorials (Needs Lambert W function) // https://mathoverflow.net/a/28977 + // An identity is satisfied by every x, and not by the points a numerical search + // starts from: `sqrt(x)^2 - x` is zero wherever it is evaluated, so every start of + // Newton's grid converged at once and each was kept, two hundred numbers for an + // equation every number satisfies. Asked of the simplifier here, where every + // analytical route has declined, since it is a whole simplification; and only an + // unconditional zero, since `(x^2 - 1)/(x - 1) - x - 1` is zero for every x but 1. + // https://github.com/asc-community/AngouriMath/issues/1420 + if (expr.Vars.Count == 1 && expr.Simplify() is Integer { IsZero: true }) + return MathS.Sets.C; + // A numerical search that comes back with nothing has not shown there is // nothing to find: Newton's method is started from finitely many points inside // a bounded region, so an empty result is a fact about the search rather than diff --git a/Sources/Tests/UnitTests/Algebra/SolveTest/IdentityEquationTest.cs b/Sources/Tests/UnitTests/Algebra/SolveTest/IdentityEquationTest.cs index 48e54b4e1..5c27f8c47 100644 --- a/Sources/Tests/UnitTests/Algebra/SolveTest/IdentityEquationTest.cs +++ b/Sources/Tests/UnitTests/Algebra/SolveTest/IdentityEquationTest.cs @@ -31,6 +31,17 @@ public sealed class IdentityEquationTest public void EveryValueSatisfiesAnIdentity(string equation) => Assert.Equal(MathS.Sets.C, equation.ToEntity().Solve("x")); + /// + /// And one that only the simplifier shows is an identity, which reached Newton's method + /// and came back as every point of its starting grid, two hundred numbers -- + /// https://github.com/asc-community/AngouriMath/issues/1420. + /// + [Theory] + [InlineData("sqrt(x)^2 = x")] + [InlineData("sin(x)^2 + cos(x)^2 = 1")] + public void EveryValueSatisfiesAnIdentityTheSimplifierShows(string equation) => + Assert.Equal(MathS.Sets.C, equation.ToEntity().Solve("x")); + [Theory] [InlineData("1 = 0")] [InlineData("x - x + 1 = 0")]