Insertion with a reserved replacement for collisions #
Finset.collisionInsert s p r inserts the candidate r into s, replacing it by the
reserved element p when r already belongs to s. When p ∉ s, the cardinality increases
by exactly one. The candidate remains in the result, and the original set can be recovered
from the result and candidate. This is the descending collision-replacement step in fixed-weight
sampling.
Main definitions #
Finset.collisionInsert: insert a candidate, replacing a collision by a reserved element.
Main results #
Finset.card_collisionInsert: inserting with a fresh replacement increases cardinality by one.Finset.erase_collisionInsert: recover the input from the result and the candidate.
Insert r, or insert the reserved element p if r already belongs to s.
Every old element remains after insertion with collision replacement.
The candidate belongs to the result even when it caused a collision.
A reserved element outside the old set makes each step add exactly one element.
If the old set and candidate lie in S, the result lies in insert p S.
Recover the old set by erasing the reserved element if it appears, and the candidate otherwise. The assumption that the replacement is fresh is essential.
Every element of a target set supplies a predecessor: erase the reserved element when it belongs to the target, and otherwise erase the chosen candidate.