Skip to content

Commit 60e6638

Browse files
Read the side a step function's argument arrives from off its slope (#2375)
A floor or a ceiling whose argument arrives at a jump asks the sign the argument less the jump keeps on the way in, and that sign was read only off the first derivative that does not vanish. sqrt(x) at 0 has none that is finite, so floor(sqrt(x)) at 0 from the right was not answered, where it is 0 all the way in. Where that fails, the sign is now also read off the slope g(x) / (x - a): where it tends to a non-zero L, infinities included, g has the sign of L on the right and the other on the left. For sqrt(x) the slope is 1 / sqrt(x), which tends to +oo. A sign is a question about a real value, and the slope of a complex one can tend to a real infinity: x ^ tanh(pi) on the left of 0 is |x| ^ tanh(pi) times e ^ (i pi tanh(pi)), which this read as negative. So the expression has to be real throughout the side approached, by IsRealValued or by WhereRealValued's condition holding there; its real domain condition is no test, as that of x ^ tanh(pi) is true. limitcheck at DEPTH=3 over 30 seeds against master: no case lost; one timeout fewer, which is within the noise of a case that takes about 6 s on either. Found by limitcheck at SEED=59, where floor(sqrt(x)) - (x^3)^(x/2) at 0 from the right is -1; no issue was filed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 595d9b6 commit 60e6638

3 files changed

Lines changed: 96 additions & 1 deletion

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ root near 23.
9393
| `"x^7 - 5x^6 + 1 = 0".Solve("x")` | six roots, none of them near 5 | seven roots |
9494
| `"x^4 - 3*x^(5/2) + 2 = 0".Solve("x")` | `{ 1, 4.8870…^(2/5) }` | four roots: `1`, `1.3734…^2`, and two off the real line |
9595

96+
### A step function reads the side its argument arrives from off the slope
97+
98+
**A one-sided limit of a floor or a ceiling whose argument arrives at a jump like a root is answered, where it was
99+
not.** Which side of the jump the argument comes from was read only off the first derivative that does not vanish,
100+
and `sqrt(x)` at 0 has none that is finite. It is now also read off the slope `g(x) / (x - a)`, which for `sqrt(x)`
101+
is `1 / sqrt(x)` and tends to +oo, so `sqrt(x)` is above 0 on the right.
102+
103+
| Input | Was (2.6.0) | Now |
104+
|---|---|---|
105+
| `"floor(sqrt(x))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(floor(sqrt(x)), x, 0)` | `0` |
106+
| `"ceil(sqrt(x))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(ceil(sqrt(x)), x, 0)` | `1` |
107+
| `"floor(x - sqrt(x))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(floor(x - sqrt(x)), x, 0)` | `-1` |
108+
| `"floor(1 - sqrt(1 - x))".ToEntity().Limit("x", 1, ApproachFrom.Left)` | `limitleft(floor(1 - sqrt(1 - x)), x, 1)` | `0` |
109+
| `"floor(sqrt(x)) - (x^3)^(x/2)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `NaN` | `-1` |
110+
96111
### An infinity in an expression is not read as a coefficient
97112

98113
**Wrong answer: `log(x, 0)` at 0 from the right is `+oo`, where it was `0`.** `log(x, 0)` is `ln(0) / ln(x)`, and

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,41 @@ internal static Entity AtALargeDecimal(Entity expr, Variable x)
11931193
// those margins keeps it on the same side of zero.
11941194
if (!limit.IsZero)
11951195
return limit.IsNegative ? -1 : 1;
1196-
return SignFromVanishingOrder(expr, x, dest, side);
1196+
return SignFromVanishingOrder(expr, x, dest, side) ?? SignFromTheSlope(expr, x, dest, side);
1197+
}
1198+
1199+
/// <summary>
1200+
/// The sign an expression tending to 0 keeps near a finite destination, read off the
1201+
/// limit of its slope from the destination, <c>g(x) / (x - a)</c>, or
1202+
/// <see langword="null"/> where that limit is 0 or not a real number.
1203+
/// </summary>
1204+
/// <remarks>
1205+
/// Where the slope tends to a non-zero L, infinities included, it has the sign of L near
1206+
/// a, and <c>x - a</c> is positive on the right and negative on the left, so g has the
1207+
/// sign of L on the right and the other sign on the left. This needs no derivative, and
1208+
/// answers where <see cref="SignFromVanishingOrder"/> cannot: <c>sqrt(x)</c> at 0, whose
1209+
/// derivative diverges there, has the slope <c>1 / sqrt(x)</c>, which tends to +oo, and
1210+
/// so <c>floor(sqrt(x))</c> at 0 from the right is 0, where it was not answered.
1211+
/// <para/>
1212+
/// A sign is a question about a real value, and the slope of a complex one can still tend to
1213+
/// a real infinity: <c>x ^ tanh(pi)</c> on the left of 0 is <c>|x| ^ tanh(pi)</c> times
1214+
/// <c>e ^ (i pi tanh(pi))</c>, and was read as negative. So the expression has to be real
1215+
/// throughout the side approached: real wherever it is defined, or real where the bases of its
1216+
/// roots are positive and those hold there, which <c>sqrt(x)</c>'s does on the right of 0 and
1217+
/// not on the left. Its real domain condition does not say this: that of <c>x ^ tanh(pi)</c>
1218+
/// is true. Each base is a part of the expression, so asking about it does not come back here
1219+
/// with the same question.
1220+
/// </remarks>
1221+
private static int? SignFromTheSlope(Entity expr, Variable x, Entity dest, ApproachFrom side)
1222+
{
1223+
if (side is not (ApproachFrom.Left or ApproachFrom.Right) || !dest.IsFinite)
1224+
return null;
1225+
if (!Functions.TreeAnalyzer.IsRealValued(expr, x)
1226+
&& !(Functions.TreeAnalyzer.WhereRealValued(expr, x) is { } whereReal && HoldsNear(whereReal, x, dest, side) is true))
1227+
return null;
1228+
if (EvalAssumingContinuous((expr / (x - dest)).Limit(x, dest, side)) is not Real { IsNaN: false, IsZero: false } slope)
1229+
return null;
1230+
return slope.IsNegative == (side is ApproachFrom.Left) ? 1 : -1;
11971231
}
11981232

11991233
/// <summary>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
/// A step function whose argument arrives at a jump asks the sign the argument keeps on the way in, and that sign
15+
/// was read only off the first derivative that does not vanish. <c>sqrt(x)</c> at 0 has a derivative that diverges
16+
/// there, so <c>floor(sqrt(x))</c> at 0 from the right was not answered, where it is 0 all the way in. The slope
17+
/// <c>g(x) / (x - a)</c> settles it: <c>1 / sqrt(x)</c> tends to +oo, so <c>sqrt(x)</c> is positive on the right.
18+
/// Found by limitcheck at <c>DEPTH=3</c>, <c>SEED=59</c>; no issue was filed.
19+
/// </summary>
20+
[Trait("Area", "Calculus")]
21+
public sealed class ASignFromTheSlopeTest
22+
{
23+
[Theory]
24+
[InlineData("floor(sqrt(x))", "0", ApproachFrom.Right, "0")]
25+
[InlineData("ceil(sqrt(x))", "0", ApproachFrom.Right, "1")]
26+
[InlineData("floor(-sqrt(x))", "0", ApproachFrom.Right, "-1")]
27+
[InlineData("floor(sqrt(x)) - (x^3)^(x/2)", "0", ApproachFrom.Right, "-1")]
28+
[InlineData("floor(sqrt(x) - x)", "0", ApproachFrom.Right, "0")]
29+
[InlineData("floor(x - sqrt(x))", "0", ApproachFrom.Right, "-1")]
30+
[InlineData("floor(1 - sqrt(1 - x))", "1", ApproachFrom.Left, "0")]
31+
[InlineData("ceil(1 - sqrt(1 - x))", "1", ApproachFrom.Left, "1")]
32+
[InlineData("floor(cbrt(x))", "0", ApproachFrom.Right, "0")]
33+
public void ReadsTheSignOffTheSlope(string input, string destination, ApproachFrom side, string expected)
34+
=> Assert.Equal(MathS.FromString(expected).Simplify(),
35+
MathS.FromString(input).Limit("x", destination, side).Simplify());
36+
37+
// The slope of a complex value can tend to a real infinity: x ^ tanh(pi) on the left of 0 is |x| ^ tanh(pi)
38+
// times e ^ (i pi tanh(pi)), whose sign is not -1. A root's base that is not positive on the side approached
39+
// leaves the sign unread, and a declined limit keeps its node.
40+
[Theory]
41+
[InlineData("sgn(x ^ tanh(pi))", "0", ApproachFrom.Left)]
42+
[InlineData("floor(sqrt(x))", "0", ApproachFrom.Left)]
43+
public void LeavesAComplexValueUnread(string input, string destination, ApproachFrom side)
44+
=> Assert.IsNotType<Entity.Number.Integer>(MathS.FromString(input).Limit("x", destination, side));
45+
}
46+
}

0 commit comments

Comments
 (0)