Skip to content

Keep a listed set's member that may equal one taken out, and merge member sets written another way (#2770, #2773) - #2778

Open
Rafael-SOWNet wants to merge 4 commits into
masterfrom
fix-2770-finite-set-minus-symbolic
Open

Rafael-SOWNet wants to merge 4 commits into
masterfrom
fix-2770-finite-set-minus-symbolic

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #2770
Fixes #2773

Merge after #2772. This branch contains #2772's commits (merged in, 5c467b70f), because the fix decides
membership with the FiniteSet.TryContains that #2772 makes decide by value; once #2772 lands the diff here is only
8e444f85a.

Cause

FiniteSet.TryFullSubtract took each member of the right side out of the left by its key (its evaluation), and kept
every other member of the left as though it differed from all of them.

Both are the same mechanism, membership by key; #2773's difference row is fixed by the same change, and its
construction row by the matching merge for member sets.

Change

  • FiniteSet.WithoutMembersOf (what TryFullSubtract now wraps): a member of the left is taken out where
    B.TryContains shows it is a member (by value for numbers and member sets since Decide a finite set's membership by value where the decimal key misses (#2755) #2772), kept where it is shown not
    to be one, and otherwise left undecided.
  • SetSubtractSetAndFiniteSet: where any member is undecided, the decided part is done and the difference stays
    written with only the members of the right that a kept member may equal: { a, 1 } \ { 1 } is { a } \ { 1 },
    { 1, 2, 3 } \ { 2, a } is { 1, 3 } \ { a }. This is the representation the issue proposes, and the one this
    function already gave for other sets.
  • Unionf.InvertNode (f(x) \/ A = value) needs the listed difference; where it is not decided it now declines
    rather than answering without { } at y = 1 for x \/ { 1 } = { y, 1 }.
  • WithRespelledSetsMerged: a set built with two constant member sets that each hold the other's members keeps one,
    the simplest spelling. Runs only where a set has two or more constant member sets.

Before / after

master 8b4f507c1 #2772 76a2f4a3c this branch
({ a, 1 } \ { 1 }).Simplify() { a } { a } { a } \ { 1 }
({ a, -1 } \ { a }).Simplify() { -1 } { -1 } { -1 } \ { a }
({ 22/7, b, 2 } \ { 2 }).Simplify() { 22/7, b } same { 22/7, b } \ { 2 }
({ a, b } \ { a }).Simplify() { b } same { b } \ { a }
({ a, 1 } \ { 1, 2 }).Simplify() as written as written { a } \ { 1, 2 }
({ 1, 2, 3 } \ { 2, a }).Simplify() as written as written { 1, 3 } \ { a }
(x \/ { 1 } = { y, 1 }).Solve("x") { { y }, { y, 1 } } same unsolved
({ { (1 + sqrt(2))^2 }, 1 } \ { { 3 + 2 sqrt(2) } }).InnerSimplified { { (1 + sqrt(2)) ^ 2 }, 1 } same { 1 }
({ { sqrt(8) }, 1 } \ { { 2 sqrt(2) } }).Evaled { { 2.8284…145 }, 1 } same the difference, unevaluated
{ { sqrt(8) }, { 2 sqrt(2) } } parsed two members two members { { sqrt(8) } }

{ 1, 2 } \ { a } stays as written, as before. ({ a, 1 } \ { 1 }) \/ { 1 } was { a, 1 } and is now
{ 1 } \/ ({ a } \ { 1 }): the same set, written longer.

Sweep

#2756's generator (membership of the simplified answer at sample points, 300 digits, against the definition of the
input; a, b over -1, 0, 1/2, 1, 2), with a mode for listed sets only, two seeds, and its original mixed mode
with intervals. Same inputs on each build.

master #2772 this branch
listed sets, seed 2770 (800, near-spellings perturbed): wrong 74 7 0
listed sets, seed 2771 (800): wrong 101 16 0
mixed with intervals, seed 2756 (1200): wrong 265 236 223

No row that was right on #2772's branch is wrong here. Every wrong row left in the mixed sweep has an interval with a
symbolic end, the class #2769 fixes.

Suite, harnesses, timing

Unit suite (net10.0): 22578 passed, 0 failed, 13 skipped. Library builds clean for all targets. Harnesses on this
branch: CasBench 120/121, 0 wrong; PropCheck 1355 checks, 0 failures; SimpSweep 10463/10463; RootCheck 596/596 clean;
BoundCheck 0 disagreements. Sweep simplify time on the listed-set modes is within the run-to-run spread (the runs
shared the machine).

Gate allocation (GC.GetAllocatedBytesForCurrentThread, the CommonFunctionsInterVersion inputs, two interleaved
rounds): SolveEasy 430,183 / 430,183 B/op (#2772 / branch; master 427,4xx), SimplifyEasy 28,825 / 28,825,
SimplifyHard 135.09-135.11 M on all three, Derivate 24,624 / 24,624, SolveHard 6,233,618 / 6,234,938 (+0.02%).

Trial merges

git merge-tree against #2772's head: clean. Against #2769's head: one conflict, in BREAKING-CHANGES.md, between the
two branches' own resolutions of merging #2772 into different masters (the order of the #2755 and #2721 sections), not
in this branch's entry; code merges clean.

🤖 Generated with Claude Code

Rafael-SOWNet and others added 4 commits December 6, 2026 15:25
A finite set keys its members 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, 2 sqrt(2) ends ...283146. TryContains took
the miss for "not a member" whenever both sides were constant, so
sqrt(8) in { 2 sqrt(2) } was False, the set { (1 + sqrt(2))^2, 3 + 2 sqrt(2) }
kept the number twice, and { (1 + sqrt(2))^2 } \ { 3 + 2 sqrt(2) } kept it.

On a miss, members whose evaluations are within the downcasting tolerance
of the element are compared as numbers: the same where their difference
simplifies to 0, different where enclosures in twice the working digits
are apart or the difference is a nonzero rational, and otherwise not
decided -- which TryContains reports as undecided rather than false. A
member shown the same decides membership even beside symbolic members. The
set's construction merges members shown the same, the difference of two
finite sets takes a respelled member out, and a set as an element is
compared with set members by mutual inclusion.

Evaluated, the members are decimals, which decide nothing at that
distance, as an equality of two near decimals does not: `in` asks the
written set instead, and a set operation on two evaluated sets stays
written where it returned a wrong set.

Equality of FiniteSet entities keeps comparing keys, as before, so that
entity equality never simplifies.

Measured: 600 generated respellings (radicals, rationalised and nested
forms, trigonometric and logarithmic values, complex roots, and perturbed
non-members, truth by mpmath at 200 digits) asked through TryContains,
Evaled and Simplify against sets of numbers and with a symbolic member:
master 398 / 157 wrong / 45 declined for TryContains and Evaled and
430 / 157 / 13 for Simplify; branch 600 right of 600 in each, no row worse.

Fixes #2755

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Math.Clamp and Math.ScaleB are not in netstandard2.0. The clamp is
Min/Max; 2^shift is written into the exponent bits of a double, which is
exactly 2^shift for the shifts used (0 to 1023), so the product with the
leading 62 bits of the mantissa is the same as ScaleB's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mber' into fix-2770-finite-set-minus-symbolic

# Conflicts:
#	BREAKING-CHANGES.md
…mber sets written another way

FiniteSet.TryFullSubtract took each member of the right side out of the left by its key, and
kept every other member of the left as though it differed from all of them. A member with a
variable can equal a member taken out: { a, 1 } \ { 1 } was { a }, which holds 1 at a = 1. A
member set written another way missed its key, as a member set is keyed by a set of decimals
rounded one by one, so { { (1 + sqrt(2))^2 }, 1 } \ { { 3 + 2 sqrt(2) } } kept the member.

A member of the left is now taken out by membership in the right, as FiniteSet.TryContains
decides it (by value for a number or a set since #2755), and kept only where it is shown not to
be a member. Where that is not decided the difference stays written, with what is decided
already done: { a, 1 } \ { 1 } is { a } \ { 1 }, and { 1, 2, 3 } \ { 2, a } is { 1, 3 } \ { a }.
The set-union inversion, which needs a listed difference, declines where it is not decided
rather than answer without { } at y = 1 for x \/ { 1 } = { y, 1 }. A set built with two member
sets that each hold the other's members keeps one of them.

Sweep of listed-set differences, unions and intersections checked by membership at sample
points against the definition (a, b over -1, 0, 1/2, 1, 2): 1600 cases, 175 wrong on master,
23 on #2755's branch, 0 here; none that was right got worse. On the mixed sweep with intervals
the wrong rows go 265 (master) -> 236 (#2755) -> 223, all those left at interval ends (#2756). Gate allocation
unchanged within 0.05%.

Fixes #2770
Fixes #2773

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.63%. Comparing base (8b4f507) to head (8e444f8).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2778      +/-   ##
==========================================
- Coverage   86.70%   86.63%   -0.07%     
==========================================
  Files         347      346       -1     
  Lines       77376    75798    -1578     
  Branches    22783    22207     -576     
==========================================
- Hits        67089    65668    -1421     
+ Misses       5546     5490      -56     
+ Partials     4741     4640     -101     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
fsharp 32.79% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ngouriMath/Core/Entity/Omni/Entity.Omni.Classes.cs 88.45% <ø> (+0.12%) ⬆️
...re/Entity/Omni/Sets/SetOperators.SetSubtraction.cs 90.47% <ø> (-0.44%) ⬇️
...nuous/Solvers/EquationSolver/InvertNode.Classes.cs 61.93% <ø> (-2.54%) ⬇️
...Evaluation.Discrete/Evaluation.Discrete.Classes.cs 90.12% <ø> (-0.06%) ⬇️

... and 52 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

1 participant