Skip to content

Commit 4949e4c

Browse files
Answer a step function of an unbounded argument times a vanishing factor (#2430)
* Answer a step function of an unbounded argument times a vanishing factor Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ff72b6f commit 4949e4c

5 files changed

Lines changed: 138 additions & 7 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@ A not-equal written `<>` is read as `not (a = b)`, and printed that way.
4242

4343
## Unreleased — since 2.6.0
4444

45+
### A step function of an unbounded argument times a vanishing factor has the limit of the factor times the argument
46+
47+
**Silent: a limit of `f * floor(g)`, `f * ceil(g)` or `f * round(g)`, where `f` tends to 0 and `g` is real, is
48+
answered with the limit of `f * g`.** The step is within 1 of its argument, so the two products differ by `f` times
49+
something bounded, which tends to 0. Each side used to stop at `0 * floor(+oo)`, which 2.6.0 answered with a wrong `0`
50+
one-sided and `NaN` two-sided. Where `f * g` has no limit of its own the limit is left as it was. Found by limitcheck;
51+
no issue was filed.
52+
53+
| Input | Was (2.6.0) | Now |
54+
|---|---|---|
55+
| `"x * floor(2/x)".ToEntity().Limit("x", 0)` | `NaN` | `2` |
56+
| `"x * floor(2/x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `0` | `2` |
57+
| `"floor(1/x) * sin(x)".ToEntity().Limit("x", 0)` | `NaN` | `1` |
58+
| `"x^2 * floor(1/x^2)".ToEntity().Limit("x", 0)` | `0` | `1` |
59+
| `"x * ceil(1/x)".ToEntity().Limit("x", 0)` | `NaN` | `1` |
60+
| `"x * round(1/x)".ToEntity().Limit("x", 0)` | throws `OverflowException` | `1` |
61+
| `"x^2 * floor(1/x)".ToEntity().Limit("x", 0)` | `NaN` | `0` |
62+
| `"x * floor(1/x^2)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `0` | `+oo` |
63+
| `"x * floor(1/x^2)".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `0` | `-oo` |
64+
| `"x * floor(2/x) + 3".ToEntity().Limit("x", 0)` | `limit(x * floor(2 / x) + 3, x, 0)` | `5` |
65+
| `"floor(x) / x".ToEntity().Limit("x", "+oo")` | `0` | `1` |
66+
4567
### A product with a quotient for a factor is read over that quotient's divisor in a one-sided limit
4668

4769
**Silent: a one-sided limit of a product whose factors tend to 0 and to an infinity, one of them a quotient, is asked
@@ -101,6 +123,9 @@ and 1 in order. 2.6.0 answered the third with a wrong `0`. Found by limitcheck;
101123
| `"x^2 * floor(1/x^2)".ToEntity().Limit("x", 0)` | `0` | `limit(x ^ 2 * floor(1 / x ^ 2), x, 0)` |
102124
| `"x * ceil(1/x)".ToEntity().Limit("x", 0)` | `NaN` | `limit(x * ceil(1 / x), x, 0)` |
103125

126+
These four are answered with their values by the entry *A step function of an unbounded argument times a vanishing
127+
factor has the limit of the factor times the argument*, above.
128+
104129
### A two-sided limit whose side stops at a finite indeterminate form is left unevaluated
105130

106131
**Silent: a two-sided limit is left unevaluated, rather than answered, where a side's limit stops at an indeterminate

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,47 @@ static bool OnAJump(Entity argument, System.Func<Real, bool> jump)
250250
? Real.NaN
251251
: null;
252252

253+
/// <summary>
254+
/// A step function of an unbounded argument times a factor that vanishes: the limit of
255+
/// <c>f * floor(g)</c> is the limit of <c>f * g</c>, and the same for <c>ceil</c> and
256+
/// <c>round</c>.
257+
/// </summary>
258+
/// <remarks>
259+
/// <c>floor(g) = g - r</c> with <c>0 &lt;= r &lt; 1</c> wherever <c>g</c> is real, <c>ceil(g) = g + r</c>
260+
/// with the same bound, and <c>round(g)</c> is within 1/2 of <c>g</c>. So
261+
/// <c>f * floor(g) - f * g</c> is <c>f</c> times something bounded by 1, which tends to 0
262+
/// wherever <c>f</c> does, and the two products have the same limit, a value or an
263+
/// infinity alike. Assumed, and checked: <c>g</c> is real-valued, and the other factors
264+
/// tend to 0. Nothing is assumed of <c>g</c>'s limit, which is the point -- the descent
265+
/// puts each part's own limit in place of the part, so <c>x floor(2/x)</c> at 0 was read
266+
/// as <c>0 * floor(+oo)</c>, a form it cannot settle, where it is 2 from either side.
267+
/// <para/>
268+
/// Only a limit is taken from it. A <c>NaN</c> for <c>f * g</c> would say the same of the
269+
/// step, but inside the machinery <c>NaN</c> can also be a form nothing read, so it is left
270+
/// to the rules that already decide those.
271+
/// </remarks>
272+
internal static Entity? SolveAsAStepOfAnUnboundedArgument(Entity expr, Variable x)
273+
{
274+
if (expr is not (Mulf or Divf) || !expr.Nodes.Any(static node => node is Floorf or Ceilf or Roundf))
275+
return null;
276+
var factors = Mulf.LinearChildren(expr);
277+
for (var i = 0; i < factors.Count; i++)
278+
{
279+
if (factors[i] is not (Floorf or Ceilf or Roundf) || !factors[i].ContainsNode(x))
280+
continue;
281+
var argument = factors[i].DirectChildren[0];
282+
if (!IsRealValued(argument, x))
283+
continue;
284+
var rest = factors.Where((_, j) => j != i).Aggregate((Entity)Integer.One, static (product, factor) => product * factor);
285+
if (!rest.ContainsNode(x) || !VanishesAtInfinity(rest, x))
286+
continue;
287+
if (LimitFunctional.ComputeLimit((rest * argument).InnerSimplified, x, Real.PositiveInfinity) is { } limit
288+
&& limit.Evaled != MathS.NaN)
289+
return limit;
290+
}
291+
return null;
292+
}
293+
253294
private static bool VanishesAtInfinity(Entity expr, Variable x)
254295
=> LimitFunctional.ComputeLimit(expr, x, Real.PositiveInfinity) is { } limit
255296
&& limit.Evaled is Real { IsZero: true };

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ private static Entity AsAPowerOfTheVariable(Entity node, Variable x)
130130
var oscillationResult = LimitSolvers.SolveAsOscillationWithoutLimit(expr, x);
131131
if (oscillationResult is { }) return oscillationResult;
132132

133+
// After both rules above, which settle the products they read without asking for
134+
// another limit; this one asks for the limit of a second product.
135+
var stepResult = LimitSolvers.SolveAsAStepOfAnUnboundedArgument(expr, x);
136+
if (stepResult is { }) return stepResult;
137+
133138
return null;
134139
}
135140

@@ -184,8 +189,8 @@ node is Floorf or Ceilf or Roundf or Signumf
184189
{
185190
// Set where no answer came because a side has none yet, rather than because a side
186191
// does not exist or the two differ. Neither side is then known to be NaN, so neither
187-
// is the limit: x floor(2/x) at 0 is 2 from each side, the one-sided paths do not
188-
// decide it, and the two-sided one answered NaN.
192+
// is the limit: floor(1/x) / floor(2/x) at 0 is 1/2 from each side, the one-sided
193+
// paths do not decide it, and a NaN here would say there is no limit.
189194
aSideIsUndecided = false;
190195
if (bothSidesDepth >= MaxBothSidesDepth
191196
|| MathS.Settings.Codomain.Value is not AngouriMath.Core.Domain.Real && !IsRealOnBothSides(expr, x, dest))
@@ -213,7 +218,7 @@ node is Floorf or Ceilf or Roundf or Signumf
213218

214219
// An indeterminate form a side's own limit could not read is NaN inside the machinery,
215220
// where it stops the search, and withheld at the outermost call, where it is not an
216-
// answer. One with an infinity in it, 0 * floor(-oo) for x floor(2/x), is a product or
221+
// answer. One with an infinity in it, such as 0 * oo or oo / oo, is a product or
217222
// a quotient of parts whose rates were never compared, so that side is undecided rather
218223
// than absent. So is one of finite parts where the expression takes real values on that
219224
// side: erf(abs(x)) / x^4 at 0 stops at 0 / 0 from each side, is +oo from each, and was
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// f floor(g), f ceil(g) and f round(g), where f tends to 0 and g is real, have the limit of f g: the step is within 1
16+
/// of its argument, so the two products differ by f times something bounded. x floor(2/x) at 0 was left unevaluated,
17+
/// each side stopping at 0 * floor(+-oo), where it is 2. Each value here was checked at x = +-7/3 * 10^-k for k from 4
18+
/// to 8. No issue was filed.
19+
/// </summary>
20+
[Trait("Area", "Calculus")]
21+
public sealed class AStepOfAnUnboundedArgumentTimesAVanishingFactorTest
22+
{
23+
[Theory]
24+
[InlineData("x * floor(2/x)", "0", "2")]
25+
[InlineData("floor(1/x) * sin(x)", "0", "1")]
26+
[InlineData("x^2 * floor(1/x^2)", "0", "1")]
27+
[InlineData("x * ceil(1/x)", "0", "1")]
28+
[InlineData("x * round(1/x)", "0", "1")]
29+
[InlineData("x * ceil(-2/x)", "0", "-2")]
30+
[InlineData("-3 * x * floor(1/x)", "0", "-3")]
31+
[InlineData("x^2 * floor(1/x)", "0", "0")]
32+
[InlineData("(x - 1) * floor(1/(x - 1))", "1", "1")]
33+
[InlineData("x * floor(2/x) + 3", "0", "5")]
34+
[InlineData("floor(x) / x", "+oo", "1")]
35+
public void FromEachSideAndBoth(string input, string destination, string expected)
36+
{
37+
var expr = input.ToEntity();
38+
Assert.Equal(expected.ToEntity(), expr.Limit("x", destination, ApproachFrom.Left).InnerSimplified);
39+
Assert.Equal(expected.ToEntity(), expr.Limit("x", destination, ApproachFrom.Right).InnerSimplified);
40+
Assert.Equal(expected.ToEntity(), expr.Limit("x", destination).InnerSimplified);
41+
}
42+
43+
// Where f g has no limit, neither has f floor(g): the sides diverge in different directions, so there is none.
44+
[Theory]
45+
[InlineData("x * floor(1/x^2)")]
46+
[InlineData("sqrt(abs(x)) * floor(1/x)")]
47+
public void SidesThatDivergeApart(string input)
48+
{
49+
var expr = input.ToEntity();
50+
Assert.Equal(Entity.Number.Real.NegativeInfinity, expr.Limit("x", 0, ApproachFrom.Left));
51+
Assert.Equal(Entity.Number.Real.PositiveInfinity, expr.Limit("x", 0, ApproachFrom.Right));
52+
Assert.Equal(MathS.NaN, expr.Limit("x", 0));
53+
}
54+
55+
// x floor(sin(1/x)/x) is sin(1/x) up to a term that vanishes, and has no limit. The rule takes only a value from
56+
// the limit of f g, so it leaves this unevaluated rather than claiming anything.
57+
[Fact]
58+
public void AnOscillatingProductIsNotAnswered()
59+
=> Assert.IsType<Entity.Limitf>("x * floor(sin(1/x)/x)".ToEntity().Limit("x", 0));
60+
}
61+
}

‎Sources/Tests/UnitTests/Calculus/AnUndecidedSideLeavesTheLimitUnevaluatedTest.cs‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ namespace AngouriMath.Tests.Calculus
2020
public sealed class AnUndecidedSideLeavesTheLimitUnevaluatedTest
2121
{
2222
[Theory]
23-
[InlineData("x * floor(2/x)")]
24-
[InlineData("floor(1/x) * sin(x)")]
25-
[InlineData("x^2 * floor(1/x^2)")]
26-
[InlineData("x * ceil(1/x)")]
23+
// 1/2 from each side. The four this was written for, x floor(2/x) among them, are answered now, and are pinned
24+
// in AStepOfAnUnboundedArgumentTimesAVanishingFactorTest.
25+
[InlineData("floor(1/x) / floor(2/x)")]
2726
// A side that stops at 0 / 0, or at c / 0, of an expression real beside the point is undecided too:
2827
// erf(abs(x)) / x^4 is +oo from each side, 1 / log(x^2, cos(x)) is +oo, abs(x)^erf(x) is 1.
2928
[InlineData("erf(abs(x)) / x^4")]

0 commit comments

Comments
 (0)