diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index abfa92ca4..ceb332d29 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -1055,6 +1055,25 @@ real is an arm of a piecewise, saying where it holds. Rubi's 7.3.6 and 7.4.2 | `"x*sqrt(c - a*c*x)/e^(3*atanh(a*x))".Integrate("x")` | left unevaluated | the antiderivative on both sides of `a x = 1`, where `master` gave one `provided c - a c x >= 0` | | `"sqrt(x)/(sqrt(1/x + 1)*sqrt(1 - x^2))".Integrate("x")` | left unevaluated | the antiderivative on both sides of `x = 0`, where `master` gave one `provided x >= 0` | +### A quadratic that shares a root with a linear beside it is written over it + +**Answers where there were none.** In Rubi's 1.2.1.2 and 1.2.1.4 a quadratic under a root stands +beside a power of a linear that divides it: `a d h + (c d^2 + a h^2) x + c d h x^2` is +`(d + h x)(a h + c d x)`. Nothing split a quadratic with symbols in it over a root it shares, so it +was read as irreducible and the integral was declined or ran out of time. A quadratic beside a +linear under a root now takes the linear's root where it vanishes there, and its other root by +the sum of the two. Each linear is then written once, as in the entry above +([#718](https://github.com/asc-community/AngouriMath/issues/718)), and the two roots of the shared +linear are one whole power of it. That is done only where it leaves two linears or fewer. Beside a +whole power of the linear, as in `(d + h x)^3 sqrt(a d h + ...)`, or beside a third linear, as in +`x sqrt(a d h + ...)/(d + h x)`, the quadratic is read whole, as before. + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"(d + h*x)^(7/2)/(a*d*h + (c*d^2 + a*h^2)*x + c*d*h*x^2)^(3/2)".Integrate("x")` | left unevaluated | `K` times a sum of powers of `sqrt(a h + c d x)`, `provided a h + c d x >= 0` | +| `"(d + h*x)^(3/2)*(a*d*h + (c*d^2 + a*h^2)*x + c*d*h*x^2)^(1/2)".Integrate("x")` | left unevaluated | `K` times a polynomial in `sqrt(a h + c d x)`, `provided a h + c d x >= 0` | +| `"sqrt(d + h*x)/sqrt(a*d*h + (c*d^2 + a*h^2)*x + c*d*h*x^2)".Integrate("x")` | left unevaluated | `K` times `2 sqrt(a h + c d x)/(c d)`, `provided a h + c d x >= 0` | + ### The inverse hyperbolic tangent's answer is given on its domain, and says so `1/((1 - a^2 x^2)^(5/2) artanh(a x))` was left unevaluated, although the substitution `a x = tanh(u)` diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 031d3595f..2e3790c49 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -19018,15 +19018,41 @@ private static bool TryWriteAPairOfLinearsOverARadicand(Entity expr, Entity.Vari // is under such a power, and whether it is a quotient with x below the bar. var roots = new List<(Entity Root, Number.Rational Exponent, HashSet Bases, bool UnderARoot)>(); var bases = new List<(HashSet Roots, bool UnderARoot, bool AQuotient)>(); + // The roots of the linears written under a power that is not whole, which a quadratic + // beside them may share: `a d e + (c d^2 + a e^2) x + c d e x^2` is + // `(d + e x)(a e + c d x)`. Beside a whole power of the linear, `(d + e x)^3 sqrt(a d e + // + ...)`, the quadratic is under a root beside a polynomial, which the rules for one + // answer as it is written. + var writtenRoots = new List(); + foreach (var node in expr.Nodes) + if (node is Powf((Sumf or Minusf) and var linear, Number.Rational power) && power is not Number.Integer + && linear.ContainsNode(x) && TreeAnalyzer.TryGetPolyLinear(linear, x, out var writtenSlope, out var writtenIntercept) + && !writtenSlope.ContainsNode(x) && !writtenIntercept.ContainsNode(x) && writtenSlope.Evaled is not Number.Complex { IsZero: true }) + { + var writtenRoot = Reduced(-writtenIntercept / writtenSlope); + if (!writtenRoots.Contains(writtenRoot)) + writtenRoots.Add(writtenRoot); + } + // Set where a quadratic under a power that is not whole came apart only through a root + // it shares, which no other rule reads it as. + var splitThroughAShare = false; if (!Read(expr, Number.Integer.One)) return null; // With every power whole the integrand is a rational function, and a root of a quotient // shared with another base is the same help: `e^(2 acoth(a x))/(c - c/(a^2 x^2))^2` is // `K x^4/((a x + 1)(a x - 1)^3)`, which the partial fractions answer at once, where // as written it ran out of time; and `K` is a constant there, with no arms to it. + // And a quadratic that came apart through a root it shares is help on its own where it + // leaves two linears or fewer, a product the rules for two linears answer: the linear + // it shares stands under a root too, and the two roots of it are one power that is + // whole. `(d + e x)^(7/2)/(a d e + (c d^2 + a e^2) x + c d e x^2)^(3/2)` is + // `K (d + e x)^2/(a e + c d x)^(3/2)`, where as written it was declined. Beside a + // third, as in `(a d e + ...)^(3/2)/(x^5 (d + e x))`, it is a product of three, which + // those rules do not answer, and the quadratic is left to the rules that read it whole. var wholePowersOnly = !bases.Any(written => written.UnderARoot); - if (!roots.Any(root => root.Bases.Count(which => bases[which].UnderARoot) >= 2 - || root.Bases.Any(which => (bases[which].UnderARoot || wholePowersOnly) && bases[which].AQuotient) && root.Bases.Count >= 2) + if (!(splitThroughAShare && roots.Count(root => root.Exponent != Number.Integer.Zero) <= 2 + || roots.Any(root => root.Bases.Count(which => bases[which].UnderARoot) >= 2 + || root.Bases.Any(which => (bases[which].UnderARoot || wholePowersOnly) && bases[which].AQuotient) && root.Bases.Count >= 2)) || roots.Count(root => root.Exponent is not Number.Integer) > 2) return null; // Each linear with the root's denominator for its leading coefficient: `a x + 1` for @@ -19220,6 +19246,19 @@ bool WithItsRoots(Entity polynomial, Number.Rational exponent, int @base, bool u Add(Reduced(-root), exponent); return true; } + if (degree.Equals(EInteger.FromInt32(2))) + { + var (c2, c1, c0) = (CoefficientOf(highest), CoefficientOf(lowest.Add(EInteger.One)), CoefficientOf(lowest)); + // A root of a linear written beside it, and the other root by their sum. + foreach (var shared in writtenRoots) + if (Reduced(c2 * shared * shared + c1 * shared + c0) == Number.Integer.Zero) + { + Add(shared, exponent); + Add(Reduced(-c1 / c2 - shared), exponent); + splitThroughAShare |= underARoot; + return true; + } + } return false; void Add(Entity root, Number.Rational times) diff --git a/Sources/Tests/UnitTests/Calculus/EachLinearWrittenOnceIntegralTest.cs b/Sources/Tests/UnitTests/Calculus/EachLinearWrittenOnceIntegralTest.cs index 6f96cfd1d..6434c3a00 100644 --- a/Sources/Tests/UnitTests/Calculus/EachLinearWrittenOnceIntegralTest.cs +++ b/Sources/Tests/UnitTests/Calculus/EachLinearWrittenOnceIntegralTest.cs @@ -48,7 +48,28 @@ public sealed class EachLinearWrittenOnceIntegralTest [InlineData("x*sqrt(c-c/(a*x))/e^(3*atanh(a*x))", "a=1.37,c=-2.11")] [InlineData("e^(2*acoth(a*x))/(c-c/(a^2*x^2))^2", "a=1.37,c=2.11")] [InlineData("1/(e^(2*atanh(a*x))*(c-c/(a^2*x^2))^4)", "a=1.37,c=-2.11")] + // A quadratic that shares a root with a linear beside it, Rubi's 1.2.1.2 and 1.2.1.4: + // `a d e + (c d^2 + a e^2) x + c d e x^2` is `(d + e x)(a e + c d x)`, and comes apart + // only through the root it shares, where the linear stands under a root as well. + [InlineData("(d+h*x)^(7/2)/(a*d*h+(c*d^2+a*h^2)*x+c*d*h*x^2)^(3/2)", "a=1.37,c=2.11,d=0.83,h=1.9")] + [InlineData("(d+h*x)^(3/2)*(a*d*h+(c*d^2+a*h^2)*x+c*d*h*x^2)^(1/2)", "a=1.37,c=2.11,d=0.83,h=1.9")] + [InlineData("sqrt(d+h*x)/sqrt(a*d*h+(c*d^2+a*h^2)*x+c*d*h*x^2)", "a=1.37,c=2.11,d=0.83,h=1.9")] public void IsAnsweredWithEachLinearOnce(string integrand, string pins) + => DifferentiatesBack(integrand, pins); + + /// + /// Beside a third linear, a quadratic is not taken apart through the root it shares. That + /// would leave a product of three linears, which the rules for two do not answer, and + /// written so x sqrt(a d h + ...)/(d + h x) grows past what fits in memory. Read + /// whole, it is answered. + /// + [Theory] + [InlineData("x*sqrt(a*d*h+(c*d^2+a*h^2)*x+c*d*h*x^2)/(d+h*x)", "a=1.37,c=2.11,d=0.83,h=1.9")] + [InlineData("sqrt(a*d*h+(c*d^2+a*h^2)*x+c*d*h*x^2)/(x*(d+h*x))", "a=1.37,c=2.11,d=0.83,h=1.9")] + public void BesideAThirdLinearTheQuadraticIsReadWhole(string integrand, string pins) + => DifferentiatesBack(integrand, pins); + + private static void DifferentiatesBack(string integrand, string pins) { var integral = integrand.ToEntity().Integrate("x").Substitute("C", 0); Assert.DoesNotContain("integral(", integral.Stringize());