Skip to content

Commit 58e8162

Browse files
A listed solution set is filtered by a decided condition (#1443)
"x^2 = 4 and not x = 2".Solve("x") was the conjunction left as written: #1036 taught the solver not to intersect a listed set with a condition a search had left open, since 1 is a root of x^6 + x y + 1 = 0 only when y is -2, and the rule stopped at the shape. The two are told apart now: a member at which the condition is decided is kept where it is True and dropped where it is False, and the conjunction stays written the moment one member is undecided, so #1036's case is as it was. Decided by evaluation, and by simplification where evaluation leaves it open -- the solution of 2 v + 1 = 2 u + 1 arrives as -(1 - 2u - 1)/2, and `not that = u` is the simplifier's -- so that the injectivity of a linear map, forall u in RR : forall v in RR : 2 u + 1 = 2 v + 1 implies u = v, is True: the reference's Def 7.4.6, item 6 of #1409. #1409 #1036 Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 897ba4b commit 58e8162

4 files changed

Lines changed: 112 additions & 3 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,22 @@ shown and the argument list of symbolic length wait for v3. Every one of these w
694694
| `1 * 2 * ... * n` | `UnhandledParseException` | `product(k, k, 1, n)`, which is `n!` for `n >= 1` |
695695
| `{1, 4, 9, ..., n}` | `UnhandledParseException` | `InvalidArgumentParseException`, naming the term off the progression |
696696

697+
### A listed solution set is filtered by a decided condition
698+
699+
`"x^2 = 4 and not x = 2".Solve("x")` is `{ -2 }`; it was the conjunction left as written, because
700+
#1036 taught the solver not to intersect a listed set with a condition a search had left open
701+
(1 is a root of `x^6 + x y + 1 = 0` only when `y` is -2). The two are told apart now: a member
702+
at which the condition is decided is kept or dropped, and the conjunction stays written the
703+
moment one member is undecided, so #1036's case is as it was. Decided by evaluation, and by
704+
simplification where evaluation leaves it open, so that `forall u in RR : forall v in RR :
705+
2 u + 1 = 2 v + 1 implies u = v` — the injectivity of a linear map, Def 7.4.6 of the reference
706+
of [#1409](https://github.com/asc-community/AngouriMath/issues/1409) — is `True`.
707+
708+
| Input | Was (2.5.0) | Now |
709+
|---|---|---|
710+
| `"x^2 = 4 and not x = 2".Solve("x")` | `{ x : x ^ 2 = 4 and not x = 2 }` | `{ -2 }` |
711+
| `"x^2 = 4 and x > 0".Solve("x")` | `{ 2 }` | `{ 2 }` — unchanged, both sides being settled |
712+
| `"x^6 + x*y + 1 = 0 and x - 1 = 0".Solve("x")` | `{ x : … }`, as written | unchanged |
697713
### `image` and `preimage` of a set under an expression
698714

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

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
291291
[AngouriMath/Functions/NumberTheory/ResidueClasses.cs]
292292
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
293293

294+
[Tests/UnitTests/Algebra/ConjunctionFilterTest.cs]
295+
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
296+
294297
[Tests/UnitTests/Core/Sets/ImageAndPreImageTest.cs]
295298
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
296299

‎Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs‎

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,41 @@ private static Set Implication(Entity left, Entity right, Variable x)
247247
/// <a href="https://github.com/asc-community/AngouriMath/issues/1036">#1036</a>
248248
/// </remarks>
249249
private static Set Conjunction(Set left, Set right, Entity statement, Variable x)
250-
=> (left, right) is (ConditionalSet, FiniteSet) or (FiniteSet, ConditionalSet)
251-
? new ConditionalSet(x, statement)
252-
: (Set)MathS.Intersection(left, right);
250+
=> (left, right) switch
251+
{
252+
(ConditionalSet condition, FiniteSet listed) => Filtered(listed, condition, statement, x),
253+
(FiniteSet listed, ConditionalSet condition) => Filtered(listed, condition, statement, x),
254+
_ => (Set)MathS.Intersection(left, right),
255+
};
256+
257+
/// <summary>
258+
/// The members of a listed solution set at which the other side's condition is
259+
/// decided: kept where it evaluates to <c>True</c>, dropped where <c>False</c> -- so
260+
/// <c>x^2 = 4 and not x = 2</c> is <c>{ -2 }</c> -- and the conjunction as written the
261+
/// moment one member is undecided, which is #1036's case, where a search left the
262+
/// condition open and 1 was a root only when y was -2.
263+
/// </summary>
264+
private static Set Filtered(FiniteSet listed, ConditionalSet condition, Entity statement, Variable x)
265+
{
266+
if (condition.Var is not Variable bound)
267+
return new ConditionalSet(x, statement);
268+
var kept = new List<Entity>();
269+
foreach (var member in listed)
270+
{
271+
// Evaluated, and simplified where evaluation leaves it open: the solution of
272+
// 2 v + 1 = 2 u + 1 arrives as -(1 - 2u - 1)/2, and `not that = u` is decided
273+
// by the simplifier and not by evaluation.
274+
var at = condition.Predicate.Substitute(bound, member);
275+
var decided = at.Evaled;
276+
if (decided is not Entity.Boolean)
277+
decided = at.Simplify();
278+
if (decided == Entity.Boolean.True)
279+
kept.Add(member);
280+
else if (decided != Entity.Boolean.False)
281+
return new ConditionalSet(x, statement);
282+
}
283+
return new FiniteSet(kept);
284+
}
253285

254286
/// <summary>
255287
/// The solutions of <c>difference = 0 (mod modulus)</c> in <paramref name="x"/>, where
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.Algebra
14+
{
15+
/// <summary>
16+
/// A conjunction whose one side is a listed solution set and whose other is a condition:
17+
/// the members are kept where the condition is decided <c>True</c> at them, dropped where
18+
/// <c>False</c>, and the conjunction stays written the moment one is undecided -- which is
19+
/// #1036's case, where the condition was a search left open. <c>x^2 = 4 and not x = 2</c>
20+
/// is <c>{ -2 }</c>; and with it the injectivity of a linear map is decided, the
21+
/// reference's Def 7.4.6 (Sullivan and Mackey).
22+
/// <see href="https://github.com/asc-community/AngouriMath/issues/1409"/>,
23+
/// <see href="https://github.com/asc-community/AngouriMath/issues/1036"/>.
24+
/// </summary>
25+
[Trait("Area", "Algebra")]
26+
public sealed class ConjunctionFilterTest
27+
{
28+
[Theory]
29+
[InlineData("x^2 = 4 and not x = 2", "{-2}")]
30+
[InlineData("x^2 = 4 and not x = 3", "{-2, 2}")]
31+
[InlineData("x^2 = 4 and x > 0", "{2}")]
32+
[InlineData("(x - 1) (x - 2) = 0 and not x = 1 and not x = 2", "{}")]
33+
public void AListedSetIsFilteredByADecidedCondition(string statement, string expected)
34+
{
35+
var solved = statement.ToEntity().Solve("x");
36+
var wanted = (Set)expected.ToEntity().Evaled;
37+
Assert.Equal(Boolean.True, MathS.Sets.Subset(solved, wanted).Evaled);
38+
Assert.Equal(Boolean.True, MathS.Sets.Subset(wanted, solved).Evaled);
39+
}
40+
41+
/// <summary>#1036: a member whose condition is not decided is not kept and not dropped -- the conjunction is left as written.</summary>
42+
[Fact]
43+
public void AnUndecidedConditionLeavesTheConjunctionWritten()
44+
{
45+
var solved = "x^6 + x*y + 1 = 0 and x - 1 = 0".ToEntity().Solve("x");
46+
Assert.IsType<Set.ConditionalSet>(solved);
47+
}
48+
49+
/// <summary>The inner statement of injectivity, and injectivity itself, for a linear map; the quadratic is refuted by a witness.</summary>
50+
[Fact]
51+
public void InjectivityOfALinearMapIsDecided()
52+
{
53+
Assert.Equal(Boolean.True, "forall v in RR : 2 v + 1 = 2 u + 1 implies v = u".ToEntity().Evaled);
54+
Assert.Equal(Boolean.True, "forall u in RR : forall v in RR : 2 u + 1 = 2 v + 1 implies u = v".ToEntity().Evaled);
55+
Assert.Equal(Boolean.False, "forall u in RR : forall v in RR : u^2 = v^2 implies u = v".ToEntity().Evaled);
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)