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
14 changes: 14 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ real root sitting just past that zero was not answered. The bracket is halved do
| `"(x^2 - 3x - 3)^(1/3) + sqrt(3x - 4) = 3".ToEntity().Solve("x")` | `{ 1.3099 - 2.3063i, 1.3099 + 2.3063i }` | also `3.7961670056822383` |
| `"(x^2 - 3x - 3)^(1/3) + sqrt(3x - 4) = 3 provided x in RR".ToEntity().Solve("x")` | `{ }` | `{ 3.7961670056822383 }` |

### A derivatives' quotient that grew but has a value is read

**Silent: `ln(sin(x)) / ln(sinh(x))` from the right at 0 is 1, where 2.6.0 answered `NaN`, the claim that the limit
does not exist.** l'Hopital's rule bounds how much its derivatives' quotient may grow, so that it does not differentiate
without end, and the product rule doubles `cos(x) * sinh(x)`. A quotient past the bound is now taken where it has a
finite real value at a finite destination, and nothing in it jumps: it needs no more differentiating there.

| Input | Was (2.6.0) | Now |
|---|---|---|
| `"ln(sin(x)) / ln(sinh(x))".ToEntity().Limit("x", 0, ApproachFrom.Right)` | `NaN`, in 10 s | `1` |
| `"cos(x) * sinh(x) / sin(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `1` |
| `"cos(x) * (e^x - e^(-x)) / sin(x)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated | `2` |
| `"log(sinh(x), sin(x)) * cos(x - 2)".ToEntity().Limit("x", 0, ApproachFrom.Right)` | unevaluated, in 37 s | `cos(-2)` |

### A quotient of logarithms is differentiated only where both diverge

**Silent: a limit of a quotient of logarithms whose divisor tends to 0 is no longer answered by l'Hopital's rule, which
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,18 @@ internal static Entity AtALargeDecimal(Entity expr, Variable x)
private static bool AlreadyBeingDifferentiated(Entity quotient)
=> (lHopitalChain ??= new()).Contains(quotient);

/// <summary>
/// The value of <paramref name="expr"/> at a finite <paramref name="dest"/>, where it is a finite real number and
/// nothing in it jumps, which is its limit there; otherwise <see langword="null"/>.
/// </summary>
private static Entity? ItsValueAt(Entity expr, Variable x, Entity dest)
{
if (!dest.IsFinite || expr.Nodes.Any(static node => node is Floorf or Ceilf or Roundf or Signumf or Piecewise))
return null;
var there = expr.Substitute(x, dest);
return there.Evaled is Real { IsFinite: true, IsNaN: false } ? there.InnerSimplified : null;
}

/// <summary>
/// Whether differentiating both parts has left a quotient bigger than the one it came
/// from by more than a step on the way to an answer accounts for. Each step asks what
Expand Down Expand Up @@ -1590,8 +1602,15 @@ bool DoesNotSettle(Entity argument) => argument.ContainsNode(x)
// l'Hopital has nothing to say about a derivative it cannot take.
if (applied.Nodes.Any(node => node is Derivativef))
return null;
if (AlreadyBeingDifferentiated(applied) || GrewTooMuch(expr, applied))
if (AlreadyBeingDifferentiated(applied))
return null;
// The bound is on differentiating again, and a quotient that has a value at
// a finite destination needs no more of it: the product rule doubles
// cos(x) * (e^x - e^(-x)), and its derivatives' quotient, which is 2 at 0,
// was turned away, so cos(x) * sinh(x) / sin(x) from the right at 0 was
// left unevaluated, and ln(sin(x)) / ln(sinh(x)) with it.
if (GrewTooMuch(expr, applied))
return ItsValueAt(applied, x, dest);
lHopitalApplications++;
MultithreadingFunctional.ExitIfCancelled();
lHopitalChain!.Add(applied);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// 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>
/// l'Hopital's rule bounds how much its derivatives' quotient may grow, which is a bound on differentiating again, and
/// the product rule doubles <c>cos(x) * sinh(x)</c>. The quotient it turned away, <c>cos(x) * (e^x + e^(-x)) - sin(x)
/// * (e^x - e^(-x))</c> over 2, is 1 at 0 and needed no more of it: <c>cos(x) * sinh(x) / sin(x)</c> from the right at
/// 0 was left unevaluated, with <c>ln(sin(x)) / ln(sinh(x))</c>, and <c>(sinh(x) * (x + 2))^arcsin(2x)</c> took 5.7 s
/// to answer 1. Found by limitcheck at <c>DEPTH=3</c>, <c>SEED=31</c> and <c>SEED=33</c>; no issue was filed.
/// </summary>
[Trait("Area", "Calculus")]
public sealed class AGrownQuotientWithAValueIsReadTest
{
[Theory]
[InlineData("cos(x) * sinh(x) / sin(x)", "1")]
[InlineData("cos(x) * (e^x - e^(-x)) / sin(x)", "2")]
[InlineData("ln(sin(x)) / ln(sinh(x))", "1")]
[InlineData("log(sinh(x), sin(x)) * cos(x - 2)", "cos(2)")]
[InlineData("(sinh(x) * (x + 2))^arcsin(2x)", "1")]
public void IsTheLimitFromTheRight(string input, string expected)
{
var limit = MathS.FromString(input).Limit("x", 0, ApproachFrom.Right);
Assert.False(limit is Entity.Limitf, $"lim x->0+ {input} was left unevaluated");
var difference = (limit - MathS.FromString(expected)).EvalNumerical();
Assert.True(difference is Entity.Number.Complex value && Entity.Number.Complex.Abs(value) is Entity.Number.Real abs && abs < 1e-10,
$"lim x->0+ {input} = {limit}, which is not {expected}");
}
}
}
Loading