Skip to content

Commit 3f74443

Browse files
A half-odd power of the secant beside the cosine is integrated as the cosine's (#1743)
The substitutions that read a function of the cosine read the secant as 1/cos to a whole power only, so sec(x)^(3/2)/sqrt(1 + cos(x)) was declined while 1/(cos(x)^(3/2) sqrt(1 + cos(x))) was answered. A half-odd power of the secant beside the cosine of the same argument is written as the cosine's power on the other side of the bar, and the answer is multiplied by K = sec(x)^p cos(x)^p, which is 1 where the cosine is positive and -1 where it is negative, so it holds on both sides. The same for the cosecant beside the sine. 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 7075a74 commit 3f74443

4 files changed

Lines changed: 153 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,24 @@ one form across the zeros.
11661166
| `"sqrt(a + a*sin(x))".Integrate("x")` | unevaluated (`a^2 = a^2` is not decided by evaluation) | `-2 sqrt(2a) sgn(sin(u)) cos(u)` |
11671167
| `"sqrt(1 + sin(x))".Integrate("x")` | `-2 cos(x)/sqrt(1 + sin(x))` | unchanged, the closed rule's |
11681168

1169+
### A half-odd power of the secant beside the cosine is integrated as the cosine's
1170+
1171+
**Answers where there were none.** `sec(x)^(3/2)/sqrt(1 + cos(x))` was declined while
1172+
`1/(cos(x)^(3/2) sqrt(1 + cos(x)))`, which it is wherever the cosine is positive, was answered: the
1173+
substitutions that read a function of the cosine read the secant as `1/cos` to a whole power only.
1174+
A half-odd power of the secant beside the cosine is written as the cosine's on the other side of
1175+
the bar now, `sec(x)^p = K/cos(x)^p`, with `K = sec(x)^p cos(x)^p` in front of the answer: `K` is 1
1176+
where the cosine is positive and -1 where it is negative, so the answer holds on both sides. The
1177+
same for the cosecant beside the sine. Rubi's 4.2.2.1, 4.2.3.1 and 4.2.4.2
1178+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
1179+
1180+
| Input | Was (2.5.0) | Now |
1181+
|---|---|---|
1182+
| `"sec(x)^(3/2)/sqrt(1 + cos(x))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in `tan(x/2)`, times `K` |
1183+
| `"1/((a + a*cos(x))^(7/2)*sec(x)^(7/2))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in `tan(x/2)`, over `K` |
1184+
| `"(A + c*cos(x)^2)*sec(x)^(11/2)*sqrt(a + a*cos(x))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in `tan(x/2)`, times `K` |
1185+
| `"sqrt(csc(x))*sqrt(a + a*sin(x))".ToEntity().Integrate("x")` | `integral(...)` | an antiderivative in `tan(x/2)`, times `csc(x)^(1/2) sin(x)^(1/2)` |
1186+
11691187
### Half-odd powers of `a ± a sec` and `a ± a csc` are integrated by the half-angle tangent
11701188

11711189
Rubi's `(a + b sec)^m (d sec)^n` files with `a^2 = b^2` hold about a thousand problems with a

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23725,6 +23725,82 @@ bool IsAPolynomialInBoth(Entity polynomial)
2372523725
return null;
2372623726
}
2372723727

23728+
/// <summary>
23729+
/// A half-odd power of the secant or the cosecant, in an integrand with the cosine or the
23730+
/// sine of the same argument in it, written as a power of the cosine or the sine:
23731+
/// <c>sec(z)^p = K/cos(z)^p</c> with <c>K = sec(z)^p cos(z)^p</c>, which is 1 wherever the
23732+
/// cosine is positive and -1 wherever it is negative, so it stands in front of the answer.
23733+
/// </summary>
23734+
/// <remarks>
23735+
/// <para>
23736+
/// <c>sec(x)^(3/2)/sqrt(1 + cos(x))</c> was declined while
23737+
/// <c>1/(cos(x)^(3/2) sqrt(1 + cos(x)))</c>, which it is wherever the cosine is positive,
23738+
/// was answered: the substitutions that read a function of the cosine read the secant as
23739+
/// <c>1/cos</c> to a whole power only. Only beside the cosine, so that a power of the
23740+
/// secant with no cosine keeps the rules for the secant. Rubi's 4.2.2.1, 4.2.3.1 and
23741+
/// 4.2.4.2.
23742+
/// </para>
23743+
/// <para>
23744+
/// Only a half-odd power of the secant itself, because that is what keeps <c>K</c> real:
23745+
/// the integrand is then real exactly where the rewritten one is, and an answer for the
23746+
/// rewritten one, which holds where it is real, holds where the integrand is. A constant
23747+
/// inside the power, <c>sqrt(b sec(x))</c>, or a quarter makes <c>K</c> imaginary on one
23748+
/// side, and the integrand real where the rewritten one is not: for a negative <c>b</c>,
23749+
/// <c>sqrt(b sec(x))</c> is real where the cosine is negative and <c>1/sqrt(cos(x))</c>
23750+
/// is not, and nothing about an answer for the second says anything there.
23751+
/// </para>
23752+
/// https://github.com/asc-community/AngouriMath/issues/718
23753+
/// </remarks>
23754+
internal static Entity? SolveByWritingAPowerOfTheSecantInTheCosine(Entity expr, Entity.Variable x, bool integrateByParts)
23755+
{
23756+
if (!expr.Nodes.Any(node => node is Secantf or Cosecantf))
23757+
return null;
23758+
var factors = FactorsOfTheIntegrand(expr);
23759+
var index = -1;
23760+
Entity? reciprocal = null;
23761+
Number.Rational? exponent = null;
23762+
for (var k = 0; k < factors.Count; k++)
23763+
{
23764+
if (factors[k].Factor is not Powf((Secantf or Cosecantf) and var found, var power)
23765+
|| power.Evaled is not Number.Rational fraction || fraction is Number.Integer
23766+
|| !fraction.ERational.Denominator.Equals(EInteger.FromInt32(2)) || !found.ContainsNode(x))
23767+
continue;
23768+
if (index >= 0)
23769+
return null;
23770+
(index, reciprocal, exponent) = (k, found, fraction);
23771+
}
23772+
if (index < 0 || reciprocal is null || exponent is null)
23773+
return null;
23774+
var function = reciprocal is Secantf(var argument) ? MathS.Cos(argument) : MathS.Sin(((Cosecantf)reciprocal).Argument);
23775+
// The reciprocal nowhere else and the function somewhere: the power is then all of
23776+
// the secant there is, and the rest of the integrand a function of the cosine.
23777+
if (expr.Nodes.Count(node => node == reciprocal) != 1 || !expr.ContainsNode(function))
23778+
return null;
23779+
var (written, underneath) = factors[index];
23780+
// The power is K/cos^p above the bar and cos^p/K below it. The cosine's power goes to
23781+
// the side where it is positive, so that the rest is one quotient as the rules read it.
23782+
var negative = exponent.ERational.IsNegative;
23783+
var raised = MathS.Pow(function, negative ? -exponent : exponent);
23784+
var raisedAbove = underneath != negative;
23785+
Entity? above = null;
23786+
Entity? below = null;
23787+
for (var k = 0; k < factors.Count; k++)
23788+
{
23789+
var (factor, side) = k == index ? (raised, !raisedAbove) : factors[k];
23790+
if (factor == Number.Integer.One)
23791+
continue;
23792+
if (side)
23793+
below = below is null ? factor : below * factor;
23794+
else
23795+
above = above is null ? factor : above * factor;
23796+
}
23797+
var numerator = above ?? Number.Integer.One;
23798+
var rewritten = below is null ? numerator : numerator / below;
23799+
var constant = written * MathS.Pow(function, exponent);
23800+
return Integration.ComputeAsTheSameQuestion(rewritten, x, integrateByParts)
23801+
?.Pipe(answer => underneath ? answer / constant : answer * constant);
23802+
}
23803+
2372823804
/// <summary>
2372923805
/// A rational function of <c>sin(x)</c> and <c>cos(x)</c>, turned into a rational function
2373023806
/// of one variable by the half-angle substitution <c>t = tan(x/2)</c> and handed to the

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,9 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
967967
if (expr is Entity.Sumf or Entity.Minusf
968968
&& (answer = IndefiniteIntegralSolver.SolveByGatheringACommonPolynomialFactorOfASum(expr, x, integrateByParts)) is { })
969969
return answer;
970+
// A power of the secant that is not whole beside the cosine, written as the cosine's
971+
// with the constant that takes in front, which the substitutions below read.
972+
if ((answer = IndefiniteIntegralSolver.SolveByWritingAPowerOfTheSecantInTheCosine(expr, x, integrateByParts)) is { }) return answer;
970973
// The half-angle substitution goes *after* linearity, and that is not a preference.
971974
// It fires on anything built from sines and cosines, and it answers `cos(x) + 1` with
972975
// a correct expression in tan(x/2) some forty characters long where splitting the sum
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 half-odd power of the secant beside the cosine, or of the cosecant beside the sine,
16+
/// which is the cosine's power on the other side of the bar times <c>sec(x)^p cos(x)^p</c>,
17+
/// 1 where the cosine is positive and -1 where it is negative. Compared on both sides, where
18+
/// the integrand is real and where it is not, which is where the constant is what keeps the
19+
/// answer right. Rubi's 4.2.2.1, 4.2.3.1 and 4.2.4.2.
20+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
21+
/// </summary>
22+
[Trait("Area", "Calculus")]
23+
public sealed class PowerOfTheSecantBesideTheCosineIntegralTest
24+
{
25+
[Theory]
26+
[InlineData("sec(x)^(3/2)/sqrt(1 + cos(x))")]
27+
[InlineData("sec(x)^(5/2)*(a + a*cos(x))^(3/2)")]
28+
[InlineData("1/((a + a*cos(x))^(7/2)*sec(x)^(7/2))")]
29+
[InlineData("(a + a*cos(x))^(3/2)*(A + B*cos(x))/sqrt(sec(x))")]
30+
[InlineData("(A + c*cos(x)^2)*sec(x)^(11/2)*sqrt(a + a*cos(x))")]
31+
[InlineData("sqrt(csc(x))*sqrt(a + a*sin(x))")]
32+
[InlineData("1/((a + a*sin(x))^(3/2)*csc(x)^(3/2))")]
33+
public void OnBothSidesOfTheCosine(string integrand)
34+
{
35+
var integral = integrand.ToEntity().Integrate("x");
36+
Assert.DoesNotContain("integral(", integral.Stringize());
37+
Assert.DoesNotContain("NaN", integral.Stringize());
38+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("A", 0.9).Substitute("B", 1.4).Substitute("c", 0.6);
39+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
40+
var original = Pinned(integrand.ToEntity());
41+
var compared = 0;
42+
foreach (var at in new[] { -2.6, -1.1, -0.4, 0.3, 0.8, 1.2, 2.0, 2.7 })
43+
{
44+
var want = original.Substitute("x", at).EvalNumerical();
45+
if (want.IsNaN)
46+
continue;
47+
compared++;
48+
var got = derivative.Substitute("x", at).EvalNumerical();
49+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
50+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
51+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
52+
}
53+
Assert.True(compared >= 6, $"only {compared} points could be compared for {integrand}");
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)