Skip to content

Commit 2bb6031

Browse files
The sine and cosine integrals are reached through an inverse trigonometric function (#1536)
`1/arcsin(x)` was left unintegrated. Under `x = sin(u)`, `x^m/(a + b arcsin(c x))^n` is a polynomial in the sine and the cosine over a power of `a + b u`, which the sine and cosine integrals answer. A rule before the general substitution search, which does not find it, now takes the inverse substitution where the inverse function, or a function of it alone, is below the bar, and asks the question in `u` of the sine and cosine rule alone: what else the substitution leaves is declined at once, not searched. The tangent, cotangent, secant and cosecant it leaves are read as quotients of the sine and the cosine. Rubi's problems whose answer uses Si, Ci, Shi or Chi (1186, 3 s): 71 more solved -- 5.1.x, 5.2.x, 5.3.4, 5.5.1 and 5.6.1, ten of them timeouts before -- none lost, 0 wrong. Part of #1501. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ab9145f commit 2bb6031

4 files changed

Lines changed: 127 additions & 13 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,24 @@ multiple of it, `(d - c^2 d x^2)^(3/2)`, is written over it the same way, with
14761476
Rubi's 5.1.4, 5.1.5, 5.2.4 and 5.2.5, all 504 problems that count: 405 to 463, no row lost, 77
14771477
timeouts to 19.
14781478

1479+
### An inverse trigonometric function below the bar is integrated to the sine and cosine integrals
1480+
1481+
`1/arcsin(x)` was left unintegrated. Under the substitution that undoes the inverse function,
1482+
`x = sin(u)` for `arcsin(x)`, `x^m/(a + b arcsin(c x))^n` is a polynomial in the sine and the cosine
1483+
over a power of `a + b u`, which the sine and cosine integrals answer. That substitution was taken
1484+
only where it removed a radical, an exponential of the inverse function or a power of it, and is
1485+
now taken where the inverse function, or a function of it alone, is below the bar, before the
1486+
general substitution search, which does not find it. The tangent, cotangent, secant and cosecant it
1487+
leaves are read as quotients of the sine and the cosine
1488+
([#1501](https://github.com/asc-community/AngouriMath/issues/1501)).
1489+
1490+
| Input | Was (2.5.0) | Now |
1491+
|---|---|---|
1492+
| `"1/asin(x)".Integrate("x")` | `integral(1 / arcsin(x), x)` | `Ci(arcsin(x)) + C` |
1493+
| `"x/asin(x)".Integrate("x")` | `integral(x / arcsin(x), x)` | `1/2 * Si(2 * arcsin(x)) + C` |
1494+
| `"1/(a+b*asin(c*x))".Integrate("x")` | `integral(1 / (a + b * arcsin(c * x)), x)` | `Si` and `Ci` of `(a + b arcsin(c x))/b` |
1495+
| `"x/((c+a^2*c*x^2)^2*atan(a*x))".Integrate("x")` | `integral(x / ((c + a ^ 2 * c * x ^ 2) ^ 2 * arctan(a * x)), x)` | `1/2 * Si(2 * arctan(a * x)) / (a ^ 2 * c ^ 2) + C` |
1496+
14791497
### A perfect square in a power of the variable is read as one
14801498

14811499
`sqrt(a^2 + 2 a b x^2 + b^2 x^4) sqrt(c + e x + d x^2)` was left unevaluated. The radicand is

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

Lines changed: 90 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4144,6 +4144,7 @@ void Add(int k, bool isSine, Entity coefficient)
41444144
private static Entity? OverAPowerOfALinear(Entity expr, Entity.Variable x, Entity argument)
41454145
{
41464146
var (sine, cosine) = (MathS.Sin(argument), MathS.Cos(argument));
4147+
var (tangent, cotangent, secant, cosecant) = (MathS.Tan(argument), MathS.Cotan(argument), MathS.Sec(argument), MathS.Cosec(argument));
41474148
var s = Variable.CreateUnique(expr, "s");
41484149
var c = Variable.CreateUnique(expr + s, "c");
41494150
Entity constant = Number.Integer.One;
@@ -4157,12 +4158,18 @@ void Add(int k, bool isSine, Entity coefficient)
41574158
constant = underneath ? constant / factor : constant * factor;
41584159
continue;
41594160
}
4160-
// A polynomial in the sine and the cosine, above the bar.
4161-
if (factor.ContainsNode(sine) || factor.ContainsNode(cosine))
4161+
// A polynomial in the sine and the cosine, above the bar, the other four written as
4162+
// quotients of the two: `tan(u) cos(u)^2`, which the substitution x = tan(u)
4163+
// leaves, is `s c`, and what is not a polynomial after that is declined below.
4164+
if (factor.ContainsNode(sine) || factor.ContainsNode(cosine) || factor.ContainsNode(tangent)
4165+
|| factor.ContainsNode(cotangent) || factor.ContainsNode(secant) || factor.ContainsNode(cosecant))
41624166
{
4163-
var read = factor.Replace(node => node == sine ? s : node == cosine ? c : node);
4164-
if (underneath || read.ContainsNode(x))
4167+
var read = factor.Replace(node =>
4168+
node == sine ? s : node == cosine ? c : node == tangent ? s / c : node == cotangent ? c / s
4169+
: node == secant ? 1 / c : node == cosecant ? 1 / s : node);
4170+
if (read.ContainsNode(x))
41654171
return null;
4172+
read = underneath ? 1 / read : read;
41664173
trigonometric = trigonometric is null ? read : trigonometric * read;
41674174
continue;
41684175
}
@@ -4472,9 +4479,13 @@ private static (Entity Elementary, Entity Si, Entity Ci) APowerTimesASineOrACosi
44724479
{
44734480
Sinf(var argument) when argument.ContainsNode(x) => argument,
44744481
Cosf(var argument) when argument.ContainsNode(x) => argument,
4482+
Tanf(var argument) when argument.ContainsNode(x) => argument,
4483+
Cotanf(var argument) when argument.ContainsNode(x) => argument,
4484+
Secantf(var argument) when argument.ContainsNode(x) => argument,
4485+
Cosecantf(var argument) when argument.ContainsNode(x) => argument,
44754486
Powf(var @base, Number.Integer) => ASineOrCosineArgument(@base, x),
44764487
Mulf(var left, var right) => ASineOrCosineArgument(left, x) ?? ASineOrCosineArgument(right, x),
4477-
Divf(var numerator, _) => ASineOrCosineArgument(numerator, x),
4488+
Divf(var numerator, var denominator) => ASineOrCosineArgument(numerator, x) ?? ASineOrCosineArgument(denominator, x),
44784489
Sumf(var left, var right) => ASineOrCosineArgument(left, x) ?? ASineOrCosineArgument(right, x),
44794490
Minusf(var left, var right) => ASineOrCosineArgument(left, x) ?? ASineOrCosineArgument(right, x),
44804491
_ => null,
@@ -5254,6 +5265,48 @@ private static bool TryReadTrigonometricDenominator(
52545265
}
52555266
}
52565267

5268+
/// <summary>
5269+
/// Whether <paramref name="inverse"/>, or a function of it and of nothing else in
5270+
/// <paramref name="x"/>, is a factor below the bar of <paramref name="expr"/> or a
5271+
/// negative power of one.
5272+
/// </summary>
5273+
private static bool TheInverseIsBelowTheBar(Entity expr, Entity inverse, Entity.Variable x)
5274+
{
5275+
var u = Variable.CreateUnique(expr, "u_inv");
5276+
return FactorsOfTheIntegrand(expr).Any(pair =>
5277+
(pair.Underneath || pair.Factor is Powf(_, Number.Integer { EInteger.Sign: < 0 }))
5278+
&& pair.Factor.ContainsNode(inverse) && !pair.Factor.Substitute(inverse, u).ContainsNode(x));
5279+
}
5280+
5281+
/// <summary>
5282+
/// <see cref="SolveByInverseTrigonometricSubstitution"/> where the inverse function is
5283+
/// below the bar, asked before the general substitution search: under the substitution the
5284+
/// integrand is the sine and cosine integrals' at once, and the search in front of it spent
5285+
/// five seconds on <c>x/((c + a^2 c x^2)^2 arctan(a x))</c> finding nothing. Only that
5286+
/// question is asked in <c>u</c>, of <see cref="SolveATrigonometricOfALinearOverAPowerOfALinear"/>.
5287+
/// Where the substitution leaves anything else -- a quadratic it does not read as a
5288+
/// multiple of the radicand, <c>(a^2 + a^2 tan(u)^2)^3</c> -- the whole search in
5289+
/// <c>u</c> runs past thirty seconds, on integrands the general substitution search
5290+
/// answers in under one.
5291+
/// </summary>
5292+
internal static Entity? SolveAReciprocalOfAnInverseTrigonometricFunction(Entity expr, Entity.Variable x, bool integrateByParts)
5293+
{
5294+
if (expr is not (Divf or Mulf or Powf))
5295+
return null;
5296+
Entity? inverse = null;
5297+
foreach (var node in expr.Nodes)
5298+
{
5299+
if (node is not (Arcsinf or Arccosf or Arctanf or Arcsecantf or Arccosecantf or Arccotanf))
5300+
continue;
5301+
if (inverse is not null && inverse != node)
5302+
return null;
5303+
inverse = node;
5304+
}
5305+
return inverse is not null && TheInverseIsBelowTheBar(expr, inverse, x)
5306+
? UndoingTheInverseTrigonometricFunction(expr, x, integrateByParts, onlyTheSineAndCosineIntegrals: true)
5307+
: null;
5308+
}
5309+
52575310
/// <summary>
52585311
/// An integrand holding an inverse trigonometric function of the variable itself,
52595312
/// integrated by the substitution that undoes it: <c>x = sin(u)</c> for <c>arcsin(x)</c>,
@@ -5297,6 +5350,15 @@ private static bool TryReadTrigonometricDenominator(
52975350
/// https://github.com/asc-community/AngouriMath/issues/718
52985351
/// </remarks>
52995352
internal static Entity? SolveByInverseTrigonometricSubstitution(Entity expr, Entity.Variable x, bool integrateByParts)
5353+
=> UndoingTheInverseTrigonometricFunction(expr, x, integrateByParts, onlyTheSineAndCosineIntegrals: false);
5354+
5355+
/// <summary>
5356+
/// <see cref="SolveByInverseTrigonometricSubstitution"/>, or, with
5357+
/// <paramref name="onlyTheSineAndCosineIntegrals"/>, the substitution taken because the
5358+
/// inverse function is below the bar and the question in <c>u</c> asked of the sine and
5359+
/// cosine integrals' rule alone.
5360+
/// </summary>
5361+
private static Entity? UndoingTheInverseTrigonometricFunction(Entity expr, Entity.Variable x, bool integrateByParts, bool onlyTheSineAndCosineIntegrals)
53005362
{
53015363
// The one inverse function, of the variable or of a linear in it.
53025364
Entity? inverse = null;
@@ -5416,13 +5478,25 @@ private static bool TryReadTrigonometricDenominator(
54165478
var powerOfTheInverse = expr.Nodes.Any(node =>
54175479
node is Powf(var @base, Number.Integer power) && power.EInteger.CompareTo(EInteger.One) > 0
54185480
&& @base.ContainsNode(inverse) && !@base.Substitute(inverse, u).ContainsNode(x));
5419-
if (radicalsRemoved == 0 && !exponentialOfTheInverse && !powerOfTheInverse)
5420-
return null;
5421-
// The cosecant and the cotangent carry the sign of u into the root, and a first
5422-
// power of either beside a root is parts' -- `arccot(x)/(1 + x^2)^(3/2)` is
5423-
// `x arccot(x)/sqrt(1 + x^2) + 1/sqrt(1 + x^2)` there, with no sign in it.
5424-
if (inverse is Arccosecantf or Arccotanf && !exponentialOfTheInverse && !powerOfTheInverse)
5425-
return null;
5481+
// Or, asked for the sine and cosine integrals, the inverse function below the bar, or
5482+
// a function of it alone there: `x^m/(a + b arcsin(c x))^n` is a polynomial in the
5483+
// sine and cosine over a power of `a + b u`, where parts in x has no integral of the
5484+
// reciprocal to take.
5485+
if (onlyTheSineAndCosineIntegrals)
5486+
{
5487+
if (!TheInverseIsBelowTheBar(expr, inverse, x))
5488+
return null;
5489+
}
5490+
else
5491+
{
5492+
if (radicalsRemoved == 0 && !exponentialOfTheInverse && !powerOfTheInverse)
5493+
return null;
5494+
// The cosecant and the cotangent carry the sign of u into the root, and a first
5495+
// power of either beside a root is parts' -- `arccot(x)/(1 + x^2)^(3/2)` is
5496+
// `x arccot(x)/sqrt(1 + x^2) + 1/sqrt(1 + x^2)` there, with no sign in it.
5497+
if (inverse is Arccosecantf or Arccotanf && !exponentialOfTheInverse && !powerOfTheInverse)
5498+
return null;
5499+
}
54265500
// And nothing else of `x` under a root, which the construction did not reach:
54275501
// `x^3 arcsin(x)/sqrt(1 - x^4)` under the sine is a root of `1 - sin(u)^4`, worse
54285502
// than what it came from, and 1.4 s of declining it.
@@ -5467,7 +5541,10 @@ node is Powf(var @base, Number.Rational power) && power is not Number.Integer &&
54675541
// The same question in another variable, not a step in the search for it: asked at
54685542
// the top when this was, so the closed rules that answer only at the top --
54695543
// `e^u sin(u)^3` is the exponential-times-trigonometric rule's -- are consulted.
5470-
if (Integration.ComputeAsAQuestionOfItsOwn(integrand, u, integrateByParts) is not { } result)
5544+
var result = onlyTheSineAndCosineIntegrals
5545+
? SolveATrigonometricOfALinearOverAPowerOfALinear(integrand, u)
5546+
: Integration.ComputeAsAQuestionOfItsOwn(integrand, u, integrateByParts);
5547+
if (result is null)
54715548
return null;
54725549
if (result.ContainsNode(signOfU))
54735550
// The sign squared is one, and the sign itself is the sign of x.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,9 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
599599
// Sines and cosines of a linear over a power of a linear, onto Si and Ci under u = the
600600
// linear, where the search would take the quotient by parts without end.
601601
if ((answer = IndefiniteIntegralSolver.SolveATrigonometricOfALinearOverAPowerOfALinear(expr, x)) is { }) return answer;
602+
// And an inverse trigonometric function below the bar, which under the substitution that
603+
// undoes it is the same question; before the search, which does not find it.
604+
if ((answer = IndefiniteIntegralSolver.SolveAReciprocalOfAnInverseTrigonometricFunction(expr, x, integrateByParts)) is { }) return answer;
602605
// A fractional power of a perfect square is the power of the modulus, sgn(P) P^(2r).
603606
if ((answer = IndefiniteIntegralSolver.SolveByTakingARootOfAPerfectSquare(expr, x, integrateByParts)) is { }) return answer;
604607
// x^(n - 1) g(x^n) with a symbolic n is g(u)/n under u = x^n.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ public void OverSeveralLinears(string integrand)
106106
public void UnderAPowerOfTheVariable(string integrand)
107107
=> DifferentiatesBack(integrand, new[] { 0.35, 0.9, 1.45, 2.3 }, Pins);
108108

109+
/// <summary>
110+
/// An inverse sine, cosine or tangent below the bar is undone by the substitution
111+
/// <c>x = sin(u)</c> and its kin, after which the integrand is a polynomial in the sine and
112+
/// cosine over a power of <c>a + b u</c>. Rubi's 5.1.2 and 5.3.4,
113+
/// <c>x^m/(a + b arcsin(c x))^n</c> and <c>x^m/((c + a^2 c x^2)^2 arctan(a x))</c>.
114+
/// </summary>
115+
[Theory]
116+
[InlineData("1/asin(x)")]
117+
[InlineData("x/asin(c*x)")]
118+
[InlineData("x^2/(a + b*asin(c*x))")]
119+
[InlineData("1/acos(x)")]
120+
[InlineData("sqrt(1 - x^2)/asin(x)")]
121+
[InlineData("x/((c + d^2*c*x^2)^2*atan(d*x))")]
122+
public void ThroughAnInverseTrigonometricFunction(string integrand)
123+
=> DifferentiatesBack(integrand, new[] { 0.15, 0.3, 0.5, 0.7 }, Pins);
124+
109125
[Theory]
110126
[InlineData("sin(x)/x", "Si(x)")]
111127
[InlineData("cos(x)/x", "Ci(x)")]

0 commit comments

Comments
 (0)