Skip to content

Commit 1cdcd63

Browse files
Integrate half-odd powers of a ± a sin beside a fractional power of the cosine (#1964)
Rubi's (e cos(c + d x))^p (a + a sin(c + d x))^m with half-odd p and m were past the budget: the substitution search spent it on the two radicals. Under u = sin(y) they are (1 + u)^A (1 - u)^B with A and B quarter-odd, which by Chebyshev's theorem is elementary only where A + B = m + p - 1 is whole. With every power a number, the rule now asks only where A, B or A + B is whole and the rest is a polynomial in u. (a + a sin(y)) sqrt(e cos(y)), which is elliptic, is declined before anything is asked. Numeric powers are read one level below the question too, where the polynomial term hands 1/(A B) on as (A B)^(-1), and a whole power of a product is read as the powers of its factors. Three of the file master answered in six to eleven seconds under a condition now come through in a twentieth of a second without one. Part of #233. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 58d0dec commit 1cdcd63

4 files changed

Lines changed: 123 additions & 6 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3708,6 +3708,27 @@ Rubi's 1.1.4.2, `(c x)^m (a x^j + b x^n)^p` ([#718](https://github.com/asc-commu
37083708
| `"x/sqrt(a*x + b*x^4)".Integrate("x")` | left unevaluated | `K` times `2 ln(2 b x^(3/2) + 2 sqrt(b) sqrt(a + b x^3))/(3 sqrt(b))` for `b > 0`, an arcsine for `b < 0`; real where `x < -(a/b)^(1/3)` as well, where `K` is `-1` |
37093709
| `"x^(3/2*(n - 1))/(a*x^(n - 1) + b*x^n + c*x^(n + 1))^(3/2)".Integrate("x")` | left unevaluated | `K (2 b + 4 c x)/((4 a c - b^2) sqrt(a + b x + c x^2))`; `K` is 1 for a positive `x`, and a sign for a negative one, `-1` for `n = 2.3` |
37103710

3711+
### Half-odd powers of `a ± a sin` beside a fractional power of the cosine are integrated through the sine
3712+
3713+
**Answers where there were none.** `(e cos(c + d x))^(5/2) (a + a sin(c + d x))^(3/2)`,
3714+
`sqrt(e cos(c + d x))/sqrt(a + a sin(c + d x))` and the 22 others of Rubi's 4.1.1.2 with a half-odd power of each were
3715+
declined. Under `u = sin(y)` they are `(1 + u)^A (1 - u)^B` with `A` and `B` quarter-odd, which by Chebyshev's theorem
3716+
is elementary only where `A + B` is whole. The rule below now takes numeric powers where `A`, `B` or `A + B` is whole
3717+
and the rest is a polynomial in `u`, also one level below the question, and declines
3718+
`(a + a sin(y)) sqrt(e cos(y))`, which is elliptic, before asking anything. Three of the file the unreleased master
3719+
answered in six to eleven seconds, under a condition, now come through it in a twentieth of a second and without one,
3720+
and `sqrt(e sin(c + d x))/sqrt(a - a cos(c + d x))`, which it answered by the half angle only for positive `a` and `e`, is
3721+
answered for either sign ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
3722+
3723+
| Input | Was (2.5.0) | Now |
3724+
|---|---|---|
3725+
| `"(k*cos(c + d*x))^(5/2)*(a + a*sin(c + d*x))^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | 1,156 characters |
3726+
| `"sqrt(k*cos(c + d*x))/sqrt(a + a*sin(c + d*x))".ToEntity().Integrate("x")` | `integral(...)` | 859 characters |
3727+
| `"(a + a*sin(c + d*x))^(5/2)/(k*cos(c + d*x))^(13/2)".ToEntity().Integrate("x")` | `integral(...)` | 468 characters |
3728+
| `"(k*cos(c + d*x))^(9/2)/(a + a*sin(c + d*x))^(5/2)".ToEntity().Integrate("x")` | `integral(...)` | 1,073 characters |
3729+
| `"(a + a*sin(c + d*x))^(3/2)/(k*cos(c + d*x))^(9/2)".ToEntity().Integrate("x")` | `integral(...)`; 456 characters under a condition, in 10.6 s, on the unreleased master | 403 characters, in 61 ms |
3730+
| `"sqrt(k*sin(c + d*x))/sqrt(a - a*cos(c + d*x))".ToEntity().Integrate("x")` | `integral(...)`; on the unreleased master, an answer only where `a > 0` and `k > 0` | 825 characters, for either sign |
3731+
37113732
### Symbolic powers of `a ± a sin` beside a power of the cosine are integrated through the sine
37123733

37133734
**Answers where there were none.** `(a + a sin(h + f x))^m sqrt(c - c sin(h + f x))` and its kin,

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

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5469,8 +5469,8 @@ Entity Integral(ERational power)
54695469
}
54705470

54715471
/// <summary>
5472-
/// Powers of <c>a ± a sin(y)</c> with a symbolic exponent, beside a power of
5473-
/// <c>g cos(y)</c> and anything else in the sine alone, under <c>u = sin(y)</c>:
5472+
/// Powers of <c>a ± a sin(y)</c> with a symbolic exponent, or beside a fractional power of
5473+
/// <c>g cos(y)</c>, and anything else in the sine alone, under <c>u = sin(y)</c>:
54745474
/// <c>(1 + sin(y))(1 - sin(y))</c> is <c>cos(y)^2</c>, so each factor is a power of
54755475
/// <c>1 + u</c> or of <c>1 - u</c> up to a factor constant on each interval where it is
54765476
/// defined, and <c>dy = du/cos(y)</c> is one more pair of half powers. The cosine's the
@@ -5495,12 +5495,24 @@ Entity Integral(ERational power)
54955495
/// <c>(a (1 + u))^m</c> is not <c>a^m (1 + u)^m</c> for every <c>a</c>, and the quotient
54965496
/// of the two is constant on each interval either way. At the question asked only, and
54975497
/// only where an exponent is symbolic: numeric half powers are the half angle's.
5498+
/// </para>
5499+
/// <para>
5500+
/// But for a fractional power of the cosine, which the half angle does not read: Rubi's
5501+
/// <c>(e cos(c + d x))^p (a + a sin(c + d x))^m</c> with half-odd <c>p</c> and <c>m</c>
5502+
/// were past the budget, the substitution search spending it on the two radicals. In
5503+
/// <c>u</c> they are <c>(1 + u)^A (1 - u)^B</c> with <c>A</c> and <c>B</c> quarter-odd, which
5504+
/// by Chebyshev's theorem is elementary only where <c>A + B = m + p - 1</c> is whole, and
5505+
/// with every power a number the rule asks only where <c>A</c>, <c>B</c> or <c>A + B</c> is
5506+
/// whole and the rest is a polynomial in <c>u</c>: <c>(a + a sin(y)) sqrt(e cos(y))</c>, which
5507+
/// is elliptic, is declined before anything is asked. Numeric powers are read one level
5508+
/// below the question too, where the polynomial term hands <c>1/(A B)</c> on as
5509+
/// <c>(A B)^(-1)</c>, and a whole power of a product is read as the powers of its factors.
54985510
/// https://github.com/asc-community/AngouriMath/issues/718
54995511
/// </para>
55005512
/// </remarks>
55015513
internal static Entity? SolveSymbolicPowersOfOnePlusMinusASineThroughTheSine(Entity expr, Entity.Variable x, bool integrateByParts)
55025514
{
5503-
if (!Integration.AnsweringTheQuestionAsked)
5515+
if (!Integration.AnsweringTheQuestionAskedOrOneBelow)
55045516
return null;
55055517
Entity? argument = null;
55065518
foreach (var node in expr.Nodes)
@@ -5519,8 +5531,12 @@ Entity Integral(ERational power)
55195531
var cosine = MathS.Cos(argument);
55205532
// Each factor as a base and an exponent, a power of a power read as one power: the
55215533
// quotient of the two spellings is constant on each interval, and K carries it.
5534+
// A whole power of a product is the product of the powers: `1/(A B)` is handed on as
5535+
// `(A B)^(-1)` by the polynomial term.
55225536
var factors = new List<(Entity Factor, Entity Base, Entity Exponent)>();
5523-
foreach (var factor in Mulf.LinearChildren(expr))
5537+
foreach (var factor in Mulf.LinearChildren(expr).SelectMany(factor => factor is Powf(var product, Number.Integer power) && product is Mulf or Divf
5538+
? Mulf.LinearChildren(product).Select(part => (Entity)MathS.Pow(part, power))
5539+
: new[] { factor }))
55245540
{
55255541
Entity @base = factor, exponent = Number.Integer.One;
55265542
while (@base is Powf(var inner, var power))
@@ -5580,12 +5596,22 @@ Entity Integral(ERational power)
55805596
return null;
55815597
rest *= inU;
55825598
}
5583-
if (!symbolic)
5599+
// Symbolic powers at the question asked only. Numeric powers are the half angle's, but
5600+
// for a fractional power of the complement, which it does not read; and those one level
5601+
// down too, where the polynomial term hands on `1/(A B)` as `(A B)^(-1)`.
5602+
if (symbolic ? !Integration.AnsweringTheQuestionAsked
5603+
: !(ofTheComplement.InnerSimplified is Number.Rational complementPower && !IsWhole(complementPower.ERational)))
55845604
return null;
55855605
// dy = du/complement takes one more half power of each.
55865606
var half = Number.Rational.Create(1, 2);
55875607
var a = (plus + ofTheComplement * half - half).Simplify();
55885608
var b = (minus + ofTheComplement * half - half).Simplify();
5609+
// With every power a number, only where Chebyshev's theorem says the question in u is
5610+
// elementary, and beside a polynomial in u: otherwise it is a search past the budget.
5611+
if (!symbolic && !(a is Number.Rational ra && b is Number.Rational rb
5612+
&& (IsWhole(ra.ERational) || IsWhole(rb.ERational) || IsWhole(ra.ERational.Add(rb.ERational)))
5613+
&& IsAPolynomialInU(rest.InnerSimplified)))
5614+
return null;
55895615
// A zero exponent leaves its factor out: `(1 - u)^0` is one provided `u` is not one, and
55905616
// the condition would stand between the question and the rules that answer it.
55915617
Entity PowerOf(Entity @base, Entity exponent) => exponent == Number.Integer.Zero ? Number.Integer.One : MathS.Pow(@base, exponent);
@@ -5619,6 +5645,14 @@ Entity Integral(ERational power)
56195645
}
56205646
return found;
56215647
}
5648+
5649+
static bool IsWhole(ERational value) => value.IsInteger();
5650+
5651+
// Free of u, or a polynomial in it with coefficients free of it.
5652+
bool IsAPolynomialInU(Entity part)
5653+
=> !part.ContainsNode(u)
5654+
|| TreeAnalyzer.TryGetPolynomial(part, u, out var terms)
5655+
&& terms.Keys.All(power => power.Sign >= 0) && terms.Values.All(coefficient => !coefficient.ContainsNode(u));
56225656
}
56235657

56245658
/// <summary>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,8 @@ private static Entity WithItsPiecewiseSumsCombined(Entity expr)
10451045
if ((answer = IndefiniteIntegralSolver.SolveAPowerOfACosineAndASinePlusTheirAmplitude(expr, x)) is { }) return answer;
10461046
// And symbolic powers of `a ± a sin(y)` beside a power of `g cos(y)`, by u = sin(y), where
10471047
// `(1 + u)(1 - u)` is the cosine's square: the half angle wants numeric powers, and the
1048-
// substitution search spent the budget on these.
1048+
// substitution search spent the budget on these. Numeric ones too beside a fractional
1049+
// power of `g cos(y)`, which the half angle does not read.
10491050
if ((answer = IndefiniteIntegralSolver.SolveSymbolicPowersOfOnePlusMinusASineThroughTheSine(expr, x, integrateByParts)) is { }) return answer;
10501051
// And a half-odd power of a +- a sec(y), which is that square over cos(y): by the half-angle
10511052
// tangent, in which the whole is rational beside one root.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
/// Numeric powers of <c>a ± a sin(y)</c> beside a fractional power of <c>k cos(y)</c>, under
16+
/// <c>u = sin(y)</c>: <c>(1 + u)^A (1 - u)^B</c> with <c>A + B</c> whole, which the half angle
17+
/// does not read and the substitution search spent the budget on. Checked where the cosine is
18+
/// positive, and with <c>k</c> negative where it is negative, both real. Rubi's 4.1.1.2.
19+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class FractionalPowersOfACosineBesideOnePlusASineIntegralTest
23+
{
24+
[Theory]
25+
[InlineData("(k*cos(c + d*x))^(5/2)*(a + a*sin(c + d*x))^(3/2)")]
26+
[InlineData("sqrt(k*cos(c + d*x))/sqrt(a + a*sin(c + d*x))")]
27+
[InlineData("(a + a*sin(c + d*x))^(5/2)/(k*cos(c + d*x))^(13/2)")]
28+
[InlineData("(k*cos(c + d*x))^(9/2)/(a + a*sin(c + d*x))^(5/2)")]
29+
[InlineData("1/((k*cos(c + d*x))^(7/2)*(a + a*sin(c + d*x))^(3/2))")]
30+
[InlineData("(k*cos(c + d*x))^(3/2)*sqrt(a - a*sin(c + d*x))")]
31+
[InlineData("sin(c + d*x)*sqrt(k*cos(c + d*x))*(a + a*sin(c + d*x))^(3/2)")]
32+
[InlineData("(k*sin(c + d*x))^(3/2)*(a + a*cos(c + d*x))^(3/2)")]
33+
public void ThroughTheSine(string integrand)
34+
{
35+
var integral = integrand.ToEntity().Integrate("x");
36+
var text = integral.Stringize();
37+
Assert.DoesNotContain("integral(", text);
38+
Assert.True(text.Length < 3000, $"{text.Length} characters of answer for {integrand}");
39+
// y = c + d x stays inside (0, pi/2) at the first pins and inside (pi/2, pi) at the second.
40+
foreach (var (k, c) in new[] { (0.7, 0.4), (-0.7, 2.2) })
41+
{
42+
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("k", k).Substitute("c", c).Substitute("d", 0.3);
43+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
44+
var original = Pinned(integrand.ToEntity());
45+
var compared = 0;
46+
foreach (var at in new[] { -1.2, -0.7, 0.3, 0.8, 1.3, 2.9 })
47+
{
48+
var want = original.Substitute("x", at).EvalNumerical();
49+
var got = derivative.Substitute("x", at).EvalNumerical();
50+
if (want.IsNaN)
51+
continue;
52+
compared++;
53+
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
54+
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
55+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, k = {k}, where the integrand is {want}");
56+
}
57+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
58+
}
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)