Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,22 @@ 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 |
### `image` and `preimage` of a set under an expression

`image(f(x), x in A)` is `{ f(x) : x in A }` — `union({f(x)}, x in A)` — listed over a listed
Expand Down
3 changes: 3 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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/Core/Sets/ImageAndPreImageTest.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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,41 @@ private static Set Implication(Entity left, Entity right, Variable x)
/// <a href="https://github.com/asc-community/AngouriMath/issues/1036">#1036</a>
/// </remarks>
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),
};

/// <summary>
/// The members of a listed solution set at which the other side's condition is
/// decided: kept where it evaluates to <c>True</c>, dropped where <c>False</c> -- so
/// <c>x^2 = 4 and not x = 2</c> is <c>{ -2 }</c> -- 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.
/// </summary>
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<Entity>();
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);
}

/// <summary>
/// The solutions of <c>difference = 0 (mod modulus)</c> in <paramref name="x"/>, where
Expand Down
58 changes: 58 additions & 0 deletions Sources/Tests/UnitTests/Algebra/ConjunctionFilterTest.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 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 <c>True</c> at them, dropped where
/// <c>False</c>, and the conjunction stays written the moment one is undecided -- which is
/// #1036's case, where the condition was a search left open. <c>x^2 = 4 and not x = 2</c>
/// is <c>{ -2 }</c>; and with it the injectivity of a linear map is decided, the
/// reference's Def 7.4.6 (Sullivan and Mackey).
/// <see href="https://github.com/asc-community/AngouriMath/issues/1409"/>,
/// <see href="https://github.com/asc-community/AngouriMath/issues/1036"/>.
/// </summary>
[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);
}

/// <summary>#1036: a member whose condition is not decided is not kept and not dropped -- the conjunction is left as written.</summary>
[Fact]
public void AnUndecidedConditionLeavesTheConjunctionWritten()
{
var solved = "x^6 + x*y + 1 = 0 and x - 1 = 0".ToEntity().Solve("x");
Assert.IsType<Set.ConditionalSet>(solved);
}

/// <summary>The inner statement of injectivity, and injectivity itself, for a linear map; the quadratic is refuted by a witness.</summary>
[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);
}
}
}
Loading