Skip to content

Commit 8dbdedc

Browse files
Rafael-SOWNetclaude
andcommitted
Write an even power of the sine beside the secant in the cosine
Rubi's 4.5.1.3 sin(c + d x)^2/(a + b sec(c + d x)) ran past the corpus's budget: the half-angle substitution wrote it in 117,751 characters, and sin(x)^4/(a + b sec(x)) in 160,657. SolveByWritingARationalFunctionOfTheSecantInTheCosine wrote a rational function of the secant in the cosine beside the cosine itself, where the half-angle had written cos(x)^2/(a + b sec(x)) in 117,409 characters, and declined beside the sine as a second function. The sine stands there to even powers only, and sin(z)^(2k) is (1 - cos(z)^2)^k exactly, so it is now written so: (1 - cos(x)^2) cos(x)/(a cos(x) + b) is a polynomial over a linear in the cosine, 969 characters. The cosine beside the cosecant is written in the sine the same way. An odd power of the complement still declines. Part of #233. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent e30f63f commit 8dbdedc

3 files changed

Lines changed: 77 additions & 3 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ coefficients are the roots of that quadratic, and the polynomial over it is spli
117117
| `"1/(4*a*c+4*c^2*x^2+4*c*d*x^3+d^2*x^4)".ToEntity().Integrate("x")` | `integral(...)` | 3,920 characters |
118118
| `"x/(4*a*c+4*c^2*x^2+4*c*d*x^3+d^2*x^4)".ToEntity().Integrate("x")` | `integral(...)` | 2,315 characters |
119119

120+
### An even power of the sine beside the secant is written in the cosine
121+
122+
**Answers where there were none, shorter than master's.** Rubi's 4.5.1.3 `sin(c + d x)^2/(a + b sec(c + d x))` ran
123+
past the corpus's budget. The half-angle substitution wrote it in 117,751 characters, and `sin(x)^4/(a + b sec(x))` in
124+
160,657. A rational function of the secant was written in the cosine only beside the cosine itself. The sine beside it
125+
stands to even powers only, and `sin(z)^(2k)` is `(1 - cos(z)^2)^k`, so the integrand is now written in the cosine, as a
126+
polynomial over a linear in it. The cosine beside the cosecant is written in the sine the same way
127+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
128+
129+
| Input | Was (2.5.0) | Now |
130+
|---|---|---|
131+
| `"sin(c+d*x)^2/(a+b*sec(c+d*x))".ToEntity().Integrate("x")` | `integral(...)` | 1,187 characters, where before this change master gave 117,751 |
132+
| `"sin(x)^4/(a+b*sec(x))".ToEntity().Integrate("x")` | `integral(...)` | 1,729 characters, where before this change master gave 160,657 |
133+
| `"cos(x)^2/(a+b*csc(x))".ToEntity().Integrate("x")` | `integral(...)` | 994 characters, where before this change master gave 2,271 |
134+
120135
### An exponential of a quadratic over a power of the linear through its vertex is a moment about it
121136

122137
**Answers where there were none.** `f^(a + b x + c x^2)/(b + 2 c x)` was declined, and so were five more of Rubi's 2.3,

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46958,8 +46958,14 @@ bool IsAPolynomialInBoth(Entity polynomial)
4695846958
var argument = reciprocal.DirectChildren.First();
4695946959
var function = reciprocal is Secantf ? MathS.Cos(argument) : MathS.Sin(argument);
4696046960
// The cosine of the same argument beside the secant, or the sine beside the cosecant, is
46961-
// what the rewritten integrand is in already; any other is a second function.
46962-
if (partners.Any(partner => partner != function))
46961+
// what the rewritten integrand is in already, and the other of the two is too where it
46962+
// stands only to even powers, `sin(z)^(2k)` being `(1 - cos(z)^2)^k`: the half-angle
46963+
// substitution wrote `sin(x)^2/(a + b sec(x))` in 117,517 characters, where
46964+
// `(1 - cos(x)^2) cos(x)/(a cos(x) + b)` is 969. Any other is a second function.
46965+
var complement = reciprocal is Secantf ? MathS.Sin(argument) : MathS.Cos(argument);
46966+
static bool AnEvenPower(Entity node, Entity of) => node is Powf(var @base, Number.Integer { EInteger: var power }) && @base == of && power.IsEven && power.Sign > 0;
46967+
var inEvenPowers = expr.Nodes.Count(node => node == complement) == expr.Nodes.Count(node => AnEvenPower(node, complement));
46968+
if (partners.Any(partner => partner != function && (partner != complement || !inEvenPowers)))
4696346969
return null;
4696446970
// Only two sums in the secant or more, all below the bar: one, or one above, the rules for
4696546971
// the secant answer as written, and in the cosine `sec(x)^5/(a + b sec(x))^3` ran past five
@@ -46978,7 +46984,11 @@ bool IsAPolynomialInBoth(Entity polynomial)
4697846984
if (partners.Count > 0
4697946985
&& (!below.Nodes.Any(ASum) || Mulf.LinearChildren(below).Any(factor => factor is Powf(var @base, _) && ASum(@base))))
4698046986
return null;
46981-
var rewritten = Functions.SingleQuotient.Combine(expr.Replace(node => node == reciprocal ? 1 / function : node));
46987+
var rewritten = Functions.SingleQuotient.Combine(expr.Replace(node =>
46988+
node == reciprocal ? 1 / function
46989+
: AnEvenPower(node, complement) && node is Powf(_, Number.Integer { EInteger: var power })
46990+
? MathS.Pow(1 - MathS.Pow(function, 2), Number.Integer.Create(power / 2))
46991+
: node));
4698246992
return Integration.ComputeAsTheSameQuestion(rewritten, x, integrateByParts);
4698346993
}
4698446994

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 even power of the sine beside a rational function of the secant, written in the cosine,
16+
/// <c>sin(z)^(2k)</c> as <c>(1 - cos(z)^2)^k</c>: the half-angle substitution wrote Rubi's 4.5.1.3
17+
/// <c>sin(c + d x)^2/(a + b sec(c + d x))</c> in 117,751 characters and past the corpus's budget,
18+
/// where in the cosine it is a polynomial over a linear. The cosine beside the cosecant the same way.
19+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class AnEvenPowerOfTheSineBesideASecantIntegralTest
23+
{
24+
[Theory]
25+
// Rubi 4.5.1.3:238.
26+
[InlineData("sin(c + d*x)^2/(a + b*sec(c + d*x))")]
27+
[InlineData("sin(x)^4/(a + b*sec(x))")]
28+
[InlineData("cos(x)^2/(a + b*csc(x))")]
29+
public void IsAnsweredInTheCosine(string integrand)
30+
{
31+
var integral = integrand.ToEntity().Integrate("x");
32+
var text = integral.Stringize();
33+
Assert.DoesNotContain("integral(", text);
34+
Assert.True(text.Length < 3000, $"{integrand} came back in {text.Length} characters");
35+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7).Substitute("c", 0.4).Substitute("d", 0.9);
36+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
37+
var original = Pinned(integrand.ToEntity());
38+
foreach (var at in new[] { -2.2, -0.9, 0.3, 1.4, 2.1 })
39+
{
40+
var want = original.Substitute("x", at).EvalNumerical();
41+
var got = derivative.Substitute("x", at).EvalNumerical();
42+
Assert.False(got.IsNaN, $"d/dx of the antiderivative of {integrand} has no value at x = {at}, where the integrand is {want}");
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+
}
48+
}
49+
}

0 commit comments

Comments
 (0)