From d671451f5d21a55778716377de9b321c861beb2d Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 10:57:29 +0000 Subject: [PATCH 01/12] A power of x beside a symbolic block of the third degree or more is split off N/(x^k B), where the block B has a symbol in it and a constant term that is not zero, is split at the power of x: the first k terms of the power series of N/B at 0 are the part over x^k, and the rest is a polynomial over B exactly, which the rules for a binomial and the rest read. The split over written factors took linear and quadratic blocks only, so 1/(x (x^3 + c)) was declined where 1/(x (x^3 + 2)) was answered. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 16 ++++ .../Integration/IndefiniteIntegralSolver.cs | 89 +++++++++++++++++++ .../SymbolicFactorsPartialFractionsTest.cs | 17 ++++ 3 files changed, 122 insertions(+) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index dbfa4ae0c..aa4d3896e 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -196,6 +196,22 @@ rules' already | `"asin(sqrt(1 + x) - sqrt(x))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in `arcsin(sqrt(1 + x) - sqrt(x))` | | `"x^3*atan(-sqrt(x)+sqrt(1+x))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in the arctangent | +### A power of `x` beside a symbolic block of the third degree or more is split off + +**Answers where there were none.** `N/(x^k B)`, where the block `B` has a symbol in it and a +constant term that is not zero, is split at the power of `x`: the first `k` terms of the power +series of `N/B` at 0 are the part over `x^k`, and the rest is a polynomial over `B` exactly. The +split over written factors took linear and quadratic blocks only, so `1/(x (x^3 + c))` was declined +where `1/(x (x^3 + 2))` was answered. Rubi's `x^m (a + b x^n)^p` +([#718](https://github.com/asc-community/AngouriMath/issues/718)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"1/(x*(x^3 + c))".Integrate("x")` | left unevaluated | `ln(x)/c - ln(c x^3 + c^2)/(3 c)` | +| `"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)` | +| `"1/(x*(a + b*x^5))".Integrate("x")` | left unevaluated | `ln(x)/a - ln(a b x^5 + a^2)/(5 a)` | +| `"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)` | + ### The hyperbolic functions have antiderivatives, and so does anything rational in `e^(k x)` An integrand rational in `e^(k x)` becomes a rational function of one variable under diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 8d1c36503..f3173f114 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -783,6 +783,12 @@ is var (multiple, leftover) return termByTerm; } + // A power of x beside a block with a symbol in it that x does not divide: + // `1/(x (x^3 + c))`, which the written-factor split above declines for a block past + // the second degree. Split at the power of x, each part goes to a rule that reads it. + if (IntegrateOverAPowerOfXBesideABlock(numerator, denominator, x, integrateByParts) is { } besideABlock) + return besideABlock; + // Last, because everything above answers in exact arithmetic where it can: a // binomial denominator the splits above could not take apart -- `x^3 + 2`, `x^5 + 1`, // `a x^3 - b` -- decomposed at its roots of unity in closed form. @@ -845,6 +851,89 @@ is var (multiple, leftover) return (total / b).Substitute(t, linear).InnerSimplified; } + /// + /// N/(x^k B), where the block B has a symbol in it and a constant term that + /// is not zero, split at the power of x. N/B has a power series at 0, and its first + /// k terms P are the part over x^k: N/(x^k B) = P/x^k + R/B, with + /// R = (N - P B)/x^k exactly. + /// + /// + /// 1/(x (x^3 + 2)) had an antiderivative and 1/(x (x^3 + c)) did not: the + /// first is split over the rationals, and the split over written factors takes linear + /// and quadratic blocks only. Rubi writes x^m (a + b x^n)^p by the hundred, and a + /// root of a square in it, 1/(x sqrt((a + b x^3)^2)), is this once its modulus is + /// taken. The constant term is divided by, in the generic case as everywhere here. + /// https://github.com/asc-community/AngouriMath/issues/718 + /// + private static Entity? IntegrateOverAPowerOfXBesideABlock(Entity numerator, Entity denominator, Entity.Variable x, bool integrateByParts) + { + var k = 0; + Entity block = Number.Integer.One; + foreach (var factor in Mulf.LinearChildren(denominator)) + { + if (factor == x) + k++; + else if (factor is Powf(var @base, Number.Integer e) && @base == x && e.EInteger.Sign > 0 && e.EInteger.CanFitInInt32()) + k += e.EInteger.ToInt32Unchecked(); + else + block = block == Number.Integer.One ? factor : block * factor; + } + if (k == 0 || k > MaximumPowerOfXBesideABlock || !block.ContainsNode(x) || !block.Vars.Any(symbol => symbol != x)) + return null; + if (!TreeAnalyzer.TryGetPolynomial(block, x, out var below) || !TreeAnalyzer.TryGetPolynomial(numerator, x, out var above)) + return null; + foreach (var term in below.Concat(above)) + if (term.Key.Sign < 0 || !term.Key.CanFitInInt32() || term.Value.ContainsNode(x)) + return null; + var degreeBelow = below.Keys.Max()!.ToInt32Unchecked(); + var degreeAbove = above.Count == 0 ? 0 : above.Keys.Max()!.ToInt32Unchecked(); + if (degreeBelow > MaximumPowerOfXBesideABlock || !below.TryGetValue(EInteger.Zero, out var constant) || VanishesIdentically(constant)) + return null; + Entity Coefficient(Dictionary polynomial, int power) + => polynomial.TryGetValue(EInteger.FromInt32(power), out var coefficient) ? coefficient : Number.Integer.Zero; + + // P: the first k terms of the power series of N/B at 0. + var series = new Entity[k]; + for (var j = 0; j < k; j++) + { + var sum = Coefficient(above, j); + for (var i = 1; i <= j; i++) + sum -= Coefficient(below, i) * series[j - i]; + series[j] = Functions.PartialFractions.InLowestTermsOverTheSymbols(sum / constant); + } + + // R = (N - P B)/x^k, whose coefficient of x^(m - k) is that of x^m in N - P B. + Entity remainder = Number.Integer.Zero; + for (var m = k; m <= System.Math.Max(degreeAbove, degreeBelow + k - 1); m++) + { + var coefficient = Coefficient(above, m); + for (var j = System.Math.Max(0, m - degreeBelow); j <= System.Math.Min(k - 1, m); j++) + coefficient -= series[j] * Coefficient(below, m - j); + coefficient = Functions.PartialFractions.InLowestTermsOverTheSymbols(coefficient); + if (!VanishesIdentically(coefficient)) + remainder += m == k ? coefficient : coefficient * MathS.Pow(x, m - k); + } + + // The part over x^k term by term, and the rest over the block as it is written. + Entity overX = Number.Integer.Zero; + for (var j = 0; j < k; j++) + if (!VanishesIdentically(series[j])) + overX += j == k - 1 + ? series[j] * IntegralPatterns.AntiderivativeLog(x) + : series[j] * MathS.Pow(x, j - k + 1) / (j - k + 1); + if (remainder == Number.Integer.Zero) + return overX; + return Integration.ComputeIndefiniteIntegral(remainder / block, x, integrateByParts) is { } overTheBlock + ? overX + overTheBlock + : null; + } + + /// + /// The largest power of x, and the largest degree of the block beside it, that + /// takes: Rubi's suite goes to twelve. + /// + private const int MaximumPowerOfXBesideABlock = 12; + /// /// A polynomial over a binomial a x^n + b, n >= 3, decomposed at the /// n-th roots of -b/a and integrated term by term in closed form. diff --git a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs index fed7dadbc..890366697 100644 --- a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs +++ b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs @@ -118,6 +118,23 @@ public void TheNumericSpellingsStillAnswer(string integrand) DifferentiatesBack(integrand, "x"); } + /// + /// A power of x beside a block of the third degree or more with a symbol in it, split at + /// the power of x: 1/(x (x^3 + c)) was declined where 1/(x (x^3 + 2)) was + /// answered. Rubi's x^m (a + b x^n)^p, by the hundred. + /// + [Theory] + [InlineData("1/(x*(x^3 + c))")] + [InlineData("1/(x^2*(x^3 + c))")] + [InlineData("1/(x*(x^3 + c)^2)")] + [InlineData("1/(x^4*(a + b*x^3))")] + [InlineData("1/(x*(a + b*x^5))")] + [InlineData("(1 + x)/(x^2*(x^3 + c))")] + [InlineData("(c + d*x + e*x^2)/(x^2*(a + b*x^3))")] + [InlineData("(c + d*x^3 + e*x^6)/(x^4*(a + b*x^3)^2)")] + public void APowerOfXBesideASymbolicBlock(string integrand) + => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3), ("c", 0.4), ("d", 1.1), ("e", 0.6)); + /// /// A repeated linear factor is one block, P/(a + b u)^k, which the rule for /// a polynomial over a power of a linear reads; Welz's 1/(a + b e^(p x))^2 is From 43f4406113b82c35cd27059f12fb931e877e83a2 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 11:01:56 +0000 Subject: [PATCH 02/12] Symbolic blocks in one power of x are split in that power Blocks that are each a polynomial in one power x^n, n >= 3, linear or quadratic in it, with a symbol among them, are split in u = x^n by the split over written factors, one residue of the numerator's powers modulo n at a time, and each fraction back in x is over one block, which the rule for a binomial reads. 1/((a + b x^3)(c + d x^3)) was declined: over the rationals it does not factor, and a block of the third degree is nothing the split over written factors reads. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 9 +- .../Integration/IndefiniteIntegralSolver.cs | 103 ++++++++++++++++++ .../SymbolicFactorsPartialFractionsTest.cs | 14 +++ 3 files changed, 124 insertions(+), 2 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index aa4d3896e..d5d0f11be 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -196,13 +196,16 @@ rules' already | `"asin(sqrt(1 + x) - sqrt(x))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in `arcsin(sqrt(1 + x) - sqrt(x))` | | `"x^3*atan(-sqrt(x)+sqrt(1+x))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in the arctangent | -### A power of `x` beside a symbolic block of the third degree or more is split off +### A power of `x` beside a symbolic block, and symbolic blocks in one power of `x`, are split **Answers where there were none.** `N/(x^k B)`, where the block `B` has a symbol in it and a constant term that is not zero, is split at the power of `x`: the first `k` terms of the power series of `N/B` at 0 are the part over `x^k`, and the rest is a polynomial over `B` exactly. The split over written factors took linear and quadratic blocks only, so `1/(x (x^3 + c))` was declined -where `1/(x (x^3 + 2))` was answered. Rubi's `x^m (a + b x^n)^p` +where `1/(x (x^3 + 2))` was answered. And blocks that are each a polynomial in one power `x^n`, +`n >= 3`, linear or quadratic in it, are split in `u = x^n`, where they are linear or quadratic +factors the split over written factors reads: `1/((a + b x^3)(c + d x^3))`. Rubi's +`x^m (a + b x^n)^p` and `(a + b x^n)^p (c + d x^n)^q` ([#718](https://github.com/asc-community/AngouriMath/issues/718)). | Input | Was (2.5.0) | Now | @@ -211,6 +214,8 @@ where `1/(x (x^3 + 2))` was answered. Rubi's `x^m (a + b x^n)^p` | `"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)` | | `"1/(x*(a + b*x^5))".Integrate("x")` | left unevaluated | `ln(x)/a - ln(a b x^5 + a^2)/(5 a)` | | `"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)` | +| `"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` | +| `"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` | ### The hyperbolic functions have antiderivatives, and so does anything rational in `e^(k x)` diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index f3173f114..684e28991 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -789,6 +789,12 @@ is var (multiple, leftover) if (IntegrateOverAPowerOfXBesideABlock(numerator, denominator, x, integrateByParts) is { } besideABlock) return besideABlock; + // Blocks that are each a polynomial in one power of x past the second, + // `1/((a + b x^3)(c + d x^3))`: split in `u = x^n`, where they are linear or quadratic, + // and each fraction back in x is over one block, which the rule for a binomial reads. + if (IntegrateOverBlocksInAPowerOfX(numerator, denominator, x, integrateByParts) is { } overBlocksInAPower) + return overBlocksInAPower; + // Last, because everything above answers in exact arithmetic where it can: a // binomial denominator the splits above could not take apart -- `x^3 + 2`, `x^5 + 1`, // `a x^3 - b` -- decomposed at its roots of unity in closed form. @@ -928,6 +934,103 @@ Entity Coefficient(Dictionary polynomial, int power) : null; } + /// + /// N/(B_1 ... B_m) where every block B_i is a polynomial in x^n for one + /// n >= 3, linear or quadratic in it, with a symbol among them: split in + /// u = x^n by , + /// one residue of the numerator's powers modulo n at a time, each fraction then + /// over one block in x. + /// + /// + /// 1/((a + b x^3)(c + d x^3)) was declined: over the rationals it does not factor, + /// and the split over written factors reads a block of the third degree as nothing. In + /// u = x^3 it is 1/((a + b u)(c + d u)), two linear factors. A numerator + /// term x^r M(x^n) keeps its x^r outside the split, which is exact since + /// the blocks are polynomials in x^n alone. + /// https://github.com/asc-community/AngouriMath/issues/718 + /// + private static Entity? IntegrateOverBlocksInAPowerOfX(Entity numerator, Entity denominator, Entity.Variable x, bool integrateByParts) + { + var blocks = new List<(Dictionary Polynomial, int Power)>(); + Entity constant = Number.Integer.One; + foreach (var factor in Mulf.LinearChildren(denominator)) + { + if (!factor.ContainsNode(x)) + { + constant = constant == Number.Integer.One ? factor : constant * factor; + continue; + } + var (@base, power) = factor is Powf(var b, Number.Integer e) && e.EInteger.Sign > 0 && e.EInteger.CanFitInInt32() + ? (b, e.EInteger.ToInt32Unchecked()) + : (factor, 1); + if (!TreeAnalyzer.TryGetPolynomial(@base, x, out var polynomial) || polynomial.Count < 2) + return null; + foreach (var term in polynomial) + if (term.Key.Sign < 0 || !term.Key.CanFitInInt32() || term.Value.ContainsNode(x)) + return null; + blocks.Add((polynomial, power)); + } + if (blocks.Count < 2 || !(numerator + denominator).Vars.Any(symbol => symbol != x)) + return null; + // n, the greatest common divisor of every power the blocks hold. + var n = EInteger.Zero; + foreach (var (polynomial, _) in blocks) + foreach (var power in polynomial.Keys) + n = n.Gcd(power); + if (n.CompareTo(EInteger.FromInt32(3)) < 0 || n.CompareTo(EInteger.FromInt32(MaximumPowerOfXBesideABlock)) > 0) + return null; + var step = n.ToInt32Unchecked(); + foreach (var (polynomial, _) in blocks) + if (polynomial.Keys.Max()!.ToInt32Unchecked() / step > 2) + return null; + if (!TreeAnalyzer.TryGetPolynomial(numerator, x, out var above)) + return null; + foreach (var term in above) + if (term.Key.Sign < 0 || !term.Key.CanFitInInt32() || term.Value.ContainsNode(x)) + return null; + + var u = Entity.Variable.CreateUnique(numerator + denominator, "u"); + Entity InU(Dictionary polynomial) + { + Entity sum = Number.Integer.Zero; + foreach (var (power, coefficient) in polynomial.OrderBy(term => term.Key)) + { + var degree = power.ToInt32Unchecked() / step; + var term = degree == 0 ? coefficient : coefficient * (degree == 1 ? u : MathS.Pow(u, degree)); + sum = sum == Number.Integer.Zero ? term : sum + term; + } + return sum; + } + Entity below = constant; + foreach (var (polynomial, power) in blocks) + { + var block = InU(polynomial); + below = below == Number.Integer.One ? (power == 1 ? block : MathS.Pow(block, power)) : below * (power == 1 ? block : MathS.Pow(block, power)); + } + + Entity total = Number.Integer.Zero; + foreach (var residue in above.GroupBy(term => term.Key.ToInt32Unchecked() % step)) + { + Entity inU = Number.Integer.Zero; + foreach (var (power, coefficient) in residue) + { + var degree = power.ToInt32Unchecked() / step; + inU += degree == 0 ? coefficient : coefficient * MathS.Pow(u, degree); + } + if (!Functions.PartialFractions.TrySplitOverWrittenFactors(inU, below, u, out var decomposition)) + return null; + var outside = residue.Key == 0 ? (Entity)Number.Integer.One : residue.Key == 1 ? x : MathS.Pow(x, residue.Key); + foreach (var fraction in Sumf.LinearChildren(decomposition)) + { + var inX = outside * fraction.Substitute(u, MathS.Pow(x, step)); + if (Integration.ComputeIndefiniteIntegral(inX, x, integrateByParts) is not { } integrated) + return null; + total += integrated; + } + } + return total; + } + /// /// The largest power of x, and the largest degree of the block beside it, that /// takes: Rubi's suite goes to twelve. diff --git a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs index 890366697..ae2672b42 100644 --- a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs +++ b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs @@ -135,6 +135,20 @@ public void TheNumericSpellingsStillAnswer(string integrand) public void APowerOfXBesideASymbolicBlock(string integrand) => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3), ("c", 0.4), ("d", 1.1), ("e", 0.6)); + /// + /// Blocks that are each a polynomial in one power of x past the second, split in + /// u = x^n, where they are linear: 1/((a + b x^3)(c + d x^3)) was declined. + /// With a power of x beside them as well, both splits in turn. + /// + [Theory] + [InlineData("1/((a + b*x^3)*(c + d*x^3))")] + [InlineData("x/((a + b*x^3)*(c + d*x^3))")] + [InlineData("x^4/((a + b*x^3)*(c + d*x^3))")] + [InlineData("1/((a + b*x^4)*(c + d*x^4))")] + [InlineData("1/(x^2*(a + b*x^3)*(c + d*x^3))")] + public void SymbolicBlocksInOnePowerOfX(string integrand) + => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3), ("c", 0.4), ("d", 1.1)); + /// /// A repeated linear factor is one block, P/(a + b u)^k, which the rule for /// a polynomial over a power of a linear reads; Welz's 1/(a + b e^(p x))^2 is From 73c7f335cacbe5ab07611ca235374b5e5d732769 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 11:07:09 +0000 Subject: [PATCH 03/12] A quotient with x below a bar inside it is written over one bar Every rule the partial fractions try reads the numerator and the denominator as polynomials, and `a + b/x` is not one, so 1/(a + b/x) was declined where x/(a x + b) was answered, and so was the numeric 1/(2 + 3/x^2)^3. Such a quotient is written over one bar first. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 10 +++++++--- .../Integration/IndefiniteIntegralSolver.cs | 18 ++++++++++++++++++ .../SymbolicFactorsPartialFractionsTest.cs | 13 +++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index d5d0f11be..219fe88be 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -196,7 +196,7 @@ rules' already | `"asin(sqrt(1 + x) - sqrt(x))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in `arcsin(sqrt(1 + x) - sqrt(x))` | | `"x^3*atan(-sqrt(x)+sqrt(1+x))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in the arctangent | -### A power of `x` beside a symbolic block, and symbolic blocks in one power of `x`, are split +### A power of `x` beside a symbolic block, and symbolic blocks in one power of `x`, are split, and `1/(a + b/x)` is read **Answers where there were none.** `N/(x^k B)`, where the block `B` has a symbol in it and a constant term that is not zero, is split at the power of `x`: the first `k` terms of the power @@ -204,8 +204,10 @@ series of `N/B` at 0 are the part over `x^k`, and the rest is a polynomial over split over written factors took linear and quadratic blocks only, so `1/(x (x^3 + c))` was declined where `1/(x (x^3 + 2))` was answered. And blocks that are each a polynomial in one power `x^n`, `n >= 3`, linear or quadratic in it, are split in `u = x^n`, where they are linear or quadratic -factors the split over written factors reads: `1/((a + b x^3)(c + d x^3))`. Rubi's -`x^m (a + b x^n)^p` and `(a + b x^n)^p (c + d x^n)^q` +factors the split over written factors reads: `1/((a + b x^3)(c + d x^3))`. And a quotient with +`x` below a bar inside it is written over one bar first, since every rule after it reads polynomials: +`1/(a + b/x)` was declined where `x/(a x + b)` was answered. Rubi's `x^m (a + b x^n)^p` and +`(a + b x^n)^p (c + d x^n)^q` ([#718](https://github.com/asc-community/AngouriMath/issues/718)). | Input | Was (2.5.0) | Now | @@ -216,6 +218,8 @@ factors the split over written factors reads: `1/((a + b x^3)(c + d x^3))`. Rubi | `"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)` | | `"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` | | `"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` | +| `"1/(a+b/x)".Integrate("x")` | left unevaluated | `x/a - b ln(a x + b)/a^2` | +| `"1/(2+3/x^2)^3".Integrate("x")`, `1/(a + b/x^3)` | left unevaluated | an antiderivative | ### The hyperbolic functions have antiderivatives, and so does anything rational in `e^(k x)` diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 684e28991..2372c1536 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -626,6 +626,16 @@ Entity Back(Entity mapped) if (!TryReadAsQuotient(expr, out var numerator, out var denominator)) return null; + // A quotient with x below a bar inside it, `1/(a + b/x)`, written over one bar: every + // rule below reads the numerator and the denominator as polynomials, and `a + b/x` is + // not one, where `x/(a x + b)` is read at once. Once: what one bar gives has none. + if ((HasTheVariableBelowABar(numerator, x) || HasTheVariableBelowABar(denominator, x)) + && Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(expr)) is var (top, bottom) + && !HasTheVariableBelowABar(top, x) && !HasTheVariableBelowABar(bottom, x) + && bottom.ContainsNode(x)) + return SolveByPartialFractions(top / bottom, x, integrateByParts) + ?? Integration.ComputeIndefiniteIntegral(top / bottom, x, integrateByParts); + // The helper answers null for a fraction that is already proper, so this cannot // fire on one and recurse into the problem it started from. The check on the // quotient is the second half of that guarantee: a division that came back with @@ -1326,6 +1336,14 @@ node is Powf(var radicand, Number.Rational r) && r is not Number.Integer && radi return RothsteinTrager.Integrate(numerator, denominator, x); } + /// + /// Whether stands below a bar somewhere inside + /// : in a divisor, or under a negative whole power. + /// + private static bool HasTheVariableBelowABar(Entity expr, Entity.Variable x) + => expr.Nodes.Any(node => node is Entity.Divf(_, var divisor) && divisor.ContainsNode(x) + || node is Entity.Powf(var @base, Number.Integer { EInteger.Sign: < 0 }) && @base.ContainsNode(x)); + private static bool TryReadAsQuotient(Entity expr, out Entity numerator, out Entity denominator) { // An exponent read evaluated: the normalisation writes `(u^2 - 1)^5` below the bar diff --git a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs index ae2672b42..68d1ecfe2 100644 --- a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs +++ b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs @@ -149,6 +149,19 @@ public void APowerOfXBesideASymbolicBlock(string integrand) public void SymbolicBlocksInOnePowerOfX(string integrand) => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3), ("c", 0.4), ("d", 1.1)); + /// + /// A quotient with x below a bar inside it is written over one bar first: + /// 1/(a + b/x) was declined where x/(a x + b) was answered, and so was the + /// numeric 1/(2 + 3/x^2)^3. + /// + [Theory] + [InlineData("1/(a + b/x)")] + [InlineData("1/(a + b/x^2)^2")] + [InlineData("1/(a + b/x^3)")] + [InlineData("1/(2 + 3/x^2)^3")] + public void AQuotientWithXBelowABarInsideIt(string integrand) + => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3)); + /// /// A repeated linear factor is one block, P/(a + b u)^k, which the rule for /// a polynomial over a power of a linear reads; Welz's 1/(a + b e^(p x))^2 is From 685b1178233755bacab9cd1c56cc004c29cc47b8 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 11:18:33 +0000 Subject: [PATCH 04/12] A product of sums in a symbolic power of x is written out (a + b x^n)(c + d x^n)^3 had no antiderivative, and written out it is eight powers of x, each answered at once: no rule reads a power of x whose exponent is a symbol as a polynomial, and the rule that writes out a power takes one power and not a product of them. A product whose factors with x in them are sums, positive whole powers of sums and powers of x is written out now, as late as that rule and for the same reason. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 4 +- .../Integration/IndefiniteIntegralSolver.cs | 44 +++++++++++++++++++ .../Integration/Integration.Definition.cs | 2 + .../SymbolicFactorsPartialFractionsTest.cs | 10 +++++ 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 219fe88be..90a7ca6d9 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -206,7 +206,8 @@ where `1/(x (x^3 + 2))` was answered. And blocks that are each a polynomial in o `n >= 3`, linear or quadratic in it, are split in `u = x^n`, where they are linear or quadratic factors the split over written factors reads: `1/((a + b x^3)(c + d x^3))`. And a quotient with `x` below a bar inside it is written over one bar first, since every rule after it reads polynomials: -`1/(a + b/x)` was declined where `x/(a x + b)` was answered. Rubi's `x^m (a + b x^n)^p` and +`1/(a + b/x)` was declined where `x/(a x + b)` was answered. And a product of sums in `x^n` with a +symbol for `n` is written out, as a power of one already was. Rubi's `x^m (a + b x^n)^p` and `(a + b x^n)^p (c + d x^n)^q` ([#718](https://github.com/asc-community/AngouriMath/issues/718)). @@ -220,6 +221,7 @@ factors the split over written factors reads: `1/((a + b x^3)(c + d x^3))`. And | `"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` | | `"1/(a+b/x)".Integrate("x")` | left unevaluated | `x/a - b ln(a x + b)/a^2` | | `"1/(2+3/x^2)^3".Integrate("x")`, `1/(a + b/x^3)` | left unevaluated | an antiderivative | +| `"(a+b*x^n)*(c+d*x^n)^3".Integrate("x")` | left unevaluated | written out, eight powers of `x` integrated: `a c^3 x + ... + b d^3 x^(4 n + 1)/(4 n + 1)` | ### The hyperbolic functions have antiderivatives, and so does anything rational in `e^(k x)` diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 2372c1536..54b028654 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -16110,6 +16110,50 @@ bool IsAConstantTimesAPowerOfOneMinusUSquared(Entity polynomial, out Entity cons return Integration.ComputeIndefiniteIntegral(written, x, integrateByParts); } + /// + /// A product of sums, of positive whole powers of sums and of powers of the variable, + /// written out and integrated term by term. + /// + /// + /// (a + b x^n)(c + d x^n)^3 had no antiderivative, and written out it is eight + /// powers of x, each answered at once: no rule reads a power of x whose exponent is a + /// symbol as a polynomial, and the rule above writes out one power and not a product of + /// them. As late as that one, and for the same reason: a product that a rule answers in + /// its own terms is not written out. Only where every factor with x in it is a sum, a + /// positive whole power of one, or a power of x itself, so that writing it out is a finite + /// identity, bounded by . + /// https://github.com/asc-community/AngouriMath/issues/718 + /// + internal static Entity? SolveByExpandingAProductOfSums(Entity expr, Entity.Variable x, bool integrateByParts) + { + if (expr is not Mulf) + return null; + var sums = 0; + foreach (var factor in Mulf.LinearChildren(expr)) + { + if (!factor.ContainsNode(x)) + continue; + switch (factor) + { + case Sumf or Minusf: + case Powf(Sumf or Minusf, Number.Integer power) when power.EInteger.CompareTo(EInteger.One) > 0: + sums++; + break; + case Entity.Variable when factor == x: + case Powf(var @base, var exponent) when @base == x && !exponent.ContainsNode(x): + break; + default: + return null; + } + } + if (sums == 0) + return null; + var written = expr.Expand(); + if (written is not Sumf and not Minusf) + return null; + return Integration.ComputeIndefiniteIntegral(written, x, integrateByParts); + } + /// /// Several square roots of polynomials in the variable, written as one: /// sqrt(1 + x^2) sqrt(1 - x^2) is sqrt(1 - x^4), and a root below the bar diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs index 5889a488e..b8efc187f 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs @@ -1052,6 +1052,8 @@ private static Entity Normalized(Entity expr, Entity.Variable x) => // throws away whatever structure it had: (1 + x^2)^2 is answered as a power and only // wants writing out if that fails. if ((answer = IndefiniteIntegralSolver.SolveByExpandingAPower(expr, x, integrateByParts)) is { }) return answer; + // And a product of such powers and sums, written out for the same reason and as late. + if ((answer = IndefiniteIntegralSolver.SolveByExpandingAProductOfSums(expr, x, integrateByParts)) is { }) return answer; // The sign of a real-valued factor is constant between its zeros, and goes in // front of the antiderivative of the rest. After every rule that reads the sign // where it stands: `cos(x) sgn(sin(x))` is `|sin(x)|` by the substitution, and diff --git a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs index 68d1ecfe2..c06f5061a 100644 --- a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs +++ b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs @@ -162,6 +162,16 @@ public void SymbolicBlocksInOnePowerOfX(string integrand) public void AQuotientWithXBelowABarInsideIt(string integrand) => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3)); + /// + /// A product of sums in a power of x whose exponent is a symbol, written out: each term is + /// a power of x, answered at once, and no rule reads the product as a polynomial. + /// + [Theory] + [InlineData("(a + b*x^n)*(c + d*x^n)^3")] + [InlineData("(c + d*x^(n - 1))*(a + b*x^n)^3")] + public void AProductOfSumsInASymbolicPowerOfX(string integrand) + => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3), ("c", 0.4), ("d", 1.1), ("n", 1.3)); + /// /// A repeated linear factor is one block, P/(a + b u)^k, which the rule for /// a polynomial over a power of a linear reads; Welz's 1/(a + b e^(p x))^2 is From 11c8500e33308d0f06db897dd3aca3f05b6ac0f6 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 11:35:02 +0000 Subject: [PATCH 05/12] The one bar takes out the power of x it put in Writing 1/((a + c/x^2 + b/x) x (d + e x)^2) over one bar clears its bars with a power of x, and leaves x^3/(x^2 Q L^2): the rules after it read the two sides as coprime, and answered that wrongly. The greatest power of x dividing both is taken out of each, the denominator's factors kept as written. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- .../Integration/IndefiniteIntegralSolver.cs | 75 ++++++++++++++++++- .../SymbolicFactorsPartialFractionsTest.cs | 8 +- 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 54b028654..6e4f32c48 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -629,12 +629,16 @@ Entity Back(Entity mapped) // A quotient with x below a bar inside it, `1/(a + b/x)`, written over one bar: every // rule below reads the numerator and the denominator as polynomials, and `a + b/x` is // not one, where `x/(a x + b)` is read at once. Once: what one bar gives has none. + // What the bars were cleared with is a power of x on both sides, `x^3/(x^2 Q L^2)` for + // `1/((a + b/x + c/x^2) x L^2)`, and it is cancelled: the rules below read a numerator + // and a denominator with a common factor as coprime, and answered that one wrongly. if ((HasTheVariableBelowABar(numerator, x) || HasTheVariableBelowABar(denominator, x)) && Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(expr)) is var (top, bottom) && !HasTheVariableBelowABar(top, x) && !HasTheVariableBelowABar(bottom, x) - && bottom.ContainsNode(x)) - return SolveByPartialFractions(top / bottom, x, integrateByParts) - ?? Integration.ComputeIndefiniteIntegral(top / bottom, x, integrateByParts); + && bottom.ContainsNode(x) + && WithoutACommonPowerOfX(top, bottom, x) is var (reducedTop, reducedBottom)) + return SolveByPartialFractions(reducedTop / reducedBottom, x, integrateByParts) + ?? Integration.ComputeIndefiniteIntegral(reducedTop / reducedBottom, x, integrateByParts); // The helper answers null for a fraction that is already proper, so this cannot // fire on one and recurse into the problem it started from. The check on the @@ -1336,6 +1340,71 @@ node is Powf(var radicand, Number.Rational r) && r is not Number.Integer && radi return RothsteinTrager.Integrate(numerator, denominator, x); } + /// + /// over with the greatest + /// power of that divides both taken out of each, the denominator's + /// factors kept as written; the two unchanged where none does, or where a side is not a + /// polynomial in . + /// + private static (Entity Numerator, Entity Denominator) WithoutACommonPowerOfX(Entity numerator, Entity denominator, Entity.Variable x) + { + static int LowestPower(Dictionary polynomial) + => polynomial.Keys.Min()!.ToInt32Unchecked(); + if (!TreeAnalyzer.TryGetPolynomial(numerator, x, out var above) || above.Count == 0 + || above.Keys.Any(power => power.Sign < 0 || !power.CanFitInInt32())) + return (numerator, denominator); + var factors = new List<(Dictionary? Polynomial, Entity Written, int Power, int Lowest)>(); + var available = 0; + foreach (var factor in Mulf.LinearChildren(denominator)) + { + var (@base, power) = factor is Powf(var b, Number.Integer e) && e.EInteger.Sign > 0 && e.EInteger.CanFitInInt32() + ? (b, e.EInteger.ToInt32Unchecked()) + : (factor, 1); + if (!@base.ContainsNode(x)) + { + factors.Add((null, factor, 1, 0)); + continue; + } + if (!TreeAnalyzer.TryGetPolynomial(@base, x, out var polynomial) || polynomial.Count == 0 + || polynomial.Keys.Any(k => k.Sign < 0 || !k.CanFitInInt32())) + return (numerator, denominator); + var lowest = LowestPower(polynomial); + factors.Add((polynomial, factor, power, lowest)); + available += lowest * power; + } + var common = System.Math.Min(LowestPower(above), available); + if (common == 0) + return (numerator, denominator); + Entity Shifted(Dictionary polynomial, int by) + { + Entity sum = Number.Integer.Zero; + foreach (var (power, coefficient) in polynomial.OrderBy(term => term.Key)) + { + var degree = power.ToInt32Unchecked() - by; + var term = degree == 0 ? coefficient : coefficient * (degree == 1 ? x : MathS.Pow(x, degree)); + sum = sum == Number.Integer.Zero ? term : sum + term; + } + return sum; + } + var left = common; + Entity below = Number.Integer.One; + foreach (var (polynomial, written, power, lowest) in factors) + { + Entity kept = written; + if (polynomial is not null && lowest > 0 && left >= lowest * power) + { + var @base = Shifted(polynomial, lowest); + kept = power == 1 ? @base : MathS.Pow(@base, power); + left -= lowest * power; + } + if (kept != Number.Integer.One) + below = below == Number.Integer.One ? kept : below * kept; + } + // Whatever could not come out of a factor whole stays below the bar as written. + var taken = common - left; + return taken == 0 ? (numerator, denominator) : (Shifted(above, taken), below); + } + /// /// Whether stands below a bar somewhere inside /// : in a divisor, or under a negative whole power. diff --git a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs index c06f5061a..dc29fc796 100644 --- a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs +++ b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs @@ -152,15 +152,19 @@ public void SymbolicBlocksInOnePowerOfX(string integrand) /// /// A quotient with x below a bar inside it is written over one bar first: /// 1/(a + b/x) was declined where x/(a x + b) was answered, and so was the - /// numeric 1/(2 + 3/x^2)^3. + /// numeric 1/(2 + 3/x^2)^3. The power of x the bars were cleared with is taken out + /// of both sides again, since the rules after it read the two as coprime: Rubi's + /// 1/((a + c/x^2 + b/x) x (d + e x)^2) was answered wrongly without that. /// [Theory] [InlineData("1/(a + b/x)")] [InlineData("1/(a + b/x^2)^2")] [InlineData("1/(a + b/x^3)")] [InlineData("1/(2 + 3/x^2)^3")] + [InlineData("1/((a + c/x^2 + b/x)*x*(d + e*x)^2)")] + [InlineData("x^2/((a + c/x^2 + b/x)*(d + e*x)^2)")] public void AQuotientWithXBelowABarInsideIt(string integrand) - => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3)); + => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3), ("c", 0.4), ("d", 1.1), ("e", 0.6)); /// /// A product of sums in a power of x whose exponent is a symbol, written out: each term is From 513b297abf23a5123b377e1259dc274ae586bc0a Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 11:38:36 +0000 Subject: [PATCH 06/12] One symbolic block quadratic in a power of x is split at its roots a + b x^n + c x^(2n), n >= 3, with a symbol in it, is c (u - r_1)(u - r_2) in u = x^n, and the split in u takes the two factors as it takes two blocks, each then a binomial in x: 1/(a + b x^3 + c x^6) and (1 + x^4)/(1 + b x^4 + x^8) were declined, where a + b x^2 + c x^4 was answered that way already. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 4 ++- .../Integration/IndefiniteIntegralSolver.cs | 27 +++++++++++++++---- .../SymbolicFactorsPartialFractionsTest.cs | 7 ++++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 90a7ca6d9..4ea002291 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -204,7 +204,8 @@ series of `N/B` at 0 are the part over `x^k`, and the rest is a polynomial over split over written factors took linear and quadratic blocks only, so `1/(x (x^3 + c))` was declined where `1/(x (x^3 + 2))` was answered. And blocks that are each a polynomial in one power `x^n`, `n >= 3`, linear or quadratic in it, are split in `u = x^n`, where they are linear or quadratic -factors the split over written factors reads: `1/((a + b x^3)(c + d x^3))`. And a quotient with +factors the split over written factors reads: `1/((a + b x^3)(c + d x^3))`; one block quadratic in +`u` is two at its roots, as `a + b x^2 + c x^4` already was. And a quotient with `x` below a bar inside it is written over one bar first, since every rule after it reads polynomials: `1/(a + b/x)` was declined where `x/(a x + b)` was answered. And a product of sums in `x^n` with a symbol for `n` is written out, as a power of one already was. Rubi's `x^m (a + b x^n)^p` and @@ -219,6 +220,7 @@ symbol for `n` is written out, as a power of one already was. Rubi's `x^m (a + b | `"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)` | | `"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` | | `"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` | +| `"1/(a+b*x^3+c*x^6)".Integrate("x")`, `(1 + x^4)/(1 + b x^4 + x^8)` | left unevaluated | the same, at the two roots of the quadratic in `x^n`, over `sqrt(b^2 - 4 a c)` | | `"1/(a+b/x)".Integrate("x")` | left unevaluated | `x/a - b ln(a x + b)/a^2` | | `"1/(2+3/x^2)^3".Integrate("x")`, `1/(a + b/x^3)` | left unevaluated | an antiderivative | | `"(a+b*x^n)*(c+d*x^n)^3".Integrate("x")` | left unevaluated | written out, eight powers of `x` integrated: `a c^3 x + ... + b d^3 x^(4 n + 1)/(4 n + 1)` | diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 6e4f32c48..ce3d96dc8 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -984,7 +984,7 @@ Entity Coefficient(Dictionary polynomial, int power) return null; blocks.Add((polynomial, power)); } - if (blocks.Count < 2 || !(numerator + denominator).Vars.Any(symbol => symbol != x)) + if (blocks.Count == 0 || !(numerator + denominator).Vars.Any(symbol => symbol != x)) return null; // n, the greatest common divisor of every power the blocks hold. var n = EInteger.Zero; @@ -1015,12 +1015,29 @@ Entity InU(Dictionary polynomial) } return sum; } - Entity below = constant; - foreach (var (polynomial, power) in blocks) + var inUBlocks = blocks.Select(pair => (Block: InU(pair.Polynomial), pair.Power)).ToList(); + // One block, quadratic in u, is two at its roots: `a + b u + c u^2` is + // `c (u - r_1)(u - r_2)` with `r = (-b ± sqrt(b^2 - 4 a c))/(2 c)`, exact wherever the + // two differ, which is the generic case; a discriminant that is zero as written declines. + if (inUBlocks.Count == 1) { - var block = InU(polynomial); - below = below == Number.Integer.One ? (power == 1 ? block : MathS.Pow(block, power)) : below * (power == 1 ? block : MathS.Pow(block, power)); + var (polynomial, power) = blocks[0]; + if (polynomial.Keys.Max()!.ToInt32Unchecked() != 2 * step) + return null; + Entity At(int degree) => polynomial.TryGetValue(EInteger.FromInt32(degree * step), out var coefficient) ? coefficient : Number.Integer.Zero; + var (a, b, c) = (At(0), At(1), At(2)); + var discriminant = b * b - 4 * a * c; + if (VanishesIdentically(discriminant)) + return null; + var root = MathS.Sqrt(discriminant); + var first = Functions.PartialFractions.InLowestTermsOverTheSymbols((-b + root) / (2 * c)); + var second = Functions.PartialFractions.InLowestTermsOverTheSymbols((-b - root) / (2 * c)); + constant = constant == Number.Integer.One ? (power == 1 ? c : MathS.Pow(c, power)) : constant * (power == 1 ? c : MathS.Pow(c, power)); + inUBlocks = [(u - first, power), (u - second, power)]; } + Entity below = constant; + foreach (var (block, power) in inUBlocks) + below = below == Number.Integer.One ? (power == 1 ? block : MathS.Pow(block, power)) : below * (power == 1 ? block : MathS.Pow(block, power)); Entity total = Number.Integer.Zero; foreach (var residue in above.GroupBy(term => term.Key.ToInt32Unchecked() % step)) diff --git a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs index dc29fc796..e40a7f586 100644 --- a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs +++ b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs @@ -138,7 +138,8 @@ public void APowerOfXBesideASymbolicBlock(string integrand) /// /// Blocks that are each a polynomial in one power of x past the second, split in /// u = x^n, where they are linear: 1/((a + b x^3)(c + d x^3)) was declined. - /// With a power of x beside them as well, both splits in turn. + /// With a power of x beside them as well, both splits in turn; and one block quadratic in + /// u is split at its two roots. /// [Theory] [InlineData("1/((a + b*x^3)*(c + d*x^3))")] @@ -146,6 +147,10 @@ public void APowerOfXBesideASymbolicBlock(string integrand) [InlineData("x^4/((a + b*x^3)*(c + d*x^3))")] [InlineData("1/((a + b*x^4)*(c + d*x^4))")] [InlineData("1/(x^2*(a + b*x^3)*(c + d*x^3))")] + // One block quadratic in x^n is two at its roots. + [InlineData("1/(a + b*x^3 + c*x^6)")] + [InlineData("x/(a + b*x^3 + c*x^6)")] + [InlineData("(1 + x^4)/(1 + b*x^4 + x^8)")] public void SymbolicBlocksInOnePowerOfX(string integrand) => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3), ("c", 0.4), ("d", 1.1)); From 153afd117b6b85ec63b1d94a6f957b89665ffa0e Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 11:59:10 +0000 Subject: [PATCH 07/12] Two symbolic blocks or more in x^2 are split in it too The split over written factors reads a block of x^2 only while it is quadratic in x, so 1/(x^4 (d + e x^2)(a + c x^4)) was declined. The split in u = x^n takes n = 2 as well where there are two blocks or more; one quadratic in x^2 alone stays the biquadratic rule's. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 4 +++- .../Continuous/Integration/IndefiniteIntegralSolver.cs | 6 ++++-- .../Calculus/SymbolicFactorsPartialFractionsTest.cs | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 4ea002291..5b8658bee 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -203,7 +203,8 @@ constant term that is not zero, is split at the power of `x`: the first `k` term series of `N/B` at 0 are the part over `x^k`, and the rest is a polynomial over `B` exactly. The split over written factors took linear and quadratic blocks only, so `1/(x (x^3 + c))` was declined where `1/(x (x^3 + 2))` was answered. And blocks that are each a polynomial in one power `x^n`, -`n >= 3`, linear or quadratic in it, are split in `u = x^n`, where they are linear or quadratic +`n >= 3`, or `n = 2` for two blocks or more, linear or quadratic in it, are split in +`u = x^n`, where they are linear or quadratic factors the split over written factors reads: `1/((a + b x^3)(c + d x^3))`; one block quadratic in `u` is two at its roots, as `a + b x^2 + c x^4` already was. And a quotient with `x` below a bar inside it is written over one bar first, since every rule after it reads polynomials: @@ -221,6 +222,7 @@ symbol for `n` is written out, as a power of one already was. Rubi's `x^m (a + b | `"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` | | `"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` | | `"1/(a+b*x^3+c*x^6)".Integrate("x")`, `(1 + x^4)/(1 + b x^4 + x^8)` | left unevaluated | the same, at the two roots of the quadratic in `x^n`, over `sqrt(b^2 - 4 a c)` | +| `"1/(x^4*(d+e*x^2)*(a+c*x^4))".Integrate("x")` | left unevaluated | powers of `x`, an arctangent over `d + e x^2`, and the biquadratic's arctangents | | `"1/(a+b/x)".Integrate("x")` | left unevaluated | `x/a - b ln(a x + b)/a^2` | | `"1/(2+3/x^2)^3".Integrate("x")`, `1/(a + b/x^3)` | left unevaluated | an antiderivative | | `"(a+b*x^n)*(c+d*x^n)^3".Integrate("x")` | left unevaluated | written out, eight powers of `x` integrated: `a c^3 x + ... + b d^3 x^(4 n + 1)/(4 n + 1)` | diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index ce3d96dc8..f35732c11 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -950,7 +950,7 @@ Entity Coefficient(Dictionary polynomial, int power) /// /// N/(B_1 ... B_m) where every block B_i is a polynomial in x^n for one - /// n >= 3, linear or quadratic in it, with a symbol among them: split in + /// n >= 2, linear or quadratic in it, with a symbol among them: split in /// u = x^n by , /// one residue of the numerator's powers modulo n at a time, each fraction then /// over one block in x. @@ -991,7 +991,9 @@ Entity Coefficient(Dictionary polynomial, int power) foreach (var (polynomial, _) in blocks) foreach (var power in polynomial.Keys) n = n.Gcd(power); - if (n.CompareTo(EInteger.FromInt32(3)) < 0 || n.CompareTo(EInteger.FromInt32(MaximumPowerOfXBesideABlock)) > 0) + // In x^2 for two blocks or more only: one quadratic in x^2 is the biquadratic rule's. + if (n.CompareTo(EInteger.FromInt32(2)) < 0 || n.Equals(EInteger.FromInt32(2)) && blocks.Count < 2 + || n.CompareTo(EInteger.FromInt32(MaximumPowerOfXBesideABlock)) > 0) return null; var step = n.ToInt32Unchecked(); foreach (var (polynomial, _) in blocks) diff --git a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs index e40a7f586..089f1fc11 100644 --- a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs +++ b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs @@ -151,6 +151,8 @@ public void APowerOfXBesideASymbolicBlock(string integrand) [InlineData("1/(a + b*x^3 + c*x^6)")] [InlineData("x/(a + b*x^3 + c*x^6)")] [InlineData("(1 + x^4)/(1 + b*x^4 + x^8)")] + // Two blocks in x^2, which the split over written factors reads only while both are quadratic. + [InlineData("1/(x^4*(d + e*x^2)*(a + c*x^4))")] public void SymbolicBlocksInOnePowerOfX(string integrand) => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3), ("c", 0.4), ("d", 1.1)); From ad27b796774d6792192be68ef0378452f60a5052 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 11:59:27 +0000 Subject: [PATCH 08/12] The breaking-changes entry for the rational functions in x^n, written as one list Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 5b8658bee..2ee6738eb 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -196,21 +196,22 @@ rules' already | `"asin(sqrt(1 + x) - sqrt(x))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in `arcsin(sqrt(1 + x) - sqrt(x))` | | `"x^3*atan(-sqrt(x)+sqrt(1+x))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in the arctangent | -### A power of `x` beside a symbolic block, and symbolic blocks in one power of `x`, are split, and `1/(a + b/x)` is read - -**Answers where there were none.** `N/(x^k B)`, where the block `B` has a symbol in it and a -constant term that is not zero, is split at the power of `x`: the first `k` terms of the power -series of `N/B` at 0 are the part over `x^k`, and the rest is a polynomial over `B` exactly. The -split over written factors took linear and quadratic blocks only, so `1/(x (x^3 + c))` was declined -where `1/(x (x^3 + 2))` was answered. And blocks that are each a polynomial in one power `x^n`, -`n >= 3`, or `n = 2` for two blocks or more, linear or quadratic in it, are split in -`u = x^n`, where they are linear or quadratic -factors the split over written factors reads: `1/((a + b x^3)(c + d x^3))`; one block quadratic in -`u` is two at its roots, as `a + b x^2 + c x^4` already was. And a quotient with -`x` below a bar inside it is written over one bar first, since every rule after it reads polynomials: -`1/(a + b/x)` was declined where `x/(a x + b)` was answered. And a product of sums in `x^n` with a -symbol for `n` is written out, as a power of one already was. Rubi's `x^m (a + b x^n)^p` and -`(a + b x^n)^p (c + d x^n)^q` +### Rational functions of `x` and `x^n` with symbols in them are taken apart + +**Answers where there were none.** The partial fractions took apart a denominator with symbols in it +only where its factors were linear or quadratic, so `1/(x (x^3 + c))` was declined where +`1/(x (x^3 + 2))` was answered. Now: +- a power of `x` beside a block `B` whose constant term is not zero is split off: the first `k` + terms of the power series of `N/B` at 0 are the part over `x^k`, and the rest is a polynomial + over `B` exactly; +- blocks that are each a polynomial in one power `x^n` are split in `u = x^n`, where they are linear + or quadratic, for `n >= 3`, or `n = 2` with two blocks or more; one block quadratic in `u` is two + at its roots, as `a + b x^2 + c x^4` already was; +- a quotient with `x` below a bar inside it, `1/(a + b/x)`, is written over one bar first, and the + power of `x` that cleared the bars is taken out of both sides again; +- a product of sums in `x^n` with a symbol for `n` is written out, as a power of one already was. + +Rubi's `x^m (a + b x^n)^p` and `(a + b x^n)^p (c + d x^n)^q` ([#718](https://github.com/asc-community/AngouriMath/issues/718)). | Input | Was (2.5.0) | Now | From ee7faa57017c5a75dd8d8760bd6d9f929cceeefe Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 13:49:13 +0000 Subject: [PATCH 09/12] One block in a power of x is split at its roots last The roots of a + b u + c u^2 are complex where b^2 < 4ac, and every fraction after the split is over a binomial x^n - r with one in it. A rule after the split that branches on the sign of r has no branch for a complex one: (d + e x^4)/(x^3 (a + b x^4 + c x^8)) came to x/(x^4 - r), and the table's piecewise on the sign of r had no value at any point, where the substitution v = x^2 answers the block whole. The split of one block is now its own rule, after every other, so that whatever answers the block whole answers first. The examples it was for are still answered, at either sign of the discriminant. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- .../Integration/IndefiniteIntegralSolver.cs | 29 ++++++++++++++++++- .../Integration/Integration.Definition.cs | 3 ++ .../SymbolicFactorsPartialFractionsTest.cs | 13 +++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index f35732c11..93e7deca5 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -963,7 +963,7 @@ Entity Coefficient(Dictionary polynomial, int power) /// the blocks are polynomials in x^n alone. /// https://github.com/asc-community/AngouriMath/issues/718 /// - private static Entity? IntegrateOverBlocksInAPowerOfX(Entity numerator, Entity denominator, Entity.Variable x, bool integrateByParts) + private static Entity? IntegrateOverBlocksInAPowerOfX(Entity numerator, Entity denominator, Entity.Variable x, bool integrateByParts, bool oneBlockAtItsRoots = false) { var blocks = new List<(Dictionary Polynomial, int Power)>(); Entity constant = Number.Integer.One; @@ -1023,6 +1023,13 @@ Entity InU(Dictionary polynomial) // two differ, which is the generic case; a discriminant that is zero as written declines. if (inUBlocks.Count == 1) { + // Last, from SolveByOneBlockInAPowerOfXAtItsRoots: the roots are complex where + // b^2 < 4ac, and a rule after the split that branches on the sign of one has no + // branch for it. `x (a + b x^4)/(c + d x^4 + e x^8)` comes to `x/(x^4 - r)`, and the + // table's piecewise on the sign of `r` has no value anywhere for a complex `r`, + // where the substitution `v = x^2` answers the block whole. + if (!oneBlockAtItsRoots) + return null; var (polynomial, power) = blocks[0]; if (polynomial.Keys.Max()!.ToInt32Unchecked() != 2 * step) return null; @@ -16198,6 +16205,26 @@ bool IsAConstantTimesAPowerOfOneMinusUSquared(Entity polynomial, out Entity cons return Integration.ComputeIndefiniteIntegral(written, x, integrateByParts); } + /// + /// A rational function over one block quadratic in a power of x, a + b x^n + c x^(2n) + /// with a symbol in it, split at the block's roots in u = x^n: the single block + /// leaves to this. + /// + /// + /// The roots are (-b ± sqrt(b^2 - 4ac))/(2c), complex where b^2 < 4ac, and + /// every fraction after the split is over a binomial x^n - r with that root in it. + /// Last, so that whatever answers the block whole answers first: a rule that branches on + /// the sign of r has no branch for a complex one. + /// https://github.com/asc-community/AngouriMath/issues/718 + /// + internal static Entity? SolveByOneBlockInAPowerOfXAtItsRoots(Entity expr, Entity.Variable x, bool integrateByParts) + { + var (numerator, denominator) = Functions.SingleQuotient.Of(expr); + return denominator.ContainsNode(x) && !numerator.Nodes.Any(node => node is Powf(_, Number.Rational r) && r is not Number.Integer) + ? IntegrateOverBlocksInAPowerOfX(numerator, denominator, x, integrateByParts, oneBlockAtItsRoots: true) + : null; + } + /// /// A product of sums, of positive whole powers of sums and of powers of the variable, /// written out and integrated term by term. diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs index b8efc187f..b2ffdc619 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs @@ -1054,6 +1054,9 @@ private static Entity Normalized(Entity expr, Entity.Variable x) => if ((answer = IndefiniteIntegralSolver.SolveByExpandingAPower(expr, x, integrateByParts)) is { }) return answer; // And a product of such powers and sums, written out for the same reason and as late. if ((answer = IndefiniteIntegralSolver.SolveByExpandingAProductOfSums(expr, x, integrateByParts)) is { }) return answer; + // One block quadratic in a power of x, split at its roots, which are complex where its + // discriminant is negative: as late, so that a rule answering the block whole goes first. + if ((answer = IndefiniteIntegralSolver.SolveByOneBlockInAPowerOfXAtItsRoots(expr, x, integrateByParts)) is { }) return answer; // The sign of a real-valued factor is constant between its zeros, and goes in // front of the antiderivative of the rest. After every rule that reads the sign // where it stands: `cos(x) sgn(sin(x))` is `|sin(x)|` by the substitution, and diff --git a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs index 089f1fc11..18fbea5e1 100644 --- a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs +++ b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs @@ -156,6 +156,19 @@ public void APowerOfXBesideASymbolicBlock(string integrand) public void SymbolicBlocksInOnePowerOfX(string integrand) => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3), ("c", 0.4), ("d", 1.1)); + /// + /// The same with the block's roots complex, b^2 < 4 a c as pinned. The split at + /// the roots is last, since a rule after it that branches on the sign of a root has no + /// branch for a complex one: the third row is answered whole by v = x^2, and split + /// first it had no value anywhere. + /// + [Theory] + [InlineData("1/(a + b*x^3 + c*x^6)")] + [InlineData("(1 + x^4)/(1 + b*x^4 + x^8)")] + [InlineData("(d + e*x^4)/(x^3*(a + b*x^4 + c*x^8))")] + public void OneBlockWhoseRootsAreComplex(string integrand) + => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 0.9), ("c", 1.3), ("d", 1.1), ("e", 0.6)); + /// /// A quotient with x below a bar inside it is written over one bar first: /// 1/(a + b/x) was declined where x/(a x + b) was answered, and so was the From 2607ebe83f2c691a5da41e67c86cf781cf4baa63 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 18:22:08 +0000 Subject: [PATCH 10/12] The splits in a power of x answer only what they were written for Each of these splits integrates its parts again, so where it fires on a shape it was not written for, the whole question is asked a level down, and inside a search that is paid for every candidate. - A power of x beside a block is split off only where the quotient is in lowest terms in x, a factor of the block is past the second degree, and the question is the one asked or one substitution below it. - Only a quotient of polynomials is written over one bar. - A block that x divides is left to the content, where its roots would include a zero not recognised as one. - A product of sums is written out only for the question asked, and only where each sum is of powers of x. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- .../Integration/IndefiniteIntegralSolver.cs | 49 ++++++++++++++++--- .../SymbolicFactorsPartialFractionsTest.cs | 12 +++++ 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 93e7deca5..a10928fe1 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -632,10 +632,14 @@ Entity Back(Entity mapped) // What the bars were cleared with is a power of x on both sides, `x^3/(x^2 Q L^2)` for // `1/((a + b/x + c/x^2) x L^2)`, and it is cancelled: the rules below read a numerator // and a denominator with a common factor as coprime, and answered that one wrongly. + // Only where both sides are then polynomials in x, which is what the rules below read: + // anything else, written over one bar, would be the whole question asked again a level + // down, from inside every search that passes through here. if ((HasTheVariableBelowABar(numerator, x) || HasTheVariableBelowABar(denominator, x)) && Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(expr)) is var (top, bottom) && !HasTheVariableBelowABar(top, x) && !HasTheVariableBelowABar(bottom, x) && bottom.ContainsNode(x) + && TreeAnalyzer.TryGetPolynomial(top, x, out _) && TreeAnalyzer.TryGetPolynomial(bottom, x, out _) && WithoutACommonPowerOfX(top, bottom, x) is var (reducedTop, reducedBottom)) return SolveByPartialFractions(reducedTop / reducedBottom, x, integrateByParts) ?? Integration.ComputeIndefiniteIntegral(reducedTop / reducedBottom, x, integrateByParts); @@ -887,8 +891,15 @@ is var (multiple, leftover) /// private static Entity? IntegrateOverAPowerOfXBesideABlock(Entity numerator, Entity denominator, Entity.Variable x, bool integrateByParts) { + // For the question asked, or one substitution below it, as the blocks in a power of x + // are: the rest over the block is integrated again. + if (!Integration.AnsweringTheQuestionAskedOrOneBelow) + return null; var k = 0; Entity block = Number.Integer.One; + // Whether a factor of the block, or the base of a power of one, is past the second + // degree: linear and quadratic ones, and their powers, are the written-factor split's. + var pastTheSecondDegree = false; foreach (var factor in Mulf.LinearChildren(denominator)) { if (factor == x) @@ -896,15 +907,25 @@ is var (multiple, leftover) else if (factor is Powf(var @base, Number.Integer e) && @base == x && e.EInteger.Sign > 0 && e.EInteger.CanFitInInt32()) k += e.EInteger.ToInt32Unchecked(); else + { block = block == Number.Integer.One ? factor : block * factor; + var written = factor is Powf(var raised, Number.Integer { EInteger.Sign: > 0 }) ? raised : factor; + pastTheSecondDegree |= TreeAnalyzer.TryGetPolynomial(written, x, out var terms) && terms.Keys.Any(power => power.CompareTo(EInteger.FromInt32(2)) > 0); + } } - if (k == 0 || k > MaximumPowerOfXBesideABlock || !block.ContainsNode(x) || !block.Vars.Any(symbol => symbol != x)) + if (k == 0 || k > MaximumPowerOfXBesideABlock || !pastTheSecondDegree || !block.ContainsNode(x) || !block.Vars.Any(symbol => symbol != x)) return null; if (!TreeAnalyzer.TryGetPolynomial(block, x, out var below) || !TreeAnalyzer.TryGetPolynomial(numerator, x, out var above)) return null; foreach (var term in below.Concat(above)) if (term.Key.Sign < 0 || !term.Key.CanFitInInt32() || term.Value.ContainsNode(x)) return null; + // In lowest terms in x: where x divides the numerator as well, the part over x^k is + // nothing, and the rest is the whole question asked again a level down, out of reach + // of the rules that answer only the question asked. `(A x^3 + B x^4 + C x^5)/(x (a + + // b x^2 + c x^4)^2)` is answered at the top once the x is cancelled. + if (!above.TryGetValue(EInteger.Zero, out var numeratorConstant) || VanishesIdentically(numeratorConstant)) + return null; var degreeBelow = below.Keys.Max()!.ToInt32Unchecked(); var degreeAbove = above.Count == 0 ? 0 : above.Keys.Max()!.ToInt32Unchecked(); if (degreeBelow > MaximumPowerOfXBesideABlock || !below.TryGetValue(EInteger.Zero, out var constant) || VanishesIdentically(constant)) @@ -982,6 +1003,11 @@ Entity Coefficient(Dictionary polynomial, int power) foreach (var term in polynomial) if (term.Key.Sign < 0 || !term.Key.CanFitInInt32() || term.Value.ContainsNode(x)) return null; + // A block x divides is the content's to take apart, not one to split at roots: + // `b x^4 + c x^8`, read as quadratic in x^4 with no constant term, has + // `(-b ± sqrt(b^2))/(2 c)` for roots, one of them a zero that is not recognised. + if (!polynomial.TryGetValue(EInteger.Zero, out var blockConstant) || VanishesIdentically(blockConstant)) + return null; blocks.Add((polynomial, power)); } if (blocks.Count == 0 || !(numerator + denominator).Vars.Any(symbol => symbol != x)) @@ -16234,14 +16260,18 @@ bool IsAConstantTimesAPowerOfOneMinusUSquared(Entity polynomial, out Entity cons /// powers of x, each answered at once: no rule reads a power of x whose exponent is a /// symbol as a polynomial, and the rule above writes out one power and not a product of /// them. As late as that one, and for the same reason: a product that a rule answers in - /// its own terms is not written out. Only where every factor with x in it is a sum, a - /// positive whole power of one, or a power of x itself, so that writing it out is a finite - /// identity, bounded by . + /// its own terms is not written out. Only where every factor with x in it is a sum of + /// powers of x, a positive whole power of one, or a power of x itself, so that writing it + /// out is a finite identity, bounded by , + /// whose terms are each answered at once; and only for the question asked, not for what a + /// rule leaves over. A sum of exponentials is a sum too: integration by parts on + /// x^2 Shi(a + b x) sinh(a + b x) leaves a run of them beside powers of x, and + /// written out each term is a search of its own. /// https://github.com/asc-community/AngouriMath/issues/718 /// internal static Entity? SolveByExpandingAProductOfSums(Entity expr, Entity.Variable x, bool integrateByParts) { - if (expr is not Mulf) + if (expr is not Mulf || !Integration.AnsweringTheQuestionAsked) return null; var sums = 0; foreach (var factor in Mulf.LinearChildren(expr)) @@ -16250,8 +16280,8 @@ bool IsAConstantTimesAPowerOfOneMinusUSquared(Entity polynomial, out Entity cons continue; switch (factor) { - case Sumf or Minusf: - case Powf(Sumf or Minusf, Number.Integer power) when power.EInteger.CompareTo(EInteger.One) > 0: + case Sumf or Minusf when IsASumOfPowersOfX(factor, x): + case Powf((Sumf or Minusf) and var sum, Number.Integer power) when power.EInteger.CompareTo(EInteger.One) > 0 && IsASumOfPowersOfX(sum, x): sums++; break; case Entity.Variable when factor == x: @@ -16267,6 +16297,11 @@ bool IsAConstantTimesAPowerOfOneMinusUSquared(Entity polynomial, out Entity cons if (written is not Sumf and not Minusf) return null; return Integration.ComputeIndefiniteIntegral(written, x, integrateByParts); + + // Each term a constant times a power of x, the power's exponent free of x. + static bool IsASumOfPowersOfX(Entity sum, Entity.Variable x) + => Sumf.LinearChildren(sum).All(term => Mulf.LinearChildren(term).All(factor => + !factor.ContainsNode(x) || factor == x || factor is Powf(var @base, var exponent) && @base == x && !exponent.ContainsNode(x))); } /// diff --git a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs index 18fbea5e1..f842909b9 100644 --- a/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs +++ b/Sources/Tests/UnitTests/Calculus/SymbolicFactorsPartialFractionsTest.cs @@ -196,6 +196,18 @@ public void AQuotientWithXBelowABarInsideIt(string integrand) public void AProductOfSumsInASymbolicPowerOfX(string integrand) => DifferentiatesBack(integrand, "x", ("a", 1.7), ("b", 2.3), ("c", 0.4), ("d", 1.1), ("n", 1.3)); + /// + /// What the splits above leave whole: a numerator that x divides as well, and a quotient + /// written over one bar that is not of polynomials. Split, each part would be the whole + /// question asked again a level down, and the rules that answer these at the top would not + /// be reached in the time they take there. + /// + [Theory] + [InlineData("(p*x^3 + q*x^4 + r*x^5)/(x*(a + b*x^2 + c*x^4)^2)")] + [InlineData("sec(c + d*x)^8/(a + i*a*tan(c + d*x))^4")] + public void WhatTheSplitsLeaveWhole(string integrand) + => DifferentiatesBack(integrand, "x", ("a", 1.81), ("b", 2.18), ("c", 2.55), ("d", 1.1), ("p", 0.7), ("q", 1.07), ("r", 1.44)); + /// /// A repeated linear factor is one block, P/(a + b u)^k, which the rule for /// a polynomial over a power of a linear reads; Welz's 1/(a + b e^(p x))^2 is From 96dc8cfbf6b7d609d95778c1fb568d7ab9daab2d Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 22:43:29 +0000 Subject: [PATCH 11/12] The two blocks at the roots are a list initialiser, not a collection expression A collection expression for a List is lowered through CollectionsMarshal, which is in System.Runtime.InteropServices, an assembly the kernel does not reference. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- .../Continuous/Integration/IndefiniteIntegralSolver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index a10928fe1..3dba4c930 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -1068,7 +1068,7 @@ Entity InU(Dictionary polynomial) var first = Functions.PartialFractions.InLowestTermsOverTheSymbols((-b + root) / (2 * c)); var second = Functions.PartialFractions.InLowestTermsOverTheSymbols((-b - root) / (2 * c)); constant = constant == Number.Integer.One ? (power == 1 ? c : MathS.Pow(c, power)) : constant * (power == 1 ? c : MathS.Pow(c, power)); - inUBlocks = [(u - first, power), (u - second, power)]; + inUBlocks = new List<(Entity Block, int Power)> { (u - first, power), (u - second, power) }; } Entity below = constant; foreach (var (block, power) in inUBlocks) From 9040983c4f16c00ec88f0bf6620a8e1081e47ddd Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 2 Oct 2026 23:04:34 +0000 Subject: [PATCH 12/12] The coefficients are read off their pairs, which netstandard2.0 does not deconstruct Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- .../Continuous/Integration/IndefiniteIntegralSolver.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index de0b910fc..49c6054aa 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -1048,8 +1048,9 @@ Entity Coefficient(Dictionary polynomial, int power) Entity InU(Dictionary polynomial) { Entity sum = Number.Integer.Zero; - foreach (var (power, coefficient) in polynomial.OrderBy(term => term.Key)) + foreach (var entry in polynomial.OrderBy(term => term.Key)) { + var (power, coefficient) = (entry.Key, entry.Value); var degree = power.ToInt32Unchecked() / step; var term = degree == 0 ? coefficient : coefficient * (degree == 1 ? u : MathS.Pow(u, degree)); sum = sum == Number.Integer.Zero ? term : sum + term; @@ -1091,8 +1092,9 @@ Entity InU(Dictionary polynomial) foreach (var residue in above.GroupBy(term => term.Key.ToInt32Unchecked() % step)) { Entity inU = Number.Integer.Zero; - foreach (var (power, coefficient) in residue) + foreach (var entry in residue) { + var (power, coefficient) = (entry.Key, entry.Value); var degree = power.ToInt32Unchecked() / step; inU += degree == 0 ? coefficient : coefficient * MathS.Pow(u, degree); } @@ -1443,8 +1445,9 @@ static int LowestPower(Dictionary polynomial) Entity Shifted(Dictionary polynomial, int by) { Entity sum = Number.Integer.Zero; - foreach (var (power, coefficient) in polynomial.OrderBy(term => term.Key)) + foreach (var entry in polynomial.OrderBy(term => term.Key)) { + var (power, coefficient) = (entry.Key, entry.Value); var degree = power.ToInt32Unchecked() - by; var term = degree == 0 ? coefficient : coefficient * (degree == 1 ? x : MathS.Pow(x, degree)); sum = sum == Number.Integer.Zero ? term : sum + term;