Skip to content

Commit d752c58

Browse files
Rafael-SOWNetclaude
andcommitted
Integrate a power beside an exponential of a power as an incomplete gamma function
int x^m F^(a + b x^n) dx is -F^a x^(m + 1) z^(-s) gamma(s, z)/n with z = -b ln(F) x^n and s = (m + 1)/n, and int (c + d x)^m F^(a + b x) dx the same with n = 1 under t = c + d x: x^(m + 1) z^(-s) is constant between the cuts, and gamma(s, z) differentiates to -z^(s - 1) e^(-z) z'. Only where s is neither whole nor half a whole number, whose integrals are elementary, exponential integrals or error functions and keep those answers, or where it is past 30, where parts would take s steps: x^100 e^(-a x) is -a^(-101) gamma(101, a x). Where the constant factor is one number on both half-lines it is written so, and the answer has a value at 0: e^(x^3) is gamma(1/3, -x^3)/3. Two costs this exposed, each fixed here. By parts integrated (a + b ln(c x^n))^p into a gamma function of a logarithm and handed its remainder on, which nothing integrates and the searches sampled thousands of times: three by-parts paths now decline a gamma function of an argument that is not linear. And a definite integral of an answer undefined at a bound, x^2 e^(x^4) from 0, took a limit through l'Hopital's rule for over a minute; it is left as written there. gamma's own limit is taken by continuity where its value is finite. The order is read through Simplify where its symbols cancel: (-1 + n + 1)/n is 1, and (p x)^(n - 1) e^(x^n) keeps its elementary answer. Rubi's suite on the harness that reads GAMMA, against master e62a56d: 48,502 -> 48,634 of 49,052, 0 wrong, 0 rows lost, timeouts 5 -> 2; the gains are 68 in 2.3, 24 in 3.1.2, 12 in 8.6 and the logarithm files. Two rows' allocation grew in the run and is identical alone on both builds. Five tests that pinned a decline answer now, each checked by value. Part of #2075; answers #180's item 22. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent e62a56d commit d752c58

10 files changed

Lines changed: 439 additions & 15 deletions

‎BREAKING-CHANGES.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ as `a - b = 0`, as a statement's own solve reads it: `"x + 1 = 3".Solve("x")` wa
145145
of `x`, by parts, in gamma functions of `u`.
146146
And of a whole `a <= 0` over a power of another linear, by parts, where what is left is an exponential over
147147
linears.
148+
- **Integrals in it.** `x^m F^(a + b x^n)` and `(c + d x)^m F^(a + b x)` are `-F^a x^(m + 1) z^(-s) gamma(s, z)/n`, with
149+
`z = -b ln(F) x^n` and `s = (m + 1)/n`, where `s` is neither whole nor half a whole number, or is past 30, as
150+
`x^31 e^(-x)` is, whose sum of 32 terms is `-gamma(32, x)` now. A definite integral of such an answer that is
151+
undefined at a bound is left as written.
148152
([#2075](https://github.com/asc-community/AngouriMath/issues/2075))
149153

150154
| Input | Was (2.6.0) | Now |
@@ -156,6 +160,10 @@ as `a - b = 0`, as a statement's own solve reads it: `"x + 1 = 3".Solve("x")` wa
156160
| `"x^2*gamma(0, a*x)".ToEntity().Integrate("x")` | a `FunctionArgumentCountException` | `x ^ 3 / 3 * gamma(0, a * x) - 1 / (3 * a ^ 3) * 2 * e ^ (-a * x) * (1 + a * x + (a * x) ^ 2 / 2) + C` |
157161
| `"x^m*gamma(n, b*x)".ToEntity().Integrate("x")` | a `FunctionArgumentCountException` | `(x ^ (m + 1) * gamma(n, b * x) - x ^ m * (b * x) ^ (-m) * gamma(n + m + 1, b * x) / b) / (m + 1) + C` |
158162
| `"gamma(0, a + b*x)/(c + d*x)^2".ToEntity().Integrate("x")` | a `FunctionArgumentCountException` | `-gamma(0, a + b x)/(d (c + d x))` and two exponential integrals, of `a + b x` and of `b (c + d x)/d` |
163+
| `"x^(1/3)*e^(-x)".ToEntity().Integrate("x")` | `integral(x ^ (1/3) * e ^ (-x), x)` | `-gamma(4/3, x) + C` |
164+
| `"(c + d*x)^m*e^(a + b*x)".ToEntity().Integrate("x")` | `integral((c + d * x) ^ m * e ^ (a + b * x), x)` | `e ^ (a - b * c / d) * (c + d * x) ^ m * (-b * (c + d * x) / d) ^ (-m) * gamma(m + 1, -b * (c + d * x) / d) / b + C` |
165+
| `"x^31*e^(-x)".ToEntity().Integrate("x")` | a sum of 32 terms, 6,172 characters | `-gamma(32, x) + C` |
166+
| `"integral(e^(x^3), x, 0, 1)".ToEntity().Simplify()` | `integral(e ^ x ^ 3, x, 0, 1)` | `(gamma(1/3, -1) - (-2/3)!) / 3`, which is `1.3419044179774…` |
159167

160168
### Numerical equality is to half the evaluation's digits
161169

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,11 @@ private static bool OnlyInsideTranscendentalFunctions(Entity expr, Entity.Variab
260260
// And one with a polynomial in x beside something in its antiderivative: what parts
261261
// leaves then has the power it took away, and asking it does not descend --
262262
// `x erfc(a + b x)^2`, whose cofactor's antiderivative has `x erfc(a + b x)^2` in it.
263+
// Nor one whose antiderivative is an incomplete gamma function of an argument that is not linear, which
264+
// the remainder would hold: see TryIntegrateByPartsOnce. `(g + h x)^2 (a + b ln(c (d (e + f x)^p)^q))^n`
265+
// went from a decline in three seconds to one in two minutes.
263266
if (Integration.ComputeAsAQuestionOfItsOwn(rest, x, integrateByParts: true) is not { } antiderivative
264-
|| HasAPolynomialFactorIn(antiderivative, x))
267+
|| HasAPolynomialFactorIn(antiderivative, x) || IntroducesAnIncompleteGammaFunctionOfANonlinear(antiderivative, rest, x))
265268
{
266269
remainder.Add(term);
267270
continue;
@@ -5166,6 +5169,9 @@ static Entity WithTheConstantMatchedTo(Entity antiderivative, Entity derivativeO
51665169
?? Integration.ComputeIndefiniteIntegral(toIntegrate, x, false);
51675170
if (integral is null) return null;
51685171
var differential = polynomialToDifferentiate.Differentiate(x);
5172+
// And the next round integrates what this one returned, which nothing does where that is an incomplete
5173+
// gamma function of an argument that is not linear: see TryIntegrateByPartsOnce.
5174+
if (!TreeAnalyzer.IsZero(differential) && IntroducesAnIncompleteGammaFunctionOfANonlinear(integral, toIntegrate, x)) return null;
51695175
var result = IntegrateByPartsPolynomial(differential, integral, x, currentRecursion + 1);
51705176
return (result is null) ? null : polynomialToDifferentiate * integral - result;
51715177
}
@@ -5194,6 +5200,12 @@ static Entity WithTheConstantMatchedTo(Entity antiderivative, Entity derivativeO
51945200
byThePolynomialsParts = integralOfU is not null;
51955201
}
51965202
if (integralOfU is null) return null;
5203+
// Not where the integral of u is an incomplete gamma function of an argument that is not linear, which u
5204+
// did not hold: the remainder holds it then, and nothing here integrates it. (a + b ln(c x^n))^p beside
5205+
// d + e ln(f x^r) integrates the power to gamma(p + 1, -(a + b ln(c x^n))/(b n)), and the search on its
5206+
// remainder sampled it three thousand times before declining, thirty-five seconds where it had been one.
5207+
// https://github.com/asc-community/AngouriMath/issues/2075
5208+
if (IntroducesAnIncompleteGammaFunctionOfANonlinear(integralOfU, u, x)) return null;
51975209

51985210
// Differentiate v
51995211
var derivativeOfV = v.Differentiate(x).InnerSimplified;
@@ -50047,6 +50059,23 @@ Entity Term(Entity? sum, Entity coefficient, int power)
5004750059
/// </summary>
5004850060
[System.ThreadStatic] private static bool askingTheTermsOfARemainder;
5004950061

50062+
/// <summary>
50063+
/// Whether <paramref name="integral"/> holds an incomplete gamma function of an argument not linear in
50064+
/// <paramref name="x"/> where <paramref name="integrand"/> holds none.
50065+
/// </summary>
50066+
private static bool IntroducesAnIncompleteGammaFunctionOfANonlinear(Entity integral, Entity integrand, Variable x)
50067+
{
50068+
foreach (var node in integral.Nodes)
50069+
if (node is IncompleteGammaf { LowerLimit: var argument } && !TreeAnalyzer.TryGetPolyLinear(argument, x, out _, out _))
50070+
{
50071+
foreach (var written in integrand.Nodes)
50072+
if (written is IncompleteGammaf)
50073+
return false;
50074+
return true;
50075+
}
50076+
return false;
50077+
}
50078+
5005050079
private static bool IsASpecialFunction(Entity node)
5005150080
=> node is Entity.Erff or Entity.Erfcf or Entity.Erfif or Entity.Eif or Entity.Lif
5005250081
or Entity.Sif or Entity.Cif or Entity.Shif or Entity.Chif;

0 commit comments

Comments
 (0)