Skip to content

Commit a27661f

Browse files
Symbolic powers of a ± a sin beside a power of the cosine are integrated through the sine (#1754)
(a + a sin(h + f x))^m sqrt(c - c sin(h + f x)) was declined, with the other symbolic powers of a +- a sin beside the cosine or a function of the sine: the half angle at which 1 +- sin is a square wants numeric powers. (1 + sin(y))(1 - sin(y)) is cos(y)^2, so under u = sin(y) each such power, a power of g cos(y) beside it and dy itself are powers of 1 + u and 1 - u, up to a factor constant on each interval, and the rest is asked in u; the answer is that antiderivative times the factor, the powers as written over the form they were rewritten to. The cosine's the same way. Of the 100 such problems of family 4 the corpus checks, master answers 37 and this 81. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent d276b34 commit a27661f

4 files changed

Lines changed: 227 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,26 @@ either now; and the secant quotient was simplified to `cos/(b^(5/2) d)` through
906906
`(1/cos)^(3/2) = cos^(-3/2)`, which is wrong for every negative cosine and cancelled against the
907907
same wrong step on the denominator. On the 1774-problem independent suites this is 1707 to 1705, the two `asin` rows, with the sign error gone.
908908

909+
### Symbolic powers of `a ± a sin` beside a power of the cosine are integrated through the sine
910+
911+
**Answers where there were none.** `(a + a sin(h + f x))^m sqrt(c - c sin(h + f x))` and its kin,
912+
Rubi's `(a + b sin)^m (c + d sin)^n` files with `a^2 = b^2`, `c^2 = d^2` and a symbolic exponent,
913+
were declined or past the budget. `(1 + sin(y))(1 - sin(y))` is `cos(y)^2`, so under `u = sin(y)`
914+
each such power, a power of `g cos(y)` beside them and `dy` itself are powers of `1 + u` and
915+
`1 - u`, up to a factor constant on each interval, and the rest is asked in `u`; the cosine's the
916+
same way. The answer is the antiderivative in `u` times that factor, the powers as written over
917+
the form they were rewritten to. Where the question in `u` is `(1 + u)^A (1 - u)^B` with `A + B`
918+
a whole number below `-2` it is declined still
919+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
920+
921+
| Input | Was (2.5.0) | Now |
922+
|---|---|---|
923+
| `"(a + a*sin(h + f*x))^m*sqrt(c - c*sin(h + f*x))".ToEntity().Integrate("x")` | `integral(...)` | the integrand times `(1 + sin(h + f x))/(f (m + 1/2) cos(h + f x))`, written unreduced |
924+
| `"cos(h + f*x)^2*(a + a*sin(h + f*x))^m/sqrt(c - c*sin(h + f*x))".ToEntity().Integrate("x")` | `integral(...)` | the integrand times `(1 + sin(h + f x))/(f (m + 3/2) cos(h + f x))`, written unreduced |
925+
| `"(g*cos(h + f*x))^(1 - 2*m)*(a + a*sin(h + f*x))^m*(c - c*sin(h + f*x))^(m - 1)".ToEntity().Integrate("x")` | `integral(...)` | the integrand times `-(1 - sin(h + f x)) ln(1 - sin(h + f x))/(f cos(h + f x))` |
926+
| `"(a + a*sin(h + f*x))^m*(c - c*sin(h + f*x))^(-1 - m)".ToEntity().Integrate("x")` | `integral(...)` | the integrand times `(1 + sin(h + f x))(1 - sin(h + f x))/(f (1 + 2 m) cos(h + f x))`, written unreduced |
927+
| `"(a + a*cos(h + f*x))^m*sqrt(c - c*cos(h + f*x))".ToEntity().Integrate("x")` | `integral(...)` | the integrand times `-(1 + cos(h + f x))/(f (m + 1/2) sin(h + f x))`, written unreduced |
928+
909929
### A power of x comes out of a fractional power of a sum whose every term has it
910930

911931
`(a x^j + b x^n)^p` with a fractional `p`, the power of x common to every term inside the power,

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

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3608,6 +3608,159 @@ Entity Step(ERational power)
36083608
return answer.Nodes.Any(node => node == MathS.NaN) ? null : answer;
36093609
}
36103610

3611+
/// <summary>
3612+
/// Powers of <c>a ± a sin(y)</c> with a symbolic exponent, beside a power of
3613+
/// <c>g cos(y)</c> and anything else in the sine alone, under <c>u = sin(y)</c>:
3614+
/// <c>(1 + sin(y))(1 - sin(y))</c> is <c>cos(y)^2</c>, so each factor is a power of
3615+
/// <c>1 + u</c> or of <c>1 - u</c> up to a factor constant on each interval where it is
3616+
/// defined, and <c>dy = du/cos(y)</c> is one more pair of half powers. The cosine's the
3617+
/// same way, by <c>u = cos(y)</c> beside a power of <c>g sin(y)</c>.
3618+
/// </summary>
3619+
/// <remarks>
3620+
/// <para>
3621+
/// Rubi's <c>(a + b sin)^m (c + d sin)^n</c> files with <c>a^2 = b^2</c> and
3622+
/// <c>c^2 = d^2</c> hold about a hundred and twenty problems with a symbolic exponent,
3623+
/// <c>(a + a sin(e + f x))^m sqrt(c - c sin(e + f x))</c> the plainest, and none was
3624+
/// answered: the half angle at which <c>1 ± sin(y)</c> is a square, the rule before this
3625+
/// one, wants numeric powers, and the substitution search spent the budget on them. What
3626+
/// is asked in <c>u</c> is <c>(1 + u)^A (1 - u)^B R(u)</c>, which is elementary where one
3627+
/// of <c>A</c>, <c>B</c> and <c>A + B</c> is a whole number and the rest is a
3628+
/// polynomial, and is declined where it is not.
3629+
/// </para>
3630+
/// <para>
3631+
/// The answer is <c>K G(sin(y))/F</c>, for <c>G</c> the antiderivative in <c>u</c>,
3632+
/// <c>F</c> the slope of <c>y</c> and <c>K</c> the powers as written over the form they
3633+
/// were rewritten to and over <c>cos(y)</c>: a quotient whose logarithmic derivative is
3634+
/// zero, so the answer holds whatever <c>a</c>, <c>g</c> and the exponents are --
3635+
/// <c>(a (1 + u))^m</c> is not <c>a^m (1 + u)^m</c> for every <c>a</c>, and the quotient
3636+
/// of the two is constant on each interval either way. At the question asked only, and
3637+
/// only where an exponent is symbolic: numeric half powers are the half angle's.
3638+
/// https://github.com/asc-community/AngouriMath/issues/718
3639+
/// </para>
3640+
/// </remarks>
3641+
internal static Entity? SolveSymbolicPowersOfOnePlusMinusASineThroughTheSine(Entity expr, Entity.Variable x, bool integrateByParts)
3642+
{
3643+
if (!Integration.AnsweringTheQuestionAsked)
3644+
return null;
3645+
Entity? argument = null;
3646+
foreach (var node in expr.Nodes)
3647+
{
3648+
if (TrigonometricArgument(node) is not { } thisArgument || !thisArgument.ContainsNode(x))
3649+
continue;
3650+
if (argument is null)
3651+
argument = thisArgument;
3652+
else if (argument != thisArgument)
3653+
return null;
3654+
}
3655+
if (argument is null || !TreeAnalyzer.TryGetPolyLinear(argument, x, out var rate, out _)
3656+
|| rate.ContainsNode(x) || TreeAnalyzer.IsZero(rate))
3657+
return null;
3658+
var sine = MathS.Sin(argument);
3659+
var cosine = MathS.Cos(argument);
3660+
// Each factor as a base and an exponent, a power of a power read as one power: the
3661+
// quotient of the two spellings is constant on each interval, and K carries it.
3662+
var factors = new List<(Entity Factor, Entity Base, Entity Exponent)>();
3663+
foreach (var factor in Mulf.LinearChildren(expr))
3664+
{
3665+
Entity @base = factor, exponent = Number.Integer.One;
3666+
while (@base is Powf(var inner, var power))
3667+
{
3668+
@base = inner;
3669+
exponent = power * exponent;
3670+
}
3671+
if (exponent.ContainsNode(x))
3672+
return null;
3673+
factors.Add((factor, @base, exponent.InnerSimplified));
3674+
}
3675+
// Which function the sums are of: all of one kind.
3676+
bool? ofTheSine = null;
3677+
foreach (var (_, @base, _) in factors)
3678+
if (@base.ContainsNode(x) && ReadAsOnePlusMinusAFunction(@base, sine, cosine) is var (_, _, isSine))
3679+
{
3680+
if (ofTheSine is { } kind && kind != isSine)
3681+
return null;
3682+
ofTheSine = isSine;
3683+
}
3684+
if (ofTheSine is not { } sineKind)
3685+
return null;
3686+
var function = sineKind ? sine : cosine;
3687+
var complement = sineKind ? cosine : sine;
3688+
var u = Variable.CreateUnique(expr, "u_one_plus_minus");
3689+
// The exponents of 1 + f, of 1 - f and of the complement, the factors that carry
3690+
// them as they stand, and the rest in u.
3691+
Entity plus = Number.Integer.Zero, minus = Number.Integer.Zero, ofTheComplement = Number.Integer.Zero;
3692+
Entity asItIs = Number.Integer.One, rest = Number.Integer.One;
3693+
var symbolic = false;
3694+
foreach (var (factor, @base, exponent) in factors)
3695+
{
3696+
if (!factor.ContainsNode(x))
3697+
{
3698+
rest *= factor;
3699+
continue;
3700+
}
3701+
if (ReadAsOnePlusMinusAFunction(@base, sine, cosine) is var (_, isPlus, _))
3702+
{
3703+
if (isPlus)
3704+
plus += exponent;
3705+
else
3706+
minus += exponent;
3707+
asItIs *= factor;
3708+
symbolic |= exponent is not Number;
3709+
continue;
3710+
}
3711+
if (AsAPowerOfTheComplement(@base) is { } sign)
3712+
{
3713+
ofTheComplement += sign * exponent;
3714+
asItIs *= factor;
3715+
symbolic |= exponent is not Number;
3716+
continue;
3717+
}
3718+
var inU = factor.Substitute(function, u);
3719+
if (inU.ContainsNode(x))
3720+
return null;
3721+
rest *= inU;
3722+
}
3723+
if (!symbolic)
3724+
return null;
3725+
// dy = du/complement takes one more half power of each.
3726+
var half = Number.Rational.Create(1, 2);
3727+
var a = (plus + ofTheComplement * half - half).Simplify();
3728+
var b = (minus + ofTheComplement * half - half).Simplify();
3729+
// A zero exponent leaves its factor out: `(1 - u)^0` is one provided `u` is not one, and
3730+
// the condition would stand between the question and the rules that answer it.
3731+
Entity PowerOf(Entity @base, Entity exponent) => exponent == Number.Integer.Zero ? Number.Integer.One : MathS.Pow(@base, exponent);
3732+
var integrand = (PowerOf(1 + u, a) * PowerOf(1 - u, b) * rest).InnerSimplified;
3733+
if (Integration.ComputeAsAQuestionOfItsOwn(integrand, u, integrateByParts) is not { } result)
3734+
return null;
3735+
// d sin(y) = cos(y) dy and d cos(y) = -sin(y) dy.
3736+
Entity constant = asItIs * PowerOf(1 + function, (-a).InnerSimplified) * PowerOf(1 - function, (-b).InnerSimplified) / (rate * complement);
3737+
if (!sineKind)
3738+
constant = -constant;
3739+
var answer = constant * result.Substitute(u, function);
3740+
return answer.Nodes.Any(node => node == MathS.NaN) ? null : answer;
3741+
3742+
// 1 for a constant times the complement, -1 for a constant times its reciprocal
3743+
// function, null for anything else.
3744+
int? AsAPowerOfTheComplement(Entity @base)
3745+
{
3746+
int? found = null;
3747+
foreach (var part in Mulf.LinearChildren(@base))
3748+
{
3749+
if (!part.ContainsNode(x))
3750+
continue;
3751+
if (found is not null)
3752+
return null;
3753+
if (part == complement)
3754+
found = 1;
3755+
else if (sineKind ? part is Secantf(var s) && s == argument : part is Cosecantf(var c) && c == argument)
3756+
found = -1;
3757+
else
3758+
return null;
3759+
}
3760+
return found;
3761+
}
3762+
}
3763+
36113764
/// <summary>
36123765
/// Half-odd powers of <c>a ± a sec(y)</c>, beside powers of <c>d sec(y)</c> or
36133766
/// <c>d cos(y)</c> and anything rational in the sine and cosine of <c>y</c>, by the

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,10 @@ private static Entity Normalized(Entity expr, Entity.Variable x) =>
848848
// cosine, by the half angle at which they are squares: `1 + sin(y)` is `2 sin(u)^2`. Before
849849
// the substitution search, which spent twenty seconds on the radicals of the sine.
850850
if ((answer = IndefiniteIntegralSolver.SolveByTheHalfAngleWhereOnePlusASineIsASquare(expr, x, integrateByParts)) is { }) return answer;
851+
// And symbolic powers of `a ± a sin(y)` beside a power of `g cos(y)`, by u = sin(y), where
852+
// `(1 + u)(1 - u)` is the cosine's square: the half angle wants numeric powers, and the
853+
// substitution search spent the budget on these.
854+
if ((answer = IndefiniteIntegralSolver.SolveSymbolicPowersOfOnePlusMinusASineThroughTheSine(expr, x, integrateByParts)) is { }) return answer;
851855
// And a half-odd power of a +- a sec(y), which is that square over cos(y): by the half-angle
852856
// tangent, in which the whole is rational beside one root.
853857
if ((answer = IndefiniteIntegralSolver.SolveByTheHalfAngleTangentBesideAHalfOddPowerOfOnePlusASecant(expr, x, integrateByParts)) is { }) return answer;
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+
/// Powers of <c>a ± a sin(y)</c> with a symbolic exponent, beside a power of <c>g cos(y)</c> and
16+
/// a function of the sine, under <c>u = sin(y)</c>, where <c>(1 + u)(1 - u)</c> is the cosine's
17+
/// square; and the cosine's the same way. Rubi's <c>(a + b sin)^m (c + d sin)^n</c> files.
18+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
19+
/// </summary>
20+
[Trait("Area", "Calculus")]
21+
public sealed class PowersOfOnePlusAndMinusASineIntegralTest
22+
{
23+
[Theory]
24+
[InlineData("(a + a*sin(h + f*x))^m*sqrt(c - c*sin(h + f*x))")]
25+
[InlineData("(a + a*sin(h + f*x))^m*(c - c*sin(h + f*x))^(5/2)*(p + q*sin(h + f*x)^2)")]
26+
[InlineData("cos(h + f*x)^2*(a + a*sin(h + f*x))^m/sqrt(c - c*sin(h + f*x))")]
27+
[InlineData("(g*cos(h + f*x))^(1 - 2*m)*(a + a*sin(h + f*x))^m*(c - c*sin(h + f*x))^(m - 1)")]
28+
[InlineData("(a + a*sin(h + f*x))^m*(c - c*sin(h + f*x))^(-1 - m)")]
29+
[InlineData("(a - a*sin(h + f*x))^m*(c + c*sin(h + f*x))^n*(b*(m - n) + b*(1 + m + n)*sin(h + f*x))")]
30+
[InlineData("(a + a*cos(h + f*x))^m*sqrt(c - c*cos(h + f*x))")]
31+
public void ThroughTheSine(string integrand)
32+
{
33+
var integral = integrand.ToEntity().Integrate("x");
34+
Assert.DoesNotContain("integral(", integral.Stringize());
35+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.9).Substitute("c", 0.7)
36+
.Substitute("h", 0.4).Substitute("f", 1.3).Substitute("g", 0.8).Substitute("m", 0.37)
37+
.Substitute("n", 1.21).Substitute("p", 1.1).Substitute("q", 0.6);
38+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
39+
var original = Pinned(integrand.ToEntity());
40+
foreach (var at in new[] { -2.1, -0.9, 0.3, 0.7, 1.6, 2.2 })
41+
{
42+
var want = original.Substitute("x", at).EvalNumerical();
43+
var got = derivative.Substitute("x", at).EvalNumerical();
44+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
45+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
46+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
47+
}
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)