Skip to content

Commit 6d8f3ca

Browse files
Integrate a power beside a Laurent polynomial in an exponential term by term (#2103)
(c + d x)^m/(a + a tanh(e + f x)) was declined. tanh(u) is (e^(2u) - 1)/(e^(2u) + 1) here, so the factor is (1 + e^(-2u))/(2a), a Laurent polynomial in e^(2u), and each of its terms beside the power of the linear is a gamma function. A rational function of one exponential e^B is now read in w = e^B, every exponential a whole multiple of B, and where the quotient has a power of w below the bar and two terms or more, each term is integrated alone. Beside it only constants and powers of x or of one linear, the shapes the gamma rule reads: - for a linear B, at least one of them not whole. Whole powers are elementary or the sine and cosine integrals, sin(x)/x is Si(x), and are answered as such; - for any other B, powers of x alone: x sinh(a + b x^n)^2 is x (e^(2a + 2b x^n) - 2 + e^(-2a - 2b x^n))/4. Beside anything else, sin(c + d/x)/(e + f x) or (a + b x^n)^p sin(c + d x), asking the gamma rule of each term was a slow decline, and the first version of this answered sin(x)/x in gamma functions. The sine, cosine, tangent and cotangent of a linear A are written in e^(i A) first: 1/(1 + i tan(u)) is (1 + e^(-2 i u))/2. And a power of an exponential, (F^E)^n, is F^(n E) times (F^E)^n F^(-n E), which is constant between the cuts and is carried through as a constant: (a + b (F^(g (e + f x)))^n)^2 (c + d x)^m, which timed out, is three gamma functions. Part of #2075. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent e1fe08c commit 6d8f3ca

3 files changed

Lines changed: 158 additions & 0 deletions

File tree

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

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18214,6 +18214,145 @@ static EInteger Choose(int whole, int chosen)
1821418214
}
1821518215
}
1821618216

18217+
/// <summary>
18218+
/// A power of x or of a linear that is not a polynomial, beside a rational function of one exponential of a linear
18219+
/// <c>e^B</c> that is a Laurent polynomial in it: <c>tanh(u)</c> is <c>(e^(2u) - 1)/(e^(2u) + 1)</c> here, so
18220+
/// <c>1/(a + a tanh(u))</c> is <c>(1 + e^(-2u))/(2a)</c>, and <c>tan(u)</c> and <c>cot(u)</c> are written in
18221+
/// <c>e^(2 i u)</c> first: <c>1/(1 + i tan(u))</c> is <c>(1 + e^(-2 i u))/2</c>. Each term is then the power beside
18222+
/// an exponential of a linear, a gamma function. And beside any power of x, or none, a Laurent polynomial in an
18223+
/// exponential of something in x that is not linear: <c>x sinh(a + b x^n)^2</c>. The exponentials are whole
18224+
/// multiples of one, and the quotient in <c>w = e^B</c> has a power of w below the bar, or this declines. Rubi's
18225+
/// 6.3.1, 6.4.1, 4.3.10, 4.4.10, 6.1.3 and 6.2.3.
18226+
/// https://github.com/asc-community/AngouriMath/issues/2075
18227+
/// </summary>
18228+
internal static Entity? SolveAPowerBesideALaurentPolynomialInAnExponential(Entity expr, Entity.Variable x, bool integrateByParts)
18229+
{
18230+
if (!Integration.AnsweringTheQuestionAskedOrOneBelow || expr is not (Mulf or Divf or Powf))
18231+
return null;
18232+
// The sine, cosine, tangent and cotangent of a linear A in E = e^(i A): sin(A) = (E - 1/E)/(2 i), cos(A) =
18233+
// (E + 1/E)/2, tan(A) = (E^2 - 1)/(i (E^2 + 1)) and cot(A) = i (E^2 + 1)/(E^2 - 1).
18234+
var written = expr.Replace(node =>
18235+
{
18236+
if (node is not (Sinf or Cosf or Tanf or Cotanf))
18237+
return node;
18238+
var argument = node.DirectChildren.First();
18239+
if (!argument.ContainsNode(x) || !TreeAnalyzer.TryGetPolyLinear(argument, x, out _, out _))
18240+
return node;
18241+
var exponential = MathS.Pow(MathS.e, MathS.i * argument);
18242+
return node switch
18243+
{
18244+
Sinf => (exponential - 1 / exponential) / (2 * MathS.i),
18245+
Cosf => (exponential + 1 / exponential) / 2,
18246+
Tanf => (MathS.Sqr(exponential) - 1) / (MathS.i * (MathS.Sqr(exponential) + 1)),
18247+
_ => MathS.i * (MathS.Sqr(exponential) + 1) / (MathS.Sqr(exponential) - 1),
18248+
};
18249+
});
18250+
if (written.Nodes.Any(node => node is TrigonometricFunction && node.ContainsNode(x)))
18251+
return null;
18252+
// A power of an exponential, (F^E)^n, is F^(n E) times K = (F^E)^n F^(-n E), which is constant between the
18253+
// cuts, its derivative being 0: carried through as a constant and written back in the answer.
18254+
var constantsBetweenTheCuts = new List<(Variable Name, Entity Value)>();
18255+
written = written.Replace(node =>
18256+
{
18257+
if (node is not Powf(Powf(var @base, var exponent) power, var outer) || @base.ContainsNode(x) || !exponent.ContainsNode(x)
18258+
|| outer.ContainsNode(x) || outer is Number.Integer)
18259+
return node;
18260+
var name = Variable.CreateUnique(expr, "k_cut" + constantsBetweenTheCuts.Count);
18261+
constantsBetweenTheCuts.Add((name, node * MathS.Pow(@base, -(outer * exponent))));
18262+
return name * MathS.Pow(@base, outer * exponent);
18263+
});
18264+
// The factors holding an exponential of x, and the rest, which must be a power that is not a polynomial.
18265+
var (numerator, denominator) = written is Divf(var above, var below) ? (above, below) : (written, (Entity)Number.Integer.One);
18266+
Entity function = Number.Integer.One;
18267+
Entity beside = Number.Integer.One;
18268+
for (var side = 0; side < 2; side++)
18269+
foreach (var factor in Mulf.LinearChildren(side == 0 ? numerator : denominator))
18270+
{
18271+
var holdsAnExponential = factor.Nodes.Any(node => node is Powf(var @base, var power) && !@base.ContainsNode(x) && power.ContainsNode(x));
18272+
if (holdsAnExponential)
18273+
function = side == 0 ? function * factor : function / factor;
18274+
else
18275+
beside = side == 0 ? beside * factor : beside / factor;
18276+
}
18277+
if (!function.ContainsNode(x))
18278+
return null;
18279+
// Every exponential a whole multiple of the first: e^(k B) is w^k.
18280+
Entity? unit = null;
18281+
foreach (var node in function.Nodes)
18282+
if (node is Powf(var @base, var power) && !@base.ContainsNode(x) && power.ContainsNode(x))
18283+
{
18284+
unit = @base == MathS.e ? power : MathS.Ln(@base) * power;
18285+
break;
18286+
}
18287+
if (unit is null)
18288+
return null;
18289+
// Beside it only constants and powers of x or of one linear, whose terms the gamma rule reads. Beside an
18290+
// exponential of a linear, at least one power that is not whole: whole powers are elementary, or the sine and
18291+
// cosine integrals, sin(x)/x is Si(x), and are answered as such. Beside one of something else, powers of x
18292+
// alone: sinh(a + b x^n)^2 x^k is (e^(2 a + 2 b x^n) - 2 + e^(-2 a - 2 b x^n)) x^k/4, where sin(c + d/x)/(e + f x)
18293+
// and (a + b x^n)^p sin(c + d x) are not the gamma rule's, and asking it of each term was a slow decline.
18294+
Entity? linearBase = null;
18295+
var notWhole = false;
18296+
var (besideAbove, besideBelow) = beside is Divf(var besideNumerator, var besideDenominator) ? (besideNumerator, besideDenominator) : (beside, (Entity)Number.Integer.One);
18297+
for (var side = 0; side < 2; side++)
18298+
foreach (var factor in Mulf.LinearChildren(side == 0 ? besideAbove : besideBelow))
18299+
{
18300+
if (!factor.ContainsNode(x))
18301+
continue;
18302+
var (powered, exponentOfIt) = factor is Powf(var b, var e) && !e.ContainsNode(x) ? (b, e) : (factor, (Entity)Number.Integer.One);
18303+
if (!TreeAnalyzer.TryGetPolyLinear(powered, x, out _, out _) || linearBase is not null && powered != linearBase)
18304+
return null;
18305+
linearBase = powered;
18306+
notWhole |= exponentOfIt is not Number.Integer;
18307+
}
18308+
if (TreeAnalyzer.TryGetPolyLinear(unit, x, out _, out _) ? !notWhole : linearBase is not null && linearBase != x)
18309+
return null;
18310+
var w = Variable.CreateUnique(expr, "w_exp");
18311+
var failed = false;
18312+
var inW = function.Replace(node =>
18313+
{
18314+
if (node is not Powf(var @base, var power) || @base.ContainsNode(x) || !power.ContainsNode(x))
18315+
return node;
18316+
var natural = @base == MathS.e ? power : MathS.Ln(@base) * power;
18317+
// The ratio comes with the condition that the unit is not 0, which it is not as a function of x.
18318+
var ratio = (natural / unit).Simplify();
18319+
while (ratio is Providedf(var unconditional, _))
18320+
ratio = unconditional;
18321+
if (ratio is Number.Integer multiple && multiple.EInteger.Abs().CompareTo(EInteger.FromInt32(12)) <= 0)
18322+
return MathS.Pow(w, multiple);
18323+
failed = true;
18324+
return node;
18325+
});
18326+
if (failed || inW.ContainsNode(x))
18327+
return null;
18328+
var (top, bottom) = Functions.SingleQuotient.Of(inW);
18329+
if (!TreeAnalyzer.TryGetPolynomial(bottom.Expand(), w, out var belowInW) || belowInW.Count != 1
18330+
|| !TreeAnalyzer.TryGetPolynomial(top.Expand(), w, out var aboveInW) || aboveInW.Keys.Any(power => power.Sign < 0 || power.CompareTo(EInteger.FromInt32(12)) > 0))
18331+
return null;
18332+
// One term is the question again, respelled: x e^(sin(x)) is x w. Not where a power of an exponential was
18333+
// written as one.
18334+
if (constantsBetweenTheCuts.Count == 0 && aboveInW.Count(term => !TreeAnalyzer.IsZero(term.Value)) < 2)
18335+
return null;
18336+
var only = belowInW.Single();
18337+
var (lowest, scale) = (only.Key, only.Value);
18338+
Entity? answer = null;
18339+
foreach (var entry in aboveInW)
18340+
{
18341+
var (power, coefficient) = (entry.Key, entry.Value);
18342+
if (TreeAnalyzer.IsZero(coefficient))
18343+
continue;
18344+
var shift = power.Subtract(lowest);
18345+
var term = shift.IsZero ? coefficient / scale * beside
18346+
: coefficient / scale * beside * MathS.Pow(MathS.e, (Number.Integer.Create(shift) * unit).InnerSimplified);
18347+
if (Integration.ComputeAsAQuestionOfItsOwn(term.InnerSimplified, x, integrateByParts) is not { } integrated)
18348+
return null;
18349+
answer = answer is null ? integrated : answer + integrated;
18350+
}
18351+
foreach (var (name, value) in constantsBetweenTheCuts)
18352+
answer = answer?.Substitute(name, value);
18353+
return answer;
18354+
}
18355+
1821718356
/// <summary>
1821818357
/// A polynomial beside a function of one shifted linear <c>a + b x</c> that parts cannot reach, written in
1821918358
/// <c>u = a + b x</c>: a power that is not whole of something holding a logarithm of it, <c>x (a + b ln(c (d + e x)))^p</c>,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,7 @@ internal static bool ASumOverRootsWouldAnswer
982982
if ((answer = IndefiniteIntegralSolver.SolveByWritingAnExponentAsAPowerOfAShiftedLinear(expr, x, integrateByParts)) is { }) return answer;
983983
if ((answer = IndefiniteIntegralSolver.SolveAPolynomialBesideATranscendentalPowerOfAShiftedLinear(expr, x, integrateByParts)) is { }) return answer;
984984
if ((answer = IndefiniteIntegralSolver.SolveAPowerOfXBesideATranscendentalPowerOfABinomial(expr, x, integrateByParts)) is { }) return answer;
985+
if ((answer = IndefiniteIntegralSolver.SolveAPowerBesideALaurentPolynomialInAnExponential(expr, x, integrateByParts)) is { }) return answer;
985986
// A half-odd power of a ± a sin(y) beside powers of other linears in the sine, by the half
986987
// angle, before the polynomial term: beneath it the substitution search ran out of time.
987988
if ((answer = IndefiniteIntegralSolver.SolveAHalfOddPowerOfOnePlusMinusASineBesidePowersOfLinearsInIt(expr, x, integrateByParts)) is { }) return answer;

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,24 @@ public void APositiveRateIsTakenOutOfThePower()
218218
[InlineData("(c + a*asin(d - a*x))^n")]
219219
public void ASymbolicPowerOfAnInverseSineOrCosine(string integrand) => DifferentiatesBack(integrand);
220220

221+
/// <summary>
222+
/// A power of a linear beside a rational function of a hyperbolic or circular tangent that is a Laurent polynomial
223+
/// in an exponential: <c>1/(a + a tanh(u))</c> is <c>(1 + e^(-2u))/(2a)</c>. And a power of x beside a square of a
224+
/// hyperbolic function of a power of x, and powers of an exponential, <c>(F^E)^n</c>, which are <c>F^(n E)</c> times a
225+
/// constant between the cuts. Rubi's 6.3.1, 6.4.1, 4.3.10, 4.4.10, 6.1.3, 6.2.3, 2.2 and 2.1.
226+
/// </summary>
227+
[Theory]
228+
[InlineData("(d + f*x)^m/(a + a*tanh(c + b*x))")]
229+
[InlineData("(d + f*x)^m/(a + a*coth(c + b*x))^2")]
230+
[InlineData("(d + f*x)^m/(a + i*a*tan(c + b*x))")]
231+
[InlineData("(d + f*x)^m/(a + i*a*cot(c + b*x))^3")]
232+
[InlineData("x*sinh(a + b*x^n)^2")]
233+
[InlineData("cosh(a + b*x^3)^2")]
234+
[InlineData("sinh(a + b*x^n)^2/x^2")]
235+
[InlineData("(a + b*(c^(d + f*x))^n)^2*(d + f*x)^m")]
236+
[InlineData("(c^(a + b*x))^n*(d + f*x)^(4/3)")]
237+
public void APowerBesideALaurentPolynomialInAnExponential(string integrand) => DifferentiatesBack(integrand);
238+
221239
/// <summary>
222240
/// Not where the integral is elementary, an exponential integral or an error function: those keep the form
223241
/// they had.

0 commit comments

Comments
 (0)