Skip to content

Commit 9cec2d5

Browse files
Write an exponent given expanded as the power of a shifted linear it is (#2097)
e^(a^3 + 3 a^2 b x + 3 a b^2 x^2 + b^3 x^3) x^k was declined, where e^((a + b x)^3) x^k is answered by the rule for a polynomial beside a function of one shifted linear. An exponential of a polynomial of degree 3 to 12, given expanded, is now written as p (x + s)^n plus a constant, where p is the leading coefficient and s = p_(n - 1)/(n p), exactly when each lower coefficient is p C(n, j) s^(n - j). Then it is asked again as the same question, at the same depth, so that the rules scoped to the question asked or one below still read it. Part of #2075. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent ecefbcb commit 9cec2d5

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18148,6 +18148,66 @@ bool Read(Entity node, bool insideASum)
1814818148
return back.Nodes.Any(node => node == MathS.NaN) ? null : back;
1814918149
}
1815018150

18151+
/// <summary>
18152+
/// An exponential of a polynomial of degree 3 to 12 written expanded where it is a multiple of a power of one shifted
18153+
/// linear and a constant, written so: <c>a^3 + 3 a^2 b x + 3 a b^2 x^2 + b^3 x^3</c> is <c>b^3 (x + a/b)^3</c>. With
18154+
/// <c>p</c> the leading coefficient and <c>s = p_(n - 1)/(n p)</c>, the polynomial less <c>p (x + s)^n</c> is a constant
18155+
/// exactly where each lower coefficient is <c>p C(n, j) s^(n - j)</c>, and the integrand with the exponent written so
18156+
/// is the rule's below for a polynomial beside a function of a shifted linear. Rubi's 2.3.
18157+
/// https://github.com/asc-community/AngouriMath/issues/2075
18158+
/// </summary>
18159+
internal static Entity? SolveByWritingAnExponentAsAPowerOfAShiftedLinear(Entity expr, Entity.Variable x, bool integrateByParts)
18160+
{
18161+
if (!Integration.AnsweringTheQuestionAskedOrOneBelow)
18162+
return null;
18163+
foreach (var node in expr.Nodes)
18164+
{
18165+
// Written expanded: a power of a sum in x is already written as one, and its expansion would be read again.
18166+
if (node is not Powf(var @base, var exponent) || @base.ContainsNode(x)
18167+
|| !exponent.Nodes.Any(inner => inner is Sumf or Minusf && inner.ContainsNode(x))
18168+
|| exponent.Nodes.Any(inner => inner is Powf(Sumf or Minusf, _) && inner.ContainsNode(x))
18169+
|| !TreeAnalyzer.TryGetPolynomial(exponent, x, out var monomials) || monomials is null || monomials.Keys.Any(degree => degree.Sign < 0))
18170+
continue;
18171+
var n = monomials.Keys.Max()!;
18172+
if (n.CompareTo(EInteger.FromInt32(3)) < 0 || n.CompareTo(EInteger.FromInt32(12)) > 0
18173+
|| !monomials.TryGetValue(n.Subtract(EInteger.One), out var next) || VanishesIdentically(next))
18174+
continue;
18175+
var degree = n.ToInt32Checked();
18176+
// Both small, and simplified so that the answer reads them: 3 a b^2/(3 b^3) is a/b. The condition that comes
18177+
// with it, that the leading coefficient is not 0, is the reading's own: the polynomial is of degree n.
18178+
var leading = monomials[n].InnerSimplified;
18179+
var shift = (next / (degree * leading)).Simplify();
18180+
while (shift is Providedf(var unconditional, _))
18181+
shift = unconditional;
18182+
var isAShiftedPower = true;
18183+
for (var j = 1; j <= degree - 2 && isAShiftedPower; j++)
18184+
{
18185+
var coefficient = monomials.TryGetValue(EInteger.FromInt32(j), out var written) ? written : Number.Integer.Zero;
18186+
isAShiftedPower = VanishesIdentically(coefficient - leading * Number.Integer.Create(Choose(degree, j)) * MathS.Pow(shift, degree - j));
18187+
}
18188+
if (!isAShiftedPower)
18189+
continue;
18190+
var constant = monomials.TryGetValue(EInteger.Zero, out var free) ? free : Number.Integer.Zero;
18191+
var left = (constant - leading * MathS.Pow(shift, degree)).Simplify();
18192+
while (left is Providedf(var unconditional, _))
18193+
left = unconditional;
18194+
var asAPower = VanishesIdentically(left) ? leading * MathS.Pow(x + shift, degree) : leading * MathS.Pow(x + shift, degree) + left;
18195+
// The same question, respelled: asked at this depth, so that the rules scoped to the question asked or one
18196+
// below still read it.
18197+
var rewritten = expr.Replace(inner => inner == node ? MathS.Pow(@base, asAPower) : inner);
18198+
return Integration.ComputeAsTheSameQuestion(rewritten, x, integrateByParts);
18199+
}
18200+
return null;
18201+
18202+
static EInteger Choose(int whole, int chosen)
18203+
{
18204+
var result = EInteger.One;
18205+
for (var i = 1; i <= chosen; i++)
18206+
result = result.Multiply(EInteger.FromInt32(whole - chosen + i)).Divide(EInteger.FromInt32(i));
18207+
return result;
18208+
}
18209+
}
18210+
1815118211
/// <summary>
1815218212
/// A polynomial beside a function of one shifted linear <c>a + b x</c> that parts cannot reach, written in
1815318213
/// <c>u = a + b x</c>: a power that is not whole of something holding a logarithm of it, <c>x (a + b ln(c (d + e x)))^p</c>,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ internal static bool ASumOverRootsWouldAnswer
936936
// x leaves a Gaussian of the shifted linear beside a polynomial, which nothing reads.
937937
if ((answer = IndefiniteIntegralSolver.SolveAPolynomialBesideErrorFunctionsOfAShiftedLinear(expr, x, integrateByParts)) is { }) return answer;
938938
// And beside a symbolic power of a logarithm of one, or an exponential of a power of one, the same way.
939+
if ((answer = IndefiniteIntegralSolver.SolveByWritingAnExponentAsAPowerOfAShiftedLinear(expr, x, integrateByParts)) is { }) return answer;
939940
if ((answer = IndefiniteIntegralSolver.SolveAPolynomialBesideATranscendentalPowerOfAShiftedLinear(expr, x, integrateByParts)) is { }) return answer;
940941
if ((answer = IndefiniteIntegralSolver.SolveAPowerOfXBesideATranscendentalPowerOfABinomial(expr, x, integrateByParts)) is { }) return answer;
941942
// A half-odd power of a ± a sin(y) beside powers of other linears in the sine, by the half

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ public void APositiveRateIsTakenOutOfThePower()
193193
[InlineData("Chi(a + b*x)^2")]
194194
public void AnExponentWrittenOtherwise(string integrand) => DifferentiatesBack(integrand);
195195

196+
/// <summary>
197+
/// An exponent written expanded that is a power of one shifted linear and a constant, written so first:
198+
/// <c>a^3 + 3 a^2 b x + 3 a b^2 x^2 + b^3 x^3</c> is <c>(a + b x)^3</c>. Rubi's 2.3.
199+
/// </summary>
200+
[Theory]
201+
[InlineData("e^(a^3 + 3*a^2*b*x + 3*a*b^2*x^2 + b^3*x^3)*x")]
202+
[InlineData("f^(c + d^3 + 3*d^2*x + 3*d*x^2 + x^3)")]
203+
[InlineData("x^2*e^(b*(1 + 4*x + 6*x^2 + 4*x^3 + x^4))")]
204+
public void AnExponentThatIsAPowerOfAShiftedLinearWrittenExpanded(string integrand) => DifferentiatesBack(integrand);
205+
196206
/// <summary>
197207
/// Not where the integral is elementary, an exponential integral or an error function: those keep the form
198208
/// they had.

0 commit comments

Comments
 (0)