Skip to content
54 changes: 54 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,34 @@ them wrong past a relative `1e-90`; this branch has all 5300 exact and right. Of
part, and none that was right on master changed. The 177 left `NaN` are `cos`, `sin` and `tan` of
`10^k i` from `k = 10`, `NaN` on master too, where `cosh(10^k)` is past the exponents.

### A point at the end of an empty interval is kept, and an end is a member only of an interval known not to be empty

**Silent: wrong answers become right ones.** Uniting a point with an interval closed the interval's end at it without
asking whether the interval was empty, so the point was lost where the interval was reversed; with ends that are not
numbers, `a in [a; b]` was decided yes, which holds only for `a <= b`. An empty interval now adds nothing and meets
nothing before anything else is asked of it, and a point stays beside an interval that may be empty. The ends are
compared by value: two spellings of one number, which round apart in their last digits, are equal where their
difference simplifies to 0, values closer than the working digits are told apart by enclosures in more digits, and
what neither settles is left undecided. Measured on master `a3f3b9ed1` and on this branch
([#2756](https://github.com/asc-community/AngouriMath/issues/2756)).

| | Was | Now |
|---|---|---|
| `{ 2 } \/ (2; 1)` | `[2; 1)`, which is empty | `{ 2 }` |
| `{ 1 } \/ (2; 1)` | `(2; 1]` | `{ 1 }` |
| `{ -sqrt(3), 22/7, sqrt(2) / 2 } \/ (sqrt(2) / 2; 1/2)` | `{ -sqrt(3), 22/7 } \/ [sqrt(2) / 2; 1/2)` | `{ -sqrt(3), 22/7, sqrt(2) / 2 }` |
| `{ a } \/ (a; b)` | `[a; b)` | `{ a } \/ (a; b)` |
| `{ a } /\ [a; b]` | `{ a }` | `{ a } /\ [a; b]` |
| `[2; 1] /\ [0; 2]` | `{ 2 }` | `{ }` |
| `[1/2; 0] /\ (-oo; 1/2]` | `{ 1/2 }` | `{ }` |
| `[0; sqrt(2) / 2] \/ [1/sqrt(2); 1]` | as written | `[0; 1]` |
| `Interval.TryContains`: `a` in `[a; b]` | decided, yes | not decided |
| `Interval.TryContains`: `3` in `[a; 2]` | not decided | decided, no |
| `Interval.TryContains`: `1/sqrt(2)` in `[0; sqrt(2)/2)` | decided, yes | decided, no |
| `Interval.TryContains`: `pi + 10^(-120)` in `[0; pi]` | decided, yes | decided, no |
| `Interval.TryContains`: `pi - 10^(-120)` in `(0; pi)` | decided, no | decided, yes |
| `Interval.IsSetEmpty` of `[2; 1]` or `[a; a)` | `false` | `true` |

### A comparison of exact numbers is exact, and one the decimals cannot decide stays written

**Not silent: wrong `True` and `False` answers change.** A comparison of two evaluated numbers went through their
Expand All @@ -503,6 +531,32 @@ before v3, which decides exact comparisons exactly (#1019 §10). Two decimals th
| `sqrt(5)^1000 = 5^500` | `False` | stays written |
| `sqrt(2) < sqrt(2) + 10^(-150)` | `False` | stays written |

### A finite set holds a member written another way

**Silent: wrong answers become right ones.** A finite set looked its members up by their hundred-digit evaluations,
and one number written two ways can evaluate to decimals that differ in the last digit: `sqrt(8)` ends `...283145` and
`2 sqrt(2)` ends `...283146`. A miss on the decimal was taken for "not a member", so a set rejected its own element,
kept it twice, and did not take it out. Members whose evaluations agree that far are now compared as numbers: the same
where their difference simplifies to 0, different where enclosures in twice the working digits are apart, and otherwise
undecided. An evaluated set has only the decimals, which decide nothing at that distance, so an operation on two such
sets stays written where it gave a wrong set. Measured on master `578680eed` and on this branch
([#2755](https://github.com/asc-community/AngouriMath/issues/2755)).

| | Was (`578680eed`) | Now |
|---|---|---|
| `TryContains`: `sqrt(8)` in `{ 2 sqrt(2) }` | decided, not a member | decided, a member |
| `TryContains`: `sqrt(8)` in `{ x, 2 sqrt(2) }` | undecided | decided, a member |
| `(sqrt(8) in { -2 sqrt(2), 2 sqrt(2) }).Simplify()` | `False` | `True` |
| `(cos(pi/5) in { (1 + sqrt(5))/4 }).Evaled` | `False` | `True` |
| `{ (1 + sqrt(2))^2, 3 + 2 sqrt(2) }.Simplify()` | `{ (1 + sqrt(2)) ^ 2, 3 + 2 * sqrt(2) }` | `{ 3 + 2 * sqrt(2) }` |
| `({ (1 + sqrt(2))^2 } \ { 3 + 2 sqrt(2) }).Simplify()` | `{ (1 + sqrt(2)) ^ 2 }` | `{ }` |
| `({ (1 + sqrt(2))^2 } /\ { 3 + 2 sqrt(2) }).Simplify()` | `{ }` | `{ (1 + sqrt(2)) ^ 2 }` |
| `({ sin(pi/3) } = { sqrt(3)/2 }).Simplify()` | `False` | `True` |
| `({ sqrt(8) } \ { 2 sqrt(2) }).Evaled` | `{ 2.8284...283145 }` | the difference of the two evaluated sets, unevaluated |

Two numbers whose evaluations agree in every digit still share a key, and `pi + 10^(-120) in { pi }` is still
`True`: that is [#1376](https://github.com/asc-community/AngouriMath/issues/1376).

### A rational function in nine to sixteen variables has a canonical form

**Silent: a sum of fractions is gathered and cancelled whatever its variables are called.** A monomial held eight
Expand Down
3 changes: 3 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
[AngouriMath/Core/Entity/Omni/Sets/Cardinality.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

[AngouriMath/Core/Entity/Omni/Sets/FiniteSet.SameNumber.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/SubsetTest.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
102 changes: 67 additions & 35 deletions Sources/AngouriMath/Core/Entity/Omni/Entity.Omni.Classes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static Dictionary<Entity, Entity> BuildDictionaryFromElements(IEnumerabl
else
dict[elem.Evaled] = dict.TryGetValue(elem.Evaled, out var value) ? Simplificator.PickSimplest(elem, value) : elem;
}
return dict;
return noCheck ? dict : WithRespelledMembersMerged(dict);
}

/// <summary>
Expand Down Expand Up @@ -130,7 +130,25 @@ internal static bool TryFullSubtract(FiniteSet A, FiniteSet B, [NotNullWhen(true
var constantSets = A.Vars.Count == 0 && B.Vars.Count == 0;
var dict = BuildDictionaryFromElements(A.Elements, noCheck: true);
foreach (var el in B)
if (!dict.Remove(el.Evaled) && !constantSets) { resultSet = null; return false; }
{
if (dict.Remove(el.Evaled))
continue;
if (!constantSets) { resultSet = null; return false; }
// A member of B written otherwise than in A is taken out of A where it is
// the same number, and leaves the difference as written where that is
// not decided. https://github.com/asc-community/AngouriMath/issues/2755
if (el.Evaled is not Complex value)
continue;
switch (MemberWithTheValueOf(dict, el, value, out var key))
{
case true:
dict.Remove(key!);
break;
case null:
resultSet = null;
return false;
}
}
resultSet = new FiniteSet(dict.Values, noCheck: true); // we didn't add anything
return true;
}
Expand All @@ -142,6 +160,28 @@ public override bool TryContains(Entity entity, out bool contains)
contains = elements.ContainsKey(entity.Evaled);
// x in { x, 2 } and 2 in { x, 2 } are both unambiguously true
if (contains) return true;
// The keys are evaluations rounded to the working digits, and sqrt(8) in
// { 2 sqrt(2) } misses its key in the last digit, so the members near it are
// compared as numbers, and a set as an element with the sets among the members.
// One shown the same makes it a member whatever the others are:
// sqrt(8) in { x, 2 sqrt(2) }. One not shown either way leaves it undecided.
// https://github.com/asc-community/AngouriMath/issues/2755
if (entity.Vars.Count == 0)
{
var byValue = entity.Evaled switch
{
FiniteSet listed => MemberWithTheMembersOf(elements, entity as FiniteSet ?? listed),
Complex value => MemberWithTheValueOf(elements, entity, value, out _),
_ => false,
};
if (byValue is true)
{
contains = true;
return true;
}
if (byValue is null)
return false;
}
// however, 1 in { x, 2 }, y in { x, 2 } are both unknown
// meanwhile, 2 in { 1, 3 } is unambiguously false
return entity.Vars.Count == 0 && elements.Keys.All(el => el.Vars.Count == 0);
Expand All @@ -164,8 +204,10 @@ public bool Equals(FiniteSet? other)
return false;
if (other.Count != Count)
return false;
// Equality of entities compares the members' evaluations and proves nothing:
// it is not the membership, which can simplify to decide.
foreach (var pair in elements)
if (!other.TryContains(pair.Key, out var contains) || !contains)
if (!other.elements.ContainsKey(pair.Key))
return false;
return true;
}
Expand Down Expand Up @@ -262,44 +304,30 @@ public override Entity Replace(Func<Entity, Entity> func)
=> func(New(Left.Replace(func), Right.Replace(func)));

/// <inheritdoc/>
/// <remarks>
/// A point is a member where it is above the left end, or at it and the end is
/// closed, and below the right end likewise; failing either side decides it is not
/// one, whatever the other end is. The ends are compared by value. An end itself is
/// a member only where the interval is not empty: <c>a in [a; b]</c> holds for
/// <c>a &lt;= b</c> alone, and was decided yes, so <c>{ a } \/ (a; b)</c> was
/// closed into <c>[a; b)</c>, which loses <c>a</c> where <c>b &lt;= a</c>.
/// https://github.com/asc-community/AngouriMath/issues/2756
/// </remarks>
public override bool TryContains(Entity entity, out bool contains)
{
contains = false;
var element = entity;
entity = entity.Evaled;
if (entity is Complex and not Real)
{
contains = false;
if (entity.Evaled is Complex and not Real)
return true;
}
if (Left == Right && !(LeftClosed && RightClosed))
{
contains = false;
return true;
}
if (!IsNumeric)
{
if (entity == Left)
{
contains = LeftClosed;
return true;
}
if (entity == Right)
{
contains = RightClosed;
return true;
}
}
if (entity is not Real re)
return false;
if (!IsNumeric)
return false;
// By value, and at an end by whether it is that number, however it is written:
// https://github.com/asc-community/AngouriMath/issues/2732
if (SetOperators.Order(Left, LeftReal, element, re) is not { } fromLeft
|| SetOperators.Order(element, re, Right, RightReal) is not { } toRight)
// An end is below an infinity at the far side, whatever its value.
var fromLeft = Left == Real.NegativeInfinity && entity == Right ? -1 : SetOperators.Order(Left, entity);
var toRight = Right == Real.PositiveInfinity && entity == Left ? -1 : SetOperators.Order(entity, Right);
if (fromLeft > 0 || fromLeft == 0 && !LeftClosed || toRight > 0 || toRight == 0 && !RightClosed)
return true;
if (fromLeft is null || toRight is null)
return false;
contains = (fromLeft < 0 || LeftClosed && fromLeft == 0) && (toRight < 0 || RightClosed && toRight == 0);
contains = true;
return true;
}

Expand All @@ -326,7 +354,11 @@ public override int GetHashCode()
public override bool IsSetFinite => false;

/// <inheritdoc/>
public override bool IsSetEmpty => false;
/// <remarks>
/// Known to be empty: the left end above the right, or at it with an end open.
/// https://github.com/asc-community/AngouriMath/issues/2756
/// </remarks>
public override bool IsSetEmpty => SetOperators.IsEmpty(this);

/// <inheritdoc/>
public override Set Filter(Entity predicate, Variable over) => new ConditionalSet(over, predicate & over.In(this));
Expand Down
Loading
Loading