Skip to content

Commit 007a362

Browse files
Membership in a set operation is decided by Kleene's connectives (#2221)
Unionf.TryContains returned the right side's verdict whenever the left did not say yes, so a left side that left membership open and a right side that excluded the element made the union False. 2^89 - 1 is a Mersenne prime, past the machine word, where PP leaves membership open: (2^89 - 1) in (PP \/ [0; 1]) False, on 2.6.0 and master (2^89 - 1) in ([0; 1] \/ PP) left as written A union contains what either side contains. It is now Kleene's or: a member where either side decides it is, outside where both decide it is not, and open otherwise. Intersectionf and SetMinusf were not wrong. Each decided only where both sides did. They are now Kleene's and: an element one side decides is outside, or that a difference's right side decides is inside, is outside whatever the other side says. So (2^89 - 1) in ([0; 1] \ PP) and (2^89 - 1) in (PP \ [0; 10^30]) are False, where they were left open. Contains.cs pinned 1 in {x} \ {1} as undecided. 1 is in {1}, so it is outside the difference whatever x is, and the row now expects it decided False. Every other row of that table is unchanged. MembershipInASetOperationTest: 17 cases, of which 5 fail on master, the three union answers and the two differences. Fixes #2219. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 8707aae commit 007a362

5 files changed

Lines changed: 112 additions & 14 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,21 @@ around a principal `n`-th root of an `n`-th power, for a whole `n >= 2`, establi
521521
|---|---|---|
522522
| `"forall t in RR : t >= 0 implies sqrt(t^2) = t".ToEntity().Simplify()` | `forall t in RR : t >= 0 implies sqrt(t ^ 2) = t` | `True` |
523523

524+
### Membership in a union is not decided by one side alone
525+
526+
**Silent: a membership answered `False` is left open, where it was wrong; and some left open are decided.** Membership
527+
in a union, an intersection and a set difference is decided from each side's by Kleene's connectives. A union was
528+
`False` where one side left membership open and the other excluded the element: `2^89 - 1` is a Mersenne prime past
529+
the machine word, `PP` leaves its membership open, and it was outside `PP \/ [0; 1]`. An intersection and a difference
530+
were decided only where both sides were, and are now decided where one side settles it
531+
([#2219](https://github.com/asc-community/AngouriMath/issues/2219)).
532+
533+
| Input | Was (2.6.0) | Now |
534+
|---|---|---|
535+
| `"(2^89 - 1) in (PP \/ [0; 1])".ToEntity().Evaled` | `False` | `618970019642690137449562111 in PP \/ [0; 1]` |
536+
| `"(2^89 - 1) in ([0; 1] \ PP)".ToEntity().Evaled` | `618970019642690137449562111 in [0; 1] \ PP` | `False` |
537+
| `"(2^89 - 1) in (PP \ [0; 10^30])".ToEntity().Evaled` | `618970019642690137449562111 in PP \ [0; 1000000000000000000000000000000]` | `False` |
538+
524539
### A system is not answered with a copy of one of its rows
525540

526541
**Silent: a repeated row goes.** Two branches of an elimination can reach one solution, and each was answered: two

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
466466
[Tests/UnitTests/Core/Sets/PrimeSetTest.cs]
467467
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
468468

469+
[Tests/UnitTests/Core/Sets/MembershipInASetOperationTest.cs]
470+
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
471+
469472
[Tests/UnitTests/Calculus/InverseHyperbolicSecantIntegralTest.cs]
470473
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
471474

‎Sources/AngouriMath/Core/Entity/Omni/Entity.Omni.Classes.cs‎

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,23 @@ public override bool TryContains(Entity entity, out bool contains)
827827
{
828828
contains = false;
829829
if (Left is not Set left || Right is not Set right) return false;
830-
if (left.TryContains(entity, out contains) && contains) return true;
831-
if (right.TryContains(entity, out contains)) return true;
832-
return false;
830+
// Kleene's or: a member of either side is a member, and an element is outside only
831+
// where both sides decide it is. One side undecided and the other excluding it leaves
832+
// it undecided: 2^89 - 1 in PP \/ [0; 1] is not False, the number being prime.
833+
// https://github.com/asc-community/AngouriMath/issues/2219
834+
var leftDecided = left.TryContains(entity, out var inLeft);
835+
if (leftDecided && inLeft)
836+
{
837+
contains = true;
838+
return true;
839+
}
840+
var rightDecided = right.TryContains(entity, out var inRight);
841+
if (rightDecided && inRight)
842+
{
843+
contains = true;
844+
return true;
845+
}
846+
return leftDecided && rightDecided;
833847
}
834848

835849
internal override Priority Priority => Priority.Union;
@@ -876,12 +890,17 @@ public override bool TryContains(Entity entity, out bool contains)
876890
contains = false;
877891
if (Left is not Set left || Right is not Set right)
878892
return false;
879-
if (left.TryContains(entity, out var leftContains) && right.TryContains(entity, out var rightContains))
880-
{
881-
contains = leftContains && rightContains;
893+
// Kleene's and: an element either side decides is outside is outside, whatever the
894+
// other says, and a member only where both decide it is.
895+
// https://github.com/asc-community/AngouriMath/issues/2219
896+
var leftDecided = left.TryContains(entity, out var inLeft);
897+
if (leftDecided && !inLeft)
882898
return true;
883-
}
884-
return false;
899+
var rightDecided = right.TryContains(entity, out var inRight);
900+
if (rightDecided && !inRight)
901+
return true;
902+
contains = leftDecided && rightDecided;
903+
return contains;
885904
}
886905

887906
internal override Priority Priority => Priority.Intersection;
@@ -930,12 +949,17 @@ public override bool TryContains(Entity entity, out bool contains)
930949
contains = false;
931950
if (Left is not Set left || Right is not Set right)
932951
return false;
933-
if (left.TryContains(entity, out var leftContains) && right.TryContains(entity, out var rightContains))
934-
{
935-
contains = leftContains && !rightContains;
952+
// In the left and not in the right, by Kleene's and: outside where the left decides it
953+
// is not a member or the right decides it is, whatever the other says.
954+
// https://github.com/asc-community/AngouriMath/issues/2219
955+
var leftDecided = left.TryContains(entity, out var inLeft);
956+
if (leftDecided && !inLeft)
936957
return true;
937-
}
938-
return false;
958+
var rightDecided = right.TryContains(entity, out var inRight);
959+
if (rightDecided && inRight)
960+
return true;
961+
contains = leftDecided && rightDecided;
962+
return contains;
939963
}
940964

941965
internal override Priority Priority => Priority.SetMinus;

‎Sources/Tests/UnitTests/Core/Sets/Contains.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ public sealed class Contains
8686
[InlineData("{x} \\ {x}", "x", false)]
8787
[InlineData("{x} \\ {y}", "1", false, false)]
8888
[InlineData("{x} \\ {y}", "z", false, false)]
89-
[InlineData("{x} \\ {1}", "1", false, false)]
89+
// 1 is in {1}, and so outside the difference whatever x is: decided, by Kleene's and.
90+
// https://github.com/asc-community/AngouriMath/issues/2219
91+
[InlineData("{x} \\ {1}", "1", false)]
9092
[InlineData("{x} \\ {1}", "x", false, false)]
9193

9294
// A closed non-leaf is not a number and not a boolean, so it is a member of
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
using static AngouriMath.Entity;
12+
13+
namespace AngouriMath.Tests.Core.Sets
14+
{
15+
/// <summary>
16+
/// Membership in a union, an intersection and a difference of sets is decided from each side's by Kleene's
17+
/// connectives, where a side may leave it open: <c>2^89 - 1</c>, a Mersenne prime, is past the machine word
18+
/// and its membership in <c>PP</c> is left open. A union of <c>PP</c> with a set excluding it was
19+
/// <c>False</c>. <a href="https://github.com/asc-community/AngouriMath/issues/2219">#2219</a>
20+
/// </summary>
21+
[Trait("Area", "Core")]
22+
public sealed class MembershipInASetOperationTest
23+
{
24+
[Theory]
25+
// One side open, the other excluding it: open, in either order.
26+
[InlineData("(2^89 - 1) in (PP \\/ [0; 1])")]
27+
[InlineData("(2^89 - 1) in ([0; 1] \\/ PP)")]
28+
[InlineData("(2^89 - 1) in (PP \\/ (-oo; 0))")]
29+
[InlineData("(2^89 - 1) in (PP \\/ ({2} \\/ [5; 7]))")]
30+
// One side open, the other containing it: open for an intersection, and for a difference whose right side is open.
31+
[InlineData("(2^89 - 1) in (PP /\\ [0; 10^30])")]
32+
[InlineData("(2^89 - 1) in ([0; 10^30] \\ PP)")]
33+
[InlineData("(2^89 - 1) in (PP \\ [0; 1])")]
34+
public void LeftOpen(string input)
35+
=> Assert.IsType<Set.Inf>(input.ToEntity().Evaled);
36+
37+
[Theory]
38+
// A union holds where either side does.
39+
[InlineData("(2^89 - 1) in (PP \\/ [0; 10^30])", "True")]
40+
[InlineData("2 in (PP \\/ [5; 7])", "True")]
41+
[InlineData("6 in (PP \\/ [5; 7])", "True")]
42+
[InlineData("4 in (PP \\/ [5; 7])", "False")]
43+
// An intersection fails where either side does.
44+
[InlineData("(2^89 - 1) in (PP /\\ (-oo; 0))", "False")]
45+
[InlineData("(2^89 - 1) in (PP /\\ [0; 1])", "False")]
46+
[InlineData("7 in (PP /\\ [5; 10^30])", "True")]
47+
// A difference fails where its left side does, or its right side holds.
48+
[InlineData("(2^89 - 1) in ([0; 1] \\ PP)", "False")]
49+
[InlineData("(2^89 - 1) in (PP \\ [0; 10^30])", "False")]
50+
[InlineData("7 in (PP \\ [0; 5])", "True")]
51+
public void Decided(string input, string expected)
52+
=> Assert.Equal(expected.ToEntity(), input.ToEntity().Evaled);
53+
}
54+
}

0 commit comments

Comments
 (0)