Skip to content

Commit a78c1bd

Browse files
Integrate a power of a quotient of linears over a half-odd power of their product (#1960)
The parser folds e^(n acoth(a x)) into ((a x + 1)/(a x - 1))^(n/2), a power T^alpha of a quotient of linears T = (p + q x)/(r + s x). Over a half-odd power of a multiple Q of their product, with a power of x beside it, the antiderivative has Liouville's shape T^alpha P(x) Q^(1/2 - K). Since T'/T is D/((p + q x)(r + s x)), asking F' to be the integrand is a three-term recurrence for P's coefficients, solved from the bottom up. The last equation fixes p_0 and the one past it is checked: where it fails, the antiderivative is hypergeometric and the rule declines. Rubi's 7.4.2 e^(n acoth(a x))/(c - a^2 c x^2)^(3/2) to ^(9/2), and the same beside x, x^2 and x^3, were declined. Part of #233. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent d1d0296 commit a78c1bd

4 files changed

Lines changed: 186 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,21 @@ integrand is then `x^(2n + 1) (c + d x)^n (2 c + 3 d x)`, the derivative of `x^(
154154
| `"x^(2*n)*(c+d*x)^n*(2*c*x+3*d*x^2)".ToEntity().Integrate("x")` | `integral(...)` | 61 characters |
155155
| `"x^(n-1)*(c+d*x^2)^n*(c*x+3*d*x^3)".ToEntity().Integrate("x")` | `integral(...)` | 65 characters |
156156

157+
### A power of a quotient of linears over a half-odd power of their product is integrated
158+
159+
**Answers where there were none.** `e^(n acoth(a x))/(c - a^2 c x^2)^(3/2)` was declined, and so were its `^(5/2)` to
160+
`^(9/2)` and the same beside `x`, `x^2` and `x^3`, Rubi's 7.4.2. The parser folds `e^(n acoth(a x))` into
161+
`((a x + 1)/(a x - 1))^(n/2)`, a power `T^alpha` of a quotient of linears, and over a half-odd power of a multiple `Q` of
162+
their product the antiderivative is `T^alpha P(x) Q^(1/2 - K)` for a polynomial `P` whose coefficients a three-term
163+
recurrence gives; where the recurrence leaves an equation it cannot meet, the antiderivative is not of that shape and
164+
it is still declined ([#233](https://github.com/asc-community/AngouriMath/issues/233)).
165+
166+
| Input | Was (2.5.0) | Now |
167+
|---|---|---|
168+
| `"e^(n*acoth(a*x))/(c-a^2*c*x^2)^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | 140 characters |
169+
| `"e^(n*acoth(a*x))*x/(c-a^2*c*x^2)^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | 155 characters |
170+
| `"e^(n*acoth(a*x))*x^3/(c-a^2*c*x^2)^(5/2)".ToEntity().Integrate("x")` | `integral(...)` | 397 characters |
171+
157172
### A power of a quotient of linears beside whole powers of them is integrated under the quotient
158173

159174
**Answers where there were none.** `e^(n acoth(a x))/(c - a^2 c x^2)^2` was declined, and so were its `^3` and `^4`, Rubi's

‎Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,109 @@ private static bool IsADerivativeOfAFactorBelowTheBar(Entity expr, Entity.Variab
10021002
}
10031003
}
10041004

1005+
/// <summary>
1006+
/// <c>x^j T^alpha/Q^(K + 1/2)</c>, a power of a quotient of linears <c>T = (p + q x)/(r + s x)</c>
1007+
/// over a half-odd power of a multiple of their product, <c>Q = kappa (p + q x)(r + s x)</c>,
1008+
/// closed by Liouville's ansatz <c>F = T^alpha P(x) Q^(1/2 - K)</c>. With <c>D = q r - p s</c>,
1009+
/// <c>T'/T = D/((p + q x)(r + s x))</c>, so <c>F' = T^alpha Q^(-K - 1/2) (alpha kappa D P + Q P' - (K - 1/2) Q' P)</c>,
1010+
/// and asking the bracket to be <c>x^j</c> is, with <c>Q = A x^2 + B x + C</c>, the three-term
1011+
/// system <c>A (m - 2K) p_(m-1) + (alpha kappa D + B (m - K + 1/2)) p_m + C (m + 1) p_(m+1) = [m = j]</c>,
1012+
/// solved from <c>p_0</c> up, the last equation fixing <c>p_0</c> and the one past it checked.
1013+
/// <c>e^(n acoth(a x))</c> arrives folded as <c>((a x + 1)/(a x - 1))^(n/2)</c>: Rubi's 7.4.2
1014+
/// <c>e^(n acoth(a x))/(c - a^2 c x^2)^(3/2)</c> is <c>e^(n acoth(a x)) (a x - n)/(a c (1 - n^2) sqrt(c - a^2 c x^2))</c>.
1015+
/// https://github.com/asc-community/AngouriMath/issues/233
1016+
/// </summary>
1017+
/// <remarks>
1018+
/// The principal powers are differentiated as such wherever <c>T</c> and <c>Q</c> are not 0,
1019+
/// on a cut as off it, so the answer holds where the integrand is defined. Where the check
1020+
/// past the last equation fails, the antiderivative is not of this shape -- a hypergeometric
1021+
/// one -- and the rule declines. Only for a power of <c>T</c> that is not whole, and
1022+
/// <c>Q</c> without a root at 0, which the system divides by.
1023+
/// </remarks>
1024+
internal static Entity? SolveAPowerOfAQuotientOfLinearsOverAHalfOddPowerOfTheirProduct(Entity expr, Entity.Variable x)
1025+
{
1026+
Powf? power = null;
1027+
Entity constant = Number.Integer.One;
1028+
var j = 0;
1029+
Entity? quadratic = null;
1030+
ERational? quadraticPower = null;
1031+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr))
1032+
{
1033+
if (!factor.ContainsNode(x))
1034+
{
1035+
constant = underneath ? constant / factor : constant * factor;
1036+
continue;
1037+
}
1038+
if (!underneath && power is null && factor is Powf(Divf(var above, var below), var alpha)
1039+
&& !alpha.ContainsNode(x) && alpha.Evaled is not Number.Integer && above.ContainsNode(x) && below.ContainsNode(x))
1040+
{
1041+
power = (Powf)factor;
1042+
continue;
1043+
}
1044+
if (!underneath && APowerOfTheVariable(factor, x) is { } k && k > 0)
1045+
{
1046+
j += k;
1047+
continue;
1048+
}
1049+
if (quadratic is null && factor is Powf(var q, Number.Rational r) && r.ERational.Denominator.Equals(EInteger.FromInt32(2)))
1050+
{
1051+
quadratic = q;
1052+
quadraticPower = underneath ? r.ERational.Negate() : r.ERational;
1053+
continue;
1054+
}
1055+
return null;
1056+
}
1057+
if (power is null || quadratic is null || quadraticPower is null || j > 12 || power.Base is not Divf(var top, var bottom)
1058+
|| !TreeAnalyzer.TryGetPolyLinear(top, x, out var qs, out var ps) || TreeAnalyzer.IsZero(qs)
1059+
|| !TreeAnalyzer.TryGetPolyLinear(bottom, x, out var ss, out var rs) || TreeAnalyzer.IsZero(ss)
1060+
|| !TreeAnalyzer.TryGetPolyQuadratic(quadratic, x, out var a2, out var b2, out var c2) || TreeAnalyzer.IsZero(a2))
1061+
return null;
1062+
// Q a multiple of the linears' product, and its power -(K + 1/2).
1063+
var kappa = Functions.PartialFractions.Bare((a2 / (qs * ss)).Simplify());
1064+
if (!VanishesIdentically(b2 - kappa * (ps * ss + qs * rs)) || !VanishesIdentically(c2 - kappa * ps * rs) || VanishesIdentically(c2))
1065+
return null;
1066+
var half = quadraticPower.Negate().Subtract(ERational.FromInt32(1).Divide(ERational.FromInt32(2))).ToLowestTerms();
1067+
if (!half.Denominator.Equals(EInteger.One) || !half.Numerator.CanFitInInt32() || half.Numerator.Abs().CompareTo(EInteger.FromInt32(12)) > 0)
1068+
return null;
1069+
var bigK = half.Numerator.ToInt32Checked();
1070+
var d = System.Math.Max(2 * bigK - 1, j - 1);
1071+
if (d < 0 || d > 12)
1072+
return null;
1073+
var determinant = qs * rs - ps * ss;
1074+
var alphaKappaD = (power.Exponent * kappa * determinant).InnerSimplified;
1075+
Entity Beta(int m) => alphaKappaD + b2 * (Number.Integer.Create(m - bigK) + Number.Rational.Create(1, 2));
1076+
Entity Rhs(int m) => m == j ? Number.Integer.One : Number.Integer.Zero;
1077+
// p_m = u_m + v_m lambda, lambda = p_0.
1078+
var u = new Entity[d + 2];
1079+
var v = new Entity[d + 2];
1080+
(u[0], v[0]) = (Number.Integer.Zero, Number.Integer.One);
1081+
Entity Lower(Entity[] w, int m) => m - 1 < 0 ? Number.Integer.Zero : a2 * (m - 2 * bigK) * w[m - 1];
1082+
for (var m = 0; m < d; m++)
1083+
{
1084+
var divisor = c2 * (m + 1);
1085+
u[m + 1] = Functions.PartialFractions.Bare(((Rhs(m) - Lower(u, m) - Beta(m) * u[m]) / divisor).Simplify());
1086+
v[m + 1] = Functions.PartialFractions.Bare(((Number.Integer.Zero - Lower(v, m) - Beta(m) * v[m]) / divisor).Simplify());
1087+
}
1088+
// The degree-d equation, with p_(d+1) = 0, fixes lambda.
1089+
var constantPart = (Lower(u, d) + Beta(d) * u[d]).InnerSimplified;
1090+
var lambdaPart = (Lower(v, d) + Beta(d) * v[d]).InnerSimplified;
1091+
if (VanishesIdentically(lambdaPart))
1092+
return null;
1093+
var lambda = Functions.PartialFractions.Bare(((Rhs(d) - constantPart) / lambdaPart).Simplify());
1094+
var coefficients = Enumerable.Range(0, d + 1).Select(m => Functions.PartialFractions.Bare((u[m] + v[m] * lambda).Simplify())).ToArray();
1095+
// The one past it: A (d + 1 - 2K) p_d = [d + 1 = j].
1096+
if (!VanishesIdentically(a2 * (d + 1 - 2 * bigK) * coefficients[d] - Rhs(d + 1)))
1097+
return null;
1098+
Entity polynomial = Number.Integer.Zero;
1099+
for (var m = 0; m <= d; m++)
1100+
if (!VanishesIdentically(coefficients[m]))
1101+
polynomial += coefficients[m] * (m == 0 ? Number.Integer.One : m == 1 ? x : MathS.Pow(x, m));
1102+
if (polynomial == Number.Integer.Zero)
1103+
return null;
1104+
var raised = Number.Rational.Create(1 - 2 * bigK, 2);
1105+
return constant * power * polynomial * MathS.Pow(quadratic, raised);
1106+
}
1107+
10051108
/// <summary>
10061109
/// A quotient by the square of a base, by parts against the base's reciprocal, where the
10071110
/// base's derivative makes the rest exact: <c>N/(M v^2)</c> is <c>g v'/v^2</c> with

‎Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,8 @@ private static Entity WithItsPiecewiseSumsCombined(Entity expr)
791791
if ((answer = IndefiniteIntegralSolver.SolveByPartsAgainstALogarithmOfARadicalSum(expr, x)) is { }) return answer;
792792
// A function of tanh(L) or coth(L) alone that is not rational in it, under u = tanh(L).
793793
if ((answer = IndefiniteIntegralSolver.SolveAFunctionOfTheHyperbolicTangent(expr, x, integrateByParts)) is { }) return answer;
794+
// A power of a quotient of linears over a half-odd power of their product, by Liouville's ansatz.
795+
if ((answer = IndefiniteIntegralSolver.SolveAPowerOfAQuotientOfLinearsOverAHalfOddPowerOfTheirProduct(expr, x)) is { }) return answer;
794796
// A power of an exponential with a positive base is the exponential of the product,
795797
// exactly, and only that spelling is one the exponential rules read.
796798
if ((answer = IndefiniteIntegralSolver.SolveByFlatteningAPowerOfAnExponential(expr, x, integrateByParts)) is { }) return answer;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using System;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// <c>x^j e^(n acoth(a x))/(c - a^2 c x^2)^(K + 1/2)</c>, closed by Liouville's ansatz
16+
/// <c>e^(n acoth(a x)) P(x)/(c - a^2 c x^2)^(K - 1/2)</c>: the first is Rubi's
17+
/// <c>e^(n acoth(a x)) (a x - n)/(a c (1 - n^2) sqrt(c - a^2 c x^2))</c>. They were declined.
18+
/// Rubi's 7.4.2.
19+
/// <a href="https://github.com/asc-community/AngouriMath/issues/233">#233</a>
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class APowerOfAQuotientOfLinearsOverAHalfOddPowerOfTheirProductIntegralTest
23+
{
24+
[Fact]
25+
public void RubisAnswer()
26+
{
27+
var integral = "e^(n*acoth(a*x))/(c - a^2*c*x^2)^(3/2)".ToEntity().Integrate("x").Substitute("C", 0);
28+
var rubi = "e^(n*acoth(a*x))*(a*x - n)/(a*c*(1 - n^2)*sqrt(c - a^2*c*x^2))".ToEntity();
29+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("c", 0.7).Substitute("n", 0.4);
30+
foreach (var at in new[] { -2.9, -1.4, 1.3, 2.9 })
31+
{
32+
var difference = (Pinned(integral) - Pinned(rubi)).Substitute("x", at).EvalNumerical();
33+
Assert.True(Math.Abs((double)difference.RealPart) + Math.Abs((double)difference.ImaginaryPart) < 1e-9, $"{difference} at {at}");
34+
}
35+
}
36+
37+
[Theory]
38+
[InlineData("e^(n*acoth(a*x))/(c - a^2*c*x^2)^(5/2)")]
39+
[InlineData("e^(n*acoth(a*x))*x/(c - a^2*c*x^2)^(3/2)")]
40+
[InlineData("e^(n*acoth(a*x))*x^3/(c - a^2*c*x^2)^(5/2)")]
41+
[InlineData("e^(n*atanh(a*x))/(c - a^2*c*x^2)^(3/2)")]
42+
public void ByTheAnsatz(string integrand)
43+
{
44+
var integral = integrand.ToEntity().Integrate("x");
45+
var text = integral.Stringize();
46+
Assert.DoesNotContain("integral(", text);
47+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("c", 0.7).Substitute("n", 0.4);
48+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
49+
var original = Pinned(integrand.ToEntity());
50+
var compared = 0;
51+
// Inside and outside the roots at -1/1.3 and 1/1.3.
52+
foreach (var at in new[] { -2.9, -1.4, -0.4, 0.3, 0.6, 1.3, 2.9 })
53+
{
54+
var want = original.Substitute("x", at).EvalNumerical();
55+
var got = derivative.Substitute("x", at).EvalNumerical();
56+
if (want.IsNaN)
57+
continue;
58+
compared++;
59+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
60+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
61+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
62+
}
63+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)