Skip to content

Commit dd5cc83

Browse files
Rafael-SOWNetclaude
andcommitted
Find the breaks of each case where a definite integral's antiderivative splits on a parameter
The antiderivative of 1/(t^2 + y^2) is a case split on y, and its case y = 0, -1/t, has a pole at 0. The breaks were looked for in the whole split, where the logarithm of the case y^2 < 0 cannot be listed, so none were looked for at all and the case y = 0 answered -1/t at the bounds: -2 over [-1, 1], 0 over the line, for a positive integrand whose integral diverges. A piecewise antiderivative whose conditions do not mention the variable is now taken across the range case by case, each with its own breaks, and the case y = 0 is +oo, as the integral of 1/t^2 over [-1, 1] is. The other cases are as they were. Part of #2461 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 28682b1 commit dd5cc83

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ The calculus nodes and the binders — `derivative`, `integral`, `limit`, `sum`,
6161
names the node and says to compile `.Evaled` or `Simplify()` instead. The LINQ compiler said the bound variable was not
6262
among the arguments.
6363

64+
### A definite integral whose antiderivative splits into cases finds the breaks of each case
65+
66+
**Silent: a wrong value is corrected.** The antiderivative of `1/(t^2 + y^2)` is a case split on `y`, and its case
67+
`y = 0`, `-1/t`, has a pole at 0. The breaks were looked for in the whole split, where the logarithm of the case
68+
`y^2 < 0` cannot be listed, so none were looked for at all, and the case `y = 0` answered `-1/t` taken at the bounds:
69+
`-2` over `[-1, 1]`, a negative value for a positive integrand whose integral diverges
70+
([#2461](https://github.com/asc-community/AngouriMath/issues/2461)). Each case whose condition is on the parameters is now
71+
taken across the range by itself, and the case `y = 0` diverges, as `integral(1/t^2, t, -1, 1)` does. The other cases
72+
are as they were. With `Simplify`, the case `y = 0` of:
73+
74+
| Input | Was (2.7.0) | Now |
75+
|---|---|---|
76+
| `integral(1/(t^2+y^2), t, -1, 1)` | `(-2) provided (y = 0)` | `+oo provided (y = 0)` |
77+
| `integral(1/(t^2+y^2), t, -oo, +oo)` | `0 provided (y = 0)` | `+oo provided (y = 0)` |
78+
| `integral(1/(t^2+y^2), t, 1, 2)` | `(1/2) provided (y = 0)` | unchanged |
79+
6480
### `factorize`, `nextprime`, `divisors`, `gradient`, `divergence` and `φ` are refused by name
6581

6682
**Not silent: these names followed by a bracket now throw `UnrecognizedFunctionParseException` where they were read as

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ public Entity Integrate(Variable x, Entity from, Entity to) =>
7575
/// </remarks>
7676
private static Entity? AcrossTheRange(Entity antiderivative, Variable x, Entity from, Entity to)
7777
{
78+
// Case by case where the cases are on the parameters, so that the breaks of each are found in it: 1/(t^2 + y^2)
79+
// is 1/t^2 at y = 0, whose antiderivative -1/t has a pole at 0, and the logarithm of the case y^2 < 0, whose
80+
// zeros cannot be listed, hid it when the antiderivative was read whole -- the integral over [-1, 1] was -2
81+
// there. https://github.com/asc-community/AngouriMath/issues/2461
82+
if (antiderivative is Piecewise piecewise && piecewise.Cases.All(@case => !@case.Predicate.ContainsNode(x)))
83+
{
84+
var cases = new List<Providedf>();
85+
foreach (var @case in piecewise.Cases)
86+
{
87+
if (AcrossTheRange(@case.Expression, x, from, to) is not { } value)
88+
return null;
89+
cases.Add(new Providedf(value, @case.Predicate));
90+
}
91+
return new Piecewise(cases);
92+
}
7893
var (lower, upper) = (from.Evaled as Number.Real, to.Evaled as Number.Real);
7994
if (lower is { IsNaN: true } || upper is { IsNaN: true })
8095
(lower, upper) = (null, null);

‎Sources/Tests/UnitTests/Calculus/IntegralAcrossABreakTest.cs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,29 @@ public void Issue2460_ACrossingOfABranchCutIsCounted(string integrand, string fr
133133
[InlineData("1/(1 + (x - i)^2)", "-1", "1")]
134134
public void Issue2460_ACrossingThatCannotBeSettledIsNotAnswered(string integrand, string from, string to)
135135
=> Assert.Contains(Definite(integrand, from, to).Nodes, node => node is Entity.Integralf);
136+
137+
/// <summary>
138+
/// The antiderivative of <c>1/(x^2 + y^2)</c> is a case split on <c>y</c>, and its case <c>y = 0</c>, <c>-1/x</c>,
139+
/// has a pole at 0 that was not looked for, since the breaks were read on the whole split and the logarithm of
140+
/// the case <c>y^2 &lt; 0</c> could not be listed: the integral over <c>[-1, 1]</c> was <c>-2</c> at
141+
/// <c>y = 0</c>. Each case is now taken across the range by itself, and that one diverges, as <c>1/x^2</c> does.
142+
/// https://github.com/asc-community/AngouriMath/issues/2461
143+
/// </summary>
144+
[Theory]
145+
[InlineData("1/(x^2 + y^2)", "-1", "1", "+oo")]
146+
[InlineData("1/(x^2 + y^2)", "-oo", "+oo", "+oo")]
147+
[InlineData("1/(x^2 + y^2)", "1", "2", "1/2")]
148+
[InlineData("1/(x^2 + y^2)", "1", "-1", "-oo")]
149+
public void Issue2461_TheCaseOfAParameterIsTakenAcrossTheRangeByItself(string integrand, string from, string to, string atZero)
150+
=> Assert.Equal(atZero.ToEntity().Simplify(), Definite(integrand, from, to).Substitute("y", 0).Simplify());
151+
152+
/// <summary>And the other cases are as they were: <c>2 arctan(1/|y|)/|y|</c> over <c>[-1, 1]</c> for a real <c>y</c>.</summary>
153+
[Theory]
154+
[InlineData(0.5)]
155+
[InlineData(-0.7)]
156+
[InlineData(2)]
157+
public void Issue2461_ANonzeroParameterKeepsItsValue(double y)
158+
=> AgreesWith(Definite("1/(x^2 + y^2)", "-1", "1").Substitute("y", y).Simplify(),
159+
2 * System.Math.Atan(1 / System.Math.Abs(y)) / System.Math.Abs(y), 0, $"the integral of 1/(x^2 + y^2) over [-1, 1] at y = {y}");
136160
}
137161
}

0 commit comments

Comments
 (0)