Skip to content

Commit 54c1d10

Browse files
A sum that is the derivative of a product of powers is read as one (#1803)
m x^(m - 1) (a + b x^n)^p + b n p x^(m + n - 1) (a + b x^n)^(p - 1) is the derivative of x^m (a + b x^n)^p written out as a sum, and was declined: the rule that reads the derivative of a product of powers reads the product beside one bracket, and split into its terms neither term is elementary. A sum of products of powers of the same bases is written as their common product, each base to the least of its exponents, times the bracket of what is left, and asked so; the differences of the exponents are simplified, since -1 + m + n - (-1 + m) is left as written by the inner simplification. Rubi's 1.1.3.2. 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 b3e736e commit 54c1d10

3 files changed

Lines changed: 109 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,20 @@ is written so, after the substitutions, and the factor goes in front of the answ
384384
| `"(1/(1 - x^2))^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | `sgn(1 - x^2) x/sqrt(1 - x^2)` |
385385
| `"(c/(a + b*x^2))^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | `(c/(a + b x^2))^(3/2) (a + b x^2)^(3/2) x/(a sqrt(a + b x^2))` |
386386

387+
### A sum that is the derivative of a product of powers is read as one
388+
389+
**Answers where there were none.** `m x^(m - 1) (a + b x^n)^p + b n p x^(m + n - 1) (a + b x^n)^(p - 1)` is
390+
the derivative of `x^m (a + b x^n)^p`, written out as a sum, and was declined: the rule that reads a
391+
derivative of a product of powers reads the product beside one bracket, and split into its terms neither is
392+
elementary. A sum of products of powers of the same bases is written as their common product, each base
393+
to the least of its exponents, times the bracket of what is left, and asked so. Rubi's 1.1.3.2
394+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
395+
396+
| Input | Was (2.5.0) | Now |
397+
|---|---|---|
398+
| `"m*x^(m-1)*(a+b*x^n)^p + b*n*p*x^(m+n-1)*(a+b*x^n)^(p-1)".ToEntity().Integrate("x")` | `integral(...)` | `x^m (a + b x^n)^p` |
399+
| `"-1/2*b*n*x^(-1+m+n)/(a+b*x^n)^(3/2)+m*x^(-1+m)/sqrt(a+b*x^n)".ToEntity().Integrate("x")` | `integral(...)` | `x^m/sqrt(a + b x^n)` |
400+
387401
### A whole power of a quotient with a symbol in it is integrated as the quotient of the powers
388402

389403
**Answers where there were none, and a slowdown since 2.5.0 undone.** `(c/(a + c x^2))^2` was

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

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12831,6 +12831,83 @@ static bool IsRationalInBoth(Entity e, Entity.Variable x, Entity.Variable L)
1283112831
/// <summary>The largest power of the logarithm the tower ansatz reads or tries.</summary>
1283212832
private const int MaximumTowerDegree = 4;
1283312833

12834+
/// <summary>
12835+
/// <paramref name="sum"/>, every term of which is a constant times powers of the same
12836+
/// bases with <paramref name="x"/> in them, as the product of those bases to the least of
12837+
/// each one's exponents times the sum of what is left. Null where a base is not in every
12838+
/// term, where no exponent of one is the least, or where the least are all whole, which
12839+
/// the rational rules read.
12840+
/// </summary>
12841+
private static Entity? WithTheCommonPowersOut(Entity sum, Entity.Variable x)
12842+
{
12843+
var terms = new List<(Entity Constant, Dictionary<Entity, Entity> Powers)>();
12844+
foreach (var term in Sumf.LinearChildren(sum))
12845+
{
12846+
Entity constant = Number.Integer.One;
12847+
var powers = new Dictionary<Entity, Entity>();
12848+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(term))
12849+
{
12850+
if (!factor.ContainsNode(x))
12851+
{
12852+
constant = underneath ? constant / factor : constant * factor;
12853+
continue;
12854+
}
12855+
var (@base, exponent) = factor is Powf(var b, var e) && !e.ContainsNode(x) ? (b, e) : (factor, (Entity)Number.Integer.One);
12856+
if (@base is Number || !@base.ContainsNode(x))
12857+
return null;
12858+
if (underneath)
12859+
exponent = -exponent;
12860+
powers[@base] = powers.TryGetValue(@base, out var before) ? (before + exponent).InnerSimplified : exponent.InnerSimplified;
12861+
}
12862+
terms.Add((constant, powers));
12863+
}
12864+
if (terms.Count < 2)
12865+
return null;
12866+
var bases = terms[0].Powers.Keys.ToList();
12867+
if (bases.Count == 0 || terms.Any(term => term.Powers.Count != bases.Count || bases.Any(@base => !term.Powers.ContainsKey(@base))))
12868+
return null;
12869+
// For each base the least of its exponents, against which every other is more by a
12870+
// whole number or by a sum of symbols with no sign in front: `x^(m - 1)` beside
12871+
// `x^(m + n - 1)` leaves `x^n` in the bracket, as the derivative of `a + b x^n` does.
12872+
// Simplified, not inner-simplified: `-1 + m + n - (-1 + m)` is left as written by the
12873+
// latter, and is `n`.
12874+
static Entity Difference(Entity exponent, Entity from)
12875+
=> Functions.PartialFractions.Bare((exponent - from).Simplify());
12876+
static bool More(Entity difference)
12877+
=> difference is Number.Integer { EInteger.Sign: >= 0 }
12878+
|| difference is not Number && difference is not Mulf(Number.Real { IsNegative: true }, _) && difference.Vars.Any();
12879+
var least = new Dictionary<Entity, Entity>();
12880+
foreach (var @base in bases)
12881+
{
12882+
var exponents = terms.Select(term => term.Powers[@base]).ToList();
12883+
Entity? lowest = null;
12884+
foreach (var candidate in exponents)
12885+
if (exponents.All(other => Difference(other, candidate) is var difference && (difference == Number.Integer.Zero || More(difference))))
12886+
{
12887+
lowest = candidate;
12888+
break;
12889+
}
12890+
if (lowest is null)
12891+
return null;
12892+
least[@base] = lowest;
12893+
}
12894+
if (least.Values.All(exponent => exponent is Number.Integer))
12895+
return null;
12896+
Entity bracket = Number.Integer.Zero;
12897+
foreach (var (constant, powers) in terms)
12898+
{
12899+
Entity rest = constant;
12900+
foreach (var @base in bases)
12901+
if (Difference(powers[@base], least[@base]) is var raised && raised != Number.Integer.Zero)
12902+
rest = rest * (raised == Number.Integer.One ? @base : MathS.Pow(@base, raised));
12903+
bracket = bracket == Number.Integer.Zero ? rest : bracket + rest;
12904+
}
12905+
Entity common = Number.Integer.One;
12906+
foreach (var @base in bases)
12907+
common = common * MathS.Pow(@base, least[@base]);
12908+
return common * bracket;
12909+
}
12910+
1283412911
/// <summary>
1283512912
/// A product of powers times a sum that is the derivative of the product with some of
1283612913
/// the powers raised by one: <c>e^x x^2 ln(x)^2 (3 + (3 + x) ln(x))</c> is
@@ -12863,6 +12940,13 @@ static bool IsRationalInBoth(Entity e, Entity.Variable x, Entity.Variable L)
1286312940
{
1286412941
if (!Integration.AnsweringTheQuestionAskedOrOneBelow)
1286512942
return null;
12943+
// A sum of products of powers of the same bases is their common product times a
12944+
// bracket, which is the shape read below: `m x^(m - 1) (a + b x^n)^p + b n p x^(m + n - 1)
12945+
// (a + b x^n)^(p - 1)` is `x^(m - 1) (a + b x^n)^(p - 1) (m (a + b x^n) + b n p x^n)`,
12946+
// the derivative of `x^m (a + b x^n)^p`. As a sum it was split, and neither term is
12947+
// elementary.
12948+
if (expr is Sumf or Minusf)
12949+
return WithTheCommonPowersOut(expr, x) is { } factored ? SolveAsTheDerivativeOfAProductOfPowers(factored, x) : null;
1286612950
Entity constant = Number.Integer.One;
1286712951
Entity? bracket = null;
1286812952
var raisable = new List<(Entity Base, Entity Exponent)>();

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ public void TwoSymbolicPowersOfPolynomials()
125125
public void WithoutASumOrWithXRaisedFromNothing(string integrand)
126126
=> DifferentiatesBackWithParametersPinned(integrand, Points);
127127

128+
/// <summary>
129+
/// The derivative written out as a sum, the common powers in each term: they come out in
130+
/// front and the rest is the bracket, where split into its terms neither is elementary.
131+
/// Rubi's 1.1.3.2.
132+
/// </summary>
133+
[Theory]
134+
[InlineData("-1/2*b*n*x^(-1+m+n)/(a+b*x^n)^(3/2)+m*x^(-1+m)/sqrt(a+b*x^n)")]
135+
[InlineData("m*x^(m-1)*(a+b*x^n)^p + b*n*p*x^(m+n-1)*(a+b*x^n)^(p-1)")]
136+
public void ASumWithTheCommonPowersInEachTerm(string integrand)
137+
=> DifferentiatesBackWithParametersPinned(integrand, Points);
138+
128139
/// <summary>A product of powers that is no such derivative is still declined: <c>sqrt(1 + x^3)</c> is elliptic.</summary>
129140
[Fact]
130141
public void APowerThatIsNoDerivativeIsDeclined()

0 commit comments

Comments
 (0)