Skip to content

Commit c42ec55

Browse files
A definite integral's value at a bound where the antiderivative is undefined is its limit there (#1509)
* A definite integral's value at a bound where the antiderivative is undefined is its limit there A definite integral substituted each bound into the antiderivative, so -(x + 1) e^(-x) at +oo was -oo * 0 and the integral of x e^(-x) over [0, +oo) was NaN, as was ln(x) over [0, 1] from 0 * -oo at 0. Where the substitution is NaN, the bound's value is now the antiderivative's limit there from inside the range: from the left at +oo, from the right at -oo, and at a finite bound from the side the other bound is on where both are numbers. A bound the substitution answers is answered as before, and a limit that is not decided leaves the NaN, as for sin(x) over [0, +oo). Closes #1507. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura * Record the definite integral's limit at a bound in BREAKING-CHANGES Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9e9b60b commit c42ec55

4 files changed

Lines changed: 128 additions & 1 deletion

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,27 @@ undeclared variable.
15971597
| `"erfc(1)".Simplify()` | `erfc` | `erfc(1)`, and `0.157299207050285…` evaluated |
15981598
| `"erf(x)".Differentiate("x")` | `UnrecognizedFunctionParseException` | `2 / sqrt(pi) * e ^ (-x ^ 2)` |
15991599

1600+
### A definite integral is the limit at a bound where its antiderivative is undefined
1601+
1602+
`integral(x * e^(-x), x, 0, +oo)` was `NaN`, this library's way of saying a value does not
1603+
exist. It exists, and it is `1`. A definite integral substituted each bound into the
1604+
antiderivative, and `-(x + 1) e^(-x)` at `+oo` is `-oo * 0`; `x ln(x) - x` at `0` is `0 * -oo`.
1605+
At a bound where the substitution is `NaN`, the value is now the antiderivative's limit there,
1606+
taken from inside the range: from the left at `+oo`, from the right at `-oo`, and at a finite
1607+
bound from the side the other bound is on. Nothing the substitution answered changes, and an
1608+
antiderivative with no limit at the bound still gives `NaN`, as `-cos(x)` does at `+oo`
1609+
([#1507](https://github.com/asc-community/AngouriMath/issues/1507)).
1610+
1611+
| Input | Was (2.5.0) | Now |
1612+
|---|---|---|
1613+
| `integral(x * e^(-x), x, 0, +oo)` | `NaN` | `1` |
1614+
| `integral(e^(-x) * sin(x), x, 0, +oo)` | `NaN` | `1/2` |
1615+
| `integral(x^3 * e^(-x^2), x, 0, +oo)` | `integral(e ^ (-x ^ 2) * x ^ 3, x, 0, +oo)` | `1/2` |
1616+
| `integral(ln(x), x, 0, 1)` | `NaN` | `-1` |
1617+
| `integral(x * ln(x), x, 0, 1)` | `NaN` | `-1/4` |
1618+
| `integral(1/x^2, x, 0, 1)` | `NaN` | `+oo` |
1619+
| `integral(sin(x), x, 0, +oo)` | `NaN` | `NaN` |
1620+
16001621
### `binomial(n, k)` is a function
16011622

16021623
**Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,3 +621,6 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
621621

622622
[Tests/UnitTests/Calculus/InverseHyperbolicSubstitutionTest.cs]
623623
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
624+
625+
[Tests/UnitTests/Calculus/ImproperIntegralTest.cs]
626+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

‎Sources/AngouriMath/Functions/Continuous/Integration/Integration.Definition.cs‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,43 @@ public Entity Integrate(Variable x, Entity from, Entity to) =>
5757
Functions.Algebra.BreakpointIntegration.HasABreak(this, x)
5858
? Functions.Algebra.BreakpointIntegration.Split(this, x, from, to) ?? new Integralf(this, x, (from, to))
5959
: Transformation.Integration(x).Apply(this).Output is { } antiderivative
60-
? antiderivative.Substitute(x, to) - antiderivative.Substitute(x, from)
60+
? AtTheBound(antiderivative, x, to, from) - AtTheBound(antiderivative, x, from, to)
6161
: new Integralf(this, x, (from, to));
6262

63+
/// <summary>
64+
/// The antiderivative's value at one bound of a definite integral: its value there, and
65+
/// where that is undefined, its limit as the bound is approached from inside the range,
66+
/// which is what an improper integral is.
67+
/// </summary>
68+
/// <remarks>
69+
/// <c>-(x + 1) e^(-x)</c> at <c>+oo</c> is <c>-oo * 0</c>, which is <c>NaN</c>, so the integral
70+
/// of <c>x e^(-x)</c> from 0 to <c>+oo</c> was <c>NaN</c> where it is 1; and <c>x ln(x) - x</c>
71+
/// at 0 is <c>0 * -oo</c>, so the integral of <c>ln(x)</c> from 0 to 1 was <c>NaN</c> where it
72+
/// is -1. The limit is taken only where the value is undefined, so a bound the substitution
73+
/// answered is answered as before. Its side is known at an infinity, and at a finite bound
74+
/// from the other bound where both are numbers. Elsewhere, and where the limit is not
75+
/// decided, the value stays undefined, as it is for <c>sin(x)</c> from 0 to <c>+oo</c>,
76+
/// whose antiderivative has no limit there.
77+
/// </remarks>
78+
private static Entity AtTheBound(Entity antiderivative, Variable x, Entity bound, Entity otherBound)
79+
{
80+
var value = antiderivative.Substitute(x, bound);
81+
if (!value.InnerSimplified.IsNaN)
82+
return value;
83+
ApproachFrom? side = (bound.InnerSimplified, otherBound.InnerSimplified) switch
84+
{
85+
(Number.Real { EDecimal: var at }, _) when at.IsPositiveInfinity() => ApproachFrom.Left,
86+
(Number.Real { EDecimal: var at }, _) when at.IsNegativeInfinity() => ApproachFrom.Right,
87+
(Number.Real at, Number.Real other) when at > other => ApproachFrom.Left,
88+
(Number.Real at, Number.Real other) when at < other => ApproachFrom.Right,
89+
_ => null
90+
};
91+
if (side is not { } inside)
92+
return value;
93+
var limit = antiderivative.Limit(x, bound, inside);
94+
return limit.IsNaN || limit.Nodes.Any(node => node is Limitf) ? value : limit;
95+
}
96+
6397
/// <summary>
6498
/// Integrates numerically over <paramref name="x"/> between two bounds, without
6599
/// looking for an antiderivative. Only works for one-variable functions.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using AngouriMath.Extensions;
9+
using Xunit;
10+
11+
namespace AngouriMath.Tests.Calculus
12+
{
13+
/// <summary>
14+
/// A definite integral's value at a bound is the antiderivative's value there, and where that
15+
/// is undefined, its limit from inside the range, which is what an improper integral is.
16+
/// <c>-(x + 1) e^(-x)</c> at <c>+oo</c> is <c>-oo * 0</c>, so the integral of <c>x e^(-x)</c>
17+
/// over <c>[0, +oo)</c> was <c>NaN</c>; <c>x ln(x) - x</c> at 0 is <c>0 * -oo</c>, so the
18+
/// integral of <c>ln(x)</c> over <c>[0, 1]</c> was too.
19+
/// https://github.com/asc-community/AngouriMath/issues/1507
20+
/// </summary>
21+
[Trait("Area", "Calculus")]
22+
public sealed class ImproperIntegralTest
23+
{
24+
private static Entity Definite(string integrand, string from, string to)
25+
=> MathS.Integral(integrand.ToEntity(), "x", from.ToEntity(), to.ToEntity()).Simplify();
26+
27+
[Theory]
28+
[InlineData("x * e^(-x)", "0", "+oo", "1")]
29+
[InlineData("x^2 * e^(-x)", "0", "+oo", "2")]
30+
[InlineData("x^3 * e^(-x^2)", "0", "+oo", "1/2")]
31+
[InlineData("ln(x) / x^2", "1", "+oo", "1")]
32+
[InlineData("e^(-x) * sin(x)", "0", "+oo", "1/2")]
33+
[InlineData("x * e^x", "-oo", "0", "-1")]
34+
public void AnInfiniteBoundIsALimit(string integrand, string from, string to, string value)
35+
=> Assert.Equal(value.ToEntity(), Definite(integrand, from, to));
36+
37+
/// <summary>
38+
/// A finite bound is approached from the side the other bound is on, so the range may
39+
/// run either way.
40+
/// </summary>
41+
[Theory]
42+
[InlineData("ln(x)", "0", "1", "-1")]
43+
[InlineData("x * ln(x)", "0", "1", "-1/4")]
44+
[InlineData("ln(x)", "1", "0", "1")]
45+
[InlineData("x * e^(-x)", "+oo", "0", "-1")]
46+
public void ABoundWhereTheAntiderivativeIsUndefinedIsALimit(string integrand, string from, string to, string value)
47+
=> Assert.Equal(value.ToEntity(), Definite(integrand, from, to));
48+
49+
/// <summary>A divergent integral is <c>+oo</c> where the limit is.</summary>
50+
[Fact]
51+
public void ADivergentIntegralIsItsLimit() => Assert.Equal("+oo".ToEntity(), Definite("1/x^2", "0", "1"));
52+
53+
/// <summary>
54+
/// And <c>NaN</c> where there is no limit: <c>-cos(x)</c> does not settle as <c>x</c> grows.
55+
/// </summary>
56+
[Fact]
57+
public void AnAntiderivativeWithoutALimitLeavesNaN() => Assert.Equal(MathS.NaN, Definite("sin(x)", "0", "+oo"));
58+
59+
/// <summary>A bound the substitution answers is answered as it was.</summary>
60+
[Theory]
61+
[InlineData("e^(-x)", "0", "+oo", "1")]
62+
[InlineData("1/(x^2 + 1)", "-oo", "+oo", "pi")]
63+
[InlineData("x * e^(-x^2)", "0", "+oo", "1/2")]
64+
[InlineData("1/sqrt(x)", "0", "1", "2")]
65+
[InlineData("1/x", "1", "+oo", "+oo")]
66+
public void ABoundWithAValueKeepsIt(string integrand, string from, string to, string value)
67+
=> Assert.Equal(value.ToEntity(), Definite(integrand, from, to));
68+
}
69+
}

0 commit comments

Comments
 (0)