Skip to content

Commit f3e514a

Browse files
Read a vanishing absolute value as vanishing from above (#2364)
1/abs(x) at 0 was NaN -- the claim that the limit does not exist -- where it is +oo. The sign a vanishing divisor keeps was read off its derivatives, and the derivative of abs(x) is sgn(x), 0 at 0, with nothing after it, so each side was left unevaluated and the two descents not matching made the two-sided limit NaN. Same on 2.6.0. An absolute value, and a real power, a product or a quotient of such things, is now never negative by its form: a divisor of that kind vanishes from above, and a power of it to an exponent tending to a negative number tends to +oo. Two sides that agree were promoted to the two-sided limit only for an expression shown real on both, which knew nothing of an absolute value, a sine, a cosine, an arctangent or an arcsine, nor of a real power of something never negative: sin(arcsin(x)) * (tan(-1) + 2/x) is 2 from each side and was NaN, and sqrt(x^2)^(-3/2) +oo. Those are read now. That makes tan(x/2) at pi real on both sides, and it asked its two sides in full again each time, though the descent had answered them +oo and -oo -- the one-sided path returns the descent's value first, so they differ again -- and the definite integral of 1/(2 + cos(x)) over [0, pi] ran out of its budget of limits. Both sides are asked again only where one came back NaN. limitcheck, DEPTH=3, seeds 14, 16, 19, 23, 26, 29 against master 53ce725: compared 30980 -> 30987, the limit is NaN where the values settle 79 -> 75, the wrong values unchanged. Found at SEED=29; no issue was filed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 53ce725 commit f3e514a

5 files changed

Lines changed: 135 additions & 3 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,29 @@ did, and `ln(x + 2) / ln(x + 3)` at 0 was `ln(2) / ln(3)`. With symbols it was n
204204
| `"limit(ln(a + 1/x) / ln(b + 1/x), x, +oo)".ToEntity().Simplify()` | `a / b` | `ln(a) / ln(b)` |
205205
| `"limit(ln(1 + x) / ln(y + x), x, 0)".ToEntity().Simplify()` | `1 / y` | `0 provided not ln(y) = 0` |
206206

207+
### A limit over a vanishing absolute value is not claimed not to exist
208+
209+
**Silent: `1/abs(x)` at 0 is `+oo`, where it was `NaN`, the claim that the limit does not exist.** The sign a
210+
vanishing divisor keeps was read off its derivatives, and the derivative of `abs(x)` is `sgn(x)`, 0 at 0, with
211+
nothing after it: each side was left unevaluated, and the two-sided limit was `NaN`. An absolute value, and a real
212+
power, product or quotient of absolute values, now vanishes from above. And two sides that agree are the two-sided
213+
limit for an expression real on both sides, which now includes an absolute value, a sine, a cosine and an
214+
arctangent of something real, and an arcsine and an arccosine inside (-1, 1). Where the sides differ, as for
215+
`x / abs(x)`, the limit is still `NaN`.
216+
217+
| Input | Was (2.6.0) | Now |
218+
|---|---|---|
219+
| `"1/abs(x)".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
220+
| `"1/abs(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(1 / abs(x), x, 0)` | `+oo` |
221+
| `"-2/abs(x)".ToEntity().Limit("x", 0)` | `NaN` | `-oo` |
222+
| `"1/abs(sin(x))".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
223+
| `"(x + 1)/abs(x)".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
224+
| `"1/abs(x - 1)".ToEntity().Limit("x", 1)` | `NaN` | `+oo` |
225+
| `"abs(x)^(-3/2)".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
226+
| `"abs(x)^(-3/2)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(abs(x) ^ (-3/2), x, 0)` | `+oo` |
227+
| `"sqrt(x^2)^(-3/2)".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
228+
| `"sin(arcsin(x)) * (tan(-1) + 2/x)".ToEntity().Limit("x", 0)` | `NaN` | `2` |
229+
207230
### An equation in two different square roots is solved exactly
208231

209232
**Silent: an equation `m_1 sqrt(A) + m_2 sqrt(B) + P = 0` in x alone, with two different square roots, is answered in

‎Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Limit.Classes.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ partial record Powf
328328
// the logarithm above declines it. https://github.com/asc-community/AngouriMath/issues/2266
329329
if (exponentLimit?.Evaled is not Integer && ArrivesOnTheCutOffTheRealLine(Base, baseLimit, x, dist))
330330
return null;
331+
// A base that is never negative and vanishes, to an exponent tending to a negative
332+
// number, tends to +oo: 0 to a negative power has no value, and abs(x)^(-3/2) at 0
333+
// was left unevaluated from each side for it. Where the base vanishes, it does from
334+
// above.
335+
if (baseLimit?.Evaled is Real { IsZero: true } && exponentLimit?.Evaled is Real { IsNegative: true, IsFinite: true }
336+
&& IsNeverNegative(Base))
337+
return Real.PositiveInfinity;
331338
var substituted =
332339
(baseLimit, exponentLimit)
333340
switch {

‎Sources/AngouriMath/Functions/Continuous/Limits/Solvers/Solvers.Definition.cs‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,34 @@ bool RealThere(Entity node)
216216
Mulf(var multiplier, var multiplicand) => RealThere(multiplier) && RealThere(multiplicand),
217217
Divf(var dividend, var divisor) => RealThere(dividend) && RealThere(divisor),
218218
Powf(var @base, Integer) => RealThere(@base),
219-
Powf(var @base, var exponent) => RealThere(@base) && RealThere(exponent) && PositiveOnBothSides(@base),
219+
Powf(var @base, var exponent) => RealThere(@base) && RealThere(exponent)
220+
&& (NotNegativeThere(@base) || PositiveOnBothSides(@base)),
220221
Logf(var @base, var antilogarithm) => RealThere(@base) && RealThere(antilogarithm)
221222
&& PositiveOnBothSides(@base) && PositiveOnBothSides(antilogarithm),
223+
// An absolute value is real whatever it is of, and a sine, a cosine and an
224+
// arctangent of a real argument are real. An arcsine and an arccosine are real
225+
// on [-1, 1], so near the point only where their argument is inside it there.
226+
// 1/abs(x)^3 at 0 and sin(arcsin(x)) * (c + 2/x) were NaN for want of these,
227+
// where each side agrees with the other.
228+
Absf => true,
229+
Sinf(var argument) => RealThere(argument),
230+
Cosf(var argument) => RealThere(argument),
231+
Arctanf(var argument) => RealThere(argument),
232+
Arcsinf(var argument) => RealThere(argument) && StrictlyInsideTheUnitInterval(argument),
233+
Arccosf(var argument) => RealThere(argument) && StrictlyInsideTheUnitInterval(argument),
222234
_ => false
223235
};
224236
}
237+
// Not negative on either side, so that a real power of it is real: what IsNeverNegative
238+
// reads off the form, an even power of something real, and a real power that is itself
239+
// real -- sqrt(x^2), whose base vanishes at 0 and is not positive there.
240+
bool NotNegativeThere(Entity node)
241+
=> IsNeverNegative(node)
242+
|| node is Powf(var @base, Integer { EInteger.IsEven: true }) && RealThere(@base)
243+
|| node is Powf(_, not Integer) && RealThere(node);
244+
bool StrictlyInsideTheUnitInterval(Entity node)
245+
=> node.Substitute(x, dest).Evaled is Real { IsFinite: true } value
246+
&& value.EDecimal.Abs().CompareTo(PeterO.Numbers.EDecimal.One) < 0;
225247
bool PositiveOnBothSides(Entity node)
226248
=> !node.ContainsNode(x)
227249
? node.Evaled is Real { IsPositive: true }
@@ -485,7 +507,14 @@ internal static T WithinABudget<T>(int limits, System.Func<T> compute)
485507
return byRule;
486508
// Asking each side properly, which is what the two above were not asked.
487509
// https://github.com/asc-community/AngouriMath/issues/719
488-
if (WhereBothSidesAgree(expr, x, dest) is { } agreed)
510+
// Only where a side came back NaN. A side the descent answered with a value is
511+
// what asking that side outright answers too, since the one-sided path returns
512+
// the descent's value before anything else, so two values that differ differ
513+
// again: tan(x/2) at pi, +oo and -oo, asked both sides through the whole of the
514+
// machinery each time, and a definite integral over [0, pi] spent its budget of
515+
// limits on that.
516+
if ((fromLeft.Evaled == MathS.NaN || fromRight.Evaled == MathS.NaN)
517+
&& WhereBothSidesAgree(expr, x, dest) is { } agreed)
489518
return agreed;
490519
return MathS.NaN; // A two-sided limit cannot exist if the limit from left and right don't match.
491520
}

‎Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,13 +1102,35 @@ internal static bool IsDeterminate(Entity combined, Variable x)
11021102
// https://github.com/asc-community/AngouriMath/issues/2274
11031103
if (EvalAssumingContinuous(dividend.Limit(x, dest, side)) is not Real { IsZero: false, IsNaN: false } dividendLimit)
11041104
return null;
1105-
if (SignFromVanishingOrder(divisor, x, dest, side) is not { } divisorSign)
1105+
if ((IsNeverNegative(divisor) ? 1 : SignFromVanishingOrder(divisor, x, dest, side)) is not { } divisorSign)
11061106
return null;
11071107
return dividendLimit.IsNegative == divisorSign > 0
11081108
? Real.NegativeInfinity
11091109
: Real.PositiveInfinity;
11101110
}
11111111

1112+
/// <summary>
1113+
/// Whether an expression is real and not negative wherever it has a value, by its
1114+
/// form: an absolute value, a power of such a thing to a real exponent, a product or a
1115+
/// quotient of them, a positive constant.
1116+
/// </summary>
1117+
/// <remarks>
1118+
/// The sign a vanishing divisor keeps is otherwise read off its derivatives, which an
1119+
/// absolute value does not have where it vanishes: the derivative of abs(x) is sgn(x),
1120+
/// 0 at 0, and the next one has no value there. So 1/abs(x) at 0 was left unevaluated
1121+
/// from each side and NaN from both, where it is +oo. Where such an expression vanishes
1122+
/// it does so from above, whatever its argument does.
1123+
/// </remarks>
1124+
internal static bool IsNeverNegative(Entity expr) => expr switch
1125+
{
1126+
Absf => true,
1127+
Powf(var @base, var exponent) => IsNeverNegative(@base) && exponent.Evaled is Real { IsNaN: false },
1128+
Mulf(var multiplier, var multiplicand) => IsNeverNegative(multiplier) && IsNeverNegative(multiplicand),
1129+
Divf(var dividend, var divisor) => IsNeverNegative(dividend) && IsNeverNegative(divisor),
1130+
_ when expr.Evaled is Real { IsNegative: false, IsNaN: false } => !expr.FreeVariables.Any(),
1131+
_ => false
1132+
};
1133+
11121134
/// <summary>
11131135
/// The sign an expression that vanishes at the destination keeps on one side of it,
11141136
/// or <see langword="null"/> where it cannot be read off.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.Core;
9+
using Xunit;
10+
11+
namespace AngouriMath.Tests.Calculus
12+
{
13+
/// <summary>
14+
/// <c>1/abs(x)</c> at 0 was NaN -- the claim that the limit does not exist -- where it is +oo from both sides. The sign
15+
/// a vanishing divisor keeps was read off its derivatives, and the derivative of <c>abs(x)</c> is <c>sgn(x)</c>, 0 at
16+
/// 0, with nothing after it; so each side was left unevaluated, and the two-sided limit was NaN for the descent's two
17+
/// readings not matching. And where both sides were answered, they were promoted to the two-sided limit only for an
18+
/// expression shown real on both sides, which knew nothing of an absolute value, a sine or an arcsine:
19+
/// <c>sin(arcsin(x)) * (tan(-1) + 2/x)</c> is 2 from each side and was NaN. The same on 2.6.0. Found by limitcheck at
20+
/// <c>DEPTH=3</c>, <c>SEED=29</c>; no issue was filed.
21+
/// </summary>
22+
[Trait("Area", "Calculus")]
23+
public sealed class AnAbsoluteValueVanishesFromAboveTest
24+
{
25+
[Theory]
26+
[InlineData("1/abs(x)", "0", "+oo")]
27+
[InlineData("1/abs(x)^3", "0", "+oo")]
28+
[InlineData("-2/abs(x)", "0", "-oo")]
29+
[InlineData("1/abs(x - 1)", "1", "+oo")]
30+
[InlineData("1/abs(sin(x))", "0", "+oo")]
31+
[InlineData("(x + 1)/abs(x)", "0", "+oo")]
32+
[InlineData("abs(x)^(-3/2)", "0", "+oo")]
33+
[InlineData("sqrt(x^2)^(-3/2)", "0", "+oo")]
34+
[InlineData("sin(arcsin(x)) * (tan(-1) + 2/x)", "0", "2")]
35+
public void IsTheLimitFromEachSideAndBoth(string input, string destination, string expected)
36+
{
37+
foreach (var side in new[] { ApproachFrom.Left, ApproachFrom.Right, ApproachFrom.BothSides })
38+
Assert.Equal(MathS.FromString(expected), MathS.FromString(input).Limit("x", destination, side));
39+
}
40+
41+
// Where the two sides differ, or one of them is not a limit of real values, there is still no two-sided limit.
42+
[Theory]
43+
[InlineData("x/abs(x)")]
44+
[InlineData("sqrt(x^2)/x")]
45+
[InlineData("abs(x)^(1/2)/x")]
46+
[InlineData("arcsin(x + 1)/x")]
47+
[InlineData("x^x")]
48+
public void HasNoTwoSidedLimit(string input)
49+
=> Assert.Equal(MathS.NaN, MathS.FromString(input).Limit("x", 0));
50+
}
51+
}

0 commit comments

Comments
 (0)