Skip to content

Commit 58d0dec

Browse files
Integrate exponentials of two bases over a power of x to the exponential integral (#1963)
a^x b^x/x was declined. The rules read one exponential, and a^x b^x is two of different bases that no spelling of the integrand merges: (a b)^x is e^(x ln(a b)), and ln(a b) is not ln(a) + ln(b) for every a and b. Beside a negative power of x, the product of exponentials with no quadratic left in the exponent is now integrated term by term: each power of x against e^(b x), by parts down to Ei(b x). A rate that cancels, b - b from e^(b x) e^(-b x), is decided by its value, and leaves a power of x alone. Rubi's 2.3 a^x b^x/x to a^x b^x/x^3. Part of #233. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 03f6c17 commit 58d0dec

3 files changed

Lines changed: 118 additions & 4 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4904,6 +4904,23 @@ now, and a closed interval at one point meets the other in that point or in noth
49044904
|---|---|---|
49054905
| `"(3; 1) /\ [0; 5]".ToEntity().InnerSimplified` | `[0; 5]` — wrong | `{ }` |
49064906

4907+
### Exponentials of linears in two bases over a power of x are integrated to the exponential integral
4908+
4909+
**Answers where there were none.** `a^x b^x/x`, `a^x b^x/x^2` and `a^x b^x/x^3`, Rubi's 2.3, were declined, and so was
4910+
`sinh(f x)^2/x`. The rules for an exponential over a power of x read one exponential, and no spelling of the integrand
4911+
merges two: `(a b)^x` is `e^(x ln(a b))`, and `ln(a b)` is not `ln(a) + ln(b)` for every `a` and `b`. A product of
4912+
exponentials of linears beside a negative power of x is now taken as one, `e^(r x)` with `r = ln(a) + ln(b)`, by parts
4913+
down to `Ei(r x)`. Where the rates cancel, as `e^(f x) e^(-f x)` does in `sinh(f x)^2`, the term is the power of x
4914+
alone, decided as a value rather than read off the written `f - f`. An exponent with a quadratic in it, or a sine
4915+
beside the exponentials, is declined as before ([#233](https://github.com/asc-community/AngouriMath/issues/233)).
4916+
4917+
| Input | Was (2.5.0) | Now |
4918+
|---|---|---|
4919+
| `"a^x*b^x/x".ToEntity().Integrate("x")` | `integral(...)` | `Ei((ln(a) + ln(b)) x)`, 27 characters |
4920+
| `"a^x*b^x/x^3".ToEntity().Integrate("x")` | `integral(...)` | `e^(r x)` over `x^2` and over `x`, and `Ei(r x)`, 214 characters |
4921+
| `"a^(c+d*x)*b^(f+g*x)/x".ToEntity().Integrate("x")` | `integral(...)` | `e^(c ln(a) + f ln(b)) Ei((d ln(a) + g ln(b)) x)`, 65 characters |
4922+
| `"sinh(f*x)^2/x".ToEntity().Integrate("x")` | `integral(...)` | `Ei(2 f x)/4 - ln(x)/2 + Ei(-2 f x)/4`, 63 characters |
4923+
49074924
### A power of an exponential over a polynomial is integrated to the exponential integral
49084925

49094926
**Answers where there were none.** `(F^(g (e + f x)))^n` with a symbol for `F` or `n` was read by no rule

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

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8423,8 +8423,10 @@ void AddALinear(Entity linear, int power)
84238423
quadratics.Add((coefficient, a, b, c));
84248424
}
84258425
// Some exponent left a quadratic: with none, the product is the elementary
8426-
// exponential's, and the rules for that answer it without an imaginary unit.
8427-
if (!quadratics.Any(term => !TreeAnalyzer.IsZero(term.A)))
8426+
// exponential's, and the rules for that answer it without an imaginary unit -- except
8427+
// beside a negative power of x, below.
8428+
var aQuadratic = quadratics.Any(term => !TreeAnalyzer.IsZero(term.A));
8429+
if (!aQuadratic && trigonometrics > 0)
84288430
return null;
84298431
// The polynomial and the power of x together: as the product written, for the moments
84308432
// at a square's centre, which substitute into it as the integrand writes it, and as
@@ -8446,6 +8448,8 @@ void AddALinear(Entity linear, int power)
84468448
if (powers is not null && powers.Keys.Any(power => power.Abs().CompareTo(EInteger.FromInt32(MostPowerOfAPolynomialBesideExponentials)) > 0))
84478449
return null;
84488450
var aNegativePower = powers is not null && powers.Keys.Any(power => power.Sign < 0);
8451+
if (!aQuadratic && !aNegativePower)
8452+
return null;
84498453
Entity total = Number.Integer.Zero;
84508454
foreach (var (coefficient, a, b, c) in quadratics)
84518455
{
@@ -8460,9 +8464,39 @@ void AddALinear(Entity linear, int power)
84608464
else
84618465
integral = IntegralPatterns.APolynomialTimesTheGaussian(written, MathS.e, a, b, c, x);
84628466
}
8463-
// A negative power beside an elementary exponential is the exponential integral.
8467+
// A negative power beside an elementary exponential is the exponential integral:
8468+
// for exponentials alone, each power of x against e^(b x) by parts down to Ei(b x).
8469+
// The other rules read one exponential, and a^x b^x/x is two of different bases,
8470+
// which no spelling of the integrand merges: (a b)^x is e^(x ln(a b)), and
8471+
// ln(a b) is not ln(a) + ln(b) for every a and b.
84648472
else if (aNegativePower)
8465-
return null;
8473+
{
8474+
if (aQuadratic || powers is null)
8475+
return null;
8476+
// A rate that cancels, `b - b` from e^(b x) e^(-b x), is a power of x alone, and is
8477+
// decided as a value: written, it is not zero, and the exponential integral of it
8478+
// divided by it.
8479+
if (VanishesIdentically(b))
8480+
{
8481+
Entity powersIntegrated = Number.Integer.Zero;
8482+
foreach (var monomial in powers)
8483+
powersIntegrated += monomial.Value * (monomial.Key.Equals(EInteger.FromInt32(-1))
8484+
? MathS.Ln(x)
8485+
: MathS.Pow(x, Number.Integer.Create(monomial.Key + 1)) / Number.Integer.Create(monomial.Key + 1));
8486+
integral = MathS.Pow(MathS.e, c) * powersIntegrated;
8487+
total += coefficient * integral;
8488+
continue;
8489+
}
8490+
var exponential = MathS.Pow(MathS.e, b * x);
8491+
Entity elementary = Number.Integer.Zero, ei = Number.Integer.Zero;
8492+
foreach (var monomial in powers)
8493+
{
8494+
var (part, eiCoefficient) = APowerTimesAnExponential(monomial.Key.ToInt32Checked(), b, exponential, x);
8495+
elementary += monomial.Value * part;
8496+
ei += monomial.Value * eiCoefficient;
8497+
}
8498+
integral = MathS.Pow(MathS.e, c) * (elementary + ei * MathS.Ei(b * x));
8499+
}
84668500
else if (!TreeAnalyzer.IsZero(b))
84678501
integral = MathS.Pow(MathS.e, b * x + c) * APolynomialAgainstAnExponential(powers, b, x);
84688502
else
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 AngouriMath.Extensions;
10+
using Xunit;
11+
12+
namespace AngouriMath.Tests.Calculus
13+
{
14+
/// <summary>
15+
/// Exponentials of linears in different bases over a power of x: <c>a^x b^x/x</c> is
16+
/// <c>Ei((ln(a) + ln(b)) x)</c>. The rule for a product of exponentials left every product
17+
/// without a quadratic to the rules for one exponential, and beside a negative power of x none
18+
/// of them reads two. Rubi's 2.3.
19+
/// <a href="https://github.com/asc-community/AngouriMath/issues/233">#233</a>
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class ExponentialsOfTwoBasesOverAPowerOfXIntegralTest
23+
{
24+
[Fact]
25+
public void TheExponentialIntegralOfTheSumOfTheLogarithms()
26+
=> Assert.Equal("Ei((ln(a) + ln(b)) * x)".ToEntity(), "a^x*b^x/x".ToEntity().Integrate("x").Substitute("C", 0).InnerSimplified);
27+
28+
[Theory]
29+
[InlineData("a^x*b^x/x^2")]
30+
[InlineData("a^x*b^x/x^3")]
31+
[InlineData("a^x*b^x*(1 + x)/x^2")]
32+
[InlineData("a^(c + d*x)*b^(f + g*x)/x")]
33+
[InlineData("2^x*3^x/x")]
34+
// e^(b x) e^(-b x) beside 1/x is 1/x, its rate b - b decided as a value: written, the rate is
35+
// not zero, and these were answered with the exponential integral of it divided by it.
36+
[InlineData("x*Shi(f*x)*sinh(f*x)")]
37+
[InlineData("x*Chi(f*x)*cosh(f*x)")]
38+
[InlineData("sinh(f*x)^2/x")]
39+
public void ByPartsDownToTheExponentialIntegral(string integrand)
40+
{
41+
var integral = integrand.ToEntity().Integrate("x");
42+
var text = integral.Stringize();
43+
Assert.DoesNotContain("integral(", text);
44+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7).Substitute("c", 0.4).Substitute("d", 0.3)
45+
.Substitute("f", 2.3).Substitute("g", -0.6);
46+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
47+
var original = Pinned(integrand.ToEntity());
48+
var compared = 0;
49+
foreach (var at in new[] { -0.9, -0.4, 0.3, 0.8, 1.3, 2.9 })
50+
{
51+
var want = original.Substitute("x", at).EvalNumerical();
52+
var got = derivative.Substitute("x", at).EvalNumerical();
53+
if (want.IsNaN)
54+
continue;
55+
compared++;
56+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
57+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
58+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
59+
}
60+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)