From a5664c3caa2fb78dbaebd5bebc0fcab2e8c3d876 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Sat, 3 Oct 2026 03:56:21 +0000 Subject: [PATCH 1/2] An exponential or a hyperbolic function over a quadratic is split at the quadratic's roots The rule for an exponential, or sinh and cosh, over several linears read linears only, so cosh(c + d x)/(a + b x^2) was declined where sin(c + d x)/(a + b x^2) was answered: the rule for a sine or a cosine writes a quadratic as its leading coefficient times the linears of its two roots. The exponential rule writes it the same way now, and takes exponentials of linears only, which is what the terms it splits into go to. Both rules divided a numerator past the degree by the linears of the roots, which with a symbol in the quadratic left the remainder in the squares of its roots; they divide by the quadratic as written now, in one helper they share. Part of https://github.com/asc-community/AngouriMath/issues/718 Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 26 +++ .../Integration/IndefiniteIntegralSolver.cs | 153 +++++++++++------- .../HyperbolicIntegralIntegrationTest.cs | 31 ++++ .../TrigonometricIntegralIntegrationTest.cs | 6 +- 4 files changed, 154 insertions(+), 62 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index d036a8063..1b18b3773 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -2762,6 +2762,32 @@ measured on a build, `v2.5.0` against this change. | `"x^3*e^(2*x)/((x+1)*(x-2))".Integrate("x")` | `integral(x ^ 3 * e ^ (2 * x) / ((x + 1) * (x - 2)), x)` | `e ^ (2 * x) * (-1/4 + 1/2 * x) + e ^ (2 * x) / 2 + 1/3 * e ^ (-2) * Ei(2 * (x + 1)) + 8/3 * e ^ 4 * Ei(2 * (x - 2)) + C` | | `"x*sin(x)/((c+d*x)*(x-2))".Integrate("x")` | `integral(x * sin(x) / ((c + d * x) * (x - 2)), x)` | in `Si` and `Ci` of `(c + d x)/d` and `x - 2` | +### An exponential or a hyperbolic function over a quadratic is split at the quadratic's roots + +**Answers where there were none.** `sin(c + d x)/(a + b x^2)` was answered, the rule for a sine or a +cosine writing the quadratic as its leading coefficient times the linears of its two roots, and +`cosh(c + d x)/(a + b x^2)` was declined, as was `e^x/(x^2 + x + 1)`: the rule for an exponential or +`sinh` and `cosh` over several linears read linears only. It writes a quadratic the same way now. +The roots are complex where the discriminant is negative, and the integrals at the two conjugate +arguments add up to a real answer. An exponential that is not of a linear is not split: +`sinh(sqrt((1 - a x)/(1 + a x)))/(1 - a^2 x^2)` is still answered whole, by its substitution. And +both rules divided a numerator past the degree by the linears of the roots, which with a symbol in +the quadratic left a remainder in the squares of its roots that nothing read: `x^2 sin(c + d x)/(a + b x^2)` +was declined. They divide by the quadratic as it is written now. Rubi's 6.2.2, +`(e x)^m (a + b x^n)^p cosh(c + d x)`, its 4.1.11, and exponentials in its 2.3 +([#718](https://github.com/asc-community/AngouriMath/issues/718)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"cosh(c + d*x)/(a + b*x^2)".ToEntity().Integrate("x")` | `integral(...)` | `Chi` and `Shi` of `d (x -/+ sqrt(-4 a b)/(2 b))` | +| `"x*sinh(c + d*x)/(a + b*x^2)".ToEntity().Integrate("x")` | `integral(...)` | the same | +| `"cosh(c + d*x)/(x*(a + b*x^2))".ToEntity().Integrate("x")` | `integral(...)` | the same, and `Chi(d x)` and `Shi(d x)` | +| `"x^3*cosh(c + d*x)/(a + b*x^2)".ToEntity().Integrate("x")` | `integral(...)` | `e^(c + d x)` and `e^(-c - d x)` times linears, and the same | +| `"cosh(x)/(x^2 - 2)".ToEntity().Integrate("x")` | `integral(...)` | `Chi` and `Shi` of `x -/+ sqrt(2)` | +| `"e^(c + d*x)/(a + b*x^2)".ToEntity().Integrate("x")` | `integral(...)` | `Ei` of `d (x -/+ sqrt(-4 a b)/(2 b))` | +| `"e^x/(x^2 + x + 1)".ToEntity().Integrate("x")` | `integral(...)` | `Ei` of `x + (1 -/+ sqrt(-3))/2` | +| `"x^2*sin(c + d*x)/(a + b*x^2)".ToEntity().Integrate("x")` | `integral(...)` | `cos(d x)` and `sin(d x)`, and `Si` and `Ci` of `d (x -/+ sqrt(-4 a b)/(2 b))` | + ### An inverse trigonometric function below the bar is integrated to the sine and cosine integrals `1/arcsin(x)` was left unintegrated. Under the substitution that undoes the inverse function, diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 261c1f821..6cd6e1b22 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -4343,7 +4343,8 @@ bool Read(Entity factor, int times) /// . e^x/(x (x + 1)) is /// e^x/x - e^x/(x + 1), which is Ei(x) - Ei(x + 1)/e; the trigonometric rule /// splits the same way (). It is also what by parts leaves - /// of Ei(a + b x)/x^2, e^(a + b x)/((a + b x) x). + /// of Ei(a + b x)/x^2, e^(a + b x)/((a + b x) x). A quadratic below the bar is + /// the linears of its two roots: Rubi's 6.2.2, cosh(c + d x)/(a + b x^2). /// https://github.com/asc-community/AngouriMath/issues/1501 /// internal static Entity? SolveAnExponentialOverSeveralLinears(Entity expr, Entity.Variable x) @@ -4354,6 +4355,16 @@ bool Read(Entity factor, int times) var linears = new List<(Entity Linear, int Power)>(); Entity? polynomial = null; Entity? exponentials = null; + // The denominator as it is written, each quadratic monic, for the division. + Entity written = Number.Integer.One; + void AddALinear(Entity linear, int power) + { + var at = linears.FindIndex(pair => pair.Linear == linear); + if (at < 0) + linears.Add((linear, power)); + else + linears[at] = (linear, linears[at].Power + power); + } foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr)) { if (!factor.ContainsNode(x)) @@ -4367,11 +4378,21 @@ bool Read(Entity factor, int times) exponent = -exponent; if (exponent < 0 && TreeAnalyzer.TryGetPolyLinear(@base, x, out var slopeOfIt, out _) && !TreeAnalyzer.IsZero(slopeOfIt)) { - var at = linears.FindIndex(pair => pair.Linear == @base); - if (at < 0) - linears.Add((@base, -exponent)); - else - linears[at] = (@base, linears[at].Power - exponent); + AddALinear(@base, -exponent); + written *= MathS.Pow(@base, -exponent); + continue; + } + // A quadratic is its leading coefficient times the linears of its two roots, complex + // where its discriminant is negative, as the trigonometric rule writes it: + // `cosh(c + d x)/(a + b x^2)` is a sum over `x -/+ sqrt(-a/b)`, each the one-linear + // question, and the integrals of the two conjugate arguments add up to a real answer. + if (exponent < 0 && TreeAnalyzer.TryGetPolyQuadratic(@base, x, out var leading, out var middle, out var last) && !TreeAnalyzer.IsZero(leading)) + { + var discriminant = MathS.Sqrt(middle * middle - 4 * leading * last); + constant /= MathS.Pow(leading, -exponent); + AddALinear(LessTheRoot(((-middle + discriminant) / (2 * leading)).InnerSimplified, x), -exponent); + AddALinear(LessTheRoot(((-middle - discriminant) / (2 * leading)).InnerSimplified, x), -exponent); + written *= MathS.Pow(Monic(leading, middle, last, x), -exponent); continue; } if (underneath) @@ -4390,31 +4411,15 @@ bool Read(Entity factor, int times) } if (exponentials is null || linears.Count < 2 || linears.Count > 4 || linears.Sum(pair => pair.Power) > 12) return null; - // Over each linear by partial fractions, the polynomial part first, since the split is - // of a proper fraction -- as the trigonometric rule does it. Only where the fraction is - // not proper already: divided, `x` over `(c + d x)(x - 2)` came back as a quotient and a - // remainder `2 provided not c + d x = 0`, which nothing splits. + // Exponentials of linears only, which is what the one-linear rules read: split, a term of + // `sinh(sqrt((1 - a x)/(1 + a x)))/(1 - a^2 x^2)` goes to the whole integrator, and the + // substitution that answers the question whole in a tenth of a second is not reached. + if (!Sumf.LinearChildren(exponentials.Expand()).All(term => ReadAnExponentialTerm(term, x) is not null)) + return null; + // Over each linear by partial fractions, as the trigonometric rule does it. var denominator = linears.Aggregate((Entity)Number.Integer.One, (product, pair) => product * MathS.Pow(pair.Linear, pair.Power)); - Entity numerator = polynomial ?? Number.Integer.One; - var terms = new List(); - if (numerator.ContainsNode(x) - && TreeAnalyzer.TryGetPolynomial(numerator, x, out var monomialsAbove) - && monomialsAbove.Keys.Any(degree => degree.CompareTo(EInteger.FromInt32(linears.Sum(pair => pair.Power))) >= 0) - && TreeAnalyzer.PolynomialLongDivision(numerator, denominator, genericCase: true, inTermsOf: x) is var (quotient, remainder)) - { - if (!TreeAnalyzer.IsZero(quotient)) - terms.Add(quotient); - numerator = remainder is Divf(var left, _) ? left : (numerator - quotient * denominator).Expand().InnerSimplified; - } - if (!TreeAnalyzer.IsZero(numerator)) - { - if (!Functions.PartialFractions.TrySplitOverWrittenFactors(numerator, denominator, x, out var decomposition)) - return null; - var fractions = decomposition.InnerSimplified; - if (fractions is Divf(var over, var by) && !by.ContainsNode(x)) - fractions = Sumf.LinearChildren(over).Aggregate((Entity)Number.Integer.Zero, (all, one) => all + one / by); - terms.AddRange(Sumf.LinearChildren(fractions)); - } + if (OverEachLinear(polynomial ?? Number.Integer.One, written, denominator, linears.Sum(pair => pair.Power), x) is not { } terms) + return null; Entity sum = Number.Integer.Zero; foreach (var term in terms) { @@ -5116,6 +5121,52 @@ void Add(int k, bool isSine, Entity coefficient) return UnderAPowerOfTheVariable(expr, x, argument); } + // x - r, written x + |r| where the root is a negative number: x + 1 for the root -1. + private static Entity LessTheRoot(Entity root, Entity.Variable x) => + root is Number.Complex { RealPart.IsNegative: true } or Number.Complex { RealPart.EDecimal.IsZero: true, ImaginaryPart.IsNegative: true } + ? x + (-root).InnerSimplified : (x - root).InnerSimplified; + + // A quadratic divided by its leading coefficient, `x^2 + (b/a) x + c/a`, in the generic + // case: the division declines a divisor with a condition on it. + private static Entity Monic(Entity leading, Entity middle, Entity last, Entity.Variable x) => + Functions.PartialFractions.Bare((MathS.Sqr(x) + middle / leading * x + last / leading).InnerSimplified); + + /// + /// over a denominator as terms each over one linear: the + /// polynomial part first, divided by the denominator as it is , + /// and the proper rest split into partial fractions over , + /// the same denominator with each quadratic in it written as the linears of its roots. + /// Divided by those linears, `x^2` over `(x - r)(x + r)`, `r = sqrt(-a/b)`, left a remainder + /// in `r^2` that nothing read as `-a/b`. Only where the fraction is not proper already: + /// divided, `x` over `(c + d x)(x - 2)` came back as a quotient and a remainder + /// `2 provided not c + d x = 0`, which nothing splits. Null where the split declines. + /// + private static List? OverEachLinear(Entity numerator, Entity written, Entity overTheLinears, int degreeBelow, Entity.Variable x) + { + var terms = new List(); + if (numerator.ContainsNode(x) + && TreeAnalyzer.TryGetPolynomial(numerator, x, out var monomialsAbove) + && monomialsAbove.Keys.Any(degree => degree.CompareTo(EInteger.FromInt32(degreeBelow)) >= 0) + && TreeAnalyzer.PolynomialLongDivision(numerator, written, genericCase: true, inTermsOf: x) is var (quotient, remainder)) + { + if (!TreeAnalyzer.IsZero(quotient)) + terms.Add(quotient); + // The remainder comes over the divisor already. + numerator = remainder is Divf(var left, _) ? left : (numerator - quotient * written).Expand().InnerSimplified; + } + if (!TreeAnalyzer.IsZero(numerator)) + { + if (!Functions.PartialFractions.TrySplitOverWrittenFactors(numerator, overTheLinears, x, out var decomposition)) + return null; + // The sum of the fractions, over a constant it may come divided by. + var fractions = decomposition.InnerSimplified; + if (fractions is Divf(var over, var by) && !by.ContainsNode(x)) + fractions = Sumf.LinearChildren(over).Aggregate((Entity)Number.Integer.Zero, (all, one) => all + one / by); + terms.AddRange(Sumf.LinearChildren(fractions)); + } + return terms; + } + /// /// where the argument is /// , linear in . Two or more linears below @@ -5132,6 +5183,8 @@ void Add(int k, bool isSine, Entity coefficient) var linears = new List<(Entity Linear, int Power)>(); Entity? polynomial = null; Entity? trigonometric = null; + // The denominator as it is written, each quadratic monic, for the division. + Entity written = Number.Integer.One; void AddALinear(Entity linear, int power) { var at = linears.FindIndex(pair => pair.Linear == linear); @@ -5140,10 +5193,6 @@ void AddALinear(Entity linear, int power) else linears[at] = (linear, linears[at].Power + power); } - // x - r, written x + |r| where the root is a negative number: x + 1 for the root -1. - Entity LessTheRoot(Entity root) => - root is Number.Complex { RealPart.IsNegative: true } or Number.Complex { RealPart.EDecimal.IsZero: true, ImaginaryPart.IsNegative: true } - ? x + (-root).InnerSimplified : (x - root).InnerSimplified; foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr)) { if (!factor.ContainsNode(x)) @@ -5174,7 +5223,10 @@ Entity LessTheRoot(Entity root) => if (exponent < 0) { if (TreeAnalyzer.TryGetPolyLinear(@base, x, out var slopeOfIt, out _) && !TreeAnalyzer.IsZero(slopeOfIt)) + { AddALinear(@base, -exponent); + written *= MathS.Pow(@base, -exponent); + } // A quadratic is its leading coefficient times the linears of its two roots, // complex where its discriminant is negative: `sin(c + d x)/(a + b x^2)` is a // sum over `x -/+ sqrt(-a/b)`, each the one-linear question, and the sine and @@ -5185,8 +5237,9 @@ Entity LessTheRoot(Entity root) => var first = ((-middle + discriminant) / (2 * leading)).InnerSimplified; var second = ((-middle - discriminant) / (2 * leading)).InnerSimplified; constant /= MathS.Pow(leading, -exponent); - AddALinear(LessTheRoot(first), -exponent); - AddALinear(LessTheRoot(second), -exponent); + AddALinear(LessTheRoot(first, x), -exponent); + AddALinear(LessTheRoot(second, x), -exponent); + written *= MathS.Pow(Monic(leading, middle, last, x), -exponent); } else return null; @@ -5206,32 +5259,10 @@ Entity LessTheRoot(Entity root) => return AgainstAPowerOfALinear(polynomial, linears[0].Linear, linears[0].Power, angles, argument, x, needsAnIntegral: true) is var (one, _) && one is not null ? Functions.PartialFractions.Bare((constant * one).InnerSimplified) : null; - // Over each linear by partial fractions, and each term the one-linear question; the - // polynomial part first, since the split is of a proper fraction -- and only where it is - // not proper already, as in SolveAnExponentialOverSeveralLinears. + // Over each linear by partial fractions, and each term the one-linear question. var denominator = linears.Aggregate((Entity)Number.Integer.One, (product, pair) => product * MathS.Pow(pair.Linear, pair.Power)); - Entity numerator = polynomial ?? Number.Integer.One; - var terms = new List(); - if (numerator.ContainsNode(x) - && TreeAnalyzer.TryGetPolynomial(numerator, x, out var monomialsAbove) - && monomialsAbove.Keys.Any(degree => degree.CompareTo(EInteger.FromInt32(linears.Sum(pair => pair.Power))) >= 0) - && TreeAnalyzer.PolynomialLongDivision(numerator, denominator, genericCase: true, inTermsOf: x) is var (quotient, remainder)) - { - if (!TreeAnalyzer.IsZero(quotient)) - terms.Add(quotient); - // The remainder comes over the divisor already. - numerator = remainder is Divf(var left, _) ? left : (numerator - quotient * denominator).Expand().InnerSimplified; - } - if (!TreeAnalyzer.IsZero(numerator)) - { - if (!Functions.PartialFractions.TrySplitOverWrittenFactors(numerator, denominator, x, out var decomposition)) - return null; - // The sum of the fractions, over a constant it may come divided by. - var fractions = decomposition.InnerSimplified; - if (fractions is Divf(var over, var by) && !by.ContainsNode(x)) - fractions = Sumf.LinearChildren(over).Aggregate((Entity)Number.Integer.Zero, (all, one) => all + one / by); - terms.AddRange(Sumf.LinearChildren(fractions)); - } + if (OverEachLinear(polynomial ?? Number.Integer.One, written, denominator, linears.Sum(pair => pair.Power), x) is not { } terms) + return null; Entity sum = Number.Integer.Zero; var special = false; foreach (var term in terms) diff --git a/Sources/Tests/UnitTests/Calculus/HyperbolicIntegralIntegrationTest.cs b/Sources/Tests/UnitTests/Calculus/HyperbolicIntegralIntegrationTest.cs index 7b7282918..21a5bc619 100644 --- a/Sources/Tests/UnitTests/Calculus/HyperbolicIntegralIntegrationTest.cs +++ b/Sources/Tests/UnitTests/Calculus/HyperbolicIntegralIntegrationTest.cs @@ -78,6 +78,37 @@ public void ASumOfExponentialsOverAPowerOfALinear(string integrand) public void ASumOfExponentialsOverSeveralLinears(string integrand) => DifferentiatesBack(integrand, AroundZero, Pins); + /// + /// And over a quadratic, which is the linears of its two roots, complex where its + /// discriminant is negative, the integrals of the two conjugate arguments adding up to a + /// real answer. Rubi's 6.2.2, cosh(c + d x)/(a + b x^2); a numerator past the degree + /// is divided by the quadratic as it is written. + /// + [Theory] + [InlineData("cosh(c + d*x)/(a + b*x^2)")] + [InlineData("x^2*cosh(c + d*x)/(a + b*x^2)")] + [InlineData("x^3*cosh(c + d*x)/(a + b*x^2)")] + [InlineData("x^2*e^(c + d*x)/(a + b*x^2)")] + [InlineData("sinh(c + d*x)/(a - b*x^2)")] + [InlineData("x*sinh(c + d*x)/(a + b*x^2)")] + [InlineData("cosh(c + d*x)/(x*(a + b*x^2))")] + [InlineData("x^2*cosh(c + d*x)/(a + b*x^2)^2")] + [InlineData("cosh(x)/(x^2 - 2)")] + [InlineData("e^x/(x^2 + x + 1)")] + public void ASumOfExponentialsOverAQuadratic(string integrand) + => DifferentiatesBack(integrand, AroundZero, Pins); + + /// + /// An exponential of something other than a linear is not split over the linears below + /// it: sinh(sqrt((1 - a x)/(1 + a x)))/(1 - a^2 x^2) is a substitution's, answered + /// whole, where each term of the split would go to the whole integrator. + /// + [Theory] + [InlineData("sinh(sqrt(1 - a*x)/sqrt(1 + a*x))/(1 - a^2*x^2)")] + [InlineData("cosh(sqrt(1 - a*x)/sqrt(1 + a*x))^3/(1 - a^2*x^2)")] + public void AnExponentialOfSomethingElseIsNotSplit(string integrand) + => DifferentiatesBack(integrand, AroundZero, Pins); + /// /// An inverse hyperbolic tangent below the bar, beside a whole power of 1 - a^2 x^2: /// under x = tanh(u)/a it is a polynomial in sinh(u) and cosh(u) over diff --git a/Sources/Tests/UnitTests/Calculus/TrigonometricIntegralIntegrationTest.cs b/Sources/Tests/UnitTests/Calculus/TrigonometricIntegralIntegrationTest.cs index 478d248c0..1be53f52d 100644 --- a/Sources/Tests/UnitTests/Calculus/TrigonometricIntegralIntegrationTest.cs +++ b/Sources/Tests/UnitTests/Calculus/TrigonometricIntegralIntegrationTest.cs @@ -97,7 +97,9 @@ public void OverSeveralLinears(string integrand) /// A quadratic below the bar is its leading coefficient times the linears of its two /// roots, complex where its discriminant is negative, and the sine and cosine integrals of /// the two conjugate arguments add up to a real answer. Rubi's 4.1.11 and 4.7.7, - /// sin(c + d x)/(a + b x^2) and sin(a + b x)/(c + d x + e x^2). + /// sin(c + d x)/(a + b x^2) and sin(a + b x)/(c + d x + e x^2). A numerator past + /// the degree is divided by the quadratic as it is written, since the remainder of a division + /// by the linears of symbolic roots was left in their squares. /// [Theory] [InlineData("sin(x)/(1 + x^2)")] @@ -106,6 +108,8 @@ public void OverSeveralLinears(string integrand) [InlineData("sin(c + d*x)/(a + b*x^2)")] [InlineData("cos(x)/(x*(1 + x^2))")] [InlineData("sin(x)/(1 + x^2)^2")] + [InlineData("x^2*sin(c + d*x)/(a + b*x^2)")] + [InlineData("x^3*cos(c + d*x)/(a + b*x^2)")] public void OverAQuadratic(string integrand) => DifferentiatesBack(integrand, AroundZero, Pins); From bcbc4c060a4ea1fc5948d6d7d3fa5ffa0e45695d Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Sat, 3 Oct 2026 04:10:52 +0000 Subject: [PATCH 2/2] A binomial past the quadratic below the bar is split at its roots too a + b x^3 and a + b x^4 below an exponential, a sinh or cosh, or a sine or cosine of a linear are written as their leading coefficient times the linears of their roots, (a/b)^(1/n) times the n-th roots of -1, as a quadratic is: sin(c + d x)/(a + b x^3) is a sum of sine and cosine integrals at the three roots. Rubi's 4.1.11 and 6.2.2 hold twenty of each. x sin(x)/(1 + x^3) is answered so, and the tower ansatz's row of what nothing reads moves to x sin(x)/(1 + x + x^3). Part of https://github.com/asc-community/AngouriMath/issues/718 Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 14 ++++--- .../Integration/IndefiniteIntegralSolver.cs | 37 +++++++++++++++++++ .../HyperbolicIntegralIntegrationTest.cs | 13 +++++++ .../TrigonometricIntegralIntegrationTest.cs | 12 ++++-- .../Calculus/TrigonometricTowerAnsatzTest.cs | 2 +- 5 files changed, 69 insertions(+), 9 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 1b18b3773..1474d1dbd 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -2762,18 +2762,19 @@ measured on a build, `v2.5.0` against this change. | `"x^3*e^(2*x)/((x+1)*(x-2))".Integrate("x")` | `integral(x ^ 3 * e ^ (2 * x) / ((x + 1) * (x - 2)), x)` | `e ^ (2 * x) * (-1/4 + 1/2 * x) + e ^ (2 * x) / 2 + 1/3 * e ^ (-2) * Ei(2 * (x + 1)) + 8/3 * e ^ 4 * Ei(2 * (x - 2)) + C` | | `"x*sin(x)/((c+d*x)*(x-2))".Integrate("x")` | `integral(x * sin(x) / ((c + d * x) * (x - 2)), x)` | in `Si` and `Ci` of `(c + d x)/d` and `x - 2` | -### An exponential or a hyperbolic function over a quadratic is split at the quadratic's roots +### An exponential, hyperbolic or trigonometric function over a quadratic or a binomial is split at its roots **Answers where there were none.** `sin(c + d x)/(a + b x^2)` was answered, the rule for a sine or a cosine writing the quadratic as its leading coefficient times the linears of its two roots, and `cosh(c + d x)/(a + b x^2)` was declined, as was `e^x/(x^2 + x + 1)`: the rule for an exponential or -`sinh` and `cosh` over several linears read linears only. It writes a quadratic the same way now. -The roots are complex where the discriminant is negative, and the integrals at the two conjugate -arguments add up to a real answer. An exponential that is not of a linear is not split: +`sinh` and `cosh` over several linears read linears only. It writes a quadratic the same way now, +and both rules write a binomial `a + b x^3` or `a + b x^4` as the linears of its roots, +`(a/b)^(1/n)` times the n-th roots of -1. The roots are complex where the discriminant is negative, +and the integrals at conjugate arguments add up to a real answer. An exponential that is not of a linear is not split: `sinh(sqrt((1 - a x)/(1 + a x)))/(1 - a^2 x^2)` is still answered whole, by its substitution. And both rules divided a numerator past the degree by the linears of the roots, which with a symbol in the quadratic left a remainder in the squares of its roots that nothing read: `x^2 sin(c + d x)/(a + b x^2)` -was declined. They divide by the quadratic as it is written now. Rubi's 6.2.2, +was declined. They divide by the denominator as it is written now. Rubi's 6.2.2, `(e x)^m (a + b x^n)^p cosh(c + d x)`, its 4.1.11, and exponentials in its 2.3 ([#718](https://github.com/asc-community/AngouriMath/issues/718)). @@ -2787,6 +2788,9 @@ was declined. They divide by the quadratic as it is written now. Rubi's 6.2.2, | `"e^(c + d*x)/(a + b*x^2)".ToEntity().Integrate("x")` | `integral(...)` | `Ei` of `d (x -/+ sqrt(-4 a b)/(2 b))` | | `"e^x/(x^2 + x + 1)".ToEntity().Integrate("x")` | `integral(...)` | `Ei` of `x + (1 -/+ sqrt(-3))/2` | | `"x^2*sin(c + d*x)/(a + b*x^2)".ToEntity().Integrate("x")` | `integral(...)` | `cos(d x)` and `sin(d x)`, and `Si` and `Ci` of `d (x -/+ sqrt(-4 a b)/(2 b))` | +| `"sin(c + d*x)/(a + b*x^3)".ToEntity().Integrate("x")` | `integral(...)` | `Si` and `Ci` of `d` times `x` less each root of `a + b x^3` | +| `"cosh(c + d*x)/(a + b*x^3)".ToEntity().Integrate("x")` | `integral(...)` | `Chi` and `Shi` the same | +| `"e^x/(a + b*x^4)".ToEntity().Integrate("x")` | `integral(...)` | `Ei` of `x` less each root of `a + b x^4` | ### An inverse trigonometric function below the bar is integrated to the sine and cosine integrals diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 6cd6e1b22..b4aa050aa 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -4395,6 +4395,15 @@ void AddALinear(Entity linear, int power) written *= MathS.Pow(Monic(leading, middle, last, x), -exponent); continue; } + // And a binomial past the quadratic the linears of its roots: `cosh(c + d x)/(a + b x^3)`. + if (exponent < 0 && TheRootsOfABinomial(@base, x) is { } binomial) + { + constant /= MathS.Pow(binomial.Leading, -exponent); + foreach (var root in binomial.Roots) + AddALinear(LessTheRoot(root, x), -exponent); + written *= MathS.Pow(binomial.Monic, -exponent); + continue; + } if (underneath) return null; if (factor.Nodes.Any(node => node is Powf(var b, var e) && !b.ContainsNode(x) && e.ContainsNode(x))) @@ -5131,6 +5140,26 @@ private static Entity LessTheRoot(Entity root, Entity.Variable x) => private static Entity Monic(Entity leading, Entity middle, Entity last, Entity.Variable x) => Functions.PartialFractions.Bare((MathS.Sqr(x) + middle / leading * x + last / leading).InnerSimplified); + // `a + b x^n` for an n of 3 or 4, as its leading coefficient, its n roots, and itself monic in + // the generic case. The roots are `(a/b)^(1/n)` times the n-th roots of -1, `e^(i pi (2k + 1)/n)`: + // only their n-th power is used, so they are the roots whichever branch the n-th root takes. + private static (Entity Leading, Entity[] Roots, Entity Monic)? TheRootsOfABinomial(Entity binomial, Entity.Variable x) + { + if (!TreeAnalyzer.TryGetPolynomial(binomial, x, out var terms) || terms.Count != 2 + || !terms.TryGetValue(EInteger.Zero, out var free) || free.ContainsNode(x) || TreeAnalyzer.IsZero(free)) + return null; + var top = terms.First(term => !term.Key.IsZero); + if (top.Value.ContainsNode(x) || TreeAnalyzer.IsZero(top.Value) || !top.Key.CanFitInInt32() || top.Key.ToInt32Checked() is not (3 or 4)) + return null; + var n = top.Key.ToInt32Checked(); + var scale = MathS.Pow(Functions.PartialFractions.InLowestTermsOverTheSymbols(free / top.Value), Number.Rational.Create(1, n)); + Entity[] rootsOfMinusOne = n == 3 + ? new Entity[] { -1, (1 + MathS.i * MathS.Sqrt(3)) / 2, (1 - MathS.i * MathS.Sqrt(3)) / 2 } + : new Entity[] { (1 + MathS.i) / MathS.Sqrt(2), (1 - MathS.i) / MathS.Sqrt(2), (-1 + MathS.i) / MathS.Sqrt(2), (-1 - MathS.i) / MathS.Sqrt(2) }; + return (top.Value, rootsOfMinusOne.Select(root => (root * scale).InnerSimplified).ToArray(), + Functions.PartialFractions.Bare((MathS.Pow(x, n) + free / top.Value).InnerSimplified)); + } + /// /// over a denominator as terms each over one linear: the /// polynomial part first, divided by the denominator as it is , @@ -5241,6 +5270,14 @@ void AddALinear(Entity linear, int power) AddALinear(LessTheRoot(second, x), -exponent); written *= MathS.Pow(Monic(leading, middle, last, x), -exponent); } + // And a binomial past the quadratic the linears of its roots: `sin(c + d x)/(a + b x^3)`. + else if (TheRootsOfABinomial(@base, x) is { } binomial) + { + constant /= MathS.Pow(binomial.Leading, -exponent); + foreach (var root in binomial.Roots) + AddALinear(LessTheRoot(root, x), -exponent); + written *= MathS.Pow(binomial.Monic, -exponent); + } else return null; continue; diff --git a/Sources/Tests/UnitTests/Calculus/HyperbolicIntegralIntegrationTest.cs b/Sources/Tests/UnitTests/Calculus/HyperbolicIntegralIntegrationTest.cs index 21a5bc619..aa55682f1 100644 --- a/Sources/Tests/UnitTests/Calculus/HyperbolicIntegralIntegrationTest.cs +++ b/Sources/Tests/UnitTests/Calculus/HyperbolicIntegralIntegrationTest.cs @@ -98,6 +98,19 @@ public void ASumOfExponentialsOverSeveralLinears(string integrand) public void ASumOfExponentialsOverAQuadratic(string integrand) => DifferentiatesBack(integrand, AroundZero, Pins); + /// + /// And over a binomial past the quadratic, a + b x^3 or a + b x^4, which is the + /// linears of its roots, (a/b)^(1/n) times the n-th roots of -1. + /// + [Theory] + [InlineData("cosh(c + d*x)/(a + b*x^3)")] + [InlineData("x*cosh(c + d*x)/(a + b*x^3)")] + [InlineData("cosh(c + d*x)/(x*(a + b*x^3))")] + [InlineData("cosh(x)/(1 + x^3)")] + [InlineData("e^x/(a + b*x^4)")] + public void ASumOfExponentialsOverABinomial(string integrand) + => DifferentiatesBack(integrand, AroundZero, Pins); + /// /// An exponential of something other than a linear is not split over the linears below /// it: sinh(sqrt((1 - a x)/(1 + a x)))/(1 - a^2 x^2) is a substitution's, answered diff --git a/Sources/Tests/UnitTests/Calculus/TrigonometricIntegralIntegrationTest.cs b/Sources/Tests/UnitTests/Calculus/TrigonometricIntegralIntegrationTest.cs index 1be53f52d..a820c8f9f 100644 --- a/Sources/Tests/UnitTests/Calculus/TrigonometricIntegralIntegrationTest.cs +++ b/Sources/Tests/UnitTests/Calculus/TrigonometricIntegralIntegrationTest.cs @@ -97,9 +97,10 @@ public void OverSeveralLinears(string integrand) /// A quadratic below the bar is its leading coefficient times the linears of its two /// roots, complex where its discriminant is negative, and the sine and cosine integrals of /// the two conjugate arguments add up to a real answer. Rubi's 4.1.11 and 4.7.7, - /// sin(c + d x)/(a + b x^2) and sin(a + b x)/(c + d x + e x^2). A numerator past - /// the degree is divided by the quadratic as it is written, since the remainder of a division - /// by the linears of symbolic roots was left in their squares. + /// sin(c + d x)/(a + b x^2) and sin(a + b x)/(c + d x + e x^2), and a binomial past + /// it, a + b x^3 or a + b x^4, the linears of its roots. A numerator past the degree + /// is divided by the denominator as it is written, since the remainder of a division by the + /// linears of symbolic roots was left in their powers. /// [Theory] [InlineData("sin(x)/(1 + x^2)")] @@ -110,6 +111,11 @@ public void OverSeveralLinears(string integrand) [InlineData("sin(x)/(1 + x^2)^2")] [InlineData("x^2*sin(c + d*x)/(a + b*x^2)")] [InlineData("x^3*cos(c + d*x)/(a + b*x^2)")] + [InlineData("sin(c + d*x)/(a + b*x^3)")] + [InlineData("x^3*sin(c + d*x)/(a + b*x^3)")] + [InlineData("sin(c + d*x)/(a + b*x^3)^2")] + [InlineData("sin(x)/(1 + x^4)")] + [InlineData("x*sin(x)/(1 + x^3)")] public void OverAQuadratic(string integrand) => DifferentiatesBack(integrand, AroundZero, Pins); diff --git a/Sources/Tests/UnitTests/Calculus/TrigonometricTowerAnsatzTest.cs b/Sources/Tests/UnitTests/Calculus/TrigonometricTowerAnsatzTest.cs index e9fb37e72..c4064679e 100644 --- a/Sources/Tests/UnitTests/Calculus/TrigonometricTowerAnsatzTest.cs +++ b/Sources/Tests/UnitTests/Calculus/TrigonometricTowerAnsatzTest.cs @@ -96,7 +96,7 @@ public void TheAnswerIsInTheSineAndCosine() [InlineData("tan(x)/x")] [InlineData("x/sin(x)")] [InlineData("x*tan(x)")] - [InlineData("x*sin(x)/(1 + x^3)")] + [InlineData("x*sin(x)/(1 + x + x^3)")] public void ANonElementaryOneIsDeclined(string integrand) => Assert.Contains("integral(", integrand.ToEntity().Integrate("x").Stringize()); }