diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md
index 7f1a98f7d..1487600ca 100644
--- a/BREAKING-CHANGES.md
+++ b/BREAKING-CHANGES.md
@@ -591,6 +591,29 @@ decided, such as `sqrt(a)`, is kept intersected with `RR`. Measured on master (2
| `"x^3 - 2 <= 0".Solve("x")` | `{ (-1/2 + i * 1/2 * sqrt(3)) * 2 ^ (1/3), (-1/2 + i * -1/2 * sqrt(3)) * 2 ^ (1/3) } \/ (-oo; 2 ^ (1/3)]` | `(-oo; 2 ^ (1/3)]` |
| `"x^2 <= a".Solve("x")` | `{ sqrt(a), -sqrt(a) } \/ { x : -(-4) * a >= 0 and x in (-1/2 * abs(2 * sqrt(a)); abs(2 * sqrt(a)) / 2) }` | `{ x : -(-4) * a >= 0 and x in (-1/2 * abs(2 * sqrt(a)); abs(2 * sqrt(a)) / 2) } \/ { sqrt(a), -sqrt(a) } /\ RR` |
+### A value tan, cotan, tanh, sec, cosec or a power never takes has no roots, and a far-out near-root is not one
+
+**Silent: numbers that were not roots are gone.** `tan(w)` is `i` only where `e^(2 i w) = 0`, which is nowhere, and
+likewise `tan` and `cotan` never take `-i`, `tanh` and `coth` never take `-1`, `sec` and `cosec` never take 0, and a
+power of a number that is not 0 never takes 0. An equation through one of these at such a value has no roots whatever
+is inside; it went on past the analytical answer to Newton's method, which answered points where the equation only
+tends to hold, `x - i cos(arcsin(x))` being `1 / (2x)` far out. Such an equation is now `{ }`, and Newton's method
+keeps a point only where the Newton step from it is shorter than a thousandth of its size (at least 1). Measured on
+master (a3f3b9ed1) and on this branch; every one of 90 changed rows in a sweep of 1408 is such an equation
+([#2763](https://github.com/asc-community/AngouriMath/issues/2763)).
+
+| `.Solve("x")` | Was (master) | Now |
+|---|---|---|
+| `tan(arcsin(x)) = i` | `{ -24258808.638504 + 87745223.784967i, 24258808.638504 + 87745223.784967i }` | `{ }` |
+| `cotan(arccos(x)) = i` | three points of size about 10^8 | `{ }` |
+| `tan(x^2 + 1) = i` | forty points from `-8.04 - 8.00i` to `10.05 + 8.02i` | `{ }` |
+| `tan(arcsec(x)) = i` | dozens of points `5.9E-10i` to `5.1E-9i` | `{ }` |
+| `tan(sinh(x)) = i` | `union({ ln(-204.20823846791 + 40.00362744916i) + 2 * pi * i * n, … }, n in ZZ)` | `{ }` |
+| `tanh(cosh(x)) = -1` | `{ -8 - 10i, -8 - 4i, …, 10 + 10i }`, twenty points of the search's grid | `{ }` |
+| `tan(ln(x)) = i` | `{ x : tan(ln(x)) = i }` | `{ }` |
+| `e^(artanh(x)) = 0` | `{ -1 }`, where `artanh` has no value | `{ }` |
+| `x - i cos(arcsin(x)) = 0` | `{ -24258808.638504 + 87745223.784967i, 24258808.638504 + 87745223.784967i }` | `{ x : x - i * cos(arcsin(x)) = 0 }` |
+
### An odd root of a negative number is real with downcasting off as well
**Silent, with `MathS.Settings.DowncastingEnabled` off only.** An odd root of a negative number is the real one:
diff --git a/Sources/.editorconfig b/Sources/.editorconfig
index 9c6d89c21..6f9a71f87 100644
--- a/Sources/.editorconfig
+++ b/Sources/.editorconfig
@@ -1109,9 +1109,15 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
[Tests/UnitTests/Common/StatementAsANumberCompilationTest.cs]
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
+[AngouriMath/Functions/Continuous/Solvers/EquationSolver/OmittedValueSolver.cs]
+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
+
[AngouriMath/Functions/Continuous/Solvers/EquationSolver/LambertWSolver.cs]
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
+[Tests/UnitTests/Algebra/SolveTest/AValueAFunctionNeverTakesHasNoRootsTest.cs]
+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
+
[Tests/UnitTests/Algebra/SolveTest/LambertWSolveTest.cs]
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
diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/AnalyticalEquationSolver.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/AnalyticalEquationSolver.cs
index 5d4fdb265..7f60b2f5c 100644
--- a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/AnalyticalEquationSolver.cs
+++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/AnalyticalEquationSolver.cs
@@ -165,6 +165,12 @@ internal static Set Solve(Entity expr, Variable x, bool compensateSolving = fals
return new ConditionalSet(x, residual.Equalizes(0));
}
+ // tan(arcsin(x)) = i has no root, since tan(w) = i for no w; the spellings tried for it
+ // went on to Newton's method and answered points far out where it nearly holds.
+ // https://github.com/asc-community/AngouriMath/issues/2763
+ if (!compensateSolving && OmittedValueSolver.Solve(expr, x) is { } neverTaken)
+ return neverTaken;
+
// Over the reals an equation in moduli of linear functions is solved by cases, between
// the kinks: |x - 2| = |x - 3| is x = 5/2, Sullivan and Mackey's Prob 1.5.16.
// https://github.com/asc-community/AngouriMath/issues/1573
diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/OmittedValueSolver.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/OmittedValueSolver.cs
new file mode 100644
index 000000000..b33670cf8
--- /dev/null
+++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/OmittedValueSolver.cs
@@ -0,0 +1,123 @@
+//
+// Copyright (c) 2019-2026 Angouri.
+// AngouriMath is licensed under MIT.
+// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
+// Website: https://am.angouri.org.
+//
+
+using System.Collections.Generic;
+using System.Linq;
+using static AngouriMath.Entity;
+using static AngouriMath.Entity.Number;
+
+namespace AngouriMath.Functions.Algebra.AnalyticalSolving
+{
+ ///
+ /// An equation in x only through one function F(u), every root of which, as an
+ /// equation in F(u), is a value F never takes: it has no roots.
+ /// tan(arcsin(x)) = i is { }. https://github.com/asc-community/AngouriMath/issues/2763
+ ///
+ ///
+ ///
+ /// The values each function omits at every finite argument w:
+ /// tan(w) = i is e^(2 i w) = 0 and tan(w) = -i is e^(-2 i w) = 0, and
+ /// cotan the same, so both omit i and -i; sec and cosec, one over
+ /// a finite number, omit 0; and b^w = e^(w ln(b)) omits 0 for a number b that is
+ /// not 0.
+ ///
+ ///
+ /// The equation tan(t) = i is already answered { }, and the replacement of the inner
+ /// subtree finds that. But the spellings tried after it, x / cos(arcsin(x)) = i among them,
+ /// went on to Newton's method, which answered points of size 10^8 where
+ /// x - i cos(arcsin(x)) is 1 / (2x), under its tolerance but not 0. Answered here,
+ /// before any spelling, the equation is never searched.
+ ///
+ ///
+ internal static class OmittedValueSolver
+ {
+ ///
+ /// where = 0 is such an equation,
+ /// otherwise .
+ ///
+ internal static Set? Solve(Entity expr, Variable x)
+ {
+ // Only numbers besides x, so that only numbers are left besides t: a tan(x^2) = i a holds
+ // everywhere at a = 0. Asked first, as it is the cheapest: most equations with a parameter
+ // end here, before any node is looked at.
+ foreach (var variable in expr.Vars)
+ if (variable != x)
+ return null;
+ int? occurrences = null;
+ foreach (var node in expr.Nodes)
+ {
+ if (OmittedValues(node, x) is not { } omitted
+ || expr.CountNode(node) * node.CountNode(x) != (occurrences ??= expr.CountNode(x)))
+ continue;
+ var t = Variable.CreateTemp(expr.Vars);
+ var inT = expr.Substitute(node, t);
+ // A polynomial all of whose roots are omitted values vanishes at one of them; most do not,
+ // and are let go before their roots are looked for.
+ if (!IsPolynomialIn(inT, t)
+ || !omitted.Any(value => inT.Substitute(t, value).Evaled is Complex { IsZero: true })
+ || PolynomialSolver.SolveAsPolynomial(inT, t, out var isIdentity) is not { } roots
+ || isIdentity)
+ return null;
+ var all = roots.Select(root => root.InnerSimplified).ToList();
+ return all.Count > 0 && all.All(root => omitted.Any(value => IsExactly(root, value)))
+ ? Set.Empty : null;
+ }
+ return null;
+ }
+
+ ///
+ /// Whether is written as a polynomial in : sums,
+ /// differences and products of it, its whole powers, and quotients by what does not contain it.
+ /// A quotient by t could have its roots cancelled or added, and a polynomial's roots are
+ /// all of its roots. tanh(u) = -1 is (t - 1) / (t + 1) = -1 in t = e^(2u), and is
+ /// left to the solvers after this.
+ ///
+ private static bool IsPolynomialIn(Entity expr, Variable t)
+ => !expr.ContainsNode(t) || expr switch
+ {
+ Variable when expr == t => true,
+ Sumf(var a, var b) => IsPolynomialIn(a, t) && IsPolynomialIn(b, t),
+ Minusf(var a, var b) => IsPolynomialIn(a, t) && IsPolynomialIn(b, t),
+ Mulf(var a, var b) => IsPolynomialIn(a, t) && IsPolynomialIn(b, t),
+ Divf(var a, var b) => !b.ContainsNode(t) && IsPolynomialIn(a, t),
+ Powf(var a, Integer { EInteger: var n }) => n.Sign > 0 && IsPolynomialIn(a, t),
+ _ => false,
+ };
+
+ ///
+ /// The values 's function never takes, where the node has
+ /// in its argument; otherwise .
+ ///
+ private static Complex[]? OmittedValues(Entity node, Variable x)
+ => node switch
+ {
+ Tanf(var argument) when argument.ContainsNode(x) => new[] { Complex.ImaginaryOne, Complex.MinusImaginaryOne },
+ Cotanf(var argument) when argument.ContainsNode(x) => new[] { Complex.ImaginaryOne, Complex.MinusImaginaryOne },
+ Secantf(var argument) when argument.ContainsNode(x) => new Complex[] { Integer.Zero },
+ Cosecantf(var argument) when argument.ContainsNode(x) => new Complex[] { Integer.Zero },
+ Powf(var @base, var power) when power.ContainsNode(x) && IsNonZeroConstant(@base) => new Complex[] { Integer.Zero },
+ _ => null,
+ };
+
+ ///
+ /// A base known not to be 0 without evaluating it: an exact number that is not 0, or
+ /// e or pi.
+ ///
+ private static bool IsNonZeroConstant(Entity @base)
+ => @base == MathS.e || @base == MathS.pi
+ || @base is Complex number && IsExact(number) && !number.IsZero;
+
+ private static bool IsExact(Complex number)
+ => number.RealPart is Rational && number.ImaginaryPart is Rational;
+
+ /// Whether is the number , compared exactly.
+ private static bool IsExactly(Entity root, Complex value)
+ => root is Complex number && IsExact(number)
+ && ((Rational)number.RealPart).ERational.CompareTo(((Rational)value.RealPart).ERational) == 0
+ && ((Rational)number.ImaginaryPart).ERational.CompareTo(((Rational)value.ImaginaryPart).ERational) == 0;
+ }
+}
diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/NumericalSolving/NewtonSolver.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/NumericalSolving/NewtonSolver.cs
index b4c81f5eb..2c0f792f2 100644
--- a/Sources/AngouriMath/Functions/Continuous/Solvers/NumericalSolving/NewtonSolver.cs
+++ b/Sources/AngouriMath/Functions/Continuous/Solvers/NumericalSolving/NewtonSolver.cs
@@ -237,7 +237,11 @@ void IterateFrom(NumericsComplex start)
// https://github.com/asc-community/AngouriMath/issues/1420
if (forTheSolver && !AreIsolated(distinct, f))
return null;
- return new HashSet(distinct.Select(root => Refined(function, derivative, v, root)));
+ var refined = new HashSet();
+ foreach (var root in distinct)
+ if (Refined(function, derivative, v, root) is { } kept)
+ refined.Add(kept);
+ return refined;
}
///
@@ -250,7 +254,9 @@ void IterateFrom(NumericsComplex start)
///
/// , found in double, carried to the working precision by Newton's
- /// steps in the library's own evaluation, and given to the digits the error left is known to.
+ /// steps in the library's own evaluation, and given to the digits the error left is known to; or
+ /// where the first of those steps is longer than a thousandth of the root's
+ /// size, at least 1, so that no root is near it.
///
///
///
@@ -272,7 +278,7 @@ void IterateFrom(NumericsComplex start)
/// a double is sure of.
///
///
- private static Complex Refined(Entity function, Entity derivative, Entity.Variable v, Complex root)
+ private static Complex? Refined(Entity function, Entity derivative, Entity.Variable v, Complex root)
{
var context = MathS.Settings.DecimalPrecisionContext.Value;
if (context.Precision.IsZero || !context.Precision.CanFitInInt32())
@@ -293,6 +299,17 @@ private static Complex Refined(Entity function, Entity derivative, Entity.Variab
{
if (Step(current, System.Math.Min(digits, working)) is not var (next, step))
return RoundedTo(root, DoubleDigits);
+ // A root is where the Newton step from it is short, and not only where the value is small: a
+ // function that tends to 0 far out is under any tolerance there, and the step from such a point
+ // is as long as the point. x - i cos(arcsin(x)) is 1 / (2x) for large x, and points of size 10^8
+ // were answered as roots of it; in double it is 0 there outright. At a root found in double the
+ // first step is the error left, about 10^-16 of its size, and at a root of order m about the m-th
+ // root of that over m, inside a thousandth up to m = 6. A first step of 0 can be the value read as 0
+ // below the downcasting floor at these digits, as 1 / (2x) is at 10^31, and is taken again at all
+ // of them. https://github.com/asc-community/AngouriMath/issues/2763
+ if (count == 0 && (step.IsZero && working < digits && Step(current, digits) is var (_, again) ? again : step) is var first
+ && first.Abs().EDecimal.CompareTo(EDecimal.Max(EDecimal.One, root.Abs().EDecimal).Multiply(EDecimal.Create(1, -3))) > 0)
+ return null;
current = next;
last = step;
if (working >= digits && step.Abs().EDecimal.CompareTo(current.Abs().EDecimal.Multiply(enough)) <= 0)
diff --git a/Sources/Tests/UnitTests/Algebra/SolveTest/AValueAFunctionNeverTakesHasNoRootsTest.cs b/Sources/Tests/UnitTests/Algebra/SolveTest/AValueAFunctionNeverTakesHasNoRootsTest.cs
new file mode 100644
index 000000000..fbf25ce4d
--- /dev/null
+++ b/Sources/Tests/UnitTests/Algebra/SolveTest/AValueAFunctionNeverTakesHasNoRootsTest.cs
@@ -0,0 +1,73 @@
+//
+// Copyright (c) 2019-2026 Angouri.
+// AngouriMath is licensed under MIT.
+// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
+// Website: https://am.angouri.org.
+//
+
+using System.Linq;
+using AngouriMath.Extensions;
+using Xunit;
+
+namespace AngouriMath.Tests.Algebra
+{
+ ///
+ /// tan(w) = i is e^(2 i w) = 0, so tan never takes i or -i, nor
+ /// does cotan; sec and cosec never take 0, nor does a power of a number that
+ /// is not 0. An equation in x through one of them alone, at such a value, has no roots, whatever
+ /// is inside. tan(arcsin(x)) = i was answered with two points of size 10^8, found by
+ /// Newton's method on x - i cos(arcsin(x)), which is 1 / (2x) there.
+ /// https://github.com/asc-community/AngouriMath/issues/2763
+ ///
+ [Trait("Area", "Algebra")]
+ public sealed class AValueAFunctionNeverTakesHasNoRootsTest
+ {
+ [Theory]
+ [InlineData("tan(arcsin(x)) = i")]
+ [InlineData("tan(arcsin(x)) = -i")]
+ [InlineData("cotan(arccos(x)) = i")]
+ [InlineData("2 tan(arcsin(x)) = 2i")]
+ [InlineData("tan(arcsin(x))^2 = -1")]
+ [InlineData("tan(x^2 + 1) = i")]
+ [InlineData("tan(sqrt(x)) = -i")]
+ [InlineData("sec(x^2) = 0")]
+ [InlineData("2^(x^2 + x) = 0")]
+ public void HasNoRoots(string equation)
+ => Assert.True(Assert.IsType(equation.ToEntity().Solve("x")).IsSetEmpty);
+
+ ///
+ /// A root of a value only one of whose roots is omitted is still solved for the other:
+ /// (tan(x) - i)(tan(x) - 1) = 0 is tan(x) = 1, x = pi/4 + pi n.
+ ///
+ [Fact]
+ public void AnotherValueIsStillSolved()
+ {
+ var roots = "(tan(x) - i)(tan(x) - 1) = 0".ToEntity().Solve("x");
+ Assert.False(roots is Entity.Set.FiniteSet { IsSetEmpty: true });
+ Assert.Contains("pi / 4", roots.ToString());
+ }
+
+ ///
+ /// Newton's method keeps a point only where the step from it is short. x - i cos(arcsin(x))
+ /// has no root, since x = i sqrt(1 - x^2) squares to 0 = -1, and is 1 / (2x)
+ /// far out, under the search's tolerance but with a step as long as the point; and in double it
+ /// is 0 there outright. Left unsolved, which is honest; the points are not roots.
+ ///
+ [Fact]
+ public void APointWhereTheFunctionOnlyTendsToZeroIsNotARoot()
+ {
+ var roots = "x - i cos(arcsin(x)) = 0".ToEntity().Solve("x");
+ Assert.False(roots is Entity.Set.FiniteSet { IsSetEmpty: false });
+ }
+
+ /// The search still answers a genuine root: cos(x) = x at 0.7390851332151607.
+ [Fact]
+ public void AGenuineRootIsStillFound()
+ {
+ var roots = Assert.IsType("cos(x) = x".ToEntity().Solve("x"));
+ Assert.Contains(roots, root => root.EvalNumerical() is var value
+ && System.Math.Abs(value.RealPart.EDecimal.ToDouble() - 0.7390851332151607) < 1e-12
+ && value.ImaginaryPart.IsZero);
+ }
+ }
+}