Skip to content

Commit 0c2ad34

Browse files
A polynomial may stand beside a root of a ± a cos(y) (#1474)
`x^3 sqrt(a + a cos(c + d x))` was left as written. The half angle at which `a ± a cos(y)` is a square answers the root alone, and it substitutes the angle -- so anything else that mentioned the variable stopped it, a polynomial among them, and the rule declined rather than handing on a question it had already made simpler. What is left of the variable is the variable itself. With `u` half the angle -- a quarter turn further for the sine's identity -- `x` is `(2u - offset)/rate`, so a polynomial in `x` is a polynomial in `u`, and what is handed on is one times a cosine of `u`: the shape the closed rules answer. Family 4 of the Rubi suite: 287 -> 290 of 422, 0 wrong; family 6 377/417 and the 1774-problem suite 1707 unchanged. Suite 12649 passed; allocation gate passed on all 19 gated benchmarks. Each row differentiates back with `a` positive and negative, where the sign the rule writes is what changes. Part of #718. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 78272aa commit 0c2ad34

3 files changed

Lines changed: 51 additions & 4 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,22 @@ it in the answer, and what the loop asks is whether the degree has fallen to not
11731173
| `"F^(c*(a+b*x))*sin(d+pe*x)^3".Integrate("x")` | left unevaluated | the antiderivative |
11741174
| `"F^(c*(a+b*x))*sin(d+pe*x)*cos(d+pe*x)".Integrate("x")` | left unevaluated | the antiderivative |
11751175

1176+
### A polynomial may stand beside a root of `a ± a cos(y)`
1177+
1178+
`x^3 sqrt(a + a cos(c + d x))` was left as written. The half angle at which `a ± a cos(y)` is a
1179+
square answers the root alone, and it substitutes the angle -- so anything else that mentioned
1180+
the variable stopped it, a polynomial among them. What is left of the variable is the variable
1181+
itself: with `u` half the angle (a quarter turn further for the sine's identity), `x` is
1182+
`(2u - offset)/rate`, so the polynomial is a polynomial in `u`, and what is handed on is one
1183+
times a cosine of `u`, which the closed rules answer. Rubi's 4.2.10
1184+
([#718](https://github.com/asc-community/AngouriMath/issues/718)).
1185+
1186+
| Input | Was (2.5.0) | Now |
1187+
|---|---|---|
1188+
| `"x^3*sqrt(a+a*cos(c+d*x))".Integrate("x")` | left unevaluated | the antiderivative, with `sgn(cos((c + d x)/2))` in front |
1189+
| `"x^3*sqrt(a-a*cos(x))".Integrate("x")` | left unevaluated | the antiderivative |
1190+
| `"x^2*sqrt(a+a*sin(x))".Integrate("x")` | left unevaluated | the antiderivative |
1191+
11761192
### `binomial(n, k)` is a function
11771193

11781194
**Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,7 @@ Entity Step(ERational power)
24262426
else if (argument != thisArgument)
24272427
return null;
24282428
}
2429-
if (argument is null || !TreeAnalyzer.TryGetPolyLinear(argument, x, out var rate, out _)
2429+
if (argument is null || !TreeAnalyzer.TryGetPolyLinear(argument, x, out var rate, out var offsetOfArgument)
24302430
|| rate.ContainsNode(x) || TreeAnalyzer.IsZero(rate))
24312431
return null;
24322432
if (!expr.Nodes.All(node => !node.ContainsNode(x)
@@ -2494,8 +2494,19 @@ Entity Step(ERational power)
24942494
return constant * MathS.Pow(square, Number.Integer.Create(twoP));
24952495
});
24962496
var inU = rewritten.Substitute(sine, sineInU).Substitute(cosine, cosineInU);
2497+
// What is left of the variable is the variable itself: the angle is `rate x + offset`
2498+
// and `u` is half of it (a quarter turn on for the sine), so `x` is
2499+
// `(2u - pi/2 - offset)/rate` there and `(2u - offset)/rate` here -- and
2500+
// `x^3 sqrt(a + a cos(c + d x))` is a polynomial in `u` times a cosine of it, which
2501+
// the closed rules answer, where the rule used to decline anything beside the root.
24972502
if (inU.ContainsNode(x))
2498-
return null;
2503+
{
2504+
var argumentInU = sineKind ? (2 * u - MathS.pi / 2).InnerSimplified : (2 * u).InnerSimplified;
2505+
var xInU = ((argumentInU - offsetOfArgument) / rate).InnerSimplified;
2506+
inU = inU.Substitute(x, xInU);
2507+
if (inU.ContainsNode(x))
2508+
return null;
2509+
}
24992510
// dx = 2 du / rate.
25002511
var integrand = (inU * 2 / rate).InnerSimplified;
25012512
if (Integration.ComputeAsAQuestionOfItsOwn(integrand, u, integrateByParts) is not { } result)
@@ -12416,7 +12427,7 @@ bool IsAConstantTimesAPowerOfOneMinusUSquared(Entity polynomial, out Entity cons
1241612427
else if (argument != thisArgument)
1241712428
return null;
1241812429
}
12419-
if (argument is null || !TreeAnalyzer.TryGetPolyLinear(argument, x, out var rate, out _)
12430+
if (argument is null || !TreeAnalyzer.TryGetPolyLinear(argument, x, out var rate, out var offsetOfArgument)
1242012431
|| rate.ContainsNode(x) || TreeAnalyzer.IsZero(rate))
1242112432
return null;
1242212433
if (!expr.Nodes.All(node => !node.ContainsNode(x)
@@ -14846,7 +14857,7 @@ bool IsAPolynomialInBoth(Entity polynomial)
1484614857
else if (argument != thisArgument)
1484714858
return null;
1484814859
}
14849-
if (argument is null || !TreeAnalyzer.TryGetPolyLinear(argument, x, out var rate, out _)
14860+
if (argument is null || !TreeAnalyzer.TryGetPolyLinear(argument, x, out var rate, out var offsetOfArgument)
1485014861
|| rate.ContainsNode(x) || TreeAnalyzer.IsZero(rate))
1485114862
return null;
1485214863
var sine = MathS.Sin(argument);

‎Sources/Tests/UnitTests/Calculus/HalfAngleSquareTest.cs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,26 @@ public void ThePairOfPowersTwoApartIsElementary(string integrand)
151151
Assert.True(compared >= 4, $"only {compared} of five points were comparable for {integrand}");
152152
}
153153

154+
/// <summary>
155+
/// A polynomial beside the root: the rule substitutes the half angle, and what is left
156+
/// of the variable is the variable itself -- <c>x</c> is <c>(2u - offset)/rate</c> for
157+
/// the cosine and a quarter turn further for the sine -- so
158+
/// <c>x^3 sqrt(a + a cos(c + d x))</c> is a polynomial in <c>u</c> times a cosine of it,
159+
/// which the closed rules answer. It used to decline anything standing beside the root.
160+
/// Rubi's 4.2.1. <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
161+
/// </summary>
162+
[Theory]
163+
[InlineData("x^3*sqrt(a + a*cos(c + d*x))")]
164+
[InlineData("x*sqrt(a + a*cos(x))")]
165+
[InlineData("x^3*sqrt(a - a*cos(x))")]
166+
[InlineData("x^2*sqrt(a + a*sin(x))")]
167+
[InlineData("x*(a + a*cos(x))^(3/2)")]
168+
public void APolynomialMayStandBesideTheRoot(string integrand)
169+
{
170+
DifferentiatesBack(integrand, 2);
171+
DifferentiatesBack(integrand, -3);
172+
}
173+
154174
/// <summary>A combination that does not kill the residual is not this rule's, and is left alone.</summary>
155175
[Fact]
156176
public void AnotherCoefficientIsLeftAsWritten()

0 commit comments

Comments
 (0)