Skip to content

Commit 346b218

Browse files
A sine or cosine of the reciprocal of a linear beside a power of it is integrated under u = 1/L (#1737)
sin(a + b/x)/x^3 is -u sin(a + b u) under u = 1/x, one step by parts, and was declined. A trigonometric function of a + b/L^k beside L^m with m <= -3 is a polynomial in u = 1/L times the function; it is integrated so and written back. Rubi's 4.1.12 and 4.2.12. 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 9588be9 commit 346b218

4 files changed

Lines changed: 149 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,6 +2885,22 @@ quadratic is. `w` is real for a positive `x`, and the answer says so, `provided
28852885
| `"(a^2+b^2/x^(2/5)+2*a*b/x^(1/5))^(5/2)".Integrate("x")`, Rubi 1.2.3.2 #659 | left unevaluated | an antiderivative in `x^(-1/5)`, under the same condition |
28862886
| `"(1+2*x^(1/2)+x)^(3/2)".Integrate("x")` | left unevaluated | `2 (x/2 + x^(3/2) + 3 x^2/4 + x^(5/2)/5) provided x > 0` |
28872887

2888+
### A sine or cosine of the reciprocal of a linear beside a power of it is integrated under `u = 1/L`
2889+
2890+
**Answers where there were none.** `sin(a + b/x)/x^3` was declined, while under `u = 1/x` it is
2891+
`-u sin(a + b u)`, one step by parts. A trigonometric function of `a + b/L^k`, `L` a linear, beside
2892+
`L^m` with `m <= -3` is a polynomial in `u = 1/L` times the function, and is integrated so and written
2893+
back. Rubi's 4.1.12 and 4.2.12, `(e x)^m (a + b sin(c + d x^n))^p` for a negative `n`. The other
2894+
powers were answered already and are answered as before
2895+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
2896+
2897+
| Input | Was (2.5.0) | Now |
2898+
|---|---|---|
2899+
| `"sin(a + b/x)/x^3".ToEntity().Integrate("x")` | `integral(...)` | a sine and a cosine of `a + b/x` |
2900+
| `"cos(a + b/x)/x^4".ToEntity().Integrate("x")` | `integral(...)` | the same |
2901+
| `"sin(a + b/x^2)/x^5".ToEntity().Integrate("x")` | `integral(...)` | the same, of `a + b/x^2` |
2902+
| `"sin(a + b/(c + d*x))/(c + d*x)^3".ToEntity().Integrate("x")` | `integral(...)` | the same, of `a + b/(c + d x)` |
2903+
28882904
### A power of the variable times a sine or cosine of a logarithm, and a power of a monomial
28892905

28902906
`x^2 sin(a + b ln(c x^n))` and `(c x^n)^b` were both left as written. Two rules, each exact:

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16017,6 +16017,84 @@ private static bool TryReadAPowerTimesARadicalQuadratic(Entity expr, Entity.Vari
1601716017
return (-constant / slope * answerInU.Substitute(u, 1 / linear)).InnerSimplified;
1601816018
}
1601916019

16020+
/// <summary>
16021+
/// Sines, cosines and the rest of a function of the reciprocal of a linear, beside a whole
16022+
/// power of the linear: <c>L^m f(a + b/L^k)</c> with <c>L = c + d x</c>. Under <c>u = 1/L</c>,
16023+
/// <c>dx = -du/(d u^2)</c>, and it is <c>-(1/d) u^(-m - 2) f(a + b u^k)</c>: a polynomial times
16024+
/// the function for <c>m &lt;= -2</c>, which by parts is elementary for a sine or cosine of a
16025+
/// linear. <c>sin(a + b/x)/x^3</c> is <c>-u sin(a + b u)</c>. Rubi's 4.1.12 and 4.2.12,
16026+
/// <c>(e x)^m (a + b sin(c + d x^n))^p</c> for a negative <c>n</c>; the exponential's case is
16027+
/// <see cref="SolveAGaussianInAReciprocal"/>.
16028+
/// https://github.com/asc-community/AngouriMath/issues/718
16029+
/// </summary>
16030+
/// <remarks>
16031+
/// Every factor with the variable in it is read: a trigonometric function of something of
16032+
/// <c>L</c> with <c>1/L</c> in it, or a whole power of <c>L</c>; anything else and the rule
16033+
/// declines, rather than write a polynomial of <c>x</c> in <c>u</c>. Only for <c>m &lt;= -3</c>:
16034+
/// the other powers are answered as written, and asked here would come back respelled.
16035+
/// </remarks>
16036+
internal static Entity? SolveAFunctionOfTheReciprocalOfALinear(Entity expr, Entity.Variable x, bool integrateByParts)
16037+
{
16038+
static bool IsATrigonometric(Entity node) => node is Sinf or Cosf or Tanf or Cotanf or Secantf or Cosecantf;
16039+
// The linear a trigonometric argument divides by.
16040+
Entity? linear = null;
16041+
foreach (var node in expr.Nodes)
16042+
if (IsATrigonometric(node) && node.DirectChildren.First() is var argument && argument.ContainsNode(x)
16043+
&& ALinearBelowABar(argument, x) is { } below)
16044+
{
16045+
linear = below;
16046+
break;
16047+
}
16048+
if (linear is null || !TreeAnalyzer.TryGetPolyLinear(linear, x, out var slope, out _) || TreeAnalyzer.IsZero(slope))
16049+
return null;
16050+
var u = Variable.CreateUnique(expr, "u_rec");
16051+
Entity constant = Number.Integer.One;
16052+
var power = EInteger.Zero;
16053+
Entity inU = Number.Integer.One;
16054+
var sawAFunction = false;
16055+
foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr))
16056+
{
16057+
if (!factor.ContainsNode(x))
16058+
{
16059+
constant = underneath ? constant / factor : constant * factor;
16060+
continue;
16061+
}
16062+
var (candidate, k) = factor is Powf(var raised, Number.Integer n) ? (raised, n.EInteger) : (factor, EInteger.One);
16063+
if (candidate == linear)
16064+
{
16065+
power = underneath ? power.Subtract(k) : power.Add(k);
16066+
continue;
16067+
}
16068+
// A function of the reciprocal of the linear, read in u; a whole power of one as well.
16069+
// Bottom-up, so that each quotient by the linear is met whole; the linear anywhere
16070+
// else is left, and declines.
16071+
if (!factor.Nodes.Any(IsATrigonometric))
16072+
return null;
16073+
var rewritten = factor.Replace(node => node switch
16074+
{
16075+
Divf(var numerator, Powf(var below, Number.Integer k)) when below == linear => numerator * MathS.Pow(u, k),
16076+
Divf(var numerator, var below) when below == linear => numerator * u,
16077+
Powf(var below, Number.Integer { EInteger.Sign: < 0 } k) when below == linear => MathS.Pow(u, -k),
16078+
_ => node
16079+
}).InnerSimplified;
16080+
if (rewritten.ContainsNode(x))
16081+
return null;
16082+
sawAFunction = true;
16083+
inU = underneath ? inU / rewritten : inU * rewritten;
16084+
}
16085+
// L^m dx = -u^(-m - 2) du/d. Only where that is a positive power of u: at m = -2 the
16086+
// integrand is the derivative of its argument times a function of it, and above, a power
16087+
// of u below the bar is the sine and cosine integrals', both answered as written.
16088+
var inUPower = power.Negate().Subtract(EInteger.FromInt32(2));
16089+
if (!sawAFunction || inUPower.Sign <= 0 || inUPower.CompareTo(EInteger.FromInt32(24)) > 0)
16090+
return null;
16091+
var question = -constant / slope * MathS.Pow(u, Number.Integer.Create(inUPower)) * inU;
16092+
if (Integration.ComputeAsAQuestionOfItsOwn(question, u, integrateByParts) is not { } answer
16093+
|| answer.Nodes.Any(node => node is Integralf || node == MathS.NaN))
16094+
return null;
16095+
return answer.Substitute(u, 1 / linear);
16096+
}
16097+
1602016098
/// <summary>
1602116099
/// The linear a node of <paramref name="exponent"/> divides by, <c>b/L^k</c> or <c>L^(-k)</c>,
1602216100
/// or <see langword="null"/>.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,8 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
638638
if ((answer = IndefiniteIntegralSolver.SolveByWritingAPowerOfAnExponentialAsAMultipleOfOne(expr, x, integrateByParts)) is { }) return answer;
639639
// An exponential of a quadratic in 1/L beside a power of L, onto the Gaussian under u = 1/L.
640640
if ((answer = IndefiniteIntegralSolver.SolveAGaussianInAReciprocal(expr, x)) is { }) return answer;
641+
// And a trigonometric function of the reciprocal of a linear beside a power of it, under u = 1/L.
642+
if ((answer = IndefiniteIntegralSolver.SolveAFunctionOfTheReciprocalOfALinear(expr, x, integrateByParts)) is { }) return answer;
641643
// An exponential of a multiple of a logarithm is a power of the argument, which is
642644
// how every inverse hyperbolic function under an exponential arrives.
643645
if ((answer = IndefiniteIntegralSolver.SolveByFoldingAnExponentialOfALogarithm(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+
/// A sine or cosine of <c>a + b/L^k</c> beside <c>L^m</c>, <c>m &lt;= -3</c>, under <c>u = 1/L</c>:
16+
/// <c>sin(a + b/x)/x^3</c> is <c>-u sin(a + b u)</c>, elementary by parts, and was declined.
17+
/// Rubi's 4.1.12 and 4.2.12, <c>(e x)^m (a + b sin(c + d x^n))^p</c> for a negative <c>n</c>.
18+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
19+
/// </summary>
20+
[Trait("Area", "Calculus")]
21+
public sealed class FunctionOfTheReciprocalIntegralTest
22+
{
23+
[Theory]
24+
[InlineData("sin(a + b/x)/x^3")]
25+
[InlineData("cos(a + b/x)/x^4")]
26+
[InlineData("sin(a + b/x)^2/x^3")]
27+
[InlineData("cos(a + b/x)^3/x^4")]
28+
[InlineData("sin(a + b/x^2)/x^5")]
29+
[InlineData("sin(a + b/(c + d*x))/(c + d*x)^3")]
30+
public void UnderTheReciprocal(string integrand)
31+
{
32+
var integral = integrand.ToEntity().Integrate("x");
33+
Assert.DoesNotContain("integral(", integral.Stringize());
34+
Assert.DoesNotContain("NaN", integral.Stringize());
35+
Entity Pinned(Entity e) => e.Substitute("a", 2.3).Substitute("b", 0.7).Substitute("c", 1.3).Substitute("d", 1.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[] { -1.7, -0.9, 0.3, 0.8, 1.6, 2.9 })
40+
{
41+
var want = original.Substitute("x", at).EvalNumerical();
42+
if (want.IsNaN || Math.Abs((double)want.ImaginaryPart) > 1e-12)
43+
continue;
44+
compared++;
45+
var got = derivative.Substitute("x", at).EvalNumerical();
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)),
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)