Skip to content

Commit 90db9db

Browse files
Leave a polynomial unsolved where a candidate root fails it (#2515)
An equation that is a polynomial as written has no root a rewrite could have added, so a candidate that fails it is the solver's error, and the candidates that pass are not known to be all of the roots. Only where every candidate failed was it left unsolved; where some passed they were the answer. A degree-twelve polynomial with roots near 1e-12 had eleven numerical candidates fail and was answered with the twelfth, 10^-12, alone; the system solver for 2 + 3x + (-3 - x) x sgn(1 - x) = 0 with x written as 10^12 x took that as every root of the real part, and the equation was answered { }, though -sqrt(2) 10^-12 is a root. And the check read the polynomial through a condition it carried, which it could not: the degree-ten one it reaches had come back from Simplify with one. APolynomialHasARootTest asserted that x^2 - 4 with candidates { 2, 5 } answers { 2 }, which leaves -2 out; it now asserts that it is unsolved, and that candidates which all hold are kept. Cross-checks of the unscaled equations: unchanged. With x written as 10^12 x, abs/sgn equations that differ 25 -> 23, the answer { } gone and 11 -> 9 answers missing a root; the rest are answers left unsolved. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1b493a4 commit 90db9db

5 files changed

Lines changed: 83 additions & 13 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ other names refused by name are ([#2182](https://github.com/asc-community/Angour
153153
| `"beta(x)".ToEntity()` | `beta * x` | throws `FunctionArgumentCountException` |
154154
| `"norm (x)".ToEntity()` | `norm * x` | `norm * x`, unchanged |
155155

156+
### A polynomial with a candidate root that fails it is left unsolved
157+
158+
**Silent: answers with wrong or missing roots become unsolved.** An equation that is a polynomial as written has no
159+
root that a rewrite could have added, so a candidate that fails it is the solver's error, and the candidates that pass
160+
are not known to be all of the roots. Only where every candidate failed was the equation left unsolved; where some
161+
passed, they were the answer. The check also read the polynomial through a condition it carries, which it could not
162+
before. A polynomial of degree twelve with roots near `1e-12`, which an equation in `sgn` with `x` written as
163+
`10^12 x` reaches, is now unsolved.
164+
165+
| Input | Was (2.8.0) | Now |
166+
|---|---|---|
167+
| The degree-twelve polynomial the real part of that `sgn` equation solves to | eleven decimal roots, ten of them not roots | unsolved |
168+
| `"2 + 3 * (10^12 * x) + (-3 - 10^12 * x) * (10^12 * x) * sgn(1 - 10^12 * x) = 0".ToEntity().Solve("x")` | unsolved (`{ }` on master since the residual is judged against its terms) | unsolved |
169+
156170
### A family of roots whose members carry a condition is listed inside a bounded interval
157171

158172
**Silent.** Since 2.8.0 a family of roots met with a bounded interval is listed, but not where its members carry a

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
153153
[Tests/UnitTests/Algebra/SolveTest/AMultipleOfASumOfFunctionsTest.cs]
154154
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
155155

156+
[Tests/UnitTests/Algebra/SolveTest/APolynomialWithTinyRootsIsNotAnsweredInPartTest.cs]
157+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
158+
156159
[Tests/UnitTests/Algebra/SolveTest/InverseTrigonometricPairEquationTest.cs]
157160
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
158161

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,18 @@ internal static Set WithoutSpuriousRoots(Set roots, Entity equation, Variable x)
6969
}
7070
if (survivors is null)
7171
return roots;
72-
var kept = survivors.ToSet();
73-
// A polynomial of degree one or more has a root over the complex numbers, so where every
74-
// candidate for one fails, what failed is the solver, and the empty set left would claim
75-
// there is no root: (x + 1)^3 = 2 was { } while Cardano's C was 0 for a shifted cube, and
76-
// 31x^4 - 62x^3 + 33x^2 - 2x - 1 = 0 while a biquadratic quartic was shifted by -b a / 4.
77-
// Left unsolved instead, which says only that the roots were not found.
78-
if (kept.Count == 0 && IsAPolynomialWithARoot(equation, x))
72+
// An equation that is a polynomial as written has no root a rewrite could have added, so a
73+
// candidate that fails it is the solver's number, not a spurious root, and the roots that
74+
// pass are not known to be all of them. Where every candidate fails, the empty set left
75+
// would claim there is no root, which a polynomial of degree one or more always has over
76+
// the complex numbers: (x + 1)^3 = 2 was { } while Cardano's C was 0 for a shifted cube,
77+
// and 31x^4 - 62x^3 + 33x^2 - 2x - 1 = 0 while a biquadratic quartic was shifted by
78+
// -b a / 4. And where some pass, they are an answer with roots missing: a degree-twelve
79+
// polynomial with roots near 1e-12 had eleven numerical candidates fail and was answered
80+
// with the twelfth alone. Left unsolved, which says only that the roots were not found.
81+
if (IsAPolynomialWithARoot(equation, x))
7982
return Unsolved(equation, x);
80-
return kept;
83+
return survivors.ToSet();
8184
}
8285

8386
/// <summary><paramref name="equation"/> as a condition on <paramref name="x"/>: the roots were not found.</summary>
@@ -90,8 +93,9 @@ private static Set Unsolved(Entity equation, Variable x)
9093
/// polynomial has a root.
9194
/// </summary>
9295
private static bool IsAPolynomialWithARoot(Entity equation, Variable x)
96+
// Read through a condition the equation carries, as a polynomial's does once simplified.
9397
=> MathS.Settings.Codomain.Value != Core.Domain.Real
94-
&& TreeAnalyzer.TryGetPolynomial(equation, x, out var monomials)
98+
&& TreeAnalyzer.TryGetPolynomial(Functions.PartialFractions.Bare(equation), x, out var monomials)
9599
&& monomials.Keys.All(power => power.Sign >= 0)
96100
&& monomials.Where(monomial => monomial.Key.Sign > 0)
97101
.Any(monomial => monomial.Value.Evaled is Number.Complex { IsZero: false })

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,23 @@ public void APolynomialWhoseCandidatesAllFailIsLeftUnsolved(string polynomial)
3232
=> Assert.IsType<ConditionalSet>(
3333
StatementSolver.WithoutSpuriousRoots(new FiniteSet((Entity)5, (Entity)7), polynomial.ToEntity(), "x"));
3434

35-
/// <summary>The roots that hold are kept, as before.</summary>
35+
/// <summary>
36+
/// The roots that hold are not an answer either. A polynomial as written has no root a
37+
/// rewrite could have added, so a candidate that fails it is the solver's number, and the
38+
/// ones that pass are not known to be all: <c>{ 2 }</c> for <c>x^2 - 4</c> leaves out -2. This
39+
/// asserted <c>{ 2 }</c> until a degree-twelve polynomial with roots near 1e-12 was answered
40+
/// with one root of twelve that way.
41+
/// </summary>
42+
[Fact]
43+
public void APolynomialWithSomeCandidatesFailingIsLeftUnsolved()
44+
=> Assert.IsType<ConditionalSet>(
45+
StatementSolver.WithoutSpuriousRoots(new FiniteSet((Entity)2, (Entity)5), "x^2 - 4".ToEntity(), "x"));
46+
47+
/// <summary>The candidates that all hold are the answer, untouched.</summary>
3648
[Fact]
37-
public void TheRootsThatHoldAreKept()
38-
=> Assert.Equal("{ 2 }".ToEntity(),
39-
StatementSolver.WithoutSpuriousRoots(new FiniteSet((Entity)2, (Entity)5), "x^2 - 4".ToEntity(), "x").InnerSimplified);
49+
public void CandidatesThatAllHoldAreKept()
50+
=> Assert.Equal("{ 2, -2 }".ToEntity(),
51+
StatementSolver.WithoutSpuriousRoots(new FiniteSet((Entity)2, (Entity)(-2)), "x^2 - 4".ToEntity(), "x").InnerSimplified);
4052

4153
/// <summary>
4254
/// An equation that is not a polynomial can have no root, and its empty set is an answer:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.Set;
11+
12+
namespace AngouriMath.Tests.Algebra
13+
{
14+
/// <summary>
15+
/// <c>2 + 3x + (-3 - x) x sgn(1 - x) = 0</c> with <c>x</c> written as <c>10^12 x</c> has the root
16+
/// <c>-sqrt(2) 10^-12</c>, and was answered <c>{ }</c>. Its parts solve to a degree-twelve
17+
/// polynomial with roots near 1e-12, whose numerical candidates all but one failed the check;
18+
/// the one exact root, <c>10^-12</c>, was answered as all of them, and the system solver above it
19+
/// took that root, a zero of the signum, and left nothing. A candidate that fails a polynomial as
20+
/// written is the solver's error, and the answer is left unsolved. Found by solving generated
21+
/// equations with <c>x</c> written as <c>10^12 x</c>; no issue was filed.
22+
/// </summary>
23+
[Trait("Area", "Algebra")]
24+
public sealed class APolynomialWithTinyRootsIsNotAnsweredInPartTest
25+
{
26+
[Fact]
27+
public void TheScaledSignumEquationIsNotEmpty()
28+
{
29+
var answer = "2 + 3 * (10^12 * x) + (-3 - 10^12 * x) * (10^12 * x) * sgn(1 - 10^12 * x) = 0".ToEntity().Solve("x");
30+
Assert.False(answer is FiniteSet { Count: 0 }, $"answered {answer}, but -sqrt(2) 10^-12 is a root");
31+
}
32+
33+
[Fact]
34+
public void TheUnscaledEquationIsAsBefore()
35+
=> Assert.IsType<ConditionalSet>("2 + 3x + (-3 - x) * x * sgn(1 - x) = 0".ToEntity().Solve("x"));
36+
}
37+
}

0 commit comments

Comments
 (0)