From 8753e41df3cb9f267d8f9a17e3c56c84ec973940 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Sat, 28 Nov 2026 21:49:53 +0000 Subject: [PATCH] Cancel the logarithms of the moduli of polynomials at -oo (#2633) At -oo a factor such as x + 1 is negative. The real-logarithm rewrite (#2616) therefore takes its logarithm in the antiderivative as ln|x + 1|. The degree split before the limit at an infinite bound (#2626) reads only polynomials, so it declined, and 1/(x^5 + 1) over (-oo, -2] was left unevaluated while its mirror over [2, +oo) was answered. ln|a| = d ln|x| + ln(|a| / |x|^d) holds for every real x but 0, just as ln(a) does for a positive. The modulus of a polynomial now has that polynomial's degree. Co-Authored-By: Claude Opus 5.5 --- BREAKING-CHANGES.md | 16 ++++++++ .../Integration/Integration.Definition.cs | 7 ++++ .../LogarithmsCancelAtMinusInfinityTest.cs | 37 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 Sources/Tests/UnitTests/Calculus/LogarithmsCancelAtMinusInfinityTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 5b268de30..6d8e43fea 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -148,6 +148,22 @@ converges, what is left tends to the logarithms of the leading coefficients | `integral(1/(x^7+1), x, 0, +oo)` | unevaluated | `pi / (7 sin(pi/7))`, written through `cotan(pi/7)` | | `integral(1/(x^5+1), x, 1, +oo)` | unevaluated | `0.18064…`, in closed form | +### Logarithms cancel at -oo as they do at +oo + +**An answer where there was none.** At `-oo` a factor such as `x + 1` is negative, and its logarithm in the +antiderivative is taken of its modulus, `ln|x + 1|`. The divergent parts of the logarithms were cancelled for +polynomials only, so `1/(x^5 + 1)` over `(-oo, -2]` was left unevaluated where over `[2, +oo)` it was answered. The +modulus of a polynomial now counts as having the polynomial's degree, since `ln|a| = d ln|x| + ln(|a| / |x|^d)`. +Over `(-oo, +oo)` the same integrand has a pole at `-1`, where its two sides are `-oo` and `+oo`, so it has no value +(`NaN`), as `1/x` over `[-1, 1]` has none +([#2633](https://github.com/asc-community/AngouriMath/issues/2633)). + +| simplified | Was (2.10.0) | Now | +|---|---|---| +| `integral(1/(x^5+1), x, -oo, -2)` | unevaluated | `-0.01584…`, in closed form | +| `integral(x/(x^5+1), x, -oo, -2)` | unevaluated | `0.04216…`, in closed form | +| `integral(1/(x^5+1), x, -oo, +oo)` | unevaluated | `NaN`: it diverges at `x = -1` | + ### An integral through a sum over roots is not NaN at infinity, nor taken across a real root **Not silent: wrong answers.** The antiderivative of `1/(x^3 + x + 1)` is a sum over the roots of `r^3 + r + 1`. diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs index cfa71cd04..a4ffece95 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs @@ -635,6 +635,13 @@ bool IsPositiveOnTheWay(Entity argument) // The degree of a polynomial in x with numeric coefficients, or null. Integer? DegreeOf(Entity argument) { + // The modulus of a polynomial, which the real logarithms are taken of where the polynomial is negative + // on the way: ln|a| = d ln|x| + ln(|a| / |x|^d) for every real x but 0, as ln(a) is for a positive. At + // -oo, x + 1 of the antiderivative of 1/(x^5 + 1) is negative, its logarithm is ln|x + 1|, and read as no + // polynomial it left the integral over (-oo, -2] unevaluated where over [2, +oo) it was answered. + // https://github.com/asc-community/AngouriMath/issues/2633 + if (argument is Absf(var inside)) + argument = inside; if (Functions.Algebra.LimitSolvers.ParseAsPolynomial(argument, x) is not { Count: > 0 } monomials) return null; var highest = monomials.Keys.Max()!; diff --git a/Sources/Tests/UnitTests/Calculus/LogarithmsCancelAtMinusInfinityTest.cs b/Sources/Tests/UnitTests/Calculus/LogarithmsCancelAtMinusInfinityTest.cs new file mode 100644 index 000000000..2f0dc7fda --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/LogarithmsCancelAtMinusInfinityTest.cs @@ -0,0 +1,37 @@ +// +// 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 +{ + /// + /// At -oo a factor such as x + 1 is negative, and its logarithm in the antiderivative is taken as + /// ln|x + 1|. The logarithms' divergent parts were cancelled only for polynomials, not for their moduli, so + /// 1/(x^5 + 1) over (-oo, -2] was left unevaluated, while over [2, +oo) it was answered. + /// https://github.com/asc-community/AngouriMath/issues/2633 + /// + [Trait("Area", "Calculus")] + public sealed class LogarithmsCancelAtMinusInfinityTest + { + /// Values from mpmath's quadrature at 50 digits. + [Theory] + [InlineData("1/(x^5 + 1)", "-oo", "-2", "-0.0158464764791928627633934699598")] + [InlineData("1/(x^3 + 1)", "-oo", "-2", "-0.131787532408771838087216376644")] + [InlineData("x/(x^5 + 1)", "-oo", "-2", "0.0421645551880158608736332906964")] + public void TheIntegralDownToMinusInfinityIsAnswered(string integrand, string from, string to, string expected) + { + var integral = integrand.ToEntity().Integrate("x", from.ToEntity(), to.ToEntity()).Simplify(); + Assert.DoesNotContain(integral.Nodes, node => node is Integralf); + var difference = (integral - expected.ToEntity()).EvalNumerical(); + Assert.True(difference.Abs() < 1e-12, $"{integrand} over [{from}, {to}] was {integral}, not {expected}"); + } + } +}