Skip to content

Commit 1ea1f8a

Browse files
A power of a + i a csch is integrated in the exponential (#1823)
In w = e^y the sum is a (w + i)^2/(w^2 - 1), so a power of it not whole is a^p (w + i)^(2p) (w^2 - 1)^(-p) times a constant on every interval where both are continuous. 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 d8dff2a commit 1ea1f8a

4 files changed

Lines changed: 132 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,21 @@ nested integrals cost twice as much per level
237237
| `new Integralf("t + a".ToEntity(), "t", (0, 1)).Substitute("a", "t")` | `integral(t + t, t, 0, 1)` | `integral(t_1 + t, t_1, 0, 1)` |
238238
| `new Summationf("k * a".ToEntity(), "k", 1, 3).Substitute("a", "k")` | `sum(k * k, k, 1, 3)`, 14 | `sum(k_1 * k, k_1, 1, 3)`, `6 k` |
239239

240+
### A power of `a + i a csch` is integrated in the exponential
241+
242+
**Answers where there were none.** `sqrt(a + i a csch(c + d x))` was declined, with the rest of Rubi's
243+
6.6.3 that is a power of the sum not whole. In `w = e^(c + d x)` the sum is `a (w + i)^2/(w^2 - 1)`, the
244+
square of a complex function over a real one, so its power is `a^p (w + i)^(2p) (w^2 - 1)^(-p)` times a
245+
constant on every interval where both are continuous, and the integrand in `w` is answered at once. The
246+
constant is not written: the answer is the integrand times the antiderivative in `w` over what that
247+
differentiates back to ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
248+
249+
| Input | Was (2.5.0) | Now |
250+
|---|---|---|
251+
| `"sqrt(a + i*a*csch(c + d*x))".ToEntity().Integrate("x")` | `integral(...)` | 454 characters |
252+
| `"(a + i*a*csch(c + d*x))^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | 834 characters |
253+
| `"1/sqrt(a - i*a*csch(c + d*x))".ToEntity().Integrate("x")` | `integral(...)` | 575 characters |
254+
240255
### A power of a constant below `1e-50` is no longer simplified to zero
241256

242257
**Answers that were wrong.** Evaluation rounds a value within `1e-50` of an integer onto it, and

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24709,6 +24709,70 @@ private static (Entity OverTheTwo, Entity Argument)? ReadTheHyperbolicFunctions(
2470924709
return constant * result;
2471024710
}
2471124711

24712+
/// <summary>
24713+
/// A power of <c>a ± i a csch(y)</c>, not whole, integrated in <c>w = e^y</c>: there
24714+
/// <c>csch(y)</c> is <c>2 w/(w^2 - 1)</c> and the sum is <c>a (w ± i)^2/(w^2 - 1)</c>, so its power is
24715+
/// <c>a^p (w ± i)^(2p) (w^2 - 1)^(-p)</c> times a constant on every interval where both are
24716+
/// continuous, and <c>dy = dw/w</c>.
24717+
/// </summary>
24718+
/// <remarks>
24719+
/// Rubi's <c>sqrt(a + i a csch(c + d x))</c> and the rest of 6.6.3's were declined: the sum is
24720+
/// the square of a complex function over a real one, which nothing read. The constant is not
24721+
/// written: the answer is the integrand times the antiderivative in <c>w</c> over what that
24722+
/// antiderivative differentiates back to, a quotient constant wherever it is continuous; and it
24723+
/// is kept only where its derivative is the integrand at the sampled points.
24724+
/// https://github.com/asc-community/AngouriMath/issues/718
24725+
/// </remarks>
24726+
internal static Entity? SolveAPowerOfAnImaginaryHyperbolicCosecantSumInTheExponential(Entity expr, Entity.Variable x, bool integrateByParts)
24727+
{
24728+
var s = Variable.CreateUnique(expr, "s_hyp");
24729+
var c = Variable.CreateUnique(expr, "c_hyp");
24730+
if (ReadTheHyperbolicFunctions(expr, x, s, c) is not var (read, argument)
24731+
|| read.ContainsNode(c) || read.ContainsNode(x)
24732+
|| !TreeAnalyzer.TryGetPolyLinear(argument, x, out var slope, out _) || TreeAnalyzer.IsZero(slope))
24733+
return null;
24734+
Entity? radicand = null;
24735+
Number.Rational? power = null;
24736+
Entity constant = Number.Integer.One;
24737+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(read))
24738+
{
24739+
if (!factor.ContainsNode(s))
24740+
{
24741+
constant = underneath ? constant / factor : constant * factor;
24742+
continue;
24743+
}
24744+
if (radicand is not null || factor is not Powf(var @base, Number.Rational exponent) || exponent is Number.Integer)
24745+
return null;
24746+
(radicand, power) = (@base, underneath ? Number.Rational.Create(exponent.ERational.Negate()) : exponent);
24747+
}
24748+
if (radicand is null || power is null || !radicand.Nodes.Any(node => node is Divf(_, var below) && below == s || node is Powf(var b, Number.Integer { EInteger.Sign: < 0 }) && b == s))
24749+
return null;
24750+
// In w: s = (w - 1/w)/2, and the sum as one quotient.
24751+
var w = Variable.CreateUnique(expr, "w_exp");
24752+
var (top, bottom) = Functions.SingleQuotient.Of(Functions.SingleQuotient.Combine(radicand.Substitute(s, (w - 1 / w) / 2)));
24753+
foreach (var sign in new[] { MathS.i, -MathS.i })
24754+
{
24755+
var square = MathS.Sqr(w + sign);
24756+
// Bare: the quotient simplifies to `a provided not w + i = 0`, a condition on w beside a constant.
24757+
var q = Functions.PartialFractions.Bare((top / square).Simplify());
24758+
if (q.ContainsNode(w))
24759+
continue;
24760+
var twice = Number.Rational.Create(power.ERational.Multiply(ERational.FromInt32(2)));
24761+
var inW = (constant * MathS.Pow(q, power) * MathS.Pow(w + sign, twice) * MathS.Pow(bottom, Number.Rational.Create(power.ERational.Negate())) / (slope * w)).InnerSimplified;
24762+
if (Integration.ComputeAsAQuestionOfItsOwn(inW, w, integrateByParts) is not { } inTermsOfW
24763+
|| inTermsOfW.Nodes.Any(node => node == MathS.NaN))
24764+
return null;
24765+
// Checked in w, where the antiderivative is of the integrand as written: in x, with the
24766+
// slope a symbol pinned at a sample, e^(c + d x) at the sampled points was past what the
24767+
// evaluation decides.
24768+
if (!Functions.PartialFractions.HoldsAtSampledPoints(inTermsOfW.Differentiate(w), inW, w))
24769+
return null;
24770+
var exponential = MathS.Pow(MathS.e, argument);
24771+
return expr * inTermsOfW.Substitute(w, exponential) / (inW.Substitute(w, exponential) * slope * exponential);
24772+
}
24773+
return null;
24774+
}
24775+
2471224776
/// <summary>
2471324777
/// <paramref name="radicand"/> read as <c>a (1 ± i s)</c> for the hyperbolic sine
2471424778
/// <paramref name="sine"/>: the constant <c>a</c>, and whether the imaginary unit comes

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,8 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
909909
if ((answer = IndefiniteIntegralSolver.SolveByTheHalfAngleWhereOnePlusAHyperbolicCosineIsASquare(expr, x, integrateByParts)) is { }) return answer;
910910
// The hyperbolic sine's, off the real line: 1 + i sinh(y) is (cosh(y/2) + i sinh(y/2))^2.
911911
if ((answer = IndefiniteIntegralSolver.SolveAHalfOddPowerOfOnePlusAnImaginaryHyperbolicSine(expr, x, integrateByParts)) is { }) return answer;
912+
// And the cosecant's: a ± i a csch(y) is a (w ± i)^2/(w^2 - 1) in w = e^y.
913+
if ((answer = IndefiniteIntegralSolver.SolveAPowerOfAnImaginaryHyperbolicCosecantSumInTheExponential(expr, x, integrateByParts)) is { }) return answer;
912914
// A quotient of linears as a function's argument, written over its denominator: a
913915
// constant plus a multiple of the reciprocal of a linear, which the rules read.
914916
if ((answer = IndefiniteIntegralSolver.SolveByWritingAQuotientOfLinearsOverItsDenominator(expr, x, integrateByParts)) is { }) return answer;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
/// A power of <c>a ± i a csch(c + d x)</c>, not whole, integrated in <c>w = e^(c + d x)</c>, where the sum
16+
/// is <c>a (w ± i)^2/(w^2 - 1)</c>. Rubi's 6.6.3. The integrands are complex for a real <c>x</c> and are
17+
/// compared as complex numbers, on both signs of the argument.
18+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
19+
/// </summary>
20+
[Trait("Area", "Calculus")]
21+
public sealed class APowerOfAnImaginaryHyperbolicCosecantSumIntegralTest
22+
{
23+
[Theory]
24+
[InlineData("sqrt(a + i*a*csch(c + d*x))")]
25+
[InlineData("(a + i*a*csch(c + d*x))^(3/2)")]
26+
[InlineData("1/sqrt(a - i*a*csch(c + d*x))")]
27+
public void InTheExponential(string integrand)
28+
{
29+
var integral = integrand.ToEntity().Integrate("x");
30+
var text = integral.Stringize();
31+
Assert.DoesNotContain("integral(", text);
32+
Assert.True(text.Length < 5000, $"{text.Length} characters of answer for {integrand}");
33+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("c", 0.4).Substitute("d", 1.1);
34+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
35+
var original = Pinned(integrand.ToEntity());
36+
var compared = 0;
37+
foreach (var at in new[] { -1.2, -0.7, 0.3, 0.8, 1.3, 2.9 })
38+
{
39+
var want = original.Substitute("x", at).EvalNumerical();
40+
var got = derivative.Substitute("x", at).EvalNumerical();
41+
if (want.IsNaN)
42+
continue;
43+
compared++;
44+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
45+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
46+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
47+
}
48+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)