Skip to content

Commit 12ee980

Browse files
An exponential of a quadratic in the reciprocal of a linear is integrated onto the Gaussian (#1520)
L^m F^(A/L^2 + B/L + C) with L = c + d x: under u = 1/L, dx = -du/(d u^2), and it is -(1/d) u^(-m - 2) F^(A u^2 + B u + C), the Gaussian beside a power, which the table's moments answer, written back with u = 1/L. The exponent is rewritten into u a node at a time. Rubi's 2.3, f^(a + b/x^2) x^m and F^(a + b/(c + d x)^2) (c + d x)^m. SolveAPolynomialTimesARationalFunctionOfAnExponential's doc comment is moved onto it, from above SolveByFlatteningAPowerOfAnExponential's own, and the dispatcher's comment for the flattening rule back above that rule's line. Part of #1501. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 22021b1 commit 12ee980

4 files changed

Lines changed: 141 additions & 18 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,21 @@ 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 quadratic in `1/x` or `1/(c + d x)` is integrated
1714+
1715+
`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`,
1716+
is now integrated under `u = 1/L`, where it is the Gaussian beside a power of `u`. The hyperbolic
1717+
functions of `a + b/x^2` come out too, since they are these exponentials. An odd power that ends at
1718+
the exponential integral, as `x e^(-1/x^2)` does, is still left unintegrated
1719+
([#1501](https://github.com/asc-community/AngouriMath/issues/1501)).
1720+
1721+
| Input | Was (2.5.0) | Now |
1722+
|---|---|---|
1723+
| `"e^(-1/x^2)".Integrate("x")` | `integral(e ^ ((-1) / x ^ 2), x)` | the antiderivative, with `erf` |
1724+
| `"f^(a + b/x^2)*x^2".Integrate("x")` | `integral(f ^ (a + b / x ^ 2) * x ^ 2, x)` | the antiderivative |
1725+
| `"f^(a + b/(c + d*x)^2)/(c + d*x)^4".Integrate("x")` | `integral(f ^ (a + b / (c + d * x) ^ 2) / (c + d * x) ^ 4, x)` | the antiderivative |
1726+
| `"sinh(a + b/x^2)".Integrate("x")` | `integral((e ^ (a + b / x ^ 2) - e ^ (-(a + b / x ^ 2))) / 2, x)` | the antiderivative |
1727+
17131728
### `binomial(n, k)` is a function
17141729

17151730
**Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled

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

Lines changed: 101 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10344,25 +10344,90 @@ private static bool TryReadAPowerTimesARadicalQuadratic(Entity expr, Entity.Vari
1034410344
}
1034510345

1034610346
/// <summary>
10347-
/// A polynomial in <c>x</c> times a rational function of exponentials of <c>x</c>,
10348-
/// by parts against the whole rational function: <c>x tanh(x)^2</c> is
10349-
/// <c>x ((e^(2x) - 1)/(e^(2x) + 1))^2</c>, whose antiderivative under <c>u = e^(2x)</c> is
10350-
/// <c>x - tanh(x)</c>, a polynomial and a rational function of the exponential again,
10351-
/// and what parts leaves is <c>x - tanh(x)</c> itself, a degree lower in <c>x</c>.
10347+
/// An exponential of a quadratic in the reciprocal of a linear, beside a whole power of
10348+
/// the linear: <c>L^m F^(A/L^2 + B/L + C)</c> with <c>L = c + d x</c>. Under <c>u = 1/L</c>,
10349+
/// <c>dx = -du/(d u^2)</c>, and it is <c>-(1/d) u^(-m - 2) F^(A u^2 + B u + C)</c>: the
10350+
/// Gaussian beside a power, which the table's moments answer, written back with
10351+
/// <c>u = 1/L</c>. Rubi's 2.3, <c>f^(a + b/x^2) x^m</c> and <c>F^(a + b/(c + d x)^2) (c + d x)^m</c>.
10352+
/// https://github.com/asc-community/AngouriMath/issues/1501
1035210353
/// </summary>
1035310354
/// <remarks>
10354-
/// <para>
10355-
/// The general parts rule splits the sum <c>(x + x e^(4x))/(e^(2x) + 1)^2</c> and takes
10356-
/// each term on its own, and each term's antiderivative in <c>u</c> holds a logarithm
10357-
/// of <c>e^(2x) + 1</c> -- the two cancel in the sum and neither on its own -- so each
10358-
/// leaves <c>x ln(e^(2x) + 1)</c> behind, a dilogarithm, and twenty-five seconds of
10359-
/// search that found nothing. Here the rational function goes to the exponential
10360-
/// substitution whole, and where its antiderivative keeps a logarithm of an
10361-
/// exponential's sum the integrand is declined at once: <c>x/(e^x + 1)</c> is not
10362-
/// elementary, and this says so in a millisecond.
10363-
/// </para>
10364-
/// https://github.com/asc-community/AngouriMath/issues/718
10355+
/// The exponent is rewritten into <c>u</c> a node at a time -- <c>b/L^k</c> is <c>b u^k</c> --
10356+
/// rather than by substituting <c>x = (1/u - c)/d</c> and asking the simplifier to see
10357+
/// that <c>1/(1/u)^2</c> is <c>u^2</c>.
1036510358
/// </remarks>
10359+
internal static Entity? SolveAGaussianInAReciprocal(Entity expr, Entity.Variable x)
10360+
{
10361+
Powf? exponential = null;
10362+
Entity? linear = null;
10363+
var power = EInteger.Zero;
10364+
Entity constant = Number.Integer.One;
10365+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr))
10366+
{
10367+
if (!factor.ContainsNode(x))
10368+
{
10369+
constant = underneath ? constant / factor : constant * factor;
10370+
continue;
10371+
}
10372+
if (!underneath && exponential is null && factor is Powf(var @base, var exponent) && !@base.ContainsNode(x) && exponent.ContainsNode(x))
10373+
{
10374+
exponential = (Powf)factor;
10375+
continue;
10376+
}
10377+
// The linear, or a whole power of it, above or below the bar.
10378+
var (candidate, k) = factor is Powf(var b, Number.Integer n) && n.EInteger.CanFitInInt32() ? (b, n.EInteger) : (factor, EInteger.One);
10379+
if (linear is not null && linear != candidate
10380+
|| !TreeAnalyzer.TryGetPolyLinear(candidate, x, out var slopeOfIt, out _) || slopeOfIt is null || TreeAnalyzer.IsZero(slopeOfIt))
10381+
return null;
10382+
linear = candidate;
10383+
power = underneath ? power - k : power + k;
10384+
}
10385+
if (exponential is null)
10386+
return null;
10387+
linear ??= ALinearBelowABar(exponential.Exponent, x);
10388+
if (linear is null || !TreeAnalyzer.TryGetPolyLinear(linear, x, out var slope, out _) || slope is null || TreeAnalyzer.IsZero(slope))
10389+
return null;
10390+
var u = Variable.CreateUnique(expr, "u");
10391+
var exponentInU = exponential.Exponent.Replace(node => node switch
10392+
{
10393+
Divf(var numerator, Powf(var below, Number.Integer k)) when below == linear => numerator * MathS.Pow(u, k),
10394+
Divf(var numerator, var below) when below == linear => numerator * u,
10395+
Powf(var below, Number.Integer { EInteger.Sign: < 0 } k) when below == linear => MathS.Pow(u, -k),
10396+
_ => node
10397+
});
10398+
if (exponentInU.ContainsNode(x) || !TreeAnalyzer.TryGetPolyQuadratic(exponentInU, u, out var square, out _, out _) || TreeAnalyzer.IsZero(square))
10399+
return null;
10400+
var powerInU = -power - EInteger.FromInt32(2);
10401+
if (!powerInU.CanFitInInt32() || powerInU.Abs().CompareTo(EInteger.FromInt32(32)) > 0)
10402+
return null;
10403+
var gaussian = MathS.Pow(exponential.Base, exponentInU);
10404+
var inU = powerInU.IsZero ? gaussian : MathS.Pow(u, Number.Integer.Create(powerInU)) * gaussian;
10405+
if (IntegralPatterns.TryStandardIntegrals(inU, u) is not { } answerInU)
10406+
return null;
10407+
return (-constant / slope * answerInU.Substitute(u, 1 / linear)).InnerSimplified;
10408+
}
10409+
10410+
/// <summary>
10411+
/// The linear a node of <paramref name="exponent"/> divides by, <c>b/L^k</c> or <c>L^(-k)</c>,
10412+
/// or <see langword="null"/>.
10413+
/// </summary>
10414+
private static Entity? ALinearBelowABar(Entity exponent, Entity.Variable x)
10415+
{
10416+
foreach (var node in exponent.Nodes)
10417+
{
10418+
var below = node switch
10419+
{
10420+
Divf(_, Powf(var b, Number.Integer)) => b,
10421+
Divf(_, var b) => b,
10422+
Powf(var b, Number.Integer { EInteger.Sign: < 0 }) => b,
10423+
_ => null
10424+
};
10425+
if (below is { } && below.ContainsNode(x) && TreeAnalyzer.TryGetPolyLinear(below, x, out var slope, out _) && slope is { } && !TreeAnalyzer.IsZero(slope))
10426+
return below;
10427+
}
10428+
return null;
10429+
}
10430+
1036610431
/// <summary>
1036710432
/// A power of an exponential of <c>x</c> with a positive constant base, written as the
1036810433
/// exponential of the product: <c>(e^x)^(1/3)</c> is <c>e^(x/3)</c> and <c>(3^(3x))^(1/4)</c>
@@ -10881,6 +10946,26 @@ node is Powf(Mulf(var l, var r) product, Number.Integer power) && product.Contai
1088110946
return distributed == expr ? null : Integration.ComputeAsTheSameQuestion(distributed, x, integrateByParts);
1088210947
}
1088310948

10949+
/// <summary>
10950+
/// A polynomial in <c>x</c> times a rational function of exponentials of <c>x</c>,
10951+
/// by parts against the whole rational function: <c>x tanh(x)^2</c> is
10952+
/// <c>x ((e^(2x) - 1)/(e^(2x) + 1))^2</c>, whose antiderivative under <c>u = e^(2x)</c> is
10953+
/// <c>x - tanh(x)</c>, a polynomial and a rational function of the exponential again,
10954+
/// and what parts leaves is <c>x - tanh(x)</c> itself, a degree lower in <c>x</c>.
10955+
/// </summary>
10956+
/// <remarks>
10957+
/// <para>
10958+
/// The general parts rule splits the sum <c>(x + x e^(4x))/(e^(2x) + 1)^2</c> and takes
10959+
/// each term on its own, and each term's antiderivative in <c>u</c> holds a logarithm
10960+
/// of <c>e^(2x) + 1</c> -- the two cancel in the sum and neither on its own -- so each
10961+
/// leaves <c>x ln(e^(2x) + 1)</c> behind, a dilogarithm, and twenty-five seconds of
10962+
/// search that found nothing. Here the rational function goes to the exponential
10963+
/// substitution whole, and where its antiderivative keeps a logarithm of an
10964+
/// exponential's sum the integrand is declined at once: <c>x/(e^x + 1)</c> is not
10965+
/// elementary, and this says so in a millisecond.
10966+
/// </para>
10967+
/// https://github.com/asc-community/AngouriMath/issues/718
10968+
/// </remarks>
1088410969
internal static Entity? SolveAPolynomialTimesARationalFunctionOfAnExponential(Entity expr, Entity.Variable x, bool integrateByParts)
1088510970
{
1088610971
// The polynomial factors above the bar, and the rest, which holds x in exponents only.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,16 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
564564
// among them, `(c x)^m x^n`, by the power rule with the written power kept as
565565
// it is. Beside the polynomial term, since that is what it is.
566566
if ((answer = IndefiniteIntegralSolver.SolveAProductOfPowersOfTheVariable(expr, x)) is { }) return answer;
567-
// A power of an exponential with a positive base is the exponential of the product,
568-
// exactly, and only that spelling is one the exponential rules read.
569567
// A power of x times a power of its logarithm, by the closed reduction: exact,
570568
// and by parts n times where the exponent is a symbol was not taken.
571569
if ((answer = IndefiniteIntegralSolver.SolveAPowerTimesAPowerOfTheLogarithm(expr, x)) is { }) return answer;
572570
// And a half-odd power of it, onto the Gaussian's moments by t = sqrt(F).
573571
if ((answer = IndefiniteIntegralSolver.SolveAPowerTimesAHalfOddPowerOfTheLogarithm(expr, x)) is { }) return answer;
572+
// A power of an exponential with a positive base is the exponential of the product,
573+
// exactly, and only that spelling is one the exponential rules read.
574574
if ((answer = IndefiniteIntegralSolver.SolveByFlatteningAPowerOfAnExponential(expr, x, integrateByParts)) is { }) return answer;
575+
// An exponential of a quadratic in 1/L beside a power of L, onto the Gaussian under u = 1/L.
576+
if ((answer = IndefiniteIntegralSolver.SolveAGaussianInAReciprocal(expr, x)) is { }) return answer;
575577
// An exponential of a multiple of a logarithm is a power of the argument, which is
576578
// how every inverse hyperbolic function under an exponential arrives.
577579
if ((answer = IndefiniteIntegralSolver.SolveByFoldingAnExponentialOfALogarithm(expr, x, integrateByParts)) is { }) return answer;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,27 @@ public void ASymbolicGaussianIsUnconditional()
125125
public void ASymbolicGaussianWithALinearTermBesideAPolynomial(string integrand)
126126
=> DifferentiatesBack(integrand, ("f", "2"), ("a", "1/3"), ("b", "-2/3"), ("c", "-5/4"), ("d", "3/2"), ("p", "1/2"), ("q", "3"));
127127

128+
/// <summary>
129+
/// An exponential of a quadratic in the reciprocal of a linear, beside a whole power of
130+
/// the linear, under <c>u = 1/L</c>: the Gaussian beside a power. Rubi's 2.3,
131+
/// <c>f^(a + b/x^2) x^m</c> and <c>F^(a + b/(c + d x)^2) (c + d x)^m</c>. The points are off 0,
132+
/// where the exponent is undefined.
133+
/// </summary>
134+
[Theory]
135+
[InlineData("e^(-1/x^2)")]
136+
[InlineData("e^(-1/x^2)/x^2")]
137+
[InlineData("x^2*e^(-1/x^2)")]
138+
[InlineData("e^(1/(2 + 3*x)^2)/(2 + 3*x)^4")]
139+
public void TheGaussianInAReciprocal(string integrand) => DifferentiatesBack(integrand);
140+
141+
[Theory]
142+
[InlineData("f^(a + b/x^2)")]
143+
[InlineData("f^(a + b/x^2)*x^2")]
144+
[InlineData("f^(a + b/x^2)/x^4")]
145+
[InlineData("f^(a + b/(c + d*x)^2)*(c + d*x)^2")]
146+
public void ASymbolicGaussianInAReciprocal(string integrand)
147+
=> DifferentiatesBack(integrand, ("f", "2"), ("a", "1/3"), ("b", "-2/3"), ("c", "5"), ("d", "3/2"));
148+
128149
/// <summary>
129150
/// An odd negative power ends at <c>int e^(A x^2)/x</c>, which is the exponential
130151
/// integral, so it is not taken.

0 commit comments

Comments
 (0)