The areas / V33. Data structures and computation
Mathlib.Data.List.Lattice
52 declarations and 7 deprecated aliases. Mathlib docs · Source
Lattice structure of lists
This file proves basic properties about List.disjoint, List.union, List.inter and
List.bagInter, which are defined in core Lean and Data.List.Defs.
l₁ ∪ l₂ is the list where all elements of l₁ have been inserted in l₂ in order. For example,
[0, 0, 1, 2, 2, 3] ∪ [4, 3, 3, 0] = [1, 2, 4, 3, 3, 0].
l₁ ∩ l₂ is the list of elements of l₁ in order which are in l₂. For example,
[0, 0, 1, 2, 2, 3] ∩ [4, 3, 3, 0] = [0, 0, 3].
List.bagInter l₁ l₂ is the list of elements that are in both l₁ and l₂,
counted with multiplicity and in the order they appear in l₁.
As opposed to List.inter, List.bagInter copes well with multiplicity. For example,
bagInter [0, 1, 2, 3, 2, 1, 0] [1, 0, 1, 4, 3] = [0, 1, 3, 1].
Disjoint
union
inter
bagInter
theorem List.bagInter.match_1.congr_eq_1 E1 #
∀ {α : Type u_1} (motive : List α → List α → Sort u_2) (x x_1 : List α) (h_1 : (x : List α) → motive [] x)
(h_2 : (x : List α) → motive x []) (h_3 : (a : α) → (l₁ l₂ : List α) → motive (a :: l₁) l₂) (x_2 : List α),
x = [] →
x_1 = x_2 →
(match x, x_1 with
| [], x => h_1 x
| x, [] => h_2 x
| a :: l₁, l₂ => h_3 a l₁ l₂) ≍
h_1 x_2
theorem List.bagInter.match_1.congr_eq_2 E1 #
∀ {α : Type u_1} (motive : List α → List α → Sort u_2) (x x_1 : List α) (h_1 : (x : List α) → motive [] x)
(h_2 : (x : List α) → motive x []) (h_3 : (a : α) → (l₁ l₂ : List α) → motive (a :: l₁) l₂) (x_2 : List α),
x = x_2 →
x_1 = [] →
(x_2 = [] → False) →
(match x, x_1 with
| [], x => h_1 x
| x, [] => h_2 x
| a :: l₁, l₂ => h_3 a l₁ l₂) ≍
h_2 x_2
theorem List.bagInter.induct_unfolding E1 #
∀ {α : Type u_1} [inst : BEq α] (motive : List α → List α → List α → Prop),
(∀ (x : List α), motive [] x []) →
(∀ (t : List α), (t = [] → False) → motive t [] []) →
(∀ (a : α) (l₁ l₂ : List α),
(l₂ = [] → False) →
List.elem a l₂ = true →
motive l₁ (l₂.erase a) (l₁.bagInter (l₂.erase a)) → motive (a :: l₁) l₂ (a :: l₁.bagInter (l₂.erase a))) →
(∀ (a : α) (l₁ l₂ : List α),
(l₂ = [] → False) →
¬List.elem a l₂ = true → motive l₁ l₂ (l₁.bagInter l₂) → motive (a :: l₁) l₂ (l₁.bagInter l₂)) →
∀ (a a_1 : List α), motive a a_1 (a.bagInter a_1)
theorem List.bagInter.match_1.congr_eq_3 E1 #
∀ {α : Type u_1} (motive : List α → List α → Sort u_2) (x x_1 : List α) (h_1 : (x : List α) → motive [] x)
(h_2 : (x : List α) → motive x []) (h_3 : (a : α) → (l₁ l₂ : List α) → motive (a :: l₁) l₂) (a : α) (l₁ l₂ : List α),
x = a :: l₁ →
x_1 = l₂ →
(l₂ = [] → False) →
(match x, x_1 with
| [], x => h_1 x
| x, [] => h_2 x
| a :: l₁, l₂ => h_3 a l₁ l₂) ≍
h_3 a l₁ l₂
theorem List.Disjoint.symm E1 #
∀ {α : Type u_1} {l₁ l₂ : List α}, l₁.Disjoint l₂ → l₂.Disjoint l₁
Alias of List.disjoint_symm.
instance List.instSymmDisjoint_mathlib E0 #
∀ {α : Type u_1}, Std.Symm List.Disjoint
theorem List.mem_union_left E0 #
∀ {α : Type u_1} {l₁ : List α} {a : α} [inst : DecidableEq α], a ∈ l₁ → ∀ (l₂ : List α), a ∈ l₁ ∪ l₂
theorem List.mem_union_right E0 #
∀ {α : Type u_1} {l₂ : List α} {a : α} [inst : DecidableEq α] (l₁ : List α), a ∈ l₂ → a ∈ l₁ ∪ l₂
theorem List.sublist_suffix_of_union E1 #
∀ {α : Type u_1} [inst : DecidableEq α] (l₁ l₂ : List α), ∃ t, t.Sublist l₁ ∧ t ++ l₂ = l₁ ∪ l₂
theorem List.suffix_union_right E1 #
∀ {α : Type u_1} [inst : DecidableEq α] (l₁ l₂ : List α), l₂ <:+ l₁ ∪ l₂
theorem List.union_sublist_append E1 #
∀ {α : Type u_1} [inst : DecidableEq α] (l₁ l₂ : List α), (l₁ ∪ l₂).Sublist (l₁ ++ l₂)
theorem List.forall_mem_union E1 #
∀ {α : Type u_1} {l₁ l₂ : List α} {p : α → Prop} [inst : DecidableEq α],
(∀ x ∈ l₁ ∪ l₂, p x) ↔ (∀ x ∈ l₁, p x) ∧ ∀ x ∈ l₂, p x
theorem List.forall_mem_of_forall_mem_union_left E1 #
∀ {α : Type u_1} {l₁ l₂ : List α} {p : α → Prop} [inst : DecidableEq α], (∀ x ∈ l₁ ∪ l₂, p x) → ∀ x ∈ l₁, p x
theorem List.forall_mem_of_forall_mem_union_right E1 #
∀ {α : Type u_1} {l₁ l₂ : List α} {p : α → Prop} [inst : DecidableEq α], (∀ x ∈ l₁ ∪ l₂, p x) → ∀ x ∈ l₂, p x
theorem List.Subset.union_eq_right E1 #
∀ {α : Type u_1} [inst : DecidableEq α] {xs ys : List α}, xs ⊆ ys → xs ∪ ys = ys
theorem List.inter_nil E0 #
∀ {α : Type u_1} [inst : DecidableEq α] (l : List α), [] ∩ l = []
theorem List.inter_cons_of_mem E0 #
∀ {α : Type u_1} {l₂ : List α} {a : α} [inst : DecidableEq α] (l₁ : List α), a ∈ l₂ → (a :: l₁) ∩ l₂ = a :: l₁ ∩ l₂
theorem List.inter_cons_of_notMem E0 #
∀ {α : Type u_1} {l₂ : List α} {a : α} [inst : DecidableEq α] (l₁ : List α), a ∉ l₂ → (a :: l₁) ∩ l₂ = l₁ ∩ l₂
theorem List.inter_cons E1 #
∀ {α : Type u_1} {l₂ : List α} {a : α} [inst : DecidableEq α] (l₁ : List α),
(a :: l₁) ∩ l₂ = if a ∈ l₂ then a :: l₁ ∩ l₂ else l₁ ∩ l₂
theorem List.inter_nil' E0 #
∀ {α : Type u_1} [inst : DecidableEq α] (l : List α), l ∩ [] = []
theorem List.mem_of_mem_inter_left E0 #
∀ {α : Type u_1} {l₁ l₂ : List α} {a : α} [inst : DecidableEq α], a ∈ l₁ ∩ l₂ → a ∈ l₁
theorem List.mem_of_mem_inter_right E0 #
∀ {α : Type u_1} {l₁ l₂ : List α} {a : α} [inst : DecidableEq α], a ∈ l₁ ∩ l₂ → a ∈ l₂
theorem List.mem_inter_of_mem_of_mem E0 #
∀ {α : Type u_1} {l₁ l₂ : List α} {a : α} [inst : DecidableEq α], a ∈ l₁ → a ∈ l₂ → a ∈ l₁ ∩ l₂
theorem List.inter_subset_left E1 #
∀ {α : Type u_1} [inst : DecidableEq α] {l₁ l₂ : List α}, l₁ ∩ l₂ ⊆ l₁
theorem List.inter_subset_right E1 #
∀ {α : Type u_1} [inst : DecidableEq α] {l₁ l₂ : List α}, l₁ ∩ l₂ ⊆ l₂
theorem List.subset_inter E1 #
∀ {α : Type u_1} [inst : DecidableEq α] {l l₁ l₂ : List α}, l ⊆ l₁ → l ⊆ l₂ → l ⊆ l₁ ∩ l₂
theorem List.inter_eq_nil_iff_disjoint E1 #
∀ {α : Type u_1} {l₁ l₂ : List α} [inst : DecidableEq α], l₁ ∩ l₂ = [] ↔ l₁.Disjoint l₂
theorem List.Disjoint.inter_eq_nil E1 #
∀ {α : Type u_1} {l₁ l₂ : List α} [inst : DecidableEq α], l₁.Disjoint l₂ → l₁ ∩ l₂ = []
Alias of the reverse direction of List.inter_eq_nil_iff_disjoint.
theorem List.forall_mem_inter_of_forall_left E1 #
∀ {α : Type u_1} {l₁ : List α} {p : α → Prop} [inst : DecidableEq α],
(∀ x ∈ l₁, p x) → ∀ (l₂ : List α), ∀ x ∈ l₁ ∩ l₂, p x
theorem List.forall_mem_inter_of_forall_right E1 #
∀ {α : Type u_1} {l₂ : List α} {p : α → Prop} [inst : DecidableEq α] (l₁ : List α), (∀ x ∈ l₂, p x) → ∀ x ∈ l₁ ∩ l₂, p x
theorem List.inter_reverse E0 #
∀ {α : Type u_1} [inst : DecidableEq α] {xs ys : List α}, xs ∩ ys.reverse = xs ∩ ys
theorem List.Subset.inter_eq_left E1 #
∀ {α : Type u_1} [inst : DecidableEq α] {xs ys : List α}, xs ⊆ ys → xs ∩ ys = xs
theorem List.Sublist.inter_left E1 #
∀ {α : Type u_1} [inst : DecidableEq α] {l₁ l₂ l₃ : List α}, l₂.Sublist l₃ → (l₁ ∩ l₂).Sublist (l₁ ∩ l₃)
theorem List.Sublist.inter_right E1 #
∀ {α : Type u_1} [inst : DecidableEq α] {l₁ l₂ l₃ : List α}, l₁.Sublist l₂ → (l₁ ∩ l₃).Sublist (l₂ ∩ l₃)
theorem List.nil_bagInter E0 #
∀ {α : Type u_1} [inst : DecidableEq α] (l : List α), [].bagInter l = []
theorem List.bagInter_nil E0 #
∀ {α : Type u_1} [inst : DecidableEq α] (l : List α), l.bagInter [] = []
theorem List.cons_bagInter_of_mem E0 #
∀ {α : Type u_1} {l₂ : List α} {a : α} [inst : DecidableEq α] (l₁ : List α),
a ∈ l₂ → (a :: l₁).bagInter l₂ = a :: l₁.bagInter (l₂.erase a)
theorem List.cons_bagInter_of_notMem E0 #
∀ {α : Type u_1} {l₂ : List α} {a : α} [inst : DecidableEq α] (l₁ : List α),
a ∉ l₂ → (a :: l₁).bagInter l₂ = l₁.bagInter l₂
theorem List.cons_bagInter E1 #
∀ {α : Type u_1} {l₁ l₂ : List α} {a : α} [inst : DecidableEq α],
(a :: l₁).bagInter l₂ = if a ∈ l₂ then a :: l₁.bagInter (l₂.erase a) else l₁.bagInter l₂
theorem List.bagInter_cons_of_notMem E0 #
∀ {α : Type u_1} {l₁ : List α} {a : α} [inst : DecidableEq α] (l₂ : List α),
a ∉ l₁ → l₁.bagInter (a :: l₂) = l₁.bagInter l₂
theorem List.mem_bagInter E0 #
∀ {α : Type u_1} [inst : DecidableEq α] {a : α} {l₁ l₂ : List α}, a ∈ l₁.bagInter l₂ ↔ a ∈ l₁ ∧ a ∈ l₂
theorem List.count_bagInter E0 #
∀ {α : Type u_1} [inst : DecidableEq α] {a : α} {l₁ l₂ : List α},
List.count a (l₁.bagInter l₂) = min (List.count a l₁) (List.count a l₂)
theorem List.bagInter_sublist_left E1 #
∀ {α : Type u_1} [inst : DecidableEq α] {l₁ l₂ : List α}, (l₁.bagInter l₂).Sublist l₁
theorem List.singleton_bagInter E1 #
∀ {α : Type u_1} {l₁ : List α} [inst : DecidableEq α] (a : α), [a].bagInter l₁ = if a ∈ l₁ then [a] else []
theorem List.bagInter_singleton E1 #
∀ {α : Type u_1} {l₁ : List α} [inst : DecidableEq α] (a : α), l₁.bagInter [a] = if a ∈ l₁ then [a] else []
theorem List.bagInter_erase_of_notMem E0 #
∀ {α : Type u_1} {l₁ l₂ : List α} {a : α} [inst : DecidableEq α], a ∉ l₁ → l₁.bagInter (l₂.erase a) = l₁.bagInter l₂
theorem List.erase_bagInter_of_notMem E0 #
∀ {α : Type u_1} {l₁ l₂ : List α} {a : α} [inst : DecidableEq α], a ∉ l₂ → (l₁.erase a).bagInter l₂ = l₁.bagInter l₂
theorem List.bagInter_nil_iff_inter_nil E1 #
∀ {α : Type u_1} [inst : DecidableEq α] (l₁ l₂ : List α), l₁.bagInter l₂ = [] ↔ l₁ ∩ l₂ = []
theorem List.bagInter_eq_nil_iff_disjoint E0 #
∀ {α : Type u_1} {l₁ l₂ : List α} [inst : DecidableEq α], l₁.bagInter l₂ = [] ↔ l₁.Disjoint l₂
theorem List.Nodup.bagInter_right E1 #
∀ {α : Type u_1} {l₁ l₂ : List α} [inst : DecidableEq α], l₁.Nodup → (l₁.bagInter l₂).Nodup
theorem List.Nodup.bagInter_left E1 #
∀ {α : Type u_1} {l₁ l₂ : List α} [inst : DecidableEq α], l₂.Nodup → (l₁.bagInter l₂).Nodup
theorem List.Sublist.bagInter_inter E1 #
∀ {α : Type u_1} {l₁ l₂ : List α} [inst : DecidableEq α], (l₁.bagInter l₂).Sublist (l₁ ∩ l₂)
Deprecated aliases
| Name | New name | Since |
|---|---|---|
List.bagInter_cons_of_not_mem | List.bagInter_cons_of_notMem | 2026-09-28 |
List.bagInter_erase_of_not_mem | List.bagInter_erase_of_notMem | 2026-09-28 |
List.cons_bagInteger | List.cons_bagInter | 2026-05-13 |
List.cons_bagInter_of_neg | List.cons_bagInter_of_notMem | 2026-05-13 |
List.cons_bagInter_of_not_mem | List.cons_bagInter_of_notMem | 2026-09-28 |
List.cons_bagInter_of_pos | List.cons_bagInter_of_mem | 2026-05-13 |
List.erase_bagInter_of_not_mem | List.erase_bagInter_of_notMem | 2026-09-28 |