diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 891e0ae34..8055b1ed9 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -295,6 +295,23 @@ power up each step, and what reaches the first power is integrated once over the | `"1/(a + b*x^2 + c*x^4)^3".ToEntity().Integrate("x")` | `integral(...)` | the same | | `"x/(a + b*x^3 + c*x^6)^2".ToEntity().Integrate("x")` | `integral(...)` | a polynomial over `a + b x^3 + c x^6`, and the integral of a polynomial over it | +### A polynomial over a power of a quadratic with a sum of symbols in it is reduced + +**Answers where there were none.** The reduction of `N(x)/Q(x)^n` divides `N` by the quadratic a +power at a time. With a sum of symbols among the quadratic's coefficients, the remainder it computed +held the terms the division had taken away, written two ways, and read as of the second degree it +stopped the reduction: `x^4/(d x^2 + b c - a d)^5` was declined where `x^4/(d x^2 + k)^5` was +answered. The remainder the division reports is taken where the computed one is not linear, and an +improper fraction is declined before the first division rather than after the last. This is what +`t = sqrt(a + b x)` makes of Rubi's 1.1.1.2 `(a + b x)^(m/2)/(c + d x)^n` +([#718](https://github.com/asc-community/AngouriMath/issues/718)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"x^4/(d*x^2 + b*c - a*d)^5".ToEntity().Integrate("x")`, and `x^6` over the fourth power | `integral(...)` | the antiderivative | +| `"(1 - b*x^2)^3/(c*(1 - b*x^2) + a*d*x^2)^3".ToEntity().Integrate("x")` | no answer within a minute | the antiderivative | +| `"(a + b*x)^(5/2)/(c + d*x)^4".ToEntity().Integrate("x")` | `integral(...)` | the antiderivative | + ### A symbolic parameter no longer stops a rational integrand being integrated `1/(8 + x^3)` and `1/(16 - x^4)` are answered at once. `1/(a^3 + x^3)` and `1/(a^4 - x^4)` were not, diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IntegralPatterns.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IntegralPatterns.cs index 56baeea45..573679294 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IntegralPatterns.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IntegralPatterns.cs @@ -1134,6 +1134,14 @@ private static Entity IntegrateLinearOverPowerOfQuadratic( if (power < 2) return null; + // An improper fraction comes down to the first power with a numerator of the second + // degree, and is declined there, after a division at every power above it: declined + // before the first. With symbols in the quadratic each division is a simplification + // of every coefficient. + if (TreeAnalyzer.TryGetPolynomial(numerator, x, out var terms) && terms.Count > 0 + && terms.Keys.Max()!.CompareTo(EInteger.FromInt32(2 * power)) >= 0) + return null; + var division = TreeAnalyzer.PolynomialLongDivision(numerator, quadratic, genericCase: true, inTermsOf: x); if (division is null) return null; @@ -1150,6 +1158,15 @@ private static Entity IntegrateLinearOverPowerOfQuadratic( var remainder = Functions.PartialFractions.Bare((numerator - quotient * quadratic).InnerSimplified); if (remainder.ContainsNode(x) && !TreeAnalyzer.TryGetPolyLinear(remainder, x, out _, out _)) remainder = Functions.PartialFractions.Bare((numerator - quotient * quadratic).Expand().InnerSimplified); + // The division writes the quotient's coefficients simplified, and the quadratic is + // subtracted as it is written, so a term the division took away can come back as the + // difference of two spellings of one value: `x^4` over `1/(-b + a) + x^2` left + // `(1/(a - b) - 1/(-b + a)) x^2`, and the reduction declined where over `1/(a - b) + x^2` + // it answered. The remainder the division reports over the divisor has no such term. + if (remainder.ContainsNode(x) && !TreeAnalyzer.TryGetPolyLinear(remainder, x, out _, out _) + && division.Value.Remainder is Entity.Divf(var reportedAbove, var reportedBelow) && reportedBelow == quadratic + && (!reportedAbove.ContainsNode(x) || TreeAnalyzer.TryGetPolyLinear(reportedAbove, x, out _, out _))) + remainder = Functions.PartialFractions.Bare(reportedAbove.InnerSimplified); // The remainder of a division by a quadratic is linear or a constant; one that // still has the variable to a higher power -- the division declined in its own // way, on `csch(29/10 + 13/10 x)^3 (17/10 + 23/10 sech(...)^2)^3` through the diff --git a/Sources/Tests/UnitTests/Calculus/SymbolicCoefficientIntegralsTest.cs b/Sources/Tests/UnitTests/Calculus/SymbolicCoefficientIntegralsTest.cs index 2e338dcbb..32cac8f90 100644 --- a/Sources/Tests/UnitTests/Calculus/SymbolicCoefficientIntegralsTest.cs +++ b/Sources/Tests/UnitTests/Calculus/SymbolicCoefficientIntegralsTest.cs @@ -105,6 +105,40 @@ public void ALinearNumeratorOverTheSameShape( string integrand, string coefficients, double[] points) => AssertIsAntiderivative(integrand, coefficients, points); + /// + /// A polynomial over a power of a quadratic with a sum of symbols among its coefficients. + /// The reduction divides the numerator by the quadratic a power at a time, and the + /// remainder it took held the terms the division had taken away, written two ways: + /// x^4/(1/(-b + a) + x^2)^3 was declined where x^4/(1/(a - b) + x^2)^3 was + /// answered. The last row is what t = sqrt(a + b x) makes of it. + /// + /// + /// Checked with the symbols pinned and nothing simplified: the answers are piecewises + /// over the sign of the quadratic's constant term, and simplifying them with the + /// symbols left in is what the helper above does and what these do not need. + /// + [Theory] + [InlineData("x ^ 4 / (1 / (-b + a) + x ^ 2) ^ 3")] + [InlineData("x ^ 4 / (c / (-b * c + a * d) + x ^ 2) ^ 3")] + [InlineData("(1 - b * x ^ 2) ^ 3 / (c * (1 - b * x ^ 2) + a * d * x ^ 2) ^ 3")] + [InlineData("x ^ 4 / (d * x ^ 2 + b * c - a * d) ^ 5")] + [InlineData("x ^ 6 / (d * x ^ 2 + b * c - a * d) ^ 4")] + [InlineData("(a + b * x) ^ (5/2) / (c + d * x) ^ 4")] + public void APolynomialOverAPowerOfAQuadraticWithASumOfSymbolsInIt(string integrand) + { + var f = integrand.ToEntity(); + var antiderivative = f.Integrate("x"); + Assert.DoesNotContain("integral(", antiderivative.Stringize()); + Entity Pin(Entity e) => e.Substitute("a", 0.7).Substitute("b", 1.3).Substitute("c", 2.1).Substitute("d", 1.9); + var derivative = Pin(antiderivative.Substitute("C", 0)).Differentiate("x"); + foreach (var point in new[] { 0.3, 0.6, 0.9 }) + { + var expected = Pin(f).Substitute("x", point).EvalNumerical().RealPart.EDecimal.ToDouble(); + var actual = derivative.Substitute("x", point).EvalNumerical().RealPart.EDecimal.ToDouble(); + Assert.Equal(expected, actual, 8); + } + } + // The neighbouring shapes must keep working: a symbolic leading coefficient *with* an // x term never had the defect, because the a = 0 arm divides by a b that is not zero. [Theory]