@@ -24047,6 +24047,105 @@ private static bool IsARationalFunctionOfExponentials(Entity expr, Entity.Variab
2404724047 return Integration.ComputeAsAQuestionOfItsOwn(inU, u, integrateByParts)?.Substitute(u, polynomial);
2404824048 }
2404924049
24050+ /// <summary>
24051+ /// An exponential of a multiple of a hyperbolic sine or cosine of a linear, beside a function
24052+ /// of the exponentials of the linear whose quotient by the derivative of that sine or cosine
24053+ /// is a rational function of it: under <c>u = e^L + s e^(-L)</c>, twice the cosine or the
24054+ /// sine, <c>e^(n sinh(L)) cosh(L)</c> is <c>e^(n u/2)/2</c>, <c>e^(n cosh(L)) tanh(L)</c> is
24055+ /// <c>e^(n u/2)/u</c>, onto the exponential integral, and <c>e^(n sinh(L)) sinh(2L)</c> is
24056+ /// <c>u e^(n u/2)/2</c>. The substitution answers the trigonometric ones written as nodes --
24057+ /// <c>e^(n cos(x)) tan(x)</c> is <c>-Ei(n cos(x))</c> -- while a hyperbolic function arrives as
24058+ /// exponentials, and no rule read the sine or cosine in them. Rubi's 6.7.1.
24059+ /// https://github.com/asc-community/AngouriMath/issues/718
24060+ /// </summary>
24061+ /// <remarks>
24062+ /// Every exponential of the variable but the outer one is a whole power of <c>w = e^L</c>, with
24063+ /// <c>L</c> the linear their exponents are whole multiples of, compared as polynomials and not
24064+ /// as written; the quotient is written in <c>u = w + s/w</c> by undetermined coefficients and a
24065+ /// check at points, or the rule declines.
24066+ /// </remarks>
24067+ internal static Entity? SolveAnExponentialOfAHyperbolicFunctionBesideItsDerivative(Entity expr, Entity.Variable x, bool integrateByParts)
24068+ {
24069+ bool IsAnExponential(Entity node) => node is Powf(var b, var p) && !b.ContainsNode(x) && p.ContainsNode(x);
24070+ // The outer exponential, above the bar, with exponentials of the variable in its exponent.
24071+ Powf? outer = null;
24072+ Entity rest = Number.Integer.One;
24073+ foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr))
24074+ {
24075+ if (!underneath && outer is null && factor is Powf(var @base, var exponent) && @base == MathS.e && exponent.Nodes.Any(IsAnExponential))
24076+ {
24077+ outer = (Powf)factor;
24078+ continue;
24079+ }
24080+ rest = underneath ? rest / factor : rest * factor;
24081+ }
24082+ if (outer is null)
24083+ return null;
24084+ // The exponentials inside it and beside it, each `e^(k L)` with one linear L.
24085+ var multiples = new Dictionary<Entity, ERational>();
24086+ Entity? unitSlope = null, unitOffset = null, unit = null;
24087+ foreach (var node in expr.Nodes)
24088+ {
24089+ if (node == outer || !IsAnExponential(node) || multiples.ContainsKey(node))
24090+ continue;
24091+ if (node is not Powf(var @base, var exponent) || @base != MathS.e
24092+ || !TreeAnalyzer.TryGetPolyLinear(exponent, x, out var slope, out var offset) || TreeAnalyzer.IsZero(slope))
24093+ return null;
24094+ if (unit is null)
24095+ {
24096+ (unit, unitSlope, unitOffset) = (exponent, slope, offset);
24097+ multiples[node] = ERational.One;
24098+ continue;
24099+ }
24100+ if (Functions.PartialFractions.Bare((slope / unitSlope!).Simplify()).Evaled is not Number.Rational ratio || ratio.ERational.IsZero
24101+ || !IsTheZeroPolynomial((offset - ratio * unitOffset!).InnerSimplified))
24102+ return null;
24103+ multiples[node] = ratio.ERational;
24104+ }
24105+ if (unit is null || unitSlope is null)
24106+ return null;
24107+ var numerators = EInteger.Zero;
24108+ var denominators = EInteger.One;
24109+ foreach (var multiple in multiples.Values)
24110+ {
24111+ numerators = numerators.Gcd(multiple.Numerator.Abs());
24112+ denominators = denominators.Multiply(multiple.Denominator).Divide(denominators.Gcd(multiple.Denominator));
24113+ }
24114+ var step = ERational.Create(numerators, denominators);
24115+ if (multiples.Values.Any(multiple => multiple.Divide(step).ToLowestTerms().Numerator.Abs().CompareTo(EInteger.FromInt32(8)) > 0))
24116+ return null;
24117+ var w = Variable.CreateUnique(expr, "w_hyp");
24118+ Entity InW(Entity e) => e.Replace(node =>
24119+ node != outer && multiples.TryGetValue(node, out var multiple) ? MathS.Pow(w, Number.Integer.Create(multiple.Divide(step).ToLowestTerms().Numerator)) : node);
24120+ // The exponent `c (w + s/w) + d`: a multiple of the sine or the cosine in w and nothing else.
24121+ if (!TreeAnalyzer.TryGetPolynomial(InW(outer.Exponent), w, out var exponentRead)
24122+ || exponentRead.Keys.Any(degree => degree.Abs().CompareTo(EInteger.One) > 0)
24123+ || exponentRead.Values.Any(coefficient => coefficient.ContainsNode(x))
24124+ || !exponentRead.TryGetValue(EInteger.One, out var c) || !exponentRead.TryGetValue(EInteger.FromInt32(-1), out var cBelow))
24125+ return null;
24126+ int sign;
24127+ if (IsTheZeroPolynomial((cBelow - c).InnerSimplified))
24128+ sign = 1;
24129+ else if (IsTheZeroPolynomial((cBelow + c).InnerSimplified))
24130+ sign = -1;
24131+ else
24132+ return null;
24133+ var d = exponentRead.TryGetValue(EInteger.Zero, out var constantTerm) ? constantTerm : Number.Integer.Zero;
24134+ // du = slope (w - s/w) dx, with u = w + s/w and the slope that of the unit, step L.
24135+ var restInW = InW(rest);
24136+ if (restInW.ContainsNode(x))
24137+ return null;
24138+ var slopeOfW = (Number.Rational.Create(step) * unitSlope).InnerSimplified;
24139+ if (!TryWriteInTheReciprocalVariable(restInW / (slopeOfW * (w - Number.Integer.Create(sign) / w)), w, sign, out var u, out var inU))
24140+ return null;
24141+ var question = (MathS.Pow(MathS.e, c * u + d) * inU).InnerSimplified;
24142+ if (Integration.ComputeAsAQuestionOfItsOwn(question, u, integrateByParts) is not { } answer || answer.Nodes.Any(node => node is Integralf))
24143+ return null;
24144+ var exponentOfW = (Number.Rational.Create(step) * unit).InnerSimplified;
24145+ return Functions.PartialFractions.Bare(answer.InnerSimplified)
24146+ .Substitute(u, MathS.Pow(MathS.e, exponentOfW) + Number.Integer.Create(sign) * MathS.Pow(MathS.e, -exponentOfW));
24147+ }
24148+
2405024149 /// <summary>
2405124150 /// A factor of <paramref name="expr"/>, read through products and quotients, that is a
2405224151 /// constant to a polynomial in <paramref name="x"/> of degree two or more, or <see langword="null"/>.
0 commit comments