Skip to content

Commit 9f4b3a6

Browse files
Take agreeing sides for the two-sided limit where the expression is real on both (#2336)
Under the complex codomain, the default, two one-sided limits that agree were not taken for the two-sided one: x^x has a limit from the left only through its complex values, and no two-sided limit over the reals. (x^2)^x is real on both sides of 0 and tends to 1 from each, and its two-sided limit was NaN, the claim that there is none. They are now taken for it where the expression is real on both sides, decided structurally: every power to an exponent that is not whole, and every logarithm, has a base positive on both sides by SignNear. x^x is still NaN at 0. | | 2.6.0 and master | now | |---|---|---| | (x^2)^x at 0 | NaN | 1 | | (x*x)^(x - 1) at 0 | NaN | +oo | limitcheck, 600 expressions at each of seeds 1, 7 and 11: the findings are master's but for the (x*x)^(x - 1) row at seed 11, which is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0a58c74 commit 9f4b3a6

3 files changed

Lines changed: 91 additions & 2 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,19 @@ Two-sided, each side is now taken with its own value, and `floor(x)^x` at 0 is 1
309309
| `"floor(x)^tanh(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` |
310310
| `"floor(x)^x".ToEntity().Limit("x", 0)` | unevaluated | `NaN`, the sides differ |
311311

312+
### A two-sided limit of an expression real on both sides is where its sides agree
313+
314+
**Silent: a two-sided limit that was `NaN` although both sides agree has their value, where the expression is real on
315+
both sides.** Under the complex codomain, the default, two one-sided limits that agree were not taken to be the
316+
two-sided limit: `x^x` has a limit from the left only through its complex values, and it has no two-sided limit over the
317+
reals. Now they are taken to be where every power to an exponent that is not whole, and every logarithm, has a base
318+
positive on both sides. `x^x` is still `NaN` at 0.
319+
320+
| Input | Was (2.6.0) | Now |
321+
|---|---|---|
322+
| `"(x^2)^x".ToEntity().Limit("x", 0)` | `NaN` | `1` |
323+
| `"(x*x)^(x - 1)".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
324+
312325
### A limit of a logarithm that is not decided is left unevaluated
313326

314327
**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: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ node is Floorf or Ceilf or Roundf or Signumf
150150
/// </remarks>
151151
private static Entity? WhereBothSidesAgree(Entity expr, Variable x, Entity dest)
152152
{
153-
if (MathS.Settings.Codomain.Value is not AngouriMath.Core.Domain.Real
154-
|| bothSidesDepth >= MaxBothSidesDepth)
153+
if (bothSidesDepth >= MaxBothSidesDepth
154+
|| MathS.Settings.Codomain.Value is not AngouriMath.Core.Domain.Real && !IsRealOnBothSides(expr, x, dest))
155155
return null;
156156
bothSidesDepth++;
157157
try
@@ -168,6 +168,45 @@ node is Floorf or Ceilf or Roundf or Signumf
168168
finally { bothSidesDepth--; }
169169
}
170170

171+
/// <summary>
172+
/// Whether <paramref name="expr"/> is real on both sides of a real <paramref name="dest"/>,
173+
/// close enough to it, decided structurally: every power to an exponent that is not whole,
174+
/// and every logarithm, has a base and an argument positive on both sides, by
175+
/// <see cref="SignNear"/>. Where it is, its one-sided limits are limits of real values from
176+
/// either side, and their agreeing is the two-sided limit under any codomain. <c>x^x</c>
177+
/// is not, its base being negative on the left, and stays without one; <c>(x^2)^x</c> is,
178+
/// and was NaN at 0 where each side is 1. Anything else unlisted is not real, which costs
179+
/// coverage and never correctness.
180+
/// </summary>
181+
private static bool IsRealOnBothSides(Entity expr, Variable x, Entity dest)
182+
{
183+
if (dest.Evaled is not Real { IsFinite: true })
184+
return false;
185+
return RealThere(expr);
186+
bool RealThere(Entity node)
187+
{
188+
if (!node.ContainsNode(x))
189+
return node.Evaled is Real { IsFinite: true };
190+
return node switch
191+
{
192+
Variable variable => variable == x,
193+
Sumf(var augend, var addend) => RealThere(augend) && RealThere(addend),
194+
Minusf(var minuend, var subtrahend) => RealThere(minuend) && RealThere(subtrahend),
195+
Mulf(var multiplier, var multiplicand) => RealThere(multiplier) && RealThere(multiplicand),
196+
Divf(var dividend, var divisor) => RealThere(dividend) && RealThere(divisor),
197+
Powf(var @base, Integer) => RealThere(@base),
198+
Powf(var @base, var exponent) => RealThere(@base) && RealThere(exponent) && PositiveOnBothSides(@base),
199+
Logf(var @base, var antilogarithm) => RealThere(@base) && RealThere(antilogarithm)
200+
&& PositiveOnBothSides(@base) && PositiveOnBothSides(antilogarithm),
201+
_ => false
202+
};
203+
}
204+
bool PositiveOnBothSides(Entity node)
205+
=> !node.ContainsNode(x)
206+
? node.Evaled is Real { IsPositive: true }
207+
: SignNear(node, x, dest, ApproachFrom.Left) is 1 && SignNear(node, x, dest, ApproachFrom.Right) is 1;
208+
}
209+
171210
/// <summary>
172211
/// How deep <see cref="WhereBothSidesAgree"/> may nest. Each one-sided limit it asks
173212
/// for may itself reach a two-sided limit of a subexpression, so without a bound the
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// Under the complex codomain two agreeing one-sided limits were not taken for the two-sided one, since <c>x^x</c> has a
16+
/// limit from the left only through its complex values. <c>(x^2)^x</c> is real on both sides of 0 and tends to 1 from
17+
/// each, and its two-sided limit was NaN, the claim that there is none. No issue was filed; found by work/limitcheck at
18+
/// seed 11.
19+
/// </summary>
20+
[Trait("Area", "Calculus")]
21+
public sealed class ALimitRealOnBothSidesTest
22+
{
23+
[Theory]
24+
[InlineData("(x^2)^x", "1")]
25+
[InlineData("(x*x)^(x - 1)", "+oo")]
26+
[InlineData("(x^4)^(x - 1)", "+oo")]
27+
public void IsWhereItsSidesAgree(string expression, string limit)
28+
=> Assert.Equal(limit.ToEntity().Evaled, expression.ToEntity().Limit("x", 0).Evaled);
29+
30+
// Negative on the left, where the values are complex: still no two-sided limit.
31+
[Theory]
32+
[InlineData("x^x")]
33+
[InlineData("(x/pi)^x")]
34+
public void IsNotWhereOneSideIsComplex(string expression)
35+
=> Assert.Equal(MathS.NaN, expression.ToEntity().Limit("x", 0).Evaled);
36+
}
37+
}

0 commit comments

Comments
 (0)