Skip to content

Commit 2aab628

Browse files
Drop a radical root in back-substitution only where an interval shows it fails (#2521)
The Groebner back-substitution puts each root of the last equation into the others and drops a root that leaves one a nonzero number. A root with a radical in it, or an equation holding one assigned before, is put to a number by evaluating, and where the terms are large they cancel to what their hundred digits leave, which downcasting reads as a rational: the root (-4 10^24 - sqrt(28 10^48)) / 6 of its own quartic, with terms near 1e96, left 13/10000. So the system for the parts of x in an equation in a modulus with roots near 10^23 or more dropped its real roots, and 1 - 2x + x|-2 - 3x| = 0 with x written as 10^-24 x was { }. An equation that is a polynomial over Q at the root is still decided exactly; one that is not is decided by an interval, and a root it does not show to fail goes on. Near 10^30 InnerSimplified itself evaluates the radicals into decimals past its digits and downcasts them to integers, so the narrowed equations are wrong before this check is reached, and roots are still lost there, as on master. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 94d6f2c commit 2aab628

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ no longer reads a root whose decimals were flushed to `0` as extending to no sol
7373
| `"x^5 - 3*10^(-60)*x + 10^(-150) = 0".ToEntity().Solve("x")` | `0` among the roots, where the polynomial is `10^-150` | `3.33e-91` in its place |
7474
| `"(1 + i) + 2*(10^12*x) - 3*(10^12*x)^2 + 10^12*x*abs(3 - 10^12*x) = 0".ToEntity().Solve("x")` | `{ -1.87e-13 - 1.58e-13i }`, one root of two | both, `10^-12` times those of the equation in `x` |
7575

76+
### A root with a radical in it is not dropped for what its evaluation leaves
77+
78+
**Silent: `{ }` becomes the roots.** An equation in a modulus is solved for the real and imaginary parts of `x` as a
79+
system, and each root of the system's last equation is put into the others, a root that leaves one a nonzero number
80+
being dropped. A root with a radical in it is put in by evaluating, and where the terms are large they cancel to what
81+
their hundred digits leave, which downcasting reads as a rational: the root of its own polynomial left `13/10000`.
82+
So the real roots of equations whose roots are near `10^23` or more were dropped, and the answer was `{ }`. Such a
83+
root is now dropped only where an interval shows the equation is not 0 at it. Near `10^30` the evaluation rounds
84+
past what an interval can tell, and roots are still lost there.
85+
86+
| Input | Was (2.8.0) | Now |
87+
|---|---|---|
88+
| `"(1 - 2*(10^(-24)*x)) + 10^(-24)*x*abs(-2 - 3*(10^(-24)*x)) = 0".ToEntity().Solve("x")` | `{ }` | `{ -10^24/3 * sqrt(7) - 2 * 10^24/3 }` |
89+
| `"-2*(10^(-24)*x) + 3*(10^(-24)*x)^2 - 2*abs(-3 + 2*(10^(-24)*x)) = 0".ToEntity().Solve("x")` | `{ }` | its two roots, `10^24` times `-(1 + sqrt(19))/3` and `(sqrt(19) - 1)/3` |
90+
7691
### An exact root is not dropped by its condition's rounding
7792

7893
**Silent: answers that were `{ }` now have their roots.** A root found under a condition is kept where the condition

‎Sources/AngouriMath/Functions/Algebra/Groebner/GroebnerSystemSolver.cs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ static bool BackSubstitute(
215215
// the flushed decimals are not to be trusted either.
216216
if (VanishesAtTheExactRoot(equation, variable, root))
217217
return budget.Allow(false, "a root past the decimal range");
218+
// And an equation with a radical in it, from this root or one assigned before, is
219+
// put to a number by evaluating, where a large term cancels to what its digits
220+
// leave, which downcasting reads as a rational: the root
221+
// (-4 10^24 - sqrt(28 10^48)) / 6 of its own quartic, whose terms are near 1e96,
222+
// left 13/10000, and the one real root of 1 - 2x + x|-2 - 3x| = 0 with x written
223+
// as 10^-24 x was taken for no root, the answer { }. Only an interval leaving 0 out
224+
// shows such a root extends to nothing; an equation that is a polynomial over Q is
225+
// decided exactly.
226+
var exactly = equation.Substitute(variable, root);
227+
if (!root.Nodes.Any(IsADecimal)
228+
&& MultivariatePolynomial.TryParse(exactly, new Dictionary<Variable, int>()) is null
229+
&& !AnalyticalSolving.StatementSolver.IsShownNotZero(exactly))
230+
continue;
218231
consistent = false;
219232
}
220233
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.Extensions;
9+
using Xunit;
10+
using static AngouriMath.Entity;
11+
using static AngouriMath.Entity.Set;
12+
13+
namespace AngouriMath.Tests.Algebra
14+
{
15+
/// <summary>
16+
/// An equation in a modulus is solved as a system for the parts of <c>x</c>, and a root of the
17+
/// system's last equation that leaves another a nonzero number is dropped. A root with a radical
18+
/// in it is put in by evaluating, and where the terms are large the evaluation leaves a rational
19+
/// that is not 0 although the root is one: so the real roots of these equations, near
20+
/// <c>10^23</c> or more, were dropped and the answer was <c>{ }</c>. Found by solving generated
21+
/// equations with <c>x</c> written as <c>10^-30 x</c>; no issue was filed.
22+
/// </summary>
23+
[Trait("Area", "Algebra")]
24+
public sealed class ARadicalRootIsNotDroppedForItsRoundingTest
25+
{
26+
[Theory]
27+
[InlineData("(1 - 2 * {0}) + {0} * abs(-2 - 3 * {0})", 1)]
28+
[InlineData("-2 * {0} + 3 * {0}^2 - 2 * abs(-3 + 2 * {0})", 2)]
29+
public void EveryRootIsFoundAtScale(string shape, int count)
30+
{
31+
foreach (var digits in new[] { 0, 23, 24 })
32+
{
33+
var scaled = string.Format(shape, $"(10^(-{digits}) * x)");
34+
var answer = Assert.IsType<FiniteSet>($"{scaled} = 0".ToEntity().Solve("x"));
35+
Assert.Equal(count, answer.Count);
36+
var unscaled = string.Format(shape, "x").ToEntity();
37+
foreach (var root in answer)
38+
{
39+
var residual = Assert.IsAssignableFrom<Number.Complex>(unscaled.Substitute("x", root * MathS.Pow(10, -digits)).EvalNumerical());
40+
Assert.True(residual.Abs() < 1e-30, $"{root} leaves {residual} at 10^{digits}");
41+
}
42+
}
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)