The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V33. Data structures and computation

Mathlib.Data.List.NodupEquivFin

19 declarations. Mathlib docs · Source

Equivalence between Fin (length l) and elements of a list

Given a list l,

  • if l has no duplicates, then List.Nodup.getEquiv is the equivalence between Fin (length l) and {x // x ∈ l} sending i to ⟨get l i, _⟩ with the inverse sending ⟨x, hx⟩ to ⟨indexOf x l, _⟩;

  • if l has no duplicates and contains every element of a type α, then List.Nodup.getEquivOfForallMemList defines an equivalence between Fin (length l) and α; if α does not have decidable equality, then there is a bijection List.Nodup.getBijectionOfForallMemList;

  • if l is sorted w.r.t. (<), then List.SortedLT.getIso is the same bijection reinterpreted as an OrderIso.

theorem OrderEmbedding.ofMapLEIff.congr_simp E1 #

∀ {α : Type u_6} {β : Type u_7} [inst : PartialOrder α] [inst_1 : Preorder β] (f f_1 : α → β) (e_f : f = f_1)
  (hf : ∀ (a b : α), f a ≤ f b ↔ a ≤ b), OrderEmbedding.ofMapLEIff f hf = OrderEmbedding.ofMapLEIff f_1 ⋯

def List.Nodup.getBijectionOfForallMemList E1 #

{α : Type u_1} → (l : List α) → l.Nodup → (∀ (x : α), x ∈ l) → { f // Function.Bijective f }

If l lists all the elements of α without duplicates, then List.get defines a bijection Fin l.length → α. See List.Nodup.getEquivOfForallMemList for a version giving an equivalence when there is decidable equality.

theorem List.Nodup.getBijectionOfForallMemList_coe E0 #

∀ {α : Type u_1} (l : List α) (nd : l.Nodup) (h : ∀ (x : α), x ∈ l) (i : Fin l.length),
  ↑(List.Nodup.getBijectionOfForallMemList l nd h) i = l.get i

def List.Nodup.getEquiv E1 #

{α : Type u_1} → [DecidableEq α] → (l : List α) → l.Nodup → Fin l.length ≃ { x // x ∈ l }

If l has no duplicates, then List.get defines an equivalence between Fin (length l) and the set of elements of l.

theorem List.Nodup.getEquiv_apply_coe E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (H : l.Nodup) (i : Fin l.length),
  ↑((List.Nodup.getEquiv l H) i) = l.get i

theorem List.Nodup.getEquiv_symm_apply_val E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (H : l.Nodup) (x : { x // x ∈ l }),
  ↑((List.Nodup.getEquiv l H).symm x) = List.idxOf (↑x) l

def List.Nodup.getEquivOfForallMemList E1 #

{α : Type u_1} → [DecidableEq α] → (l : List α) → l.Nodup → (∀ (x : α), x ∈ l) → Fin l.length ≃ α

If l lists all the elements of α without duplicates, then List.get defines an equivalence between Fin l.length and α.

See List.Nodup.getBijectionOfForallMemList for a version without decidable equality.

theorem List.Nodup.getEquivOfForallMemList_apply E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (nd : l.Nodup) (h : ∀ (x : α), x ∈ l) (i : Fin l.length),
  (List.Nodup.getEquivOfForallMemList l nd h) i = l.get i

theorem List.Nodup.getEquivOfForallMemList_symm_apply_val E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (nd : l.Nodup) (h : ∀ (x : α), x ∈ l) (a : α),
  ↑((List.Nodup.getEquivOfForallMemList l nd h).symm a) = List.idxOf a l

def List.getEquivOfForallCountEqOne E1 #

{α : Type u_1} → [inst : DecidableEq α] → (l : List α) → (∀ (x : α), List.count x l = 1) → Fin l.length ≃ α

Alternative phrasing of List.Nodup.getEquivOfForallMemList using List.count.

theorem List.getEquivOfForallCountEqOne_apply E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (h : ∀ (x : α), List.count x l = 1) (i : Fin l.length),
  (l.getEquivOfForallCountEqOne h) i = l[↑i]

theorem List.getEquivOfForallCountEqOne_symm_apply_val E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (l : List α) (h : ∀ (x : α), List.count x l = 1) (a : α),
  ↑((l.getEquivOfForallCountEqOne h).symm a) = List.idxOf a l

def List.SortedLT.getIso E1 #

{α : Type u_1} → [inst : Preorder α] → [DecidableEq α] → (l : List α) → l.SortedLT → Fin l.length ≃o { x // x ∈ l }

If l is a list sorted w.r.t. (<), then List.get defines an order isomorphism between Fin (length l) and the set of elements of l.

theorem List.SortedLT.coe_getIso_apply E0 #

∀ {α : Type u_1} [inst : Preorder α] {l : List α} [inst_1 : DecidableEq α] (H : l.SortedLT) {i : Fin l.length},
  ↑((List.SortedLT.getIso l H) i) = l.get i

theorem List.SortedLT.coe_getIso_symm_apply E0 #

∀ {α : Type u_1} [inst : Preorder α] {l : List α} [inst_1 : DecidableEq α] (H : l.SortedLT) {x : { x // x ∈ l }},
  ↑((List.SortedLT.getIso l H).symm x) = List.idxOf (↑x) l

theorem List.sublist_of_orderEmbedding_getElem?_eq E0 #

∀ {α : Type u_1} {l l' : List α} (f : ℕ ↪o ℕ), (∀ (ix : ℕ), l[ix]? = l'[f ix]?) → l.Sublist l'

If there is f, an order-preserving embedding of ℕ into ℕ such that any element of l found at index ix can be found at index f ix in l', then Sublist l l'.

theorem List.sublist_iff_exists_orderEmbedding_getElem?_eq E0 #

∀ {α : Type u_1} {l l' : List α}, l.Sublist l' ↔ ∃ f, ∀ (ix : ℕ), l[ix]? = l'[f ix]?

A l : List α is Sublist l l' for l' : List α iff there is f, an order-preserving embedding of ℕ into ℕ such that any element of l found at index ix can be found at index f ix in l'.

theorem List.sublist_iff_exists_fin_orderEmbedding_get_eq E0 #

∀ {α : Type u_1} {l l' : List α}, l.Sublist l' ↔ ∃ f, ∀ (ix : Fin l.length), l.get ix = l'.get (f ix)

A l : List α is Sublist l l' for l' : List α iff there is f, an order-preserving embedding of Fin l.length into Fin l'.length such that any element of l found at index ix can be found at index f ix in l'.

theorem List.duplicate_iff_exists_distinct_get E1 #

∀ {α : Type u_1} {l : List α} {x : α}, List.Duplicate x l ↔ ∃ n m, ∃ (_ : n < m), x = l.get n ∧ x = l.get m

An element x : α of l : List α is a duplicate iff it can be found at two distinct indices n m : ℕ inside the list l.