Skip to content

Commit b9171c0

Browse files
Over the complex numbers, an equation in and out of a modulus is left unsolved (#2307)
x^2/abs(1 - x^2) = x was answered by a numerical search in the complex codomain, the default, with two non-real entries beside 1.618 that solve nothing: Newton's method assumes a holomorphic function, and its near-copies of a root came back as roots. abs(x^2 - 4) = 3x had 4.0000000000000062 + 1.6e-7 i beside { 1, 4 }. Over the complex numbers |u| = +-u only where u is real, which a root need not make it (x^2 + 1 = |x| has roots at +-0.618 i), so a split by the sign cannot say it found every root either. An equation with x inside abs, sgn, conj, Re, Im or arg and outside it as well is now left unsolved in the complex codomain, at the point where only the search is left, as |x - 2| = |x - 3| already was (#1573). That gives up the cases the search happened to answer right, x * abs(x) = 4 among them; over the reals each is solved by cases, exactly, since #2178. ModulusEquationTest takes six such equations left unsolved, four of which master answered, and two that are still answered. The suite, the trio, F#, AOT and the eight harnesses pass. Fixes #2139. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 5d973db commit b9171c0

4 files changed

Lines changed: 70 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,21 @@ unchanged ([#2256](https://github.com/asc-community/AngouriMath/issues/2256)).
10341034
| `"max(x, x)".ToEntity().Simplify()` | `x` | `x provided x in RR` |
10351035
| `"max(x, 2)".ToEntity().DomainCondition` | `True` | `x in RR` |
10361036

1037+
### Over the complex numbers, an equation in and out of a modulus is left unsolved
1038+
1039+
**Silent: an equation with `x` inside `abs`, `sgn`, `conj`, `Re`, `Im` or `arg` and outside it too is left unsolved
1040+
in the complex codomain, the default, where a numerical search answered it.** Newton's method assumes a holomorphic
1041+
function, and over the complex numbers `|u| = ±u` only where `u` is real, which a root need not make it, so neither
1042+
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
1043+
happened to be right, as for `x * abs(x) = 4`, the answer is given up with the rest; over the reals each is still
1044+
solved by cases, exactly ([#2139](https://github.com/asc-community/AngouriMath/issues/2139)).
1045+
1046+
| Input | Was (2.6.0) | Now |
1047+
|---|---|---|
1048+
| `"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 }` |
1049+
| `"abs(x^2 - 4) = 3x".ToEntity().Solve("x")` | `{ 1, 4, 4.0000000000000062… + 1.6E-7i }` | `{ x : abs(x ^ 2 - 4) = 3 * x }` |
1050+
| `"x * abs(x) = 4".ToEntity().Solve("x")` | `{ 2 }` | `{ x : x * abs(x) = 4 }` |
1051+
10371052
### `conjugate`, `conj` and `arg` are functions
10381053

10391054
**Not silent: these names followed by a bracket are now the complex conjugate and the principal argument, where they

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,14 @@ bool ProductIsDefinedAt(Entity root)
392392
if (ModulusSolver.IsRealForEveryComplex(expr, x))
393393
return Unsolved(expr, x);
394394

395+
// Over the complex numbers, x inside a modulus or another function that is not
396+
// holomorphic and outside it as well is not the search's either: Newton's method
397+
// 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
400+
if (MathS.Settings.Codomain.Value != Core.Domain.Real && ModulusSolver.IsInsideAndOutsideAFunctionThatIsNotHolomorphic(expr, x))
401+
return Unsolved(expr, x);
402+
395403
// A numerical search that comes back with nothing has not shown there is
396404
// nothing to find: Newton's method is started from finitely many points inside
397405
// a bounded region, so an empty result is a fact about the search rather than

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ internal static class ModulusSolver
3737
internal static bool IsRealForEveryComplex(Entity expr, Variable x)
3838
=> expr.ContainsNode(x) && RealWhereverItIs(expr, x);
3939

40+
/// <summary>
41+
/// Whether <paramref name="x"/> is both inside a function that is not holomorphic -- a
42+
/// modulus, a signum, a conjugate, a real or imaginary part, an argument -- and outside every
43+
/// such function somewhere in <paramref name="expr"/>.
44+
/// </summary>
45+
/// <remarks>
46+
/// Newton's method assumes a holomorphic function, and over the complex numbers
47+
/// <c>|u| = +-u</c> only where <c>u</c> is real, which a root need not make it:
48+
/// <c>x^2 + 1 = |x|</c> has roots at <c>+-0.618 i</c>, where <c>|x|</c> is <c>0.618</c>. So
49+
/// neither the search nor a split by the sign finds every root, and the search's near-copies
50+
/// of a root came back as roots: <c>x^2/|1 - x^2| = x</c> had <c>1.618 + 1.7e-9 i</c> beside
51+
/// <c>1.618</c>. https://github.com/asc-community/AngouriMath/issues/2139
52+
/// </remarks>
53+
internal static bool IsInsideAndOutsideAFunctionThatIsNotHolomorphic(Entity expr, Variable x)
54+
=> expr.Nodes.Any(node => IsNotHolomorphic(node) && node.ContainsNode(x)) && IsOutsideThem(expr, x);
55+
56+
private static bool IsNotHolomorphic(Entity node)
57+
=> node is Absf or Signumf or Conjugatef or Ref or Imf or Argf;
58+
59+
private static bool IsOutsideThem(Entity expr, Variable x)
60+
=> expr == x || !IsNotHolomorphic(expr) && expr.DirectChildren.Any(child => IsOutsideThem(child, x));
61+
4062
private static bool RealWhereverItIs(Entity expr, Variable x)
4163
=> expr switch
4264
{

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,31 @@ public sealed class ModulusEquationTest
3333
public void OverTheComplexNumbersACurveIsNotAListOfPoints(string equation)
3434
=> Assert.IsType<ConditionalSet>(equation.ToEntity().Solve("x"));
3535

36+
/// <summary>
37+
/// <c>x</c> inside a function that is not holomorphic and outside it too: Newton's method
38+
/// assumes a holomorphic function, and over the complex numbers <c>|u| = +-u</c> only where
39+
/// <c>u</c> is real, which a root need not make it, so neither the search nor a split by the
40+
/// sign finds every root. Left unsolved. The search's near-copies of a root came back as
41+
/// roots: <c>x^2/|1 - x^2| = x</c> had <c>1.618 + 1.7e-9 i</c> beside <c>1.618</c>.
42+
/// <a href="https://github.com/asc-community/AngouriMath/issues/2139">#2139</a>
43+
/// </summary>
44+
[Theory]
45+
[InlineData("x^2/abs(1 - x^2) = x")]
46+
[InlineData("abs(x^2 - 4) = 3 x")]
47+
[InlineData("x^2 + 1 = abs(x)")]
48+
[InlineData("x * abs(x) = 4")]
49+
[InlineData("x + sgn(x) = 3")]
50+
[InlineData("x + conj(x) = 2 + i")]
51+
public void OverTheComplexNumbersAnEquationInAndOutOfAModulusIsLeftUnsolved(string equation)
52+
=> Assert.IsType<ConditionalSet>(equation.ToEntity().Solve("x"));
53+
54+
/// <summary>The variable only inside the modulus, or not in one at all, is answered as before.</summary>
55+
[Theory]
56+
[InlineData("abs(x) = 2")]
57+
[InlineData("x^2 = 4")]
58+
public void OverTheComplexNumbersTheOthersAreStillAnswered(string equation)
59+
=> Assert.IsNotType<ConditionalSet>(equation.ToEntity().Solve("x"));
60+
3661
/// <summary>
3762
/// Sullivan and Mackey's Prob 1.5.16, and moduli between which a whole interval solves.
3863
/// </summary>

0 commit comments

Comments
 (0)