Skip to content

Commit 2247602

Browse files
An exponential of a polynomial beside the polynomial's derivative is integrated under u = P (#1525)
G^P k P' f(P), with P a polynomial of degree two or more and P' a factor of its own up to a constant, is k G^u f(u) under u = P. The substitution search reads this u and does not reach it: it writes an exponential of a sum as a product of exponentials for its own search, and e^(a + b x + c x^2) is then e^a e^(b x) e^(c x^2), with no P in it to replace; it took 24 s to decline. Rubi's 2.3, e^(a + b x + c x^2) (b + 2 c x) (a + b x + c x^2)^(n/2). Part of #1501. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 621a319 commit 2247602

4 files changed

Lines changed: 85 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,18 @@ since they are these exponentials
17101710
| `"(p + q*x)^2*f^(a + b*x + c*x^2)".Integrate("x")` | `integral((p + q * x) ^ 2 * f ^ (a + b * x + c * x ^ 2), x)` | the antiderivative |
17111711
| `"x^2*sinh(a + b*x + c*x^2)".Integrate("x")` | `integral(x ^ 2 * (e ^ (a + b * x + c * x ^ 2) - e ^ (-(a + b * x + c * x ^ 2))) / 2, x)` | the antiderivative |
17121712

1713+
### An exponential of a polynomial beside the polynomial's derivative is integrated
1714+
1715+
`e^(a + b x + c x^2) (b + 2 c x) sqrt(a + b x + c x^2)` was left unintegrated. `G^P k P' f(P)`, with
1716+
`P` a polynomial of degree two or more and `P'` a factor of its own up to a constant, is now
1717+
integrated under `u = P`, as `k G^u f(u)`
1718+
([#1501](https://github.com/asc-community/AngouriMath/issues/1501)).
1719+
1720+
| Input | Was (2.5.0) | Now |
1721+
|---|---|---|
1722+
| `"e^(a + b*x + c*x^2)*(b + 2*c*x)*(a + b*x + c*x^2)^(1/2)".Integrate("x")` | `integral(e ^ (a + b * x + c * x ^ 2) * (b + 2 * c * x) * sqrt(a + b * x + c * x ^ 2), x)` | the antiderivative, with `erfi` |
1723+
| `"e^(a + b*x + c*x^2)*(b + 2*c*x)/(a + b*x + c*x^2)^(3/2)".Integrate("x")` | `integral(e ^ (a + b * x + c * x ^ 2) * (b + 2 * c * x) / (a + b * x + c * x ^ 2) ^ (3/2), x)` | the antiderivative, with `erfi` |
1724+
17131725
### An exponential of a quadratic in `1/x` or `1/(c + d x)` is integrated
17141726

17151727
`e^(-1/x^2)` was left unintegrated. `L^m F^(A/L^2 + B/L + C)`, with `L = c + d x` and a whole `m`,

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17235,6 +17235,63 @@ private static bool IsARationalFunctionOfExponentials(Entity expr, Entity.Variab
1723517235
}
1723617236
}
1723717237

17238+
/// <summary>
17239+
/// An exponential of a polynomial beside the polynomial's derivative, with the rest a
17240+
/// function of the polynomial: <c>G^P k P' f(P)</c> is <c>k G^u f(u)</c> under <c>u = P</c>.
17241+
/// Rubi's 2.3, <c>e^(a + b x + c x^2) (b + 2 c x) (a + b x + c x^2)^(n/2)</c>.
17242+
/// https://github.com/asc-community/AngouriMath/issues/1501
17243+
/// </summary>
17244+
/// <remarks>
17245+
/// <see cref="SolveBySubstitution"/> reads this <c>u</c> and does not reach it: for its
17246+
/// own search it writes an exponential of a sum as a product of exponentials, so that
17247+
/// <c>e^(e^x) e^x</c> is <c>e^u du</c>, and <c>e^(a + b x + c x^2)</c> is then
17248+
/// <c>e^a e^(b x) e^(c x^2)</c>, with no <c>P</c> left in it to replace. Declining took
17249+
/// it 24 s. Only a polynomial of degree two or more, whose derivative is a factor of its
17250+
/// own: an exponential of a linear is the table's.
17251+
/// </remarks>
17252+
internal static Entity? SolveByTheExponentAsTheVariable(Entity expr, Entity.Variable x, bool integrateByParts)
17253+
{
17254+
if (expr is not (Mulf or Divf) || AnExponentialOfAPolynomial(expr, x) is not { } exponential)
17255+
return null;
17256+
var polynomial = exponential.Exponent;
17257+
var derivative = polynomial.Differentiate(x);
17258+
Entity? scale = null;
17259+
Entity rest = Number.Integer.One;
17260+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr))
17261+
{
17262+
// The derivative, up to a constant, above the bar: a sum, as it is written.
17263+
if (scale is null && !underneath && factor is Sumf or Minusf && factor.ContainsNode(x)
17264+
&& Functions.PartialFractions.Bare((factor / derivative).Simplify()) is var ratio && !ratio.ContainsNode(x)
17265+
&& ratio.Evaled is not Number.Complex { IsZero: true })
17266+
{
17267+
scale = ratio;
17268+
continue;
17269+
}
17270+
rest = underneath ? rest / factor : rest * factor;
17271+
}
17272+
if (scale is null)
17273+
return null;
17274+
var u = Variable.CreateUnique(expr, "u");
17275+
var inU = (scale * rest.Replace(node => node == polynomial ? u : node)).InnerSimplified;
17276+
if (inU.ContainsNode(x))
17277+
return null;
17278+
return Integration.ComputeAsAQuestionOfItsOwn(inU, u, integrateByParts)?.Substitute(u, polynomial);
17279+
}
17280+
17281+
/// <summary>
17282+
/// A factor of <paramref name="expr"/>, read through products and quotients, that is a
17283+
/// constant to a polynomial in <paramref name="x"/> of degree two or more, or <see langword="null"/>.
17284+
/// </summary>
17285+
private static Powf? AnExponentialOfAPolynomial(Entity expr, Entity.Variable x) => expr switch
17286+
{
17287+
Mulf(var left, var right) => AnExponentialOfAPolynomial(left, x) ?? AnExponentialOfAPolynomial(right, x),
17288+
Divf(var numerator, var denominator) => AnExponentialOfAPolynomial(numerator, x) ?? AnExponentialOfAPolynomial(denominator, x),
17289+
Powf(var @base, Sumf or Minusf) power when !@base.ContainsNode(x) && power.Exponent.ContainsNode(x)
17290+
&& TreeAnalyzer.TryGetPolynomial(power.Exponent, x, out var monomials)
17291+
&& monomials.Keys.All(degree => degree.Sign >= 0) && monomials.Keys.Any(degree => degree.CompareTo(EInteger.One) > 0) => power,
17292+
_ => null
17293+
};
17294+
1723817295
/// <summary>
1723917296
/// Attempts to solve an integral using u-substitution.
1724017297
/// Looks for patterns where f(g(x)) * g'(x) can be integrated as F(g(x)).

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
579579
// An exponential of a multiple of a logarithm is a power of the argument, which is
580580
// how every inverse hyperbolic function under an exponential arrives.
581581
if ((answer = IndefiniteIntegralSolver.SolveByFoldingAnExponentialOfALogarithm(expr, x, integrateByParts)) is { }) return answer;
582+
// An exponential of a polynomial beside the polynomial's derivative, under u = P,
583+
// which the substitution search does not reach: it writes the exponential apart.
584+
if ((answer = IndefiniteIntegralSolver.SolveByTheExponentAsTheVariable(expr, x, integrateByParts)) is { }) return answer;
582585
// `A + i A tan(z)` is `A e^(i z)/cos(z)`, which beside a polynomial is a shape the
583586
// closed rules answer, where the imaginary unit in the coefficient is read by none.
584587
if ((answer = IndefiniteIntegralSolver.SolveByWritingAnImaginaryTangentAsAnExponential(expr, x, integrateByParts)) is { }) return answer;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ public void ASymbolicGaussianWithALinearTermBesideAPolynomial(string integrand)
146146
public void ASymbolicGaussianInAReciprocal(string integrand)
147147
=> DifferentiatesBack(integrand, ("f", "2"), ("a", "1/3"), ("b", "-2/3"), ("c", "5"), ("d", "3/2"));
148148

149+
/// <summary>
150+
/// An exponential of a quadratic beside the quadratic's derivative and a half-odd power of
151+
/// the quadratic, under <c>u = a + b x + c x^2</c>: <c>e^u u^(n/2)</c>. Rubi's 2.3. The
152+
/// quadratic is positive at every point for these pins.
153+
/// </summary>
154+
[Theory]
155+
[InlineData("e^(a + b*x + c*x^2)*(b + 2*c*x)*(a + b*x + c*x^2)^(1/2)")]
156+
[InlineData("e^(a + b*x + c*x^2)*(b + 2*c*x)*(a + b*x + c*x^2)^(5/2)")]
157+
[InlineData("e^(a + b*x + c*x^2)*(b + 2*c*x)/(a + b*x + c*x^2)^(3/2)")]
158+
[InlineData("3*e^(a + b*x + c*x^2)*(2*b + 4*c*x)/sqrt(a + b*x + c*x^2)")]
159+
public void TheExponentAsTheVariable(string integrand)
160+
=> DifferentiatesBack(integrand, ("a", "1/3"), ("b", "-2/3"), ("c", "5/4"));
161+
149162
/// <summary>
150163
/// An odd negative power ends at <c>int e^(A x^2)/x</c>, which is the exponential
151164
/// integral, so it is not taken.

0 commit comments

Comments
 (0)