Skip to content

Commit 7907c4c

Browse files
Put a step function at its one-sided limit before a one-sided limit is taken (#2332)
floor, ceil, round and sgn take only whole values, so one that has a limit from a side equals that limit on an interval on that side. Each is now put in as its one-sided limit wherever that limit is a whole number, before a one-sided limit is taken, and in the two-sided path each side gets its own. floor(x) is 0 on (0, 1), so floor(x)^x there is 0 to a positive power. It was read as the form 0^0 through e^(x ln(floor(x))), and answered 1: | | 2.6.0 | master | now | |---|---|---|---| | floor(x)^x at 0+ | 1 | 1 | 0 | | floor(x)^tanh(x) at 0+ | unevaluated | 1 | 0 | | floor(x)^x at 0 | unevaluated | 1 | NaN, 1 from the left and 0 from the right | limitcheck, 600 expressions at each of seeds 1, 7 and 11: the findings are master's at 1 and 7, and at 11 the floor(x)^tanh(x) row is gone. 11 more limits are answered across seeds 1 and 7, each agreeing with the values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9e687f0 commit 7907c4c

3 files changed

Lines changed: 83 additions & 2 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,20 @@ powers of `x` found it.
282282
|---|---|---|
283283
| `"(3x - 4) * sqrt(x) + 3 + 3x - 4x^2 = 0".Solve("x")` | four roots, one of them 1.3233…, which is not a root | the other three |
284284

285+
### A step function that has a limit from one side is that limit on that side
286+
287+
**Silent: a limit of a power whose base is a `floor`, `ceil`, `round` or `sgn` that is 0 on the side approached is 0,
288+
where it was 1.** These functions take only whole values, so where one has a limit from a side it equals that limit on
289+
a whole interval on that side, and is now put in as it before the limit is taken. `floor(x)` is 0 on `(0, 1)`, so
290+
`floor(x)^x` there is 0 to a positive power; it was read as the form `0^0` through `e^(x ln(floor(x)))` and answered 1.
291+
Two-sided, each side is now taken with its own value, and `floor(x)^x` at 0 is 1 from the left and 0 from the right.
292+
293+
| Input | Was (2.6.0) | Now |
294+
|---|---|---|
295+
| `"floor(x)^x".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `1` | `0` |
296+
| `"floor(x)^tanh(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` |
297+
| `"floor(x)^x".ToEntity().Limit("x", 0)` | unevaluated | `NaN`, the sides differ |
298+
285299
### A limit of a logarithm that is not decided is left unevaluated
286300

287301
**Not silent: what overflowed the stack now returns.** A limit of a logarithm whose argument has no limit, as

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ internal static partial class LimitFunctional
101101
return null;
102102
}
103103

104+
/// <summary>
105+
/// <paramref name="expr"/> with each <c>floor</c>, <c>ceil</c>, <c>round</c> and <c>sgn</c> of
106+
/// <paramref name="x"/> whose limit from <paramref name="side"/> is a whole number put
107+
/// in as that number. Each takes only whole values, so where it has a limit it takes
108+
/// that value on the whole of some interval on that side: the substitution is exact
109+
/// there, and not an approximation. Without it, <c>floor(x) ^ x</c> at 0+ was read as
110+
/// the form 0^0 and answered 1 through <c>e ^ (x ln(floor(x)))</c>, where on (0, 1) it
111+
/// is 0 to a positive power, which is 0.
112+
/// </summary>
113+
private static Entity WithStepsAtTheirLimits(Entity expr, Variable x, Entity dest, ApproachFrom side)
114+
{
115+
if (!expr.Nodes.Any(node => node is Floorf or Ceilf or Roundf or Signumf))
116+
return expr;
117+
return expr.Replace(node =>
118+
node is Floorf or Ceilf or Roundf or Signumf
119+
&& node.ContainsNode(x)
120+
&& node.ComputeLimitDivideEtImpera(x, dest, side) is { } limit
121+
&& limit.Evaled is Integer whole
122+
? whole
123+
: node);
124+
}
125+
104126
/// <summary>
105127
/// The limit where the two one-sided limits agree, asked of each side through the
106128
/// whole of <see cref="ComputeLimit"/>, or <see langword="null"/> where either side
@@ -278,6 +300,7 @@ internal static T WithinABudget<T>(int limits, System.Func<T> compute)
278300

279301
if (side is ApproachFrom.Left or ApproachFrom.Right)
280302
{
303+
expr = WithStepsAtTheirLimits(expr, x, dest, side);
281304
var oneSided = expr.ComputeLimitDivideEtImpera(x, dest, side);
282305
if (oneSided is { } found && (acceptNaN || found.Evaled != MathS.NaN))
283306
return oneSided;
@@ -377,8 +400,10 @@ internal static T WithinABudget<T>(int limits, System.Func<T> compute)
377400
// https://github.com/asc-community/AngouriMath/issues/1186
378401
return atInfinity;
379402
}
380-
else if (expr.ComputeLimitDivideEtImpera(x, dest, ApproachFrom.Left) is { } fromLeft
381-
&& expr.ComputeLimitDivideEtImpera(x, dest, ApproachFrom.Right) is { } fromRight)
403+
// Each side with its own steps put in: floor(x) ^ x at 0 is 1 from the left and 0
404+
// from the right, and read bare both sides were 1.
405+
else if (WithStepsAtTheirLimits(expr, x, dest, ApproachFrom.Left).ComputeLimitDivideEtImpera(x, dest, ApproachFrom.Left) is { } fromLeft
406+
&& WithStepsAtTheirLimits(expr, x, dest, ApproachFrom.Right).ComputeLimitDivideEtImpera(x, dest, ApproachFrom.Right) is { } fromRight)
382407
{
383408
if (fromLeft == fromRight && (acceptNaN || fromLeft.Evaled != MathS.NaN))
384409
return fromLeft;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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;
9+
using AngouriMath.Core;
10+
using AngouriMath.Extensions;
11+
using Xunit;
12+
13+
namespace AngouriMath.Tests.Calculus
14+
{
15+
/// <summary>
16+
/// <c>floor</c>, <c>ceil</c>, <c>round</c> and <c>sgn</c> take only whole values, so one that has a limit from a side is
17+
/// equal to it on an interval on that side. <c>floor(x) ^ x</c> at 0+ is 0 to a positive power on <c>(0, 1)</c>, and was
18+
/// read as the form <c>0^0</c> and answered 1. No issue was filed; found by work/limitcheck at seed 11.
19+
/// </summary>
20+
[Trait("Area", "Calculus")]
21+
public sealed class AStepFunctionNearItsLimitTest
22+
{
23+
[Theory]
24+
[InlineData("floor(x)^x", "0")]
25+
[InlineData("floor(x)^tanh(x)", "0")]
26+
[InlineData("floor(x)^sin(x)", "0")]
27+
[InlineData("ceil(x)^x", "1")]
28+
[InlineData("x^sgn(x)", "0")]
29+
public void FromTheRight(string expression, string limit)
30+
=> Assert.Equal(limit.ToEntity(), expression.ToEntity().Limit("x", 0, ApproachFrom.Right).Simplify());
31+
32+
// floor(x) is -1 on (-1, 0), and (-1)^x tends to 1.
33+
[Fact]
34+
public void FromTheLeft()
35+
=> Assert.Equal(1, "floor(x)^x".ToEntity().Limit("x", 0, ApproachFrom.Left).Simplify());
36+
37+
// 1 from the left and 0 from the right: no limit.
38+
[Fact]
39+
public void BothSidesDiffer()
40+
=> Assert.Equal(MathS.NaN, "floor(x)^x".ToEntity().Limit("x", 0).Simplify());
41+
}
42+
}

0 commit comments

Comments
 (0)