@@ -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
0 commit comments