Skip to content

Commit f300ee7

Browse files
The sine and cosine integrals are split over a quadratic's two roots (#1537)
`sin(x)/(1 + x^2)` was left unintegrated: only linears were read below the bar. A quadratic there is its leading coefficient times the linears of its two roots, complex where the discriminant is negative, and the partial fractions over them go on as over any linears. A conjugate pair of roots gives conjugate terms, whose sum is real on the real line. Three tests used `sin(x)/(x^2 + 1)^2` and `x sin(x)/(1 + x^2)` as integrands no rule answers; they ask a cubic below the bar now, whose roots are not written. Rubi's problems whose answer uses Si, Ci, Shi or Chi (1186, 3 s): 33 more solved -- 4.1.11, 4.1.12, 4.2.12 and 4.7.7 -- none lost, 0 wrong. Part of #1501. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 2bb6031 commit f300ee7

6 files changed

Lines changed: 74 additions & 17 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,21 @@ was refused, so each was read as a product with an undeclared variable
17041704
| `"Chi(1)".Simplify()` | `Chi` | `Chi(1)`, and `0.8378669409802082…` evaluated |
17051705
| `"Si(x)".Differentiate("x")` | `Si` | `sin(x) / x` |
17061706

1707+
### A quadratic below a sine or a cosine is split over its two roots
1708+
1709+
`sin(x)/(1 + x^2)` was left unintegrated. A quadratic below the bar, beside sines and cosines of a
1710+
linear, is its leading coefficient times the linears of its two roots, complex where its
1711+
discriminant is negative, and each term of the partial fractions over them is the one-linear
1712+
question: `Si` and `Ci` of `x - r`. Where the roots are a conjugate pair so are the two terms, and
1713+
their sum is real on the real line
1714+
([#1501](https://github.com/asc-community/AngouriMath/issues/1501)).
1715+
1716+
| Input | Was (2.5.0) | Now |
1717+
|---|---|---|
1718+
| `"cos(x)/(x^2-1)".Integrate("x")` | `integral(cos(x) / (x ^ 2 - 1), x)` | `Si` and `Ci` of `x - 1` and of `x + 1` |
1719+
| `"sin(x)/(1+x^2)".Integrate("x")` | `integral(sin(x) / (1 + x ^ 2), x)` | `Si` and `Ci` of `x - i` and of `x + i` |
1720+
| `"sin(c+d*x)/(a+b*x^2)".Integrate("x")` | `integral(sin(c + d * x) / (a + b * x ^ 2), x)` | `Si` and `Ci` of `d (x ∓ sqrt(-4 a b)/(2 b))` |
1721+
17071722
### The sine and cosine integrals are integrated to
17081723

17091724
`sin(x)/x` was left unintegrated. A polynomial in sines and cosines of a linear, beside a

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,6 +4151,18 @@ void Add(int k, bool isSine, Entity coefficient)
41514151
var linears = new List<(Entity Linear, int Power)>();
41524152
Entity? polynomial = null;
41534153
Entity? trigonometric = null;
4154+
void AddALinear(Entity linear, int power)
4155+
{
4156+
var at = linears.FindIndex(pair => pair.Linear == linear);
4157+
if (at < 0)
4158+
linears.Add((linear, power));
4159+
else
4160+
linears[at] = (linear, linears[at].Power + power);
4161+
}
4162+
// x - r, written x + |r| where the root is a negative number: x + 1 for the root -1.
4163+
Entity LessTheRoot(Entity root) =>
4164+
root is Number.Complex { RealPart.IsNegative: true } or Number.Complex { RealPart.EDecimal.IsZero: true, ImaginaryPart.IsNegative: true }
4165+
? x + (-root).InnerSimplified : (x - root).InnerSimplified;
41544166
foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr))
41554167
{
41564168
if (!factor.ContainsNode(x))
@@ -4180,13 +4192,23 @@ void Add(int k, bool isSine, Entity coefficient)
41804192
// A linear, or a whole power of one, below the bar or as a negative power.
41814193
if (exponent < 0)
41824194
{
4183-
if (!TreeAnalyzer.TryGetPolyLinear(@base, x, out var slopeOfIt, out _) || TreeAnalyzer.IsZero(slopeOfIt))
4184-
return null;
4185-
var at = linears.FindIndex(pair => pair.Linear == @base);
4186-
if (at < 0)
4187-
linears.Add((@base, -exponent));
4195+
if (TreeAnalyzer.TryGetPolyLinear(@base, x, out var slopeOfIt, out _) && !TreeAnalyzer.IsZero(slopeOfIt))
4196+
AddALinear(@base, -exponent);
4197+
// A quadratic is its leading coefficient times the linears of its two roots,
4198+
// complex where its discriminant is negative: `sin(c + d x)/(a + b x^2)` is a
4199+
// sum over `x -/+ sqrt(-a/b)`, each the one-linear question, and the sine and
4200+
// cosine integrals of the two conjugate arguments add up to a real answer.
4201+
else if (TreeAnalyzer.TryGetPolyQuadratic(@base, x, out var leading, out var middle, out var last) && !TreeAnalyzer.IsZero(leading))
4202+
{
4203+
var discriminant = MathS.Sqrt(middle * middle - 4 * leading * last);
4204+
var first = ((-middle + discriminant) / (2 * leading)).InnerSimplified;
4205+
var second = ((-middle - discriminant) / (2 * leading)).InnerSimplified;
4206+
constant /= MathS.Pow(leading, -exponent);
4207+
AddALinear(LessTheRoot(first), -exponent);
4208+
AddALinear(LessTheRoot(second), -exponent);
4209+
}
41884210
else
4189-
linears[at] = (@base, linears[at].Power - exponent);
4211+
return null;
41904212
continue;
41914213
}
41924214
if (TreeAnalyzer.TryGetPolynomial(factor, x, out var monomials) && monomials.Keys.All(degree => degree.Sign >= 0 && degree.CompareTo(EInteger.FromInt32(12)) <= 0))

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,22 @@ public void AskingTwiceAnswersTheSame(string integrand)
9595
}
9696

9797
/// <summary>
98-
/// An integrand with no elementary antiderivative, which runs every solver to exhaustion
99-
/// and so pays the full cost of the search. It took <b>115 seconds</b> before the answers
100-
/// were kept, and about one after.
98+
/// An integrand no rule answers, which runs every solver to exhaustion and so pays the
99+
/// full cost of the search: a sine over a cubic, whose roots the sine and cosine integrals
100+
/// would have to be written over. The quadratic <c>sin(x)/(x^2 + 1)^2</c>, which this
101+
/// asked before the sine and cosine integrals were split over a quadratic's two roots,
102+
/// took <b>115 seconds</b> before the answers were kept, and about one after.
101103
/// </summary>
102104
/// <remarks>
103-
/// The bound is two orders of magnitude above what it now takes and a quarter of what it
104-
/// used to, so it is a guard against the regression rather than a measurement of the
105-
/// machine. A timing assertion tight enough to be a benchmark would only flake.
105+
/// The bound is two orders of magnitude above what it takes and a quarter of what the
106+
/// quadratic used to, so it is a guard against the regression rather than a measurement of
107+
/// the machine. A timing assertion tight enough to be a benchmark would only flake.
106108
/// </remarks>
107109
[Fact]
108110
public void AnIntegralWithNoAnswerStillFinishesQuickly()
109111
{
110112
var watch = Stopwatch.StartNew();
111-
var answer = "sin(x) / (x ^ 2 + 1) ^ 2".ToEntity().Integrate("x").Simplify();
113+
var answer = "sin(x) / (x ^ 3 + 1) ^ 2".ToEntity().Integrate("x").Simplify();
112114
watch.Stop();
113115

114116
Assert.Contains("integral(", answer.Stringize());

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ public void ASquaredLogarithmTimesAPolynomial(string integrand)
9393

9494
/// <summary>
9595
/// The measure that bounds the recursion, asserted where it is load-bearing.
96-
/// <c>sin(x)/(x^2 + 1)^2</c> has no elementary antiderivative, so every solver runs to
97-
/// exhaustion on it and it pays the full cost of the search.
96+
/// <c>sin(x)/(x^3 + 1)^2</c> has no antiderivative the rules write -- the sine and cosine
97+
/// integrals would need the cubic's roots -- so every solver runs to exhaustion on it and
98+
/// it pays the full cost of the search. The 83 seconds below were the quadratic
99+
/// <c>sin(x)/(x^2 + 1)^2</c>'s, which is answered over its two roots now.
98100
/// </summary>
99101
/// <remarks>
100102
/// The bound is a wall that cannot fire on a slow runner — the work is about a second —
@@ -107,7 +109,7 @@ public void ASquaredLogarithmTimesAPolynomial(string integrand)
107109
public void AnUnanswerableIntegralDoesNotPayForTheRecursion()
108110
{
109111
var watch = Stopwatch.StartNew();
110-
var answer = "sin(x) / (x ^ 2 + 1) ^ 2".ToEntity().Integrate("x");
112+
var answer = "sin(x) / (x ^ 3 + 1) ^ 2".ToEntity().Integrate("x");
111113
watch.Stop();
112114

113115
Assert.Contains("integral(", answer.Stringize());

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ public void APowerOfASineOrACosineOverAPowerOfALinear(string integrand)
9191
public void OverSeveralLinears(string integrand)
9292
=> DifferentiatesBack(integrand, AroundZero, Pins);
9393

94+
/// <summary>
95+
/// A quadratic below the bar is its leading coefficient times the linears of its two
96+
/// roots, complex where its discriminant is negative, and the sine and cosine integrals of
97+
/// the two conjugate arguments add up to a real answer. Rubi's 4.1.11 and 4.7.7,
98+
/// <c>sin(c + d x)/(a + b x^2)</c> and <c>sin(a + b x)/(c + d x + e x^2)</c>.
99+
/// </summary>
100+
[Theory]
101+
[InlineData("sin(x)/(1 + x^2)")]
102+
[InlineData("cos(x)/(x^2 - 4)")]
103+
[InlineData("x*sin(2*x)/(x^2 + x + 1)")]
104+
[InlineData("sin(c + d*x)/(a + b*x^2)")]
105+
[InlineData("cos(x)/(x*(1 + x^2))")]
106+
[InlineData("sin(x)/(1 + x^2)^2")]
107+
public void OverAQuadratic(string integrand)
108+
=> DifferentiatesBack(integrand, AroundZero, Pins);
109+
94110
/// <summary>
95111
/// An argument <c>a + b x^r</c> beside a power of <c>x</c> is the same question under
96112
/// <c>u = x^r</c>, for a whole, a fractional, a negative and a symbolic <c>r</c>. Rubi's

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void TheAnswerIsInTheSineAndCosine()
9696
[InlineData("tan(x)/x")]
9797
[InlineData("x/sin(x)")]
9898
[InlineData("x*tan(x)")]
99-
[InlineData("x*sin(x)/(1 + x^2)")]
99+
[InlineData("x*sin(x)/(1 + x^3)")]
100100
public void ANonElementaryOneIsDeclined(string integrand)
101101
=> Assert.Contains("integral(", integrand.ToEntity().Integrate("x").Stringize());
102102
}

0 commit comments

Comments
 (0)