From 64713d34905fc0fb78f2e4c8abd42221cae2321e Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 21 Sep 2026 06:44:49 +0000 Subject: [PATCH] A listed solution set is filtered by a decided condition "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. https://github.com/asc-community/AngouriMath/issues/1409 https://github.com/asc-community/AngouriMath/issues/1036 Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 17 ++++++ Sources/.editorconfig | 3 + .../Solvers/EquationSolver/SolveStatement.cs | 38 +++++++++++- .../Algebra/ConjunctionFilterTest.cs | 58 +++++++++++++++++++ 4 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 Sources/Tests/UnitTests/Algebra/ConjunctionFilterTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 4262161f5..f38e76f9b 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -694,6 +694,23 @@ shown and the argument list of symbolic length wait for v3. Every one of these w | `1 * 2 * ... * n` | `UnhandledParseException` | `product(k, k, 1, n)`, which is `n!` for `n >= 1` | | `{1, 4, 9, ..., n}` | `UnhandledParseException` | `InvalidArgumentParseException`, naming the term off the progression | +### A listed solution set is filtered by a decided condition + +`"x^2 = 4 and not x = 2".Solve("x")` is `{ -2 }`; it was the conjunction left as written, because +#1036 taught the solver not to intersect a listed set with a condition a search had left open +(1 is a root of `x^6 + x y + 1 = 0` only when `y` is -2). The two are told apart now: a member +at which the condition is decided is kept or dropped, 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, so that `forall u in RR : forall v in RR : +2 u + 1 = 2 v + 1 implies u = v` — the injectivity of a linear map, Def 7.4.6 of the reference +of [#1409](https://github.com/asc-community/AngouriMath/issues/1409) — is `True`. + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"x^2 = 4 and not x = 2".Solve("x")` | `{ x : x ^ 2 = 4 and not x = 2 }` | `{ -2 }` | +| `"x^2 = 4 and x > 0".Solve("x")` | `{ 2 }` | `{ 2 }` — unchanged, both sides being settled | +| `"x^6 + x*y + 1 = 0 and x - 1 = 0".Solve("x")` | `{ x : … }`, as written | unchanged | + ### `binomial(n, k)` is a function **Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled diff --git a/Sources/.editorconfig b/Sources/.editorconfig index d7cf87fac..eef6a4a7f 100644 --- a/Sources/.editorconfig +++ b/Sources/.editorconfig @@ -291,6 +291,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed [AngouriMath/Functions/NumberTheory/ResidueClasses.cs] 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 +[Tests/UnitTests/Algebra/ConjunctionFilterTest.cs] +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 + [Tests/UnitTests/Algebra/MembershipSolvingTest.cs] 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 diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs index 2c73f591d..59590193a 100644 --- a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs @@ -247,9 +247,41 @@ private static Set Implication(Entity left, Entity right, Variable x) /// #1036 /// private static Set Conjunction(Set left, Set right, Entity statement, Variable x) - => (left, right) is (ConditionalSet, FiniteSet) or (FiniteSet, ConditionalSet) - ? new ConditionalSet(x, statement) - : (Set)MathS.Intersection(left, right); + => (left, right) switch + { + (ConditionalSet condition, FiniteSet listed) => Filtered(listed, condition, statement, x), + (FiniteSet listed, ConditionalSet condition) => Filtered(listed, condition, statement, x), + _ => (Set)MathS.Intersection(left, right), + }; + + /// + /// The members of a listed solution set at which the other side's condition is + /// decided: kept where it evaluates to True, dropped where False -- so + /// x^2 = 4 and not x = 2 is { -2 } -- and the conjunction as written the + /// moment one member is undecided, which is #1036's case, where a search left the + /// condition open and 1 was a root only when y was -2. + /// + private static Set Filtered(FiniteSet listed, ConditionalSet condition, Entity statement, Variable x) + { + if (condition.Var is not Variable bound) + return new ConditionalSet(x, statement); + var kept = new List(); + foreach (var member in listed) + { + // Evaluated, and simplified 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 decided + // by the simplifier and not by evaluation. + var at = condition.Predicate.Substitute(bound, member); + var decided = at.Evaled; + if (decided is not Entity.Boolean) + decided = at.Simplify(); + if (decided == Entity.Boolean.True) + kept.Add(member); + else if (decided != Entity.Boolean.False) + return new ConditionalSet(x, statement); + } + return new FiniteSet(kept); + } /// /// The solutions of difference = 0 (mod modulus) in , where diff --git a/Sources/Tests/UnitTests/Algebra/ConjunctionFilterTest.cs b/Sources/Tests/UnitTests/Algebra/ConjunctionFilterTest.cs new file mode 100644 index 000000000..d1946cc45 --- /dev/null +++ b/Sources/Tests/UnitTests/Algebra/ConjunctionFilterTest.cs @@ -0,0 +1,58 @@ +// +// Copyright (c) 2019-2026 Angouri. +// AngouriMath is licensed under MIT. +// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. +// Website: https://am.angouri.org. +// + +using AngouriMath; +using AngouriMath.Extensions; +using Xunit; +using static AngouriMath.Entity; + +namespace AngouriMath.Tests.Algebra +{ + /// + /// A conjunction whose one side is a listed solution set and whose other is a condition: + /// the members are kept where the condition is decided True at them, dropped where + /// False, and the conjunction stays written the moment one is undecided -- which is + /// #1036's case, where the condition was a search left open. x^2 = 4 and not x = 2 + /// is { -2 }; and with it the injectivity of a linear map is decided, the + /// reference's Def 7.4.6 (Sullivan and Mackey). + /// , + /// . + /// + [Trait("Area", "Algebra")] + public sealed class ConjunctionFilterTest + { + [Theory] + [InlineData("x^2 = 4 and not x = 2", "{-2}")] + [InlineData("x^2 = 4 and not x = 3", "{-2, 2}")] + [InlineData("x^2 = 4 and x > 0", "{2}")] + [InlineData("(x - 1) (x - 2) = 0 and not x = 1 and not x = 2", "{}")] + public void AListedSetIsFilteredByADecidedCondition(string statement, string expected) + { + var solved = statement.ToEntity().Solve("x"); + var wanted = (Set)expected.ToEntity().Evaled; + Assert.Equal(Boolean.True, MathS.Sets.Subset(solved, wanted).Evaled); + Assert.Equal(Boolean.True, MathS.Sets.Subset(wanted, solved).Evaled); + } + + /// #1036: a member whose condition is not decided is not kept and not dropped -- the conjunction is left as written. + [Fact] + public void AnUndecidedConditionLeavesTheConjunctionWritten() + { + var solved = "x^6 + x*y + 1 = 0 and x - 1 = 0".ToEntity().Solve("x"); + Assert.IsType(solved); + } + + /// The inner statement of injectivity, and injectivity itself, for a linear map; the quadratic is refuted by a witness. + [Fact] + public void InjectivityOfALinearMapIsDecided() + { + Assert.Equal(Boolean.True, "forall v in RR : 2 v + 1 = 2 u + 1 implies v = u".ToEntity().Evaled); + Assert.Equal(Boolean.True, "forall u in RR : forall v in RR : 2 u + 1 = 2 v + 1 implies u = v".ToEntity().Evaled); + Assert.Equal(Boolean.False, "forall u in RR : forall v in RR : u^2 = v^2 implies u = v".ToEntity().Evaled); + } + } +}