Skip to content

Commit 9a82a17

Browse files
An exponential of a hyperbolic sine or cosine beside a function of it over its derivative is integrated (#1739)
e^(n cosh(a + b x)) tanh(a + b x) is Ei(n cosh(a + b x))/b, as e^(n cos(x)) tan(x) is -Ei(n cos(x)), and was declined: a hyperbolic function arrives as exponentials, and the substitution that reads the sine or cosine as a node had none to read. In w = e^L the rest over the derivative of the outer exponent's sine or cosine is asked as a rational function of u = w + s/w, twice that sine or cosine, and where it is one, integrated in u. Rubi's 6.7.1. 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 6bbed69 commit 9a82a17

4 files changed

Lines changed: 172 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,6 +2682,23 @@ with `int F` the next power over `p^2`. Rubi's 6.1.1, 6.2.1, 6.5.1 and 6.6.1
26822682
| `"x/sech(x)^(7/2)-5/21*x*sqrt(sech(x))".Integrate("x")` | left unevaluated | the antiderivative, over two reduction steps |
26832683
| `"x/csch(x)^(3/2)+1/3*x*sqrt(csch(x))".Integrate("x")` | left unevaluated | the antiderivative |
26842684

2685+
### An exponential of a hyperbolic sine or cosine beside a function of it over its derivative is integrated
2686+
2687+
**Answers where there were none.** `e^(n cosh(a + b x)) tanh(a + b x)` is `Ei(n cosh(a + b x))/b`, as
2688+
`e^(n cos(x)) tan(x)` is `-Ei(n cos(x))`, which was answered; the hyperbolic one was declined, after
2689+
seconds, and so were `e^(n sinh(a + b x)) sinh(2 (a + b x))` and the same with half the argument in the
2690+
exponent, Rubi's 6.7.1. A hyperbolic function arrives as exponentials, and the substitution that reads
2691+
the sine or cosine as a node had none to read. Written in `w = e^L`, the integrand beside the outer
2692+
exponential over the derivative of its sine or cosine is now asked as a rational function of
2693+
`u = w + s/w`, twice that sine or cosine; where it is one, it is integrated in `u` and written back
2694+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
2695+
2696+
| Input | Was (2.5.0) | Now |
2697+
|---|---|---|
2698+
| `"exp(n*cosh(a + b*x))*tanh(a + b*x)".ToEntity().Integrate("x")` | `integral(...)` | `Ei(n cosh(a + b x))/b`, written as exponentials |
2699+
| `"exp(n*sinh(a + b*x))*sinh(2*(a + b*x))".ToEntity().Integrate("x")` | `integral(...)` | elementary in `sinh(a + b x)` and its exponential |
2700+
| `"exp(n*cosh(1/2*(a + b*x)))*sinh(a + b*x)".ToEntity().Integrate("x")` | `integral(...)` | the same in `cosh((a + b x)/2)` |
2701+
26852702
### A hyperbolic function of a logarithm is integrated, the exponent folded structurally
26862703

26872704
`tanh(ln(x))` was left as written. The library spells `tanh(y)` with `e^(2y)`, so a hyperbolic

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

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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"/>.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,9 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
646646
// An exponential of a polynomial beside the polynomial's derivative, under u = P,
647647
// which the substitution search does not reach: it writes the exponential apart.
648648
if ((answer = IndefiniteIntegralSolver.SolveByTheExponentAsTheVariable(expr, x, integrateByParts)) is { }) return answer;
649+
// And an exponential of a hyperbolic sine or cosine of a linear beside a function of it
650+
// over its derivative, under u = twice that sine or cosine, which arrive as exponentials.
651+
if ((answer = IndefiniteIntegralSolver.SolveAnExponentialOfAHyperbolicFunctionBesideItsDerivative(expr, x, integrateByParts)) is { }) return answer;
649652
// `A + i A tan(z)` is `A e^(i z)/cos(z)`, which beside a polynomial is a shape the
650653
// closed rules answer, where the imaginary unit in the coefficient is read by none.
651654
if ((answer = IndefiniteIntegralSolver.SolveByWritingAnImaginaryTangentAsAnExponential(expr, x, integrateByParts)) is { }) return answer;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
/// An exponential of a hyperbolic sine or cosine of a linear beside a function of it over its
16+
/// derivative, under <c>u</c> twice that sine or cosine: <c>e^(n cosh(a + b x)) tanh(a + b x)</c>
17+
/// is <c>Ei(n cosh(a + b x))/b</c>, as <c>e^(n cos(x)) tan(x)</c> is <c>-Ei(n cos(x))</c>, and was
18+
/// declined, the hyperbolic functions arriving as exponentials. Rubi's 6.7.1.
19+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class ExponentialOfAHyperbolicIntegralTest
23+
{
24+
[Theory]
25+
[InlineData("exp(n*cosh(a + b*x))*tanh(a + b*x)")]
26+
[InlineData("exp(n*sinh(a + b*x))*coth(a + b*x)")]
27+
[InlineData("exp(n*sinh(a + b*x))*sinh(2*(a + b*x))")]
28+
[InlineData("exp(n*cosh(1/2*(a + b*x)))*sinh(a + b*x)")]
29+
[InlineData("exp(n*sinh(a*c + b*c*x))*cosh(c*(a + b*x))")]
30+
public void UnderTwiceTheSineOrCosine(string integrand)
31+
{
32+
var integral = integrand.ToEntity().Integrate("x");
33+
Assert.DoesNotContain("integral(", integral.Stringize());
34+
Assert.DoesNotContain("NaN", integral.Stringize());
35+
Entity Pinned(Entity e) => e.Substitute("a", 0.3).Substitute("b", 0.7).Substitute("c", 1.1).Substitute("n", 0.6);
36+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
37+
var original = Pinned(integrand.ToEntity());
38+
var compared = 0;
39+
foreach (var at in new[] { -1.7, -0.9, 0.3, 0.8, 1.6, 2.9 })
40+
{
41+
var want = original.Substitute("x", at).EvalNumerical();
42+
if (want.IsNaN || Math.Abs((double)want.ImaginaryPart) > 1e-12)
43+
continue;
44+
compared++;
45+
var got = derivative.Substitute("x", at).EvalNumerical();
46+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
47+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart)),
48+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
49+
}
50+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)