@@ -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
0 commit comments