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 #
List.Perm.exists_perm_map_eq: the lifted permutation.List.flatMap_filter_key_perm: gathering a list into buckets indexed by distinct keys preserves all entries and their multiplicities.
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) :
Gathering the buckets of a list in a duplicate-free order that covers all its keys permutes the original list.