Skip to content

Commit 0585dbb

Browse files
A power of a linear beside a symbolic block is split at the linear's root (#1706)
* A power of a linear beside a symbolic block is split at the linear's root 1/((x - c)(a + b x^3)) was declined: the split over written factors takes linear and quadratic blocks only, and the split beside a block at a power of x (#1700) is at 0. N/(L^k B) for a linear L = g + h x splits the same way at L's root r: N/B has a power series in s = x - r, its first k terms are the part over s^k, and (N - P B)/s^k is a polynomial over the block exactly. The coefficients at the root are read by Taylor's formula and the block is left as it is written, for the rules that read it. Writing 1/(x (a + b (c + d x)^3)) in c + d x makes this shape, as Rubi's 1.3.1 does. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura * The breaking-changes entry names the split beside another linear Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura * A block that is a polynomial in a power of the linear is left to the substitution of the linear 1/((c + d x)^2 (a + b (c + d x)^3)^2) is a function of c + d x, which the substitution of it reads. Split at the root of the linear, the rest would go back over the block written in x, which the rules over x search for 20 s. The block is shifted and read before the numerator, so such a question is declined before the numerator is shifted. Part of #718 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent e73a940 commit 0585dbb

3 files changed

Lines changed: 169 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ only where its factors were linear or quadratic, so `1/(x (x^3 + c))` was declin
204204
- a power of `x` beside a block `B` whose constant term is not zero is split off: the first `k`
205205
terms of the power series of `N/B` at 0 are the part over `x^k`, and the rest is a polynomial
206206
over `B` exactly;
207+
- a power of another linear `g + h x` beside such a block is split the same way at the linear's
208+
root, where the coefficients of `N` and `B` are read by Taylor's formula;
207209
- blocks that are each a polynomial in one power `x^n` are split in `u = x^n`, where they are linear
208210
or quadratic, for `n >= 3`, or `n = 2` with two blocks or more; one block quadratic in `u` is two
209211
at its roots, as `a + b x^2 + c x^4` already was;
@@ -219,6 +221,8 @@ Rubi's `x^m (a + b x^n)^p` and `(a + b x^n)^p (c + d x^n)^q`
219221
| `"1/(x*(x^3 + c))".Integrate("x")` | left unevaluated | `ln(x)/c - ln(c x^3 + c^2)/(3 c)` |
220222
| `"1/(x^4*(a + b*x^3))".Integrate("x")` | left unevaluated | `-1/(3 a x^3) - b ln(x)/a^2 + b ln(a^2 b x^3 + a^3)/(3 a^2)` |
221223
| `"1/(x*(a + b*x^5))".Integrate("x")` | left unevaluated | `ln(x)/a - ln(a b x^5 + a^2)/(5 a)` |
224+
| `"1/((x - c)*(a + b*x^3))".Integrate("x")` | left unevaluated | `ln(x - c)/(a + b c^3)`, and logarithms and an arctangent at the binomial's roots |
225+
| `"1/((g + h*x)*(a + b*x^3))".Integrate("x")` | left unevaluated | `h^3 ln(g + h x)/(a h^3 - b g^3)`, and the same |
222226
| `"1/(x^2*(x^3 + c))".Integrate("x")`, and `(c + d x + e x^2)/(x^2 (a + b x^3))` | left unevaluated | a logarithm and an arctangent in `c^(1/3)`, beside `-1/(c x)` |
223227
| `"1/((a+b*x^3)*(c+d*x^3))".Integrate("x")`, and `x/((a + b x^3)(c + d x^3))` | left unevaluated | logarithms and arctangents in `(-a/b)^(1/3)` and `(-c/d)^(1/3)`, over `a d - b c` |
224228
| `"1/((a+b*x^4)*(c+d*x^4))".Integrate("x")` | left unevaluated | arctangents and logarithms of each binomial's roots, over `a d - b c` |

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

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,10 @@ is var (multiple, leftover)
830830
// the second degree. Split at the power of x, each part goes to a rule that reads it.
831831
if (IntegrateOverAPowerOfXBesideABlock(numerator, denominator, x, integrateByParts) is { } besideABlock)
832832
return besideABlock;
833+
// And a power of another linear beside such a block, split at its root the same way:
834+
// `1/((u - c)(a + b u^3))`, which writing `1/(x (a + b (c + d x)^3))` in `c + d x` makes.
835+
if (IntegrateOverAPowerOfALinearBesideABlock(numerator, denominator, x, integrateByParts) is { } besideABlockAtARoot)
836+
return besideABlockAtARoot;
833837

834838
// Blocks that are each a polynomial in one power of x past the second,
835839
// `1/((a + b x^3)(c + d x^3))`: split in `u = x^n`, where they are linear or quadratic,
@@ -993,6 +997,155 @@ Entity Coefficient(Dictionary<EInteger, Entity> polynomial, int power)
993997
: null;
994998
}
995999

1000+
/// <summary>
1001+
/// <c>N/(L^k B)</c> for a linear <c>L = g + h x</c> other than x, beside a block <c>B</c>
1002+
/// with a symbol in it, past the second degree, that does not vanish at the root of L:
1003+
/// split there as <see cref="IntegrateOverAPowerOfXBesideABlock"/> splits at 0. With
1004+
/// <c>s = x - r</c>, <c>r = -g/h</c>, <c>N/B</c> has a power series in <c>s</c>, and its first
1005+
/// <c>k</c> terms <c>P</c> are the part over <c>s^k</c>: <c>N/(s^k B) = P/s^k + R/B</c>, with
1006+
/// <c>R = (N - P B)/s^k</c> exactly.
1007+
/// </summary>
1008+
/// <remarks>
1009+
/// <c>1/(x (a + b (c + d x)^3))</c> is <c>1/((u - c)(a + b u^3))</c> in <c>u = c + d x</c>: a
1010+
/// linear beside a binomial, which nothing took apart, since the split over written
1011+
/// factors takes linear and quadratic blocks only. The coefficients of N and B at the
1012+
/// root are read by Taylor's formula, and the block is left as it is written, for the
1013+
/// rules that read it. Rubi's 1.3.1.
1014+
/// https://github.com/asc-community/AngouriMath/issues/718
1015+
/// </remarks>
1016+
private static Entity? IntegrateOverAPowerOfALinearBesideABlock(Entity numerator, Entity denominator, Entity.Variable x, bool integrateByParts)
1017+
{
1018+
// For the question asked, or one substitution below it: the rest over the block is
1019+
// integrated again.
1020+
if (!Integration.AnsweringTheQuestionAskedOrOneBelow)
1021+
return null;
1022+
Entity? linear = null;
1023+
var k = 0;
1024+
Entity block = Number.Integer.One;
1025+
var pastTheSecondDegree = false;
1026+
foreach (var factor in Mulf.LinearChildren(denominator))
1027+
{
1028+
var (@base, power) = factor is Powf(var raised, Number.Integer e) && e.EInteger.Sign > 0 && e.EInteger.CanFitInInt32()
1029+
? (raised, e.EInteger.ToInt32Unchecked())
1030+
: (factor, 1);
1031+
if (@base != x && @base.ContainsNode(x) && TreeAnalyzer.TryGetPolyLinear(@base, x, out var slope, out var offset)
1032+
&& !slope.ContainsNode(x) && !offset.ContainsNode(x))
1033+
{
1034+
if (linear is { } && linear != @base)
1035+
return null;
1036+
linear = @base;
1037+
k += power;
1038+
}
1039+
else
1040+
{
1041+
block = block == Number.Integer.One ? factor : block * factor;
1042+
pastTheSecondDegree |= TreeAnalyzer.TryGetPolynomial(@base, x, out var terms) && terms.Keys.Any(degree => degree.CompareTo(EInteger.FromInt32(2)) > 0);
1043+
}
1044+
}
1045+
if (linear is null || k > MaximumPowerOfXBesideABlock || !pastTheSecondDegree || !block.ContainsNode(x) || !block.Vars.Any(symbol => symbol != x)
1046+
|| !TreeAnalyzer.TryGetPolyLinear(linear, x, out var h, out var g) || VanishesIdentically(h)
1047+
|| !TreeAnalyzer.TryGetPolynomial(block, x, out var below) || !TreeAnalyzer.TryGetPolynomial(numerator, x, out var above))
1048+
return null;
1049+
foreach (var term in below.Concat(above))
1050+
if (term.Key.Sign < 0 || !term.Key.CanFitInInt32() || term.Value.ContainsNode(x))
1051+
return null;
1052+
var degreeBelow = below.Keys.Max()!.ToInt32Unchecked();
1053+
var degreeAbove = above.Count == 0 ? 0 : above.Keys.Max()!.ToInt32Unchecked();
1054+
if (degreeBelow > MaximumPowerOfXBesideABlock || degreeAbove > MaximumPowerOfXBesideABlock)
1055+
return null;
1056+
var root = Functions.PartialFractions.InLowestTermsOverTheSymbols(-g / h);
1057+
// N and B in s = x - r, by Taylor's formula.
1058+
Entity[] InS(Dictionary<EInteger, Entity> polynomial, int degree)
1059+
{
1060+
var shifted = new Entity[degree + 1];
1061+
for (var i = 0; i <= degree; i++)
1062+
{
1063+
Entity sum = Number.Integer.Zero;
1064+
for (var m = i; m <= degree; m++)
1065+
if (polynomial.TryGetValue(EInteger.FromInt32(m), out var coefficient))
1066+
sum += coefficient * Binomial(m, i) * (m == i ? Number.Integer.One : MathS.Pow(root, m - i));
1067+
shifted[i] = Functions.PartialFractions.InLowestTermsOverTheSymbols(sum);
1068+
}
1069+
return shifted;
1070+
}
1071+
// Where s divides B, the block shares the root.
1072+
var b = InS(below, degreeBelow);
1073+
if (VanishesIdentically(b[0]))
1074+
return null;
1075+
// A block that is a polynomial in a power of the linear, `a + b (c + d x)^3`, makes the
1076+
// whole a function of the linear, which the substitution of it reads. Split here, the
1077+
// rest goes back over that block written in x, which the rules over x search long for:
1078+
// 20 s for `1/((c + d x)^2 (a + b (c + d x)^3)^2)`.
1079+
static int Gcd(int p, int q) => q == 0 ? p : Gcd(q, p % q);
1080+
var stride = 0;
1081+
for (var i = 1; i < b.Length; i++)
1082+
if (!VanishesIdentically(b[i]))
1083+
stride = Gcd(stride, i);
1084+
if (stride > 1)
1085+
return null;
1086+
// Where s divides N, the part over s^k is nothing and the rest is the question asked
1087+
// again.
1088+
var n = InS(above, degreeAbove);
1089+
if (VanishesIdentically(n[0]))
1090+
return null;
1091+
Entity At(Entity[] polynomial, int power) => power < polynomial.Length ? polynomial[power] : Number.Integer.Zero;
1092+
1093+
// P: the first k terms of the power series of N/B at r.
1094+
var series = new Entity[k];
1095+
for (var j = 0; j < k; j++)
1096+
{
1097+
var sum = At(n, j);
1098+
for (var i = 1; i <= j; i++)
1099+
sum -= At(b, i) * series[j - i];
1100+
series[j] = Functions.PartialFractions.InLowestTermsOverTheSymbols(sum / b[0]);
1101+
}
1102+
1103+
// R = (N - P B)/s^k in s, and then in x.
1104+
var top = System.Math.Max(degreeAbove, degreeBelow + k - 1);
1105+
var inS = new Entity[System.Math.Max(top - k + 1, 0)];
1106+
for (var m = k; m <= top; m++)
1107+
{
1108+
var coefficient = At(n, m);
1109+
for (var j = System.Math.Max(0, m - degreeBelow); j <= System.Math.Min(k - 1, m); j++)
1110+
coefficient -= series[j] * At(b, m - j);
1111+
inS[m - k] = Functions.PartialFractions.InLowestTermsOverTheSymbols(coefficient);
1112+
}
1113+
Entity remainder = Number.Integer.Zero;
1114+
for (var j = 0; j < inS.Length; j++)
1115+
{
1116+
Entity sum = Number.Integer.Zero;
1117+
for (var m = j; m < inS.Length; m++)
1118+
if (!VanishesIdentically(inS[m]))
1119+
sum += inS[m] * Binomial(m, j) * (m == j ? Number.Integer.One : MathS.Pow(-root, m - j));
1120+
var coefficient = Functions.PartialFractions.InLowestTermsOverTheSymbols(sum);
1121+
if (!VanishesIdentically(coefficient))
1122+
remainder += j == 0 ? coefficient : coefficient * (j == 1 ? x : MathS.Pow(x, j));
1123+
}
1124+
1125+
// L^k is h^k s^k, and s is L/h: the part over L^k term by term, and the rest over the
1126+
// block as it is written.
1127+
Entity overTheLinear = Number.Integer.Zero;
1128+
for (var j = 0; j < k; j++)
1129+
if (!VanishesIdentically(series[j]))
1130+
overTheLinear += j == k - 1
1131+
? series[j] * IntegralPatterns.AntiderivativeLog(linear)
1132+
: series[j] * MathS.Pow(h, k - 1 - j) * MathS.Pow(linear, j - k + 1) / (j - k + 1);
1133+
var scale = k == 1 ? h : MathS.Pow(h, k);
1134+
if (remainder == Number.Integer.Zero)
1135+
return overTheLinear / scale;
1136+
return Integration.ComputeIndefiniteIntegral(remainder / block, x, integrateByParts) is { } overTheBlock
1137+
? (overTheLinear + overTheBlock) / scale
1138+
: null;
1139+
1140+
static Entity Binomial(int n, int k)
1141+
{
1142+
var result = EInteger.One;
1143+
for (var i = 1; i <= k; i++)
1144+
result = result.Multiply(EInteger.FromInt32(n - k + i)).Divide(EInteger.FromInt32(i));
1145+
return Number.Integer.Create(result);
1146+
}
1147+
}
1148+
9961149
/// <summary>
9971150
/// <c>N/(B_1 ... B_m)</c> where every block <c>B_i</c> is a polynomial in <c>x^n</c> for one
9981151
/// <c>n >= 2</c>, linear or quadratic in it, with a symbol among them: split in

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ public void TheNumericSpellingsStillAnswer(string integrand)
135135
public void APowerOfXBesideASymbolicBlock(string integrand)
136136
=> DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3), ("c", 0.4), ("d", 1.1), ("e", 0.6));
137137

138+
/// <summary>
139+
/// And a power of another linear beside such a block, split at its root:
140+
/// <c>1/((x - c)(a + b x^3))</c> was declined, and so was the same over <c>g + h x</c>.
141+
/// </summary>
142+
[Theory]
143+
[InlineData("1/((x - c)*(a + b*x^3))")]
144+
[InlineData("1/((x - c)^2*(a + b*x^4))")]
145+
[InlineData("(1 + x)/((x + 2)^2*(a + b*x^3))")]
146+
[InlineData("1/((g + h*x)*(a + b*x^3))")]
147+
public void APowerOfALinearBesideASymbolicBlock(string integrand)
148+
=> DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3), ("c", 0.4), ("g", 1.1), ("h", 0.6));
149+
138150
/// <summary>
139151
/// Blocks that are each a polynomial in one power of x past the second, split in
140152
/// <c>u = x^n</c>, where they are linear: <c>1/((a + b x^3)(c + d x^3))</c> was declined.

0 commit comments

Comments
 (0)