Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,22 @@ since past about 10^100 an integer times a radical is folded into a rounded deci
| `32768 * 2^(-29/2)` | `32768 * 2 ^ (-29/2)` | `sqrt(2)` |
| `2 / (2^(-29/2) * 32768)` | `1/16384 / 2 ^ (-29/2)` | `sqrt(2)` |

### A two-sided limit is NaN only where its sides say so

**Not silent: a wrong answer becomes an unevaluated limit.** A two-sided limit came back `NaN`, the claim that it does
not exist, from an indeterminate form the machinery could not read. The difference quotient of `abs` at a symbolic
point is `sgn(a)` for every real `a` other than 0, and each side alone was left unevaluated, while the two-sided limit
was `NaN`. A side that stops at `0 / 0` where the expression has a value beside the point, its other symbols read as
a number, is now undecided for an expression that may take complex values too, as it already was for a real one, and
the limit is left unevaluated. `(x - x) / (x - x)`, which has no value anywhere, is still `NaN`
([#2667](https://github.com/asc-community/AngouriMath/issues/2667)).

| `.Limit(x, ...)` | Was (2.10.0) | Now |
|---|---|---|
| `(abs(a + x) - abs(a)) / x` at 0 | `NaN` | `limit((abs(a + x) - abs(a)) / x, x, 0)` |
| `(abs(x) - abs(a)) / (x - a)` at `a` | `NaN` | unevaluated |
| `abs(x) / x`, `1 / x`, `sin(1 / x)` at 0 | `NaN` | unchanged |

### A real integral through ln of a negative number is real

**Not silent: a divergent integral had an imaginary part, and a finite one was written through `ln` of a negative
Expand Down
3 changes: 3 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
[AngouriMath/Functions/TreeAnalyzer/PerfectPower.cs]
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

[Tests/UnitTests/Calculus/AnUndecidedSideIsNotADisagreementTest.cs]
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

[Tests/UnitTests/Common/TheWholePartOfALargeRationalPowerTest.cs]
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,15 @@ node is Floorf or Ceilf or Roundf or Signumf
// is the limit: floor(1/x) / floor(2/x) at 0 is 1/2 from each side, the one-sided
// paths do not decide it, and a NaN here would say there is no limit.
aSideIsUndecided = false;
if (bothSidesDepth >= MaxBothSidesDepth
|| MathS.Settings.Codomain.Value is not AngouriMath.Core.Domain.Real && !IsRealOnBothSides(expr, x, dest))
if (bothSidesDepth >= MaxBothSidesDepth)
return null;
// Agreement is promoted to the limit only for real-valued functions. Off them the sides
// are still asked, but only for whether one of them is undecided: a NaN is no answer where
// a side has none yet. (abs(a + x) - abs(a)) / x at 0, with a free to be complex, stops at
// 0 / 0 from each side, has a value beside the point, and was NaN where it is sgn(a) for
// every real a other than 0.
// https://github.com/asc-community/AngouriMath/issues/2667
var promoting = MathS.Settings.Codomain.Value is AngouriMath.Core.Domain.Real || IsRealOnBothSides(expr, x, dest);
bothSidesDepth++;
try
{
Expand All @@ -215,7 +221,7 @@ node is Floorf or Ceilf or Roundf or Signumf
aSideIsUndecided = true;
return null;
}
return fromLeft == fromRight || ExpressionNumerical.AreEqual(fromLeft, fromRight)
return promoting && (fromLeft == fromRight || ExpressionNumerical.AreEqual(fromLeft, fromRight))
? fromLeft : null;
}
finally { bothSidesDepth--; }
Expand All @@ -230,13 +236,45 @@ node is Floorf or Ceilf or Roundf or Signumf
// value beside the point: 0 / 0 for (x - x) / (x - x), which has no value anywhere, and
// ln(-2) / 0 for ln(-2) / ln(x) at 1, whose values there are not real and whose sides
// are infinities in different directions.
// Off the real functions a form with an infinity in it is undecided as it is on them, and of the forms of
// finite parts only 0 / 0 itself, where the expression has a value beside the point with its other symbols
// read as a number: (x - x) / (x - x) has none, and its NaN stands.
Entity? Decided(Entity? limit, ApproachFrom side)
=> limit is { } && IsAnIndeterminateForm(limit)
&& (limit.Nodes.Any(static node => node is Real { IsFinite: false })
|| IsRealBeside(expr, x, dest, side))
|| (promoting
? IsRealBeside(expr, x, dest, side)
: limit is Divf(var above, var below) && above.Evaled is Complex { IsZero: true } && below.Evaled is Complex { IsZero: true }
&& HasAValueBeside(expr, x, dest, side)))
? null : limit;
}

/// <summary>
/// Whether <paramref name="expr"/> has a finite value, real or not, at two points on <paramref name="side"/>
/// of a finite <paramref name="dest"/>, 10^-6 and 10^-9 away, with every other symbol read as one generic
/// number. A witness only: a side it finds a value on is left undecided, never answered.
/// https://github.com/asc-community/AngouriMath/issues/2667
/// </summary>
private static bool HasAValueBeside(Entity expr, Variable x, Entity dest, ApproachFrom side)
{
if (side is ApproachFrom.BothSides || dest.Evaled is Number { IsFinite: false })
return false;
var generic = Rational.Create(3719, 10000);
var reading = expr;
var at = dest;
foreach (var other in expr.Vars.Concat(dest.Vars).Where(v => v != x).Distinct().ToList())
{
reading = reading.Substitute(other, generic);
at = at.Substitute(other, generic);
}
if (at.Evaled is not Complex { IsFinite: true } point)
return false;
var sign = side is ApproachFrom.Left ? -1 : 1;
return ValueAt(Rational.Create(sign, 1_000_000)) && ValueAt(Rational.Create(sign, 1_000_000_000));
bool ValueAt(Rational offset)
=> reading.Substitute(x, point + offset).Evaled is Complex { IsFinite: true, IsNaN: false };
}

/// <summary>
/// Whether <paramref name="expr"/> has a finite real value at two points on
/// <paramref name="side"/> of a finite real <paramref name="dest"/>, 10^-6 and 10^-9 away.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
// Website: https://am.angouri.org.
//

using System.Linq;
using AngouriMath.Extensions;
using Xunit;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// A two-sided limit is NaN only where its sides disagree or one of them has no limit. Where a
/// side is undecided, the NaN of an indeterminate form the machinery could not read is not that
/// claim, and the limit is left unevaluated: the difference quotient of abs at a symbolic point
/// is sgn(a) for every real a other than 0, and was answered NaN.
/// https://github.com/asc-community/AngouriMath/issues/2667
/// </summary>
[Trait("Area", "Calculus")]
public sealed class AnUndecidedSideIsNotADisagreementTest
{
[Theory]
[InlineData("(abs(a + x) - abs(a)) / x", "0")]
[InlineData("(abs(x) - abs(a)) / (x - a)", "a")]
[InlineData("(abs(a + x) - abs(a)) * x^(-1)", "0")]
public void IsLeftUnevaluated(string expression, string destination)
{
// Through every entry point: the two-sided overload, the one naming the side, and Simplify of the node.
foreach (var limit in new[] {
expression.ToEntity().Limit("x", destination.ToEntity()),
expression.ToEntity().Limit("x", destination.ToEntity(), AngouriMath.Core.ApproachFrom.BothSides),
MathS.Limit(expression.ToEntity(), "x", destination.ToEntity()).Simplify() })
{
Assert.NotEqual(MathS.NaN, limit.Evaled);
Assert.Contains(limit.Nodes, node => node is Entity.Limitf);
}
}

/// <summary>Where the sides do disagree, or one has no limit, NaN stands.</summary>
[Theory]
[InlineData("abs(x) / x", "0")]
[InlineData("1 / x", "0")]
[InlineData("sin(1 / x)", "0")]
[InlineData("e^(1 / x)", "0")]
[InlineData("tan(x)", "pi / 2")]
[InlineData("1 / (x - a)", "a")]
[InlineData("abs(x + a) / x", "0")]
public void ADisagreementIsStillNaN(string expression, string destination)
=> Assert.Equal(MathS.NaN, expression.ToEntity().Limit("x", destination.ToEntity()).Evaled);

/// <summary>And a limit that exists is answered as before.</summary>
[Fact]
public void ANumericPointIsAnswered()
=> Assert.Equal(Entity.Number.Integer.One, "(abs(2 + x) - 2) / x".ToEntity().Limit("x", 0).Evaled);
}
}
Loading