Skip to content

Commit 84c99a3

Browse files
A cube or fourth root of a quadratic binomial beside another is integrated at the ratios where it is elementary (#1707)
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 #718 Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 0585dbb commit 84c99a3

5 files changed

Lines changed: 246 additions & 1 deletion

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,27 @@ leading coefficient once expanded, and declined: it is read expanded and bare no
359359
| `"sin(x)/(a+b*sin(x))^3".Integrate("x")`, Rubi's 4.1.2.1 row 242 | `integral(...)` | the antiderivative |
360360
| `"4*x*(1+x^2)/(a*x^2+2*b*x+a)^3".Integrate("x")` | `integral(...)` | the antiderivative |
361361

362+
### A cube or fourth root of a quadratic binomial beside another is integrated where that is elementary
363+
364+
**Answers where there were none.** `1/((A + B x^2)^(1/3) (C + D x^2))` is an elliptic integral
365+
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
366+
where `B C - 2 A D = 0`. At those ratios it is arctangents and logarithms of quotients in the root,
367+
as Rubi's 1.1.2.3 gives them, and it was left unevaluated. It is answered there now, with symbols
368+
in the constants too: by the sign of `B/A` for the cube root, and by the signs of `A` and `B` for
369+
the fourth. With `A` and `B` both positive, the fourth root's answer jumps at `x = 0`, and is an
370+
antiderivative on each side of it, as Rubi's is
371+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
372+
373+
| Input | Was (2.5.0) | Now |
374+
|---|---|---|
375+
| `"1/((1 - x^2)^(1/3)*(3 + x^2))".ToEntity().Integrate("x")` | `integral(...)` | arctangents and logarithms in `x` and `(1 - x^2)^(1/3)` |
376+
| `"1/((1 + x^2)^(1/3)*(9 + x^2))".ToEntity().Integrate("x")` | `integral(...)` | the same in `(1 + x^2)^(1/3)` |
377+
| `"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` |
378+
| `"1/((a + b*x^2)^(1/3)*(9*a + b*x^2))".ToEntity().Integrate("x")` | `integral(...)` | the same, by the sign of `b/a` |
379+
| `"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` |
380+
| `"1/((2 + 3*x^2)^(1/4)*(4 + 3*x^2))".ToEntity().Integrate("x")` | `integral(...)` | the same in `(2 + 3 x^2)^(1/4)` |
381+
| `"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))` |
382+
362383
### A rational function of the sine and cosine with symbols in it is integrated by the half angle
363384

364385
`sin(x)^2/(a + b cos(x))` was left unevaluated while `sin(x)^2/(2 + 3 cos(x))` was answered. Under

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

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,6 +4049,132 @@ private static bool TryReadAsABinomialIn(Entity expr, Entity.Variable x, out Ent
40494049
return !c.ContainsNode(x) && n >= 1;
40504050
}
40514051

4052+
/// <summary>
4053+
/// A root of a quadratic binomial beside another, <c>1/((A + B x^2)^(1/3) (C + D x^2))</c>
4054+
/// with <c>B C + 3 A D = 0</c> or <c>B C - 9 A D = 0</c>, and
4055+
/// <c>1/((A + B x^2)^(1/4) (C + D x^2))</c> with <c>B C - 2 A D = 0</c>: the ratios at which
4056+
/// the integral, elliptic otherwise, is elementary, in closed form.
4057+
/// </summary>
4058+
/// <remarks>
4059+
/// <para>
4060+
/// With <c>y</c> the root, <c>a = A^(1/3)</c>, and <c>q = sqrt(B/A)</c> or <c>sqrt(-B/A)</c> by its sign:
4061+
/// <code>
4062+
/// B C + 3 A D = 0, B/A &gt; 0: -2^(1/3) q/(4 a D) (atan(a q x/(a + 2^(1/3) y)) - atan(q x)/3
4063+
/// - (artanh(sqrt(3) (a - 2^(1/3) y)/(a q x)) + artanh(sqrt(3)/(q x)))/sqrt(3))
4064+
/// B/A &lt; 0: 2^(1/3) q/(4 a D) (artanh(a q x/(a + 2^(1/3) y)) - artanh(q x)/3
4065+
/// + (atan(sqrt(3) (a - 2^(1/3) y)/(a q x)) + atan(sqrt(3)/(q x)))/sqrt(3))
4066+
/// B C - 9 A D = 0, B/A &gt; 0: q/(12 a D) (atan((a - y)^2/(3 a^2 q x)) + atan(q x/3)
4067+
/// - sqrt(3) artanh(sqrt(3) (a - y)/(a q x)))
4068+
/// B/A &lt; 0: q/(12 a D) (artanh((a - y)^2/(3 a^2 q x)) - artanh(q x/3)
4069+
/// - sqrt(3) atan(sqrt(3) (a - y)/(a q x)))
4070+
/// </code>
4071+
/// and for the fourth root, with <c>s = sqrt(A + B x^2)</c> and <c>r = sqrt(|B|)</c>, times
4072+
/// <c>B/D</c>, which takes <c>C + D x^2</c> to <c>2 A + B x^2</c>:
4073+
/// <code>
4074+
/// A &gt; 0, B &gt; 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)
4075+
/// A &gt; 0, B &lt; 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)
4076+
/// A &lt; 0: -(atan(u) + artanh(u))/(2 (-A)^(3/4) sqrt(2) r), u = x r/((-A)^(1/4) y sqrt(2))
4077+
/// </code>
4078+
/// Rubi's, from its 1.1.2.3, written for any constants with the ratio; each was checked by
4079+
/// differentiating it at points in every sign case. The derivative of each uses only that
4080+
/// the roots are roots, so for a sign that is a symbol's both forms are given, each where
4081+
/// it holds.
4082+
/// https://github.com/asc-community/AngouriMath/issues/718
4083+
/// </para>
4084+
/// </remarks>
4085+
internal static Entity? SolveAnEllipticLookingQuotientOfBinomials(Entity expr, Entity.Variable x)
4086+
{
4087+
var (numerator, denominator) = Functions.SingleQuotient.Of(expr);
4088+
if (numerator.ContainsNode(x))
4089+
return null;
4090+
Entity constant = numerator;
4091+
Entity? radicand = null;
4092+
var order = 0;
4093+
Entity? other = null;
4094+
foreach (var factor in Mulf.LinearChildren(denominator))
4095+
{
4096+
if (!factor.ContainsNode(x))
4097+
constant = constant / factor;
4098+
else if (radicand is null && factor is Powf(var @base, Number.Rational power) && power.ERational.Numerator.Equals(EInteger.One)
4099+
&& (power.ERational.Denominator.Equals(EInteger.FromInt32(3)) || power.ERational.Denominator.Equals(EInteger.FromInt32(4))))
4100+
{
4101+
radicand = @base;
4102+
order = power.ERational.Denominator.ToInt32Unchecked();
4103+
}
4104+
else if (other is null && factor is not Powf)
4105+
other = factor;
4106+
else
4107+
return null;
4108+
}
4109+
if (radicand is null || other is null || EvenQuadratic(radicand) is not var (a0, b0) || EvenQuadratic(other) is not var (c0, d0))
4110+
return null;
4111+
var (A, B, C, D) = (a0, b0, c0, d0);
4112+
var y = MathS.Pow(radicand, Number.Rational.Create(1, order));
4113+
Entity? answer = null;
4114+
if (order == 3 && VanishesIdentically(B * C + 3 * A * D))
4115+
{
4116+
var a = MathS.Pow(A, Number.Rational.Create(1, 3));
4117+
var cube = MathS.Pow(2, Number.Rational.Create(1, 3));
4118+
var three = MathS.Sqrt(3);
4119+
var quarter = LowestOverTheSymbols(1 / (4 * D));
4120+
Entity Positive(Entity q) => -quarter * cube * q / a * (MathS.Arctan(a * q * x / (a + cube * y)) - MathS.Arctan(q * x) / 3
4121+
- (MathS.Hyperbolic.Artanh(three * (a - cube * y) / (a * q * x)) + MathS.Hyperbolic.Artanh(three / (q * x))) / three);
4122+
Entity Negative(Entity q) => quarter * cube * q / a * (MathS.Hyperbolic.Artanh(a * q * x / (a + cube * y)) - MathS.Hyperbolic.Artanh(q * x) / 3
4123+
+ (MathS.Arctan(three * (a - cube * y) / (a * q * x)) + MathS.Arctan(three / (q * x))) / three);
4124+
var ratio = LowestOverTheSymbols(B / A);
4125+
answer = BySign(ratio, Positive(MathS.Sqrt(ratio)), Negative(MathS.Sqrt(LowestOverTheSymbols(-ratio))));
4126+
}
4127+
else if (order == 3 && VanishesIdentically(B * C - 9 * A * D))
4128+
{
4129+
var a = MathS.Pow(A, Number.Rational.Create(1, 3));
4130+
var three = MathS.Sqrt(3);
4131+
var twelfth = LowestOverTheSymbols(1 / (12 * D));
4132+
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)
4133+
- three * MathS.Hyperbolic.Artanh(three * (a - y) / (a * q * x)));
4134+
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)
4135+
- three * MathS.Arctan(three * (a - y) / (a * q * x)));
4136+
var ratio = LowestOverTheSymbols(B / A);
4137+
answer = BySign(ratio, Positive(MathS.Sqrt(ratio)), Negative(MathS.Sqrt(LowestOverTheSymbols(-ratio))));
4138+
}
4139+
else if (order == 4 && VanishesIdentically(B * C - 2 * A * D))
4140+
{
4141+
var s = MathS.Sqrt(radicand);
4142+
var threeQuarters = Number.Rational.Create(3, 4);
4143+
Entity BothPositive()
4144+
{
4145+
var r = MathS.Sqrt(B);
4146+
return -(MathS.Arctan(MathS.Pow(A, threeQuarters) * (1 + s / MathS.Sqrt(A)) / (x * y * r))
4147+
+ MathS.Hyperbolic.Artanh(MathS.Pow(A, threeQuarters) * (1 - s / MathS.Sqrt(A)) / (x * y * r))) / (2 * MathS.Pow(A, threeQuarters) * r);
4148+
}
4149+
Entity SlopeNegative()
4150+
{
4151+
var r = MathS.Sqrt(-B);
4152+
return (MathS.Arctan(MathS.Pow(A, threeQuarters) * (1 - s / MathS.Sqrt(A)) / (x * y * r))
4153+
+ MathS.Hyperbolic.Artanh(MathS.Pow(A, threeQuarters) * (1 + s / MathS.Sqrt(A)) / (x * y * r))) / (2 * MathS.Pow(A, threeQuarters) * r);
4154+
}
4155+
Entity ConstantNegative()
4156+
{
4157+
var r = MathS.Sqrt(B);
4158+
var u = x * r / (MathS.Pow(-A, Number.Rational.Create(1, 4)) * y * MathS.Sqrt(2));
4159+
return -(MathS.Arctan(u) + MathS.Hyperbolic.Artanh(u)) / (2 * MathS.Pow(-A, threeQuarters) * MathS.Sqrt(2) * r);
4160+
}
4161+
var toTheRatio = LowestOverTheSymbols(B / D);
4162+
var form = BySigns(A, B, BothPositive(), SlopeNegative(), ConstantNegative());
4163+
answer = toTheRatio == Number.Integer.One ? form : toTheRatio * form;
4164+
}
4165+
return answer is null ? null : (constant * answer).InnerSimplified;
4166+
4167+
// A + B x^2, both nonzero.
4168+
(Entity, Entity)? EvenQuadratic(Entity polynomial)
4169+
{
4170+
if (!TreeAnalyzer.TryGetPolynomial(polynomial, x, out var terms) || terms.Count != 2
4171+
|| !terms.TryGetValue(EInteger.Zero, out var free) || !terms.TryGetValue(EInteger.FromInt32(2), out var square)
4172+
|| free.ContainsNode(x) || square.ContainsNode(x) || VanishesIdentically(free) || VanishesIdentically(square))
4173+
return null;
4174+
return (free, square);
4175+
}
4176+
}
4177+
40524178
/// <summary>
40534179
/// A <b>binomial differential</b> <c>x^m (a + b x^n)^(p/q)</c>, in the two of Chebyshev's
40544180
/// three cases that are not a whole power: <c>(m + 1)/n</c> whole, or

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,9 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
980980
// `a + b x^n`. After the quadratic, which is the case `n = 2` and answers it through
981981
// the trigonometric substitution -- a shorter answer than a root of a root.
982982
if ((answer = IndefiniteIntegralSolver.SolveABinomialDifferential(expr, x)) is { }) return answer;
983+
// And a root of a quadratic binomial beside another at the ratios where the integral is
984+
// elementary: `1/((1 - x^2)^(1/3) (3 + x^2))`, which is no binomial differential.
985+
if ((answer = IndefiniteIntegralSolver.SolveAnEllipticLookingQuotientOfBinomials(expr, x)) is { }) return answer;
983986
// A rational function of x^n beside `(c + d x^n)^(k - 1/n)`, rationalised by
984987
// `u = x/(c + d x^n)^(1/n)`: Timofeev's `1/((1 + x^4)(2 + x^4)^(1/4))` is `1/(1 + u^4)`.
985988
if ((answer = IndefiniteIntegralSolver.SolveByDividingByTheRoot(expr, x)) is { }) return answer;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private static void DifferentiatesBack(string integrand)
112112
/// </summary>
113113
[Theory]
114114
[InlineData("1/(x*((-1 + x)*(q - 2*q*x + x^2))^(1/3))")]
115-
[InlineData("1/((3 - x^2)*(1 + x^2)^(1/3))")]
115+
[InlineData("1/((3 - x^2)*(2 + x^2)^(1/3))")]
116116
public void DeclinedWhereTheFieldIsNotHeld(string integrand)
117117
=> Assert.Contains("integral(", integrand.ToEntity().Integrate("x").Stringize());
118118
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using System;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// A cube or fourth root of a quadratic binomial beside another, at the ratios where the
16+
/// integral, elliptic otherwise, is elementary: Rubi's 1.1.2.3.
17+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
18+
/// </summary>
19+
/// <remarks>
20+
/// Checked by differentiating back at points where the integrand is real, with the symbols
21+
/// pinned in each sign case the closed forms are written for.
22+
/// </remarks>
23+
[Trait("Area", "Calculus")]
24+
public sealed class EllipticLookingQuotientOfBinomialsTest
25+
{
26+
private static void DifferentiatesBack(string integrand, double[] points, params (string, double)[] pins)
27+
{
28+
var integral = integrand.ToEntity().Integrate("x");
29+
Assert.DoesNotContain("integral(", integral.Stringize());
30+
var derivative = integral.Substitute("C", 0).Differentiate("x");
31+
Entity original = integrand.ToEntity();
32+
foreach (var (name, value) in pins)
33+
{
34+
derivative = derivative.Substitute(name, value);
35+
original = original.Substitute(name, value);
36+
}
37+
var compared = 0;
38+
foreach (var at in points)
39+
{
40+
var got = derivative.Substitute("x", at).EvalNumerical();
41+
var want = original.Substitute("x", at).EvalNumerical();
42+
if (got.IsNaN || want.IsNaN)
43+
continue;
44+
compared++;
45+
var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart);
46+
var scale = Math.Max(1.0, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart));
47+
Assert.True(difference / scale < 1e-9,
48+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
49+
}
50+
Assert.True(compared >= 3, $"only {compared} points could be compared for {integrand}");
51+
}
52+
53+
/// <summary>
54+
/// <c>B C + 3 A D = 0</c> and <c>B C - 9 A D = 0</c> under a cube root, for each sign of
55+
/// <c>b/a</c>, and <c>B C - 2 A D = 0</c> under a fourth root, for each sign of <c>b</c> with
56+
/// <c>a</c> positive and for <c>a</c> negative.
57+
/// </summary>
58+
[Theory]
59+
[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 })]
60+
[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 })]
61+
[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 })]
62+
[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 })]
63+
[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 })]
64+
[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 })]
65+
[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 })]
66+
public void AtTheRatioWhereItIsElementary(string integrand, double a, double b, double[] points)
67+
=> DifferentiatesBack(integrand, points, ("a", a), ("b", b));
68+
69+
/// <summary>With numbers in the constants.</summary>
70+
[Theory]
71+
[InlineData("1/((1 - x^2)^(1/3)*(3 + x^2))", new[] { 0.3, 0.6, 0.9, -0.5 })]
72+
[InlineData("1/((1 + x^2)^(1/3)*(9 + x^2))", new[] { 0.3, 0.9, 1.7, -0.6 })]
73+
[InlineData("1/((3 - x^2)*(1 + x^2)^(1/3))", new[] { 0.3, 0.9, 1.4, -0.6 })]
74+
[InlineData("1/((2 + 3*x^2)^(1/4)*(4 + 3*x^2))", new[] { 0.3, 0.9, 1.7, -0.6 })]
75+
[InlineData("1/((-2 + 3*x^2)*(-1 + 3*x^2)^(1/4))", new[] { 0.7, 1.1, 1.9, -1.3 })]
76+
public void WithNumbers(string integrand, double[] points)
77+
=> DifferentiatesBack(integrand, points);
78+
79+
/// <summary>
80+
/// Across 0, where the cube root's answers are written over <c>x</c>: the value is the one
81+
/// quadrature gives.
82+
/// </summary>
83+
[Theory]
84+
[InlineData("integral(1/((1 + x^2)^(1/3)*(9 + x^2)), x, -1, 1)", 0.197369774498477432459)]
85+
[InlineData("integral(1/((1 - x^2)^(1/3)*(3 + x^2)), x, -1/2, 1/2)", 0.334352054745427304208)]
86+
public void ADefiniteIntegralAcrossZero(string integral, double expected)
87+
{
88+
var value = integral.ToEntity().Simplify();
89+
Assert.IsNotType<Entity.Integralf>(value);
90+
var number = value.EvalNumerical();
91+
Assert.True(Math.Abs((double)number.RealPart - expected) < 1e-9 && Math.Abs((double)number.ImaginaryPart) < 1e-9,
92+
$"{integral} is {value}, {number}, where quadrature gives {expected}");
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)