Skip to content

Commit 7280a44

Browse files
Integrate a power of a quotient of linears beside whole powers of them (#1953)
Under the Moebius substitution t = (p + q x)/(r + s x), p + q x = t (r + s x), r + s x = D/(q - s t) and dx = D/(q - s t)^2 dt with D = q r - p s, so t^alpha (p + q x)^j (r + s x)^k dx is D^(j + k + 1) t^(alpha + j) (q - s t)^(-(j + k + 2)) dt: a polynomial in t times a power of it wherever j + k <= -2. A whole power of a quadratic that is a multiple of the linears' product counts as a power of each. e^(n acoth(a x)) arrives folded as ((a x + 1)/(a x - 1))^(n/2), and over (c - a^2 c x^2)^m it is that. Only for a power of the quotient that is not whole: a whole one is a rational function, the partial fractions'. Rubi's 7.4.2: e^(n acoth(a x))/(c - a^2 c x^2)^m for m = 2, 3, 4, and three x^m rows of 7.3.6 and 7.4.2 whose radical substitution leaves such a power in the new variable, go from unevaluated or timed out to solved, 0 wrong. Families 0 and 1 and samples of 2-8 otherwise identical; gate and suite pass. 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 fa3eff9 commit 7280a44

4 files changed

Lines changed: 172 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ 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 beside whole powers of them is integrated under the quotient
158+
159+
**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
160+
7.4.2. The parser folds `e^(n acoth(a x))` into `((a x + 1)/(a x - 1))^(n/2)`, and under `t = (a x + 1)/(a x - 1)` -- the
161+
Moebius substitution, `p + q x = t (r + s x)` and `dx = (q r - p s)/(q - s t)^2 dt` -- a whole power of the quadratic
162+
is a polynomial in `t` times a power of it ([#233](https://github.com/asc-community/AngouriMath/issues/233)).
163+
164+
| Input | Was (2.5.0) | Now |
165+
|---|---|---|
166+
| `"e^(n*acoth(a*x))/(c-a^2*c*x^2)^2".ToEntity().Integrate("x")` | `integral(...)` | three powers of `(a x + 1)/(a x - 1)`, `n/2 - 1` to `n/2 + 1` |
167+
| `"e^(n*acoth(a*x))/(c-a^2*c*x^2)^4".ToEntity().Integrate("x")` | `integral(...)` | seven powers of it, `n/2 - 3` to `n/2 + 3` |
168+
157169
### The last digits of an evaluated sine, cosine, tangent, arcsine or arctangent
158170

159171
**Silent, and in the hundredth digit.** `EvalNumerical` at the default hundred digits gives the

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

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,109 @@ private static bool IsADerivativeOfAFactorBelowTheBar(Entity expr, Entity.Variab
709709
return (constant * (MathS.Pow(x, raised) * logarithm - 2 * slope * integral) / raised).InnerSimplified;
710710
}
711711

712+
/// <summary>
713+
/// A power of a quotient of two linears beside whole powers of the two, under the Moebius
714+
/// substitution <c>t = (p + q x)/(r + s x)</c>: then <c>p + q x = t (r + s x)</c>,
715+
/// <c>r + s x = D/(q - s t)</c> and <c>dx = D/(q - s t)^2 dt</c> with <c>D = q r - p s</c>, so
716+
/// <c>t^alpha (p + q x)^j (r + s x)^k dx</c> is <c>D^(j + k + 1) t^(alpha + j) (q - s t)^(-(j + k + 2)) dt</c>,
717+
/// a polynomial in <c>t</c> times a power of it wherever <c>j + k &lt;= -2</c>. A whole power of
718+
/// a quadratic that is a multiple of the two linears' product counts as a power of each.
719+
/// <c>e^(n acoth(a x))</c> arrives folded as <c>((a x + 1)/(a x - 1))^(n/2)</c>, and over
720+
/// <c>(c - a^2 c x^2)^m</c> it is Rubi's 7.4.2.
721+
/// https://github.com/asc-community/AngouriMath/issues/233
722+
/// </summary>
723+
/// <remarks>
724+
/// Only for a power <c>alpha</c> that is not whole: a whole one makes a rational function,
725+
/// which the partial fractions answer. <c>t^gamma</c> is differentiated to
726+
/// <c>gamma t^(gamma - 1) t'</c> on the principal branch wherever <c>t</c> is not 0, the
727+
/// negative half-line included, so the answer written back in the quotient holds where
728+
/// the integrand is defined. A half-odd power of the quadratic is left alone: it is not
729+
/// the product of the linears' powers on every side of their roots.
730+
/// </remarks>
731+
internal static Entity? SolveByTheMoebiusSubstitutionOfAQuotientOfLinears(Entity expr, Entity.Variable x)
732+
{
733+
Powf? power = null;
734+
Entity constant = Number.Integer.One;
735+
var others = new List<(Entity Base, EInteger Power)>();
736+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr))
737+
{
738+
if (!factor.ContainsNode(x))
739+
{
740+
constant = underneath ? constant / factor : constant * factor;
741+
continue;
742+
}
743+
if (!underneath && power is null && factor is Powf(Divf(var above, var below), var alpha)
744+
&& !alpha.ContainsNode(x) && alpha.Evaled is not Number.Integer
745+
&& above.ContainsNode(x) && below.ContainsNode(x))
746+
{
747+
power = (Powf)factor;
748+
continue;
749+
}
750+
var (@base, whole) = factor is Powf(var b, Number.Integer n) && n.EInteger.CanFitInInt32() ? (b, n.EInteger) : (factor, EInteger.One);
751+
others.Add((@base, underneath ? -whole : whole));
752+
}
753+
if (power is null || others.Count == 0 || power.Base is not Divf(var top, var bottom)
754+
|| !TreeAnalyzer.TryGetPolyLinear(top, x, out var q, out var p) || TreeAnalyzer.IsZero(q)
755+
|| !TreeAnalyzer.TryGetPolyLinear(bottom, x, out var s, out var r) || TreeAnalyzer.IsZero(s))
756+
return null;
757+
var determinant = (q * r - p * s).InnerSimplified;
758+
if (VanishesIdentically(determinant))
759+
return null;
760+
// Each factor a multiple of the top, of the bottom, or of their product.
761+
var j = EInteger.Zero;
762+
var k = EInteger.Zero;
763+
foreach (var (@base, n) in others)
764+
{
765+
Entity multiple;
766+
if (TreeAnalyzer.TryGetPolyLinear(@base, x, out var slope, out var intercept))
767+
{
768+
if (VanishesIdentically(slope * p - intercept * q))
769+
{
770+
multiple = (slope / q).InnerSimplified;
771+
j += n;
772+
}
773+
else if (VanishesIdentically(slope * r - intercept * s))
774+
{
775+
multiple = (slope / s).InnerSimplified;
776+
k += n;
777+
}
778+
else
779+
return null;
780+
}
781+
else if (TreeAnalyzer.TryGetPolyQuadratic(@base, x, out var a2, out var b2, out var c2) && !TreeAnalyzer.IsZero(a2))
782+
{
783+
multiple = (a2 / (q * s)).InnerSimplified;
784+
if (!VanishesIdentically(b2 - multiple * (p * s + q * r)) || !VanishesIdentically(c2 - multiple * p * r))
785+
return null;
786+
j += n;
787+
k += n;
788+
}
789+
else
790+
return null;
791+
constant *= n.Equals(EInteger.One) ? multiple : MathS.Pow(multiple, Number.Integer.Create(n));
792+
}
793+
var degree = (j + k + EInteger.FromInt32(2)).Negate();
794+
if (degree.Sign < 0 || degree.CompareTo(EInteger.FromInt32(24)) > 0 || !j.CanFitInInt32())
795+
return null;
796+
// D^(j + k + 1) t^(alpha + j) (q - s t)^degree, term by term in t.
797+
var m = degree.ToInt32Checked();
798+
Entity sum = Number.Integer.Zero;
799+
Entity binomial = Number.Integer.One;
800+
for (var i = 0; i <= m; i++)
801+
{
802+
var offset = j + EInteger.FromInt32(i + 1);
803+
var raised = (offset.IsZero ? power.Exponent : power.Exponent + Number.Integer.Create(offset)).InnerSimplified;
804+
if (raised.Evaled is Number.Complex { IsZero: true })
805+
return null;
806+
// Free of x and small, so simplified: the multiples are otherwise left as
807+
// `(1/(a (-a)))^(-2) (a - (-a))^(-3)`.
808+
var coefficient = (binomial * MathS.Pow(q, Number.Integer.Create(m - i)) * MathS.Pow(-s, Number.Integer.Create(i)) / raised).Simplify();
809+
sum += coefficient * MathS.Pow(power.Base, raised);
810+
binomial = binomial * (m - i) / (i + 1);
811+
}
812+
return ((constant * MathS.Pow(determinant, Number.Integer.Create(j + k + EInteger.One))).Simplify() * sum).InnerSimplified;
813+
}
814+
712815
/// <summary>
713816
/// A quotient by the square of a base, by parts against the base's reciprocal, where the
714817
/// 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,9 @@ private static Entity WithItsPiecewiseSumsCombined(Entity expr)
784784
if ((answer = IndefiniteIntegralSolver.SolveAPowerOverAPowerOfALogarithm(expr, x)) is { }) return answer;
785785
// And x^m artanh(A x/sqrt(d + A^2 x^2)), by parts, the logarithm's derivative read as the root it is.
786786
if ((answer = IndefiniteIntegralSolver.SolveByPartsAgainstAnArtanhWhoseDerivativeIsARoot(expr, x, integrateByParts)) is { }) return answer;
787+
// A power of a quotient of linears beside whole powers of them, which is how e^(n acoth(a x))
788+
// over a power of c - a^2 c x^2 arrives folded, under t = the quotient.
789+
if ((answer = IndefiniteIntegralSolver.SolveByTheMoebiusSubstitutionOfAQuotientOfLinears(expr, x)) is { }) return answer;
787790
// A power of an exponential with a positive base is the exponential of the product,
788791
// exactly, and only that spelling is one the exponential rules read.
789792
if ((answer = IndefiniteIntegralSolver.SolveByFlatteningAPowerOfAnExponential(expr, x, integrateByParts)) is { }) return answer;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
/// A power of a quotient of two linears beside whole powers of them, under
16+
/// <c>t = (p + q x)/(r + s x)</c>: <c>e^(n acoth(a x))/(c - a^2 c x^2)^m</c> arrives as
17+
/// <c>((a x + 1)/(a x - 1))^(n/2)</c> over the power of the quadratic, and is a polynomial in
18+
/// <c>t</c> times a power of it. For <c>m</c> past 1 it was declined. 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 APowerOfAQuotientOfLinearsBesideThemIntegralTest
23+
{
24+
[Theory]
25+
[InlineData("e^(n*acoth(a*x))/(c - a^2*c*x^2)^2")]
26+
[InlineData("e^(n*acoth(a*x))/(c - a^2*c*x^2)^3")]
27+
[InlineData("e^(n*atanh(a*x))/(c - a^2*c*x^2)^2")]
28+
[InlineData("((a*x + 1)/(a*x - 1))^(n/2)/((a*x + 1)^2*(a*x - 1)^2)")]
29+
[InlineData("((x + 2)/(3*x - 1))^(1/3)/((x + 2)*(3*x - 1)^2)")]
30+
public void UnderTheQuotient(string integrand)
31+
{
32+
var integral = integrand.ToEntity().Integrate("x");
33+
var text = integral.Stringize();
34+
Assert.DoesNotContain("integral(", text);
35+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("c", 0.7).Substitute("n", 0.9);
36+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
37+
var original = Pinned(integrand.ToEntity());
38+
var compared = 0;
39+
// On both sides of the roots, -0.77 and 0.77 for a = 1.3, and of 1/3 and -2.
40+
foreach (var at in new[] { -2.9, -1.4, -0.4, 0.2, 0.6, 1.3, 2.9 })
41+
{
42+
var want = original.Substitute("x", at).EvalNumerical();
43+
var got = derivative.Substitute("x", at).EvalNumerical();
44+
if (want.IsNaN)
45+
continue;
46+
compared++;
47+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
48+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
49+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
50+
}
51+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)