Skip to content
Open
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
26 changes: 26 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,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 square system is answered exactly whichever order its equations are in

**Not silent: a decimal answer is now exact, and a refused system has an answer.** The eliminator took the last
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
48 changes: 45 additions & 3 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
Loading
Loading