Skip to content

Commit 5df9686

Browse files
Ask the side a complex argument of a step arrives from (#2355)
The limit of a floor or a ceil read its argument as real along the path. 4^((-1)^x) at 1 from the right tends to 1/4 from below the real line, where every floor is -i, and the limit was the floor of 1/4, 0; ceil from the left was 1 where it is 1 + i. 2.6.0 answers the same. Where the limit is real and the argument is not real just off the destination, at an exact point on each side approached, the side its imaginary part arrives from decides the imaginary step, and where that is not decided the limit is declined. TreeAnalyzer's realness does not list x^x, and asked first it declined floor(x^x) at 1, 1/2 and 2; the point sample sends a limit only to the question or to declining, never to an answer. For 4^((-1)^x) the side is not decided, so the left limit, which was right, is declined with the right one. limitcheck at DEPTH=3, SEED=18 loses its two wrong limits and no other answer; on SEED=16 the declined limits are master's exactly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0116c08 commit 5df9686

3 files changed

Lines changed: 108 additions & 7 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,20 @@ powers of `x` found it.
307307
|---|---|---|
308308
| `"(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 |
309309

310+
### A floor or a ceil of a complex argument near a real limit is not the step of the limit
311+
312+
**Silent: a different answer.** The limit of a floor or a ceil read its argument as real along the path. `4^((-1)^x)`
313+
at 1 from the right tends to 1/4 from below the real line, where every floor is `-i`, and the limit was the floor of 1/4,
314+
`0`. An argument that is complex just off the destination now has its imaginary part's side asked, and where that is
315+
not decided the limit is left unevaluated. Here it is not decided, so the side whose answer was right, the left, is left
316+
unevaluated too. An argument real near the destination is read as before.
317+
318+
| Input | Was (2.6.0) | Now |
319+
|---|---|---|
320+
| `limitright(floor(4^((-1)^x)), x, 1)` | `0` | unevaluated |
321+
| `limitleft(ceil(4^((-1)^x)), x, 1)` | `1` | unevaluated |
322+
| `limitleft(floor(4^((-1)^x)), x, 1)` | `0` | unevaluated |
323+
310324
### A step function that has a limit from one side is that limit on that side
311325

312326
**Silent: a limit of a power whose base is a `floor`, `ceil`, `round` or `sgn` that is 0 on the side approached is 0,

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

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -498,20 +498,66 @@ partial record Absf
498498
// genuinely complex limit has an imaginary part that can arrive at an integer from
499499
// one side or the other.
500500
//
501-
// Like the Absf and Signumf overrides above, this reads the argument as real-valued
502-
// along the path. An argument that is complex near the destination and real at it
503-
// can still be answered here when it should not be; that is the assumption those
504-
// two already make, and narrowing it wants a way to decide realness that this
505-
// library does not have yet -- https://github.com/asc-community/AngouriMath/issues/721.
501+
// The Absf and Signumf overrides above read the argument as real-valued along the path.
502+
// This one asks: an argument that is complex near the destination and real at it is
503+
// read below by the side its imaginary part arrives from.
506504
if (value is not Complex { RealPart: var real, ImaginaryPart: var imaginary })
507505
return null;
506+
// A real limit of an argument that is not real near the destination has an imaginary
507+
// part tending to 0, which is a jump of its own: floor(4^((-1)^x)) at 1 from the right
508+
// tends to 1/4 from below the real line, where every value's floor is -i, and the
509+
// floor of the limit, 0, was the answer. Where the argument is real near the
510+
// destination -- every argument this read as real before, sqrt(x) at 4 among them --
511+
// nothing is added; where it is not, the side the imaginary part arrives from decides
512+
// the step, and where that is not decided the limit is declined.
513+
Entity imaginaryStep = Integer.Zero;
514+
if (value is Real)
515+
{
516+
if (ImaginaryStep() is not { } step)
517+
return null;
518+
imaginaryStep = step;
519+
}
520+
Entity WithTheImaginaryStep(Entity realAnswer)
521+
=> imaginaryStep is Integer { IsZero: true } ? realAnswer : realAnswer + imaginaryStep * MathS.i;
508522
if (SitsOnAJump(real))
509523
return value is Integer jump && SignNear(argument - jump, x, dist, side) is { } arrivesFrom
510-
? atAJump(jump, arrivesFrom)
524+
? WithTheImaginaryStep(atAJump(jump, arrivesFrom))
511525
: null;
512526
if (value is not Real && SitsOnAJump(imaginary))
513527
return null;
514-
return rebuild(limit);
528+
return WithTheImaginaryStep(rebuild(limit));
529+
530+
// Real near the destination where it is real at a point just off it on each side
531+
// approached: realness is not decided for every shape -- x^x is outside what
532+
// TreeAnalyzer lists -- and a sample only ever sends the limit to the question of the
533+
// imaginary part's side, or to declining, never to an answer of its own.
534+
Entity? ImaginaryStep()
535+
{
536+
if (Functions.TreeAnalyzer.IsRealValued(argument, x) || IsRealJustOff())
537+
return Integer.Zero;
538+
return SignNear(MathS.Im(argument), x, dist, side) is { } arrivesFrom && arrivesFrom != 0
539+
? atAJump(Integer.Zero, arrivesFrom)
540+
: null;
541+
}
542+
543+
bool IsRealJustOff()
544+
{
545+
var offsets = side switch
546+
{
547+
ApproachFrom.Left => new[] { -1 },
548+
ApproachFrom.Right => new[] { 1 },
549+
_ => new[] { -1, 1 },
550+
};
551+
foreach (var offset in offsets)
552+
{
553+
Entity at = dist == Real.PositiveInfinity ? Integer.Create(1000000)
554+
: dist == Real.NegativeInfinity ? Integer.Create(-1000000)
555+
: dist + Rational.Create(offset, 1000000);
556+
if (argument.Substitute(x, at).Evaled is not Real)
557+
return false;
558+
}
559+
return true;
560+
}
515561

516562
static bool SitsOnAJump(Real part) =>
517563
part is Integer || part.EDecimal.CompareTo(part.EDecimal.Floor()) == 0;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
using static AngouriMath.Entity;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// The limit of a floor or a ceil read its argument as real along the path. <c>4^((-1)^x)</c> at 1 from the right
16+
/// tends to 1/4 from below the real line, so that every floor near it is <c>-i</c>, and the limit was the floor of
17+
/// 1/4, 0. An argument that is complex just off the destination now has its imaginary part's side asked, and where
18+
/// that is not decided the limit is declined. An argument real there is read as before. Found by limitcheck at
19+
/// <c>DEPTH=3</c>; no issue was filed.
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class AStepOfAComplexArgumentNearARealLimitTest
23+
{
24+
[Theory]
25+
[InlineData("floor(4^((-1)^x))", "1", ApproachFrom.Right)]
26+
[InlineData("floor(4^((-1)^x))", "-1", ApproachFrom.Right)]
27+
[InlineData("ceil(4^((-1)^x))", "1", ApproachFrom.Left)]
28+
public void IsNotTheStepOfTheLimit(string input, string destination, ApproachFrom side)
29+
=> Assert.IsType<Limitf>(MathS.FromString(input).Limit("x", destination, side));
30+
31+
[Theory]
32+
[InlineData("floor(sqrt(x))", "4", ApproachFrom.Left, "1")]
33+
[InlineData("floor(sqrt(x))", "4", ApproachFrom.Right, "2")]
34+
[InlineData("floor(x^x)", "2", ApproachFrom.Left, "3")]
35+
[InlineData("floor(x^x)", "1", ApproachFrom.Left, "0")]
36+
[InlineData("floor(ln(x))", "1", ApproachFrom.Left, "-1")]
37+
[InlineData("ceil(x^(1/3))", "1", ApproachFrom.Right, "2")]
38+
public void ARealArgumentIsReadAsBefore(string input, string destination, ApproachFrom side, string expected)
39+
=> Assert.Equal(MathS.FromString(expected), MathS.FromString(input).Limit("x", destination, side));
40+
}
41+
}

0 commit comments

Comments
 (0)