Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()!;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// At <c>-oo</c> a factor such as <c>x + 1</c> is negative, and its logarithm in the antiderivative is taken as
/// <c>ln|x + 1|</c>. The logarithms' divergent parts were cancelled only for polynomials, not for their moduli, so
/// <c>1/(x^5 + 1)</c> over <c>(-oo, -2]</c> was left unevaluated, while over <c>[2, +oo)</c> it was answered.
/// https://github.com/asc-community/AngouriMath/issues/2633
/// </summary>
[Trait("Area", "Calculus")]
public sealed class LogarithmsCancelAtMinusInfinityTest
{
/// <summary>Values from mpmath's quadrature at 50 digits.</summary>
[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}");
}
}
}
Loading