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