Documentation

CslibFrontier.Foundations.Data.List.Perm

List permutations and keys #

If l is a permutation of l'.map f, some permutation of l' maps onto l exactly. This reorders a list of objects to follow a given order of their images: for example, the trees of a forest in the order in which a linked list visits their roots.

Main results #

theorem List.Perm.exists_perm_map_eq {α : Type u_1} {β : Type u_2} {f : α → β} {l : List β} {l' : List α} :
l.Perm (List.map f l') → ∃ (l'' : List α), l''.Perm l' ∧ List.map f l'' = l

If l is a permutation of l'.map f, some permutation of l' maps onto l exactly.

theorem List.flatMap_filter_key_perm {α : Type u_1} {κ : Type u_2} [DecidableEq κ] {keys : List κ} {xs : List α} (key : α → κ) (hkeys : keys.Nodup) (hcover : ∀ a ∈ xs, key a ∈ keys) :
(flatMap (fun (k : κ) => filter (fun (a : α) => decide (key a = k)) xs) keys).Perm xs

Gathering the buckets of a list in a duplicate-free order that covers all its keys permutes the original list.