From 6db45b9a3bc26dd973f6d165dea463b9b20f89a5 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Wed, 4 Nov 2026 10:19:11 +0000 Subject: [PATCH] Read a derivatives' quotient that grew but has a value at the point l'Hopital's rule bounds how much its derivatives' quotient may grow, which is a bound on differentiating again, and the product rule doubles cos(x) * sinh(x). The quotient it turned away, cos(x)(e^x + e^(-x)) - sin(x)(e^x - e^(-x)) over 2, is 1 at 0 and needed no more differentiating: cos(x) * sinh(x) / sin(x) from the right at 0 was left unevaluated, and so was ln(sin(x)) / ln(sinh(x)), which 2.6.0 answered NaN. log(sinh(x), sin(x)) * cos(x - 2) took 30 s to decline, and (sinh(x)(x + 2))^arcsin(2x) 5.7 s to answer 1. A quotient past the bound is now taken where it has a finite real value at a finite destination and holds no step function, which is its limit there. limitcheck, DEPTH=3, seeds 14, 16, 19, 23, 26, 28, 29, 31, 33 against master 984671d35: compared 46666 -> 46672, "did not finish in 5 s" 5 -> 1, 595 s -> 550 s, the wrong values and the NaNs unchanged. Found at SEED=31 and SEED=33; no issue was filed. Co-Authored-By: Claude Opus 5.5 --- BREAKING-CHANGES.md | 14 +++++++ .../Continuous/Limits/Transformations.cs | 21 +++++++++- .../AGrownQuotientWithAValueIsReadTest.cs | 38 +++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 Sources/Tests/UnitTests/Calculus/AGrownQuotientWithAValueIsReadTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index a603de820..cbbfbde89 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -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 diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs index 5ffbe1905..6c14eba37 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Transformations.cs @@ -1287,6 +1287,18 @@ internal static Entity AtALargeDecimal(Entity expr, Variable x) private static bool AlreadyBeingDifferentiated(Entity quotient) => (lHopitalChain ??= new()).Contains(quotient); + /// + /// The value of at a finite , where it is a finite real number and + /// nothing in it jumps, which is its limit there; otherwise . + /// + 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; + } + /// /// 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 @@ -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); diff --git a/Sources/Tests/UnitTests/Calculus/AGrownQuotientWithAValueIsReadTest.cs b/Sources/Tests/UnitTests/Calculus/AGrownQuotientWithAValueIsReadTest.cs new file mode 100644 index 000000000..094d3f9d5 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/AGrownQuotientWithAValueIsReadTest.cs @@ -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 +{ + /// + /// l'Hopital's rule bounds how much its derivatives' quotient may grow, which is a bound on differentiating again, and + /// the product rule doubles cos(x) * sinh(x). The quotient it turned away, cos(x) * (e^x + e^(-x)) - sin(x) + /// * (e^x - e^(-x)) over 2, is 1 at 0 and needed no more of it: cos(x) * sinh(x) / sin(x) from the right at + /// 0 was left unevaluated, with ln(sin(x)) / ln(sinh(x)), and (sinh(x) * (x + 2))^arcsin(2x) took 5.7 s + /// to answer 1. Found by limitcheck at DEPTH=3, SEED=31 and SEED=33; no issue was filed. + /// + [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}"); + } + } +}