diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index d50fcf3b7..f36b7cd27 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -131,6 +131,21 @@ it was ([#2611](https://github.com/asc-community/AngouriMath/issues/2611)). | `integral(1/x, x, -2, -1)` | `ln(-1) - ln(-2)` | `-ln(2)` | | `integral(1/(x^2-1), x, -1/2, 1/2)` | `(ln(-1/3) - ln(-3)) / 2` | `ln(1/3)` | +### ln(x) over a rational function symmetric under x -> a^2/x is integrated over [0, +oo) + +**An answer where there was none.** `ln(x)/(1 + x^2)` has no elementary antiderivative, and its integral over +`[0, +oo)` was left unevaluated. It is 0, because `x -> 1/x` maps it onto its own negative. In general, for rational `R` +with `R(a^2/x) a^2/x^2 = R(x)`, the integral of `ln(x) R(x)` is `ln(a)` times the integral of `R`. The rule applies +only where the integral converges: `R` finite at 0, no pole on the half-line, and the denominator of degree at least two +above the numerator. `ln(x)/x` has the symmetry and diverges, and it is not 0 +([#2638](https://github.com/asc-community/AngouriMath/issues/2638)). + +| simplified | Was (2.10.0) | Now | +|---|---|---| +| `integral(ln(x)/(1+x^2), x, 0, +oo)` | unevaluated | `0` | +| `integral(ln(x)/(x^2+x+1), x, 0, +oo)` | unevaluated | `0` | +| `integral(ln(x)/(4+x^2), x, 0, +oo)` | unevaluated | `pi * ln(4) / 8` | + ### Logarithms whose multiples are not rational multiples of each other cancel at infinity **An answer where there was none.** The antiderivative of `1/(x^5 + 1)` has three logarithms with the multiples diff --git a/Sources/.editorconfig b/Sources/.editorconfig index 3b57a7f5b..7a0ec46f9 100644 --- a/Sources/.editorconfig +++ b/Sources/.editorconfig @@ -30,6 +30,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed [AngouriMath/Functions/Continuous/Integration/RothsteinTrager.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 +[AngouriMath/Functions/Continuous/Integration/InversionSymmetry.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 + [AngouriMath/Functions/Continuous/Integration/CubeRootLogarithmAnsatz.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/Integration.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs index cfa71cd04..86af2c0d1 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs @@ -62,6 +62,9 @@ public Entity Integrate(Variable x, Entity from, Entity to) => // Where there is no antiderivative to take it through, an integrand holding abs(u) is split where u // changes sign. https://github.com/asc-community/AngouriMath/issues/2605 ?? Functions.Algebra.BreakpointIntegration.AcrossTheSignsOfAbs(this, x, from, to) + // ln(x) R(x) over [0, +oo) with R(1/x)/x^2 = R(x) is its own negative under x -> 1/x, and so 0, where it + // converges. https://github.com/asc-community/AngouriMath/issues/2638 + ?? Functions.Algebra.InversionSymmetry.OverTheHalfLine(this, x, from, to) ?? new Integralf(this, x, (from, to)); /// diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/InversionSymmetry.cs b/Sources/AngouriMath/Functions/Continuous/Integration/InversionSymmetry.cs new file mode 100644 index 000000000..75726c3d1 --- /dev/null +++ b/Sources/AngouriMath/Functions/Continuous/Integration/InversionSymmetry.cs @@ -0,0 +1,97 @@ +// +// 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.Collections.Generic; +using System.Linq; +using static AngouriMath.Entity; +using static AngouriMath.Entity.Number; + +namespace AngouriMath.Functions.Algebra +{ + /// + /// A definite integral over [0, +oo) of ln(x) R(x), R rational with R(a^2/x) a^2 / x^2 = R(x) + /// for some a > 0. With a = 1 it is 0: the substitution x -> 1/x maps the range onto itself + /// and the integrand ln(x) R(x) dx onto -ln(x) R(x) dx, so the integral is its own negative. Otherwise + /// it is ln(a) times the integral of R. + /// + /// + /// The integrand of ln(x)/(1 + x^2) has no elementary antiderivative, and the integral was left unevaluated. + /// The symmetry says nothing of an integral that diverges, and ln(x)/x has it, so the integral must also be + /// shown to converge: at 0, where ln(x) is integrable, R must be finite; at +oo it must fall + /// like x^-2 at least, the denominator's degree above the numerator's by two; and in between the denominator + /// must have no zero. https://github.com/asc-community/AngouriMath/issues/2638 + /// + internal static class InversionSymmetry + { + internal static Entity? OverTheHalfLine(Entity expr, Variable x, Entity from, Entity to) + { + if (from.Evaled is not Integer { IsZero: true } || to.Evaled is not Real { EDecimal: var upper } || !upper.IsPositiveInfinity()) + return null; + var logarithm = MathS.Ln(x); + if (!expr.ContainsNode(logarithm)) + return null; + // expr as ln(x) R(x), with no other ln(x) in it. + var standIn = Variable.CreateUnique(expr, "u"); + var linear = expr.Substitute(logarithm, standIn); + var rational = linear.Differentiate(standIn).Simplify(); + rational = Bare(rational); + if (rational.ContainsNode(standIn) || rational.Vars.Any(variable => variable != x) + || rational.Nodes.Any(node => node is Logf or Powf(_, not Integer)) + || Bare((linear - rational * standIn).Simplify()) != Integer.Zero) + return null; + if (rational is not Divf(var numerator, var denominator) + || Degree(numerator, x) is not { } numeratorDegree || Degree(denominator, x) is not { } denominatorDegree + || denominatorDegree < numeratorDegree + 2) + return null; + if (denominator.Substitute(x, 0).Evaled is not Complex { IsZero: false } atZero) + return null; + var zeros = new List<(Entity At, Real Value)>(); + if (!AntiderivativeBreaks.ZerosOf(denominator, x, Integer.Zero, Real.PositiveInfinity, zeros) || zeros.Count > 0) + return null; + // The scale a^2 that x -> a^2/x would have to keep: the product of the denominator's roots in modulus is + // |D(0) / lead(D)|, and a symmetric denominator has it a^(2 deg D). With a = 1 the integral is 0; otherwise + // x = a t turns it into ln(a) times the integral of R, plus the integral of ln(t) R(a t) a dt, which is 0: + // ln(x)/(4 + x^2) over [0, +oo) is ln(2) pi/4. + if (LeadingCoefficient(denominator, x, denominatorDegree) is not { } leading) + return null; + var squareOfTheScale = MathS.Pow(MathS.Abs(atZero / leading), Rational.Create(2, denominatorDegree)).InnerSimplified; + if (Bare((rational.Substitute(x, squareOfTheScale / x) * squareOfTheScale / MathS.Pow(x, 2) - rational).Simplify()) != Integer.Zero) + return null; + if (squareOfTheScale == Integer.One) + return Integer.Zero; + var ofTheRationalFunction = rational.Integrate(x, Integer.Zero, Real.PositiveInfinity).Simplify(); + if (ofTheRationalFunction.Nodes.Any(node => node is Integralf) || ofTheRationalFunction.Evaled is not Real { IsFinite: true }) + return null; + return (MathS.Ln(squareOfTheScale) / 2 * ofTheRationalFunction).Simplify(); + } + + private static Entity? LeadingCoefficient(Entity polynomial, Variable x, int degree) + => LimitSolvers.ParseAsPolynomial(polynomial, x) is { } monomials + && monomials.FirstOrDefault(monomial => monomial.Key.CompareTo(PeterO.Numbers.EDecimal.FromInt32(degree)) == 0) is { Value: { } coefficient } + ? coefficient + : null; + + private static Entity Bare(Entity expr) + { + while (expr is Providedf(var inner, _)) + expr = inner; + return expr; + } + + private static int? Degree(Entity polynomial, Variable x) + { + if (!polynomial.ContainsNode(x)) + return polynomial.Evaled is Complex ? 0 : null; + if (LimitSolvers.ParseAsPolynomial(polynomial, x) is not { Count: > 0 } monomials + || monomials.Values.Any(coefficient => coefficient.ContainsNode(x))) + return null; + var highest = monomials.Keys.Max()!; + return highest.IsInteger() && highest.Sign >= 0 && highest.CompareTo(PeterO.Numbers.EDecimal.FromInt32(1000)) < 0 + ? highest.ToInt32Checked() : null; + } + } +} diff --git a/Sources/Tests/UnitTests/Calculus/ALogarithmOverASymmetricRationalFunctionTest.cs b/Sources/Tests/UnitTests/Calculus/ALogarithmOverASymmetricRationalFunctionTest.cs new file mode 100644 index 000000000..42e41ba40 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/ALogarithmOverASymmetricRationalFunctionTest.cs @@ -0,0 +1,56 @@ +// +// 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.Linq; +using AngouriMath.Extensions; +using Xunit; +using static AngouriMath.Entity; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// ln(x)/(1 + x^2) has no elementary antiderivative, and its integral over [0, +oo) was left unevaluated. + /// It is 0: x -> 1/x maps it onto its own negative. Likewise ln(x) R(x) for any rational R with + /// R(a^2/x) a^2/x^2 = R(x) is ln(a) times the integral of R, where the integral converges. + /// https://github.com/asc-community/AngouriMath/issues/2638 + /// + [Trait("Area", "Calculus")] + public sealed class ALogarithmOverASymmetricRationalFunctionTest + { + /// Values from mpmath's quadrature at 30 digits. + [Theory] + [InlineData("ln(x)/(1 + x^2)", "0")] + [InlineData("ln(x)/(x^2 + x + 1)", "0")] + [InlineData("x ln(x)/(1 + x^2)^2", "0")] + [InlineData("ln(x) (1 + x^2)/(1 + x^4)", "0")] + [InlineData("ln(x)/(4 + x^2)", "0.544396522575900532625172224559")] + [InlineData("ln(x)/(9 + x^2)", "0.575232049203867110238970097303")] + [InlineData("ln(x)/(x^2 + 2x + 4)", "0.419076638473456469623951562782")] + [InlineData("ln(x)/(x^2 + 3)", "0.498165567681529093555754443278")] + public void TheIntegralOverTheHalfLineIsItsValue(string integrand, string expected) + { + var integral = integrand.ToEntity().Integrate("x", 0, "+oo".ToEntity()).Simplify(); + Assert.DoesNotContain(integral.Nodes, node => node is Integralf); + Assert.True((integral - expected.ToEntity()).EvalNumerical().Abs() < 1e-12, + $"{integrand} over [0, +oo) was {integral}, not {expected}"); + } + + /// + /// The symmetry without convergence says nothing: ln(x)/x has it and diverges, and with a pole on the + /// half-line, or a denominator not of degree two more, no value is given by it. + /// + [Theory] + [InlineData("ln(x)/x")] + [InlineData("ln(x)/(x^2 - 3x + 1)")] + [InlineData("ln(x) x/(x^2 + 1)")] + public void ADivergentIntegralIsNotZero(string integrand) + { + var integral = integrand.ToEntity().Integrate("x", 0, "+oo".ToEntity()).Simplify(); + Assert.False(integral.Evaled is Number.Complex { IsFinite: true }, $"{integrand} over [0, +oo) was {integral}"); + } + } +}