Skip to content

Commit 694abc3

Browse files
The exponential and logarithmic integrals are integrated to (#1527)
An exponential of a linear over a power of a linear, P(x) F^(a + b x)/(c + d x)^n: under u = c + d x each term is u^m e^(k u), elementary for m >= 0, Ei(k u) for m = -1, and by parts toward it below. The Gaussian's odd negative moments end at int e^(A x^2)/x = Ei(A x^2)/2, so x e^(-1/x^2) is answered under u = 1/x. And a power of x over a whole power of an affine function of a logarithm, x^p (A + B ln(c x^r))^(-k): under t = A + B L it is a constant times e^((p + 1) t/(B r)) t^(-k), which is Ei by parts; the logarithm of a power of a linear is the same question under u = d + e x. Ei(ln y) is li(y), by li's definition, so int 1/ln(x) dx is li(x). Rubi's 2.3, 3.1.2 and 3.3. Part of #1501. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 18b70c1 commit 694abc3

11 files changed

Lines changed: 455 additions & 25 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,23 @@ with an undeclared variable
16161616
| `"Ei(1)".Simplify()` | `Ei` | `Ei(1)`, and `1.895117816355936…` evaluated |
16171617
| `"Ei(x)".Differentiate("x")` | `Ei` | `e ^ x / x` |
16181618

1619+
### The exponential and logarithmic integrals are integrated to
1620+
1621+
`e^x/x` was left unintegrated. An exponential of a linear over a whole power of a linear, beside a
1622+
polynomial, is now integrated to `Ei` under `u = c + d x`, where each term is `u^m e^(k u)`: `Ei(k u)`
1623+
for `m = -1`, and by parts toward it below. The Gaussian's odd negative moments end at
1624+
`int e^(A x^2)/x = Ei(A x^2)/2`. A power of `x` over a whole power of `A + B ln(c x^r)` is integrated to
1625+
`Ei` under `t = A + B ln(c x^r)`, and so is one over a logarithm of a power of a linear, or of
1626+
`d + e x^m`. And `Ei(ln y)` is `li(y)`, by `li`'s definition, so `int 1/ln(x) dx` is `li(x)`
1627+
([#1501](https://github.com/asc-community/AngouriMath/issues/1501)).
1628+
1629+
| Input | Was (2.5.0) | Now |
1630+
|---|---|---|
1631+
| `"e^x/x".Integrate("x")` | `integral(e ^ x / x, x)` | `Ei(x) + C` |
1632+
| `"x*e^(-1/x^2)".Integrate("x")` | `integral(x * e ^ ((-1) / x ^ 2), x)` | the antiderivative, with `Ei` |
1633+
| `"1/ln(x)".Integrate("x")` | `integral(1 / ln(x), x)` | `li(x) + C` |
1634+
| `"x^m/(a + b*ln(c*x^n))".Integrate("x")` | `integral(x ^ m / (a + b * ln(c * x ^ n)), x)` | the antiderivative, with `Ei` |
1635+
16191636
### A definite integral is the limit at a bound where its antiderivative is undefined
16201637

16211638
`integral(x * e^(-x), x, 0, +oo)` was `NaN`, this library's way of saying a value does not

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,6 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
654654

655655
[Tests/UnitTests/Convenience/ExponentialIntegralTest.cs]
656656
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
657+
658+
[Tests/UnitTests/Calculus/ExponentialIntegralIntegrationTest.cs]
659+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

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

Lines changed: 277 additions & 5 deletions
Large diffs are not rendered by default.

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ private static Entity UnitGaussian(Entity A, Entity u)
135135
: MathS.Sqrt(MathS.pi) / (2 * MathS.Sqrt(-A)) * MathS.Erf(MathS.Sqrt(-A) * u);
136136

137137
/// <summary>
138-
/// <c>int k x^m F^(a x^2 + c) dx</c> for an even whole <c>m</c>, not zero, and a non-zero
139-
/// <c>a</c>: the Gaussian moments. With <c>A = a ln F</c> and <c>I_m</c> the integral of
138+
/// <c>int k x^m F^(a x^2 + c) dx</c> for a whole <c>m</c>, not zero, and a non-zero <c>a</c>: the
139+
/// Gaussian moments. With <c>A = a ln F</c> and <c>I_m</c> the integral of
140140
/// <c>x^m e^(A x^2)</c>, parts give <c>I_m = x^(m - 1) e^(A x^2)/(2A) - (m - 1)/(2A) I_(m - 2)</c>,
141141
/// and read the other way <c>I_m = x^(m + 1) e^(A x^2)/(m + 1) - 2A/(m + 1) I_(m + 2)</c> for a
142-
/// negative <c>m</c>, each two powers nearer the Gaussian <c>I_0</c>. An odd <c>m</c> ends at
143-
/// <c>I_1 = e^(A x^2)/(2A)</c>, which is elementary and answered elsewhere, or at <c>I_(-1)</c>,
144-
/// which is the exponential integral, so it is not taken here.
142+
/// negative <c>m</c>, each two powers nearer the Gaussian <c>I_0</c>. An odd positive <c>m</c>
143+
/// ends at <c>I_1 = e^(A x^2)/(2A)</c>, which is elementary and answered elsewhere, and an odd
144+
/// negative one at <c>I_(-1) = Ei(A x^2)/2</c>.
145145
/// https://github.com/asc-community/AngouriMath/issues/1501
146146
/// </summary>
147147
private static Entity? GaussianMoment(Entity expr, Entity.Variable x)
@@ -167,7 +167,9 @@ private static Entity UnitGaussian(Entity A, Entity u)
167167
// Without one, a polynomial beside the Gaussian is a sum the integrator splits first.
168168
if (!TreeAnalyzer.IsZero(b))
169169
return ShiftedMoments(coefficient, power ?? 0, polynomial, gaussian.Base, a, b, c, x);
170-
if (polynomial is not null || power is not { } m || m == 0 || m % 2 != 0 || System.Math.Abs(m) > 32)
170+
// An odd positive power is elementary, and answered elsewhere; an odd negative one ends
171+
// at the exponential integral.
172+
if (polynomial is not null || power is not { } m || m == 0 || m > 0 && m % 2 != 0 || System.Math.Abs(m) > 32)
171173
return null;
172174
var bell = MathS.Pow(gaussian.Base, a * MathS.Sqr(x));
173175
return coefficient * MathS.Pow(gaussian.Base, c) * Moment(m, a * MathS.Ln(gaussian.Base), bell, x);
@@ -243,12 +245,14 @@ private static bool TakeMomentFactor(Entity factor, bool inverted, Entity.Variab
243245
/// <summary>
244246
/// <c>I_k</c>, the integral of <c>x^k e^(A x^2)</c>, where <paramref name="bell"/> is that
245247
/// exponential as the integrand writes it: an even <c>k</c> down to the Gaussian, an odd
246-
/// positive one down to the elementary <c>I_1</c>.
248+
/// positive one down to the elementary <c>I_1</c>, and an odd negative one up to
249+
/// <c>I_(-1) = Ei(A x^2)/2</c>, the exponential integral under <c>t = x^2</c>.
247250
/// </summary>
248251
private static Entity Moment(int k, Entity A, Entity bell, Entity.Variable x) => k switch
249252
{
250253
0 => UnitGaussian(A, x),
251254
1 => bell / (2 * A),
255+
-1 => MathS.Ei(A * MathS.Sqr(x)) / 2,
252256
> 0 => MathS.Pow(x, k - 1) * bell / (2 * A) + ((1 - k) / (2 * A)).InnerSimplified * Moment(k - 2, A, bell, x),
253257
_ => MathS.Pow(x, k + 1) * bell / (k + 1) + (-2 * A / (k + 1)).InnerSimplified * Moment(k + 2, A, bell, x),
254258
};

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
571571
if ((answer = IndefiniteIntegralSolver.SolveAPowerTimesAHalfOddPowerOfTheLogarithm(expr, x)) is { }) return answer;
572572
// And an exponential of a quadratic in it, onto the Gaussian by t = ln(c x^r).
573573
if ((answer = IndefiniteIntegralSolver.SolveAPowerTimesAnExponentialOfAQuadraticInALogarithm(expr, x)) is { }) return answer;
574+
// And a negative whole power of one, onto the exponential integral by t = A + B ln(c x^r).
575+
if ((answer = IndefiniteIntegralSolver.SolveAPowerOverAPowerOfALogarithm(expr, x)) is { }) return answer;
574576
// A power of an exponential with a positive base is the exponential of the product,
575577
// exactly, and only that spelling is one the exponential rules read.
576578
if ((answer = IndefiniteIntegralSolver.SolveByFlatteningAPowerOfAnExponential(expr, x, integrateByParts)) is { }) return answer;
@@ -590,6 +592,8 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
590592
// Exponentials of quadratics, with sines, cosines and sums of them multiplied out:
591593
// each term is the Gaussian's, where the search would take the product by parts.
592594
if ((answer = IndefiniteIntegralSolver.SolveAProductOfExponentialsOfQuadratics(expr, x)) is { }) return answer;
595+
// An exponential of a linear over a power of a linear, onto the exponential integral.
596+
if ((answer = IndefiniteIntegralSolver.SolveAnExponentialOfALinearOverAPowerOfALinear(expr, x)) is { }) return answer;
593597
// A fractional power of a perfect square is the power of the modulus, sgn(P) P^(2r).
594598
if ((answer = IndefiniteIntegralSolver.SolveByTakingARootOfAPerfectSquare(expr, x, integrateByParts)) is { }) return answer;
595599
// x^(n - 1) g(x^n) with a symbolic n is g(u)/n under u = x^n.

‎Sources/AngouriMath/Functions/Evaluation/Evaluation.Continuous/Evaluation.Continuous.Arithmetics.Classes.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ protected override Entity InnerSimplify(bool isExact)
506506
a => a switch
507507
{
508508
Complex n when !isExact => Number.Ei(n),
509+
// li(y) is Ei(ln y), by its definition.
510+
Logf(var @base, var antilogarithm) when @base == MathS.e => MathS.Li(antilogarithm),
509511
Real r when r.EDecimal.IsPositiveInfinity() => Real.PositiveInfinity,
510512
Real r when r.EDecimal.IsNegativeInfinity() => Integer.Zero,
511513
_ => null

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void TheSumTheSplitLeavesIsWhatAnswersTheIntegral()
118118
// is not a break this reads, and an integrand the unit interval cannot integrate stays.
119119
[Theory]
120120
[InlineData("integral(floor(x^2), x, 0, 2)")]
121-
[InlineData("integral(floor(x) * e^(e^x) , x, 0, 2)")]
121+
[InlineData("integral(floor(x) * e^(x^3) , x, 0, 2)")]
122122
public void WhatCannotBeSplitIsLeftAsWritten(string integral)
123123
=> Assert.IsType<Integralf>(integral.ToEntity().Simplify());
124124

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ public void ItsNonElementaryNeighboursAreDeclined(string integrand)
122122
public void OneLevelUpTheTower(string integrand) => DifferentiatesBack(integrand);
123123

124124
/// <summary>
125-
/// The tower's non-elementary neighbours, pinned as declined: <c>e^x ln(x)</c> and
126-
/// <c>e^x/ln(x)</c> have no such <c>P/(D L^k)</c>, and answering them would be wrong.
125+
/// A non-elementary neighbour of the tower, pinned as declined: <c>e^x/ln(x)</c> has no such
126+
/// <c>P/(D L^k)</c>, and no antiderivative in the library's functions either. <c>e^x ln(x)</c>,
127+
/// the other neighbour, is <c>e^x ln(x) - Ei(x)</c> by parts, since <c>Ei</c> is a node.
127128
/// </summary>
128129
[Theory]
129-
[InlineData("e^x*ln(x)")]
130130
[InlineData("e^x/ln(x)")]
131131
public void TheTowersNonElementaryNeighboursAreDeclined(string integrand)
132132
=> Assert.Contains("integral(", integrand.ToEntity().Integrate("x").Stringize());
@@ -178,13 +178,12 @@ public void AnExponentialTimesARootOfAQuadraticIsDeclinedWhereThereIsNone()
178178
=> Assert.Contains("integral(", "e^x*x/sqrt(1 + x^2)".ToEntity().Integrate("x").Stringize());
179179

180180
/// <summary>
181-
/// What has no elementary antiderivative is declined, not answered: the ansatz finds
182-
/// no <c>N</c>, which by Liouville is the proof.
181+
/// What has no antiderivative in the library's functions is declined, not answered: the
182+
/// ansatz finds no <c>N</c>, which by Liouville is the proof that none is elementary.
183+
/// <c>e^x/x</c> and <c>e^x/(1 + x)</c> are not elementary either, but they are <c>Ei</c>.
183184
/// </summary>
184185
[Theory]
185-
[InlineData("e^x/x")]
186186
[InlineData("e^(x^3)")]
187-
[InlineData("e^x/(1 + x)")]
188187
[InlineData("e^(1/x)")]
189188
public void ANonElementaryOneIsDeclined(string integrand)
190189
=> Assert.Contains("integral(", integrand.ToEntity().Integrate("x").Stringize());
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using System;
9+
using System.Linq;
10+
using AngouriMath.Extensions;
11+
using Xunit;
12+
13+
namespace AngouriMath.Tests.Calculus
14+
{
15+
/// <summary>
16+
/// The integrals that answer in the exponential and logarithmic integrals: an exponential of a
17+
/// linear over a power of a linear, the Gaussian's odd negative moments, and a power of x over
18+
/// a power of a logarithm.
19+
/// https://github.com/asc-community/AngouriMath/issues/1501
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class ExponentialIntegralIntegrationTest
23+
{
24+
private static void DifferentiatesBack(string integrand, double[] points, params (string Name, string Value)[] pins)
25+
{
26+
var integral = integrand.ToEntity().Integrate("x");
27+
Assert.DoesNotContain("integral(", integral.Stringize());
28+
Entity Pinned(Entity e) => pins.Aggregate(e, (current, pin) => current.Substitute(pin.Name, pin.Value.ToEntity()));
29+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
30+
var original = Pinned(integrand.ToEntity());
31+
foreach (var at in points)
32+
{
33+
var got = derivative.Substitute("x", at).EvalNumerical();
34+
var want = original.Substitute("x", at).EvalNumerical();
35+
var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart);
36+
var scale = Math.Max(1.0, Math.Abs((double)want.RealPart));
37+
Assert.True(difference / scale < 1e-9, $"d/dx of {integral} is {got} at x = {at}, where {integrand} is {want}");
38+
}
39+
}
40+
41+
/// <summary>Either side of 0 and of every pole below.</summary>
42+
private static readonly double[] AroundZero = { -1.7, 0.35, 0.9, 1.45 };
43+
44+
/// <summary>Past 1, where every logarithm below is real and positive.</summary>
45+
private static readonly double[] PastOne = { 1.3, 1.9, 2.6, 3.4 };
46+
47+
private static readonly (string, string)[] Pins =
48+
{ ("a", "1/3"), ("b", "2/3"), ("c", "5/4"), ("d", "1/2"), ("k", "2"), ("m", "1/2"), ("n", "3"), ("F", "2") };
49+
50+
/// <summary>
51+
/// Under <c>u = c + d x</c>, each term is <c>u^m e^(k u)</c>, and <c>m = -1</c> is <c>Ei(k u)</c>.
52+
/// Rubi's 2.3, <c>F^(c (a + b x))/(d + e x)^n</c>.
53+
/// </summary>
54+
[Theory]
55+
[InlineData("e^x/x")]
56+
[InlineData("e^(2*x + 1)/(3*x + 4)")]
57+
[InlineData("e^x/x^2")]
58+
[InlineData("x*e^x/(x + 1)")]
59+
[InlineData("2^x/x^3")]
60+
[InlineData("(1 + x)^2*e^(-x)/x^2")]
61+
[InlineData("F^(c*(a + b*x))/(d + k*x)^2")]
62+
public void AnExponentialOfALinearOverAPowerOfALinear(string integrand)
63+
=> DifferentiatesBack(integrand, AroundZero, Pins);
64+
65+
/// <summary>
66+
/// The Gaussian's odd negative moments end at <c>int e^(A x^2)/x = Ei(A x^2)/2</c>, and
67+
/// <c>x e^(-1/x^2)</c> is one of them under <c>u = 1/x</c>.
68+
/// </summary>
69+
[Theory]
70+
[InlineData("e^(x^2)/x")]
71+
[InlineData("e^(-x^2)/x^3")]
72+
[InlineData("x*e^(-1/x^2)")]
73+
[InlineData("x^3*e^(-1/x^2)")]
74+
public void AnOddNegativeMomentOfTheGaussian(string integrand)
75+
=> DifferentiatesBack(integrand, AroundZero, Pins);
76+
77+
/// <summary>
78+
/// Under <c>t = A + B ln(c x^r)</c>, <c>x^p (A + B L)^(-k)</c> is a constant times
79+
/// <c>e^((p + 1) t/(B r)) t^(-k)</c>, and a power of x inside, <c>d + e x^m</c>, is the same
80+
/// question under <c>u = x^m</c>. Rubi's 3.1.2, 3.3 and 3.4.
81+
/// </summary>
82+
[Theory]
83+
[InlineData("1/ln(x)")]
84+
[InlineData("x/ln(x)")]
85+
[InlineData("x^2/ln(x)^2")]
86+
[InlineData("x^m/(a + b*ln(c*x^n))")]
87+
[InlineData("1/(a + b*ln(c*x^n))^2")]
88+
[InlineData("(d + k*x)^2/ln(c*(d + k*x)^n)")]
89+
[InlineData("(1 + x)/ln(x)")]
90+
[InlineData("x^2/ln(c*(d + k*x^3)^n)")]
91+
[InlineData("x^8/ln(c*(d + k*x^3)^n)^2")]
92+
public void APowerOverAPowerOfALogarithm(string integrand)
93+
=> DifferentiatesBack(integrand, PastOne, Pins);
94+
95+
/// <summary>
96+
/// The non-elementary neighbours the exponential ansatz declines, which <c>Ei</c> answers:
97+
/// <c>e^(e^x)</c> under <c>u = e^x</c>, and <c>e^x ln(x)</c> by parts.
98+
/// </summary>
99+
[Theory]
100+
[InlineData("e^(e^x)")]
101+
[InlineData("e^x/(1 + x)")]
102+
public void AnExponentialIntegralTheAnsatzDeclines(string integrand)
103+
=> DifferentiatesBack(integrand, AroundZero, Pins);
104+
105+
[Fact]
106+
public void TheExponentialTimesTheLogarithm()
107+
=> DifferentiatesBack("e^x*ln(x)", PastOne, Pins);
108+
109+
/// <summary>
110+
/// Where the exponential integrals cancel, the antiderivative is elementary, and is left to
111+
/// the rules that write it shortest.
112+
/// </summary>
113+
[Fact]
114+
public void WhereTheExponentialIntegralsCancelTheAnswerIsElementary()
115+
=> Assert.Equal("e ^ x / (1 + x) + C", "e^x*x/(1 + x)^2".ToEntity().Integrate("x").Stringize());
116+
117+
/// <summary><c>int 1/ln(x) dx</c> is the logarithmic integral itself, since <c>Ei(ln y) = li(y)</c>.</summary>
118+
[Fact]
119+
public void TheReciprocalOfTheLogarithmIsTheLogarithmicIntegral()
120+
{
121+
Assert.Equal(MathS.Li("x") + "C", "1/ln(x)".ToEntity().Integrate("x"));
122+
Assert.Equal(MathS.Li("y"), MathS.Ei(MathS.Ln("y")).InnerSimplified);
123+
}
124+
}
125+
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,16 @@ public void TheExponentAsTheVariable(string integrand)
160160
=> DifferentiatesBack(integrand, ("a", "1/3"), ("b", "-2/3"), ("c", "5/4"));
161161

162162
/// <summary>
163-
/// An odd negative power ends at <c>int e^(A x^2)/x</c>, which is the exponential
164-
/// integral, so it is not taken.
163+
/// An odd negative power ends at <c>int e^(A x^2)/x</c>, which is not an error function but
164+
/// the exponential integral, <c>Ei(A x^2)/2</c>.
165165
/// </summary>
166166
[Fact]
167167
public void TheGaussianOverAnOddPowerIsNotAnErrorFunction()
168-
=> Assert.Contains("integral(", "e^(-x^2)/x".ToEntity().Integrate("x").Stringize());
168+
{
169+
var integral = DifferentiatesBack("e^(-x^2)/x");
170+
Assert.Contains(integral.Nodes, node => node is Entity.Eif);
171+
Assert.DoesNotContain(integral.Nodes, node => node is Entity.Erff);
172+
}
169173

170174
[Theory]
171175
[InlineData("erf(x)")]

0 commit comments

Comments
 (0)