Skip to content

Commit 983a612

Browse files
An odd power of the tangent beside a function of the secant, in the secant (#1832)
* An odd power of the tangent beside a function of the secant, in the secant Part of #718. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura * The answers with the split are longer Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 60b8111 commit 983a612

3 files changed

Lines changed: 122 additions & 0 deletions

File tree

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4595,6 +4595,76 @@ static bool IsHalfOdd(Entity exponent) => exponent is Number.Rational rational a
45954595
return expr * inTermsOfU.Substitute(u, other.Radicand) / inX;
45964596
}
45974597

4598+
/// <summary>
4599+
/// An odd whole power of <c>tan(y)</c> beside a function of <c>sec(y)</c>, integrated in
4600+
/// <c>u = sec(y)</c>: <c>du = sec(y) tan(y) dy</c> and the even power of the tangent left over
4601+
/// is a power of <c>u^2 - 1</c>, so <c>tan(y)^n</c> with the rest is
4602+
/// <c>(u^2 - 1)^((n - 1)/2)/u du</c> beside it, exactly. The cotangent beside a function of
4603+
/// the cosecant, in <c>u = csc(y)</c>, the same.
4604+
/// </summary>
4605+
/// <remarks>
4606+
/// Rubi's <c>cot(c + d x)/(a + b sec(c + d x))^(3/2)</c> was declined and
4607+
/// <c>cot(c + d x)^3 sqrt(a + b sec(c + d x))</c> ran past thirty seconds, where in the
4608+
/// secant each is a rational function beside the root of a linear.
4609+
/// https://github.com/asc-community/AngouriMath/issues/718
4610+
/// </remarks>
4611+
internal static Entity? SolveAnOddPowerOfTheTangentBesideAFunctionOfTheSecant(Entity expr, Entity.Variable x, bool integrateByParts)
4612+
{
4613+
if (!Integration.AnsweringTheQuestionAskedOrOneBelow)
4614+
return null;
4615+
Entity? argument = null;
4616+
foreach (var node in expr.Nodes)
4617+
{
4618+
if (TrigonometricArgument(node) is not { } thisArgument || !thisArgument.ContainsNode(x))
4619+
continue;
4620+
if (argument is null)
4621+
argument = thisArgument;
4622+
else if (argument != thisArgument)
4623+
return null;
4624+
}
4625+
if (argument is null || !TreeAnalyzer.TryGetPolyLinear(argument, x, out var rate, out _)
4626+
|| rate.ContainsNode(x) || TreeAnalyzer.IsZero(rate))
4627+
return null;
4628+
if (!expr.Nodes.All(node => !node.ContainsNode(x)
4629+
|| node is Variable or Sumf or Minusf or Mulf or Divf or Sinf or Cosf or Secantf or Cosecantf or Tanf or Cotanf
4630+
|| node is Powf(_, Number.Rational)))
4631+
return null;
4632+
var t = Variable.CreateUnique(expr, "t_odd_tangent");
4633+
var u = Variable.CreateUnique(expr, "u_secant");
4634+
foreach (var ofTheSecant in new[] { true, false })
4635+
{
4636+
// The tangent and its reciprocal as one base; for the cosecant, the cotangent.
4637+
var inT = expr.Replace(node => node switch
4638+
{
4639+
Tanf(var a) when a == argument => ofTheSecant ? t : 1 / t,
4640+
Cotanf(var a) when a == argument => ofTheSecant ? 1 / t : t,
4641+
_ => node,
4642+
});
4643+
var (rest, exponents) = GatheredOverTheBases(inT, new Entity[] { t });
4644+
var n = exponents[0];
4645+
if (rest.ContainsNode(t) || !n.IsInteger() || n.ToEInteger().IsEven || !n.ToEInteger().CanFitInInt32())
4646+
continue;
4647+
var inU = rest.Replace(node => node switch
4648+
{
4649+
Secantf(var a) when ofTheSecant && a == argument => u,
4650+
Cosf(var a) when ofTheSecant && a == argument => 1 / u,
4651+
Cosecantf(var a) when !ofTheSecant && a == argument => u,
4652+
Sinf(var a) when !ofTheSecant && a == argument => 1 / u,
4653+
_ => node,
4654+
});
4655+
if (inU.ContainsNode(x))
4656+
continue;
4657+
// dy = du/(u t) for the secant, -du/(u t) for the cosecant, and t^(n - 1) = (u^2 - 1)^((n - 1)/2).
4658+
var half = n.Subtract(ERational.One).Divide(ERational.FromInt32(2)).ToEInteger();
4659+
var integrand = (inU * MathS.Pow(MathS.Sqr(u) - 1, Number.Integer.Create(half)) / ((ofTheSecant ? rate : -rate) * u)).InnerSimplified;
4660+
if (Integration.ComputeAsAQuestionOfItsOwn(integrand, u, integrateByParts) is not { } inTermsOfU
4661+
|| inTermsOfU.Nodes.Any(node => node == MathS.NaN))
4662+
return null;
4663+
return inTermsOfU.Substitute(u, ofTheSecant ? MathS.Sec(argument) : new Cosecantf(argument));
4664+
}
4665+
return null;
4666+
}
4667+
45984668
/// <summary>
45994669
/// <c>tan(y) tan(2y)</c> written <c>sec(2y) - 1</c>, and the integrand asked again in the
46004670
/// one argument <c>2y</c>.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,8 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
911911
// And the secant beside powers of a + a sec(y) and c - c sec(y), whose product is a
912912
// square of the tangent: in u = a + a sec(y), a symbolic power of it too.
913913
if ((answer = IndefiniteIntegralSolver.SolveASecantBesidePowersOfItsConjugateSums(expr, x, integrateByParts)) is { }) return answer;
914+
// And an odd power of the tangent beside a function of the secant, in u = sec(y).
915+
if ((answer = IndefiniteIntegralSolver.SolveAnOddPowerOfTheTangentBesideAFunctionOfTheSecant(expr, x, integrateByParts)) is { }) return answer;
914916
// And `a ± a cosh(y)` under a fractional power: `2a cosh(y/2)^2`, `-2a sinh(y/2)^2`.
915917
if ((answer = IndefiniteIntegralSolver.SolveByTheHalfAngleWhereOnePlusAHyperbolicCosineIsASquare(expr, x, integrateByParts)) is { }) return answer;
916918
// The hyperbolic sine's, off the real line: 1 + i sinh(y) is (cosh(y/2) + i sinh(y/2))^2.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
/// An odd power of the tangent beside a function of the secant, in <c>u = sec(y)</c>, and the
16+
/// cotangent beside one of the cosecant. Rubi's 4.5.1.4.
17+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
18+
/// </summary>
19+
[Trait("Area", "Calculus")]
20+
public sealed class AnOddPowerOfTheTangentBesideTheSecantIntegralTest
21+
{
22+
[Theory]
23+
[InlineData("cot(g + f*x)/(a + b*sec(g + f*x))^(3/2)")]
24+
[InlineData("cot(x)^3/(a + b*sec(x))^(3/2)")]
25+
[InlineData("tan(x)^3/(a + b*csc(x))")]
26+
public void InTheSecant(string integrand)
27+
{
28+
var integral = integrand.ToEntity().Integrate("x");
29+
var text = integral.Stringize();
30+
Assert.DoesNotContain("integral(", text);
31+
Assert.True(text.Length < 40000, $"{text.Length} characters of answer for {integrand}");
32+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.4).Substitute("g", 0.2).Substitute("f", 0.7);
33+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
34+
var original = Pinned(integrand.ToEntity());
35+
var compared = 0;
36+
foreach (var at in new[] { -1.2, -0.7, 0.3, 0.8, 1.3, 2.9 })
37+
{
38+
var want = original.Substitute("x", at).EvalNumerical();
39+
var got = derivative.Substitute("x", at).EvalNumerical();
40+
if (want.IsNaN)
41+
continue;
42+
compared++;
43+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
44+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
45+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
46+
}
47+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)