Skip to content

Commit 375fbb4

Browse files
Integrate an exponential over a quadratic with a double root over that linear twice (#2008)
SolveAnExponentialOverSeveralLinears' quadratic branch (#1708) applied the quadratic formula and never asked whether the discriminant is zero as a value: e^(-t)/(a^2 + 2 a b t + b^2 t^2), which t = ln(c x) makes of 1/(x^2 (a + b ln(c x))^2), came back over two "different" roots carrying sqrt((2 a b)^2 - 4 b^2 a^2), merged by TrySplitOverWrittenFactors with the root still inside -- an answer whose derivative had no value at any point. A discriminant zero by PartialFractions.IsZeroAsAValue now takes the repeated root, the linear x + m/(2 l) twice, as the trigonometric twin does since #1880; a lone double root goes to the one-linear rules as a polynomial over its power. 1/(x^2 (a + b ln(c x))^2) is c e^(a/b) (-e^(-L)/L - Ei(-L))/b^2, L = ln(c x) + a/b, Rubi's 3.1.2:95 at n = 1; 23 integrals whose answer had no value anywhere -- logarithm squares for m = 2..4 and n = 1, 2, and exponentials and hyperbolic functions over a perfect-square quadratic -- now differentiate back at four sign patterns. All 169 rows of 3.1.2 and 1,247 neighbours of families 2, 3 and 6 answer as before, character for character. 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 08a3c49 commit 375fbb4

3 files changed

Lines changed: 132 additions & 3 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7131,6 +7131,28 @@ was declined. They divide by the denominator as it is written now. Rubi's 6.2.2,
71317131
| `"cosh(c + d*x)/(a + b*x^3)".ToEntity().Integrate("x")` | `integral(...)` | `Chi` and `Shi` the same |
71327132
| `"e^x/(a + b*x^4)".ToEntity().Integrate("x")` | `integral(...)` | `Ei` of `x` less each root of `a + b x^4` |
71337133

7134+
### An exponential over a quadratic with a double root is integrated over that linear twice
7135+
7136+
**Answers where there were none.** `e^x/(a x^2 + 2 a x + a)` was declined, and so was
7137+
`1/(x^2 (a + b ln(c x))^2)`, which is `c e^(-t)/(a^2 + 2 a b t + b^2 t^2)` under `t = ln(c x)`. The
7138+
rule for an exponential or `sinh` and `cosh` over a quadratic split it over the two roots of the
7139+
quadratic formula, and did not see that a discriminant written `(2 a b)^2 - 4 b^2 a^2` is zero.
7140+
**The unreleased master answered these** with an expression carrying the square root of that zero,
7141+
and the derivative of that expression had no value at any point. A quadratic whose discriminant is
7142+
zero as a value is now one linear twice, as the rule for a sine or a cosine already reads it, and
7143+
the quotient goes onto the exponential integral: `1/(x^2 (a + b ln(c x))^2)` is
7144+
`-c e^(a/b) Ei(-(a + b ln(c x))/b)/b^2 - 1/(b x (a + b ln(c x)))`, which is Rubi's 3.1.2 with
7145+
`n = 1` ([#1879](https://github.com/asc-community/AngouriMath/issues/1879)).
7146+
7147+
| Input | Was (2.5.0) | Now |
7148+
|---|---|---|
7149+
| `"1/(x^2*(a+b*ln(c*x))^2)".ToEntity().Integrate("x")` | `integral(...)` | 133 characters |
7150+
| `"1/(x^3*(a+b*ln(c*x))^2)".ToEntity().Integrate("x")` | `integral(...)` | 168 characters |
7151+
| `"1/(x^2*(a+b*ln(c*x^2))^2)".ToEntity().Integrate("x")` | `integral(...)` | 189 characters |
7152+
| `"e^x/(a*x^2+2*a*x+a)".ToEntity().Integrate("x")` | `integral(...)` | 60 characters |
7153+
| `"cosh(x)/(a*x^2+2*a*x+a)".ToEntity().Integrate("x")` | `integral(...)` | 140 characters |
7154+
| `"e^x/(x*(a*x^2+2*a*x+a))".ToEntity().Integrate("x")` | `integral(...)` | 76 characters |
7155+
71347156
### An inverse trigonometric function below the bar is integrated to the sine and cosine integrals
71357157

71367158
`1/arcsin(x)` was left unintegrated. Under the substitution that undoes the inverse function,

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8875,6 +8875,7 @@ bool Read(Entity factor, int times)
88758875
Entity? exponentials = null;
88768876
// The denominator as it is written, each quadratic monic, for the division.
88778877
Entity written = Number.Integer.One;
8878+
var aDoubleRoot = false;
88788879
void AddALinear(Entity linear, int power)
88798880
{
88808881
var at = linears.FindIndex(pair => pair.Linear == linear);
@@ -8906,6 +8907,19 @@ void AddALinear(Entity linear, int power)
89068907
// question, and the integrals of the two conjugate arguments add up to a real answer.
89078908
if (exponent < 0 && TreeAnalyzer.TryGetPolyQuadratic(@base, x, out var leading, out var middle, out var last) && !TreeAnalyzer.IsZero(leading))
89088909
{
8910+
// A double root is one linear twice, as the trigonometric rule reads it: split
8911+
// over two roots that coincide, `e^(-t)/(a^2 + 2 a b t + b^2 t^2)` was answered
8912+
// with `sqrt((2 a b)^2 - 4 a^2 b^2)` in it, and its derivative had no value.
8913+
// https://github.com/asc-community/AngouriMath/issues/1879
8914+
if (Functions.PartialFractions.IsZeroAsAValue(middle * middle - 4 * leading * last))
8915+
{
8916+
var twice = (x + Functions.PartialFractions.InLowestTermsOverTheSymbols(middle / (2 * leading))).InnerSimplified;
8917+
constant /= MathS.Pow(leading, -exponent);
8918+
AddALinear(twice, -2 * exponent);
8919+
written *= MathS.Pow(twice, -2 * exponent);
8920+
aDoubleRoot = true;
8921+
continue;
8922+
}
89098923
var discriminant = MathS.Sqrt(middle * middle - 4 * leading * last);
89108924
constant /= MathS.Pow(leading, -exponent);
89118925
AddALinear(LessTheRoot(((-middle + discriminant) / (2 * leading)).InnerSimplified, x), -exponent);
@@ -8936,16 +8950,22 @@ void AddALinear(Entity linear, int power)
89368950
}
89378951
return null;
89388952
}
8939-
if (exponentials is null || linears.Count < 2 || linears.Count > 4 || linears.Sum(pair => pair.Power) > 12)
8953+
// One linear alone is the one-linear rules' question, unless it is a quadratic's double
8954+
// root, which they do not read.
8955+
if (exponentials is null || linears.Count < (aDoubleRoot ? 1 : 2) || linears.Count > 4 || linears.Sum(pair => pair.Power) > 12)
89408956
return null;
89418957
// Exponentials of linears only, which is what the one-linear rules read: split, a term of
89428958
// `sinh(sqrt((1 - a x)/(1 + a x)))/(1 - a^2 x^2)` goes to the whole integrator, and the
89438959
// substitution that answers the question whole in a tenth of a second is not reached.
89448960
if (!Sumf.LinearChildren(exponentials.Expand()).All(term => ReadAnExponentialTerm(term, x) is not null))
89458961
return null;
8946-
// Over each linear by partial fractions, as the trigonometric rule does it.
8962+
// Over each linear by partial fractions, as the trigonometric rule does it; a double root
8963+
// alone is one term already, which the split over one factor declines.
89478964
var denominator = linears.Aggregate((Entity)Number.Integer.One, (product, pair) => product * MathS.Pow(pair.Linear, pair.Power));
8948-
if (OverEachLinear(polynomial ?? Number.Integer.One, written, denominator, linears.Sum(pair => pair.Power), x) is not { } terms)
8965+
var terms = linears.Count == 1
8966+
? new List<Entity> { (polynomial ?? Number.Integer.One) / denominator }
8967+
: OverEachLinear(polynomial ?? Number.Integer.One, written, denominator, linears.Sum(pair => pair.Power), x);
8968+
if (terms is null)
89498969
return null;
89508970
Entity sum = Number.Integer.Zero;
89518971
foreach (var term in terms)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
/// An exponential over a quadratic whose discriminant is zero as a value and not as written,
16+
/// <c>a x^2 + 2 a x + a</c>, or <c>a^2 + 2 a b t + b^2 t^2</c>, which is what
17+
/// <c>1/(x^2 (a + b ln(c x))^2)</c> is under <c>t = ln(c x)</c>. Split over two roots that
18+
/// coincide, the answer carried <c>sqrt((2 a b)^2 - 4 a^2 b^2)</c>, and its derivative had no
19+
/// value at any point. Each is answered with an antiderivative that differentiates back
20+
/// wherever the integrand is real, or left unevaluated, and never answered with no value.
21+
/// <a href="https://github.com/asc-community/AngouriMath/issues/1879">#1879</a>
22+
/// </summary>
23+
[Trait("Area", "Calculus")]
24+
public sealed class AnExponentialOverAQuadraticWithADoubleRootIntegralTest
25+
{
26+
private static readonly double[] Positive = { 0.31, 0.57, 0.83, 1.29, 1.77, 2.41 };
27+
private static readonly double[] BothSides = { -2.3, -1.7, -0.6, -0.3, 0.4, 1.9 };
28+
29+
private static void HasAValueAndDifferentiatesBack(string integrand, Entity integral, double[] points, params (string, double)[] pins)
30+
{
31+
using var _ = MathS.Settings.DowncastingEnabled.Set(false);
32+
var derivative = integral.Substitute("C", 0).Differentiate("x");
33+
Entity original = integrand.ToEntity();
34+
foreach (var (name, value) in pins)
35+
{
36+
derivative = derivative.Substitute(name, value);
37+
original = original.Substitute(name, value);
38+
}
39+
var compared = 0;
40+
foreach (var at in points)
41+
{
42+
var want = original.Substitute("x", at).EvalNumerical();
43+
if (want.IsNaN)
44+
continue;
45+
var got = derivative.Substitute("x", at).EvalNumerical();
46+
Assert.False(got.IsNaN,
47+
$"d/dx of the antiderivative of {integrand} has no value at x = {at}, where the integrand is {want}");
48+
compared++;
49+
var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart);
50+
var scale = Math.Max(1.0, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart));
51+
Assert.True(difference / scale < 1e-8,
52+
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
53+
}
54+
Assert.True(compared >= 3, $"only {compared} of {points.Length} points were comparable for {integrand}");
55+
}
56+
57+
[Theory]
58+
[InlineData("1/(x^2*(a+b*ln(c*x))^2)", true)]
59+
[InlineData("1/(x^3*(a+b*ln(c*x))^2)", true)]
60+
[InlineData("1/(x^4*(a+b*ln(c*x))^2)", true)]
61+
[InlineData("1/(x^2*(a+b*ln(c*x))^3)", true)]
62+
[InlineData("1/(x^2*(a+b*ln(c*x^2))^2)", true)]
63+
[InlineData("1/(x^2*(a+b*ln(c*x^n))^2)", true)]
64+
[InlineData("1/(x^(3/2)*(a+b*ln(c*x))^2)", true)]
65+
[InlineData("1/(x^2*(a+b*ln(c/x))^2)", true)]
66+
[InlineData("ln(c*x)/(x^2*(a+b*ln(c*x))^2)", true)]
67+
[InlineData("e^x/(a*x^2+2*a*x+a)", false)]
68+
[InlineData("cosh(x)/(a*x^2+2*a*x+a)", false)]
69+
[InlineData("(e^x+e^(2*x))/(a*x^2+2*a*x+a)", false)]
70+
[InlineData("e^x/(a*x^2+2*a*b*x+a*b^2)", false)]
71+
[InlineData("e^x/((c+d)*x^2+2*(c+d)*x+(c+d))", false)]
72+
[InlineData("e^x/(x*(a*x^2+2*a*x+a))", false)]
73+
[InlineData("sinh(x)/(x^2*(a*x^2+2*a*x+a))", false)]
74+
[InlineData("e^x/((x-1)*(a*x^2+2*a*x+a)*(x+2))", false)]
75+
public void IsAnsweredWithAValueOrLeftUnevaluated(string integrand, bool logarithmic)
76+
{
77+
var integral = integrand.ToEntity().Integrate("x");
78+
if (integral.Stringize().Contains("integral("))
79+
return;
80+
var points = logarithmic ? Positive : BothSides;
81+
HasAValueAndDifferentiatesBack(integrand, integral, points, ("a", 0.7), ("b", 1.3), ("c", 1.1), ("d", 0.9), ("n", 2));
82+
HasAValueAndDifferentiatesBack(integrand, integral, points, ("a", 0.7), ("b", -1.3), ("c", 1.1), ("d", 0.9), ("n", 2));
83+
HasAValueAndDifferentiatesBack(integrand, integral, points, ("a", -0.7), ("b", 1.3), ("c", 2.5), ("d", -0.4), ("n", 3));
84+
HasAValueAndDifferentiatesBack(integrand, integral, points, ("a", -0.7), ("b", -1.3), ("c", 2.5), ("d", -0.4), ("n", 3));
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)