diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 1532701e2..c2319c90e 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -1068,6 +1068,27 @@ in front -- the identity `sqrt(a + a sin(y))` already had. Exact for any `a`, th | `"cosh(x)/sqrt(a-a*cosh(x))".Integrate("x")` | left unevaluated | the antiderivative, with `sgn(sinh(x/2))` in front | | `"(A+B*cosh(x))/(a-a*cosh(x))^(5/2)".Integrate("x")` | left unevaluated | the antiderivative, with `sgn(sinh(x/2))` in front | +### A rational function of `e^y` with a symbolic denominator is integrated by the hyperbolic half angle + +`csch(x)^2/(a + b sinh(x))^2` was a search past eighty seconds: under `u = e^x` its denominator +is a symbolic quartic nothing factors. Under `u = tanh(x/2)` -- the hyperbolic half angle, which +the route for rational functions of the hyperbolic tangent took only where every exponential was +written with an even factor -- it is a rational function whose written factors the symbolic +partial fractions answer. It is taken now for a root-free integrand of a plain `e^y` as well, +where the denominator's shape depends on a symbol: read as a polynomial in `v = e^y`, a +coefficient that is not a number times the first, and two distinct factors of `v` below the bar. +Both conditions are measured: `tanh(x)^6/(a + a sech(x))`, whose denominator is `a` times one +the rational integrator factors over the rationals, answers a page shorter under `u = e^x`, and +`e^asinh(a + b x)/x^4` leaves `e^u(e^u + e^-u)/(e^u - e^-u - 2a)^4`, a single symbolic quadratic +to the fourth whose roots the quadratic formula gives, in a second there against thirty here. +Rubi's 6.1.5 and 6.6.3 ([#718](https://github.com/asc-community/AngouriMath/issues/718)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"csch(x)^2/(a+b*sinh(x))^2".Integrate("x")` | left unevaluated | the antiderivative, by cases on `a` and `b` | +| `"tanh(x)^4/(a+b*csch(x))".Integrate("x")` | left unevaluated | the antiderivative | +| `"csch(x)^2/(a+b*csch(x))".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 2ade68b60..a803e88b2 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -11460,6 +11460,12 @@ private static bool IsTheZeroPolynomial(Entity expr) // `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)); + // And the half of a plain `e^y`, at the top only: the integrand asked about is + // the one whose shape was read, where one below it is what another rule made. + if (!halfIsTheArgument && !hasARadical && ASymbolStandsBelowTheBar()) + { + halfIsTheArgument = true; + } foreach (var halved in new[] { false, true }) { if (halved && !halfIsTheArgument) @@ -11484,7 +11490,8 @@ private static bool IsTheZeroPolynomial(Entity expr) 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 ? Functions.PartialFractions.Bare((y / 2).Simplify()) : y)); + // tanh(y/2) spelled with e^y, which is what the integrand was written with. + var evenAnswer = evenResult.Substitute(t, halved ? (MathS.Pow(MathS.e, y) - 1) / (MathS.Pow(MathS.e, y) + 1) : MathS.Hyperbolic.Tanh(y)); if (evenAnswer.Nodes.Any(node => node == MathS.NaN)) return null; // dx is dy/d, and twice that in the half of y. @@ -11499,6 +11506,48 @@ private static bool IsTheZeroPolynomial(Entity expr) } return null; + // A symbol below the bar that the content does not account for: the half of a + // plain `e^y` is worth taking for `csch(y)^2/(a + b sinh(y))^2`, whose + // denominator under `u = e^y` is a symbolic quadratic nothing factors, and not + // for `tanh(y)^6/(a + a sech(y))`, whose denominator is `a` times one the + // rational integrator factors over the rationals -- there the exponential + // substitution answers in a page less. Read as a polynomial in `v`, with every + // coefficient divided by the first: a symbol surviving that is one the + // denominator's shape depends on. + bool ASymbolStandsBelowTheBar() + { + var inVOfExpr = expr.Replace(node => exponentials.TryGetValue(node, out var k) ? MathS.Pow(vt, Number.Integer.Create(k)) : node); + var denominator = Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(inVOfExpr)).Item2; + if (!denominator.Vars.Any(symbol => symbol != x && symbol != vt)) + return false; + if (!TreeAnalyzer.TryGetPolynomial(denominator.Expand().InnerSimplified, vt, out var monomials) || monomials.Count == 0) + return true; + var first = monomials.OrderBy(pair => pair.Key).First().Value; + var symbolic = false; + foreach (var pair in monomials) + { + var ratio = (pair.Value / first).InnerSimplified; + if (ratio.Vars.Any(symbol => symbol != x && symbol != vt) && Functions.PartialFractions.Bare(ratio.Simplify()).Vars.Any(symbol => symbol != x && symbol != vt)) + symbolic = true; + } + if (!symbolic) + return false; + // And two distinct factors of `v` below the bar, at least: one alone -- + // `(v^2 - 2 a v - 1)^4`, what the inverse hyperbolic substitution leaves of + // `e^asinh(a + b x)/x^4` -- has roots the quadratic formula gives, and + // `u = e^y` answers it in a second where the half takes thirty; the pockets + // this is for have the written `sinh` beside the symbolic factor. + var bases = new List(); + foreach (var factor in Mulf.LinearChildren(denominator)) + { + var factorBase = factor is Powf(var inner, Number.Integer) ? inner : factor; + // `v` itself is no factor: it is where an odd power of it was gathered. + if (factorBase.ContainsNode(vt) && factorBase != vt && !bases.Any(known => known == factorBase)) + bases.Add(factorBase); + } + return bases.Count >= 2; + } + // The quotient with every factor that is a multiple of 1 + t or 1 - t, on either // side of the bar and to any whole power, gathered into one power of each: the // powers of s and the homogenisations each bring their own, `sech(x)^4` arrives diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs index 2504fd4b1..a9a63adbc 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs @@ -601,11 +601,15 @@ private static Entity Normalized(Entity expr, Entity.Variable x) => // quadratic squared here, and under `u = e^x` a palindromic quartic that took the // budget. Before the substitution search, which with a symbolic slope spends the // whole of it on `u = c + d x` and never comes back to the chain. - if ((answer = IndefiniteIntegralSolver.SolveARationalFunctionOfTheHyperbolicTangent(expr, x, integrateByParts)) is { }) return answer; // Bioche's first two rules for the hyperbolic functions, read back by their // exponential spellings: `sinh(x)^3/(a + b cosh(x)^2)` is `(u^2 - 1)/(a + b u^2)` // under u = cosh(x), where the substitution search spends the budget on u = e^x. + // Before the tangent, which takes the half of a plain `e^y` for a symbolic + // denominator and makes a polynomial of twice the degree of what this answers: + // `cosh(x)^7/(a + b cosh(x)^2)` and `sech(x)^3/(a + b sinh(x))^2` are a second here + // and past the budget there. if ((answer = IndefiniteIntegralSolver.SolveByBiochesOddHyperbolicSubstitution(expr, x, integrateByParts)) is { }) return answer; + if ((answer = IndefiniteIntegralSolver.SolveARationalFunctionOfTheHyperbolicTangent(expr, x, integrateByParts)) is { }) return answer; // A rational function of a sine or a cosine over a quadratic in it with a symbol // among the coefficients, split over the quadratic's two roots: under the // half-angle it is a quartic in t with a symbol in every coefficient. diff --git a/Sources/Tests/UnitTests/Calculus/ExponentialSubstitutionIntegralTest.cs b/Sources/Tests/UnitTests/Calculus/ExponentialSubstitutionIntegralTest.cs index 8b92c3944..398685a62 100644 --- a/Sources/Tests/UnitTests/Calculus/ExponentialSubstitutionIntegralTest.cs +++ b/Sources/Tests/UnitTests/Calculus/ExponentialSubstitutionIntegralTest.cs @@ -440,7 +440,10 @@ public void ANegativePowerOfTheQuadraticIsWrittenBelowTheBar(string integrand) /// 1/(a + b coth(c + d x)^2)^2 is u^4/((b + a u^2)^2 (1 - u^2)) there, /// where under u = e^x it was a symbolic palindromic quartic squared and a /// timeout. The argument may be any linear form, and the secant's odd exponential - /// cancels in an even integrand. + /// cancels in an even integrand. An integrand of a plain e^y that is not even + /// takes the half, u = tanh(y/2), where a symbol stands below the bar: + /// csch(x)^2/(a + b csch(x)) was declined, and csch(x)^2/(a + b sinh(x))^2 + /// a search past eighty seconds under u = e^x. /// [Theory] [InlineData("1/(a + b*coth(x)^2)^2")] @@ -449,6 +452,9 @@ public void ANegativePowerOfTheQuadraticIsWrittenBelowTheBar(string integrand) [InlineData("1/(a + b*coth(c + d*x)^2)^2")] [InlineData("sech(x)^4/(a + b*sech(x)^2)^2")] [InlineData("sech(c + d*x)^4/(a + b*sech(c + d*x)^2)^2")] + [InlineData("csch(x)^2/(a + b*csch(x))")] + [InlineData("1/(a + b*sinh(x))")] + [InlineData("sinh(x)/(a + b*cosh(x) + c*sinh(x))")] public void ARationalFunctionOfTheHyperbolicTangent(string integrand) => DifferentiatesBackWithParametersPinned(integrand, new[] { -0.5, 0.23, 0.61, 1.05, 1.7 });