Skip to content

Commit 4dbe73a

Browse files
A whole power of a sum of two square roots below the bar is rationalised (#1751)
x/(sqrt(a + b x) + sqrt(c + b x))^3 was declined, while the first power of such a sum below the bar is multiplied above and below by its conjugate. A whole power of the pair below the bar is multiplied by the same power of the conjugate, expanded, over the same power of the difference of the radicands; an even power over a constant difference is left as it was, since its conjugate brings in the root of the product of the radicands. Rubi's 17 problems with a power of a sum of two square roots below the bar go from 9 to 16. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent 287c69a commit 4dbe73a

3 files changed

Lines changed: 77 additions & 2 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ answer on the far side of a root gets a real expression where it used to get a c
195195
| `1/(x*(-4+x^2)^4)` | 8,472 ms | 1,878 ms |
196196
| `1/((1+x)^3*(2+x)^3)` | 1,343 ms | 492 ms |
197197

198+
### A whole power of a sum of two square roots below the bar is rationalised
199+
200+
**Answers where there were none.** `x/(sqrt(a + b x) + sqrt(c + b x))^3` was declined, while the
201+
first power of such a sum below the bar is multiplied above and below by its conjugate, the product
202+
of the pair being the difference of the radicands. A whole power is multiplied by the same power of
203+
the conjugate now; an even power over a constant difference is left as it was, since its conjugate
204+
brings the root of the product of the radicands with it, and those were answered as written. Rubi's
205+
1.3.2 ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
206+
207+
| Input | Was (2.5.0) | Now |
208+
|---|---|---|
209+
| `"x/(sqrt(a + b*x) + sqrt(c + b*x))^3".ToEntity().Integrate("x")` | `integral(...)` | powers of the two roots over `(a - c)^3` |
210+
| `"1/(sqrt(a + b*x) + sqrt(a + c*x))^3".ToEntity().Integrate("x")` | `integral(...)` | the same, with logarithms and arctangents |
211+
| `"x^3/(sqrt(a + b*x) + sqrt(a + c*x))^2".ToEntity().Integrate("x")` | `integral(...)` | the same; 10 s on the unreleased master, a tenth of one now |
212+
198213
### Two square roots of linears with one slope are rationalised together
199214

200215
`sqrt(L1)` and `sqrt(L2)` with `L1 - L2` a constant are rational in their sum

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20255,19 +20255,33 @@ private static Entity OverTheFunctionLessARoot(Entity root, bool ofTheSine, Enti
2025520255
Entity rest = Number.Integer.One;
2025620256
foreach (var factor in Mulf.LinearChildren(denominator))
2025720257
{
20258-
if (conjugate is null && factor is Sumf or Minusf && Sumf.LinearChildren(factor).ToList() is { Count: 2 } terms
20258+
// Or a whole power of the pair, whose conjugate is the power of the pair's:
20259+
// `x/(sqrt(a + b x) + sqrt(c + b x))^3` was declined where its square was answered.
20260+
var (pair, power) = factor is Powf(var raised, Number.Integer { EInteger: var whole }) && whole.Sign > 0 && whole.CompareTo(EInteger.FromInt32(8)) <= 0
20261+
? (raised, whole.ToInt32Checked())
20262+
: (factor, 1);
20263+
if (conjugate is null && pair is Sumf or Minusf && Sumf.LinearChildren(pair).ToList() is { Count: 2 } terms
2025920264
&& terms.All(term => IsARootOfAPolynomial(term)))
2026020265
{
2026120266
// The conjugate flips the sign of the second term; the product is the
2026220267
// difference of the squares, each square a polynomial.
2026320268
var first = terms[0];
2026420269
var second = terms[1];
20265-
conjugate = first - second;
20270+
conjugate = power == 1 ? first - second : MathS.Pow(first - second, power).Expand();
2026620271
product = (SquareOf(first) - SquareOf(second)).InnerSimplified;
2026720272
// Not the same radicand twice: the difference is zero, the factor is zero
2026820273
// or a multiple of one root, and neither is this rule's.
2026920274
if (product.Evaled is Number.Complex { IsZero: true } || product.Simplify().Evaled is Number.Complex { IsZero: true })
2027020275
return null;
20276+
// An even power of the conjugate has the root of the product of the radicands
20277+
// in it, `2 sqrt(A B)` in the square, which over a constant difference leaves a
20278+
// root of a quadratic where the power as written was answered: the squares over
20279+
// `sqrt(a + b x) + sqrt(c + b x)` ran past the budget so, and were answered in a
20280+
// second as they stood.
20281+
if (power % 2 == 0 && !product.Simplify().ContainsNode(x))
20282+
return null;
20283+
if (power != 1)
20284+
product = MathS.Pow(product, power);
2027120285
continue;
2027220286
}
2027320287
rest = rest * factor;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 whole power of a sum of two square roots below the bar, multiplied above and below by the
16+
/// same power of the conjugate: <c>x/(sqrt(a + b x) + sqrt(c + b x))^3</c> is
17+
/// <c>x (sqrt(a + b x) - sqrt(c + b x))^3/(a - c)^3</c>. The first power was rationalised and
18+
/// the cubes were declined. Rubi's 1.3.2.
19+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class APowerOfASumOfRootsIntegralTest
23+
{
24+
[Theory]
25+
[InlineData("x/(sqrt(a + b*x) + sqrt(c + b*x))^3")]
26+
[InlineData("1/(sqrt(a + b*x) + sqrt(a + c*x))^3")]
27+
[InlineData("x^2/(sqrt(a + b*x) + sqrt(a + c*x))^3")]
28+
[InlineData("x^3/(sqrt(a + b*x) + sqrt(a + c*x))^2")]
29+
public void ThroughTheConjugate(string integrand)
30+
{
31+
var integral = integrand.ToEntity().Integrate("x");
32+
Assert.DoesNotContain("integral(", integral.Stringize());
33+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7).Substitute("c", 0.4);
34+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
35+
var original = Pinned(integrand.ToEntity());
36+
foreach (var at in new[] { 0.3, 0.8, 1.5, 2.4 })
37+
{
38+
var got = derivative.Substitute("x", at).EvalNumerical();
39+
var want = original.Substitute("x", at).EvalNumerical();
40+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
41+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart)),
42+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
43+
}
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)