Skip to content

Commit 0a13a63

Browse files
A power of an exponential over a polynomial is integrated to the exponential integral (#1733)
(F^(g (e + f x)))^n has the constant logarithmic derivative n g f ln F, so it is a constant times e^(n g f ln(F) x) wherever it is differentiable; with a symbol for the constant, over a polynomial the integrand is the exponential integral's, and the constant is written back as the power times e^(-n g f ln(F) x). That holds for every F, where F^(n u) holds only for a positive one. Rubi's 2.2. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent ac6e33f commit 0a13a63

4 files changed

Lines changed: 149 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

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

1759+
### A power of an exponential over a polynomial is integrated to the exponential integral
1760+
1761+
**Answers where there were none.** `(F^(g (e + f x)))^n` with a symbol for `F` or `n` was read by no rule
1762+
below a polynomial: `(F^x)^n/x` and Rubi's 2.2, `(a + b (F^(g (e + f x)))^n)^p/(c + d x)^m`, were
1763+
declined. Its logarithmic derivative is the constant `n g f ln F`, so it is a constant times
1764+
`e^(n g f ln(F) x)` wherever it is differentiable, and the answer is the exponential integral's with
1765+
that constant written back as `(F^(g (e + f x)))^n e^(-n g f ln(F) x)`. It holds for every `F`: a
1766+
negative one makes `(F^x)^n` differ from `F^(n x)` past each point where `F^x` crosses the negative
1767+
axis, and the constant carries that. A whole power is `F^(n u)` exactly and is written so
1768+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
1769+
1770+
| Input | Was (2.5.0) | Now |
1771+
|---|---|---|
1772+
| `"(F^x)^2/x".ToEntity().Integrate("x")` | `integral(...)` | `Ei(2 ln(F) x)` |
1773+
| `"(F^x)^n/x".ToEntity().Integrate("x")` | `integral(...)` | `(F^x)^n e^(-n ln(F) x) Ei(n ln(F) x)` |
1774+
| `"(a + b*(F^(g*(e + f*x)))^n)/(c + d*x)".ToEntity().Integrate("x")` | `integral(...)` | a logarithm and an exponential integral |
1775+
| `"(a + b*(F^(g*(e + f*x)))^n)^3/(c + d*x)^3".ToEntity().Integrate("x")` | `integral(...)` | powers of `c + d x` and exponential integrals |
1776+
17591777
### An exponential of a multiple of a logarithm is integrated as the power it is
17601778

17611779
`e^(k ln(q))` is `q^k` — the definition of the principal power, for every complex `q` other than

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16015,6 +16015,66 @@ node is Powf(Powf(var @base, var inner), var outer)
1601516015
return flattened == expr ? null : Integration.ComputeAsAQuestionOfItsOwn(flattened, x, integrateByParts);
1601616016
}
1601716017

16018+
/// <summary>
16019+
/// A power of an exponential the flattening above leaves -- a symbol for the base or the
16020+
/// power, <c>(F^(g (e + f x)))^n</c> -- beside a polynomial below the bar. Its logarithmic
16021+
/// derivative is the constant <c>n g f ln F</c>, so it is <c>K e^(n g f ln(F) x)</c> with
16022+
/// <c>K</c> constant wherever it is differentiable; with a symbol for <c>K</c> the integrand
16023+
/// is one the exponential integral's rules read, and the answer is written back with
16024+
/// <c>K = (F^(g (e + f x)))^n e^(-n g f ln(F) x)</c>. A whole power is the exponential of
16025+
/// the product exactly, whatever the base, and is written so. Rubi's 2.2,
16026+
/// <c>(a + b (F^(g (e + f x)))^n)^p/(c + d x)^m</c>.
16027+
/// https://github.com/asc-community/AngouriMath/issues/718
16028+
/// </summary>
16029+
/// <remarks>
16030+
/// <c>(F^u)^n</c> is <c>F^(n u)</c> only where <c>F^u</c> is on the principal branch, which
16031+
/// it is for a positive <c>F</c> and need not be for a symbol; <c>K</c> carries the
16032+
/// difference, and the answer holds for every <c>F</c>. Only beside a polynomial below the
16033+
/// bar, where nothing else reads the power: above it, the rules for a polynomial times an
16034+
/// exponential answer it as written.
16035+
/// </remarks>
16036+
internal static Entity? SolveByWritingAPowerOfAnExponentialAsAMultipleOfOne(Entity expr, Entity.Variable x, bool integrateByParts)
16037+
{
16038+
bool IsAnExponential(Entity node) => node is Powf(var b, var p) && !b.ContainsNode(x) && p.ContainsNode(x);
16039+
var powers = expr.Nodes.Where(node => node is Powf(Powf(var @base, var inner), var outer)
16040+
&& !@base.ContainsNode(x) && inner.ContainsNode(x) && !outer.ContainsNode(x)
16041+
&& !((@base == MathS.e || @base.Evaled is Number.Real { IsPositive: true }) && outer.Evaled is Number.Real))
16042+
.Distinct().ToList();
16043+
if (powers.Count == 0)
16044+
return null;
16045+
// A polynomial below the bar, or under a negative whole power.
16046+
if (!FactorsOfTheIntegrand(expr).Any(pair =>
16047+
pair.Factor.ContainsNode(x) && !pair.Factor.Nodes.Any(IsAnExponential)
16048+
&& (pair.Underneath || pair.Factor is Powf(_, Number.Integer { IsNegative: true }))
16049+
&& TreeAnalyzer.TryGetPolynomial(pair.Factor is Powf(var raised, Number.Integer) ? raised : pair.Factor, x, out var read)
16050+
&& read.Keys.All(degree => degree.Sign >= 0)))
16051+
return null;
16052+
var back = new List<(Entity.Variable Constant, Entity Value)>();
16053+
var rewritten = expr;
16054+
foreach (var node in powers)
16055+
{
16056+
if (node is not Powf(Powf(var @base, var inner), var outer)
16057+
|| !TreeAnalyzer.TryGetPolyLinear(inner, x, out var slope, out _) || TreeAnalyzer.IsZero(slope))
16058+
return null;
16059+
Entity replacement;
16060+
if (outer.Evaled is Number.Integer)
16061+
replacement = MathS.Pow(@base, (outer * inner).InnerSimplified);
16062+
else
16063+
{
16064+
var constant = Variable.CreateUnique(rewritten, "k_pow");
16065+
var rate = (outer * slope * (@base == MathS.e ? Number.Integer.One : MathS.Ln(@base))).InnerSimplified;
16066+
replacement = constant * MathS.Pow(MathS.e, rate * x);
16067+
back.Add((constant, node * MathS.Pow(MathS.e, -rate * x)));
16068+
}
16069+
rewritten = rewritten.Replace(inside => inside == node ? replacement : inside);
16070+
}
16071+
if (Integration.ComputeAsAQuestionOfItsOwn(rewritten, x, integrateByParts) is not { } answer || answer.Nodes.Any(inside => inside is Integralf))
16072+
return null;
16073+
foreach (var (constant, value) in back)
16074+
answer = answer.Substitute(constant, value);
16075+
return answer;
16076+
}
16077+
1601816078
/// <summary>
1601916079
/// An exponential of a multiple of a logarithm is a power of the argument:
1602016080
/// <c>e^(k ln(q))</c> is <c>q^k</c>, since <c>e^(k ln q)</c> is the definition of the

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
633633
// A power of an exponential with a positive base is the exponential of the product,
634634
// exactly, and only that spelling is one the exponential rules read.
635635
if ((answer = IndefiniteIntegralSolver.SolveByFlatteningAPowerOfAnExponential(expr, x, integrateByParts)) is { }) return answer;
636+
// And any other power of an exponential beside a polynomial below the bar, as a constant
637+
// multiple of an exponential wherever it is differentiable.
638+
if ((answer = IndefiniteIntegralSolver.SolveByWritingAPowerOfAnExponentialAsAMultipleOfOne(expr, x, integrateByParts)) is { }) return answer;
636639
// An exponential of a quadratic in 1/L beside a power of L, onto the Gaussian under u = 1/L.
637640
if ((answer = IndefiniteIntegralSolver.SolveAGaussianInAReciprocal(expr, x)) is { }) return answer;
638641
// An exponential of a multiple of a logarithm is a power of the argument, which is
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
/// A power of an exponential beside a polynomial below the bar: <c>(F^(g (k + f x)))^n</c> has
16+
/// the constant logarithmic derivative <c>n g f ln F</c>, so it is a constant times
17+
/// <c>e^(n g f ln(F) x)</c> wherever it is differentiable, and over a linear it is an
18+
/// exponential integral. Rubi's 2.2, <c>(a + b (F^(g (e + f x)))^n)^p/(c + d x)^m</c>, all
19+
/// declined before.
20+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
21+
/// </summary>
22+
[Trait("Area", "Calculus")]
23+
public sealed class PowerOfAnExponentialIntegralTest
24+
{
25+
[Theory]
26+
[InlineData("(F^x)^2/x")]
27+
[InlineData("(F^x)^n/x")]
28+
[InlineData("(exp(x))^n/x")]
29+
[InlineData("(a + b*(F^(g*(k + f*x)))^n)/(c + d*x)")]
30+
[InlineData("(a + b*(F^(g*(k + f*x)))^n)^2/(c + d*x)^2")]
31+
[InlineData("(a + b*(F^(g*(k + f*x)))^n)^3/(c + d*x)^3")]
32+
public void OverALinear(string integrand) => DifferentiatesBack(integrand, 3, realOnly: true);
33+
34+
/// <summary>
35+
/// With a negative base, <c>(F^x)^n</c> is not <c>F^(n x)</c>: the two differ by a power of
36+
/// <c>e^(2 pi i n)</c> that changes where <c>F^x</c> crosses the negative axis. The answer
37+
/// holds between those crossings, compared as complex numbers.
38+
/// </summary>
39+
[Theory]
40+
[InlineData("(F^x)^n/x")]
41+
[InlineData("(a + b*(F^(g*(k + f*x)))^n)/(c + d*x)")]
42+
public void OverALinearWithANegativeBase(string integrand) => DifferentiatesBack(integrand, -3, realOnly: false);
43+
44+
private static void DifferentiatesBack(string integrand, double @base, bool realOnly)
45+
{
46+
var integral = integrand.ToEntity().Integrate("x");
47+
Assert.DoesNotContain("integral(", integral.Stringize());
48+
Assert.DoesNotContain("NaN", integral.Stringize());
49+
Entity Pinned(Entity e) => e.Substitute("a", 2.3).Substitute("b", 0.7).Substitute("c", 1.3).Substitute("d", 1.7)
50+
.Substitute("f", 0.9).Substitute("g", 1.2).Substitute("k", 0.4).Substitute("n", 2.5).Substitute("F", @base);
51+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
52+
var original = Pinned(integrand.ToEntity());
53+
var compared = 0;
54+
foreach (var at in new[] { -1.7, -0.9, 0.3, 0.8, 1.6, 2.9 })
55+
{
56+
var want = original.Substitute("x", at).EvalNumerical();
57+
if (want.IsNaN || realOnly && Math.Abs((double)want.ImaginaryPart) > 1e-12)
58+
continue;
59+
compared++;
60+
var got = derivative.Substitute("x", at).EvalNumerical();
61+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
62+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
63+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
64+
}
65+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)