From 83c5bbc5aed98d31ae3311799f149901162e6c87 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Tue, 22 Sep 2026 06:16:27 +0000 Subject: [PATCH] A power of x beside a function of a symbolic power of x is integrated by substituting the power, and a square root of a perfect square is the modulus at every depth `x^(n - 1) e^(x^n)` with a symbolic n was declined: the general substitution takes a concrete power, and nothing took a symbolic one. It is `e^(x^n)/n` under u = x^n, and `x^(k n - 1) g(x^n)` for a whole k is `u^(k - 1) g(u)/n`, which is Rubi's 6.5.2 and 6.6.2 -- `(e x)^(n - 1) (a + b sech(c + d x^n))^p`, where the power in front is `e^(n - 1) x^(n - 1)` for a positive e, and the answer says so. `1/sqrt(1 + csch(x)^2)` was answered wrongly: under u = tanh(x) it is `sqrt(u^2)/(u^2 - 1)`, and six levels down the rule for a root of a quadratic beside a linear read a perfect square as a root and answered with a logarithm of zero. A square root of a perfect square is now written as `sgn(x + h) (x + h)` at every depth, before anything reads it, and Euler's substitution declines a perfect square rather than substituting `t = sqrt(u^2) - u`. The square root only: `(1 + 2u + u^2)^(5/2)` under the exponential substitution is a sign written for a variable whose sign the substitution knows, and rewriting it sent `tanh(x)/(a + b tanh(x)^2)^(5/2)` from twenty seconds to past the budget. Family 6 of the Rubi suite: 315 -> 335 of 417, 0 wrong (one wrong before); family 7 215/270 unchanged; the 1774-problem suite 1707, 0 wrong, 0 timeout. Allocation gate passed on all 19 gated benchmarks. Part of #718. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 20 +++ Sources/.editorconfig | 6 + .../Integration/IndefiniteIntegralSolver.cs | 147 ++++++++++++++++++ .../Integration/Integration.Definition.cs | 4 + .../APowerTimesAFunctionOfItsPowerTest.cs | 72 +++++++++ .../RootOfAPerfectSquareIntegralTest.cs | 68 ++++++++ 6 files changed, 317 insertions(+) create mode 100644 Sources/Tests/UnitTests/Calculus/APowerTimesAFunctionOfItsPowerTest.cs create mode 100644 Sources/Tests/UnitTests/Calculus/RootOfAPerfectSquareIntegralTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 3b69672df..06f69477f 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -993,6 +993,26 @@ the even or the odd indices, each `2^(n - 1)` — Prop 8.4.4, Thm 8.4.6, Ex 8.3. | `"sum(binomial(n,k)^2, k, 0, n)".ToEntity().Evaled` | parse error | `binomial(2 n, n)` | | `"sum(binomial(i,k), i, 0, n)".ToEntity().Evaled` | parse error | `binomial(n + 1, k + 1)` | +### A power of `x` beside a function of a symbolic power of `x` is integrated by substituting the power + +`x^(n - 1) e^(x^n)` with a symbolic `n` was left as written: it is `e^(x^n)/n`, under `u = x^n`, +and with it `x^(k n - 1) g(x^n)` for a whole `k`, which is `u^(k - 1) g(u)/n` -- Rubi's 6.5.2 and +6.6.2, where the power in front is written `(e x)^(n - 1)`, which is `e^(n - 1) x^(n - 1)` for a +positive `e` and the answer says so. And a square root of a perfect square is the modulus at +every depth: `1/sqrt(1 + csch(x)^2)` under `u = tanh(x)` is `sqrt(u^2)/(u^2 - 1)`, which the rule +for a root of a quadratic beside a linear read as a root of a quadratic and answered with a +logarithm of zero -- wrong on `master` since the hyperbolic entry above, unevaluated in 2.5.0, +and in no release -- and is `sgn(u) u/(u^2 - 1)` +([#718](https://github.com/asc-community/AngouriMath/issues/718)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"x^(n-1)*e^(x^n)".Integrate("x")` | left unevaluated | `e^(x^n)/n` | +| `"(pe*x)^(-1+n)*(a+b*csch(c+d*x^n))".Integrate("x")` | left unevaluated | the antiderivative, `provided pe > 0` | +| `"(pe*x)^(-1+n)/(a+b*sech(c+d*x^n))^2".Integrate("x")` | left unevaluated | the antiderivative, by cases on `a` and `b` | +| `"1/sqrt(1+csch(x)^2)".Integrate("x")` | left unevaluated | `-sgn(tanh(x)) ln(tanh(x)^2 - 1)/2`, in exponentials | +| `"x^4/sech(2*ln(c*x))^(1/2)".Integrate("x")` | left unevaluated | `sgn(x) (1 + c^4 x^4)^(3/2)/(6 sqrt(2) c^5)` up to the form, `provided c^4 > 0` | + ### `binomial(n, k)` is a function **Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled diff --git a/Sources/.editorconfig b/Sources/.editorconfig index e3ae9673e..98e221048 100644 --- a/Sources/.editorconfig +++ b/Sources/.editorconfig @@ -291,6 +291,12 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed [AngouriMath/Functions/NumberTheory/ResidueClasses.cs] file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n +[Tests/UnitTests/Calculus/APowerTimesAFunctionOfItsPowerTest.cs] +file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n + +[Tests/UnitTests/Calculus/RootOfAPerfectSquareIntegralTest.cs] +file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n + [Tests/UnitTests/Calculus/BinomialIdentitiesTest.cs] file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs index 904c4e61d..8d0862832 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/IndefiniteIntegralSolver.cs @@ -9093,6 +9093,13 @@ Dictionary PowerOfQ(int j) && TryReadAPowerTimesARadicalQuadratic(expr, x)) return null; + // A perfect square under the root is no radical: `sqrt(u^2)` is `|u|`, which + // `SolveByTakingARootOfAPerfectSquare` writes as `sgn(u) u`, and the substitution + // written for it -- `t = sqrt(u^2) - u`, which is zero on half the line -- is + // declined rather than made. + if ((b * b - Number.Integer.Create(4) * a * c).InnerSimplified.Evaled is Number.Complex { IsZero: true }) + return null; + var t = Variable.CreateUnique(expr, "t_euler"); Entity xInT, rootInT; Entity backSubstitution; @@ -10041,6 +10048,146 @@ Entity Without(Entity side) return answer; } + /// + /// x^(n - 1) g(x^n) with a symbolic n, which is g(u)/n under + /// u = x^n: the power in front is the derivative of the power inside up to the + /// constant n, and the rest mentions x only as x^n. Rubi's 6.5.2 and + /// 6.6.2 -- (e x)^(n - 1) (a + b sech(c + d x^n))^p -- write the power in front as + /// (e x)^(n - 1), which is e^(n - 1) x^(n - 1) for a positive e, and + /// the answer says so. A concrete n is the general substitution's; a symbolic + /// one was nobody's, and x^(n - 1) e^(x^n) was declined. + /// https://github.com/asc-community/AngouriMath/issues/718 + /// + internal static Entity? SolveByAPowerOfTheVariableTimesAFunctionOfItsPower(Entity expr, Entity.Variable x, bool integrateByParts) + { + Entity? inFront = null; + Entity? scale = null; + Entity? rest = null; + Entity constant = Number.Integer.One; + foreach (var (factor, underneath) in FactorsOfTheIntegrand(expr)) + { + if (!factor.ContainsNode(x)) + { + constant = underneath ? constant / factor : constant * factor; + continue; + } + // The power in front: x^m, or (e x)^m with e free of x, to a symbolic m. + if (inFront is null && !underneath && factor is Powf(var @base, var exponent) && !exponent.ContainsNode(x) + && exponent.Evaled is not Number && exponent.Vars.Any() + && (@base == x || @base is Mulf(var l, var r) && (l == x && !r.ContainsNode(x) || r == x && !l.ContainsNode(x)))) + { + inFront = exponent; + scale = @base == x ? null : @base is Mulf(var l2, var r2) ? (l2 == x ? r2 : l2) : null; + continue; + } + var piece = underneath ? Number.Integer.One / factor : factor; + rest = rest is null ? piece : rest * piece; + } + if (inFront is null || rest is null) + return null; + // The rest mentions x only as x^n, one n throughout. + Entity? n = null; + foreach (var node in rest.Nodes) + if (node is Powf(var b, var e) && b == x && !e.ContainsNode(x)) + { + if (n is null) + n = e; + else if (n != e) + return null; + } + if (n is null || n.Evaled is Number) + return null; + // m + 1 = k n for a whole k >= 1: x^(k n - 1) g(x^n) is u^(k - 1) g(u)/n. + // Bare: the simplification attaches `provided not n = 0` to the quotient it + // cancelled, and the generic case is what every rule answers in. + var timesN = Functions.PartialFractions.Bare(((inFront + Number.Integer.One) / n).InnerSimplified); + if (timesN is not Number.Integer k || k.EInteger.Sign <= 0) + { + timesN = Functions.PartialFractions.Bare(((inFront + Number.Integer.One) / n).Simplify()); + if (timesN is not Number.Integer k2 || k2.EInteger.Sign <= 0) + return null; + k = k2; + } + var u = Variable.CreateUnique(expr, "u_pow"); + var inU = rest.Replace(node => node is Powf(var b, var e) && b == x && e == n ? u : node); + if (inU.ContainsNode(x)) + return null; + if (k != Number.Integer.One) + inU = MathS.Pow(u, (k - Number.Integer.One).InnerSimplified) * inU; + if (Integration.ComputeAsAQuestionOfItsOwn(inU, u, integrateByParts) is not { } inner) + return null; + Entity answer = constant * inner.Substitute(u, MathS.Pow(x, n)) / n; + // (e x)^(n - 1) is e^(n - 1) x^(n - 1) for a positive e, which the answer states. + if (scale is { }) + { + answer = MathS.Pow(scale, inFront) * answer; + if (scale.Evaled is not Number.Real { IsPositive: true }) + answer = answer.Provided(new Greaterf(scale, Number.Integer.Zero)); + } + return answer; + } + + /// + /// A square root of a perfect square in is the modulus: + /// sqrt(x^2) is |x|, which for a real x is sgn(x) x, and + /// sqrt(a (x + h)^2) is sqrt(a) sgn(x + h) (x + h) for a positive number + /// a. Every rule that reads a root of a quadratic assumes it is not one: + /// 1/sqrt(1 + csch(x)^2) under u = tanh(x) is sqrt(u^2)/(u^2 - 1), + /// and the table rule for sqrt(a w^2 + b w + c) beside a linear, reached after the + /// partial fractions and a reciprocal, answered it with a logarithm of zero. + /// https://github.com/asc-community/AngouriMath/issues/718 + /// + /// + /// At every depth, unlike , since the + /// misreading is at depth; and the square root only, not (x^2 + 2x + 1)^(5/2), + /// which that rule writes as sgn(x + 1) (x + 1)^5 at the top. Below a + /// substitution the variable is one whose sign the substitution knows, and a sign + /// written for it is a factor the rest of the search has to carry: + /// tanh(x)/(a + b tanh(x)^2)^(5/2) under u = e^(2x) holds + /// (1 + 2u + u^2)^(5/2), and with that rewritten the search ran past its budget + /// where it had answered in twenty seconds. + /// + internal static Entity? SolveByTakingARootOfAPerfectSquare(Entity expr, Entity.Variable x, bool integrateByParts) + { + // Asked of every integrand at every depth, so the radicand is read as a polynomial + // only where it is small enough to be a written square: x^2, or a x^2 + b x + c. + static bool MayBeARootOfASquare(Entity node, Entity.Variable x) + => node is Powf(var radicand, Number.Rational r) && r.ERational.Equals(ERational.Create(1, 2)) + && radicand.ContainsNode(x) && radicand.Complexity <= 12 + && radicand.Nodes.Count(inner => inner == x) <= 2; + if (!expr.Nodes.Any(node => MayBeARootOfASquare(node, x))) + return null; + var changed = false; + var written = expr.Replace(node => + { + if (!MayBeARootOfASquare(node, x)) + return node; + var (radicand, exponent) = (Powf)node; + var r = (Number.Rational)exponent; + if (!TreeAnalyzer.TryGetPolynomial(radicand, x, out var monomials) || monomials.Count == 0) + return node; + var degree = monomials.Keys.Max()!; + if (!degree.Equals(EInteger.FromInt32(2)) || monomials.Keys.Any(k => k.Sign < 0)) + return node; + var a = monomials.TryGetValue(EInteger.FromInt32(2), out var a2) ? a2 : Number.Integer.Zero; + var b = monomials.TryGetValue(EInteger.One, out var b1) ? b1 : Number.Integer.Zero; + var c = monomials.TryGetValue(EInteger.Zero, out var c0) ? c0 : Number.Integer.Zero; + if (a.Evaled is not Number.Real { IsPositive: true } leading || b.Evaled is not Number.Real || c.Evaled is not Number.Real + || (b * b - Number.Integer.Create(4) * a * c).InnerSimplified.Evaled is not Number.Complex { IsZero: true }) + return node; + // a (x + h)^2 with h = b/(2a): (a (x + h)^2)^r is a^r |x + h|^(2r), and with 2r odd + // (a rational is held in lowest terms) that is a^r sgn(x + h) (x + h)^(2r). + var h = (b / (Number.Integer.Create(2) * a)).InnerSimplified; + var linear = h == Number.Integer.Zero ? x : (x + h).InnerSimplified; + var twoR = Number.Integer.Create(r.ERational.Numerator); + Entity power = twoR == Number.Integer.One ? linear : MathS.Pow(linear, twoR); + Entity signed = MathS.Signum(linear) * power; + changed = true; + return leading == Number.Integer.One ? signed : MathS.Pow(leading, r) * signed; + }); + return changed ? Integration.ComputeAsTheSameQuestion(written, x, integrateByParts) : null; + } + /// /// A whole power of a product in which the variable stands beside a constant, written /// as the product of the powers: (c x)^2 is c^2 x^2, exact for a whole diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs index 3a72288b6..aa8d60cd5 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs @@ -501,6 +501,10 @@ private static Entity Normalized(Entity expr, Entity.Variable x) => // An exponential of a multiple of a logarithm is a power of the argument, which is // how every inverse hyperbolic function under an exponential arrives. if ((answer = IndefiniteIntegralSolver.SolveByFoldingAnExponentialOfALogarithm(expr, x, integrateByParts)) is { }) return answer; + // A fractional power of a perfect square is the power of the modulus, sgn(P) P^(2r). + if ((answer = IndefiniteIntegralSolver.SolveByTakingARootOfAPerfectSquare(expr, x, integrateByParts)) is { }) return answer; + // x^(n - 1) g(x^n) with a symbolic n is g(u)/n under u = x^n. + if ((answer = IndefiniteIntegralSolver.SolveByAPowerOfTheVariableTimesAFunctionOfItsPower(expr, x, integrateByParts)) is { }) return answer; // A whole power of a product of a constant and the variable, as the product of // the powers, which is how the inverse hyperbolic secant and cosecant arrive. if ((answer = IndefiniteIntegralSolver.SolveByDistributingWholePowersOfProducts(expr, x, integrateByParts)) is { }) return answer; diff --git a/Sources/Tests/UnitTests/Calculus/APowerTimesAFunctionOfItsPowerTest.cs b/Sources/Tests/UnitTests/Calculus/APowerTimesAFunctionOfItsPowerTest.cs new file mode 100644 index 000000000..ddf611006 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/APowerTimesAFunctionOfItsPowerTest.cs @@ -0,0 +1,72 @@ +// +// Copyright (c) 2019-2026 Angouri. +// AngouriMath is licensed under MIT. +// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. +// Website: https://am.angouri.org. +// + +using System; +using AngouriMath.Extensions; +using Xunit; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// x^(k n - 1) g(x^n) with a symbolic n is u^(k - 1) g(u)/n under + /// u = x^n; Rubi's 6.5.2 and 6.6.2 write the power in front as (e x)^(n - 1), + /// which is e^(n - 1) x^(n - 1) for a positive e, and the answer says so. + /// #718 + /// + [Trait("Area", "Calculus")] + public sealed class APowerTimesAFunctionOfItsPowerTest + { + private static readonly double[] Points = { 0.3, 0.7, 1.1, 1.9, 2.6 }; + + /// Pinned with n = 5/2, a = 1/3, b = 1/2, c = 3/2, d = 2/3, e = 5/4. + private static void DifferentiatesBack(string integrand) + { + var integral = integrand.ToEntity().Integrate("x"); + Assert.DoesNotContain("integral(", integral.Stringize()); + Entity Pinned(Entity e) => e.Substitute("C", 0).Substitute("n", "5/2".ToEntity()).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; + 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}"); + } + + [Theory] + [InlineData("x^(n-1)*e^(x^n)")] + [InlineData("x^(2*n-1)*e^(x^n)")] + [InlineData("(pe*x)^(-1+n)*(a+b*csch(c+d*x^n))")] + [InlineData("(pe*x)^(-1+n)/(a+b*csch(c+d*x^n))")] + [InlineData("(pe*x)^(-1+n)*sech(c+d*x^n)^2")] + [InlineData("(pe*x)^(-1+n)/(a+b*sech(c+d*x^n))^2")] + public void APowerTimesAFunctionOfItsPower(string integrand) => DifferentiatesBack(integrand); + + [Fact] + public void TheScaleIsSaidToBePositive() + { + var integral = "(pe*x)^(-1+n)*e^(x^n)".ToEntity().Integrate("x"); + Assert.Contains(integral.Nodes, node => node is Entity.Providedf(_, var predicate) && predicate == "pe > 0".ToEntity()); + Assert.Equal("e^(x^n)/n".ToEntity().Simplify(), "x^(n-1)*e^(x^n)".ToEntity().Integrate("x").Substitute("C", 0).Simplify()); + } + + /// A power in front that is not one less than a multiple of the power inside is left alone. + [Fact] + public void APowerThatIsNotTheDerivativeIsLeftAsWritten() + => Assert.Contains("integral(", "x^n*e^(x^n)".ToEntity().Integrate("x").Stringize()); + } +} diff --git a/Sources/Tests/UnitTests/Calculus/RootOfAPerfectSquareIntegralTest.cs b/Sources/Tests/UnitTests/Calculus/RootOfAPerfectSquareIntegralTest.cs new file mode 100644 index 000000000..9a2f8cdb1 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/RootOfAPerfectSquareIntegralTest.cs @@ -0,0 +1,68 @@ +// +// Copyright (c) 2019-2026 Angouri. +// AngouriMath is licensed under MIT. +// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. +// Website: https://am.angouri.org. +// + +using System; +using AngouriMath.Extensions; +using Xunit; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// A square root of a perfect square is the modulus, sgn(P) P for a real P, at + /// every depth, and the rules that read a root of a quadratic must not see one: + /// 1/sqrt(1 + csch(x)^2) under u = tanh(x) is sqrt(u^2)/(u^2 - 1), which + /// the table rule for a root of a quadratic beside a linear answered with a logarithm of zero. + /// #718 + /// + [Trait("Area", "Calculus")] + public sealed class RootOfAPerfectSquareIntegralTest + { + private static readonly double[] Points = { -2.3, -1.7, -0.4, 0.3, 0.7, 1.1, 1.9 }; + + private static void DifferentiatesBack(string integrand) + { + var integral = integrand.ToEntity().Integrate("x").Substitute("C", 0); + Assert.DoesNotContain("integral(", integral.Stringize()); + var derivative = integral.Differentiate("x"); + var original = integrand.ToEntity(); + var compared = 0; + 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 >= 5, $"only {compared} of {Points.Length} points were comparable for {integrand}"); + } + + [Theory] + [InlineData("1/sqrt(1+csch(x)^2)")] + [InlineData("sqrt(x^2)/(x^2-1)")] + [InlineData("sqrt(x^2)/(x+2)")] + [InlineData("(x^2+2*x+1)^(3/2)/(x+3)")] + [InlineData("(4*x^2-4*x+1)^(1/2)*e^x")] + [InlineData("sqrt(sinh(x)^2)")] + public void ARootOfAPerfectSquareIsTheModulus(string integrand) => DifferentiatesBack(integrand); + + [Fact] + public void TheSignIsTheSignOfTheLinearFactor() + { + var integral = "sqrt(x^2)/(x+2)".ToEntity().Integrate("x").Substitute("C", 0); + Assert.Contains(integral.Nodes, node => node is Entity.Signumf(var argument) && argument == "x".ToEntity()); + // sgn(x) (x - 2 ln(x + 2)), compared as a value on each side of the sign change. + var difference = integral - "sgn(x) * (x - 2 * ln(x + 2))".ToEntity(); + foreach (var at in new[] { -1.5, 0.5, 3.0 }) + Assert.True(Math.Abs((double)difference.Substitute("x", at).EvalNumerical().RealPart) < 1e-12, $"at x = {at}: {integral}"); + } + } +}