From ebbba37ab16c266d3399d00dc2e6d024ad0c26fa Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 28 Sep 2026 20:04:38 +0000 Subject: [PATCH] An interval meets a union of any number of pieces, and two set builders are equal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An interval met a union piece by piece only where the union had two pieces, each an interval or a listed set, so the solution set of x^2 - 3 x + 2 >= 0, { 2 } \/ (-oo; 1] \/ (2; +oo), was not met with (1; 2) and came out as written. Any union built of such pieces is met piece by piece now, and Sullivan and Mackey's §3 Try 8, { x in RR : x^2 - 3 x + 2 >= 0 } = { y in RR : y <= 1 or y >= 2 }, is True by double containment. Part of #1409. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 15 ++++++++++++++- .../Evaluation.Omni/Evaluation.Omni.Classes.cs | 12 +++++++++--- Sources/Tests/UnitTests/Core/Sets/SubsetTest.cs | 4 ++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index edd19a65c..f820b16f1 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -653,6 +653,19 @@ too ([#1409](https://github.com/asc-community/AngouriMath/issues/1409)). `subset | `{1, 3} in powerset(ZZ)` | `UnrecognizedFunctionParseException` | `True` | | `card({1, {}})` | `#{ 1, { } }` — left as written | `2` | +### An interval meets a union of any number of pieces + +An interval met a union piece by piece only where the union had two pieces, each an interval or +a listed set. The solution set of `x^2 - 3 x + 2 >= 0` comes out in three, +`{ 2 } \/ (-oo; 1] \/ (2; +oo)`, so its meeting with `(1; 2)` was left as written, and the two set +builders of Sullivan and Mackey's §3 Try 8 were not found equal. Any union built of such pieces is +met piece by piece now ([#1409](https://github.com/asc-community/AngouriMath/issues/1409)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `{ x in RR : x^2 - 3 x + 2 >= 0 } = { y in RR : y <= 1 or y >= 2 }` | left as written | `True` | +| `"({ 2 } \/ (-oo; 1] \/ (2; +oo)) /\ (1; 2)".ToEntity().Evaled` | left as written | `{ }` | + ### An integer range is listed, and a family of sets has a union and an intersection `ZZ /\ [1; 10]` lists its members now — an integer set cut by a numeric interval with at most @@ -701,7 +714,7 @@ emptiness as a proof: `forall x in RR : x^2 in ZZ` was `True` | Input | Was (2.5.0) | Now | |---|---|---| -| `"x^2 in (0; 1)".Solve("x")` | `{}` — wrong | `((-oo; 0) \/ (0; +oo)) /\ (-1; 1)` | +| `"x^2 in (0; 1)".Solve("x")` | `{}` — wrong | `(-1; 0) \/ (0; 1)` | | `"x^2 in {1, 4}".Solve("x")` | `{}` — wrong | `{ 1, -1, 2, -2 }` | | `"x^2 in ZZ".Solve("x")` | `{}` — wrong | `{ x : x ^ 2 in ZZ }`, left as written | | `forall x in RR : x^2 in ZZ` | `UnhandledParseException` (quantifiers are new since) | `False` | diff --git a/Sources/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Classes.cs b/Sources/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Classes.cs index eba60c10b..f51e005f3 100644 --- a/Sources/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Classes.cs +++ b/Sources/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Classes.cs @@ -183,10 +183,12 @@ protected override Entity InnerSimplify(bool isExact) => MathS.Intersection(rest, SetOperators.IntersectIntervalAndInterval(one, another)).InnerSimplified(isExact), // An interval meets a union of intervals piece by piece, which is what // an inequality's solution set is: (0; +oo) /\ ((-oo; -2) \/ (0; 1/2)) - // is (0; 1/2), where as written it met nothing it could read. - (Interval interval, Unionf(var left, var right)) when left is Interval or FiniteSet && right is Interval or FiniteSet + // is (0; 1/2), where as written it met nothing it could read. The + // union may have more than two pieces: x^2 - 3 x + 2 >= 0 is solved to + // { 2 } \/ (-oo; 1] \/ (2; +oo), and that meets (1; 2) in nothing. + (Interval interval, Unionf(var left, var right) union) when MadeOfPieces(union) => MathS.Union(MathS.Intersection(interval, left).InnerSimplified(isExact), MathS.Intersection(interval, right).InnerSimplified(isExact)).InnerSimplified(isExact), - (Unionf(var left, var right), Interval interval) when left is Interval or FiniteSet && right is Interval or FiniteSet + (Unionf(var left, var right) union, Interval interval) when MadeOfPieces(union) => MathS.Union(MathS.Intersection(left, interval).InnerSimplified(isExact), MathS.Intersection(right, interval).InnerSimplified(isExact)).InnerSimplified(isExact), // (A \ B) /\ C is (A /\ C) \ B, where A meets C first: the pre-image // (RR \ { -1 }) /\ (-oo; -1) is (-oo; -1) \ { -1 }, which is the interval. @@ -197,6 +199,10 @@ protected override Entity InnerSimplify(bool isExact) _ => null }, (@this, a, b) => ((Intersectionf)@this).New(a, b), isExact, propagateSet: false); + + /// Whether the set is intervals and listed sets joined by unions, each of which meets an interval in something it can read. + private static bool MadeOfPieces(Entity set) + => set is Interval or FiniteSet || set is Unionf(var left, var right) && MadeOfPieces(left) && MadeOfPieces(right); } partial record SetMinusf diff --git a/Sources/Tests/UnitTests/Core/Sets/SubsetTest.cs b/Sources/Tests/UnitTests/Core/Sets/SubsetTest.cs index cddb63971..8c1b748f9 100644 --- a/Sources/Tests/UnitTests/Core/Sets/SubsetTest.cs +++ b/Sources/Tests/UnitTests/Core/Sets/SubsetTest.cs @@ -124,6 +124,10 @@ public void ANumberIsNotASet() [InlineData("ZZ = QQ", "False")] [InlineData("{ x in RR : x^2 = 1 } = {-1, 1}", "True")] [InlineData("{1, x} = {1, 2}", "{1, x} = {1, 2}")] + // §3's Try 8: two set builders, each solved to (-oo; 1] and [2; +oo), and a third that is + // not the same set. + [InlineData("{ x in RR : x^2 - 3 x + 2 >= 0 } = { y in RR : y <= 1 or y >= 2 }", "True")] + [InlineData("{ x in RR : x^2 - 3 x + 2 >= 0 } = { y in RR : y < 1 or y > 2 }", "False")] public void SetsAreEqualByDoubleContainment(string statement, string expected) => Assert.Equal(expected.ToEntity(), Decided(statement));