Skip to content

Commit aae0312

Browse files
A root of a square in a fractional power of x is the modulus as well (#1695)
A sum of powers of x that are whole multiples of one fractional k is read as a polynomial in w = x^k, which is exact for every x, and the root of a square in it is answered for a positive x, where w is real, as the modulus of a linear in w. Rubi's 1.2.3.2 (a^2 + b^2/x^(2/5) + 2 a b/x^(1/5))^(5/2) is a square in x^(-1/5), and was declined: 0.5 s. A root of an even order plus a positive number, sqrt(x) + 1, is not given a sign. 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 96ac3bc commit aae0312

3 files changed

Lines changed: 117 additions & 4 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,21 @@ coefficient of either sign ([#1670](https://github.com/asc-community/AngouriMath
22932293
| `"1/sqrt(-a^2-2*a*b*x-b^2*x^2)".Integrate("x")` | a piecewise whose arcsine divides by `sqrt(0)`, `NaN` for every real `b` but zero | a logarithm over `sqrt(-b^2)`, `provided b^2 > 0` |
22942294
| `"1/(x*sqrt(a^2+2*a*b*x+b^2*x^2))".Integrate("x")`, the same with `-a^2 - 2 a b x - b^2 x^2`, or with `d + e x` for `x` | left unevaluated | the antiderivative, `provided b^2 > 0` |
22952295

2296+
### A root of a square in a fractional power of `x` is the modulus of a linear in that power
2297+
2298+
**Answers where there were none.** A sum of powers of `x` that are whole multiples of one
2299+
fractional `k`, such as `a^2 + 2 a b x^(1/3) + b^2 x^(2/3)`, is read as a polynomial in `w = x^k`,
2300+
and the root of a square in it as the modulus of a linear in `w`, as the root of a square
2301+
quadratic is. `w` is real for a positive `x`, and the answer says so, `provided x > 0`. Rubi's
2302+
1.2.3.2 ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
2303+
2304+
| Input | Was (2.5.0) | Now |
2305+
|---|---|---|
2306+
| `"sqrt(a^2+2*a*b*x^(1/3)+b^2*x^(2/3))".Integrate("x")` | left unevaluated | `sgn(x^(1/3) + a/b) sqrt(b^2) (3/4 x^(4/3) + a/b x) provided x > 0 and b^2 > 0` |
2307+
| `"1/sqrt(a^2+b^2*x+2*a*b*sqrt(x))".Integrate("x")` | left unevaluated | `sgn(sqrt(x) + a/b) (2 sqrt(x) - 2 a/b ln(a/b + sqrt(x)))/sqrt(b^2)`, under the same condition |
2308+
| `"(a^2+b^2/x^(2/5)+2*a*b/x^(1/5))^(5/2)".Integrate("x")`, Rubi 1.2.3.2 #659 | left unevaluated | an antiderivative in `x^(-1/5)`, under the same condition |
2309+
| `"(1+2*x^(1/2)+x)^(3/2)".Integrate("x")` | left unevaluated | `2 (x/2 + x^(3/2) + 3 x^2/4 + x^(5/2)/5) provided x > 0` |
2310+
22962311
### A power of the variable times a sine or cosine of a logarithm, and a power of a monomial
22972312

22982313
`x^2 sin(a + b ln(c x^n))` and `(c x^n)^b` were both left as written. Two rules, each exact:

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

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14046,8 +14046,19 @@ bool MayBeARootOfASquare(Entity node, Entity.Variable x)
1404614046
return node;
1404714047
var (radicand, exponent) = (Powf)node;
1404814048
var r = (Number.Rational)exponent;
14049+
// A quadratic in a fractional power of x, `a^2 + 2 a b x^(-1/5) + b^2 x^(-2/5)`, is
14050+
// read in `w = x^k`, exact for every x since each power of x is a whole power of w;
14051+
// and real only for a positive x, which the answer then says.
14052+
Entity wBase = x;
1404914053
if (!TreeAnalyzer.TryGetPolynomial(radicand, x, out var monomials) || monomials.Count == 0)
14050-
return node;
14054+
{
14055+
if (!atTheTop || InAFractionalPowerOfX(radicand, x) is not var (inW, k))
14056+
return node;
14057+
monomials = inW;
14058+
wBase = MathS.Pow(x, k);
14059+
var positive = new Greaterf(x, Number.Integer.Zero);
14060+
assumed = assumed == Entity.Boolean.True ? positive : assumed & positive;
14061+
}
1405114062
// A quadratic in w = x^k: a w^2 + b w + c, the square being of w + h. Beyond
1405214063
// k = 1 only with the constant term written, since `a x^(2k)` alone is a power
1405314064
// of a monomial, which another rule distributes.
@@ -14066,7 +14077,7 @@ bool MayBeARootOfASquare(Entity node, Entity.Variable x)
1406614077
var a = monomials[degree];
1406714078
var b = monomials.TryGetValue(half, out var b1) ? b1 : Number.Integer.Zero;
1406814079
var c = monomials.TryGetValue(EInteger.Zero, out var c0) ? c0 : Number.Integer.Zero;
14069-
Entity w = half.Equals(EInteger.One) ? x : MathS.Pow(x, Number.Integer.Create(half));
14080+
Entity w = half.Equals(EInteger.One) ? wBase : MathS.Pow(wBase, Number.Integer.Create(half));
1407014081
// A leading coefficient of known sign, since `sqrt(a (x + h)^2)` is
1407114082
// `sqrt(a) |x + h|` for either: a number, or one positive or negative for a real
1407214083
// parameter -- `b^2` is, and `a^2 + 2 a b x + b^2 x^2` is the square Rubi writes,
@@ -14098,8 +14109,10 @@ bool MayBeARootOfASquare(Entity node, Entity.Variable x)
1409814109
// between the linear factor's zeros, and a rule below that differentiates the
1409914110
// integrand cannot evaluate `derivative(sgn(...))` -- which is the exception
1410014111
// `sqrt(a^2 + 2abx + b^2x^2) sqrt(c + ex + dx^2)` threw with it left in place.
14101-
// None where it is plainly one: an even power of x plus a positive number.
14102-
if (!whole && !(half.IsEven && h.Evaled is Number.Real { IsPositive: true }))
14112+
// None where it is plainly one: an even power of x plus a positive number, or a
14113+
// root of x of an even order plus one, `sqrt(x) + 1`.
14114+
if (!whole && !((half.IsEven || wBase is Powf(_, Number.Rational { ERational.Denominator.IsEven: true }))
14115+
&& h.Evaled is Number.Real { IsPositive: true }))
1410314116
signs = signs * MathS.Signum(linear);
1410414117
changed = true;
1410514118
return leading == Number.Integer.One ? power : MathS.Pow(leading, r) * power;
@@ -14111,6 +14124,60 @@ bool MayBeARootOfASquare(Entity node, Entity.Variable x)
1411114124
return assumed == Entity.Boolean.True ? answer : answer.Provided(assumed);
1411214125
}
1411314126

14127+
/// <summary>
14128+
/// <paramref name="sum"/> as a polynomial in <c>w = x^k</c> for a rational <c>k</c> that is
14129+
/// not whole, each of its terms a constant times a power of <paramref name="x"/> that is a
14130+
/// whole, non-negative multiple of <c>k</c>; <see langword="null"/> otherwise.
14131+
/// </summary>
14132+
private static (Dictionary<EInteger, Entity> Monomials, Number.Rational K)? InAFractionalPowerOfX(Entity sum, Entity.Variable x)
14133+
{
14134+
var terms = new List<(ERational Power, Entity Coefficient)>();
14135+
foreach (var term in Sumf.LinearChildren(sum))
14136+
{
14137+
var power = ERational.Zero;
14138+
Entity coefficient = Number.Integer.One;
14139+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(term))
14140+
{
14141+
if (!factor.ContainsNode(x))
14142+
{
14143+
coefficient = underneath ? coefficient / factor : coefficient * factor;
14144+
continue;
14145+
}
14146+
var exponent = factor == x ? ERational.One
14147+
: factor is Powf(var @base, Number.Rational q) && @base == x ? q.ERational
14148+
: (ERational?)null;
14149+
if (exponent is null)
14150+
return null;
14151+
power = underneath ? power.Subtract(exponent) : power.Add(exponent);
14152+
}
14153+
terms.Add((power, coefficient));
14154+
}
14155+
var powers = terms.Select(term => term.Power).Where(q => !q.IsZero).Distinct().ToList();
14156+
if (powers.Count == 0 || powers.All(q => q.IsInteger()) || powers.Any(q => q.Sign > 0) && powers.Any(q => q.Sign < 0))
14157+
return null;
14158+
// k the greatest common divisor of the powers, with their sign.
14159+
var numerators = EInteger.Zero;
14160+
var denominators = EInteger.One;
14161+
foreach (var q in powers)
14162+
{
14163+
numerators = numerators.Gcd(q.Numerator.Abs());
14164+
denominators = denominators.Multiply(q.Denominator).Divide(denominators.Gcd(q.Denominator));
14165+
}
14166+
var k = ERational.Create(numerators, denominators);
14167+
if (powers[0].Sign < 0)
14168+
k = k.Negate();
14169+
var monomials = new Dictionary<EInteger, Entity>();
14170+
foreach (var (power, coefficient) in terms)
14171+
{
14172+
var degree = power.Divide(k);
14173+
if (!degree.IsInteger() || degree.Sign < 0)
14174+
return null;
14175+
var key = degree.ToEInteger();
14176+
monomials[key] = monomials.TryGetValue(key, out var so) ? so + coefficient : coefficient;
14177+
}
14178+
return (monomials, Number.Rational.Create(k));
14179+
}
14180+
1411414181
/// <summary>
1411514182
/// A power of a linear that is a constant multiple of a quadratic's derivative, beside a
1411614183
/// power of the quadratic, under the linear as the variable: with <c>t = λ (b + 2 c x)</c>

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,37 @@ Entity Pin(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7).Substitute("
228228
Assert.True(compared >= 6, $"only {compared} points were comparable for {integrand}");
229229
}
230230

231+
/// <summary>
232+
/// A square in a fractional power of x, Rubi's 1.2.3.2 <c>(a^2 + b^2/x^(2/5) + 2 a b/x^(1/5))^(5/2)</c>:
233+
/// read in <c>w = x^k</c>, every power of x a whole power of w, and real for a positive x,
234+
/// which the answer says. Differentiated back where it says, with <c>a b</c> of either
235+
/// sign, so that <c>w + a/b</c> changes sign among the points for the first two.
236+
/// </summary>
237+
[Theory]
238+
[InlineData("(a^2 + b^2/x^(2/5) + 2*a*b/x^(1/5))^(5/2)")]
239+
[InlineData("sqrt(a^2 + 2*a*b*x^(1/3) + b^2*x^(2/3))")]
240+
[InlineData("(1 + 2*x^(1/2) + x)^(3/2)")]
241+
[InlineData("sqrt(4 + 4*x^(1/4) + x^(1/2))/x")]
242+
public void ASquareInAFractionalPowerOfTheVariable(string integrand)
243+
{
244+
var integral = integrand.ToEntity().Integrate("x").Substitute("C", 0);
245+
Assert.DoesNotContain("integral(", integral.Stringize());
246+
foreach (var b in new[] { 0.7, -0.7 })
247+
{
248+
Entity Pin(Entity e) => e.Substitute("a", 1.3).Substitute("b", b);
249+
var derivative = Pin(integral).Differentiate("x");
250+
var original = Pin(integrand.ToEntity());
251+
foreach (var at in new[] { 0.01, 0.31, 0.83, 2.41, 9.0 })
252+
{
253+
var got = derivative.Substitute("x", at).EvalNumerical();
254+
var want = original.Substitute("x", at).EvalNumerical();
255+
var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart);
256+
Assert.True(difference / Math.Max(1.0, Math.Abs((double)want.RealPart)) < 1e-9,
257+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, b = {b}, where the integrand is {want}: {integral}");
258+
}
259+
}
260+
}
261+
231262
[Fact]
232263
public void TheSignIsTheSignOfTheLinearFactor()
233264
{

0 commit comments

Comments
 (0)