Skip to content

Commit fa3eff9

Browse files
Integrate a power of x times an artanh whose derivative is a root, by parts (#1952)
atanh(A x/sqrt(d + B x^2)) with A^2 = B is written ln((1 + u)/(1 - u))/2, whose derivative is A/sqrt(d + B x^2): 1 - u^2 = d/(d + B x^2) and u' = A d/(d + B x^2)^(3/2). So by parts what is left is x^(m + 1)/sqrt(d + B x^2), which the radical rules answer. Differentiated as written, the logarithm was a quotient of two sums with a root in each, and the search on what was left ran past the budget. Rubi's 7.3.7: 13 rows go from unevaluated or timed out to solved (7.3 1752 -> 1765 of 1791), 0 wrong. Families 0 and 1 and samples of 2-8 otherwise identical; gate and suite pass. Part of #233. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 0f0ff07 commit fa3eff9

4 files changed

Lines changed: 138 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ since semantic versioning admits it.
129129
Measured on the suite: **7 of 8,525 tests** referenced the old reading — five boolean-solver inputs
130130
written `A | B`, and two that existed to record this spelling as at risk.
131131

132+
### A power of x times `atanh(sqrt(e) x/sqrt(d + e x^2))` is integrated by parts against the root
133+
134+
**Answers where there were none.** `x atanh(sqrt(e) x/sqrt(d + e x^2))` was declined, and so were twelve more of Rubi's
135+
7.3.7, every power of `x` from `x^6` to `1/x^9` but `1/x`. The logarithm `atanh` is written as has the derivative
136+
`sqrt(e)/sqrt(d + e x^2)`, and by parts what is left is `x^(m + 1)/sqrt(d + e x^2)`; differentiated as written it was a
137+
quotient of two sums with a root in each, which the search never brought down to the root
138+
([#233](https://github.com/asc-community/AngouriMath/issues/233)).
139+
140+
| Input | Was (2.5.0) | Now |
141+
|---|---|---|
142+
| `"atanh(x*sqrt(k)/sqrt(d+k*x^2))".ToEntity().Integrate("x")` | `integral(...)` | `x atanh(...) - sqrt(d + k x^2)/sqrt(k)`, written in the logarithm |
143+
| `"atanh(x*sqrt(k)/sqrt(d+k*x^2))/x^5".ToEntity().Integrate("x")` | `integral(...)` | by parts onto `1/(x^4 sqrt(d + k x^2))` |
144+
132145
### A power of x is taken out of a bracket to find the derivative of a product of powers
133146

134147
**Answers where there were none.** `x^(2n) (c + d x)^n (2 c x + 3 d x^2)`, Rubi's 1.3.1, was declined. A bracket that

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,76 @@ private static bool IsADerivativeOfAFactorBelowTheBar(Entity expr, Entity.Variab
639639
return Integration.ComputeAsTheSameQuestion(written, x, integrateByParts);
640640
}
641641

642+
/// <summary>
643+
/// A power of <c>x</c> times <c>artanh(A x/sqrt(d + B x^2))</c> with <c>A^2 = B</c>, by parts:
644+
/// the logarithm <c>ln((1 + u)/(1 - u))</c> that <c>artanh(u)</c> is written as has the
645+
/// derivative <c>2 u'/(1 - u^2)</c>, and for this <c>u</c>, <c>1 - u^2 = d/(d + B x^2)</c> and
646+
/// <c>u' = A d/(d + B x^2)^(3/2)</c>, so it is <c>2 A/sqrt(d + B x^2)</c>. So
647+
/// <c>integral x^m ln(...) = x^(m + 1)/(m + 1) ln(...) - 2 A/(m + 1) integral x^(m + 1)/sqrt(d + B x^2)</c>,
648+
/// for every whole <c>m</c> but <c>-1</c>. Rubi's 7.3.7, <c>x^m artanh(sqrt(e) x/sqrt(d + e x^2))</c>.
649+
/// https://github.com/asc-community/AngouriMath/issues/233
650+
/// </summary>
651+
/// <remarks>
652+
/// The search takes it by parts too, and differentiates the logarithm as written: a quotient
653+
/// of two sums with a root in each, which it never brought down to the root alone, and the
654+
/// remainder it asked about ran past the budget. The identity is algebraic, with no branch in
655+
/// it: it holds wherever <c>d</c> is not 0 and the root is.
656+
/// </remarks>
657+
internal static Entity? SolveByPartsAgainstAnArtanhWhoseDerivativeIsARoot(Entity expr, Entity.Variable x, bool integrateByParts)
658+
{
659+
Entity constant = Number.Integer.One;
660+
Logf? logarithm = null;
661+
var power = 0;
662+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr))
663+
{
664+
if (!factor.ContainsNode(x))
665+
{
666+
constant = underneath ? constant / factor : constant * factor;
667+
continue;
668+
}
669+
if (!underneath && logarithm is null && factor is Logf ln && ln.Base == MathS.e)
670+
{
671+
logarithm = ln;
672+
continue;
673+
}
674+
if (APowerOfTheVariable(factor, x) is not { } k)
675+
return null;
676+
power += underneath ? -k : k;
677+
}
678+
if (logarithm is null || power == -1 || System.Math.Abs(power) > 24
679+
|| logarithm.Antilogarithm is not Divf(Sumf(var one, var u), Minusf(var alsoOne, var alsoU))
680+
|| one != Number.Integer.One || alsoOne != Number.Integer.One || u != alsoU)
681+
return null;
682+
// u read as A x/sqrt(Q): a constant, x once above the bar, and the root of Q.
683+
Entity slope = Number.Integer.One;
684+
Entity? radicand = null;
685+
var sawX = false;
686+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(u))
687+
{
688+
if (!factor.ContainsNode(x))
689+
slope = underneath ? slope / factor : slope * factor;
690+
else if (factor == x && !underneath && !sawX)
691+
sawX = true;
692+
else if (radicand is null && factor is Powf(var @base, Number.Rational half)
693+
&& (underneath ? half == Number.Rational.Create(1, 2) : half == Number.Rational.Create(-1, 2)))
694+
radicand = @base;
695+
else
696+
return null;
697+
}
698+
if (!sawX || radicand is null
699+
|| !TreeAnalyzer.TryGetPolyQuadratic(radicand, x, out var square, out var linear, out var free)
700+
|| !TreeAnalyzer.IsZero(linear) || TreeAnalyzer.IsZero(free) || !VanishesIdentically(slope * slope - square))
701+
return null;
702+
var raised = power + 1;
703+
var rest = raised == 0 ? 1 / MathS.Sqrt(radicand)
704+
: raised > 0 ? (raised == 1 ? x : MathS.Pow(x, raised)) / MathS.Sqrt(radicand)
705+
: 1 / ((raised == -1 ? x : MathS.Pow(x, -raised)) * MathS.Sqrt(radicand));
706+
if (Integration.ComputeAsAQuestionOfItsOwn(rest, x, integrateByParts) is not { } integral
707+
|| integral.Nodes.Any(node => node is Integralf || node == MathS.NaN))
708+
return null;
709+
return (constant * (MathS.Pow(x, raised) * logarithm - 2 * slope * integral) / raised).InnerSimplified;
710+
}
711+
642712
/// <summary>
643713
/// A quotient by the square of a base, by parts against the base's reciprocal, where the
644714
/// base's derivative makes the rest exact: <c>N/(M v^2)</c> is <c>g v'/v^2</c> with

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,8 @@ private static Entity WithItsPiecewiseSumsCombined(Entity expr)
782782
if ((answer = IndefiniteIntegralSolver.SolveAPowerTimesAnExponentialOfAQuadraticInALogarithm(expr, x)) is { }) return answer;
783783
// And a negative whole power of one, onto the exponential integral by t = A + B ln(c x^r).
784784
if ((answer = IndefiniteIntegralSolver.SolveAPowerOverAPowerOfALogarithm(expr, x)) is { }) return answer;
785+
// And x^m artanh(A x/sqrt(d + A^2 x^2)), by parts, the logarithm's derivative read as the root it is.
786+
if ((answer = IndefiniteIntegralSolver.SolveByPartsAgainstAnArtanhWhoseDerivativeIsARoot(expr, x, integrateByParts)) is { }) return answer;
785787
// A power of an exponential with a positive base is the exponential of the product,
786788
// exactly, and only that spelling is one the exponential rules read.
787789
if ((answer = IndefiniteIntegralSolver.SolveByFlatteningAPowerOfAnExponential(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+
/// <c>x^m artanh(sqrt(k) x/sqrt(d + k x^2))</c>, whose derivative is <c>sqrt(k)/sqrt(d + k x^2)</c>,
16+
/// by parts. Differentiated as written, the logarithm is a quotient of two sums with a root in
17+
/// each, and the search ran past its budget on what was left. Rubi's 7.3.7.
18+
/// <a href="https://github.com/asc-community/AngouriMath/issues/233">#233</a>
19+
/// </summary>
20+
[Trait("Area", "Calculus")]
21+
public sealed class APowerTimesAnArtanhWhoseDerivativeIsARootIntegralTest
22+
{
23+
[Theory]
24+
[InlineData("atanh(x*sqrt(k)/sqrt(d + k*x^2))")]
25+
[InlineData("x*atanh(x*sqrt(k)/sqrt(d + k*x^2))")]
26+
[InlineData("x^4*atanh(x*sqrt(k)/sqrt(d + k*x^2))")]
27+
[InlineData("atanh(x*sqrt(k)/sqrt(d + k*x^2))/x^2")]
28+
[InlineData("atanh(x*sqrt(k)/sqrt(d + k*x^2))/x^5")]
29+
[InlineData("atanh(x/sqrt(1 + x^2))")]
30+
public void ByPartsAgainstTheRoot(string integrand)
31+
{
32+
var integral = integrand.ToEntity().Integrate("x");
33+
var text = integral.Stringize();
34+
Assert.DoesNotContain("integral(", text);
35+
Entity Pinned(Entity e) => e.Substitute("d", 1.3).Substitute("k", 0.7);
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[] { -2.1, -0.4, 0.3, 0.8, 1.3, 2.9 })
40+
{
41+
var want = original.Substitute("x", at).EvalNumerical();
42+
var got = derivative.Substitute("x", at).EvalNumerical();
43+
if (want.IsNaN)
44+
continue;
45+
compared++;
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) + Math.Abs((double)want.ImaginaryPart)),
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)