diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 3d1e03d67..a3fd263cd 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -1568,6 +1568,20 @@ out shorter and five longer -- `1/((c x)^(5/3) (a + b x^2)^(2/3))` was `-3/(2 a) x (c x)^(-5/3) (a + b x^2)^(1/3)` there, and is the same function written in `x^(1/3)`. 2.5.0 declined all nine. +### A binomial differential with a symbol in its exponents is integrated in Chebyshev's third case + +**Answers where there were none.** `1/(a + b x^n)^((1 + 2 n)/n)` and the rest of `x^m (a + b x^n)^p` +with a symbol in the exponents where `(m + 1)/n + p + 1` is a whole number at most 0 were declined, +but for `x^m` beside the binomial at 0. Rubi's reduction raises `p` by one, +`J(p) = -x^(m+1) (a + b x^n)^(p+1)/(a n (p + 1)) + (m + 1 + n (p + 1))/(a n (p + 1)) J(p + 1)`, and as many +steps of it as the number says reach `x^(m + 1) (a + b x^n)^(p + 1)/(a (m + 1))`. Rubi's 1.1.3.2 +([#718](https://github.com/asc-community/AngouriMath/issues/718)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"1/(a + b*x^n)^((1 + n)/n)".ToEntity().Integrate("x")` | `integral(...)` | `x (a + b x^n)^(-1/n)/a` | +| `"1/(a + b*x^n)^((1 + 2*n)/n)".ToEntity().Integrate("x")` | `integral(...)` | `x (a + b x^n)^(-1 - 1/n)/(a (n + 1)) + n x (a + b x^n)^(-1/n)/(a^2 (n + 1))` | + ### A power of a multiple of a quadratic's derivative beside a power of the quadratic is a binomial **Improvement, not silent.** `(b d + 2 c d x)^m (a + b x + c x^2)^p`, with a power that is not whole, diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 2e96723dc..b3cec16b9 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -12980,6 +12980,118 @@ static bool IsRationalInBoth(Entity e, Entity.Variable x, Entity.Variable L) return null; } + + /// + /// A binomial differential x^m (a + b x^n)^p with a symbol in its exponents, in + /// Chebyshev's third case at a whole (m + 1)/n + p + 1 = -k of at most 0: Rubi's + /// 1/(a + b x^n)^((1 + 2 n)/n). + /// + /// + /// At k = 0 the integral is x^(m + 1) (a + b x^n)^(p + 1)/(a (m + 1)), whose + /// derivative is the integrand there. Below it Rubi's reduction raises p by one, + /// + /// J(p) = -x^(m + 1) (a + b x^n)^(p + 1)/(a n (p + 1)) + (m + 1 + n (p + 1))/(a n (p + 1)) J(p + 1) + /// + /// and k steps of it reach the first. reads + /// the three cases with numbers for the exponents; with a symbol, a power of x beside the + /// binomial at k = 0 is 's, which + /// leaves a power on its own and every k past 0, and those were declined: Rubi's + /// 1.1.3.2:3301-3304. The answer is differentiated back at sampled points before it is + /// returned. + /// https://github.com/asc-community/AngouriMath/issues/718 + /// + internal static Entity? SolveABinomialInTheThirdCaseWithASymbolicExponent(Entity expr, Entity.Variable x) + { + Entity constant = Number.Integer.One; + Entity m = Number.Integer.Zero; + Entity? sum = null, p = null; + foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr)) + { + if (!factor.ContainsNode(x)) + { + constant = underneath ? constant / factor : constant * factor; + continue; + } + var (@base, exponent) = factor is Powf(var factorBase, var factorExponent) && !factorExponent.ContainsNode(x) ? (factorBase, factorExponent) : (factor, (Entity)Number.Integer.One); + if (underneath) + exponent = -exponent; + if (@base == x) + { + m = m + exponent; + continue; + } + if (sum is not null || @base is not (Sumf or Minusf)) + return null; + (sum, p) = (@base, exponent); + } + if (sum is null || p is null || ABinomial(sum) is not var (a, b, n)) + return null; + m = m.InnerSimplified; + p = p.InnerSimplified; + // A symbol among the exponents: with numbers only it is the binomial differential's. + if (!m.Vars.Any() && !n.Vars.Any() && !p.Vars.Any()) + return null; + var s = Simplified((m + 1) / n + p + 1); + if (s is not Number.Integer { EInteger: var whole } || whole.Sign > 0 || whole.CompareTo(-6) < 0) + return null; + var k = -whole.ToInt32Checked(); + static bool Zero(Entity value) => Functions.PartialFractions.IsZeroAsAValue(value); + if (Zero(m + 1) || Zero(a)) + return null; + // Each coefficient in lowest terms over the symbols: the first step's + // `(-3) n/(a n (-3 - 1/n))` is `3 n/(a (3 n + 1))`. + var raisedX = MathS.Pow(x, Simplified(m + 1)); + Entity? answer = null; + Entity coefficient = Number.Integer.One; + for (var j = 0; j < k; j++) + { + var raised = Simplified(p + j + 1); + if (Zero(raised)) + return null; + var term = LowestOverTheSymbols(-coefficient / (a * n * raised)) * raisedX * MathS.Pow(sum, raised); + answer = answer is null ? term : answer + term; + coefficient = LowestOverTheSymbols(coefficient * (m + 1 + n * raised) / (a * n * raised)); + } + var last = LowestOverTheSymbols(coefficient / (a * (m + 1))) * raisedX * MathS.Pow(sum, Simplified(p + k + 1)); + answer = constant * (answer is null ? last : answer + last); + return Functions.PartialFractions.DerivativeHoldsAtSampledPoints(answer, expr, x) ? answer : null; + + // `a + b x^n`, `b x^n + a`: the constant, the coefficient and the power, each free of x. + (Entity, Entity, Entity)? ABinomial(Entity binomial) + { + Entity? free = null, coefficient = null, power = null; + foreach (var term in Sumf.LinearChildren(binomial)) + { + if (!term.ContainsNode(x)) + { + if (free is not null) + return null; + free = term; + continue; + } + if (coefficient is not null) + return null; + Entity c = Number.Integer.One; + foreach (var part in Mulf.LinearChildren(term)) + if (!part.ContainsNode(x)) + c = c == Number.Integer.One ? part : c * part; + else if (part == x && power is null) + power = Number.Integer.One; + else if (part is Powf(var powerBase, var powerExponent) && powerBase == x && !powerExponent.ContainsNode(x) && power is null) + power = powerExponent; + else + return null; + coefficient = c; + } + return free is null || coefficient is null || power is null ? null : (free, coefficient, power); + } + + // A short exponent simplified: `p + 1 + 1` is `p + 2`, which the inner simplification + // leaves as written, and `1/n - (1 + n)/n + 1` is 0, which the simplification gives with + // `n` not 0 beside it. + static Entity Simplified(Entity exponent) + => exponent.InnerSimplified is var inner && (inner is Number || inner.Complexity > 40) ? inner : Functions.PartialFractions.Bare(inner.Simplify()); + } /// /// Powers of two linears whose exponents sum to a whole number -k, k >= 2, /// beside a polynomial of degree at most k - 2: (a + b x)^m (c + d x)^(-3 - m), diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs index 8eefb0450..05c4b58ba 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs @@ -777,6 +777,10 @@ private static Entity Normalized(Entity expr, Entity.Variable x) => // of the powers raised by one -- `e^x x^2 ln(x)^2 (3 + (3 + x) ln(x))` -- read off // the sum, for symbolic exponents too. Before the split, which loses it. if ((answer = IndefiniteIntegralSolver.SolveAsTheDerivativeOfAProductOfPowers(expr, x)) is { }) return answer; + // And a power of a binomial in x^n beside a power of x, with a symbol in the exponents, + // where Chebyshev's third case is a whole number at most 0: by Rubi's reduction, which + // the rule above does not read for a power on its own or past the first step. + if ((answer = IndefiniteIntegralSolver.SolveABinomialInTheThirdCaseWithASymbolicExponent(expr, x)) is { }) return answer; // Powers of two linears whose exponents sum to a whole number below -2, beside a polynomial of // low degree, by t = L1/L2: a power of t beside a polynomial. The rule above reads the sum -2. if ((answer = IndefiniteIntegralSolver.SolveTwoLinearPowersWhoseExponentsSumToAWholeNumber(expr, x)) is { }) return answer; diff --git a/Sources/Tests/UnitTests/Calculus/BinomialInTheThirdCaseWithASymbolicExponentIntegralTest.cs b/Sources/Tests/UnitTests/Calculus/BinomialInTheThirdCaseWithASymbolicExponentIntegralTest.cs new file mode 100644 index 000000000..fcee54bcc --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/BinomialInTheThirdCaseWithASymbolicExponentIntegralTest.cs @@ -0,0 +1,50 @@ +// +// Copyright (c) 2019-2026 Angouri. +// AngouriMath is licensed under MIT. +// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. +// Website: https://am.angouri.org. +// + +using System; +using AngouriMath.Extensions; +using Xunit; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// A binomial differential x^m (a + b x^n)^p with a symbol in its exponents, where + /// (m + 1)/n + p + 1 is a whole number at most 0: Rubi's 1.1.3.2:3301-3304 and the same + /// with a power of x beside the binomial. + /// #718 + /// + /// + /// Checked by differentiating back with a = 1.3, b = 0.7, n = 1.7 and + /// m = 0.6, at positive x, where a symbolic power of it is real. + /// + [Trait("Area", "Calculus")] + public sealed class BinomialInTheThirdCaseWithASymbolicExponentIntegralTest + { + [Theory] + [InlineData("1/(a + b*x^n)^((1 + n)/n)")] + [InlineData("1/(a + b*x^n)^((1 + 2*n)/n)")] + [InlineData("1/(a + b*x^n)^((1 + 4*n)/n)")] + [InlineData("x^2/(a + b*x^n)^((3 + 2*n)/n)")] + [InlineData("x^m*(a + b*x^n)^(-(m + 1)/n - 3)")] + public void IsIntegrated(string integrand) + { + var integral = integrand.ToEntity().Integrate("x"); + Assert.DoesNotContain("integral(", integral.Stringize()); + Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7).Substitute("n", 1.7).Substitute("m", 0.6); + var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x"); + var original = Pinned(integrand.ToEntity()); + foreach (var at in new[] { 0.3, 0.8, 1.4, 2.1 }) + { + var want = original.Substitute("x", at).EvalNumerical(); + var got = derivative.Substitute("x", at).EvalNumerical(); + Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart) + < 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)), + $"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}"); + } + } + } +}