Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,21 @@ 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 linear over a linear beside the root of a cubic binomial is integrated where that is elementary

**Answers where there were none.** `(1 + x + sqrt(3))/((1 + x - sqrt(3)) sqrt(1 + x^3))` and the rest
of Rubi's 1.3.2 quotients of linears, and of quadratics, beside the reciprocal of the root of
`a + b x^3` were declined. The curve is elliptic, and the integral elementary only at coefficients
where it is a constant times an arctangent or an inverse hyperbolic tangent of `(1 + p x)/sqrt(a + b x^3)`,
or of its square over the root. Rubi's 1.3.3 names those coefficients, and its rules are taken
([#718](https://github.com/asc-community/AngouriMath/issues/718)).

| Input | Was (2.5.0) | Now |
|---|---|---|
| `"(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)` |
| `"(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` |
| `"(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 |

### `x^2` over a three-quarter power of a quadratic binomial beside another is integrated where that is elementary

**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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4818,6 +4818,108 @@ private static bool TryReadAsABinomialIn(Entity expr, Entity.Variable x, out Ent
return !c.ContainsNode(x) && n >= 1;
}

/// <summary>
/// A linear over a linear, or a quadratic over a quadratic, beside the reciprocal of the
/// square root of a cubic binomial <c>a + b x^3</c>, at the coefficients where its
/// integral is elementary: Rubi's <c>(1 + x + sqrt(3))/((1 + x - sqrt(3)) sqrt(1 + x^3))</c>,
/// <c>(c - 2 d x)/((c + d x) sqrt(c^3 + 4 d^3 x^3))</c>.
/// </summary>
/// <remarks>
/// <para>
/// 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>
/// is elementary only where the coefficients make it so. Rubi's 1.3.3 names those places,
/// and at each the integral is a constant times <c>int du/(1 + K u^2)</c> at
/// <c>u = (1 + p x)/y</c>, or <c>(1 + p x)^2/y</c>:
/// <code>
/// 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
/// 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
/// 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):
/// ((1 + k) e/d) int 1/(1 + (3 + 2k) a u^2), u = (1 + (1 + k) d x/c)/y
/// </code>
/// and over a quadratic, <c>(f + g x + h x^2)/((c + d x + e x^2) y)</c> where
/// <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>:
/// <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>.
/// Each condition is decided at sampled values of the symbols, the inner integral is an
/// arctangent or an inverse hyperbolic tangent by the sign of its constant, and the answer
/// is differentiated back at sampled points before it is returned.
/// https://github.com/asc-community/AngouriMath/issues/718
/// </para>
/// </remarks>
internal static Entity? SolveAPseudoEllipticQuotientOverTheRootOfACubicBinomial(Entity expr, Entity.Variable x)
{
var (numerator, denominator) = Functions.SingleQuotient.Of(expr);
Entity? radicand = null;
Entity below = Number.Integer.One;
foreach (var factor in Mulf.LinearChildren(denominator))
if (factor is Powf(var @base, Number.Rational half) && half.ERational.Equals(ERational.Create(1, 2)) && @base.ContainsNode(x))
{
if (radicand is not null)
return null;
radicand = @base;
}
else
below *= factor;
if (radicand is null || numerator.Nodes.Any(node => node is Powf(_, Number.Rational r) && r is not Number.Integer && node.ContainsNode(x))
|| !TreeAnalyzer.TryGetPolynomial(radicand, x, out var cubic) || cubic.Count != 2
|| !cubic.TryGetValue(EInteger.Zero, out var a) || !cubic.TryGetValue(EInteger.FromInt32(3), out var b)
|| !TreeAnalyzer.TryGetPolynomial(numerator, x, out var above) || !TreeAnalyzer.TryGetPolynomial(below, x, out var under))
return null;
Entity Coefficient(Dictionary<EInteger, Entity> read, int power)
=> read.TryGetValue(EInteger.FromInt32(power), out var value) ? value : Number.Integer.Zero;
int Degree(Dictionary<EInteger, Entity> read) => read.Count == 0 ? -1 : read.Keys.Max()!.ToInt32Unchecked();
if (Degree(above) > 2 || Degree(under) is not (1 or 2) || Degree(above) > Degree(under))
return null;
// A condition is decided as a value, at pinned symbols where nothing simplifies it
// to zero -- `6 a d^4 e - c f (b c^3 - 22 a d^3)` at `c = 1 - sqrt(3)` and
// `d = (b/a)^(1/3)` is one -- since the answer is checked by its derivative anyway.
static bool Zero(Entity condition) => Functions.PartialFractions.IsZeroAsAValue(condition);
var y = MathS.Sqrt(radicand);
var u = Variable.CreateUnique(expr, "u_pseudo");
// int du/(1 + K u^2), by the sign of K.
Entity OverOnePlus(Entity k)
{
var kLowest = LowestOverTheSymbols(k);
return BySign(kLowest,
MathS.Arctan(MathS.Sqrt(kLowest) * u) / MathS.Sqrt(kLowest),
MathS.Hyperbolic.Artanh(MathS.Sqrt(LowestOverTheSymbols(-kLowest)) * u) / MathS.Sqrt(LowestOverTheSymbols(-kLowest)));
}
Entity? answer = null;
if (Degree(under) == 1)
{
var (e, f) = (Coefficient(above, 0), Coefficient(above, 1));
var (c, d) = (Coefficient(under, 0), Coefficient(under, 1));
if (Zero(d * e - c * f) || Zero(c))
return null;
if (Zero(b * MathS.Pow(c, 3) - 4 * a * MathS.Pow(d, 3)) && Zero(2 * d * e + c * f))
answer = (2 * e / d * OverOnePlus(3 * a)).Substitute(u, (1 + 2 * d * x / c) / y);
else if (!Zero(e) && Zero(b * MathS.Pow(c, 3) + 8 * a * MathS.Pow(d, 3)) && Zero(2 * d * e + c * f))
answer = (-2 * e / (9 * d) * OverOnePlus(-a / 9)).Substitute(u, MathS.Pow(1 + f * x / e, 2) / y);
else if (!Zero(f)
&& 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))
&& Zero(6 * a * MathS.Pow(d, 4) * e - c * f * (b * MathS.Pow(c, 3) - 22 * a * MathS.Pow(d, 3))))
{
var k = LowestOverTheSymbols((d * e + 2 * c * f) / (c * f));
answer = ((1 + k) * e / d * OverOnePlus((3 + 2 * k) * a)).Substitute(u, (1 + (1 + k) * d * x / c) / y);
}
}
else
{
var (f, g, h) = (Coefficient(above, 0), Coefficient(above, 1), Coefficient(above, 2));
var (c, d, e) = (Coefficient(under, 0), Coefficient(under, 1), Coefficient(under, 2));
if (!Zero(g) && !Zero(h)
&& Zero(b * MathS.Pow(g, 3) - 8 * a * MathS.Pow(h, 3)) && Zero(MathS.Pow(g, 2) + 2 * f * h)
&& Zero(b * d * f + b * c * g - 4 * a * e * h) && !Zero(b * d * f - 2 * a * e * h))
answer = (-g / e * OverOnePlus(-(b * d * f - 2 * a * e * h) / (2 * e * h))).Substitute(u, (1 + 2 * h * x / g) / y);
}
if (answer is null)
return null;
answer = answer.InnerSimplified;
bool holds;
using (MathS.Settings.DowncastingEnabled.Set(false))
holds = Functions.PartialFractions.HoldsAtSampledPoints(answer.Differentiate(x), expr, x);
return holds ? answer : null;
}

/// <summary>
/// A root of a quadratic binomial beside another, <c>1/((A + B x^2)^(1/3) (C + D x^2))</c>
/// with <c>B C + 3 A D = 0</c> or <c>B C - 9 A D = 0</c>, and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,11 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
// the polynomial written in powers of the linear at its root: the part the power
// divides goes over the rest alone. Before the split, so that the whole polynomial
// is reduced once rather than each of its terms.
// A linear over a linear beside the root of a cubic binomial, or a quadratic over a
// quadratic, at the coefficients where the integral is elementary: Rubi's
// `(1 + x + sqrt(3))/((1 + x - sqrt(3)) sqrt(1 + x^3))`. Before the reduction over the
// linear, which writes it as `1` and `2 sqrt(3)` over the linear, neither elementary.
if ((answer = IndefiniteIntegralSolver.SolveAPseudoEllipticQuotientOverTheRootOfACubicBinomial(expr, x)) is { }) return answer;
if ((answer = IndefiniteIntegralSolver.SolveByReducingThePolynomialOverALinearFactor(expr, x, integrateByParts)) is { }) return answer;
if (expr is Entity.Sumf or Entity.Minusf
&& (answer = IndefiniteIntegralSolver.SolveBySplittingSum(expr, x, integrateByParts)) is { })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// 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
{
/// <summary>
/// A linear over a linear, or a quadratic over a quadratic, beside the reciprocal of the
/// square root of a cubic binomial, at the coefficients where the integral is elementary:
/// Rubi's 1.3.2, by its 1.3.3's rules.
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
/// </summary>
/// <remarks>
/// Checked by differentiating back with <c>a = 1.3</c>, <c>b = 0.7</c>, <c>c = 1.1</c> and
/// <c>d = 0.6</c>, at points where the radicand is positive and away from the pole.
/// </remarks>
[Trait("Area", "Calculus")]
public sealed class PseudoEllipticQuotientIntegralTest
{
[Theory]
// b c^3 = 4 a d^3 and 2 d e + c f = 0.
[InlineData("(c - 2*d*x)/((c + d*x)*sqrt(c^3 + 4*d^3*x^3))")]
[InlineData("(2^(2/3) - 2*x)/((2^(2/3) + x)*sqrt(1 + x^3))")]
// b c^3 = -8 a d^3 and 2 d e + c f = 0.
[InlineData("(a^(1/3) + b^(1/3)*x)/((2*a^(1/3) - b^(1/3)*x)*sqrt(a + b*x^3))")]
// b^2 c^6 - 20 a b c^3 d^3 - 8 a^2 d^6 = 0, at its second condition.
[InlineData("(1 + x + sqrt(3))/((1 + x - sqrt(3))*sqrt(1 + x^3))")]
[InlineData("(1 + (b/a)^(1/3)*x - sqrt(3))/((1 + (b/a)^(1/3)*x + sqrt(3))*sqrt(a + b*x^3))")]
// A quadratic over a quadratic.
[InlineData("(2 - 2*x - x^2)/((2 + d + d*x + x^2)*sqrt(1 + x^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("c", 1.1).Substitute("d", 0.6);
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
var original = Pinned(integrand.ToEntity());
foreach (var at in new[] { -0.8, -0.4, 0.3, 1.1, 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}");
}
}
}
}
25 changes: 19 additions & 6 deletions Sources/Tests/UnitTests/Calculus/SquareRootLogarithmAnsatzTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,12 @@ private static void DifferentiatesBack(string integrand, double[] points)
private static readonly double[] AboveMinusOne = { -0.7, -0.3, 0.2, 0.5, 0.8, 1.6, 2.4, 3.5 };

/// <summary>
/// Welz's, a logarithm at the pole <c>2</c> where <c>1 + x^3</c> is <c>9</c>:
/// <c>(2/3) ln((1 + x)^2/3 - sqrt(1 + x^3)) - ln(x - 2) - ln(1 + x)/3</c>; the same with
/// a rational part, <c>(2/3) sqrt(1 + x^3)</c>, brought over the denominator, and as a
/// sum.
/// Welz's with a rational part, <c>(2/3) sqrt(1 + x^3)</c>, brought over the denominator:
/// a logarithm at the pole <c>2</c> where <c>1 + x^3</c> is <c>9</c>,
/// <c>(2/3) ln((1 + x)^2/3 - sqrt(1 + x^3)) - ln(x - 2) - ln(1 + x)/3</c>.
/// </summary>
[Theory]
[InlineData("(1+x)/((x-2)*sqrt(1+x^3))")]
[InlineData("(x^3-2*x^2+x+1)/((x-2)*sqrt(1+x^3))")]
[InlineData("(1+x)/((x-2)*sqrt(1+x^3)) + x^2/sqrt(1+x^3)")]
public void ALogarithmAtAPole(string integrand)
{
DifferentiatesBack(integrand, AboveMinusOne);
Expand All @@ -82,6 +79,22 @@ public void ALogarithmAtAPole(string integrand)
Assert.Contains("ln(x - 2)", integral);
}

/// <summary>
/// Welz's own, a linear over a linear, and as a sum: one of the pseudo-elliptic quotients
/// a closed rule answers before the ansatz is asked, as
/// <c>-(2/3) artanh((1 + x)^2/(3 sqrt(1 + x^3)))</c>, one logarithm where the ansatz
/// writes three.
/// </summary>
[Theory]
[InlineData("(1+x)/((x-2)*sqrt(1+x^3))")]
[InlineData("(1+x)/((x-2)*sqrt(1+x^3)) + x^2/sqrt(1+x^3)")]
public void WelzsIsOneLogarithm(string integrand)
{
DifferentiatesBack(integrand, AboveMinusOne);
var integral = integrand.ToEntity().Integrate("x").Stringize();
Assert.Equal(1, integral.Split("ln(").Length - 1);
}

/// <summary>
/// Bronstein's, matched at infinity: the answer is
/// <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>
Expand Down
Loading