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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// The integral down to <c>-oo</c> as the integral of <c>f(-t)</c> up to <c>+oo</c>, which it is exactly: the
/// integral of <c>f</c> over <c>(-oo, b]</c> is that of <c>f(-t)</c> over <c>[-b, +oo)</c>, and over the line it
/// is the two halves split at 0. <see langword="null"/> where a bound is not <c>-oo</c> or a half is not found.
/// </summary>
/// <remarks>
/// An antiderivative's sum over roots, <c>sum(c(r) ln(x - r))</c>, is taken at <c>+oo</c> through the
/// Euler–Jacobi identity, but at <c>-oo</c> each <c>ln(x - r)</c> nears the cut of the logarithm from a side that
/// depends on the sign of <c>Im r</c>, which a root found to a hundred digits does not decide for a real root. So
/// the bound had no value, and <c>1/(x^3 + 3x - 1)</c> over <c>(-oo, -1]</c> was left unevaluated where its
/// mirror over <c>[1, +oo)</c> was answered. Reflected, the range ends at <c>+oo</c>, where no side is asked.
/// Asked only after every other route has declined.
/// https://github.com/asc-community/AngouriMath/issues/2646
/// </remarks>
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;
}

/// <summary>
/// <c>F(b) - F(a)</c> through <paramref name="antiderivative"/>, taken piece by piece
/// where it breaks between the bounds, or <see langword="null"/> where a piece's limit at
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// An antiderivative's sum over roots was taken at <c>+oo</c> but not at <c>-oo</c>, so a rational integral down to
/// <c>-oo</c> was left unevaluated where its mirror up to <c>+oo</c> was answered. It is that mirror: the integral
/// of <c>f</c> over <c>(-oo, b]</c> is the integral of <c>f(-t)</c> over <c>[-b, +oo)</c>.
/// https://github.com/asc-community/AngouriMath/issues/2646
/// </summary>
[Trait("Area", "Calculus")]
public sealed class AnIntegralDownToMinusInfinityIsReflectedTest
{
/// <summary>Values from mpmath's quadrature at 30 digits.</summary>
[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}");
}

/// <summary>A pole on the line leaves no finite value: the reflection does not jump over it.</summary>
[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}");
}
}
}
Loading