Documentation

CslibFrontier.Foundations.Data.Finset.CollisionInsert

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 #

Main results #

def Finset.collisionInsert {α : Type u_1} [DecidableEq α] (s : Finset α) (p r : α) :

Insert r, or insert the reserved element p if r already belongs to s.

theorem Finset.subset_collisionInsert {α : Type u_1} [DecidableEq α] (s : Finset α) (p r : α) :
s ⊆ s.collisionInsert p r

Every old element remains after insertion with collision replacement.

theorem Finset.mem_collisionInsert {α : Type u_1} [DecidableEq α] (s : Finset α) (p r : α) :

The candidate belongs to the result even when it caused a collision.

theorem Finset.card_collisionInsert {α : Type u_1} [DecidableEq α] {s : Finset α} {p : α} (hp : p ∉ s) (r : α) :

A reserved element outside the old set makes each step add exactly one element.

theorem Finset.collisionInsert_subset {α : Type u_1} [DecidableEq α] {s S : Finset α} (hs : s ⊆ S) (p : α) {r : α} (hr : r ∈ insert p S) :
s.collisionInsert p r ⊆ insert p S

If the old set and candidate lie in S, the result lies in insert p S.

theorem Finset.erase_collisionInsert {α : Type u_1} [DecidableEq α] {s : Finset α} {p : α} (hp : p ∉ s) (r : α) :

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.

theorem Finset.collisionInsert_erase {α : Type u_1} [DecidableEq α] {s : Finset α} {r : α} (hr : r ∈ s) (p : α) :
(if p ∈ s then s.erase p else s.erase r).collisionInsert p r = s

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.