Skip to content

Commit a1fb7ae

Browse files
Over the complex numbers, an equation in and out of a modulus is solved in the parts of x (#2309)
* Over the complex numbers, an equation in and out of a modulus is solved in the parts of x #2307 left an equation with x inside abs, sgn, conj, Re, Im or arg and outside it too unsolved over the complex numbers, since Newton's method assumes a holomorphic function and its near-copies of a root came back as roots. Leaving it unsolved is not solving it. With x = a + b i and each |u| a real t >= 0 with t^2 = (Re u)^2 + (Im u)^2, the real and imaginary parts of the equation and one equation per modulus are a polynomial system in as many unknowns, which the Groebner solver answers exactly and completely or not at all. The roots are its solutions with a, b and every t real and no t negative, each put back into the equation as written, since clearing the denominators can add a pole. conj, Re and Im split directly. sgn(u) is u/|u| where u is not zero, and the case where it is zero is solved on its own. x^2/|1 - x^2| = x is { 0, (1 + sqrt(5))/2, (sqrt(5) - 1)/2 }, x |x| = 4 is { 2 }, x + sgn(x) = 3 is { 2 } again, and x^2 + 1 = |x| is +-i (sqrt(5) - 1)/2, which neither the search nor a split by the sign found. Left unsolved: infinitely many solutions (|x| = Re x), roots with no exact form (x^5 = |x| + 1), arg, and a system above 32 solutions by Bezout's bound, past which x^7 = |x| + 1 spent over 20 s declining. The route runs once, on the equation as asked and ahead of the spelling loop, whose spellings would each be the same system: asked of every one, x^5 = |x^3 + 1| + 1 ran it dozens of times. * Walk the tree by hand for the test that picks out these equations It is asked of every equation the solver is given, ahead of the spelling loop. Enumerating Nodes allocates an iterator at each level, and that was 4.5 MB of the kernel benchmark's SolveHard, 45% of it, which has no modulus in it. The walk allocates nothing: SolveHard allocates 187,558,968 bytes per solve on master and on the branch. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent eb19a31 commit a1fb7ae

5 files changed

Lines changed: 421 additions & 27 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,20 +1049,26 @@ unchanged ([#2256](https://github.com/asc-community/AngouriMath/issues/2256)).
10491049
| `"max(x, x)".ToEntity().Simplify()` | `x` | `x provided x in RR` |
10501050
| `"max(x, 2)".ToEntity().DomainCondition` | `True` | `x in RR` |
10511051

1052-
### Over the complex numbers, an equation in and out of a modulus is left unsolved
1053-
1054-
**Silent: an equation with `x` inside `abs`, `sgn`, `conj`, `Re`, `Im` or `arg` and outside it too is left unsolved
1055-
in the complex codomain, the default, where a numerical search answered it.** Newton's method assumes a holomorphic
1056-
function, and over the complex numbers `|u| = ±u` only where `u` is real, which a root need not make it, so neither
1057-
the search nor a split by the sign finds every root. The search's near-copies of a root came back as roots. Where it
1058-
happened to be right, as for `x * abs(x) = 4`, the answer is given up with the rest; over the reals each is still
1059-
solved by cases, exactly ([#2139](https://github.com/asc-community/AngouriMath/issues/2139)).
1052+
### Over the complex numbers, an equation in and out of a modulus is solved in the parts of `x`
1053+
1054+
**Silent: an equation with `x` inside `abs`, `sgn`, `conj`, `Re` or `Im` and outside it too is solved exactly in the
1055+
complex codomain, the default, where a numerical search answered it in decimals with near-copies of a root that solve
1056+
nothing.** Newton's method assumes a holomorphic function, and over the complex numbers `|u| = ±u` only where `u` is
1057+
real, which a root need not make it, so a split by the sign misses roots too: `x^2 + 1 = abs(x)` is solved by
1058+
`±0.618… i`. With `x = a + b i` and each modulus a real `t ≥ 0` with `t^2 = (Re u)^2 + (Im u)^2`, the equation is a
1059+
system of polynomial equations in `a`, `b` and the `t`s, solved by a Gröbner basis, and its real solutions are the
1060+
roots; `sgn(u)` is `u / |u|` where `u` is not zero and `0` where it is, and both cases are solved. Where that system
1061+
has more than finitely many solutions, roots that are not found exactly, or more than 32 by Bézout's bound, the
1062+
equation is left unsolved, as it is with `arg` in it
1063+
([#2139](https://github.com/asc-community/AngouriMath/issues/2139)).
10601064

10611065
| Input | Was (2.6.0) | Now |
10621066
|---|---|---|
1063-
| `"x^2/abs(1-x^2) = x".ToEntity().Solve("x")` | `{ 0, 0.618…, 1.618…, 1.618… + 1.7E-9i, 1.618… + 9.9E-8i }` | `{ x : x ^ 2 / abs(1 - x ^ 2) = x }` |
1064-
| `"abs(x^2 - 4) = 3x".ToEntity().Solve("x")` | `{ 1, 4, 4.0000000000000062… + 1.6E-7i }` | `{ x : abs(x ^ 2 - 4) = 3 * x }` |
1065-
| `"x * abs(x) = 4".ToEntity().Solve("x")` | `{ 2 }` | `{ x : x * abs(x) = 4 }` |
1067+
| `"x^2/abs(1-x^2) = x".ToEntity().Solve("x")` | `{ 0, 0.618…, 1.618…, 1.618… + 1.7E-9i, 1.618… + 9.9E-8i }` | `{ 0, (1 + sqrt(5)) / 2, (sqrt(5) - 1) / 2 }` |
1068+
| `"abs(x^2 - 4) = 3x".ToEntity().Solve("x")` | `{ 1, 4, 4.0000000000000062… + 1.6E-7i }` | `{ 1, 4 }` |
1069+
| `"1/abs(x) = x^2".ToEntity().Solve("x")` | `{ -1, -0.999999… - 2.1E-7i, -0.999999… + 2.1E-7i, …, 1 }`, eight entries | `{ 1, -1 }` |
1070+
| `"x^2 + 1 = abs(x)".ToEntity().Solve("x")` | `{ x : x ^ 2 + 1 = abs(x) }` | `{ 1/2 * i * (sqrt(5) - 1), 1/2 * i * (1 - sqrt(5)) }` |
1071+
| `"x^5 = abs(x) + 1".ToEntity().Solve("x")` | `{ -0.944368… - 0.686124…i, …, 1.167303… }`, eight entries for five roots | `{ x : x ^ 5 = abs(x) + 1 }` |
10661072

10671073
### `conjugate`, `conj` and `arg` are functions
10681074

‎Sources/AngouriMath/Functions/Algebra/Polynomials/MultivariatePolynomial.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ internal int DegreeIn(int variable)
147147
return degree;
148148
}
149149

150+
/// <summary>The highest total degree of a term; zero for a constant.</summary>
151+
internal int Degree
152+
{
153+
get
154+
{
155+
var degree = 0;
156+
foreach (var monomial in terms.Keys)
157+
degree = System.Math.Max(degree, TotalDegree(monomial));
158+
return degree;
159+
}
160+
}
161+
150162
/// <summary>The greatest monomial in lexicographic order; zero if there is none.</summary>
151163
private ulong LeadingMonomial()
152164
{

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ internal static Set Solve(Entity expr, Variable x, bool compensateSolving = fals
130130
if (MathS.Settings.Codomain.Value == Core.Domain.Real && ModulusSolver.SolveOverTheReals(expr, x) is { } overTheReals)
131131
return overTheReals;
132132

133+
// Over the complex numbers, one with x inside a modulus, a conjugate, a real or an
134+
// imaginary part and outside it as well is solved in the real and imaginary parts of
135+
// x, exactly: x |x| = 4 is { 2 }. Asked here, of the equation as it was asked, rather
136+
// than of each spelling below, every one of which would be the same system to solve.
137+
// https://github.com/asc-community/AngouriMath/issues/2139
138+
if (!compensateSolving && MathS.Settings.Codomain.Value != Core.Domain.Real
139+
&& ModulusSolver.IsInsideAndOutsideAFunctionThatIsNotHolomorphic(expr, x)
140+
&& ModulusSolver.SolveOverTheComplexNumbers(expr, x) is { } overTheComplexNumbers)
141+
return overTheComplexNumbers;
142+
133143
// Whether a candidate root really is one. The loose tolerance that guesses the
134144
// rational must not also be what decides this: at 1e-7, x^41 + 6x + 1 accepted
135145
// -1/6, whose residual is -1.25e-32 -- small, but the difference between an
@@ -395,8 +405,8 @@ bool ProductIsDefinedAt(Entity root)
395405
// Over the complex numbers, x inside a modulus or another function that is not
396406
// holomorphic and outside it as well is not the search's either: Newton's method
397407
// assumes a holomorphic function, and its near-copies of a root came back as roots.
398-
// Left unsolved; over the reals it is solved by cases, above.
399-
// https://github.com/asc-community/AngouriMath/issues/2139
408+
// Left unsolved where it is not solved in the parts of x, above; over the reals it is
409+
// solved by cases. https://github.com/asc-community/AngouriMath/issues/2139
400410
if (MathS.Settings.Codomain.Value != Core.Domain.Real && ModulusSolver.IsInsideAndOutsideAFunctionThatIsNotHolomorphic(expr, x))
401411
return Unsolved(expr, x);
402412

0 commit comments

Comments
 (0)