Skip to content

Commit 71eeb20

Browse files
A hyperbolic function of a logarithm is integrated, the exponent folded structurally (#1470)
`tanh(ln(x))` was left as written. The library spells `tanh(y)` with `e^(2y)`, so a hyperbolic function of a logarithm is an exponential whose exponent is a sum holding one logarithm -- `e^(a + b ln(q))` -- and SolveByFoldingAnExponentialOfALogarithm read only a product, `e^(k ln q)`. It reads the exponent structurally now: `e^(u + v)` is `e^u e^v`, `e^(u - v)` is `e^u/e^v`, `e^(k u)` and `e^(u/d)` are powers of `e^u` for an x-free k and d, and `e^(ln q)` is `q`. So `a + b ln(c x^n)` folds to `e^a (c x^n)^b`, and its negation -- which the same function writes below the bar -- to the reciprocal of that. Two conditions, both measured. Composed exponents are flattened as they fold: `n (ln(q)/2)` is `q^(n/2)` and not `(sqrt(q))^n`, whose nesting made `e^(n acoth(a x))/(c - a^2 c x^2)^4` a search of fifty seconds where the flat form is declined in three. And one logarithm in the exponent: a difference of two -- how the inverse hyperbolic cotangent of a reciprocal arrives -- folds to a power of a quotient of quotients that nothing below reads. Family 6 of the Rubi suite: 375 -> 377 of 417, 0 wrong; family 7 215/270 and the 1774-problem suite 1707 unchanged. Suite 12632 passed; allocation gate passed on all 19 gated benchmarks. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 48d447c commit 71eeb20

3 files changed

Lines changed: 103 additions & 16 deletions

File tree

‎BREAKING-CHANGES.md‎

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

1112+
### A hyperbolic function of a logarithm is integrated, the exponent folded structurally
1113+
1114+
`tanh(ln(x))` was left as written. The library spells `tanh(y)` with `e^(2y)`, so a hyperbolic
1115+
function of a logarithm is an exponential whose exponent is a *sum* holding one logarithm --
1116+
`e^(a + b ln(q))` -- and the rule that folds an exponential of a logarithm read only a product,
1117+
`e^(k ln(q))`. It reads the exponent structurally now: `e^(u + v)` is `e^u e^v`, `e^(k u)` is
1118+
`(e^u)^k` for an `x`-free `k`, `e^(u/d)` likewise, and `e^(ln q)` is `q`, so
1119+
`a + b ln(c x^n)` folds to `e^a (c x^n)^b` and its negation -- which the same function writes
1120+
below the bar -- to the reciprocal. Composed exponents are flattened as they fold: `n (ln(q)/2)`
1121+
is `q^(n/2)` and not `(sqrt(q))^n`, whose nesting made
1122+
`e^(n acoth(a x))/(c - a^2 c x^2)^4` a search of fifty seconds where the flat form is declined in
1123+
three. One logarithm in the exponent, since a difference of two folds to a power of a quotient of
1124+
quotients that nothing below reads. Rubi's 6.3.2 and 6.5.3
1125+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
1126+
1127+
| Input | Was (2.5.0) | Now |
1128+
|---|---|---|
1129+
| `"tanh(ln(x))".Integrate("x")` | left unevaluated | `x - 2 arctan(x)` up to the form |
1130+
| `"sinh(2+3*ln(x))".Integrate("x")` | left unevaluated | `e^2 x^4/8 - x^(-2)/(4 e^2)` up to the form |
1131+
| `"sech(a+2*ln(c/x^(1/2)))^3".Integrate("x")` | left unevaluated | the antiderivative |
1132+
| `"x*tanh(a+2*ln(x))^2".Integrate("x")` | left unevaluated | the antiderivative |
1133+
11121134
### `binomial(n, k)` is a function
11131135

11141136
**Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled

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

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9877,27 +9877,78 @@ node is Powf(Powf(var @base, var inner), var outer)
98779877
{
98789878
if (node is not Powf(var @base, var exponent) || @base != MathS.e || !exponent.ContainsNode(x))
98799879
return node;
9880-
// The exponent as a product with one natural logarithm of x among its factors
9881-
// and nothing else of x: `3 * (1/2 * ln(q))` is how `e^(3 acoth(a x))` arrives.
9882-
Entity? argument = null;
9883-
Entity k = Number.Integer.One;
9884-
foreach (var factor in Mulf.LinearChildren(exponent))
9885-
{
9886-
if (factor is Logf(var logBase, var inner) && logBase == MathS.e && argument is null)
9887-
argument = inner;
9888-
else if (factor.ContainsNode(x))
9889-
return node;
9890-
else
9891-
k = k * factor;
9892-
}
9893-
if (argument is null)
9880+
// The exponent read structurally, since `e^(u + v)` is `e^u e^v`, `e^(k u)` is
9881+
// `(e^u)^k` and `e^(ln q)` is `q`: `a + b ln(c x^n)` -- a hyperbolic function of
9882+
// a logarithm -- folds to `e^a (c x^n)^b`, and its negation, which the same
9883+
// function writes below the bar, to the reciprocal of that.
9884+
// One logarithm in the exponent: `a + b ln(c x^n)` is a hyperbolic function of
9885+
// a logarithm, and `n acoth(a x)` written as a difference of two -- which folds
9886+
// to a power of a quotient of quotients -- was a search of fifty seconds where
9887+
// the unfolded form is declined in three.
9888+
if (exponent.Nodes.Count(inner => inner is Logf(var logBase, _) && logBase == MathS.e) != 1)
98949889
return node;
9895-
var power = k.InnerSimplified;
9896-
return power == Number.Integer.One ? argument : MathS.Pow(argument, power);
9890+
var folded = FoldTheExponent(exponent, x);
9891+
return folded ?? node;
98979892
});
98989893
return folded == expr ? null : Integration.ComputeAsAQuestionOfItsOwn(folded, x, integrateByParts);
98999894
}
99009895

9896+
/// <summary>
9897+
/// <c>e^(exponent)</c> written without the exponential wherever the exponent is built
9898+
/// from logarithms and constants: <c>e^(u + v)</c> is <c>e^u e^v</c>, <c>e^(k u)</c> is
9899+
/// <c>(e^u)^k</c> for an <paramref name="x"/>-free <c>k</c>, and <c>e^(ln q)</c> is
9900+
/// <c>q</c>. <see langword="null"/> where a part mentioning <paramref name="x"/> is
9901+
/// none of those, and where no logarithm was folded at all.
9902+
/// </summary>
9903+
private static Entity? FoldTheExponent(Entity exponent, Entity.Variable x)
9904+
{
9905+
var folded = Fold(exponent, out var found);
9906+
return found ? folded : null;
9907+
9908+
Entity? Fold(Entity exponent, out bool found)
9909+
{
9910+
found = false;
9911+
switch (exponent)
9912+
{
9913+
case Logf(var logBase, var inner) when logBase == MathS.e:
9914+
found = true;
9915+
return inner;
9916+
case Sumf(var left, var right):
9917+
{
9918+
var foldedLeft = Fold(left, out var leftFound);
9919+
var foldedRight = Fold(right, out var rightFound);
9920+
found = leftFound || rightFound;
9921+
return foldedLeft is null || foldedRight is null ? null : foldedLeft * foldedRight;
9922+
}
9923+
case Minusf(var left, var right):
9924+
{
9925+
var foldedLeft = Fold(left, out var leftFound);
9926+
var foldedRight = Fold(right, out var rightFound);
9927+
found = leftFound || rightFound;
9928+
return foldedLeft is null || foldedRight is null ? null : foldedLeft / foldedRight;
9929+
}
9930+
case Mulf(var left, var right) when !left.ContainsNode(x):
9931+
return Raised(Fold(right, out found), left);
9932+
case Mulf(var left, var right) when !right.ContainsNode(x):
9933+
return Raised(Fold(left, out found), right);
9934+
case Divf(var above, var below) when !below.ContainsNode(x):
9935+
return Raised(Fold(above, out found), (Number.Integer.One / below).InnerSimplified);
9936+
default:
9937+
// A part free of the variable stays an exponential of itself.
9938+
return exponent.ContainsNode(x) ? null : MathS.Pow(MathS.e, exponent);
9939+
}
9940+
}
9941+
9942+
// The power of a power as one power: `n (1/2 ln q)` is `q^(n/2)` and not
9943+
// `(sqrt(q))^n`, whose nesting the rules below read as a different question --
9944+
// `e^(n acoth(a x))/(c - a^2 c x^2)^4` was a search of fifty seconds written that
9945+
// way and is declined in three written flat.
9946+
static Entity? Raised(Entity? folded, Entity power)
9947+
=> folded is null ? null
9948+
: folded is Powf(var @base, var inner) ? MathS.Pow(@base, (inner * power).InnerSimplified)
9949+
: MathS.Pow(folded, power);
9950+
}
9951+
99019952
/// <summary>
99029953
/// A logarithm whose argument is a quotient in <paramref name="x"/> that cancels with
99039954
/// the functions of <paramref name="x"/> in it taken for indeterminates, with the

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,19 @@ private static void DifferentiatesBack(string integrand)
7676
[InlineData("e^(ln(x^2 + 1)/2) * x")]
7777
[InlineData("e^(2*(1/2*ln(x + 2)))")]
7878
public void AnExponentialOfAMultipleOfALogarithm(string integrand) => DifferentiatesBack(integrand);
79+
80+
/// <summary>
81+
/// The exponent read structurally, since <c>e^(u + v)</c> is <c>e^u e^v</c> and
82+
/// <c>e^(k u)</c> is <c>(e^u)^k</c>: a hyperbolic function of a logarithm is written
83+
/// with <c>e^(a + b ln(q))</c> above the bar and <c>e^(-(a + b ln(q)))</c> below it,
84+
/// and both are powers of <c>q</c> times a constant. Rubi's 6.5.3 and 6.6.3.
85+
/// </summary>
86+
[Theory]
87+
[InlineData("sinh(2 + 3*ln(x))")]
88+
[InlineData("cosh(1 + ln(x^2 + 1))")]
89+
[InlineData("sech(3 + 2*ln(2/x^(1/2)))^3")]
90+
[InlineData("e^(1 + ln(x + 2)/2)")]
91+
[InlineData("tanh(ln(x))")]
92+
public void AHyperbolicFunctionOfALogarithm(string integrand) => DifferentiatesBack(integrand);
7993
}
8094
}

0 commit comments

Comments
 (0)