From a80c1a30e59c03b7e1cfd727b6bbcfcbe2a85cf9 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Tue, 22 Sep 2026 07:24:55 +0000 Subject: [PATCH] A root of a rational function of coth(x) is integrated by the hyperbolic half-angle `coth(x)^3/sqrt(a + b coth(x)^2)` was a search past the budget: the rational-in-tanh route refused the half-angle -- u = tanh(x) for an integrand written in e^(2x) -- whenever a root was in the integrand, because for sqrt(sinh(x)) the half makes a root of 2u/(1 - u^2) where u = e^x answers with a root of a polynomial. With a root it now takes the half where every radicand comes out over a power of u: a + b coth(x)^2 is (b + a u^2)/u^2, whose root is sqrt(b + a u^2)/|u|, and |u|^k for the bare square is sgn(u) u^k at every depth -- the one half-odd power the perfect-square rule takes beyond the square root. The halved argument is simplified (InnerSimplified left `2x/2` in the answer). Family 6 of the Rubi suite: 335 -> 344 of 417, 0 wrong, timeouts 42 -> 34; family 7 215/270 and the 1774-problem suite 1707 unchanged. Suite 12600 passed; allocation gate passed on all 19 gated benchmarks. Part of #718. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 17 ++++++++++ .../Integration/IndefiniteIntegralSolver.cs | 32 ++++++++++++++----- .../ExponentialSubstitutionIntegralTest.cs | 16 ++++++++++ 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 06f69477f..581be2d37 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -1013,6 +1013,23 @@ and in no release -- and is `sgn(u) u/(u^2 - 1)` | `"1/sqrt(1+csch(x)^2)".Integrate("x")` | left unevaluated | `-sgn(tanh(x)) ln(tanh(x)^2 - 1)/2`, in exponentials | | `"x^4/sech(2*ln(c*x))^(1/2)".Integrate("x")` | left unevaluated | `sgn(x) (1 + c^4 x^4)^(3/2)/(6 sqrt(2) c^5)` up to the form, `provided c^4 > 0` | +### A root of a rational function of `coth(x)` is integrated by the hyperbolic half-angle + +`coth(x)^3/sqrt(a + b coth(x)^2)` was a search past the budget. The rational-in-`tanh` route +declined the half-angle -- `u = tanh(x)` for an integrand written in `e^(2x)` -- whenever a +root was in the integrand, because for `sqrt(sinh(x))` the half makes a root of `2u/(1 - u^2)` +where `u = e^x` answers with a root of a polynomial. With a root it now takes the half where +every radicand comes out over a power of `u`: `a + b coth(x)^2` is `(b + a u^2)/u^2`, whose root +is `sqrt(b + a u^2)/|u|`, and `|u|^k` for the bare square is `sgn(u) u^k` at every depth. Rubi's +6.4.7, nine rows ([#718](https://github.com/asc-community/AngouriMath/issues/718)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"coth(x)^3/sqrt(a+b*coth(x)^2)".Integrate("x")` | left unevaluated | the antiderivative, in `sgn(tanh(x))` and `sqrt(b + a tanh(x)^2)`, by cases on `a + b` | +| `"coth(x)*(a+b*coth(x)^2)^(3/2)".Integrate("x")` | left unevaluated | the antiderivative | +| `"coth(x)/(a+b*coth(x)^2)^(3/2)".Integrate("x")` | left unevaluated | the antiderivative | +| `"(a+b*coth(x)^2)^(3/2)*tanh(x)^2".Integrate("x")` | left unevaluated | the antiderivative | + ### `binomial(n, k)` is a function **Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 8d0862832..45d9b3973 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -10145,14 +10145,19 @@ Entity Without(Entity side) /// written for it is a factor the rest of the search has to carry: /// tanh(x)/(a + b tanh(x)^2)^(5/2) under u = e^(2x) holds /// (1 + 2u + u^2)^(5/2), and with that rewritten the search ran past its budget - /// where it had answered in twenty seconds. + /// where it had answered in twenty seconds. The one half-odd power taken beyond the + /// square root is of the bare square, (x^2)^(3/2), which is sgn(x) x^3: + /// it is what a root of (b + a u^2)/u^2 -- a + b coth(x)^2 under + /// u = tanh(x) -- leaves once the quotient is written apart, and nothing else + /// reads it. /// internal static Entity? SolveByTakingARootOfAPerfectSquare(Entity expr, Entity.Variable x, bool integrateByParts) { // Asked of every integrand at every depth, so the radicand is read as a polynomial // only where it is small enough to be a written square: x^2, or a x^2 + b x + c. static bool MayBeARootOfASquare(Entity node, Entity.Variable x) - => node is Powf(var radicand, Number.Rational r) && r.ERational.Equals(ERational.Create(1, 2)) + => node is Powf(var radicand, Number.Rational r) && r.ERational.Denominator.Equals(EInteger.FromInt32(2)) + && (r.ERational.Equals(ERational.Create(1, 2)) || radicand is Powf(var @base, var degree) && @base == x && degree == Number.Integer.Create(2)) && radicand.ContainsNode(x) && radicand.Complexity <= 12 && radicand.Nodes.Count(inner => inner == x) <= 2; if (!expr.Nodes.Any(node => MayBeARootOfASquare(node, x))) @@ -11447,11 +11452,14 @@ private static bool IsTheZeroPolynomial(Entity expr) // for the lower degrees and the answer in the argument as written. The half only // where every exponent is written with an even factor in front -- `coth(c + d x)` // is written with `e^(2 (c + d x))`, and `tanh(c + d x)` is its argument's - // tangent, not the half-angle of `2(c + d x)` -- and not with a root in the - // integrand, which the half turns into a root of a quotient: `sinh(x)` writes - // `e^x`, and its `u = tanh(x/2)` answers were what `u = e^x` answered in less, - // Timofeev's `e^x/sqrt(e^(2x) + a^2)` among them, a root of a polynomial there. - var halfIsTheArgument = !HasARadicalOf(expr, x) && exponentials.Keys.All(node => node is Powf(_, var exponent) && WrittenWithAnEvenFactor(exponent)); + // tangent, not the half-angle of `2(c + d x)` -- and with a root in the + // integrand only where the half leaves every radicand over a power of u + // (checked once the integrand is in u, below): `sinh(x)` writes `e^x`, the half + // makes a root of `2u/(1 - u^2)` of `sqrt(sinh(x))`, and its `u = tanh(x/2)` + // answers were what `u = e^x` answered in less, Timofeev's + // `e^x/sqrt(e^(2x) + a^2)` among them, a root of a polynomial there. + var hasARadical = HasARadicalOf(expr, x); + var halfIsTheArgument = exponentials.Keys.All(node => node is Powf(_, var exponent) && WrittenWithAnEvenFactor(exponent)); foreach (var halved in new[] { false, true }) { if (halved && !halfIsTheArgument) @@ -11464,11 +11472,19 @@ private static bool IsTheZeroPolynomial(Entity expr) return null; if (InTanh(inV) is not var (inT, parity) || parity != 0) continue; + // With a root, the half only where every radicand comes out over a power + // of t -- `a + b coth(x)^2` is `(b + a t^2)/t^2`, Rubi's cotangent and + // cosecant families -- and not over `1 - t^2`, which is where the half + // makes a root of a quotient out of `sinh(x)`, and `u = e^x` answers in less. + if (halved && hasARadical && !inT.Nodes.All(node => node is not Powf(var radicand, Number.Rational root) || root is Number.Integer || !radicand.ContainsNode(t) + || Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(radicand)).Item2 is var below + && Mulf.LinearChildren(below).All(factor => !factor.ContainsNode(t) || factor == t || factor is Powf(var b, Number.Integer) && b == t))) + continue; var rationalInT = WithThePowersOfOnePlusMinusTCollected(inT / (1 - MathS.Sqr(t))); if (rationalInT.ContainsNode(square) || rationalInT.ContainsNode(vt) || rationalInT.Nodes.Any(node => node == MathS.NaN) || Integration.ComputeAsAQuestionOfItsOwn(rationalInT, t, integrateByParts) is not { } evenResult) return null; - var evenAnswer = evenResult.Substitute(t, MathS.Hyperbolic.Tanh(halved ? (y / 2).InnerSimplified : y)); + var evenAnswer = evenResult.Substitute(t, MathS.Hyperbolic.Tanh(halved ? Functions.PartialFractions.Bare((y / 2).Simplify()) : y)); if (evenAnswer.Nodes.Any(node => node == MathS.NaN)) return null; // dx is dy/d, and twice that in the half of y. diff --git a/Sources/Tests/UnitTests/Calculus/ExponentialSubstitutionIntegralTest.cs b/Sources/Tests/UnitTests/Calculus/ExponentialSubstitutionIntegralTest.cs index 7594c7b80..4a90ac908 100644 --- a/Sources/Tests/UnitTests/Calculus/ExponentialSubstitutionIntegralTest.cs +++ b/Sources/Tests/UnitTests/Calculus/ExponentialSubstitutionIntegralTest.cs @@ -452,6 +452,22 @@ public void ANegativePowerOfTheQuadraticIsWrittenBelowTheBar(string integrand) public void ARationalFunctionOfTheHyperbolicTangent(string integrand) => DifferentiatesBackWithParametersPinned(integrand, new[] { -0.5, 0.23, 0.61, 1.05, 1.7 }); + /// + /// And with a root: coth(x)^3/sqrt(a + b coth(x)^2) is u = tanh(x)'s + /// half-angle of e^(2x), and every radicand comes out over a power of u + /// -- a + b coth(x)^2 is (b + a u^2)/u^2 -- which is the shape the half + /// is admitted with a root for; the roots of 1 - u^2 that the half makes of + /// sinh(x) stay with u = e^x. Rubi's 6.4.7, each a search past the budget + /// before. https://github.com/asc-community/AngouriMath/issues/718 + /// + [Theory] + [InlineData("coth(x)^3/sqrt(a + b*coth(x)^2)")] + [InlineData("coth(x)*(a + b*coth(x)^2)^(3/2)")] + [InlineData("coth(x)/(a + b*coth(x)^2)^(3/2)")] + [InlineData("coth(2*x + 1)^3/sqrt(a + b*coth(2*x + 1)^2)")] + public void ARootOfARationalFunctionOfTheHyperbolicCotangent(string integrand) + => DifferentiatesBackWithParametersPinned(integrand, new[] { -0.5, 0.23, 0.61, 1.05, 1.7 }); + /// /// A cubed symbolic quadratic beside a quadratic with real roots was integrated to a /// wrong answer -- the Hermite ansatz's logarithmic part, with coefficients that are