Skip to content

Commit b1af529

Browse files
A linear over a linear beside the root of a cubic binomial is integrated where that is elementary (#1781)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent f6e1e30 commit b1af529

5 files changed

Lines changed: 196 additions & 6 deletions

File tree

‎BREAKING-CHANGES.md‎

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

661+
### A linear over a linear beside the root of a cubic binomial is integrated where that is elementary
662+
663+
**Answers where there were none.** `(1 + x + sqrt(3))/((1 + x - sqrt(3)) sqrt(1 + x^3))` and the rest
664+
of Rubi's 1.3.2 quotients of linears, and of quadratics, beside the reciprocal of the root of
665+
`a + b x^3` were declined. The curve is elliptic, and the integral elementary only at coefficients
666+
where it is a constant times an arctangent or an inverse hyperbolic tangent of `(1 + p x)/sqrt(a + b x^3)`,
667+
or of its square over the root. Rubi's 1.3.3 names those coefficients, and its rules are taken
668+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
669+
670+
| Input | Was (2.5.0) | Now |
671+
|---|---|---|
672+
| `"(2^(2/3) - 2*x)/((2^(2/3) + x)*sqrt(1 + x^3))".ToEntity().Integrate("x")` | `integral(...)` | `2 2^(2/3) arctan(sqrt(3) (1 + 2^(1/3) x)/sqrt(1 + x^3))/sqrt(3)` |
673+
| `"(c - 2*d*x)/((c + d*x)*sqrt(c^3 + 4*d^3*x^3))".ToEntity().Integrate("x")` | `integral(...)` | `2 c/d` times an arctangent of `sqrt(3 c^3) (1 + 2 d x/c)/sqrt(c^3 + 4 d^3 x^3)` over `sqrt(3 c^3)`, or an inverse hyperbolic tangent, by the sign of `c^3` |
674+
| `"(1+x)/((x-2)*sqrt(1+x^3))".ToEntity().Integrate("x")` | `integral(...)` | `-(2/3) artanh((1 + x)^2/(3 sqrt(1 + x^3)))`, written as a logarithm |
675+
661676
### `x^2` over a three-quarter power of a quadratic binomial beside another is integrated where that is elementary
662677

663678
**Answers where there were none.** `x^2/((A + B x^2)^(3/4) (C + D x^2))` at `B C - 2 A D = 0`, Rubi's

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

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4818,6 +4818,108 @@ private static bool TryReadAsABinomialIn(Entity expr, Entity.Variable x, out Ent
48184818
return !c.ContainsNode(x) && n >= 1;
48194819
}
48204820

4821+
/// <summary>
4822+
/// A linear over a linear, or a quadratic over a quadratic, beside the reciprocal of the
4823+
/// square root of a cubic binomial <c>a + b x^3</c>, at the coefficients where its
4824+
/// integral is elementary: Rubi's <c>(1 + x + sqrt(3))/((1 + x - sqrt(3)) sqrt(1 + x^3))</c>,
4825+
/// <c>(c - 2 d x)/((c + d x) sqrt(c^3 + 4 d^3 x^3))</c>.
4826+
/// </summary>
4827+
/// <remarks>
4828+
/// <para>
4829+
/// The curve <c>y^2 = a + b x^3</c> is elliptic, and the integral of <c>(e + f x)/((c + d x) y)</c>
4830+
/// is elementary only where the coefficients make it so. Rubi's 1.3.3 names those places,
4831+
/// and at each the integral is a constant times <c>int du/(1 + K u^2)</c> at
4832+
/// <c>u = (1 + p x)/y</c>, or <c>(1 + p x)^2/y</c>:
4833+
/// <code>
4834+
/// b c^3 = 4 a d^3, 2 d e + c f = 0: (2 e/d) int 1/(1 + 3 a u^2), u = (1 + 2 d x/c)/y
4835+
/// b c^3 = -8 a d^3, 2 d e + c f = 0: (-2 e/(9 d)) int 1/(1 - (a/9) u^2), u = (1 + f x/e)^2/y
4836+
/// b^2 c^6 - 20 a b c^3 d^3 - 8 a^2 d^6 = 0, 6 a d^4 e = c f (b c^3 - 22 a d^3), k = (d e + 2 c f)/(c f):
4837+
/// ((1 + k) e/d) int 1/(1 + (3 + 2k) a u^2), u = (1 + (1 + k) d x/c)/y
4838+
/// </code>
4839+
/// and over a quadratic, <c>(f + g x + h x^2)/((c + d x + e x^2) y)</c> where
4840+
/// <c>b g^3 = 8 a h^3</c>, <c>g^2 + 2 f h = 0</c> and <c>b d f + b c g = 4 a e h</c>:
4841+
/// <c>-(g/e) int 1/(1 - M u^2)</c>, <c>M = (b d f - 2 a e h)/(2 e h)</c>, at <c>u = (1 + 2 h x/g)/y</c>.
4842+
/// Each condition is decided at sampled values of the symbols, the inner integral is an
4843+
/// arctangent or an inverse hyperbolic tangent by the sign of its constant, and the answer
4844+
/// is differentiated back at sampled points before it is returned.
4845+
/// https://github.com/asc-community/AngouriMath/issues/718
4846+
/// </para>
4847+
/// </remarks>
4848+
internal static Entity? SolveAPseudoEllipticQuotientOverTheRootOfACubicBinomial(Entity expr, Entity.Variable x)
4849+
{
4850+
var (numerator, denominator) = Functions.SingleQuotient.Of(expr);
4851+
Entity? radicand = null;
4852+
Entity below = Number.Integer.One;
4853+
foreach (var factor in Mulf.LinearChildren(denominator))
4854+
if (factor is Powf(var @base, Number.Rational half) && half.ERational.Equals(ERational.Create(1, 2)) && @base.ContainsNode(x))
4855+
{
4856+
if (radicand is not null)
4857+
return null;
4858+
radicand = @base;
4859+
}
4860+
else
4861+
below *= factor;
4862+
if (radicand is null || numerator.Nodes.Any(node => node is Powf(_, Number.Rational r) && r is not Number.Integer && node.ContainsNode(x))
4863+
|| !TreeAnalyzer.TryGetPolynomial(radicand, x, out var cubic) || cubic.Count != 2
4864+
|| !cubic.TryGetValue(EInteger.Zero, out var a) || !cubic.TryGetValue(EInteger.FromInt32(3), out var b)
4865+
|| !TreeAnalyzer.TryGetPolynomial(numerator, x, out var above) || !TreeAnalyzer.TryGetPolynomial(below, x, out var under))
4866+
return null;
4867+
Entity Coefficient(Dictionary<EInteger, Entity> read, int power)
4868+
=> read.TryGetValue(EInteger.FromInt32(power), out var value) ? value : Number.Integer.Zero;
4869+
int Degree(Dictionary<EInteger, Entity> read) => read.Count == 0 ? -1 : read.Keys.Max()!.ToInt32Unchecked();
4870+
if (Degree(above) > 2 || Degree(under) is not (1 or 2) || Degree(above) > Degree(under))
4871+
return null;
4872+
// A condition is decided as a value, at pinned symbols where nothing simplifies it
4873+
// to zero -- `6 a d^4 e - c f (b c^3 - 22 a d^3)` at `c = 1 - sqrt(3)` and
4874+
// `d = (b/a)^(1/3)` is one -- since the answer is checked by its derivative anyway.
4875+
static bool Zero(Entity condition) => Functions.PartialFractions.IsZeroAsAValue(condition);
4876+
var y = MathS.Sqrt(radicand);
4877+
var u = Variable.CreateUnique(expr, "u_pseudo");
4878+
// int du/(1 + K u^2), by the sign of K.
4879+
Entity OverOnePlus(Entity k)
4880+
{
4881+
var kLowest = LowestOverTheSymbols(k);
4882+
return BySign(kLowest,
4883+
MathS.Arctan(MathS.Sqrt(kLowest) * u) / MathS.Sqrt(kLowest),
4884+
MathS.Hyperbolic.Artanh(MathS.Sqrt(LowestOverTheSymbols(-kLowest)) * u) / MathS.Sqrt(LowestOverTheSymbols(-kLowest)));
4885+
}
4886+
Entity? answer = null;
4887+
if (Degree(under) == 1)
4888+
{
4889+
var (e, f) = (Coefficient(above, 0), Coefficient(above, 1));
4890+
var (c, d) = (Coefficient(under, 0), Coefficient(under, 1));
4891+
if (Zero(d * e - c * f) || Zero(c))
4892+
return null;
4893+
if (Zero(b * MathS.Pow(c, 3) - 4 * a * MathS.Pow(d, 3)) && Zero(2 * d * e + c * f))
4894+
answer = (2 * e / d * OverOnePlus(3 * a)).Substitute(u, (1 + 2 * d * x / c) / y);
4895+
else if (!Zero(e) && Zero(b * MathS.Pow(c, 3) + 8 * a * MathS.Pow(d, 3)) && Zero(2 * d * e + c * f))
4896+
answer = (-2 * e / (9 * d) * OverOnePlus(-a / 9)).Substitute(u, MathS.Pow(1 + f * x / e, 2) / y);
4897+
else if (!Zero(f)
4898+
&& Zero(MathS.Pow(b, 2) * MathS.Pow(c, 6) - 20 * a * b * MathS.Pow(c, 3) * MathS.Pow(d, 3) - 8 * MathS.Pow(a, 2) * MathS.Pow(d, 6))
4899+
&& Zero(6 * a * MathS.Pow(d, 4) * e - c * f * (b * MathS.Pow(c, 3) - 22 * a * MathS.Pow(d, 3))))
4900+
{
4901+
var k = LowestOverTheSymbols((d * e + 2 * c * f) / (c * f));
4902+
answer = ((1 + k) * e / d * OverOnePlus((3 + 2 * k) * a)).Substitute(u, (1 + (1 + k) * d * x / c) / y);
4903+
}
4904+
}
4905+
else
4906+
{
4907+
var (f, g, h) = (Coefficient(above, 0), Coefficient(above, 1), Coefficient(above, 2));
4908+
var (c, d, e) = (Coefficient(under, 0), Coefficient(under, 1), Coefficient(under, 2));
4909+
if (!Zero(g) && !Zero(h)
4910+
&& Zero(b * MathS.Pow(g, 3) - 8 * a * MathS.Pow(h, 3)) && Zero(MathS.Pow(g, 2) + 2 * f * h)
4911+
&& Zero(b * d * f + b * c * g - 4 * a * e * h) && !Zero(b * d * f - 2 * a * e * h))
4912+
answer = (-g / e * OverOnePlus(-(b * d * f - 2 * a * e * h) / (2 * e * h))).Substitute(u, (1 + 2 * h * x / g) / y);
4913+
}
4914+
if (answer is null)
4915+
return null;
4916+
answer = answer.InnerSimplified;
4917+
bool holds;
4918+
using (MathS.Settings.DowncastingEnabled.Set(false))
4919+
holds = Functions.PartialFractions.HoldsAtSampledPoints(answer.Differentiate(x), expr, x);
4920+
return holds ? answer : null;
4921+
}
4922+
48214923
/// <summary>
48224924
/// A root of a quadratic binomial beside another, <c>1/((A + B x^2)^(1/3) (C + D x^2))</c>
48234925
/// with <c>B C + 3 A D = 0</c> or <c>B C - 9 A D = 0</c>, and

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,11 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
795795
// the polynomial written in powers of the linear at its root: the part the power
796796
// divides goes over the rest alone. Before the split, so that the whole polynomial
797797
// is reduced once rather than each of its terms.
798+
// A linear over a linear beside the root of a cubic binomial, or a quadratic over a
799+
// quadratic, at the coefficients where the integral is elementary: Rubi's
800+
// `(1 + x + sqrt(3))/((1 + x - sqrt(3)) sqrt(1 + x^3))`. Before the reduction over the
801+
// linear, which writes it as `1` and `2 sqrt(3)` over the linear, neither elementary.
802+
if ((answer = IndefiniteIntegralSolver.SolveAPseudoEllipticQuotientOverTheRootOfACubicBinomial(expr, x)) is { }) return answer;
798803
if ((answer = IndefiniteIntegralSolver.SolveByReducingThePolynomialOverALinearFactor(expr, x, integrateByParts)) is { }) return answer;
799804
if (expr is Entity.Sumf or Entity.Minusf
800805
&& (answer = IndefiniteIntegralSolver.SolveBySplittingSum(expr, x, integrateByParts)) is { })
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 linear over a linear, or a quadratic over a quadratic, beside the reciprocal of the
16+
/// square root of a cubic binomial, at the coefficients where the integral is elementary:
17+
/// Rubi's 1.3.2, by its 1.3.3's rules.
18+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
19+
/// </summary>
20+
/// <remarks>
21+
/// Checked by differentiating back with <c>a = 1.3</c>, <c>b = 0.7</c>, <c>c = 1.1</c> and
22+
/// <c>d = 0.6</c>, at points where the radicand is positive and away from the pole.
23+
/// </remarks>
24+
[Trait("Area", "Calculus")]
25+
public sealed class PseudoEllipticQuotientIntegralTest
26+
{
27+
[Theory]
28+
// b c^3 = 4 a d^3 and 2 d e + c f = 0.
29+
[InlineData("(c - 2*d*x)/((c + d*x)*sqrt(c^3 + 4*d^3*x^3))")]
30+
[InlineData("(2^(2/3) - 2*x)/((2^(2/3) + x)*sqrt(1 + x^3))")]
31+
// b c^3 = -8 a d^3 and 2 d e + c f = 0.
32+
[InlineData("(a^(1/3) + b^(1/3)*x)/((2*a^(1/3) - b^(1/3)*x)*sqrt(a + b*x^3))")]
33+
// b^2 c^6 - 20 a b c^3 d^3 - 8 a^2 d^6 = 0, at its second condition.
34+
[InlineData("(1 + x + sqrt(3))/((1 + x - sqrt(3))*sqrt(1 + x^3))")]
35+
[InlineData("(1 + (b/a)^(1/3)*x - sqrt(3))/((1 + (b/a)^(1/3)*x + sqrt(3))*sqrt(a + b*x^3))")]
36+
// A quadratic over a quadratic.
37+
[InlineData("(2 - 2*x - x^2)/((2 + d + d*x + x^2)*sqrt(1 + x^3))")]
38+
public void IsIntegrated(string integrand)
39+
{
40+
var integral = integrand.ToEntity().Integrate("x");
41+
Assert.DoesNotContain("integral(", integral.Stringize());
42+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7).Substitute("c", 1.1).Substitute("d", 0.6);
43+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
44+
var original = Pinned(integrand.ToEntity());
45+
foreach (var at in new[] { -0.8, -0.4, 0.3, 1.1, 1.6 })
46+
{
47+
var want = original.Substitute("x", at).EvalNumerical();
48+
var got = derivative.Substitute("x", at).EvalNumerical();
49+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
50+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
51+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
52+
}
53+
}
54+
}
55+
}

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,12 @@ private static void DifferentiatesBack(string integrand, double[] points)
6565
private static readonly double[] AboveMinusOne = { -0.7, -0.3, 0.2, 0.5, 0.8, 1.6, 2.4, 3.5 };
6666

6767
/// <summary>
68-
/// Welz's, a logarithm at the pole <c>2</c> where <c>1 + x^3</c> is <c>9</c>:
69-
/// <c>(2/3) ln((1 + x)^2/3 - sqrt(1 + x^3)) - ln(x - 2) - ln(1 + x)/3</c>; the same with
70-
/// a rational part, <c>(2/3) sqrt(1 + x^3)</c>, brought over the denominator, and as a
71-
/// sum.
68+
/// Welz's with a rational part, <c>(2/3) sqrt(1 + x^3)</c>, brought over the denominator:
69+
/// a logarithm at the pole <c>2</c> where <c>1 + x^3</c> is <c>9</c>,
70+
/// <c>(2/3) ln((1 + x)^2/3 - sqrt(1 + x^3)) - ln(x - 2) - ln(1 + x)/3</c>.
7271
/// </summary>
7372
[Theory]
74-
[InlineData("(1+x)/((x-2)*sqrt(1+x^3))")]
7573
[InlineData("(x^3-2*x^2+x+1)/((x-2)*sqrt(1+x^3))")]
76-
[InlineData("(1+x)/((x-2)*sqrt(1+x^3)) + x^2/sqrt(1+x^3)")]
7774
public void ALogarithmAtAPole(string integrand)
7875
{
7976
DifferentiatesBack(integrand, AboveMinusOne);
@@ -82,6 +79,22 @@ public void ALogarithmAtAPole(string integrand)
8279
Assert.Contains("ln(x - 2)", integral);
8380
}
8481

82+
/// <summary>
83+
/// Welz's own, a linear over a linear, and as a sum: one of the pseudo-elliptic quotients
84+
/// a closed rule answers before the ansatz is asked, as
85+
/// <c>-(2/3) artanh((1 + x)^2/(3 sqrt(1 + x^3)))</c>, one logarithm where the ansatz
86+
/// writes three.
87+
/// </summary>
88+
[Theory]
89+
[InlineData("(1+x)/((x-2)*sqrt(1+x^3))")]
90+
[InlineData("(1+x)/((x-2)*sqrt(1+x^3)) + x^2/sqrt(1+x^3)")]
91+
public void WelzsIsOneLogarithm(string integrand)
92+
{
93+
DifferentiatesBack(integrand, AboveMinusOne);
94+
var integral = integrand.ToEntity().Integrate("x").Stringize();
95+
Assert.Equal(1, integral.Split("ln(").Length - 1);
96+
}
97+
8598
/// <summary>
8699
/// Bronstein's, matched at infinity: the answer is
87100
/// <c>-ln(A - B sqrt(P))/8</c> with <c>A = x^8 + 20x^6 - 128x^5 + 54x^4 - 1408x^3 + 3124x^2 + 10001</c>

0 commit comments

Comments
 (0)