Skip to content

Commit 02d12a5

Browse files
A rational function of x^n beside a power of x and the root of a binomial is integrated (#1727)
Under u = x/(a + b x^n)^(1/n), x^j (a + b x^n)^(k - (j + 1)/n) beside a rational function of x^n is u^j times a rational function of u, for any j below n, since x^j (a + b x^n)^(-j/n) is u^j. The rule took j = 0 only, so x/((a + b x^3)^(2/3) (c + d x^3)) and x^4 (a + b x^3)^(1/3)/(c + d x^3), Rubi's 1.1.3.4, were declined. It takes any j now. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 04e2fe6 commit 02d12a5

3 files changed

Lines changed: 71 additions & 8 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,21 @@ taken apart into pieces each closed the same way
795795
| `"(2 + x)/((2 + 4*x - 3*x^2)*(1 + 3*x + 2*x^2)^(3/2))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative |
796796
| `"1/((x^2 + 1)*sqrt(x^2 + x + 1))".ToEntity().Integrate("x")` | `integral(...)` | a logarithm and an arctangent |
797797

798+
### A rational function of `x^n` beside a power of `x` and the root of a binomial is integrated
799+
800+
**Answers where there were none.** `x/((a + b x^3)^(2/3) (c + d x^3))` and `x^4 (a + b x^3)^(1/3)/(c + d x^3)`,
801+
Rubi's 1.1.3.4, were declined, while the same without the power of `x` in front was answered under
802+
`u = x/(a + b x^n)^(1/n)`. That substitution takes `x^j (a + b x^n)^(k - (j + 1)/n)` beside a rational
803+
function of `x^n` to `u^j` times a rational function of `u`, for any `j` below `n`, and is taken for
804+
those now. Each answer holds on both sides of zero, an odd root of a negative being real here
805+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
806+
807+
| Input | Was (2.5.0) | Now |
808+
|---|---|---|
809+
| `"x/((a + b*x^3)^(2/3)*(c + d*x^3))".ToEntity().Integrate("x")` | `integral(...)` | logarithms and an arctangent of `x (a + b x^3)^(-1/3)` |
810+
| `"x^4*(a + b*x^3)^(1/3)/(c + d*x^3)".ToEntity().Integrate("x")` | `integral(...)` | the same, beside a rational function of it |
811+
| `"x/((1 + x^3)^(2/3)*(2 + x^3))".ToEntity().Integrate("x")` | `integral(...)` | the same with numbers |
812+
798813
### A rational function of `x^n` beside a power of a symbolic binomial is integrated without a search
799814

800815
**Answers where there were none.** A rational function of `x^n` beside `(c + d x^n)^(k - 1/n)` is a

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

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4185,6 +4185,14 @@ Entity Carried(int numerator, int denominator, int nextSine, int nextCosine)
41854185
/// The identity holds wherever the root is real, which is where the answer is
41864186
/// asked; <c>u</c> goes back in as <c>x (c + d x^n)^(-1/n)</c>.
41874187
/// </para>
4188+
/// <para>
4189+
/// And beside a power of <c>x</c> that is not one of <c>x^n</c>: <c>x^j</c> times a
4190+
/// rational function of <c>x^n</c> times <c>(c + d x^n)^(k - (j + 1)/n)</c> is
4191+
/// <c>u^j</c> times the same in <c>u</c>, since <c>x^j (c + d x^n)^(-j/n)</c> is
4192+
/// <c>u^j</c>. Rubi's 1.1.3.4: <c>x/((a + b x^3)^(2/3) (c + d x^3))</c> is
4193+
/// <c>u/(c - (b c - a d) u^3)</c>, and <c>x^4 (a + b x^3)^(1/3)/(c + d x^3)</c> is the
4194+
/// same with <c>x^3</c> beside it; each was declined.
4195+
/// </para>
41884196
/// https://github.com/asc-community/AngouriMath/issues/718
41894197
/// </remarks>
41904198
internal static Entity? SolveByDividingByTheRoot(Entity expr, Entity.Variable x)
@@ -4195,6 +4203,8 @@ Entity Carried(int numerator, int denominator, int nextSine, int nextCosine)
41954203
Entity? c = null, d = null;
41964204
var n = 0;
41974205
var k = EInteger.Zero;
4206+
// The power of x beside it, below n: the exponent is `k - (j + 1)/n`.
4207+
var j = 0;
41984208
Entity rest = Number.Integer.One;
41994209
var (above, below) = Functions.SingleQuotient.Of(expr);
42004210
foreach (var (side, isBelow) in new[] { (above, false), (below, true) })
@@ -4206,15 +4216,18 @@ Entity Carried(int numerator, int denominator, int nextSine, int nextCosine)
42064216
if (radicand is not null || !TryReadAsABinomialIn(@base, x, out var readC, out var readD, out var readN)
42074217
|| readN < 2 || !signed.Denominator.Equals(EInteger.FromInt32(readN)))
42084218
return null;
4209-
// The numerator of the exponent is k n - 1.
4210-
var shifted = signed.Numerator.Add(EInteger.One);
4211-
if (!shifted.Remainder(EInteger.FromInt32(readN)).IsZero)
4212-
return null;
4219+
// The numerator of the exponent is k n - j - 1, for j from 0 to n - 1.
4220+
var nAsEInteger = EInteger.FromInt32(readN);
4221+
var residue = signed.Numerator.Add(EInteger.One).Remainder(nAsEInteger);
4222+
if (residue.Sign < 0)
4223+
residue = residue.Add(nAsEInteger);
4224+
var readJ = residue.IsZero ? 0 : readN - residue.ToInt32Checked();
42134225
radicand = @base;
42144226
c = readC;
42154227
d = readD;
42164228
n = readN;
4217-
k = shifted.Divide(EInteger.FromInt32(readN));
4229+
j = readJ;
4230+
k = signed.Numerator.Add(EInteger.FromInt32(readJ + 1)).Divide(nAsEInteger);
42184231
continue;
42194232
}
42204233
if (factor.ContainsNode(x) && !IsRationalIn(factor, x))
@@ -4223,8 +4236,25 @@ Entity Carried(int numerator, int denominator, int nextSine, int nextCosine)
42234236
}
42244237
if (radicand is null || c is null || d is null || TreeAnalyzer.IsZero(c) || TreeAnalyzer.IsZero(d))
42254238
return null;
4226-
// The rest as a rational function of x^n: written in a stand-in for x^n where every
4227-
// power of x is a multiple of n, and declined otherwise.
4239+
// The rest as a rational function of x^n, x^j taken out of it first: written in a
4240+
// stand-in for x^n where every power of x is a multiple of n, and declined otherwise.
4241+
if (j != 0)
4242+
{
4243+
// Out of the polynomial above the bar, each of whose powers is then a multiple of n.
4244+
var (restAbove, restBelow) = Functions.SingleQuotient.Of(rest);
4245+
if (!TreeAnalyzer.TryGetPolynomial(restAbove, x, out var aboveTerms) || aboveTerms.Count == 0)
4246+
return null;
4247+
Entity lowered = Number.Integer.Zero;
4248+
foreach (var term in aboveTerms)
4249+
{
4250+
var power = term.Key.Subtract(EInteger.FromInt32(j));
4251+
if (power.Sign < 0 || term.Value.ContainsNode(x))
4252+
return null;
4253+
var monomial = power.IsZero ? term.Value : term.Value * MathS.Pow(x, Number.Integer.Create(power));
4254+
lowered = lowered == Number.Integer.Zero ? monomial : lowered + monomial;
4255+
}
4256+
rest = restBelow == Number.Integer.One ? lowered : lowered / restBelow;
4257+
}
42284258
var xToTheN = Variable.CreateUnique(expr, "x_n");
42294259
var inXToTheN = rest.Replace(node =>
42304260
node is Powf(var xAgain, Number.Integer power) && xAgain == x && power.EInteger.Remainder(EInteger.FromInt32(n)).IsZero
@@ -4243,8 +4273,11 @@ node is Powf(var xAgain, Number.Integer power) && xAgain == x && power.EInteger.
42434273
// base is its polynomial in u first, which collects what the substitution writes twice --
42444274
// `1 - (-u^2) - u^2` is 1 under a secant's half angle -- and the factors stay as they are
42454275
// written, which the rules after this read better than their product expanded.
4276+
var restInU = inXToTheN.Substitute(xToTheN, c * uToTheN / oneMinusDUToTheN);
4277+
if (j != 0)
4278+
restInU = MathS.Pow(u, j) * restInU;
42464279
var integrand = WithTheFactorsWrittenOnBothSidesCancelled(u, Functions.SingleQuotient.Combine(
4247-
inXToTheN.Substitute(xToTheN, c * uToTheN / oneMinusDUToTheN)
4280+
restInU
42484281
* (k.IsZero ? Number.Integer.One : MathS.Pow(binomialInU, Number.Integer.Create(k)))
42494282
/ oneMinusDUToTheN).InnerSimplified);
42504283
if (integrand is Providedf(var inner, _))

‎Sources/Tests/UnitTests/Calculus/DividedByTheRootIntegralTest.cs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,20 @@ public void TimofeevsQuarticBesideAFourthRoot()
6565
[InlineData("1/((a + b*x^2)^(9/2)*(1 + x^2))")]
6666
public void AHalfOddPowerOfASymbolicQuadratic(string integrand)
6767
=> DifferentiatesBack(integrand, new[] { -1.3, -0.4, 0.3, 0.9, 1.7 }, ("a", 1.3), ("b", 0.7));
68+
69+
/// <summary>
70+
/// Beside a power of x that is not one of x^n: <c>x^j</c> times a rational function of
71+
/// <c>x^n</c> times <c>(a + b x^n)^(k - (j + 1)/n)</c> is <c>u^j</c> times the same in
72+
/// <c>u</c>. Rubi's 1.1.3.4; each was declined. On both sides of zero, the cube root of a
73+
/// negative being real.
74+
/// </summary>
75+
[Theory]
76+
[InlineData("x/((a + b*x^3)^(2/3)*(c + d*x^3))")]
77+
[InlineData("x^4/((a + b*x^3)^(2/3)*(c + d*x^3))")]
78+
[InlineData("x^7/((a + b*x^3)^(2/3)*(c + d*x^3))")]
79+
[InlineData("x^4*(a + b*x^3)^(1/3)/(c + d*x^3)")]
80+
[InlineData("x/((1 + x^3)^(2/3)*(2 + x^3))")]
81+
public void BesideAPowerOfX(string integrand)
82+
=> DifferentiatesBack(integrand, new[] { -2.7, -1.3, -0.6, 0.4, 1.3, 2.6 }, ("a", 2.3), ("b", 0.7), ("c", 1.3), ("d", 1.7));
6883
}
6984
}

0 commit comments

Comments
 (0)