diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 5fe7033d8..c6f34b89f 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -939,6 +939,24 @@ parameter, so their Ex 5.2.6 is answered with the condition the book asks about | `"sum(k/2^k, k, 1, +oo)".ToEntity().Evaled` | as written | `2` | | `"forall n in ZZ+ : sum(q^i, i, 0, n-1) = (q^n - 1)/(q - 1)".ToEntity().Evaled` | `UnhandledParseException` -- quantifiers are new since | `True provided not q = 1` | +### `(a + b asech(c x))/(d + e x)^2` is integrated, and a root written apart with `|x|` no longer needs a parity + +Rubi's 7.5.1 with a symbolic linear below the bar ran for ten minutes without an answer. By +parts leaves `1/(x^2 (d + e x) sqrt(1/(c x)^2 - 1))`, which was handed on as a product to the +power `-1` that no radical rule reads (a constant over a product is now the reciprocal with the +constant in front), had its `(c x)^2` distributed one level down past the rule that writes the +root apart (the same question now), and, written apart with `|x|` for `x > 0`, was declined +for having no parity to extend by — `sgn(x)^m` stands in for it now, exact for a whole `m`. A +root inside a logarithm's argument is left as written, since the logarithm is an atom to +every rule ([#718](https://github.com/asc-community/AngouriMath/issues/718)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"(a+b*asech(c*x))/(d+pe*x)^2".Integrate("x")` | left unevaluated | the antiderivative, in `sgn(x)`, `provided c^2 > 0` | +| `"(a+b*asech(c*x))/x^7".Integrate("x")` | left unevaluated | the antiderivative | +| `"e^(2*asech(a*x))/x^2".Integrate("x")` | left unevaluated | the antiderivative, in `sgn(x)` | +| `"x*(a+b*asech(c*x))/(d+pe*x^2)^2".Integrate("x")` | left unevaluated | the antiderivative | + ### `binomial(n, k)` is a function **Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 0a0241767..5661751f5 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -1241,7 +1241,14 @@ private static bool TryReadAsQuotient(Entity expr, out Entity numerator, out Ent // half-angle substitution for what is `-c cot(x)`. over is Entity.Powf(var @base, var power) ? Integration.ComputeIndefiniteIntegral(MathS.Pow(@base, (-power).InnerSimplified), x, integrateByParts)?.Pipe(i => div * i) : - Integration.ComputeIndefiniteIntegral(MathS.Pow(over, -1), x, integrateByParts)?.Pipe(i => div * i) : + // A constant over a product is the reciprocal of the product, asked as the + // same question with the constant in front, and not the product to the + // power -1: `pe/(x (d + e x) sqrt(1 - c^2 x^2))` handed on as + // `(x (d + e x) sqrt(1 - c^2 x^2))^(-1)` was read by no radical rule, where + // Euler's substitution reads the reciprocal as written. + div != Number.Integer.One ? + Integration.ComputeAsTheSameQuestion(Number.Integer.One / over, x, integrateByParts)?.Pipe(i => div * i) : + Integration.ComputeIndefiniteIntegral(MathS.Pow(over, -1), x, integrateByParts) : !over.ContainsNode(x) ? Integration.ComputeAsTheSameQuestion(div, x, integrateByParts)?.Pipe(i => i / over) : null, @@ -9964,7 +9971,11 @@ node is Powf(Mulf(var l, var r) product, Number.Integer power) && product.Contai && (!l.ContainsNode(x) && l.Vars.Any() || !r.ContainsNode(x) && r.Vars.Any()) ? MathS.Pow(l, power) * MathS.Pow(r, power) : node); - return distributed == expr ? null : Integration.ComputeAsAQuestionOfItsOwn(distributed, x, integrateByParts); + // The same question: `(c x)^2` and `c^2 x^2` are one integrand, and asked one + // level down the remainder by parts leaves from `asech(c x)/(d + e x)^2` sat past + // the rules scoped to the question asked or one below it, the power of a quotient + // written apart among them, which is what answers it. + return distributed == expr ? null : Integration.ComputeAsTheSameQuestion(distributed, x, integrateByParts); } internal static Entity? SolveAPolynomialTimesARationalFunctionOfAnExponential(Entity expr, Entity.Variable x, bool integrateByParts) @@ -13065,6 +13076,13 @@ private static bool OnEveryRealInterval(List bases, Entity.Variable x, S if (!Integration.AnsweringTheQuestionAskedOrOneBelow) return null; var tookAPowerOfX = false; + // Whether every power of x taken is a whole one, and whether their sum is odd: + // |x|^m for a whole m is sgn(x)^m x^m, which stands in for the extension by parity + // where the integrand has none -- `1/(x^2 (d + e x) sqrt(1/(c x)^2 - 1))`, the + // remainder by parts leaves from `asech(c x)/(d + e x)^2`, is neither even nor odd, + // and was declined for that after its antiderivative had been found. + var wholePowersOfX = true; + var oddPowersOfX = false; // A parameter's even power taken for positive -- `c^2 x^2` below the bar, which is // how `acsch(c x)` and `asech(c x)` arrive, is positive for a real `c` -- and the // answer says so: `provided c^2 > 0`, which holds exactly for a real non-zero `c`. @@ -13080,9 +13098,14 @@ private static bool OnEveryRealInterval(List bases, Entity.Variable x, S expr is Divf(var dividend, var divisor) ? Mulf.LinearChildren(dividend).Concat(Mulf.LinearChildren(divisor)) : expr is Mulf ? Mulf.LinearChildren(expr) : new[] { expr }); + // A root inside the argument of a logarithm is left as it is: the logarithm is an + // atom to every rule, whatever its argument is written as, and writing the root of + // `asech(c x)` apart re-asked `(a + b asech(c x))/(d + e x)^2` whole for a second + // and a half of nothing. + var underALogarithm = new HashSet(expr.Nodes.Where(node => node is Logf).SelectMany(log => ((Logf)log).Antilogarithm.Nodes)); var written = expr.Replace(node => { - if (node is not Powf(var @base, Number.Rational exponent) || exponent is Number.Integer || !@base.ContainsNode(x)) + if (node is not Powf(var @base, Number.Rational exponent) || exponent is Number.Integer || !@base.ContainsNode(x) || underALogarithm.Contains(node)) return node; // As one quotient where it is a sum with a quotient in it: `1 - 1/x^2` is // `(x^2 - 1)/x^2`, the derivative of the arcsecant as it is written. @@ -13216,7 +13239,9 @@ expr is Divf(var dividend, var divisor) ? Mulf.LinearChildren(dividend).Concat(M var forPositive = Integration.ComputeIndefiniteIntegral(Functions.PartialFractions.Bare(written), x, integrateByParts: true); if (forPositive is null || forPositive.Nodes.Any(node => node == MathS.NaN)) return null; - var extended = tookAPowerOfX ? ExtendedByParity(expr, forPositive, x) : forPositive; + var extended = tookAPowerOfX + ? ExtendedByParity(expr, forPositive, x) ?? (wholePowersOfX ? (oddPowersOfX ? MathS.Signum(x) * Functions.PartialFractions.Bare(forPositive) : Functions.PartialFractions.Bare(forPositive)) : null) + : forPositive; foreach (var pair in signs) if (pair.Value % 2 == 1 && extended is { }) extended = MathS.Signum(pair.Key) * extended; @@ -13319,7 +13344,12 @@ Entity PowerOfAPositive(Entity positive, Number.Rational exponent) if (degree.Sign > 0) { tookAPowerOfX = true; - var power = MathS.Pow(x, (Number.Integer.Create(degree) * exponent).InnerSimplified); + var powerOfX = (Number.Integer.Create(degree) * exponent).InnerSimplified; + if (powerOfX is Number.Integer wholePowerOfX) + oddPowersOfX ^= !wholePowerOfX.EInteger.IsEven; + else + wholePowersOfX = false; + var power = MathS.Pow(x, powerOfX); // A parameter's even power to a fractional exponent is a power of its // modulus, `(c^2)^(-1/2)` being `1/|c|`, which is one atom wherever it // stands rather than two spellings of it. diff --git a/Sources/Tests/UnitTests/Calculus/InverseHyperbolicSecantIntegralTest.cs b/Sources/Tests/UnitTests/Calculus/InverseHyperbolicSecantIntegralTest.cs index e7e2afbe8..7e3df4d0c 100644 --- a/Sources/Tests/UnitTests/Calculus/InverseHyperbolicSecantIntegralTest.cs +++ b/Sources/Tests/UnitTests/Calculus/InverseHyperbolicSecantIntegralTest.cs @@ -59,6 +59,45 @@ private static void DifferentiatesBack(string integrand) [InlineData("x/sqrt(1 + 1/(c*x)^2)")] public void AnInverseHyperbolicSecantOrCosecantWithASymbolicCoefficient(string integrand) => DifferentiatesBack(integrand); + /// + /// Rubi's 7.5.1 with a symbolic linear or quadratic below the bar: (a + b asech(c x))/(d + e x)^2 + /// ran for ten minutes without an answer. By parts leaves 1/(x^2 (d + e x) sqrt(1/(c x)^2 - 1)), + /// which was handed on as a product to the power -1 that no radical rule reads, its + /// (c x)^2 distributed one level down past the rule that writes the root apart, + /// and, once written apart with |x| for x > 0, declined for having no + /// parity to extend by -- sgn(x) stands in for it now. Pinned with a = 1/3, + /// b = 1/2, c = 3/2, d = 2/3, e = 5/4. + /// + [Theory] + [InlineData("(a+b*asech(c*x))/(d+pe*x)^2")] + [InlineData("(a+b*asech(c*x))/x^7")] + [InlineData("x*(a+b*asech(c*x))/(d+pe*x^2)^2")] + [InlineData("e^(2*asech(a*x))/x^2")] + public void ARationalFunctionWithSymbolicCoefficientsBesideTheSecant(string integrand) + { + var integral = integrand.ToEntity().Integrate("x"); + Assert.DoesNotContain("integral(", integral.Stringize()); + Entity Pinned(Entity e) => e.Substitute("C", 0).Substitute("a", "1/3".ToEntity()).Substitute("b", "1/2".ToEntity()) + .Substitute("c", "3/2".ToEntity()).Substitute("d", "2/3".ToEntity()).Substitute("pe", "5/4".ToEntity()); + var derivative = Pinned(integral).Differentiate("x"); + var original = Pinned(integrand.ToEntity()); + var compared = 0; + // Where asech(a x) with a = 1/3 is real too, 0 < x <= 3, and asech(3x/2) real, x <= 2/3. + foreach (var at in Points) + { + var got = derivative.Substitute("x", at).EvalNumerical(); + var want = original.Substitute("x", at).EvalNumerical(); + if (got.IsNaN || want.IsNaN) + continue; + compared++; + var difference = Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart); + var scale = Math.Max(1.0, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)); + Assert.True(difference / scale < 1e-9, + $"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}"); + } + Assert.True(compared >= 4, $"only {compared} of {Points.Length} points were comparable for {integrand}"); + } + [Fact] public void TheAnswerSaysTheParameterIsReal() {