Skip to content

Commit 539e91e

Browse files
Rafael-SOWNetclaude
andcommitted
The interval evaluation reads the Iverson bracket
Master gained the Iverson bracket (#1567) after this branch last merged it, and neither tier had a case: an answer holding one had no value at any point. Both read it now, 1 where its statement is decided true over the interval and 0 where false, and leave it undecided otherwise, as a piecewise is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a304fb9 commit 539e91e

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎Sources/AngouriMath/Numerics/IntervalEvaluation.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,15 @@ private static ComplexInterval Evaluate(Entity expr)
416416
return Undefined;
417417
}
418418
return Undefined;
419+
case Iversonf(var statement):
420+
// 1 where the statement holds and 0 where it does not; one the intervals
421+
// cannot settle leaves the value unsettled, as a piecewise does.
422+
return Decide(statement) switch
423+
{
424+
true => ComplexInterval.Real(Interval.Exactly(1)),
425+
false => ComplexInterval.Real(Interval.Exactly(0)),
426+
null => Undefined,
427+
};
419428
default:
420429
return Undefined;
421430
}

‎Sources/AngouriMath/Numerics/PreciseEvaluation.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,15 @@ private PreciseComplexInterval EvaluateNode(Entity expr)
492492
return undefined;
493493
}
494494
return undefined;
495+
// The Iverson bracket, 1 where its statement holds and 0 where it does not, and
496+
// undefined where the statement is not decided over the rectangle, as a piecewise is.
497+
case Iversonf(var statement):
498+
return Decide(statement) switch
499+
{
500+
true => Real(PreciseInterval.Exactly(EDecimal.One)),
501+
false => Real(PreciseInterval.Exactly(EDecimal.Zero)),
502+
null => undefined,
503+
};
495504
// The special functions, each through its derivative, which is elementary; Ei, Ci
496505
// and Chi jump across the real line left of 0, and li left of 1.
497506
case Erff(var argument):

‎Sources/Tests/UnitTests/Core/IntervalEvaluationTest.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public sealed class IntervalEvaluationTest
5353
[InlineData("piecewise(1 provided 2 < 1, sin(1) provided 3 > 2)")]
5454
[InlineData("sqrt(2) provided -4 - 4 * (137/100)^2 in RR")]
5555
[InlineData("sqrt(2) provided sqrt(-2) in CC")]
56+
[InlineData("iverson(2 > 1) * sqrt(2) + iverson(sin(1) < 0)")]
5657
public void TheIntervalHoldsTheValue(string expression)
5758
{
5859
var expr = expression.ToEntity();
@@ -89,6 +90,7 @@ private static void Holds(Interval interval, EDecimal value, string expression,
8990
[InlineData("li(1)")]
9091
[InlineData("Ci(-2 + sin(pi) * i)")]
9192
[InlineData("Ei(sin(pi))")]
93+
[InlineData("iverson(sin(pi) > 0)")]
9294
public void UndecidedWhereItShouldBe(string expression)
9395
{
9496
Assert.Null(IntervalEvaluation.Of(expression.ToEntity()));
@@ -134,6 +136,7 @@ public void MoreDigitsSettleWhatDoublesCannot()
134136
[InlineData("Ci(2 + sin(pi) * i)")]
135137
[InlineData("Shi(3/2) + Chi(-1) + Chi(1 + 2i)")]
136138
[InlineData("e^(-2) * Ei(sqrt(3)) + Si(pi/4)^2")]
139+
[InlineData("iverson(pi > 3) * sqrt(2) + iverson(e < 2)")]
137140
public void ThePreciseIntervalHoldsTheValue(string expression)
138141
{
139142
var expr = expression.ToEntity();

0 commit comments

Comments
 (0)