Skip to content

Commit 2476fae

Browse files
The inverse hyperbolic substitution reads the secant and the cosecant (#1571)
`arsech(L)` and `arcsch(L)` are written `ln(1/L + sqrt(1/L^2 - 1))` and `ln(1/L + sqrt(1/L^2 + 1))`, the `arcosh` and `arsinh` of `1/L`, and the substitution that undoes an inverse hyperbolic function read the other three and not these two. Under `L = sech(u)` and `L = csch(u)` the logarithm is `u` and `dL` is `-sinh(u)/cosh(u)^2` or `-cosh(u)/sinh(u)^2`, so `1/(x^2 (a + b arcsch(c x)))` is `-c cosh(u)/(a + b u)`, which the hyperbolic sine and cosine integrals answer. The way back writes `e^u` as `1/L + sqrt(1/L^2 - 1)` and `1/L + sqrt(1/L^2 + 1)`. The root of `1 - L^2` beside the secant is `tanh(u)`, the principal `arsech` being non-negative; the cosecant takes either sign, and the root of `1 + L^2` is not removed. The two are taken only for `x^m` beside a function of the inverse, `m <= -2`, and the argument `c x`: there the integrand in u is a polynomial in `e^u` and `e^(-u)` over at most a power of a linear, which the rules for exponentials close. A power of x above the bar is a power of `cosh(u)` below it, and by parts in x answers those. Rubi's 7.5.1, 7.5.2 and 7.6.1 in full: 222 -> 255 of 272, 0 wrong, none lost, timeouts 30 -> 15, 282 s -> 221 s. With the artanh change beside it, the families sample 764 -> 766 of 912 and family 0 1750 of 1814 row for row. The unit tests pass (net10.0), every target builds, and the allocation gate passes. Part of #1501. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a8a2b7e commit 2476fae

3 files changed

Lines changed: 145 additions & 8 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,23 @@ below are one indeterminate. Rubi's 7.5.1 and 7.6.1
991991
| `"x * acsch(c * x)".ToEntity().Integrate("x")` | `integral(x * ln(1 / (c * x) + sqrt(1 / (c * x) ^ 2 + 1)), x)` | an antiderivative, `provided c^2 > 0` |
992992
| `"x^2 * asech(c * x)".ToEntity().Integrate("x")` | `integral(...)`, the same | an antiderivative |
993993
| `"x / sqrt(1 + 1/(c*x)^2)".ToEntity().Integrate("x")` | `integral(x / sqrt(1 + 1 / (c * x) ^ 2), x)` | an antiderivative, `provided c^2 > 0` |
994+
995+
### `arsech` and `arcsch` below the bar are integrated
996+
997+
`1/(x^2 (a + b arcsch(c x)))` and `1/(x^4 (a + b arsech(c x)))` were left unevaluated. The
998+
substitution that undoes an inverse hyperbolic function read `arsinh`, `arcosh` and `artanh` off
999+
their logarithms and not these two, which are the `arsinh` and the `arcosh` of `1/L`. Under
1000+
`L = csch(u)` or `L = sech(u)` a power of `x` below the bar is a polynomial in `cosh(u)` and
1001+
`sinh(u)` over a power of `a + b u`, which the hyperbolic sine and cosine integrals and `Ei`
1002+
answer. Rubi's 7.5.1, 7.5.2 and 7.6.1
1003+
([#1501](https://github.com/asc-community/AngouriMath/issues/1501)).
1004+
1005+
| Input | Was (2.5.0) | Now |
1006+
|---|---|---|
1007+
| `"1/(x^2*(a+b*acsch(c*x)))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in `Ei` |
1008+
| `"1/(x^4*(a+b*asech(c*x)))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in `Chi` and `Shi` |
1009+
| `"1/(e^asech(a*x)*x^5)".ToEntity().Integrate("x")` | `integral(...)` | a polynomial in `1/(a x) - sqrt(1/(a x)^2 - 1)` and its reciprocal |
1010+
9941011
### `n in ZZ and 2^n > n^2` is solved to a set, and was a refusal
9951012

9961013
An inequality with an exponential or a factorial over the whole numbers is solved to the members

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

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5699,14 +5699,19 @@ node is Powf(var q, Number.Rational r) && r is not Number.Integer && q != first
56995699
/// <c>x</c> left the logarithm's derivative as a quotient of radicals.
57005700
/// The way back writes <c>e^u</c> as <c>L + sqrt(L^2 + 1)</c> and <c>e^(-u)</c> as
57015701
/// <c>sqrt(L^2 + 1) - L</c>, on the principal branch.
5702+
/// <c>arsech(L)</c> and <c>arcsch(L)</c> are the <c>arcosh</c> and <c>arsinh</c> of
5703+
/// <c>1/L</c>, and so <c>u</c> under <c>L = sech(u)</c> and <c>L = csch(u)</c>, with
5704+
/// <c>e^u</c> as <c>1/L + sqrt(1/L^2 - 1)</c> and <c>1/L + sqrt(1/L^2 + 1)</c>: Rubi's
5705+
/// <c>1/(x^2 (a + b arcsch(c x)))</c> is <c>-c cosh(u)/(a + b u)</c>, which the
5706+
/// hyperbolic sine and cosine integrals answer.
57025707
/// https://github.com/asc-community/AngouriMath/issues/718
57035708
/// </summary>
57045709
internal static Entity? SolveByInverseHyperbolicSubstitution(Entity expr, Entity.Variable x, bool integrateByParts)
57055710
{
57065711
// The one inverse hyperbolic function in the integrand, read off its logarithm.
57075712
Entity? inverse = null;
57085713
Entity? argument = null;
5709-
var kind = 0; // 1 sinh, 2 cosh, 3 tanh
5714+
var kind = 0; // 1 sinh, 2 cosh, 3 tanh, 4 sech, 5 csch
57105715
foreach (var node in expr.Nodes)
57115716
{
57125717
if (node is not Logf(var @base, var antilogarithm) || @base != MathS.e || !antilogarithm.ContainsNode(x))
@@ -5723,14 +5728,25 @@ node is Powf(var q, Number.Rational r) && r is not Number.Integer && q != first
57235728
if (!TreeAnalyzer.TryGetPolyLinear(argument, x, out var slope, out var offset) || slope is null || offset is null
57245729
|| TreeAnalyzer.IsZero(slope) || slope.Evaled is Number.Complex { IsZero: true })
57255730
return null;
5731+
// The secant's and the cosecant's are taken only where they land on what the rules for
5732+
// exponentials close: `x^m` beside a function of the inverse alone, `m <= -2`, and the
5733+
// argument `c x`. Under `x = sech(u)/c` that is `cosh(u)^(-m - 2) sinh(u)` times the
5734+
// function of u, a polynomial in `e^u` and `e^(-u)` -- `1/(x^2 (a + b arcsch(c x)))` is
5735+
// `-c cosh(u)/(a + b u)` -- where a power of x above the bar is a power of `cosh(u)` below
5736+
// it: `x^3 arsech(a x)^2` is `u^2 sinh(u)/cosh(u)^5` over `-a^4`. By parts in x answers
5737+
// such integrands in a fraction of a second, where the searches in u held their test
5738+
// past five minutes.
5739+
if (kind >= 4 && (!TreeAnalyzer.IsZero(offset) || APowerOfXBesideAFunctionOfTheInverse(expr, inverse, x) is not { } degree || degree > -2))
5740+
return null;
57265741
// The tangent's logarithm carries a half in front: `ln((1 + L)/(1 - L))/2` is u, and
57275742
// the logarithm alone is 2u.
57285743
var u = Variable.CreateUnique(expr, "u_inv");
57295744
var expU = MathS.Pow(MathS.e, u);
57305745
var expMinusU = MathS.Pow(MathS.e, -u);
57315746
var sinh = (expU - expMinusU) / 2;
57325747
var cosh = (expU + expMinusU) / 2;
5733-
Entity argumentInU, dArgument, radicandBase, root;
5748+
Entity argumentInU, dArgument;
5749+
Entity? radicandBase, root;
57345750
switch (kind)
57355751
{
57365752
case 1:
@@ -5739,9 +5755,18 @@ node is Powf(var q, Number.Rational r) && r is not Number.Integer && q != first
57395755
case 2:
57405756
(argumentInU, dArgument, radicandBase, root) = (cosh, sinh, MathS.Sqr(argument) - 1, sinh);
57415757
break;
5742-
default:
5758+
case 3:
57435759
(argumentInU, dArgument, radicandBase, root) = (sinh / cosh, 1 / MathS.Sqr(cosh), 1 - MathS.Sqr(argument), 1 / cosh);
57445760
break;
5761+
// The principal arsech is not negative, so the root of `1 - sech(u)^2` is
5762+
// `tanh(u)`; the arcsch takes either sign, and the root of `1 + csch(u)^2` is
5763+
// `|coth(u)|`, which is no radical this route removes.
5764+
case 4:
5765+
(argumentInU, dArgument, radicandBase, root) = (1 / cosh, -sinh / MathS.Sqr(cosh), 1 - MathS.Sqr(argument), sinh / cosh);
5766+
break;
5767+
default:
5768+
(argumentInU, dArgument, radicandBase, root) = (1 / sinh, -cosh / MathS.Sqr(sinh), (Entity?)null, (Entity?)null);
5769+
break;
57455770
}
57465771
var logarithmInU = kind == 3 ? 2 * u : u;
57475772

@@ -5750,6 +5775,8 @@ node is Powf(var q, Number.Rational r) && r is not Number.Integer && q != first
57505775
.Substitute(inverse, logarithmInU)
57515776
.Replace(node =>
57525777
{
5778+
if (radicandBase is null || root is null)
5779+
return node;
57535780
if (node is Powf(var wholeBase, Number.Integer whole) && whole.EInteger.CompareTo(EInteger.FromInt32(2)) >= 0
57545781
&& whole.EInteger.CompareTo(EInteger.FromInt32(64)) <= 0 && wholeBase.ContainsNode(x)
57555782
&& TreeAnalyzer.TryGetPolyQuadratic(wholeBase, x, out _, out _, out _)
@@ -5820,6 +5847,12 @@ node is Powf(var @base, Number.Rational power) && power is not Number.Integer &&
58205847
case 2:
58215848
(plus, minus) = (argument + MathS.Sqrt(MathS.Sqr(argument) - 1), argument - MathS.Sqrt(MathS.Sqr(argument) - 1));
58225849
break;
5850+
case 4:
5851+
(plus, minus) = (1 / argument + MathS.Sqrt(1 / MathS.Sqr(argument) - 1), 1 / argument - MathS.Sqrt(1 / MathS.Sqr(argument) - 1));
5852+
break;
5853+
case 5:
5854+
(plus, minus) = (1 / argument + MathS.Sqrt(1 / MathS.Sqr(argument) + 1), MathS.Sqrt(1 / MathS.Sqr(argument) + 1) - 1 / argument);
5855+
break;
58235856
default:
58245857
// e^(-u) as the reciprocal, not as the root of the reciprocal: off the real
58255858
// domain the principal roots of a quotient and of its reciprocal are not
@@ -5849,6 +5882,8 @@ node is Powf(var @base, Number.Rational power) && power is not Number.Integer &&
58495882
{
58505883
2 => new[] { "1.43", "3.17", "2.2", "5.1" },
58515884
3 => new[] { "0.29", "-0.61", "0.13", "-0.4" },
5885+
// Inside (0, 1] for a slope up to about four, where the principal arsech is real.
5886+
4 => new[] { "0.07", "0.11", "0.19", "0.23" },
58525887
_ => null,
58535888
};
58545889
var derivative = back.Differentiate(x);
@@ -5860,10 +5895,51 @@ node is Powf(var @base, Number.Rational power) && power is not Number.Integer &&
58605895
}
58615896

58625897
/// <summary>
5863-
/// The argument and the kind (1 <c>arsinh</c>, 2 <c>arcosh</c>, 3 <c>artanh</c>) of the
5864-
/// inverse hyperbolic function whose logarithm has <paramref name="antilogarithm"/>
5865-
/// as its argument -- <c>L + sqrt(L^2 + 1)</c>, <c>L + sqrt(L^2 - 1)</c> or
5866-
/// <c>(1 + L)/(1 - L)</c> for a linear <c>L</c> -- else null.
5898+
/// The <c>m</c> for which <paramref name="expr"/> is <c>x^m</c> times a function of
5899+
/// <paramref name="inverse"/> alone, else null: with the inverse written as a symbol, such an
5900+
/// integrand at <c>2x</c> is <c>2^m</c> times itself wherever it is evaluated, and two points
5901+
/// with every other symbol pinned say whether it is.
5902+
/// </summary>
5903+
private static int? APowerOfXBesideAFunctionOfTheInverse(Entity expr, Entity inverse, Entity.Variable x)
5904+
{
5905+
var w = Variable.CreateUnique(expr, "w_inv");
5906+
var inW = expr.Substitute(inverse, w);
5907+
if (!inW.ContainsNode(x))
5908+
return 0;
5909+
using var _ = MathS.Settings.DowncastingEnabled.Set(false);
5910+
var pins = new[] { "0.61", "1.37", "2.23", "0.83", "1.91" };
5911+
var index = 0;
5912+
foreach (var symbol in inW.Vars.Where(symbol => symbol != x).ToList())
5913+
inW = inW.Substitute(symbol, Number.Real.Create(EDecimal.FromString(pins[index++ % pins.Length])));
5914+
double? RatioAt(string at)
5915+
{
5916+
var point = EDecimal.FromString(at);
5917+
if (inW.Substitute(x, Number.Real.Create(point.Multiply(2))).Evaled is not Number.Complex doubled
5918+
|| inW.Substitute(x, Number.Real.Create(point)).Evaled is not Number.Complex single
5919+
|| single.IsZero || doubled.IsNaN || single.IsNaN)
5920+
return null;
5921+
// Read by its parts, since with the downcasting off a quotient on the real line is
5922+
// still a Complex.
5923+
var ratio = doubled / single;
5924+
var real = ratio.RealPart.EDecimal;
5925+
return real.IsFinite && real.Sign > 0 && ratio.ImaginaryPart.EDecimal.Abs().CompareTo(real.Multiply(EDecimal.FromString("1e-30"))) <= 0
5926+
? real.ToDouble() : null;
5927+
}
5928+
if (RatioAt("0.37") is not { } first || RatioAt("0.53") is not { } second)
5929+
return null;
5930+
var degree = System.Math.Log(first, 2);
5931+
var rounded = System.Math.Round(degree);
5932+
if (System.Math.Abs(degree - rounded) > 1e-9 || System.Math.Abs(System.Math.Log(second, 2) - rounded) > 1e-9)
5933+
return null;
5934+
return (int)rounded;
5935+
}
5936+
5937+
/// <summary>
5938+
/// The argument and the kind (1 <c>arsinh</c>, 2 <c>arcosh</c>, 3 <c>artanh</c>,
5939+
/// 4 <c>arsech</c>, 5 <c>arcsch</c>) of the inverse hyperbolic function whose logarithm
5940+
/// has <paramref name="antilogarithm"/> as its argument -- <c>L + sqrt(L^2 + 1)</c>,
5941+
/// <c>L + sqrt(L^2 - 1)</c>, <c>(1 + L)/(1 - L)</c>, <c>1/L + sqrt(1/L^2 - 1)</c> or
5942+
/// <c>1/L + sqrt(1/L^2 + 1)</c> for a linear <c>L</c> -- else null.
58675943
/// </summary>
58685944
private static (Entity Argument, int Kind)? ReadAnInverseHyperbolic(Entity antilogarithm, Entity.Variable x)
58695945
{
@@ -5880,6 +5956,28 @@ private static (Entity Argument, int Kind)? ReadAnInverseHyperbolic(Entity antil
58805956
if (IsTheSameQuadraticOnceSimplified(radicand, MathS.Sqr(linear) - 1, x))
58815957
return (linear, 2);
58825958
}
5959+
// The secant's and the cosecant's are the cosine's and the sine's of the
5960+
// reciprocal: `arsech(L)` is `ln(1/L + sqrt(1/L^2 - 1))` and `arcsch(L)` is
5961+
// `ln(1/L + sqrt(1/L^2 + 1))`.
5962+
foreach (var (reciprocal, radical) in new[] { (left, right), (right, left) })
5963+
{
5964+
if (!TryReadAHalfPower(radical, out var radicand, out var numeratorOfHalf) || numeratorOfHalf != 1 || !reciprocal.ContainsNode(x))
5965+
continue;
5966+
// Read off the bar where it is written as one, since the simplification leaves
5967+
// `1/(1/(c x))` as it is, and the answer would carry it.
5968+
var linear = reciprocal switch
5969+
{
5970+
Divf(var one, var denominator) when one == Number.Integer.One => denominator,
5971+
Powf(var @base, Number.Integer minusOne) when minusOne == Number.Integer.MinusOne => @base,
5972+
_ => (1 / reciprocal).InnerSimplified,
5973+
};
5974+
if (!TreeAnalyzer.TryGetPolyLinear(linear, x, out var slope, out _) || slope is null || TreeAnalyzer.IsZero(slope))
5975+
continue;
5976+
if (VanishesOnceSimplified(radicand - (1 / MathS.Sqr(linear) - 1)))
5977+
return (linear, 4);
5978+
if (VanishesOnceSimplified(radicand - (1 / MathS.Sqr(linear) + 1)))
5979+
return (linear, 5);
5980+
}
58835981
return null;
58845982
}
58855983
if (antilogarithm is Divf(var above, var below)

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,29 @@ private static void DifferentiatesBack(string integrand)
8181
[InlineData("asech(a*x)^3/x^2")]
8282
[InlineData("(a+b*asech(c*x))^2/x^4")]
8383
[InlineData("x^3*(a+b*acsch(c*x))^2")]
84-
public void ARationalFunctionWithSymbolicCoefficientsBesideTheSecant(string integrand)
84+
public void ARationalFunctionWithSymbolicCoefficientsBesideTheSecant(string integrand) => DifferentiatesBackPinned(integrand);
85+
86+
/// <summary>
87+
/// Rubi's 7.5.1 and 7.6.1 with the inverse below the bar. Under <c>c x = csch(u)</c>,
88+
/// <c>1/(x^2 (a + b acsch(c x)))</c> is <c>-c cosh(u)/(a + b u)</c>, which the hyperbolic
89+
/// sine and cosine integrals answer, and under <c>c x = sech(u)</c> the secant's are
90+
/// the same; the substitution that undoes an inverse hyperbolic function read the
91+
/// logarithms of the other three and not of these two. An exponential of one below the
92+
/// bar is a polynomial in <c>e^u</c> under the same substitution.
93+
/// </summary>
94+
[Theory]
95+
[InlineData("1/(x^4*(a+b*asech(c*x)))")]
96+
[InlineData("1/(x^2*(a+b*acsch(c*x)))")]
97+
[InlineData("1/(x^2*asech(c*x))")]
98+
[InlineData("1/(x^2*acsch(c*x))")]
99+
[InlineData("1/(x^2*(a+b*asech(c*x))^2)")]
100+
[InlineData("1/(x^3*(a+b*acsch(c*x))^2)")]
101+
[InlineData("1/(x^4*(a+b*asech(c*x))^3)")]
102+
[InlineData("1/(e^asech(a*x)*x^5)")]
103+
public void AnInverseHyperbolicSecantOrCosecantBelowTheBar(string integrand) => DifferentiatesBackPinned(integrand);
104+
105+
/// <summary>Pinned with <c>a = 1/3</c>, <c>b = 1/2</c>, <c>c = 3/2</c>, <c>d = 2/3</c>, <c>e = 5/4</c>.</summary>
106+
private static void DifferentiatesBackPinned(string integrand)
85107
{
86108
var integral = integrand.ToEntity().Integrate("x");
87109
Assert.DoesNotContain("integral(", integral.Stringize());

0 commit comments

Comments
 (0)