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 @@ -169,6 +169,22 @@ sum leaves the integral unevaluated ([#2624](https://github.com/asc-community/An
| `integral(1/(x^3+x+1), x, -1, 0)` | a complex number | unevaluated (it diverges) |
| `integral(1/(x^3+x+1), x, -oo, 0)` | `NaN` | unevaluated |

### A sum over roots cancels with a logarithm beside it at +oo

**An answer where there was none.** A sum over roots `sum(c(r) ln(x - r))` grows like `(sum c(r)) ln(x)` at `+oo`. It
was taken to its limit only where `sum c(r)` is 0 alone. The antiderivative of `(x + 2)/(x^4 - 2x^3 - 2x + 3)` is
`-3/4 ln(x - 1)` beside a sum with `sum c(r) = 3/4`. The two cancel together, and the integral over `[3, +oo)` was left
unevaluated. `sum c(r)` is now read exactly by the Euler–Jacobi identity, as the coefficient of `r^(n - 1)` in
`c(r) p'(r)` over `p`'s leading coefficient, and the sum stands as that multiple of `ln(x)` beside the other
logarithms. Where nothing cancels, the integral diverges and is now `+oo`, where it was left unevaluated
([#2636](https://github.com/asc-community/AngouriMath/issues/2636)).

| simplified | Was (2.10.0) | Now |
|---|---|---|
| `integral((x+2)/(x^4-2x^3-2x+3), x, 3, +oo)` | unevaluated | `3/4 ln(2) - sum(…)` = `0.16929…` |
| `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` |

### An inequality with abs of x is solved

**Not silent: an inequality that threw has an answer.** `Solve` threw `NotSufficientlySupportedException`, *"Only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,42 +382,65 @@ private static bool HoldsAnIncompleteGammaFunction(Entity expr)
{
if (!positive)
return null;
// Each sum replaced by sigma ln(x), which differs from it by what tends to 0, so that its growth meets the
// other logarithms' and the gathering cancels them together: -3/4 ln(x - 1) beside a sum with sigma = 3/4,
// in the antiderivative of (x + 2)/(x^4 - 2x^3 - 2x + 3), left the integral over [3, +oo) unevaluated where
// only a sum with sigma = 0 was taken. https://github.com/asc-community/AngouriMath/issues/2636
var settled = antiderivative.Replace(node =>
node is SumOverSetf sum && sum.ContainsNode(x) && VanishesAtPlusInfinity(sum, x) ? Integer.Zero : node);
node is SumOverSetf sum && sum.ContainsNode(x) && GrowthAtPlusInfinity(sum, x) is { } sigma
? sigma == Integer.Zero ? Integer.Zero : sigma * MathS.Ln(x)
: node);
if (settled.Nodes.Any(node => node is SumOverSetf sum && sum.ContainsNode(x)))
return null;
return AtTheBound(settled.InnerSimplified, x, bound, otherBound, continuousInside);
}

/// <summary>
/// Whether <paramref name="sum"/> is <c>sum(c(r) ln(x - r))</c> over the roots of a square-free polynomial
/// <c>p</c>, with <c>c(r) p'(r)</c> a polynomial in <c>r</c> of degree at most <c>deg p - 2</c>: then it tends
/// to 0 at <c>+oo</c> (see <see cref="AtAnInfiniteBoundThroughSumsOverRoots"/>).
/// The multiple <c>sigma = sum c(r)</c> of <c>ln(x)</c> that <paramref name="sum"/>, <c>sum(c(r) ln(x - r))</c> over
/// the roots of a square-free polynomial <c>p</c> of degree <c>n</c>, grows like at <c>+oo</c>, where
/// <c>c(r) p'(r)</c> is a polynomial <c>N(r)</c> of degree at most <c>n - 1</c>; or <see langword="null"/>.
/// </summary>
private static bool VanishesAtPlusInfinity(SumOverSetf sum, Variable x)
/// <remarks>
/// By the Euler–Jacobi identity <c>sum r^k / p'(r)</c> is 0 for <c>k &lt;= n - 2</c> and <c>1 / lead(p)</c> for
/// <c>k = n - 1</c>, so <c>sigma</c> is the coefficient of <c>r^(n - 1)</c> in <c>N</c> over <c>p</c>'s leading
/// coefficient, exactly (see <see cref="AtAnInfiniteBoundThroughSumsOverRoots"/>).
/// </remarks>
private static Entity? GrowthAtPlusInfinity(SumOverSetf sum, Variable x)
{
if (sum.Var is not Variable root || AntiderivativeBreaks.RootPolynomial(sum, x) is not { } polynomial)
return false;
return null;
var logarithm = sum.Expression.Nodes.FirstOrDefault(node =>
node is Logf(var logBase, Minusf(var variable, var subtracted)) && logBase == MathS.e && variable == x && subtracted == root);
if (logarithm is null)
return false;
return null;
var standIn = Variable.CreateUnique(sum, "u");
var linear = sum.Expression.Substitute(logarithm, standIn);
var coefficient = linear.Differentiate(standIn).InnerSimplified;
if (coefficient.ContainsNode(standIn) || coefficient.ContainsNode(x)
|| Bare((linear - coefficient * standIn).Simplify()) != Integer.Zero)
return false;
return null;
if (MathS.Polynomials.SquareFreePart(polynomial, x) is not { } squareFree
|| DegreeIn(squareFree, x) is not { } squareFreeDegree
|| DegreeIn(polynomial, x) is not { } degree || squareFreeDegree != degree || degree < 2)
return false;
return null;
// A condition the simplification writes on, that 3 r^2 + 1 is not 0, holds at every root of a
// square-free p, where p'(r) is not 0.
var numerator = Bare((coefficient.Substitute(root, x) * polynomial.Differentiate(x)).Simplify());
if (numerator == Integer.Zero)
return true;
return DegreeIn(numerator, x) is { } numeratorDegree && numeratorDegree <= degree - 2;
return Integer.Zero;
if (DegreeIn(numerator, x) is not { } numeratorDegree || numeratorDegree > degree - 1)
return null;
if (numeratorDegree <= degree - 2)
return Integer.Zero;
return CoefficientOf(polynomial, degree) is { } leading && CoefficientOf(numerator, degree - 1) is { } top
? (top / leading).InnerSimplified
: null;

Entity? CoefficientOf(Entity polynomial, int power)
=> Functions.Algebra.LimitSolvers.ParseAsPolynomial(polynomial, x) is { } monomials
&& monomials.FirstOrDefault(monomial => monomial.Key.CompareTo(PeterO.Numbers.EDecimal.FromInt32(power)) == 0) is { Value: { } coefficient }
? coefficient
: null;

static Entity Bare(Entity expr)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// 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
{
/// <summary>
/// The antiderivative of <c>(x + 2)/(x^4 - 2x^3 - 2x + 3)</c> is <c>-3/4 ln(x - 1)</c> plus a sum over the roots of a
/// cubic that grows like <c>3/4 ln(x)</c> at <c>+oo</c>. The two cancel only together, and a sum over roots was
/// taken at <c>+oo</c> only when it vanished alone, so the integral over <c>[3, +oo)</c> was left unevaluated.
/// https://github.com/asc-community/AngouriMath/issues/2636
/// </summary>
[Trait("Area", "Calculus")]
public sealed class ASumOverRootsCancelsWithALogarithmBesideItTest
{
/// <summary>Values from mpmath's quadrature at 30 digits.</summary>
[Theory]
[InlineData("(x + 2)/(x^4 - 2x^3 - 2x + 3)", "3", "0.169292631535099354480362331081")]
[InlineData("(2x + 1)/(x^4 + 2x^3 + x^2 - x - 1)", "1", "0.641214919954003672766224690615")]
[InlineData("(2x^2 + 2x - 2)/(x^4 + 2x^3 - 3x^2 - x - 3)", "2", "0.993381234988709602364110923287")]
[InlineData("(x^2 + x - 1)/(x^5 - 2x^4 + x^3 - 2x^2 + x + 1)", "2", "0.558021773663943264758932892579")]
public void TheIntegralUpToInfinityIsItsValue(string integrand, string from, string expected)
{
var integral = integrand.ToEntity().Integrate("x", from.ToEntity(), "+oo".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}, +oo) was {integral}, not {expected}");
}

/// <summary>Where the growths do not cancel the integral diverges, and is +oo.</summary>
[Fact]
public void ADivergentOneIsInfinite()
=> Assert.Equal(Number.Real.PositiveInfinity,
"(x^3 + 2)/(x^4 - 2x^3 - 2x + 3)".ToEntity().Integrate("x", 3, "+oo".ToEntity()).Simplify().Evaled);
}
}
Loading