Documentation

CslibFrontier.Foundations.Data.List.Product

Filtering and swapping list products #

The list product l₁ ×ˢ l₂ enumerates pairs with the left element outermost. Filtering it by a predicate of one component is the product with that list filtered, as for Finset (Finset.filter_product_left), and swapping its pairs permutes it into l₂ ×ˢ l₁, as for Multiset (Multiset.map_swap_product). The list forms keep the order of the pairs, which matters when lists represent bags of rows in a fixed order.

Main results #

theorem List.filter_product_left {α : Type u_1} {β : Type u_2} (p : α → Bool) (l₁ : List α) (l₂ : List β) :
filter (fun (x : α × β) => match x with | (a, snd) => p a) (l₁ ×ˢ l₂) = filter p l₁ ×ˢ l₂

Filtering a product by a predicate of the left component filters the left list.

theorem List.filter_product_right {α : Type u_1} {β : Type u_2} (p : β → Bool) (l₁ : List α) (l₂ : List β) :
filter (fun (x : α × β) => match x with | (fst, b) => p b) (l₁ ×ˢ l₂) = l₁ ×ˢ filter p l₂

Filtering a product by a predicate of the right component filters the right list.

theorem List.perm_map_swap_product {α : Type u_1} {β : Type u_2} (l₁ : List α) (l₂ : List β) :
(map Prod.swap (l₁ ×ˢ l₂)).Perm (l₂ ×ˢ l₁)

Swapping the pairs of l₁ ×ˢ l₂ gives a permutation of l₂ ×ˢ l₁.