From a98cc6fe48ecc4c56358c39904080b4095e57d6e Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Wed, 4 Nov 2026 14:06:23 +0000 Subject: [PATCH] Read an even power of a real base as never negative in a limit 1/((x^2)^tanh(1)) at 0 was NaN, the claim that the limit does not exist, where it is +oo from both sides. IsNeverNegative read a base as never negative only for an absolute value, or a real power, product or quotient of never-negative parts, so x^2 was not one. A vanishing power of it to a constant that is not a number, or to an exponent tending to a negative number, was left unevaluated from each side, and the two-sided limit was NaN for the sides not being answered. The same on 2.6.0. An even integer power of a base that TreeAnalyzer.IsRealValued says is real for real x is now never negative; IsNeverNegative takes the variable for it. The base has to be real: sqrt(x)^2 is x, and 1/(((i*x)^2)^tanh(1)), whose base is -x^2, is still not answered. limitcheck at DEPTH=3, seeds 14-36 (11 seeds), master against this: three NaNs answered, (sinh(x)^2)^(sin(x) - 1) and 1/((x^2)^tanh(1)) at seed 36 and sqrt(x^2)^tan(pi - 1) at seed 29, each +oo, and nothing else changed. Suite 18963 passed, AOT and the eight harnesses clean. Co-Authored-By: Claude Opus 5.5 --- BREAKING-CHANGES.md | 17 +++++++ .../Limits/Solvers/Limit.Classes.cs | 2 +- .../Limits/Solvers/Solvers.Definition.cs | 2 +- .../Continuous/Limits/Transformations.cs | 14 +++--- .../AnEvenPowerVanishesFromAboveTest.cs | 45 +++++++++++++++++++ 5 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 Sources/Tests/UnitTests/Calculus/AnEvenPowerVanishesFromAboveTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index a603de820..b75f30ac4 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -227,6 +227,23 @@ arctangent of something real, and an arcsine and an arccosine inside (-1, 1). Wh | `"sqrt(x^2)^(-3/2)".ToEntity().Limit("x", 0)` | `NaN` | `+oo` | | `"sin(arcsin(x)) * (tan(-1) + 2/x)".ToEntity().Limit("x", 0)` | `NaN` | `2` | +### A limit over a vanishing even power is not claimed not to exist + +**Silent: `1/((x^2)^tanh(1))` at 0 is `+oo`, where it was `NaN`, the claim that the limit does not exist.** A base +was read as never negative only for an absolute value, or a real power, product or quotient of never-negative parts, +so `x^2` was not. A vanishing power of it to a constant that is not a number, or to an exponent tending to a negative +number, was left unevaluated from each side, and the two-sided limit was `NaN`. An even power of a base real for +real `x` is now never negative. `1/(((i*x)^2)^tanh(1))`, whose base is `-x^2`, is still not answered. + +| Input | Was (2.6.0) | Now | +|---|---|---| +| `"1/((x^2)^tanh(1))".ToEntity().Limit("x", 0)` | `NaN` | `+oo` | +| `"1/((x^2)^tanh(1))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(1 / (x ^ 2) ^ ((e ^ (2 * 1) - 1) / (e ^ (2 * 1) + 1)), x, 0)` | `+oo` | +| `"(sinh(x)^2)^(sin(x) - 1)".ToEntity().Limit("x", 0)` | `NaN` | `+oo` | +| `"(sinh(x)^2)^(sin(x) - 1)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright((((e ^ x - e ^ (-x)) / 2) ^ 2) ^ (sin(x) - 1), x, 0)` | `+oo` | +| `"sqrt(x^2)^tan(pi - 1)".ToEntity().Limit("x", 0)` | `NaN` | `+oo` | +| `"sqrt(x^2)^tan(pi - 1)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright((sqrt(x ^ 2)) ^ tan(pi - 1), x, 0)` | `+oo` | + ### An equation in two different square roots is solved exactly **Silent: an equation `m_1 sqrt(A) + m_2 sqrt(B) + P = 0` in x alone, with two different square roots, is answered in diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs index 3f5fe7713..5a5334f75 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs @@ -333,7 +333,7 @@ partial record Powf // was left unevaluated from each side for it. Where the base vanishes, it does from // above. if (baseLimit?.Evaled is Real { IsZero: true } && exponentLimit?.Evaled is Real { IsNegative: true, IsFinite: true } - && IsNeverNegative(Base)) + && IsNeverNegative(Base, x)) return Real.PositiveInfinity; var substituted = (baseLimit, exponentLimit) diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs index 3e2ec8778..3c14c6e5b 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs @@ -249,7 +249,7 @@ bool RealThere(Entity node) // reads off the form, an even power of something real, and a real power that is itself // real -- sqrt(x^2), whose base vanishes at 0 and is not positive there. bool NotNegativeThere(Entity node) - => IsNeverNegative(node) + => IsNeverNegative(node, x) || node is Powf(var @base, Integer { EInteger.IsEven: true }) && RealThere(@base) || node is Powf(_, not Integer) && RealThere(node); bool StrictlyInsideTheUnitInterval(Entity node) diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs index 5ffbe1905..9dead244e 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs @@ -1102,7 +1102,7 @@ internal static bool IsDeterminate(Entity combined, Variable x) // https://github.com/asc-community/AngouriMath/issues/2274 if (EvalAssumingContinuous(dividend.Limit(x, dest, side)) is not Real { IsZero: false, IsNaN: false } dividendLimit) return null; - if ((IsNeverNegative(divisor) ? 1 : SignFromVanishingOrder(divisor, x, dest, side)) is not { } divisorSign) + if ((IsNeverNegative(divisor, x) ? 1 : SignFromVanishingOrder(divisor, x, dest, side)) is not { } divisorSign) return null; return dividendLimit.IsNegative == divisorSign > 0 ? Real.NegativeInfinity @@ -1121,12 +1121,16 @@ internal static bool IsDeterminate(Entity combined, Variable x) /// from each side and NaN from both, where it is +oo. Where such an expression vanishes /// it does so from above, whatever its argument does. /// - internal static bool IsNeverNegative(Entity expr) => expr switch + internal static bool IsNeverNegative(Entity expr, Variable x) => expr switch { Absf => true, - Powf(var @base, var exponent) => IsNeverNegative(@base) && exponent.Evaled is Real { IsNaN: false }, - Mulf(var multiplier, var multiplicand) => IsNeverNegative(multiplier) && IsNeverNegative(multiplicand), - Divf(var dividend, var divisor) => IsNeverNegative(dividend) && IsNeverNegative(divisor), + // An even power of something real: x^2, and sinh(x)^2, whose powers to a negative + // exponent were NaN at 0 from both sides for want of it. The base has to be real for + // real x, since sqrt(x)^2 is x. + Powf(var @base, Integer { EInteger.IsEven: true }) when TreeAnalyzer.IsRealValued(@base, x) => true, + Powf(var @base, var exponent) => IsNeverNegative(@base, x) && exponent.Evaled is Real { IsNaN: false }, + Mulf(var multiplier, var multiplicand) => IsNeverNegative(multiplier, x) && IsNeverNegative(multiplicand, x), + Divf(var dividend, var divisor) => IsNeverNegative(dividend, x) && IsNeverNegative(divisor, x), _ when expr.Evaled is Real { IsNegative: false, IsNaN: false } => !expr.FreeVariables.Any(), _ => false }; diff --git a/Sources/Tests/UnitTests/Calculus/AnEvenPowerVanishesFromAboveTest.cs b/Sources/Tests/UnitTests/Calculus/AnEvenPowerVanishesFromAboveTest.cs new file mode 100644 index 000000000..5a658c7b3 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/AnEvenPowerVanishesFromAboveTest.cs @@ -0,0 +1,45 @@ +// +// 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 AngouriMath.Core; +using Xunit; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// 1/((x^2)^tanh(1)) at 0 was NaN -- the claim that the limit does not exist -- where it is +oo from both sides. + /// A base was read as never negative only for an absolute value, or a power, product or quotient of never-negative + /// parts, so x^2 was not, and a vanishing power of it to a constant that is not a number, or to an exponent + /// tending to a negative number, as (sinh(x)^2)^(sin(x) - 1), was left unevaluated from each side. An even + /// power of a base real for real x is never negative now. The same on 2.6.0. Found by limitcheck at + /// DEPTH=3, SEED=36, and sqrt(x^2)^tan(pi - 1) at + /// SEED=29; no issue was filed. + /// + [Trait("Area", "Calculus")] + public sealed class AnEvenPowerVanishesFromAboveTest + { + [Theory] + [InlineData("1/((x^2)^tanh(1))", "0", "+oo")] + [InlineData("-1/((x^2)^tanh(1))", "0", "-oo")] + [InlineData("(sinh(x)^2)^(sin(x) - 1)", "0", "+oo")] + [InlineData("((x - 1)^2)^(-pi/4)", "1", "+oo")] + [InlineData("(sin(x)^4)^(-tanh(1))", "0", "+oo")] + [InlineData("sqrt(x^2)^tan(pi - 1)", "0", "+oo")] + public void IsTheLimitFromEachSideAndBoth(string input, string destination, string expected) + { + foreach (var side in new[] { ApproachFrom.Left, ApproachFrom.Right, ApproachFrom.BothSides }) + Assert.Equal(MathS.FromString(expected), MathS.FromString(input).Limit("x", destination, side)); + } + + // (i x)^2 is -x^2, negative on both sides, so a power of it to an exponent that is not whole is not real there, + // and is not claimed to diverge to +oo. + [Fact] + public void AnEvenPowerOfSomethingNotRealIsNotClaimed() + => Assert.NotEqual(MathS.FromString("+oo"), + MathS.FromString("1/(((i*x)^2)^tanh(1))").Limit("x", 0, ApproachFrom.Right)); + } +}