Skip to content

Commit 6e2b2eb

Browse files
An undecided member of an intersection stays in it (#1681)
A member of a listed set whose membership in the other set could not be decided was kept in their intersection unconditionally, so { y } /\ { 2 } was { y }, wrong at every y but 2, and Solve, which meets the solution sets of a conjunction's sides, dropped an equation with a parameter in it: x = y and x = 2 solved to { y }. Such a member now stays intersected with the other set, beside the members that are decided. Closes #1680. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 6d75300 commit 6e2b2eb

4 files changed

Lines changed: 78 additions & 3 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,23 @@ of [#1409](https://github.com/asc-community/AngouriMath/issues/1409) — is `Tru
12591259
| `"x^2 = 4 and not x = 2".Solve("x")` | `{ x : x ^ 2 = 4 and not x = 2 }` | `{ -2 }` |
12601260
| `"x^2 = 4 and x > 0".Solve("x")` | `{ 2 }` | `{ 2 }` — unchanged, both sides being settled |
12611261
| `"x^6 + x*y + 1 = 0 and x - 1 = 0".Solve("x")` | `{ x : … }`, as written | unchanged |
1262+
1263+
### An undecided member of an intersection stays in it, and a conjunction keeps its second equation
1264+
1265+
**Wrong answers, silent.** A member of a listed set whose membership in the other set could not be
1266+
decided was kept in their intersection unconditionally: `{ y } /\ { 2 }` was `{ y }`, which is
1267+
wrong at every `y` but 2. `Solve` meets the solution sets of a conjunction's two sides, so an
1268+
equation with a parameter in it was dropped: `x = y and x = 2` solved to `{ y }`. Such a member now
1269+
stays intersected with the other set, beside the members that are decided
1270+
([#1680](https://github.com/asc-community/AngouriMath/issues/1680)).
1271+
1272+
| Input | Was (2.5.0) | Now |
1273+
|---|---|---|
1274+
| `"{ y } /\ { 2 }".ToEntity().Evaled` | `{ y } \/ { }` | `{ y } /\ { 2 }` |
1275+
| `"{ y, 3 } /\ { 3 }".ToEntity().Evaled` | `{ y } \/ { 3 }` | `{ 3 } \/ { y } /\ { 3 }` |
1276+
| `"x = y and x = 2".Solve("x")` | `{ y } \/ { }`, which is `{ 1 }` at `y = 1` | `{ y } /\ { 2 }`, which is empty at `y = 1` |
1277+
| `"x + y = 3 and x - y = 1".Solve("x")` | `{ 3 - y } \/ { }` | `{ 3 - y } /\ { 1 + y }`: `{ 2 }` at `y = 1`, and empty elsewhere |
1278+
| `"x^2 = 4 and x = y".Solve("x")` | `{ 2, -2 } \/ { }` | `{ 2, -2 } /\ { y }` |
12621279
### `image` and `preimage` of a set under an expression
12631280

12641281
`image(f(x), x in A)` is `{ f(x) : x in A }` — `union({f(x)}, x in A)` — listed over a listed

‎Sources/AngouriMath/Core/Entity/Omni/Sets/SetOperators.Intersection.cs‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ namespace AngouriMath.Core.Sets
1212
{
1313
internal static partial class SetOperators
1414
{
15+
/// <summary>
16+
/// The members of <paramref name="finite"/> that are in <paramref name="set"/>, and the
17+
/// intersection left as written for those whose membership is not decided.
18+
/// </summary>
19+
/// <remarks>
20+
/// An undecided member is in the intersection only where it is in the set, so it stays
21+
/// intersected with it: <c>{ y } /\ { 2 }</c> is <c>{ 2 }</c> where <c>y = 2</c> and empty
22+
/// elsewhere, and was answered <c>{ y }</c> -- which made <c>x = y and x = 2</c> solve to
23+
/// <c>{ y }</c>. https://github.com/asc-community/AngouriMath/issues/1680
24+
/// </remarks>
1525
internal static Set IntersectFiniteSetAndSet(FiniteSet finite, Set set)
1626
{
1727
var fsb = new FiniteSetBuilder();
@@ -23,7 +33,10 @@ internal static Set IntersectFiniteSetAndSet(FiniteSet finite, Set set)
2333
else if (contains)
2434
fsb.Add(elem);
2535
}
26-
return amb.IsEmpty ? fsb.ToFiniteSet() : amb.ToFiniteSet().Unite(fsb.ToFiniteSet());
36+
if (amb.IsEmpty)
37+
return fsb.ToFiniteSet();
38+
var undecided = new Intersectionf(amb.ToFiniteSet(), set);
39+
return fsb.IsEmpty ? undecided : fsb.ToFiniteSet().Unite(undecided);
2740
}
2841

2942
internal static Set IntersectIntervalAndInterval(Interval A, Interval B)

‎Sources/Tests/UnitTests/Algebra/ConjunctionFilterTest.cs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,44 @@ public void AnUndecidedConditionLeavesTheConjunctionWritten()
4646
Assert.IsType<Set.ConditionalSet>(solved);
4747
}
4848

49+
/// <summary>
50+
/// Two listed sets meet only where their members agree: <c>x = y and x = 2</c> is
51+
/// <c>{ 2 }</c> at <c>y = 2</c> and empty elsewhere. It was <c>{ y }</c>, the second
52+
/// equation dropped, since a member of an intersection whose membership was undecided
53+
/// was kept. <see href="https://github.com/asc-community/AngouriMath/issues/1680"/>
54+
/// </summary>
55+
[Theory]
56+
[InlineData("x = y and x = 2", 2, "{2}")]
57+
[InlineData("x = y and x = 2", 0, "{}")]
58+
[InlineData("x + y = 3 and x - y = 1", 1, "{2}")]
59+
[InlineData("x + y = 3 and x - y = 1", 0, "{}")]
60+
[InlineData("x^2 = 4 and x = y", -2, "{-2}")]
61+
[InlineData("x^2 = 4 and x = y", 3, "{}")]
62+
public void ListedSetsWithAParameterMeetWhereTheyAgree(string statement, int y, string expected)
63+
{
64+
var solved = (Set)statement.ToEntity().Solve("x").Substitute("y", y).Evaled;
65+
var wanted = (Set)expected.ToEntity().Evaled;
66+
Assert.Equal(Boolean.True, MathS.Sets.Subset(solved, wanted).Evaled);
67+
Assert.Equal(Boolean.True, MathS.Sets.Subset(wanted, solved).Evaled);
68+
}
69+
70+
/// <summary>
71+
/// The same for the intersection itself: a member it cannot decide stays intersected
72+
/// with the other set, beside the members it can.
73+
/// </summary>
74+
[Theory]
75+
[InlineData("{ y } /\\ { 2 }", 2, "{2}")]
76+
[InlineData("{ y } /\\ { 2 }", 3, "{}")]
77+
[InlineData("{ y, 3 } /\\ { 3 }", 2, "{3}")]
78+
[InlineData("{ 1, 2 } /\\ { 2, y }", 1, "{1, 2}")]
79+
public void AnUndecidedMemberOfAnIntersectionStaysInIt(string intersection, int y, string expected)
80+
{
81+
var met = (Set)intersection.ToEntity().Evaled.Substitute("y", y).Evaled;
82+
var wanted = (Set)expected.ToEntity().Evaled;
83+
Assert.Equal(Boolean.True, MathS.Sets.Subset(met, wanted).Evaled);
84+
Assert.Equal(Boolean.True, MathS.Sets.Subset(wanted, met).Evaled);
85+
}
86+
4987
/// <summary>The inner statement of injectivity, and injectivity itself, for a linear map; the quadratic is refuted by a witness.</summary>
5088
[Fact]
5189
public void InjectivityOfALinearMapIsDecided()

‎Sources/Tests/UnitTests/Algebra/SolveTest/SolveEquationWithConstraints.cs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,15 @@ public void TestFinite(string expr, int rootCount)
5656
AssertRoots(eq, "x", root);
5757
}
5858

59-
[Fact(Skip = "Sets require more work")]
60-
public void TestFiniteIntersection() => TestFinite("x2 = a and x = a", 1);
59+
// x^2 = a and x = a holds only where a^2 = a: x = 0 at a = 0, x = 1 at a = 1, and for no
60+
// x elsewhere. https://github.com/asc-community/AngouriMath/issues/1680
61+
[Theory]
62+
[InlineData(0, "{ 0 }")]
63+
[InlineData(1, "{ 1 }")]
64+
[InlineData(4, "{ }")]
65+
[InlineData(-1, "{ }")]
66+
public void TestFiniteIntersection(int a, string expected)
67+
=> Assert.Equal(expected.ToEntity().Evaled, "x2 = a and x = a".Solve("x").Substitute("a", a).Evaled);
6168

6269
[Theory]
6370
[InlineData(@"x \/ { 1, 2 } = { 1, 2 }", "{ { }, { 1 }, { 2 }, { 1, 2 } }")]

0 commit comments

Comments
 (0)