From c52ade44c62f047bf6f242ef86af4fb359f97f64 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Sat, 3 Oct 2026 02:26:39 +0000 Subject: [PATCH] A cube or fourth root of a quadratic binomial beside another is integrated at the ratios where it is elementary 1/((A + B x^2)^(1/3) (C + D x^2)) with B C + 3 A D = 0 or B C - 9 A D = 0, and 1/((A + B x^2)^(1/4) (C + D x^2)) with B C - 2 A D = 0, are answered in Rubi's closed forms from its 1.1.2.3, by the sign of B/A for the cube root and by the signs of A and B for the fourth. 1/((3 - x^2)(1 + x^2)^(1/3)) is at the first ratio, so the cube-root ansatz's declined row moves to 1/((3 - x^2)(2 + x^2)^(1/3)), the same pole pair off it. Part of https://github.com/asc-community/AngouriMath/issues/718 Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 21 +++ .../Integration/IndefiniteIntegralSolver.cs | 126 ++++++++++++++++++ .../Integration/Integration.Definition.cs | 3 + .../Calculus/CubeRootLogarithmAnsatzTest.cs | 2 +- .../EllipticLookingQuotientOfBinomialsTest.cs | 95 +++++++++++++ 5 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 Sources/Tests/UnitTests/Calculus/EllipticLookingQuotientOfBinomialsTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index d036a8063..0f67143d6 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -340,6 +340,27 @@ leading coefficient once expanded, and declined: it is read expanded and bare no | `"sin(x)/(a+b*sin(x))^3".Integrate("x")`, Rubi's 4.1.2.1 row 242 | `integral(...)` | the antiderivative | | `"4*x*(1+x^2)/(a*x^2+2*b*x+a)^3".Integrate("x")` | `integral(...)` | the antiderivative | +### A cube or fourth root of a quadratic binomial beside another is integrated where that is elementary + +**Answers where there were none.** `1/((A + B x^2)^(1/3) (C + D x^2))` is an elliptic integral +except where `B C + 3 A D = 0` or `B C - 9 A D = 0`, and `1/((A + B x^2)^(1/4) (C + D x^2))` except +where `B C - 2 A D = 0`. At those ratios it is arctangents and logarithms of quotients in the root, +as Rubi's 1.1.2.3 gives them, and it was left unevaluated. It is answered there now, with symbols +in the constants too: by the sign of `B/A` for the cube root, and by the signs of `A` and `B` for +the fourth. With `A` and `B` both positive, the fourth root's answer jumps at `x = 0`, and is an +antiderivative on each side of it, as Rubi's is +([#718](https://github.com/asc-community/AngouriMath/issues/718)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"1/((1 - x^2)^(1/3)*(3 + x^2))".ToEntity().Integrate("x")` | `integral(...)` | arctangents and logarithms in `x` and `(1 - x^2)^(1/3)` | +| `"1/((1 + x^2)^(1/3)*(9 + x^2))".ToEntity().Integrate("x")` | `integral(...)` | the same in `(1 + x^2)^(1/3)` | +| `"1/((a + b*x^2)^(1/3)*(3*a - b*x^2))".ToEntity().Integrate("x")` | `integral(...)` | the same in `(a + b x^2)^(1/3)`, by the sign of `b/a` | +| `"1/((a + b*x^2)^(1/3)*(9*a + b*x^2))".ToEntity().Integrate("x")` | `integral(...)` | the same, by the sign of `b/a` | +| `"1/((a + b*x^2)^(1/4)*(2*a + b*x^2))".ToEntity().Integrate("x")` | `integral(...)` | the same in `(a + b x^2)^(1/4)`, by the signs of `a` and `b` | +| `"1/((2 + 3*x^2)^(1/4)*(4 + 3*x^2))".ToEntity().Integrate("x")` | `integral(...)` | the same in `(2 + 3 x^2)^(1/4)` | +| `"1/((-2 + 3*x^2)*(-1 + 3*x^2)^(1/4))".ToEntity().Integrate("x")` | `integral(...)` | `-(arctan(u) + artanh(u))/(2 sqrt(6))`, `u = sqrt(3) x/(sqrt(2) (-1 + 3 x^2)^(1/4))` | + ### A rational function of the sine and cosine with symbols in it is integrated by the half angle `sin(x)^2/(a + b cos(x))` was left unevaluated while `sin(x)^2/(2 + 3 cos(x))` was answered. Under diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 261c1f821..9b9d757ce 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -3778,6 +3778,132 @@ private static bool TryReadAsABinomialIn(Entity expr, Entity.Variable x, out Ent return !c.ContainsNode(x) && n >= 1; } + /// + /// A root of a quadratic binomial beside another, 1/((A + B x^2)^(1/3) (C + D x^2)) + /// with B C + 3 A D = 0 or B C - 9 A D = 0, and + /// 1/((A + B x^2)^(1/4) (C + D x^2)) with B C - 2 A D = 0: the ratios at which + /// the integral, elliptic otherwise, is elementary, in closed form. + /// + /// + /// + /// With y the root, a = A^(1/3), and q = sqrt(B/A) or sqrt(-B/A) by its sign: + /// + /// B C + 3 A D = 0, B/A > 0: -2^(1/3) q/(4 a D) (atan(a q x/(a + 2^(1/3) y)) - atan(q x)/3 + /// - (artanh(sqrt(3) (a - 2^(1/3) y)/(a q x)) + artanh(sqrt(3)/(q x)))/sqrt(3)) + /// B/A < 0: 2^(1/3) q/(4 a D) (artanh(a q x/(a + 2^(1/3) y)) - artanh(q x)/3 + /// + (atan(sqrt(3) (a - 2^(1/3) y)/(a q x)) + atan(sqrt(3)/(q x)))/sqrt(3)) + /// B C - 9 A D = 0, B/A > 0: q/(12 a D) (atan((a - y)^2/(3 a^2 q x)) + atan(q x/3) + /// - sqrt(3) artanh(sqrt(3) (a - y)/(a q x))) + /// B/A < 0: q/(12 a D) (artanh((a - y)^2/(3 a^2 q x)) - artanh(q x/3) + /// - sqrt(3) atan(sqrt(3) (a - y)/(a q x))) + /// + /// and for the fourth root, with s = sqrt(A + B x^2) and r = sqrt(|B|), times + /// B/D, which takes C + D x^2 to 2 A + B x^2: + /// + /// A > 0, B > 0: -(atan(A^(3/4) (1 + s/sqrt(A))/(x y r)) + artanh(A^(3/4) (1 - s/sqrt(A))/(x y r)))/(2 A^(3/4) r) + /// A > 0, B < 0: (atan(A^(3/4) (1 - s/sqrt(A))/(x y r)) + artanh(A^(3/4) (1 + s/sqrt(A))/(x y r)))/(2 A^(3/4) r) + /// A < 0: -(atan(u) + artanh(u))/(2 (-A)^(3/4) sqrt(2) r), u = x r/((-A)^(1/4) y sqrt(2)) + /// + /// Rubi's, from its 1.1.2.3, written for any constants with the ratio; each was checked by + /// differentiating it at points in every sign case. The derivative of each uses only that + /// the roots are roots, so for a sign that is a symbol's both forms are given, each where + /// it holds. + /// https://github.com/asc-community/AngouriMath/issues/718 + /// + /// + internal static Entity? SolveAnEllipticLookingQuotientOfBinomials(Entity expr, Entity.Variable x) + { + var (numerator, denominator) = Functions.SingleQuotient.Of(expr); + if (numerator.ContainsNode(x)) + return null; + Entity constant = numerator; + Entity? radicand = null; + var order = 0; + Entity? other = null; + foreach (var factor in Mulf.LinearChildren(denominator)) + { + if (!factor.ContainsNode(x)) + constant = constant / factor; + else if (radicand is null && factor is Powf(var @base, Number.Rational power) && power.ERational.Numerator.Equals(EInteger.One) + && (power.ERational.Denominator.Equals(EInteger.FromInt32(3)) || power.ERational.Denominator.Equals(EInteger.FromInt32(4)))) + { + radicand = @base; + order = power.ERational.Denominator.ToInt32Unchecked(); + } + else if (other is null && factor is not Powf) + other = factor; + else + return null; + } + if (radicand is null || other is null || EvenQuadratic(radicand) is not var (a0, b0) || EvenQuadratic(other) is not var (c0, d0)) + return null; + var (A, B, C, D) = (a0, b0, c0, d0); + var y = MathS.Pow(radicand, Number.Rational.Create(1, order)); + Entity? answer = null; + if (order == 3 && VanishesIdentically(B * C + 3 * A * D)) + { + var a = MathS.Pow(A, Number.Rational.Create(1, 3)); + var cube = MathS.Pow(2, Number.Rational.Create(1, 3)); + var three = MathS.Sqrt(3); + var quarter = LowestOverTheSymbols(1 / (4 * D)); + Entity Positive(Entity q) => -quarter * cube * q / a * (MathS.Arctan(a * q * x / (a + cube * y)) - MathS.Arctan(q * x) / 3 + - (MathS.Hyperbolic.Artanh(three * (a - cube * y) / (a * q * x)) + MathS.Hyperbolic.Artanh(three / (q * x))) / three); + Entity Negative(Entity q) => quarter * cube * q / a * (MathS.Hyperbolic.Artanh(a * q * x / (a + cube * y)) - MathS.Hyperbolic.Artanh(q * x) / 3 + + (MathS.Arctan(three * (a - cube * y) / (a * q * x)) + MathS.Arctan(three / (q * x))) / three); + var ratio = LowestOverTheSymbols(B / A); + answer = BySign(ratio, Positive(MathS.Sqrt(ratio)), Negative(MathS.Sqrt(LowestOverTheSymbols(-ratio)))); + } + else if (order == 3 && VanishesIdentically(B * C - 9 * A * D)) + { + var a = MathS.Pow(A, Number.Rational.Create(1, 3)); + var three = MathS.Sqrt(3); + var twelfth = LowestOverTheSymbols(1 / (12 * D)); + Entity Positive(Entity q) => twelfth * q / a * (MathS.Arctan(MathS.Pow(a - y, 2) / (3 * MathS.Pow(a, 2) * q * x)) + MathS.Arctan(q * x / 3) + - three * MathS.Hyperbolic.Artanh(three * (a - y) / (a * q * x))); + Entity Negative(Entity q) => twelfth * q / a * (MathS.Hyperbolic.Artanh(MathS.Pow(a - y, 2) / (3 * MathS.Pow(a, 2) * q * x)) - MathS.Hyperbolic.Artanh(q * x / 3) + - three * MathS.Arctan(three * (a - y) / (a * q * x))); + var ratio = LowestOverTheSymbols(B / A); + answer = BySign(ratio, Positive(MathS.Sqrt(ratio)), Negative(MathS.Sqrt(LowestOverTheSymbols(-ratio)))); + } + else if (order == 4 && VanishesIdentically(B * C - 2 * A * D)) + { + var s = MathS.Sqrt(radicand); + var threeQuarters = Number.Rational.Create(3, 4); + Entity BothPositive() + { + var r = MathS.Sqrt(B); + return -(MathS.Arctan(MathS.Pow(A, threeQuarters) * (1 + s / MathS.Sqrt(A)) / (x * y * r)) + + MathS.Hyperbolic.Artanh(MathS.Pow(A, threeQuarters) * (1 - s / MathS.Sqrt(A)) / (x * y * r))) / (2 * MathS.Pow(A, threeQuarters) * r); + } + Entity SlopeNegative() + { + var r = MathS.Sqrt(-B); + return (MathS.Arctan(MathS.Pow(A, threeQuarters) * (1 - s / MathS.Sqrt(A)) / (x * y * r)) + + MathS.Hyperbolic.Artanh(MathS.Pow(A, threeQuarters) * (1 + s / MathS.Sqrt(A)) / (x * y * r))) / (2 * MathS.Pow(A, threeQuarters) * r); + } + Entity ConstantNegative() + { + var r = MathS.Sqrt(B); + var u = x * r / (MathS.Pow(-A, Number.Rational.Create(1, 4)) * y * MathS.Sqrt(2)); + return -(MathS.Arctan(u) + MathS.Hyperbolic.Artanh(u)) / (2 * MathS.Pow(-A, threeQuarters) * MathS.Sqrt(2) * r); + } + var toTheRatio = LowestOverTheSymbols(B / D); + var form = BySigns(A, B, BothPositive(), SlopeNegative(), ConstantNegative()); + answer = toTheRatio == Number.Integer.One ? form : toTheRatio * form; + } + return answer is null ? null : (constant * answer).InnerSimplified; + + // A + B x^2, both nonzero. + (Entity, Entity)? EvenQuadratic(Entity polynomial) + { + if (!TreeAnalyzer.TryGetPolynomial(polynomial, x, out var terms) || terms.Count != 2 + || !terms.TryGetValue(EInteger.Zero, out var free) || !terms.TryGetValue(EInteger.FromInt32(2), out var square) + || free.ContainsNode(x) || square.ContainsNode(x) || VanishesIdentically(free) || VanishesIdentically(square)) + return null; + return (free, square); + } + } + /// /// A binomial differential x^m (a + b x^n)^(p/q), in the two of Chebyshev's /// three cases that are not a whole power: (m + 1)/n whole, or diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs index 0058ebd66..981416585 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs @@ -972,6 +972,9 @@ private static Entity Normalized(Entity expr, Entity.Variable x) => // `a + b x^n`. After the quadratic, which is the case `n = 2` and answers it through // the trigonometric substitution -- a shorter answer than a root of a root. if ((answer = IndefiniteIntegralSolver.SolveABinomialDifferential(expr, x)) is { }) return answer; + // And a root of a quadratic binomial beside another at the ratios where the integral is + // elementary: `1/((1 - x^2)^(1/3) (3 + x^2))`, which is no binomial differential. + if ((answer = IndefiniteIntegralSolver.SolveAnEllipticLookingQuotientOfBinomials(expr, x)) is { }) return answer; // A rational function of x^n beside `(c + d x^n)^(k - 1/n)`, rationalised by // `u = x/(c + d x^n)^(1/n)`: Timofeev's `1/((1 + x^4)(2 + x^4)^(1/4))` is `1/(1 + u^4)`. if ((answer = IndefiniteIntegralSolver.SolveByDividingByTheRoot(expr, x)) is { }) return answer; diff --git a/Sources/Tests/UnitTests/Calculus/CubeRootLogarithmAnsatzTest.cs b/Sources/Tests/UnitTests/Calculus/CubeRootLogarithmAnsatzTest.cs index c807d1be0..90bbca09a 100644 --- a/Sources/Tests/UnitTests/Calculus/CubeRootLogarithmAnsatzTest.cs +++ b/Sources/Tests/UnitTests/Calculus/CubeRootLogarithmAnsatzTest.cs @@ -112,7 +112,7 @@ private static void DifferentiatesBack(string integrand) /// [Theory] [InlineData("1/(x*((-1 + x)*(q - 2*q*x + x^2))^(1/3))")] - [InlineData("1/((3 - x^2)*(1 + x^2)^(1/3))")] + [InlineData("1/((3 - x^2)*(2 + x^2)^(1/3))")] public void DeclinedWhereTheFieldIsNotHeld(string integrand) => Assert.Contains("integral(", integrand.ToEntity().Integrate("x").Stringize()); } diff --git a/Sources/Tests/UnitTests/Calculus/EllipticLookingQuotientOfBinomialsTest.cs b/Sources/Tests/UnitTests/Calculus/EllipticLookingQuotientOfBinomialsTest.cs new file mode 100644 index 000000000..15283ea63 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/EllipticLookingQuotientOfBinomialsTest.cs @@ -0,0 +1,95 @@ +// +// 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 cube or fourth root of a quadratic binomial beside another, at the ratios where the + /// integral, elliptic otherwise, is elementary: Rubi's 1.1.2.3. + /// #718 + /// + /// + /// Checked by differentiating back at points where the integrand is real, with the symbols + /// pinned in each sign case the closed forms are written for. + /// + [Trait("Area", "Calculus")] + public sealed class EllipticLookingQuotientOfBinomialsTest + { + private static void DifferentiatesBack(string integrand, double[] points, params (string, double)[] pins) + { + var integral = integrand.ToEntity().Integrate("x"); + Assert.DoesNotContain("integral(", integral.Stringize()); + var derivative = integral.Substitute("C", 0).Differentiate("x"); + Entity original = integrand.ToEntity(); + foreach (var (name, value) in pins) + { + derivative = derivative.Substitute(name, value); + original = original.Substitute(name, value); + } + var compared = 0; + foreach (var at in points) + { + var got = derivative.Substitute("x", at).EvalNumerical(); + var want = original.Substitute("x", at).EvalNumerical(); + if (got.IsNaN || want.IsNaN) + continue; + compared++; + var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart); + var scale = Math.Max(1.0, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)); + Assert.True(difference / scale < 1e-9, + $"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}"); + } + Assert.True(compared >= 3, $"only {compared} points could be compared for {integrand}"); + } + + /// + /// B C + 3 A D = 0 and B C - 9 A D = 0 under a cube root, for each sign of + /// b/a, and B C - 2 A D = 0 under a fourth root, for each sign of b with + /// a positive and for a negative. + /// + [Theory] + [InlineData("1/((a + b*x^2)^(1/3)*(3*a - b*x^2))", 1.3, 0.7, new[] { 0.3, 0.9, 1.7, -0.6 })] + [InlineData("1/((a + b*x^2)^(1/3)*(3*a - b*x^2))", 1.3, -0.7, new[] { 0.3, 0.9, 1.1, -0.6 })] + [InlineData("1/((a + b*x^2)^(1/3)*(9*a + b*x^2))", 1.3, 0.7, new[] { 0.3, 0.9, 1.7, -0.6 })] + [InlineData("1/((a + b*x^2)^(1/3)*(9*a + b*x^2))", 1.3, -0.7, new[] { 0.3, 0.9, 1.1, -0.6 })] + [InlineData("1/((a + b*x^2)^(1/4)*(2*a + b*x^2))", 1.3, 0.7, new[] { 0.3, 0.9, 1.7, -0.6 })] + [InlineData("1/((a + b*x^2)^(1/4)*(2*a + b*x^2))", 1.3, -0.7, new[] { 0.3, 0.9, 1.1, -0.6 })] + [InlineData("1/((a + b*x^2)^(1/4)*(2*a + b*x^2))", -1.3, 0.7, new[] { 1.5, 2.0, 2.6, -1.8 })] + public void AtTheRatioWhereItIsElementary(string integrand, double a, double b, double[] points) + => DifferentiatesBack(integrand, points, ("a", a), ("b", b)); + + /// With numbers in the constants. + [Theory] + [InlineData("1/((1 - x^2)^(1/3)*(3 + x^2))", new[] { 0.3, 0.6, 0.9, -0.5 })] + [InlineData("1/((1 + x^2)^(1/3)*(9 + x^2))", new[] { 0.3, 0.9, 1.7, -0.6 })] + [InlineData("1/((3 - x^2)*(1 + x^2)^(1/3))", new[] { 0.3, 0.9, 1.4, -0.6 })] + [InlineData("1/((2 + 3*x^2)^(1/4)*(4 + 3*x^2))", new[] { 0.3, 0.9, 1.7, -0.6 })] + [InlineData("1/((-2 + 3*x^2)*(-1 + 3*x^2)^(1/4))", new[] { 0.7, 1.1, 1.9, -1.3 })] + public void WithNumbers(string integrand, double[] points) + => DifferentiatesBack(integrand, points); + + /// + /// Across 0, where the cube root's answers are written over x: the value is the one + /// quadrature gives. + /// + [Theory] + [InlineData("integral(1/((1 + x^2)^(1/3)*(9 + x^2)), x, -1, 1)", 0.197369774498477432459)] + [InlineData("integral(1/((1 - x^2)^(1/3)*(3 + x^2)), x, -1/2, 1/2)", 0.334352054745427304208)] + public void ADefiniteIntegralAcrossZero(string integral, double expected) + { + var value = integral.ToEntity().Simplify(); + Assert.IsNotType(value); + var number = value.EvalNumerical(); + Assert.True(Math.Abs((double)number.RealPart - expected) < 1e-9 && Math.Abs((double)number.ImaginaryPart) < 1e-9, + $"{integral} is {value}, {number}, where quadrature gives {expected}"); + } + } +}