Skip to content

Commit e1a1a3f

Browse files
A quadratic with rational roots counts as two linears before the substitution search (#1827)
The substitution search declines a rational function over symbolic linear factors and a quadratic, which the partial fractions split at once; the half-angle tangent's 1 - u^2 is two linear factors written together and is counted so. 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 feb0e25 commit e1a1a3f

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ after it
208208
|---|---|---|
209209
| `"(a*c + b*c*x)^(-3-2*p)*(f + g*x)*(a^2 + 2*a*b*x + b^2*x^2)^p".ToEntity().Integrate("x")` | `integral(...)`; an answer with no value on the unreleased master | the antiderivative |
210210

211+
### A quadratic with rational roots counts as two linears before the substitution search
212+
213+
**Answers where there were none.** `sec(x)^2 sin(x)/(a + b sin(x))^3` ran past thirty seconds: under the
214+
half-angle tangent it is a rational function over `(1 - u^2)^2 (a u^2 + 2 b u + a)^3`, and the substitution
215+
search spent eighty seconds on it before the partial fractions, which split it at once, were asked. The search
216+
already declines a rational function over symbolic linear factors and a quadratic; `1 - u^2` is two linear
217+
factors written together, and is counted so ([#718](https://github.com/asc-community/AngouriMath/issues/718)).
218+
219+
| Input | Was (2.5.0) | Now |
220+
|---|---|---|
221+
| `"sec(x)^2*sin(x)/(a + b*sin(x))^3".ToEntity().Integrate("x")` | `integral(...)`; past thirty seconds on the unreleased master | 5,017 characters |
222+
| `"tan(x)^2/(a + b*sin(x))^3".ToEntity().Integrate("x")` | `integral(...)`; past thirty seconds on the unreleased master | 4,816 characters |
223+
211224
### A sine of a double argument beside the argument is written as a product
212225

213226
**Answers where there were none.** `csc(a + b x)^3 sin(2a + 2b x)^7` was declined: the rule that writes multiples

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21277,6 +21277,12 @@ private static bool IsAProductOfSymbolicLinearFactors(Entity denominator, Entity
2127721277
return false;
2127821278
if (read.Keys.Max()!.Equals(EInteger.One))
2127921279
linears++;
21280+
// A quadratic with rational coefficients and rational roots is two linear factors
21281+
// written together: the half-angle tangent's `1 - u^2` beside `a u^2 + 2 b u + a` is
21282+
// `(1 - u)(1 + u)` to the split, and the search spent eighty seconds declining Rubi's
21283+
// `sec(x)^2 sin(x)/(a + b sin(x))^3` before it was asked.
21284+
else if (read.Keys.Max()!.Equals(EInteger.FromInt32(2)) && HasRationalRoots(read))
21285+
linears += 2;
2128021286
else if (read.Keys.Max()!.Equals(EInteger.FromInt32(2)))
2128121287
quadratics++;
2128221288
else
@@ -21286,6 +21292,23 @@ private static bool IsAProductOfSymbolicLinearFactors(Entity denominator, Entity
2128621292
return (linears >= 1 || !aLinearAmongThem) && linears + quadratics >= 2 && symbolic;
2128721293
}
2128821294

21295+
/// <summary>
21296+
/// Whether a quadratic read as its coefficients has rational coefficients and a
21297+
/// discriminant that is the square of a rational.
21298+
/// </summary>
21299+
private static bool HasRationalRoots(Dictionary<EInteger, Entity> quadratic)
21300+
{
21301+
Number.Rational? Coefficient(int power)
21302+
=> quadratic.TryGetValue(EInteger.FromInt32(power), out var c) ? c.Evaled as Number.Rational : Number.Integer.Zero;
21303+
if (Coefficient(2) is not { } a || Coefficient(1) is not { } b || Coefficient(0) is not { } c)
21304+
return false;
21305+
var discriminant = (b * b - 4 * a * c).Evaled;
21306+
if (discriminant is not Number.Rational d || d.ERational.IsNegative)
21307+
return false;
21308+
var root = MathS.Sqrt(d).Evaled;
21309+
return root is Number.Rational;
21310+
}
21311+
2128921312
/// <summary>
2129021313
/// Whether a written factor of <paramref name="denominator"/> with a symbol in it stands
2129121314
/// to a whole power of two or more: where the Hermite reduction's one solve takes those
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+
/// A rational function of the sine over a power of <c>a + b sin(x)</c> with the cosine below the bar: under
16+
/// the half-angle tangent, <c>(1 - u^2)</c> beside <c>a u^2 + 2 b u + a</c>, split by its partial fractions
17+
/// rather than searched for a substitution. Rubi's 4.1.1.2, 4.1.1.3 and 4.1.2.2.
18+
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
19+
/// </summary>
20+
[Trait("Area", "Calculus")]
21+
public sealed class AHalfAngleRationalFunctionOverOneMinusTheSquareIntegralTest
22+
{
23+
[Theory]
24+
[InlineData("sec(x)^2*sin(x)/(a + b*sin(x))^3")]
25+
[InlineData("tan(x)^2/(a + b*sin(x))^3")]
26+
public void ByItsPartialFractions(string integrand)
27+
{
28+
var integral = integrand.ToEntity().Integrate("x");
29+
var text = integral.Stringize();
30+
Assert.DoesNotContain("integral(", text);
31+
Assert.True(text.Length < 20000, $"{text.Length} characters of answer for {integrand}");
32+
Entity Pinned(Entity e) => e.Substitute("a", 2.3).Substitute("b", 0.7);
33+
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
34+
var original = Pinned(integrand.ToEntity());
35+
var compared = 0;
36+
foreach (var at in new[] { -1.2, -0.7, 0.3, 0.8, 1.3, 2.9 })
37+
{
38+
var want = original.Substitute("x", at).EvalNumerical();
39+
var got = derivative.Substitute("x", at).EvalNumerical();
40+
if (want.IsNaN)
41+
continue;
42+
compared++;
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+
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)