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
28 changes: 28 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,34 @@ arctangent of something real, and an arcsine and an arccosine inside (-1, 1). Wh
| `"sqrt(x^2)^(-3/2)".ToEntity().Limit("x", 0)` | `NaN` | `+oo` |
| `"sin(arcsin(x)) * (tan(-1) + 2/x)".ToEntity().Limit("x", 0)` | `NaN` | `2` |

### A quotient whose parts tend to a determinate form is answered in a limit

**Silent: a limit of a quotient whose numerator and denominator, each asked whole, tend to a form that is not
indeterminate is the quotient of the two limits, where it was left unevaluated.** The descent reads a part term by
term and can see an indeterminate form the whole does not have: `cot(x) - 1/x` at 0 is `+oo - +oo` to it and 0 asked
whole, so `(cot(x) - 1/x) / ln(x)`, 0 over `-oo`, was not answered. Most of the rows answered are on the left of 0,
where `x^x` and `ln(x)` are not real and each side's limit is the one of the complex values. Two-sided at a point it
answers only where the quotient is real on both sides, the convention `x^x` at 0 is held to. A two-sided limit whose
two sides are each answered and agree is that value, as `2 (x^x - 1)` at 0 already was, and two rows below move from
`NaN` to it, though one side is not real. One row was `NaN` on a side where the limit is 1.

| Input | Was (2.6.0) | Now |
|---|---|---|
| `"(cot(x) - 1/x) / ln(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` |
| `"(cot(x) - 1/x) / ln(x)".ToEntity().Limit("x", 0, ApproachFrom.Left)` | unevaluated | `0` |
| `"(1/sin(x) - 1/x) / ln(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `0` |
| `"ln(x) / (cot(x) - 1/x + 2)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `-oo` |
| `"(cot(x) - 1/x + 3) / (x + 2)".ToEntity().Limit("x", 0, ApproachFrom.BothSides)` | unevaluated | `3/2` |
| `"(1/sin(x) - 1/x) / cot(x)".ToEntity().Limit("x", 0, ApproachFrom.BothSides)` | unevaluated | `0` |
| `"tan(x)^2 / (x^x - 1)".ToEntity().Limit("x", 0, ApproachFrom.Left)` | unevaluated | `0` |
| `"sin(x/2) / log(x, pi)^(x - 1)".ToEntity().Limit("x", 1, ApproachFrom.Left)` | unevaluated | `sin(1/2)` |
| `"log(x, erf(x)) * (pi + 2 + x - 1)".ToEntity().Limit("x", "+oo")` | unevaluated | `0` |
| `"(-ln(x))^(abs(x) * x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `1` |
| `"arctan(x) / x^x + abs(cos(x))".ToEntity().Limit("x", 0, ApproachFrom.Left)` | `NaN` | `1` |
| `"log(1/(1 + pi), (-x)^tan(x))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | did not finish in 30 s | `0` |
| `"log(1/(1 + pi), (-x)^tan(x))".ToEntity().Limit("x", 0, ApproachFrom.BothSides)` | did not finish in 30 s | `0` |
| `"ln((-x)^tan(x))".ToEntity().Limit("x", 0, ApproachFrom.BothSides)` | `NaN` | `0` |

### A limit over a vanishing even power is not claimed not to exist

**Silent: `1/((x^2)^tanh(1))` at 0 is `+oo`, where it was `NaN`, the claim that the limit does not exist.** A base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2121,7 +2121,19 @@ bool VanishesIdentically(Entity polynomial)
if (expr is not Divf && AsQuotient(expr, x, dest, side) is { } quotient)
expr = quotient;
if (expr is Divf(var num, var den))
if (EvalAssumingContinuous(num.Limit(x, dest, side)) is var numLimit && EvalAssumingContinuous(den.Limit(x, dest, side)) is var denLimit)
if (num.Limit(x, dest, side) is var numExact && den.Limit(x, dest, side) is var denExact
&& EvalAssumingContinuous(numExact) is var numLimit && EvalAssumingContinuous(denExact) is var denLimit)
{
// The parts asked whole may make a form that is not indeterminate, where the descent
// read one of them part by part as one that is: cot(x) - 1/x at 0 is +oo - +oo to the
// descent and 0 asked whole, and (cot(x) - 1/x) / ln(x) at 0 from the right, 0 over
// -oo, was left unevaluated. The rule has nothing to differentiate there, and the
// quotient of the two limits is the limit. Two-sided at a point, only where the
// quotient is real on both sides: a side with no real values makes no two-sided
// limit, the convention x^x at 0 is held to, and sinh(-1) (x^x - 1) is not 0.
if ((side is not ApproachFrom.BothSides || !dest.IsFinite || IsRealOnBothSides(expr, x, dest))
&& QuotientOfDeterminateLimits(numExact, numLimit, denExact, denLimit) is { } determinate)
return determinate;
if (numLimit == 0 && denLimit == 0 ||
DivergesDecidedly(numLimit) && DivergesDecidedly(denLimit))
if (num is not Number && den is not Number)
Expand Down Expand Up @@ -2206,6 +2218,7 @@ bool VanishesIdentically(Entity polynomial)
}
finally { lHopitalChain.RemoveAt(lHopitalChain.Count - 1); }
}
}
return null;
// A limit times the value taken out: unchanged where nothing was, exact where the limit is
// finite, and the infinity itself where it is one, since a finite non-zero real times +oo
Expand All @@ -2216,6 +2229,23 @@ static Entity Times(Entity taken, Entity limit)
: (taken * limit).InnerSimplified;
}

/// <summary>
/// The limit of a quotient whose parts' limits make a determinate form, or <see langword="null"/> where they
/// do not: a finite limit over an infinite one is 0, an infinite one over a finite one other than 0 is the
/// infinity with the sign of the two, and a finite one over a finite one other than 0 is their quotient.
/// 0/0 and oo/oo are left to l'Hopital's rule, and anything over 0 to the side it is approached from.
/// </summary>
private static Entity? QuotientOfDeterminateLimits(Entity numExact, Entity numLimit, Entity denExact, Entity denLimit)
=> (numLimit, denLimit) switch
{
(Real { IsNaN: false, IsFinite: true }, Real { IsNaN: false, IsFinite: false }) => Integer.Zero,
(Real { IsNaN: false, IsFinite: false } infinity, Real { IsNaN: false, IsFinite: true, IsZero: false } divisor)
=> infinity.IsNegative == divisor.IsNegative ? Real.PositiveInfinity : Real.NegativeInfinity,
(Real { IsNaN: false, IsFinite: true }, Real { IsNaN: false, IsFinite: true, IsZero: false })
=> (numExact / denExact).InnerSimplified,
_ => null
};

/// <summary>
/// How deep one limit may go into rewriting itself. Each of the rewrites below hands
/// back another limit to take, and that one is entitled to be rewritten in turn, so
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// 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 AngouriMath.Extensions;
using Xunit;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// A quotient whose parts, each asked whole, tend to a form that is not indeterminate has the quotient of their
/// limits for its limit. cot(x) - 1/x at 0 is +oo - +oo read part by part and 0 asked whole, so
/// (cot(x) - 1/x) / ln(x) at 0, 0 over -oo, is 0; l'Hopital's rule was asked of it, had nothing to
/// differentiate, and it was left unevaluated. Found by limitcheck; no issue was filed.
/// </summary>
[Trait("Area", "Calculus")]
public sealed class ADeterminateQuotientIsAnsweredTest
{
[Theory]
[InlineData("(cot(x) - 1/x) / ln(x)", "0")]
[InlineData("(cot(x) - 1/x) / ln(x)^2", "0")]
[InlineData("(1/sin(x) - 1/x) / ln(x)", "0")]
[InlineData("(cot(x) - 1/x) / cot(x)", "0")]
[InlineData("ln(x) / (cot(x) - 1/x + 2)", "-oo")]
[InlineData("(cot(x) - 1/x + 3) / (x + 2)", "3/2")]
public void TheLimitFromTheRightIsAnswered(string input, string expected)
=> Assert.Equal(expected.ToEntity().Evaled, input.ToEntity().Limit("x", 0, ApproachFrom.Right).Evaled);

[Theory]
[InlineData("(cot(x) - 1/x) / ln(x)", "0")]
[InlineData("ln(x) / (cot(x) - 1/x + 2)", "-oo")]
public void TheLimitFromTheLeftIsAnswered(string input, string expected)
=> Assert.Equal(expected.ToEntity().Evaled, input.ToEntity().Limit("x", 0, ApproachFrom.Left).Evaled);

[Theory]
[InlineData("(cot(x) - 1/x + 3) / (x + 2)", "3/2")]
[InlineData("(1/sin(x) - 1/x) / cot(x)", "0")]
public void TheTwoSidedLimitIsAnswered(string input, string expected)
=> Assert.Equal(expected.ToEntity().Evaled, input.ToEntity().Limit("x", 0).Evaled);

/// <summary>
/// Two-sided, only where the quotient is real on both sides: a side with no real values makes no two-sided
/// limit, the convention x^x at 0 is held to. Each side of sinh(-1) (x^x - 1) is 0, and read as a quotient it
/// came to 0 two-sided.
/// </summary>
[Fact]
public void AQuotientNotRealOnASideHasNoTwoSidedLimit()
=> Assert.Equal(MathS.NaN, "sinh(-1) * (x^x - 1)".ToEntity().Limit("x", 0, ApproachFrom.BothSides).Evaled);
}
}
Loading