Skip to content

Commit 4c3aa3b

Browse files
A negative power of a linear beside a root of another is integrated by the recurrence on the power (#1758)
1/((a + b x)^4 sqrt(c + d x)) and (p + q x + r x^2 + s x^3)/((a + b x)^5 sqrt(c + d x)) ran past the budget: the substitution for the root makes a rational function over a power of a quadratic with symbols in it, and its reduction grows with the power. A whole power m <= -2 of one linear beside a power that is not whole of another, times a polynomial, is integrated by the recurrence int L1^m L2^n = L1^(m + 1) L2^(n + 1)/((m + 1) D) - (m + n + 2) d/((m + 1) D) int L1^(m + 1) L2^n, the polynomial written in powers of L1 first, down to int L2^n/L1. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent 8a940c9 commit 4c3aa3b

4 files changed

Lines changed: 218 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,24 @@ arctangent it is ([#718](https://github.com/asc-community/AngouriMath/issues/718
12191219
| `"(A + B*x + C*x^2)*sqrt(c + d*x)/((a + b*x)^3*sqrt(e + f*x))".ToEntity().Integrate("x")` | `integral(...)` | the roots over powers of `a + b x`, a logarithm, and an arctangent |
12201220
| `"x^2*sqrt(a + 2*x)*sqrt(c - 3*x)".ToEntity().Integrate("x")` | `integral(...)` | a cubic times the two roots, and an arctangent of `sqrt(6)/2 sqrt(a + 2 x)/sqrt(c - 3 x)` |
12211221

1222+
### A negative power of a linear beside a root of another is integrated by the recurrence on the power
1223+
1224+
**Answers where there were none, and faster ones, written differently.** `1/((a + b x)^4 sqrt(c + d x))`
1225+
was declined by 2.5.0, and the unreleased master answered it in fourteen seconds, by the substitution
1226+
for the root, over a power of a quadratic with symbols in it; with a cubic above it, past a minute.
1227+
A whole power `m <= -2` of one linear beside a power that is not whole of another, times a
1228+
polynomial, is integrated now by the recurrence
1229+
`int L1^m L2^n = L1^(m + 1) L2^(n + 1)/((m + 1) D) - (m + n + 2) d/((m + 1) D) int L1^(m + 1) L2^n`,
1230+
`D = b c - a d`, down to `int L2^n/L1`, the polynomial written in powers of `L1` first. The
1231+
answers are the same functions as master's where master gave one, written as powers of the two
1232+
linears ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
1233+
1234+
| Input | Was (2.5.0) | Now |
1235+
|---|---|---|
1236+
| `"1/((a + b*x)^4*sqrt(c + d*x))".ToEntity().Integrate("x")` | `integral(...)` | powers of `a/b + x` beside `sqrt(c + d x)`, and the arctangent or logarithm `1/((a + b x) sqrt(c + d x))` integrates to |
1237+
| `"(p + q*x + r*x^2 + s*x^3)/((a + b*x)^5*sqrt(c + d*x))".ToEntity().Integrate("x")` | `integral(...)` | the same, term by term |
1238+
| `"x/((a + b*x)^4*sqrt(c + d*x))".ToEntity().Integrate("x")` | `integral(...)` | the same |
1239+
12221240
### A polynomial over a power of a linear beside the root of a quadratic is integrated
12231241

12241242
`P(x) Q^(m/2)/(g + h x)^k`, a polynomial over a power of a linear beside a half-odd power of a

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

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9424,6 +9424,154 @@ private static Entity WithWholePowersOfProductsDistributed(Entity integrand)
94249424
return integrand;
94259425
}
94269426

9427+
/// <summary>
9428+
/// A whole power <c>m &lt;= -2</c> of a linear beside a power that is not whole of another,
9429+
/// times a polynomial: <c>1/((a + b x)^4 sqrt(c + d x))</c>,
9430+
/// <c>(A + B x + C x^2)/((a + b x)^3 (c + d x)^(3/2))</c>. The polynomial is written in powers
9431+
/// of the first linear, and each negative power is raised to <c>-1</c> by the recurrence
9432+
/// <c>int L1^m L2^n = L1^(m + 1) L2^(n + 1)/((m + 1) D) - (m + n + 2) d/((m + 1) D) int L1^(m + 1) L2^n</c>,
9433+
/// <c>L1 = a + b x</c>, <c>L2 = c + d x</c>, <c>D = b c - a d</c>; what is left are the
9434+
/// questions <c>int L2^n/L1</c> and <c>int L1^k L2^n</c> for <c>k &gt;= 0</c>, which the
9435+
/// integrator answers in a step.
9436+
/// </summary>
9437+
/// <remarks>
9438+
/// <para>
9439+
/// The recurrence is the derivative of <c>L1^(m + 1) L2^(n + 1)</c>, which is
9440+
/// <c>L1^m L2^n ((m + 1) D + (m + n + 2) d L1)</c>, read back. Under <c>v = sqrt(c + d x)</c>
9441+
/// the same integrand is a rational function over a power of a quadratic with symbols in
9442+
/// it, and the reduction of that took four seconds at the square and twenty at the fourth
9443+
/// power; and the partial fractions of a rational function beside a root are terms of
9444+
/// exactly this shape, so it is their cost too.
9445+
/// </para>
9446+
/// <para>
9447+
/// A closed reduction to smaller questions of another shape, so at any depth.
9448+
/// https://github.com/asc-community/AngouriMath/issues/718
9449+
/// </para>
9450+
/// </remarks>
9451+
internal static Entity? SolveANegativePowerOfALinearBesideAPowerOfAnotherByTheRecurrence(Entity expr, Entity.Variable x, bool integrateByParts)
9452+
{
9453+
Entity constant = Number.Integer.One;
9454+
var linears = new List<(Entity Base, Entity Exponent)>();
9455+
Entity polynomial = Number.Integer.One;
9456+
// The factors with their exponents, a whole power of a product read through: the question
9457+
// comes back as `((a/b + x)^4 sqrt(c + d x))^(-1)` once a constant is out of the bar.
9458+
var factors = new List<(Entity Base, Entity Exponent)>();
9459+
void Gather(Entity node, int times)
9460+
{
9461+
switch (node)
9462+
{
9463+
case Mulf(var left, var right):
9464+
Gather(left, times);
9465+
Gather(right, times);
9466+
break;
9467+
case Divf(var numerator, var denominator):
9468+
Gather(numerator, times);
9469+
Gather(denominator, -times);
9470+
break;
9471+
case Powf(Mulf or Divf or Powf, Number.Integer whole) when whole.EInteger.CanFitInInt32() && System.Math.Abs(whole.EInteger.ToInt32Checked()) <= MaximumRecurrenceDepth:
9472+
Gather(((Powf)node).Base, times * whole.EInteger.ToInt32Checked());
9473+
break;
9474+
case Powf(var powerBase, var power):
9475+
factors.Add((powerBase, times == 1 ? power : (power * times).InnerSimplified));
9476+
break;
9477+
default:
9478+
factors.Add((node, Number.Integer.Create(times)));
9479+
break;
9480+
}
9481+
}
9482+
Gather(expr, 1);
9483+
foreach (var (@base, exponent) in factors)
9484+
{
9485+
if (!@base.ContainsNode(x))
9486+
{
9487+
constant *= MathS.Pow(@base, exponent);
9488+
continue;
9489+
}
9490+
if (exponent.ContainsNode(x))
9491+
return null;
9492+
if (TreeAnalyzer.TryGetPolyLinear(@base, x, out var slope, out _) && !TreeAnalyzer.IsZero(slope))
9493+
{
9494+
var index = linears.FindIndex(pair => pair.Base == @base);
9495+
if (index >= 0)
9496+
linears[index] = (@base, (linears[index].Exponent + exponent).InnerSimplified);
9497+
else
9498+
linears.Add((@base, exponent));
9499+
continue;
9500+
}
9501+
if (exponent is not Number.Integer { EInteger.Sign: > 0 } whole || !whole.EInteger.CanFitInInt32())
9502+
return null;
9503+
polynomial *= whole == Number.Integer.One ? @base : MathS.Pow(@base, whole);
9504+
}
9505+
// The whole power below the bar, the power that is not whole, and the linears that are
9506+
// whole powers above it, which belong to the polynomial.
9507+
(Entity Base, int Power)? below = null;
9508+
(Entity Base, Entity Exponent)? beside = null;
9509+
foreach (var (@base, exponent) in linears)
9510+
{
9511+
if (exponent is Number.Integer whole && whole.EInteger.CanFitInInt32())
9512+
{
9513+
var power = whole.EInteger.ToInt32Checked();
9514+
if (power >= 0)
9515+
polynomial *= power == 1 ? @base : MathS.Pow(@base, power);
9516+
else if (power <= -2 && power >= -MaximumRecurrenceDepth && below is null)
9517+
below = (@base, power);
9518+
else
9519+
return null;
9520+
}
9521+
else if (beside is null && exponent is not Number.Integer)
9522+
beside = (@base, exponent);
9523+
else
9524+
return null;
9525+
}
9526+
if (below is not var (first, m) || beside is not var (second, n))
9527+
return null;
9528+
if (!TreeAnalyzer.TryGetPolyLinear(first, x, out var b, out var a) || !TreeAnalyzer.TryGetPolyLinear(second, x, out var d, out var c))
9529+
return null;
9530+
var determinant = (b * c - a * d).InnerSimplified;
9531+
if (determinant.Evaled is Number.Complex { IsZero: true })
9532+
return null;
9533+
// The polynomial in powers of the first linear: x = (t - a)/b.
9534+
var t = Variable.CreateUnique(expr, "t_linear");
9535+
if (!TreeAnalyzer.TryGetPolynomial(polynomial.Substitute(x, (t - a) / b), t, out var inT)
9536+
|| inT.Keys.Any(power => power.Sign < 0 || !power.CanFitInInt32()))
9537+
return null;
9538+
// int L1^k L2^n for k from -1 down to m, each from the one above it.
9539+
var lowest = m + inT.Keys.Min(power => power.ToInt32Checked());
9540+
var raised = new Dictionary<int, Entity>();
9541+
if (lowest <= -1)
9542+
{
9543+
if (Integration.ComputeIndefiniteIntegral(MathS.Pow(second, n) / first, x, integrateByParts) is not { } overTheFirst
9544+
|| overTheFirst.Nodes.Any(node => node is Integralf))
9545+
return null;
9546+
raised[-1] = overTheFirst;
9547+
for (var k = -2; k >= lowest; k--)
9548+
raised[k] = MathS.Pow(first, k + 1) * MathS.Pow(second, n + 1) / ((k + 1) * determinant)
9549+
- (k + n + 2) * d / ((k + 1) * determinant) * raised[k + 1];
9550+
}
9551+
Entity answer = Number.Integer.Zero;
9552+
foreach (var pair in inT)
9553+
{
9554+
var (k, coefficient) = (m + pair.Key.ToInt32Checked(), pair.Value);
9555+
if (!raised.TryGetValue(k, out var integral))
9556+
{
9557+
var question = k == 0 ? MathS.Pow(second, n) : MathS.Pow(first, k) * MathS.Pow(second, n);
9558+
if (Integration.ComputeIndefiniteIntegral(question, x, integrateByParts) is not { } answered
9559+
|| answered.Nodes.Any(node => node is Integralf))
9560+
return null;
9561+
integral = answered;
9562+
}
9563+
answer += coefficient.InnerSimplified * integral;
9564+
}
9565+
return constant * answer;
9566+
}
9567+
9568+
/// <summary>
9569+
/// The most negative whole power
9570+
/// <see cref="SolveANegativePowerOfALinearBesideAPowerOfAnotherByTheRecurrence"/> takes down
9571+
/// the recurrence: each step is one term more in the answer.
9572+
/// </summary>
9573+
private const int MaximumRecurrenceDepth = 12;
9574+
94279575
/// <summary>
94289576
/// An integrand holding a fractional power of something <b>linear</b> in the variable,
94299577
/// turned into a rational function by <c>u^q = a*x + b</c>.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,10 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
758758
// degree-8 polynomial by expanding, both right and only one worth reading. Three
759759
// tests pinned exactly that and caught this when the split was put in front of the
760760
// substitution wholesale. The expanding call stays where it was, below.
761+
// A whole power below -1 of a linear beside a power that is not whole of another, by the
762+
// recurrence that raises the whole power to -1: closed, where the substitution for the
763+
// root makes a rational function over a power of a symbolic quadratic.
764+
if ((answer = IndefiniteIntegralSolver.SolveANegativePowerOfALinearBesideAPowerOfAnotherByTheRecurrence(expr, x, integrateByParts)) is { }) return answer;
761765
// A product of powers times a sum that is the derivative of the product with some
762766
// of the powers raised by one -- `e^x x^2 ln(x)^2 (3 + (3 + x) ln(x))` -- read off
763767
// the sum, for symbolic exponents too. Before the split, which loses it.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 whole power below <c>-1</c> of a linear beside a power that is not whole of another, times
16+
/// a polynomial, by the recurrence that raises the whole power to <c>-1</c>. Rubi's
17+
/// <c>P(x) (a + b x)^m (c + d x)^n</c> files.
18+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
19+
/// </summary>
20+
[Trait("Area", "Calculus")]
21+
public sealed class LinearPowerRecurrenceIntegralTest
22+
{
23+
[Theory]
24+
[InlineData("1/((a + b*x)^4*sqrt(c + d*x))")]
25+
[InlineData("(p + q*x + r*x^2 + s*x^3)/((a + b*x)^5*sqrt(c + d*x))")]
26+
[InlineData("(c + d*x)^(3/2)/(a + b*x)^3")]
27+
[InlineData("1/(x^3*(c + d*x)^(5/2))")]
28+
[InlineData("x/((a + b*x)^4*sqrt(c + d*x))")]
29+
public void ByTheRecurrence(string integrand)
30+
{
31+
var integral = integrand.ToEntity().Integrate("x");
32+
Assert.DoesNotContain("integral(", integral.Stringize());
33+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.9).Substitute("c", 0.7)
34+
.Substitute("d", 1.1).Substitute("p", 0.4).Substitute("q", 1.3).Substitute("r", 0.8)
35+
.Substitute("s", 0.6);
36+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
37+
var original = Pinned(integrand.ToEntity());
38+
foreach (var at in new[] { -2.4, -1.5, 0.3, 0.8, 1.5, 2.4 })
39+
{
40+
var want = original.Substitute("x", at).EvalNumerical();
41+
var got = derivative.Substitute("x", at).EvalNumerical();
42+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
43+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
44+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
45+
}
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)