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
19 changes: 19 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@ root near 23.
| `"x^7 - 5x^6 + 1 = 0".Solve("x")` | six roots, none of them near 5 | seven roots |
| `"x^4 - 3*x^(5/2) + 2 = 0".Solve("x")` | `{ 1, 4.8870…^(2/5) }` | four roots: `1`, `1.3734…^2`, and two off the real line |

### An infinity in an expression is not read as a coefficient

**Wrong answer: `log(x, 0)` at 0 from the right is `+oo`, where it was `0`.** `log(x, 0)` is `ln(0) / ln(x)`, and
`ln(0)` is `-oo`, so between 0 and 1 it is `+oo` at every point. An infinity that does not depend on the variable
was read as a coefficient. `-oo / x` was taken for a constant over a line, and so tended to 0 at +oo. And a
product's or quotient's other part had its limit put in place of it, so `+oo * x` at 0 became `+oo * 0`, which
folds to 0. Such an infinity now keeps its sign times the other part's sign on the way in. Where that sign changes
at the destination, nothing is claimed one-sidedly, and two-sided the limit is NaN as the sides disagree. A
coefficient that evaluates to NaN is not read as one either, and the limit is left unevaluated rather than NaN.

| Input | Was (2.6.0) | Now |
|---|---|---|
| `"log(x, 0)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `0` | `+oo` |
| `"log(x, 0)".ToEntity().Limit("x", "+oo")` | `0` | `-oo` |
| `"-oo / x".ToEntity().Limit("x", "+oo")` | `0` | `-oo` |
| `"+oo * x".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `0` | `+oo` |
| `"arctan(log(sinh(x), 0))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `limitright(arctan(log((e ^ x - e ^ (-x)) / 2, 0)), x, 0)` | `pi / 2` |
| `"1 ^ log(1 - x, x - x)".ToEntity().Limit("x", "1/2")` | `NaN` | `limit(1 ^ log(1 - x, x - x), x, 1/2)` |

### A trigonometric function reads the value its argument tends to

**A one-sided limit at a finite point of a trigonometric function is answered, where it was left unevaluated.** The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ partial record Mulf
return lim;
else
{
var multiplierLimit = Multiplier.ComputeLimitDivideEtImpera(x, dist, side);
var multiplicandLimit = Multiplicand.ComputeLimitDivideEtImpera(x, dist, side);
if (AnInfinityTimesASign(Multiplier, Multiplicand, multiplicandLimit, dividing: false, x, dist, side) is { } byMultiplier)
return byMultiplier;
if (AnInfinityTimesASign(Multiplicand, Multiplier, multiplierLimit, dividing: false, x, dist, side) is { } byMultiplicand)
return byMultiplicand;
var (mp, md) =
(Multiplier.ComputeLimitDivideEtImpera(x, dist, side), Multiplicand.ComputeLimitDivideEtImpera(x, dist, side)) switch
(multiplierLimit, multiplicandLimit) switch
{
({ } lim1, { } lim2) when IsDeterminate(New(lim1, lim2), x) => (lim1, lim2),
({ IsFinite: true } lim1, { IsFinite: true } lim2) => (lim1, lim2),
Expand Down Expand Up @@ -105,6 +111,8 @@ partial record Divf

var dividendLimit = Dividend.ComputeLimitDivideEtImpera(x, dist, side);
var divisorLimit = Divisor.ComputeLimitDivideEtImpera(x, dist, side);
if (AnInfinityTimesASign(Dividend, Divisor, divisorLimit, dividing: true, x, dist, side) is { } byDividend)
return byDividend;
var (dividend, divisor) =
(dividendLimit, divisorLimit) switch
{
Expand Down Expand Up @@ -154,6 +162,41 @@ partial record Divf
}
}

/// <summary>
/// The limit of an infinity that does not depend on <paramref name="x"/> times, or over,
/// <paramref name="other"/>: that infinity, with the sign of <paramref name="other"/> on the
/// way in, wherever the sign does not change there; otherwise <see langword="null"/>.
/// </summary>
/// <remarks>
/// An infinity is not a coefficient. Taken as one, the descent put the other part's limit in
/// its place, and +oo * x at 0 from the right became +oo * 0, which folds to 0, while -oo / x
/// at +oo became -oo / +oo and was answered 0 as well. At every point on the way in, though,
/// +oo * x is +oo and -oo / x is -oo. This is how ln(0) / ln(x), the logarithm of 0 to the
/// base x, was answered 0 at 0 from the right, where it is +oo all the way in.
/// Only where the product or quotient of the two limits leaves the answer open: the
/// other part tends to 0, or, for a quotient, to an infinity. Elsewhere the descent
/// below already answers it.
/// </remarks>
private static Entity? AnInfinityTimesASign(Entity constant, Entity other, Entity? otherLimit, bool dividing,
Variable x, Entity dist, ApproachFrom side)
{
if (constant.ContainsNode(x) || constant.Evaled is not Real { IsFinite: false, IsNaN: false } infinity)
return null;
if (otherLimit?.Evaled is not Real { IsNaN: false } limit)
return null;
if (!limit.IsZero && (!dividing || limit.IsFinite))
return null;
var sign = limit.IsZero
? ComputeLimit(MathS.Signum(other), x, dist, side)?.Evaled
: limit.IsNegative ? Integer.MinusOne : Integer.One;
return sign switch
{
Integer one when one == 1 => infinity,
Integer minusOne when minusOne == -1 => infinity.IsNegative ? Real.PositiveInfinity : Real.NegativeInfinity,
_ => null,
};
}

/// <summary>Whether two parts' limits make a quotient 0/0 or oo/oo.</summary>
private static bool IsAnIndeterminateQuotient(Entity dividend, Entity divisor)
=> (dividend.Evaled, divisor.Evaled) switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ internal static class LimitSolvers
foreach (var monomial in monomials)
{
var simplified = monomial.Value.InnerSimplified;
// An infinity is not a coefficient: -oo / x is -oo at every x on the way to +oo,
// and read as a constant over a line it was answered 0. The descent's
// AnInfinityTimesASign is what answers it. Nor is a NaN: 1 ^ log(1 - x, x - x) is 1
// at every point near 1/2, and a coefficient evaluated to NaN answered NaN.
if (simplified.Evaled is Number { IsFinite: false })
return null;
if (simplified != Integer.Zero)
{
filteredDictionary.Add(monomial.Key, simplified);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// 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 AngouriMath.Core;
using Xunit;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// An infinity that does not depend on the variable was taken for a coefficient. <c>log(x, 0)</c>, which is
/// <c>ln(0) / ln(x)</c>, is +oo at every point between 0 and 1, since <c>ln(0)</c> is -oo, and its limit at 0
/// from the right was 0; so was <c>-oo / x</c> at +oo and <c>+oo * x</c> at 0 from the right, where each is an
/// infinity all the way in. The polynomial readers read <c>-oo / x</c> as a constant over a line, and the
/// descent put the other part's limit in the infinity's place, folding <c>+oo * 0</c> to 0. The same on 2.6.0.
/// Found by limitcheck at <c>DEPTH=3</c>, <c>SEED=55</c> and <c>SEED=57</c>; no issue was filed.
/// </summary>
[Trait("Area", "Calculus")]
public sealed class AnInfinityIsNotACoefficientTest
{
[Theory]
[InlineData("log(x, 0)", "0", ApproachFrom.Right, "+oo")]
[InlineData("log(x, 0)", "+oo", ApproachFrom.BothSides, "-oo")]
[InlineData("log(x, 0)", "1", ApproachFrom.Left, "+oo")]
[InlineData("log(x, 0)", "1", ApproachFrom.Right, "-oo")]
[InlineData("-oo / ln(x)", "0", ApproachFrom.Right, "+oo")]
[InlineData("-oo / x", "+oo", ApproachFrom.BothSides, "-oo")]
[InlineData("+oo / x", "-oo", ApproachFrom.BothSides, "-oo")]
[InlineData("+oo * x", "0", ApproachFrom.Right, "+oo")]
[InlineData("+oo * x", "0", ApproachFrom.Left, "-oo")]
[InlineData("arctan(log(sinh(x), 0))", "0", ApproachFrom.Right, "pi/2")]
public void IsTheInfinityWithTheOtherPartsSign(string input, string destination, ApproachFrom side, string expected)
=> Assert.Equal(MathS.FromString(expected).Simplify(),
MathS.FromString(input).Limit("x", destination, side).Simplify());

// The two sides disagree, so there is no two-sided limit; and a finite part over or times an infinity is
// read as before.
[Fact]
public void LeavesEverythingElseAsItWas()
{
Assert.Equal(MathS.NaN, MathS.FromString("+oo * x").Limit("x", 0));
Assert.Equal(MathS.FromString("0"), MathS.FromString("5 / x").Limit("x", "+oo"));
Assert.Equal(MathS.FromString("+oo"), MathS.FromString("+oo * x").Limit("x", "+oo"));
}

// The values are 1 near 1/2, and +oo near 0 from the right; a coefficient evaluated to NaN answered NaN for
// both. Neither is answered yet, and a declined limit keeps its node.
[Theory]
[InlineData("1 ^ log(1 - x, x - x)", "1/2", ApproachFrom.BothSides)]
[InlineData("sqrt(x) / x ^ pi + x ^ x", "0", ApproachFrom.Right)]
public void ANaNCoefficientIsNotAnAnswer(string input, string destination, ApproachFrom side)
=> Assert.IsType<Entity.Limitf>(MathS.FromString(input).Limit("x", destination, side));
}
}
Loading