Skip to content

Commit 0dd8692

Browse files
Any power of a square written out is the power of its root, in any power of x (#1698)
* Any power of a square written out is the power of its root, in any power of x A square written out, A + B w + C w^2 with B^2 = 4 A C, was read as the modulus of its root only under half an odd power and in a whole power of x. A symbolic power, (a^2 + 2 a b x + b^2 x^2)^p, a power such as 3/4, and the square in x^n or x^(1/3) were declined. The power of the square is now the power of its root L = w + B/(2 C) times F = (A + B w + C w^2)^p / L^(2p), which is constant wherever L is not zero and comes out of the integral: F above the bar, 1/F below it, and nothing where the square is not a factor of the integrand. After the rule for half an odd power, which keeps its answers, and at the top only. On Rubi's 1.2.3.2, 179 fair problems whose trinomial is a square, 156 are answered where master answers 103, none wrongly. Rubi's 1.2.1.2, 1.2.2.2 and 1.2.3.2. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura * The square below the bar is tested where the root of a square does not answer it A half-odd power of a square in a fractional power of x is the root of a square's, by its modulus, since #1695. The two rows below the bar take a symbolic power and 3/4 instead, which only this rule answers. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent f2f1ce1 commit 0dd8692

4 files changed

Lines changed: 249 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,24 @@ here that writes one does: left inside, a rule below differentiated it, and
22922292
| `"sqrt(a^2+2*a*b*x+b^2*x^2)*sqrt(c+pe*x+d*x^2)".Integrate("x")` | left unevaluated | the antiderivative |
22932293
| `"(a^2+2*a*b*x+b^2*x^2)^(5/2)".Integrate("x")` | the antiderivative, through the substitution search | `sgn(a + b x) (a + b x)^6 |b|^5/(6 b)` up to the form |
22942294

2295+
### Any power of a square written out is the power of its root, in any power of `x`
2296+
2297+
**Answers where there were none.** A square written out, `A + B w + C w^2` with `B^2 = 4 A C`,
2298+
was read as the modulus of its root only under half an odd power, and only in a whole power of
2299+
`x`. A symbolic power, `(a^2 + 2 a b x + b^2 x^2)^p`, or a power such as `3/4`, was declined, and
2300+
so was the square in `x^n` or in `x^(1/3)`. Now the power of the square is the power of its root
2301+
`L = w + B/(2 C)` times `(A + B w + C w^2)^p / L^(2p)`. That factor is constant wherever `L` is
2302+
not zero, and it goes in front of the integral. These are Rubi's 1.2.1.2, 1.2.2.2 and 1.2.3.2
2303+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
2304+
2305+
| Input | Was (2.5.0) | Now |
2306+
|---|---|---|
2307+
| `"x^2*(a^2 + 2*a*b*x^3 + b^2*x^6)^p".Integrate("x")` | left unevaluated | `(a^2 + 2 a b x^3 + b^2 x^6)^p (x^3 + a/b)/(3 (2 p + 1))`, as that factor times a power of `x^3 + a/b` |
2308+
| `"(a + b*x)*(d + e*x)^3*(a^2 + 2*a*b*x + b^2*x^2)^p".Integrate("x")` | left unevaluated | the factor times powers of `x + a/b` |
2309+
| `"(a^2 + 2*a*b*x^2 + b^2*x^4)^(3/4)".Integrate("x")` | left unevaluated | the factor times the antiderivative of `(x^2 + a/b)^(3/2)` |
2310+
| `"x*sqrt(a^2 + 2*a*b*x^n + b^2*x^(2*n))".Integrate("x")` | left unevaluated | `sqrt(a^2 + 2 a b x^n + b^2 x^(2n))/(x^n + a/b)` times `a x^2/(2 b) + x^(n + 2)/(n + 2)` |
2311+
| `"x*(a^2 + 2*a*b*x^(1/3) + b^2*x^(2/3))^p".Integrate("x")` | left unevaluated | the factor times powers of `x^(1/3) + a/b` |
2312+
22952313
### The root of a quadratic that is a square is the modulus of a linear, and was read as any quadratic
22962314

22972315
**Wrong answers, silent.** The table's entry for `k/sqrt(Q)` and `sqrt(Q)` reads a quadratic by the

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

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14477,6 +14477,141 @@ bool MayBeARootOfASquare(Entity node, Entity.Variable x)
1447714477
return assumed == Entity.Boolean.True ? answer : answer.Provided(assumed);
1447814478
}
1447914479

14480+
/// <summary>
14481+
/// A power of a square written out, <c>(A + B w + C w^2)^p</c> with <c>B^2 = 4 A C</c> and
14482+
/// <c>w = x^k</c>, as the power of its root, <c>L = w + B/(2 C)</c>: the integral is
14483+
/// <c>F</c> times the integral with <c>L^(2p)</c> in its place, where
14484+
/// <c>F = (A + B w + C w^2)^p / L^(2p)</c>.
14485+
/// </summary>
14486+
/// <remarks>
14487+
/// <para>
14488+
/// The square is <c>C L^2</c>, and <c>F</c> is constant on every interval where <c>L</c> is
14489+
/// not zero: its derivative is <c>2 p w' L^(2p-1) (C L^2 Q^(p-1) - Q^p) / L^(4p)</c>, and
14490+
/// <c>Q^(p-1) Q = Q^p</c> wherever <c>Q</c> is not zero. So <c>F</c> goes in front of the
14491+
/// integral, whatever <c>p</c> is: a symbol, <c>3/4</c>, or half an odd number with a
14492+
/// leading coefficient of unknown sign. For a whole <c>p</c> it is <c>C^p</c>. The square
14493+
/// is a factor of the integrand or nothing is read: below the bar <c>1/F</c> comes out,
14494+
/// and out of a sum nothing does.
14495+
/// </para>
14496+
/// <para>
14497+
/// After <see cref="SolveByTakingARootOfAPerfectSquare"/>, which answers half an odd power
14498+
/// of a square in a whole power of x with the sign written out, and before which nothing
14499+
/// read <c>k</c> as anything but a whole number. This reads <c>k</c> as any exponent, a
14500+
/// fraction or a symbol: Rubi's 1.2.3.2 <c>x^2 (a^2 + 2 a b x^3 + b^2 x^6)^p</c>,
14501+
/// <c>x sqrt(a^2 + 2 a b x^n + b^2 x^(2n))</c> and <c>(a^2 + 2 a b x^2 + b^2 x^4)^(3/4)</c>
14502+
/// were declined. At the top only, where the answer is the caller's, as for the sign the
14503+
/// rule above writes.
14504+
/// https://github.com/asc-community/AngouriMath/issues/718
14505+
/// </para>
14506+
/// </remarks>
14507+
internal static Entity? SolveByWritingAPowerOfASquareAsAPowerOfItsRoot(Entity expr, Entity.Variable x, bool integrateByParts)
14508+
{
14509+
if (!Integration.AnsweringTheQuestionAsked)
14510+
return null;
14511+
// The square as a factor of the integrand, above the bar or below it, and nowhere else:
14512+
// the factor comes out of a product and not out of a sum, and below the bar it is its
14513+
// reciprocal that comes out.
14514+
var (above, below) = Functions.SingleQuotient.Of(expr);
14515+
(Entity Square, Entity Exponent, Entity Root, Entity Leading, bool Below)? found = null;
14516+
foreach (var (side, isBelow) in new[] { (above, false), (below, true) })
14517+
foreach (var factor in Mulf.LinearChildren(side))
14518+
{
14519+
if (factor is not Powf(var radicand, var power) || !radicand.ContainsNode(x) || power.ContainsNode(x)
14520+
|| radicand is not (Sumf or Minusf) || radicand.Complexity > 60
14521+
|| TrinomialInAPowerOfX(radicand, x) is not var (a, b, c, w, k))
14522+
continue;
14523+
var whole = power is Number.Integer;
14524+
var halfOdd = power is Number.Rational half && half.ERational.Denominator.Equals(EInteger.FromInt32(2));
14525+
var kIsWhole = k is Number.Integer { EInteger.Sign: > 0 };
14526+
// What the rule above and the rational rules answer: half an odd power, or a
14527+
// whole one, of a square in a whole power of x.
14528+
if (kIsWhole && (whole || halfOdd))
14529+
continue;
14530+
if (!VanishesIdentically(b * b - 4 * a * c))
14531+
continue;
14532+
// Two squares would want two factors; one is what Rubi writes.
14533+
if (found is { })
14534+
return null;
14535+
var shift = Functions.PartialFractions.InLowestTermsOverTheSymbols(b / (2 * c));
14536+
found = (radicand, power, shift == Number.Integer.Zero ? w : w + shift, c, isBelow);
14537+
}
14538+
if (found is not var (square, exponent, root, leading, squareIsBelow)
14539+
|| above.Nodes.Concat(below.Nodes).Count(node => node == square) != 1)
14540+
return null;
14541+
var twice = (2 * exponent).InnerSimplified;
14542+
// The root's power above the bar either way, with a negative exponent for the square
14543+
// below it: `x (x + h)^(-2p)` is read below the top where `x/(x + h)^(2p)` was not.
14544+
Entity Without(Entity side)
14545+
{
14546+
Entity product = Number.Integer.One;
14547+
foreach (var factor in Mulf.LinearChildren(side))
14548+
if (!(factor is Powf(var radicand, var power) && radicand == square && power == exponent))
14549+
product = product == Number.Integer.One ? factor : product * factor;
14550+
return product;
14551+
}
14552+
var ofTheRoot = MathS.Pow(root, squareIsBelow ? (-twice).InnerSimplified : twice);
14553+
var written = squareIsBelow
14554+
? ofTheRoot * above / Without(below)
14555+
: ofTheRoot * Without(above) / below;
14556+
if (Integration.ComputeIndefiniteIntegral(written, x, integrateByParts) is not { } integral)
14557+
return null;
14558+
// F: the leading coefficient's power where p is whole, and the quotient otherwise.
14559+
var factorOfTheSquare = exponent is Number.Integer
14560+
? MathS.Pow(leading, exponent)
14561+
: MathS.Pow(square, exponent) / MathS.Pow(root, twice);
14562+
return (squareIsBelow ? integral / factorOfTheSquare : factorOfTheSquare * integral);
14563+
14564+
// A + B x^k + C x^(2k), each term a coefficient times a power of x, with the three
14565+
// exponents 0, k and 2k.
14566+
static (Entity A, Entity B, Entity C, Entity W, Entity K)? TrinomialInAPowerOfX(Entity sum, Entity.Variable x)
14567+
{
14568+
var terms = new List<(Entity Coefficient, Entity Exponent)>();
14569+
foreach (var term in Sumf.LinearChildren(sum))
14570+
{
14571+
if (PowerOfX(term, x) is not { } read)
14572+
return null;
14573+
terms.Add(read);
14574+
}
14575+
if (terms.Count != 3)
14576+
return null;
14577+
var constant = terms.Where(term => term.Exponent == Number.Integer.Zero).ToList();
14578+
if (constant.Count != 1)
14579+
return null;
14580+
var others = terms.Where(term => term.Exponent != Number.Integer.Zero).ToList();
14581+
foreach (var (first, second) in new[] { (others[0], others[1]), (others[1], others[0]) })
14582+
if (VanishesIdentically(second.Exponent - 2 * first.Exponent) && !VanishesIdentically(first.Exponent))
14583+
{
14584+
var k = first.Exponent.InnerSimplified;
14585+
return (constant[0].Coefficient, first.Coefficient, second.Coefficient, MathS.Pow(x, k), k);
14586+
}
14587+
return null;
14588+
}
14589+
14590+
// A term as a coefficient free of x and an exponent of x, through products and quotients.
14591+
static (Entity Coefficient, Entity Exponent)? PowerOfX(Entity term, Entity.Variable x)
14592+
{
14593+
if (!term.ContainsNode(x))
14594+
return (term, Number.Integer.Zero);
14595+
switch (term)
14596+
{
14597+
case Entity.Variable v when v == x:
14598+
return (Number.Integer.One, Number.Integer.One);
14599+
case Powf(var @base, var power) when @base == x && !power.ContainsNode(x):
14600+
return (Number.Integer.One, power);
14601+
case Mulf(var left, var right):
14602+
if (PowerOfX(left, x) is not var (lc, le) || PowerOfX(right, x) is not var (rc, re))
14603+
return null;
14604+
return (lc * rc, (le + re).InnerSimplified);
14605+
case Divf(var above, var below):
14606+
if (PowerOfX(above, x) is not var (ac, ae) || PowerOfX(below, x) is not var (bc, be))
14607+
return null;
14608+
return (ac / bc, (ae - be).InnerSimplified);
14609+
default:
14610+
return null;
14611+
}
14612+
}
14613+
}
14614+
1448014615
/// <summary>
1448114616
/// <paramref name="sum"/> as a polynomial in <c>w = x^k</c> for a rational <c>k</c> that is
1448214617
/// not whole, each of its terms a constant times a power of <paramref name="x"/> that is a

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,9 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
662662
if ((answer = IndefiniteIntegralSolver.SolveAReciprocalOfAnInverseTrigonometricFunction(expr, x, integrateByParts)) is { }) return answer;
663663
// A fractional power of a perfect square is the power of the modulus, sgn(P) P^(2r).
664664
if ((answer = IndefiniteIntegralSolver.SolveByTakingARootOfAPerfectSquare(expr, x, integrateByParts)) is { }) return answer;
665+
// And any power of a square in any power of x, as the power of its root times a factor
666+
// constant where the root is not zero: `x^2 (a^2 + 2 a b x^3 + b^2 x^6)^p`.
667+
if ((answer = IndefiniteIntegralSolver.SolveByWritingAPowerOfASquareAsAPowerOfItsRoot(expr, x, integrateByParts)) is { }) return answer;
665668
// A power of a multiple of a quadratic's derivative beside a power of the quadratic is
666669
// a binomial in the derivative: `(b d + 2 c d x)^m (a + b x + c x^2)^p`.
667670
if ((answer = IndefiniteIntegralSolver.SolveByTheDerivativeOfAQuadraticAsTheVariable(expr, x, integrateByParts)) is { }) return answer;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 System.Linq;
10+
using AngouriMath.Extensions;
11+
using Xunit;
12+
13+
namespace AngouriMath.Tests.Calculus
14+
{
15+
/// <summary>
16+
/// A power of a square written out, <c>(A + B w + C w^2)^p</c> with <c>B^2 = 4 A C</c> and
17+
/// <c>w</c> a power of x, integrated as the power of its root <c>L = w + B/(2 C)</c> times the
18+
/// factor <c>(A + B w + C w^2)^p / L^(2p)</c>, which is constant wherever <c>L</c> is not zero.
19+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
20+
/// </summary>
21+
/// <remarks>
22+
/// Differentiated back with <c>a</c> negative, so that <c>L</c> changes sign among the points
23+
/// and the factor is checked on both sides of its zero, where it is not the same constant.
24+
/// </remarks>
25+
[Trait("Area", "Calculus")]
26+
public sealed class PowerOfAPerfectSquareIntegralTest
27+
{
28+
private static readonly double[] Points = { 0.3, 0.9, 1.7, 2.6 };
29+
30+
private static void DifferentiatesBack(string integrand, params (string, double)[] pins)
31+
{
32+
var integral = integrand.ToEntity().Integrate("x");
33+
Assert.DoesNotContain("integral(", integral.Stringize());
34+
35+
// The integration constant is C_1 where the integrand has a symbol named C.
36+
Entity original = integrand.ToEntity();
37+
var derivative = (original.Vars.Any(v => v.Name == "C") ? integral : integral.Substitute("C", 0)).Differentiate("x");
38+
foreach (var (name, value) in pins)
39+
{
40+
derivative = derivative.Substitute(name, value);
41+
original = original.Substitute(name, value);
42+
}
43+
var compared = 0;
44+
foreach (var at in Points)
45+
{
46+
var got = derivative.Substitute("x", at).EvalNumerical();
47+
var want = original.Substitute("x", at).EvalNumerical();
48+
if (got.IsNaN || want.IsNaN)
49+
continue;
50+
compared++;
51+
var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart);
52+
var scale = Math.Max(1.0, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart));
53+
Assert.True(difference / scale < 1e-9,
54+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
55+
}
56+
Assert.True(compared >= 3, $"only {compared} points could be compared for {integrand}");
57+
}
58+
59+
/// <summary>
60+
/// A symbolic power, and a power that is neither whole nor half an odd number: Rubi's
61+
/// 1.2.1.2, 1.2.2.2 and 1.2.3.2, which were declined.
62+
/// </summary>
63+
[Theory]
64+
[InlineData("(a^2 + 2*a*b*x + b^2*x^2)^p")]
65+
[InlineData("(a + b*x)*(d + e*x)^3*(a^2 + 2*a*b*x + b^2*x^2)^p")]
66+
[InlineData("x^2*(a^2 + 2*a*b*x^3 + b^2*x^6)^p")]
67+
[InlineData("(a^2 + 2*a*b*x^2 + b^2*x^4)^(3/4)")]
68+
public void APowerThatIsNotHalfAnOddNumber(string integrand)
69+
=> DifferentiatesBack(integrand, ("a", -2.5), ("b", 1), ("d", 0.7), ("e", 1.3), ("p", 0.35));
70+
71+
/// <summary>
72+
/// A square in a power of x that is not a whole number: a fraction, or a symbol, Rubi's
73+
/// <c>x sqrt(a^2 + 2 a b x^n + b^2 x^(2n))</c>.
74+
/// </summary>
75+
[Theory]
76+
[InlineData("x*(a^2 + 2*a*b*x^(1/3) + b^2*x^(2/3))^p")]
77+
[InlineData("x*sqrt(a^2 + 2*a*b*x^n + b^2*x^(2*n))")]
78+
public void ASquareInAPowerThatIsNotWhole(string integrand)
79+
=> DifferentiatesBack(integrand, ("a", -2.5), ("b", 1), ("p", -1.7), ("n", 1.5));
80+
81+
/// <summary>
82+
/// The square below the bar, where it is <c>1/F</c> that comes out of the integral.
83+
/// </summary>
84+
[Theory]
85+
[InlineData("1/(a^2 + 2*a*b*x^(1/3) + b^2*x^(2/3))^p")]
86+
[InlineData("1/(a^2 + b^2/x^(2/3) + 2*a*b/x^(1/3))^(3/4)")]
87+
[InlineData("x^(2*n - 1)/(a^2 + 2*a*b*x^n + b^2*x^(2*n))^(3/2)")]
88+
[InlineData("1/(x*sqrt(a^2 + 2*a*b*x^n + b^2*x^(2*n)))")]
89+
[InlineData("x/(a^2 + 2*a*b*x + b^2*x^2)^p")]
90+
public void TheSquareBelowTheBar(string integrand)
91+
=> DifferentiatesBack(integrand, ("a", -2.5), ("b", 1), ("p", 0.35), ("n", 1.5));
92+
}
93+
}

0 commit comments

Comments
 (0)