From 2cd0cb53bcd14e5f828f80601c874a053aa41f1a Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 5 Oct 2026 04:49:24 +0000 Subject: [PATCH 1/2] A power of a constant times a whole power of a polynomial is integrated as that power (c S^k)^p, a constant times a whole power past the first of something of x by arithmetic, under a power that is not whole, was declined where it was not a function of a linear: x^2 (c (a + b x^2)^2)^(3/2) is a polynomial times a factor that is constant wherever a + b x^2 is not zero. It is integrated as K S^(k p) now, K = c^q (c S^k)^r/S^(k r) for the whole part q and the rest r of p, in front of the integral, or over it for a factor below the bar. Only factors of the integrand, only S of x by arithmetic, since a power of a function of x is the rules' for that function, which write its sign, and at the top only. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 14 +++ .../Integration/IndefiniteIntegralSolver.cs | 88 +++++++++++++++++++ .../Integration/Integration.Definition.cs | 4 + ...ePowerOutOfAPowerOfAProductIntegralTest.cs | 51 +++++++++++ 4 files changed, 157 insertions(+) create mode 100644 Sources/Tests/UnitTests/Calculus/WholePowerOutOfAPowerOfAProductIntegralTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index dc39a1fe6..007d7c73d 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -787,6 +787,20 @@ but `sqrt(q)^2 = q` ([#1598](https://github.com/asc-community/AngouriMath/issues | `"1/sqrt(-x^2 + i)".Integrate("x")` | `-arcsin(-2x/sqrt(4i)) + C` | `ln(-2x + 2i sqrt(-x^2 + i))/i + C`, an antiderivative as before, in the logarithm | | `"1/(sqrt(x)*sqrt(1 + i*x))".Integrate("x")`, and Rubi 4.3.2.1's `sqrt(tan(c + d x))/(a + i a tan(c + d x))^(5/2)` | `integral(...)` | the antiderivative | +### A power of a constant times a whole power of a polynomial is integrated as that power + +**Answers where there were none.** `(c S^k)^p`, a constant times a whole power past the first of a +polynomial in `x` under a power that is not whole, was declined where it was not a function of a +linear: `x^2 (c (a + b x^2)^2)^(3/2)` is a polynomial times a factor that is constant wherever +`a + b x^2` is not zero. It is integrated as `K S^(k p)` now, with `K = c^q (c S^k)^r/S^(k r)` for the +whole part `q` and the rest `r` of `p`. Rubi's 1.3.2 +([#718](https://github.com/asc-community/AngouriMath/issues/718)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"x^2*(c*(a + b*x^2)^2)^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | `c (c (a + b x^2)^2)^(1/2)/(a + b x^2)` times `a^3 x^3/3 + 3 a^2 b x^5/5 + 3 a b^2 x^7/7 + b^3 x^9/9` | +| `"(c*(a + b*x)^3)^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | `c (c (a + b x)^3)^(1/2)/(a + b x)^(3/2)` times `(a + b x)^(11/2)/((11/2) b)` | + ### Trigonometric functions of multiples of one linear argument are written in it `csc(a + b x) csc(2a + 2b x)^2` was left unevaluated, and `csc(1 + x) csc(2 + 2x)^2` ran twenty diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 875a31f1c..5656f51a2 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -23331,6 +23331,94 @@ private static bool HasTheSameRatioAtTwoPoints(Entity expr, Entity reference, En return lambda; } + /// + /// A power that is not whole of a constant times a whole power of something of x, + /// (c S^k)^p for a whole k past 1, as K S^(k p), with + /// K = c^q (c S^k)^r/S^(k r) for the whole part q of p and the rest + /// r: Rubi's 1.3.2 x^m (c (a + b x^2)^2)^(3/2) is K x^m (a + b x^2)^3, + /// a polynomial, and was declined. + /// + /// + /// K is constant on every interval where S is not zero: its logarithmic + /// derivative is r (k S'/S - k S'/S). So it goes in front of the integral, and over it + /// for a factor below the bar, as the factor of + /// does. A whole power of the + /// constant times the power distributes exactly, which is why only the rest of p is + /// in K. Only factors of the integrand, where K is a factor of the whole; only + /// something of x by arithmetic, since a power of a function is the rules' for that function, + /// which write its sign; and at the top only, where the answer is the caller's. + /// https://github.com/asc-community/AngouriMath/issues/718 + /// + internal static Entity? SolveByTakingAWholePowerOutOfAPowerOfAProduct(Entity expr, Entity.Variable x, bool integrateByParts) + { + if (!Integration.AnsweringTheQuestionAsked) + return null; + var (above, below) = Functions.SingleQuotient.Of(expr); + Entity constant = Number.Integer.One; + var changed = false; + var top = Rewritten(above, Number.Integer.One); + var bottom = Rewritten(below, Number.Integer.MinusOne); + if (!changed) + return null; + var question = (bottom == Number.Integer.One ? top : top / bottom).InnerSimplified; + if (Integration.ComputeIndefiniteIntegral(question, x, integrateByParts) is not { } integral) + return null; + var answer = constant * integral; + return answer.Nodes.Any(node => node == MathS.NaN) ? null : answer; + + Entity Rewritten(Entity side, Number.Integer sign) + { + Entity product = Number.Integer.One; + foreach (var factor in Mulf.LinearChildren(side)) + { + var written = factor; + if (factor is Powf(var @base, var power) && power is not Number.Integer && !power.ContainsNode(x) + && @base is Mulf or Divf && ConstantTimesAWholePower(@base, x) is var (c, inner, k)) + { + written = MathS.Pow(inner, (k * power).InnerSimplified); + var signed = (sign * power).InnerSimplified; + Entity whole = Number.Integer.Zero; + var fraction = signed; + if (signed is Number.Rational rational) + { + whole = Number.Integer.Create(rational.ERational.Numerator.Divide(rational.ERational.Denominator)); + fraction = (signed - whole).InnerSimplified; + } + var turned = MathS.Pow(@base, fraction) / MathS.Pow(inner, (k * fraction).InnerSimplified); + var turn = whole == Number.Integer.Zero || c == Number.Integer.One ? turned : MathS.Pow(c, whole) * turned; + constant = constant == Number.Integer.One ? turn : constant * turn; + changed = true; + } + product = product == Number.Integer.One ? written : product * written; + } + return product; + } + + // A product of constants and one whole power past 1 of something of x: the constant, + // the something and the power. + static (Entity Constant, Entity Inner, Number.Integer Power)? ConstantTimesAWholePower(Entity @base, Entity.Variable x) + { + Entity c = Number.Integer.One; + (Entity Inner, Number.Integer Power)? found = null; + foreach (var part in Mulf.LinearChildren(@base)) + { + if (!part.ContainsNode(x)) + { + c = c == Number.Integer.One ? part : c * part; + continue; + } + if (found is not null || part is not Powf(var inner, Number.Integer { EInteger: var k } whole) || k.CompareTo(2) < 0) + return null; + // Of x by arithmetic alone: a power of a function of x is the rules' for that + // function, which write its sign. + if (inner.Nodes.Any(node => node.ContainsNode(x) && node is not (Sumf or Minusf or Mulf or Divf or Powf or Variable))) + return null; + found = (inner, whole); + } + return found is var (i, w) ? (c, i, w) : null; + } + } + /// /// A fractional or symbolic power of a monomial, distributed: (c x^n)^b is /// c^b x^(n b) for a positive c and a n that is not whole. diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs index 15f973f6b..8ca5a8fbb 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs @@ -708,6 +708,10 @@ private static Entity Normalized(Entity expr, Entity.Variable x) => // And a fractional power of a sum whose every term has x in it, the power of x taken out // with the factor that is constant where it is not zero: `1/sqrt(a x^2 + b x^5)`. if ((answer = IndefiniteIntegralSolver.SolveByTakingAPowerOfXOutOfAFractionalPower(expr, x, integrateByParts)) is { }) return answer; + // And a constant times a whole power of something of x under a power that is not + // whole, the whole power taken out with the factor constant where it is not zero: + // `x^2 (c (a + b x^2)^2)^(3/2)` is that factor times a polynomial. + if ((answer = IndefiniteIntegralSolver.SolveByTakingAWholePowerOutOfAPowerOfAProduct(expr, x, integrateByParts)) is { }) return answer; // A power of a multiple of a quadratic's derivative beside a power of the quadratic is // a binomial in the derivative: `(b d + 2 c d x)^m (a + b x + c x^2)^p`. if ((answer = IndefiniteIntegralSolver.SolveByTheDerivativeOfAQuadraticAsTheVariable(expr, x, integrateByParts)) is { }) return answer; diff --git a/Sources/Tests/UnitTests/Calculus/WholePowerOutOfAPowerOfAProductIntegralTest.cs b/Sources/Tests/UnitTests/Calculus/WholePowerOutOfAPowerOfAProductIntegralTest.cs new file mode 100644 index 000000000..500681b93 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/WholePowerOutOfAPowerOfAProductIntegralTest.cs @@ -0,0 +1,51 @@ +// +// 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 power that is not whole of a constant times a whole power of something of x, + /// (c S^k)^p, as K S^(k p) with K constant where S is not zero. + /// Rubi's 1.3.2 and 1.1.3.2. + /// #718 + /// + /// + /// Checked by differentiating back with a = 1.3, b = 0.7 and c = 0.4, on + /// both sides of the root of a + b x, where K changes sign. + /// + [Trait("Area", "Calculus")] + public sealed class WholePowerOutOfAPowerOfAProductIntegralTest + { + [Theory] + [InlineData("x^2*(c*(a + b*x^2)^2)^(3/2)")] + [InlineData("(c*(a + b*x^2)^2)^(3/2)/x")] + [InlineData("x*(c*(a + b*x^2)^3)^(3/2)")] + [InlineData("(c*(a + b*x)^3)^(3/2)")] + [InlineData("1/(c*(a + b*x)^2)^(5/2)")] + [InlineData("1/(c*(a + b*x)^3)^(3/2)")] + 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("c", 0.4); + var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x"); + var original = Pinned(integrand.ToEntity()); + foreach (var at in new[] { -3.1, -2.5, 0.4, 1.6 }) + { + 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}"); + } + } + } +} From ba6ccad0ef0d35ea98ce09aca2df4ffbd803a5d5 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 5 Oct 2026 08:32:13 +0000 Subject: [PATCH 2/2] A whole power is taken out of a power of a product after the substitution search The substitution search answers a power of a function of a linear, and an odd power of x beside a function of x^2, more shortly than the factor in front does: 1/(c (a + b x)^2)^(5/2) in 64 characters, where taken out it was 98. Asked after it, the rule answers what the search declines, Rubi's 1.3.2:338-352, and the test checks those on both sides of the roots of a + b x^2, where the factor changes sign. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 5 ++-- .../Integration/Integration.Definition.cs | 10 ++++--- ...ePowerOutOfAPowerOfAProductIntegralTest.cs | 30 ++++++++++++------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index fc8daa62c..823354acb 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -1097,13 +1097,14 @@ but `sqrt(q)^2 = q` ([#1598](https://github.com/asc-community/AngouriMath/issues polynomial in `x` under a power that is not whole, was declined where it was not a function of a linear: `x^2 (c (a + b x^2)^2)^(3/2)` is a polynomial times a factor that is constant wherever `a + b x^2` is not zero. It is integrated as `K S^(k p)` now, with `K = c^q (c S^k)^r/S^(k r)` for the -whole part `q` and the rest `r` of `p`. Rubi's 1.3.2 +whole part `q` and the rest `r` of `p`, where the substitution search, asked first, declines it. Rubi's +1.3.2 ([#718](https://github.com/asc-community/AngouriMath/issues/718)). | Input | Was (2.5.0) | Now | |---|---|---| | `"x^2*(c*(a + b*x^2)^2)^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | `c (c (a + b x^2)^2)^(1/2)/(a + b x^2)` times `a^3 x^3/3 + 3 a^2 b x^5/5 + 3 a b^2 x^7/7 + b^3 x^9/9` | -| `"(c*(a + b*x)^3)^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | `c (c (a + b x)^3)^(1/2)/(a + b x)^(3/2)` times `(a + b x)^(11/2)/((11/2) b)` | +| `"(c*(a + b*x^2)^3)^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | `c (c (a + b x^2)^3)^(1/2)/(a + b x^2)^(3/2)` times an antiderivative of `(a + b x^2)^(9/2)` | ### A quotient by the square of a base is integrated by parts against the base's reciprocal diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs index 3925bbff0..aa9cee8f4 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs @@ -712,10 +712,6 @@ private static Entity Normalized(Entity expr, Entity.Variable x) => // And a fractional power of a sum whose every term has x in it, the power of x taken out // with the factor that is constant where it is not zero: `1/sqrt(a x^2 + b x^5)`. if ((answer = IndefiniteIntegralSolver.SolveByTakingAPowerOfXOutOfAFractionalPower(expr, x, integrateByParts)) is { }) return answer; - // And a constant times a whole power of something of x under a power that is not - // whole, the whole power taken out with the factor constant where it is not zero: - // `x^2 (c (a + b x^2)^2)^(3/2)` is that factor times a polynomial. - if ((answer = IndefiniteIntegralSolver.SolveByTakingAWholePowerOutOfAPowerOfAProduct(expr, x, integrateByParts)) is { }) return answer; // A power of a multiple of a quadratic's derivative beside a power of the quadratic is // a binomial in the derivative: `(b d + 2 c d x)^m (a + b x + c x^2)^p`. if ((answer = IndefiniteIntegralSolver.SolveByTheDerivativeOfAQuadraticAsTheVariable(expr, x, integrateByParts)) is { }) return answer; @@ -913,6 +909,12 @@ private static Entity Normalized(Entity expr, Entity.Variable x) => // substitution search, which reads each root on its own. if ((answer = IndefiniteIntegralSolver.SolveBySubstitutingTheSumOfTwoRootsOfLinears(expr, x, integrateByParts)) is { }) return answer; if ((answer = IndefiniteIntegralSolver.SolveBySubstitution(expr, x, integrateByParts)) is { }) return answer; + // A constant times a whole power of something of x under a power that is not whole, the + // whole power taken out with the factor constant where it is not zero: + // `x^2 (c (a + b x^2)^2)^(3/2)` is that factor times a polynomial. After the substitution + // search, which answers a power of a linear and an odd power of x beside a function of + // x^2 more shortly: `1/(c (a + b x)^2)^(5/2)` in 64 characters, where this writes 98. + if ((answer = IndefiniteIntegralSolver.SolveByTakingAWholePowerOutOfAPowerOfAProduct(expr, x, integrateByParts)) is { }) return answer; // A logarithmic derivative the substitution above could not read for a symbol in // an exponent: `(x^(n-1) - 1)/(x^n - n x)`. if ((answer = IndefiniteIntegralSolver.SolveALogarithmicDerivativeWithASymbolicExponent(expr, x)) is { }) return answer; diff --git a/Sources/Tests/UnitTests/Calculus/WholePowerOutOfAPowerOfAProductIntegralTest.cs b/Sources/Tests/UnitTests/Calculus/WholePowerOutOfAPowerOfAProductIntegralTest.cs index 500681b93..e60d6ac2a 100644 --- a/Sources/Tests/UnitTests/Calculus/WholePowerOutOfAPowerOfAProductIntegralTest.cs +++ b/Sources/Tests/UnitTests/Calculus/WholePowerOutOfAPowerOfAProductIntegralTest.cs @@ -14,38 +14,46 @@ namespace AngouriMath.Tests.Calculus /// /// A power that is not whole of a constant times a whole power of something of x, /// (c S^k)^p, as K S^(k p) with K constant where S is not zero. - /// Rubi's 1.3.2 and 1.1.3.2. + /// Rubi's 1.3.2:338-352, which the substitution search, asked first, declines. /// #718 /// /// - /// Checked by differentiating back with a = 1.3, b = 0.7 and c = 0.4, on - /// both sides of the root of a + b x, where K changes sign. + /// Checked by differentiating back with a = -1.3, b = 0.7 and c = 0.4, on + /// both sides of 0 and of the roots of a + b x^2, where K changes sign, wherever + /// the integrand is real. /// [Trait("Area", "Calculus")] public sealed class WholePowerOutOfAPowerOfAProductIntegralTest { + private static readonly double[] Points = { -2.3, -1.9, -0.8, -0.3, 0.4, 0.9, 1.9, 2.3 }; + [Theory] [InlineData("x^2*(c*(a + b*x^2)^2)^(3/2)")] - [InlineData("(c*(a + b*x^2)^2)^(3/2)/x")] - [InlineData("x*(c*(a + b*x^2)^3)^(3/2)")] - [InlineData("(c*(a + b*x)^3)^(3/2)")] - [InlineData("1/(c*(a + b*x)^2)^(5/2)")] - [InlineData("1/(c*(a + b*x)^3)^(3/2)")] + [InlineData("x^4*(c*(a + b*x^2)^2)^(3/2)")] + [InlineData("(c*(a + b*x^2)^2)^(3/2)")] + [InlineData("(c*(a + b*x^2)^2)^(3/2)/x^2")] + [InlineData("(c*(a + b*x^2)^3)^(3/2)")] + [InlineData("(c*(a + b*x^2)^3)^(3/2)/x^2")] 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("c", 0.4); + Entity Pinned(Entity e) => e.Substitute("a", -1.3).Substitute("b", 0.7).Substitute("c", 0.4); var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x"); var original = Pinned(integrand.ToEntity()); - foreach (var at in new[] { -3.1, -2.5, 0.4, 1.6 }) + var compared = 0; + foreach (var at in Points) { var want = original.Substitute("x", at).EvalNumerical(); + if (want.IsNaN || Math.Abs((double)want.ImaginaryPart) > 1e-12 * Math.Max(1, Math.Abs((double)want.RealPart))) + continue; var got = derivative.Substitute("x", at).EvalNumerical(); + compared++; 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)), + < 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart)), $"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}"); } + Assert.True(compared >= 4, $"only {compared} points were real for {integrand}"); } } }