Skip to content

Commit 96ac3bc

Browse files
A product of powers is read as its own raised product's derivative without a sum beside it (#1694)
* A product of powers is read as its own raised product's derivative without a sum beside it SolveAsTheDerivativeOfAProductOfPowers reads an integrand as a constant times the derivative of its powers with some of them raised by one. Three changes: - The derivative's sum is built as a sum of products, each raised base's derivative times the other raised bases, so that it reads as a polynomial and the constant comes off one monomial. Built with f'/f in it, it read as nothing, and the constant fell to simplifying a quotient of the two sums: past a minute for Rubi's 1.3.2 x (a + b x + c x^2)^m (d + e x + f x^2 + g x^3)^n (...), 0.3 s now. - Where a power is not a whole one, a product with no sum beside it is tried as well: 1/(x^2 sqrt(a x + b x^4)) is (-2/(3 a) sqrt(a x + b x^4)/x^2)'. - And there, x is raised from nothing where it is not among the powers: (a + b x^n + c x^(2 n))^p (a + b (1 + n + n p) x^n + ...) is (x (a + b x^n + c x^(2 n))^(p + 1))'. Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura * A breaking-changes entry for a product of powers read without a sum beside it Measured on the 2.5.0 tag and on this branch. 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 a34dbc3 commit 96ac3bc

3 files changed

Lines changed: 90 additions & 11 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,21 @@ and in no release -- and is `sgn(u) u/(u^2 - 1)`
20022002
| `"1/sqrt(1+csch(x)^2)".Integrate("x")` | left unevaluated | `-sgn(tanh(x)) ln(tanh(x)^2 - 1)/2`, in exponentials |
20032003
| `"x^4/sech(2*ln(c*x))^(1/2)".Integrate("x")` | left unevaluated | `sgn(x) (1 + c^4 x^4)^(3/2)/(6 sqrt(2) c^5)` up to the form, `provided c^4 > 0` |
20042004

2005+
### A product of powers is read as its own raised product's derivative without a sum beside it
2006+
2007+
**Improvement, not silent.** An integrand that is a constant times the derivative of its powers
2008+
with some of them raised by one is answered by that product. The rule wanted a sum beside the powers
2009+
and a power of `x` among them, and read the sum's quotient through `f'/f`, which with two symbolic
2010+
powers of polynomials ran past a minute. Where a power is not a whole one it now reads a product
2011+
with no sum, and `x` raised from no power at all, and the sum as a polynomial
2012+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
2013+
2014+
| Input | Was (2.5.0) | Now |
2015+
|---|---|---|
2016+
| `"1/(x^2*sqrt(a*x+b*x^4))".Integrate("x")` | left unevaluated | `-2 sqrt(a x + b x^4)/(3 a x^2)` |
2017+
| `"(a+b*x^n+c*x^(2*n))^p*(a+b*(1+n+n*p)*x^n+c*(1+2*n*(1+p))*x^(2*n))".Integrate("x")`, Rubi's 1.2.3.5 | no answer in 30 s | `x (a + b x^n + c x^(2 n))^(p + 1)` |
2018+
| Rubi 1.3.2's `x (a + b x + c x^2)^m (d + e x + f x^2 + g x^3)^n` times the sum its derivative leaves | no answer in 90 s | `x^2 (a + b x + c x^2)^(m + 1) (d + e x + f x^2 + g x^3)^(n + 1)` |
2019+
20052020
### A root of a rational function of `coth(x)` is integrated by the hyperbolic half-angle
20062021

20072022
`coth(x)^3/sqrt(a + b coth(x)^2)` was a search past the budget. The rational-in-`tanh` route

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

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9055,6 +9055,11 @@ static bool IsRationalInBoth(Entity e, Entity.Variable x, Entity.Variable L)
90559055
/// ansatz wants whole powers of its monomials, and splitting the sum loses it, since
90569056
/// <c>F^(c(a + bx)) x^m ln(dx)^n</c> on its own is not elementary.
90579057
/// </para>
9058+
/// <para>
9059+
/// Where a power is not a whole one, the sum may be missing -- the product of powers is
9060+
/// then a constant times its own raised product's derivative -- and x may be raised from
9061+
/// nothing, a power of it the integrand does not have.
9062+
/// </para>
90589063
/// https://github.com/asc-community/AngouriMath/issues/718
90599064
/// </remarks>
90609065
internal static Entity? SolveAsTheDerivativeOfAProductOfPowers(Entity expr, Entity.Variable x)
@@ -9095,34 +9100,68 @@ static bool IsRationalInBoth(Entity e, Entity.Variable x, Entity.Variable L)
90959100
}
90969101
raisable.Add((factor, underneath ? Number.Integer.MinusOne : Number.Integer.One));
90979102
}
9098-
if (bracket is null || raisable.Count == 0 || raisable.Count > 4)
9103+
if (raisable.Count == 0 || raisable.Count > 4)
9104+
return null;
9105+
// Where a power is not a whole one -- a root, or a symbolic exponent -- two more
9106+
// candidates, each a shape nothing else reads. With no sum beside two or more powers,
9107+
// the product is the derivative's up to a constant: `1/(x^2 sqrt(a x + b x^4))` is
9108+
// `(-2/(3 a) sqrt(a x + b x^4)/x^2)'`, the root raised and the power of x kept; a
9109+
// power on its own is the power rule's, or the binomial's. And x raised from nothing
9110+
// where it is not among the powers, in front of them: Rubi's
9111+
// `(a + b x^n + c x^(2 n))^p (a + b (1 + n + n p) x^n + c (1 + 2 n (1 + p)) x^(2 n))`
9112+
// is `(x (a + b x^n + c x^(2 n))^(p + 1))'`. Whole powers only are a rational
9113+
// function's, or a polynomial's beside a function, and the rules for those answer them.
9114+
if (raisable.Any(pair => pair.Exponent is not Number.Integer))
9115+
{
9116+
if (raisable.Count >= 2)
9117+
bracket ??= Number.Integer.One;
9118+
if (!raisable.Any(pair => pair.Base == x))
9119+
raisable.Insert(0, (x, Number.Integer.Zero));
9120+
}
9121+
if (bracket is null)
90999122
return null;
91009123
for (var subset = 1; subset < 1 << raisable.Count; subset++)
91019124
{
91029125
Entity candidate = kept;
91039126
Entity productOfRaisedBases = Number.Integer.One;
9104-
Entity logarithmicDerivative = Number.Integer.Zero;
9127+
for (var i = 0; i < raisable.Count; i++)
9128+
if ((subset & (1 << i)) != 0)
9129+
productOfRaisedBases *= raisable[i].Base;
9130+
// The bracket the candidate's derivative has, against the integrand's: the
9131+
// candidate is the integrand's powers with the raised bases in besides, so
9132+
// G' is (integrand without its bracket) (product of raised bases) (sum of the
9133+
// logarithmic derivatives), and the constant is the quotient of the brackets.
9134+
// Written as a sum of products, each raised base's logarithmic derivative times
9135+
// the other raised bases, so that it reads as a polynomial wherever the bases do:
9136+
// with `f'/f` left in, it read as nothing, and the constant fell to simplifying a
9137+
// quotient of the two brackets -- past a minute for Rubi's
9138+
// `x (a + b x + c x^2)^m (d + e x + f x^2 + g x^3)^n (...)`, 0.3 s read off one
9139+
// monomial.
9140+
Entity bracketOfTheDerivative = Number.Integer.Zero;
91059141
foreach (var derivative in logarithmicDerivativesKept)
9106-
logarithmicDerivative += derivative;
9142+
bracketOfTheDerivative += derivative * productOfRaisedBases;
91079143
for (var i = 0; i < raisable.Count; i++)
91089144
{
91099145
var (@base, exponent) = raisable[i];
91109146
var raised = (subset & (1 << i)) != 0;
91119147
var newExponent = raised ? (exponent + 1).InnerSimplified : exponent;
9112-
if (raised)
9113-
productOfRaisedBases *= @base;
91149148
if (newExponent.Evaled is Number.Complex { IsZero: true })
91159149
continue; // a power raised to nothing: not a factor of the candidate
91169150
candidate *= newExponent == Number.Integer.One ? @base : MathS.Pow(@base, newExponent);
9117-
logarithmicDerivative += newExponent * @base.Differentiate(x) / @base;
9151+
if (!raised)
9152+
{
9153+
bracketOfTheDerivative += newExponent * @base.Differentiate(x) * productOfRaisedBases / @base;
9154+
continue;
9155+
}
9156+
Entity theOtherRaisedBases = Number.Integer.One;
9157+
for (var j = 0; j < raisable.Count; j++)
9158+
if (j != i && (subset & (1 << j)) != 0)
9159+
theOtherRaisedBases *= raisable[j].Base;
9160+
bracketOfTheDerivative += newExponent * @base.Differentiate(x) * theOtherRaisedBases;
91189161
}
91199162
if (candidate == kept)
91209163
continue;
9121-
// The bracket the candidate's derivative has, against the integrand's: the
9122-
// candidate is the integrand's powers with the raised bases in besides, so
9123-
// G' is (integrand without its bracket) (product of raised bases) (sum of the
9124-
// logarithmic derivatives), and the constant is the quotient of the brackets.
9125-
var bracketOfTheDerivative = Functions.PartialFractions.Bare((productOfRaisedBases * logarithmicDerivative).InnerSimplified);
9164+
bracketOfTheDerivative = Functions.PartialFractions.Bare(bracketOfTheDerivative.InnerSimplified);
91269165
if (!AreProportionalAtSampledPoints(bracket, bracketOfTheDerivative, x))
91279166
continue;
91289167
// The constant is the quotient of one monomial's coefficients, the two

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,30 @@ public void TheConstantIsRead()
104104
[Fact]
105105
public void WhatIsNotADerivativeIsDeclined()
106106
=> Assert.Contains("integral(", "x^m*ln(x)^n*(1 + ln(x))".ToEntity().Integrate("x").Stringize());
107+
108+
/// <summary>
109+
/// Rubi's 1.3.2, two symbolic powers of a quadratic and a cubic beside a power of x:
110+
/// the sum is read as a polynomial and the constant off one monomial. It was a timeout.
111+
/// </summary>
112+
[Fact]
113+
public void TwoSymbolicPowersOfPolynomials()
114+
=> DifferentiatesBackWithParametersPinned(
115+
"x*(a+b*x+c*x^2)^m*(d+h*x+f*x^2+g*x^3)^n*(2*a*d+(3*b*d+3*a*h+b*d*m+a*h*n)*x+(4*c*d+4*b*h+4*a*f+2*c*d*m+b*h*m+b*h*n+2*a*f*n)*x^2+(5*c*h+5*b*f+5*a*g+2*c*h*m+b*f*m+c*h*n+2*b*f*n+3*a*g*n)*x^3+(6*c*f+6*b*g+2*c*f*m+b*g*m+2*c*f*n+3*b*g*n)*x^4+c*g*(7+2*m+3*n)*x^5)",
116+
Points);
117+
118+
/// <summary>
119+
/// Where a power is not a whole one, a product with no sum beside it, Rubi's 1.1.4.2, and
120+
/// x raised from a power the integrand does not have, Rubi's 1.2.3.5.
121+
/// </summary>
122+
[Theory]
123+
[InlineData("1/(x^2*sqrt(a*x+b*x^4))")]
124+
[InlineData("(a+b*x^n+c*x^(2*n))^p*(a+b*(1+n+n*p)*x^n+c*(1+2*n*(1+p))*x^(2*n))")]
125+
public void WithoutASumOrWithXRaisedFromNothing(string integrand)
126+
=> DifferentiatesBackWithParametersPinned(integrand, Points);
127+
128+
/// <summary>A product of powers that is no such derivative is still declined: <c>sqrt(1 + x^3)</c> is elliptic.</summary>
129+
[Fact]
130+
public void APowerThatIsNoDerivativeIsDeclined()
131+
=> Assert.Contains("integral(", "sqrt(1 + x^3)".ToEntity().Integrate("x").Stringize());
107132
}
108133
}

0 commit comments

Comments
 (0)