diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index d5b2b35ed..23f7e89fd 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -241,6 +241,22 @@ logarithms. Where nothing cancels, the integral diverges and is now `+oo`, where | `integral((2x+1)/(x^4+2x^3+x^2-x-1), x, 1, +oo)` | unevaluated | a sum over roots = `0.64121…` | | `integral(x^2/(x^3+x+1), x, 0, +oo)` | `NaN` | `+oo` | +### A rational integral down to -oo is the reflection of one up to +oo + +**An answer where there was none.** A sum over roots in an antiderivative was taken at `+oo` but not at `-oo`. There, +`ln(x - r)` nears the logarithm's cut from a side that depends on the sign of `Im r`, which a root computed to a hundred +digits does not decide for a real root. So `1/(x^3 + 3x - 1)` over `(-oo, -1]` was left unevaluated while its mirror +image over `[1, +oo)` was answered, and 2.10.0 answered it `NaN`. Where nothing else answers, the integral of `f` over +`(-oo, b]` is now taken as the integral of `f(-t)` over `[-b, +oo)`, which it equals exactly. Over the whole line it is +split at 0. A pole on the line still leaves the integral without a finite value +([#2646](https://github.com/asc-community/AngouriMath/issues/2646)). + +| simplified | Was (2.10.0) | Now | +|---|---|---| +| `integral(1/(x^3 + 3x - 1), x, -oo, -1)` | `NaN` | a sum over roots = `-0.21006…` | +| `integral(1/(x^3 + x + 1), x, -oo, -1)` | `NaN` | a sum over roots = `-0.45528…` | +| `integral(1/(x^4 + x + 1), x, -oo, +oo)` | `NaN` | a sum over roots = `2.68354…` | + ### An inequality with abs of x is solved **Not silent: an inequality that threw has an answer.** `Solve` threw `NotSufficientlySupportedException`, *"Only diff --git a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs index 065636252..26a6c80a2 100644 --- a/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs +++ b/Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs @@ -65,8 +65,42 @@ public Entity Integrate(Variable x, Entity from, Entity 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) + ?? Reflected(this, x, from, to) ?? new Integralf(this, x, (from, to)); + /// + /// The integral down to -oo as the integral of f(-t) up to +oo, which it is exactly: the + /// integral of f over (-oo, b] is that of f(-t) over [-b, +oo), and over the line it + /// is the two halves split at 0. where a bound is not -oo or a half is not found. + /// + /// + /// An antiderivative's sum over roots, sum(c(r) ln(x - r)), is taken at +oo through the + /// Euler–Jacobi identity, but at -oo each ln(x - r) nears the cut of the logarithm from a side that + /// depends on the sign of Im r, which a root found to a hundred digits does not decide for a real root. So + /// the bound had no value, and 1/(x^3 + 3x - 1) over (-oo, -1] was left unevaluated where its + /// mirror over [1, +oo) was answered. Reflected, the range ends at +oo, where no side is asked. + /// Asked only after every other route has declined. + /// https://github.com/asc-community/AngouriMath/issues/2646 + /// + private static Entity? Reflected(Entity expr, Variable x, Entity from, Entity to) + { + if (from.Evaled is not Number.Real { EDecimal: var lower } || !lower.IsNegativeInfinity() + || to.Evaled is not Number.Real { EDecimal: var upper } || upper.IsNegativeInfinity() || upper.IsNaN()) + return null; + // Simplified, so that (-x)^3, which the integrator does not read as a polynomial, is -x^3. + var mirrored = expr.Substitute(x, -x).Simplify(); + if (upper.IsPositiveInfinity()) + { + var left = mirrored.Integrate(x, Integer.Zero, to); + var right = expr.Integrate(x, Integer.Zero, to); + return left.Nodes.Any(node => node is Integralf) || right.Nodes.Any(node => node is Integralf) + ? null + : left + right; + } + var reflected = mirrored.Integrate(x, (-to).InnerSimplified, Number.Real.PositiveInfinity); + return reflected.Nodes.Any(node => node is Integralf) ? null : reflected; + } + /// /// F(b) - F(a) through , taken piece by piece /// where it breaks between the bounds, or where a piece's limit at diff --git a/Sources/Tests/UnitTests/Calculus/AnIntegralDownToMinusInfinityIsReflectedTest.cs b/Sources/Tests/UnitTests/Calculus/AnIntegralDownToMinusInfinityIsReflectedTest.cs new file mode 100644 index 000000000..61f3510d4 --- /dev/null +++ b/Sources/Tests/UnitTests/Calculus/AnIntegralDownToMinusInfinityIsReflectedTest.cs @@ -0,0 +1,48 @@ +// +// 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 AngouriMath.Extensions; +using Xunit; +using static AngouriMath.Entity; + +namespace AngouriMath.Tests.Calculus +{ + /// + /// An antiderivative's sum over roots was taken at +oo but not at -oo, so a rational integral down to + /// -oo was left unevaluated where its mirror up to +oo was answered. It is that mirror: the integral + /// of f over (-oo, b] is the integral of f(-t) over [-b, +oo). + /// https://github.com/asc-community/AngouriMath/issues/2646 + /// + [Trait("Area", "Calculus")] + public sealed class AnIntegralDownToMinusInfinityIsReflectedTest + { + /// Values from mpmath's quadrature at 30 digits. + [Theory] + [InlineData("1/(x^3 + 3x - 1)", "-oo", "-1", "-0.210069487870138069538043374088")] + [InlineData("(x - 2)/(x^4 + 3x + 1)", "-oo", "-2", "-0.245750699454190650886057045255")] + [InlineData("1/(x^3 + x + 1)", "-oo", "-1", "-0.455282857458523731560685952094")] + [InlineData("1/(x^5 + x + 1)", "-oo", "-1", "-0.236966741788900650729018693228")] + [InlineData("1/(x^4 + x + 1)", "-oo", "0", "1.84767065241331529668108960843")] + [InlineData("1/(x^4 + x + 1)", "-oo", "+oo", "2.68354824425647647957447074409")] + [InlineData("x^2/(x^4 + x + 1)", "-oo", "+oo", "2.49678114001004324638111179546")] + public void TheIntegralIsItsValue(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); + Assert.True((integral - expected.ToEntity()).EvalNumerical().Abs() < 1e-12, + $"{integrand} over [{from}, {to}] was {integral}, not {expected}"); + } + + /// A pole on the line leaves no finite value: the reflection does not jump over it. + [Fact] + public void APoleOnTheLineIsNotJumpedOver() + { + var integral = "1/(x^3 + x + 1)".ToEntity().Integrate("x", "-oo".ToEntity(), "+oo".ToEntity()).Simplify(); + Assert.False(integral.Evaled is Number.Complex { IsFinite: true }, $"over the line it was {integral}"); + } + } +}