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.Sigma

120 declarations. Mathlib docs · Source

Utilities for lists of sigmas

This file includes several ways of interacting with List (Sigma β), treated as a key-value store.

If α : Type* and β : α → Type*, then we regard s : Sigma β as having key s.1 : α and value s.2 : β s.1. Hence, List (Sigma β) behaves like a key-value store.

Main Definitions

  • List.keys extracts the list of keys.
  • List.NodupKeys determines if the store has duplicate keys.
  • List.lookup/lookup_all accesses the value(s) of a particular key.
  • List.kreplace replaces the first value with a given key by a given value.
  • List.kerase removes a value.
  • List.kinsert inserts a value.
  • List.kunion computes the union of two stores.
  • List.kextract returns a value with a given key and the rest of the values.

keys

NodupKeys

dlookup

lookupAll

kreplace

kerase

kinsert

kextract

dedupKeys

kunion

theorem List.dlookup.congr_simp E1 #

∀ {α : Type u} {β : α → Type v} {inst : DecidableEq α} [inst_1 : DecidableEq α] (a : α) (a_1 a_2 : List (Sigma β)),
  a_1 = a_2 → List.dlookup a a_1 = List.dlookup a a_2

theorem List.kextract.match_1.congr_eq_1 E1 #

∀ {α : Type u_2} {β : α → Type u_1} (a : α) (motive : Option (β a) × List (Sigma β) → Sort u_3)
  (x : Option (β a) × List (Sigma β)) (h_1 : (b' : Option (β a)) → (l' : List (Sigma β)) → motive (b', l'))
  (b' : Option (β a)) (l' : List (Sigma β)),
  x = (b', l') →
    (match x with
      | (b', l') => h_1 b' l') ≍
      h_1 b' l'

theorem List.kextract.match_3.congr_eq_2 E1 #

∀ {α : Type u_2} {β : α → Type u_1} (motive : List (Sigma β) → Sort u_3) (x : List (Sigma β)) (h_1 : Unit → motive [])
  (h_2 : (s : Sigma β) → (l : List (Sigma β)) → motive (s :: l)) (s : Sigma β) (l : List (Sigma β)),
  x = s :: l →
    (match x with
      | [] => h_1 ()
      | s :: l => h_2 s l) ≍
      h_2 s l

theorem List.kunion.match_1.congr_eq_2 E1 #

∀ {α : Type u_2} {β : α → Type u_1} (motive : List (Sigma β) → List (Sigma β) → Sort u_3) (x x_1 : List (Sigma β))
  (h_1 : (l₂ : List (Sigma β)) → motive [] l₂)
  (h_2 : (s : Sigma β) → (l₁ : List (Sigma β)) → (l₂ : List (Sigma β)) → motive (s :: l₁) l₂) (s : Sigma β)
  (l₁ : List (Sigma β)) (l₂ : List (Sigma β)),
  x = s :: l₁ →
    x_1 = l₂ →
      (match x, x_1 with
        | [], l₂ => h_1 l₂
        | s :: l₁, l₂ => h_2 s l₁ l₂) ≍
        h_2 s l₁ l₂

theorem List.kunion.match_1.congr_eq_1 E1 #

∀ {α : Type u_2} {β : α → Type u_1} (motive : List (Sigma β) → List (Sigma β) → Sort u_3) (x x_1 : List (Sigma β))
  (h_1 : (l₂ : List (Sigma β)) → motive [] l₂)
  (h_2 : (s : Sigma β) → (l₁ : List (Sigma β)) → (l₂ : List (Sigma β)) → motive (s :: l₁) l₂) (l₂ : List (Sigma β)),
  x = [] →
    x_1 = l₂ →
      (match x, x_1 with
        | [], l₂ => h_1 l₂
        | s :: l₁, l₂ => h_2 s l₁ l₂) ≍
        h_1 l₂

theorem List.lookupAll.congr_simp E1 #

∀ {α : Type u} {β : α → Type v} {inst : DecidableEq α} [inst_1 : DecidableEq α] (a : α) (a_1 a_2 : List (Sigma β)),
  a_1 = a_2 → List.lookupAll a a_1 = List.lookupAll a a_2

theorem List.kextract.match_3.congr_eq_1 E1 #

∀ {α : Type u_2} {β : α → Type u_1} (motive : List (Sigma β) → Sort u_3) (x : List (Sigma β)) (h_1 : Unit → motive [])
  (h_2 : (s : Sigma β) → (l : List (Sigma β)) → motive (s :: l)),
  x = [] →
    (match x with
      | [] => h_1 ()
      | s :: l => h_2 s l) ≍
      h_1 ()

def List.keys E3 #

{α : Type u} → {β : α → Type v} → List (Sigma β) → List α

List of keys from a list of key-value pairs

theorem List.keys_nil E0 #

∀ {α : Type u} {β : α → Type v}, [].keys = []

theorem List.keys_cons E0 #

∀ {α : Type u} {β : α → Type v} {s : Sigma β} {l : List (Sigma β)}, (s :: l).keys = s.fst :: l.keys

theorem List.keys_append E0 #

∀ {α : Type u} {β : α → Type v} {l₁ l₂ : List (Sigma β)}, (l₁ ++ l₂).keys = l₁.keys ++ l₂.keys

theorem List.mem_keys_of_mem E0 #

∀ {α : Type u} {β : α → Type v} {s : Sigma β} {l : List (Sigma β)}, s ∈ l → s.fst ∈ l.keys

theorem List.exists_of_mem_keys E1 #

∀ {α : Type u} {β : α → Type v} {a : α} {l : List (Sigma β)}, a ∈ l.keys → ∃ b, ⟨a, b⟩ ∈ l

theorem List.mem_keys E0 #

∀ {α : Type u} {β : α → Type v} {a : α} {l : List (Sigma β)}, a ∈ l.keys ↔ ∃ b, ⟨a, b⟩ ∈ l

theorem List.notMem_keys E1 #

∀ {α : Type u} {β : α → Type v} {a : α} {l : List (Sigma β)}, a ∉ l.keys ↔ ∀ (b : β a), ⟨a, b⟩ ∉ l

theorem List.ne_key E1 #

∀ {α : Type u} {β : α → Type v} {a : α} {l : List (Sigma β)}, a ∉ l.keys ↔ ∀ s ∈ l, a ≠ s.fst

def List.NodupKeys E3 #

{α : Type u} → {β : α → Type v} → List (Sigma β) → Prop

Determines whether the store uses a key several times.

theorem List.nodupKeys_iff_pairwise E1 #

∀ {α : Type u} {β : α → Type v} {l : List (Sigma β)}, l.NodupKeys ↔ List.Pairwise (fun s s' ↦ s.fst ≠ s'.fst) l

theorem List.NodupKeys.pairwise_ne E1 #

∀ {α : Type u} {β : α → Type v} {l : List (Sigma β)}, l.NodupKeys → List.Pairwise (fun s s' ↦ s.fst ≠ s'.fst) l

theorem List.nodupKeys_nil E0 #

∀ {α : Type u} {β : α → Type v}, [].NodupKeys

theorem List.nodupKeys_cons E0 #

∀ {α : Type u} {β : α → Type v} {s : Sigma β} {l : List (Sigma β)}, (s :: l).NodupKeys ↔ s.fst ∉ l.keys ∧ l.NodupKeys

theorem List.nodupKeys_middle E1 #

∀ {α : Type u} {β : α → Type v} {l₁ l₂ : List (Sigma β)} {s : Sigma β},
  (l₁ ++ s :: l₂).NodupKeys ↔ (s :: (l₁ ++ l₂)).NodupKeys

theorem List.notMem_keys_of_nodupKeys_cons E1 #

∀ {α : Type u} {β : α → Type v} {s : Sigma β} {l : List (Sigma β)}, (s :: l).NodupKeys → s.fst ∉ l.keys

theorem List.nodupKeys_of_nodupKeys_cons E1 #

∀ {α : Type u} {β : α → Type v} {s : Sigma β} {l : List (Sigma β)}, (s :: l).NodupKeys → l.NodupKeys

theorem List.nodupKeys_singleton E1 #

∀ {α : Type u} {β : α → Type v} (s : Sigma β), [s].NodupKeys

theorem List.NodupKeys.sublist E1 #

∀ {α : Type u} {β : α → Type v} {l₁ l₂ : List (Sigma β)}, l₁.Sublist l₂ → l₂.NodupKeys → l₁.NodupKeys

theorem List.NodupKeys.nodup E1 #

∀ {α : Type u} {β : α → Type v} {l : List (Sigma β)}, l.NodupKeys → l.Nodup

theorem List.perm_nodupKeys E1 #

∀ {α : Type u} {β : α → Type v} {l₁ l₂ : List (Sigma β)}, l₁.Perm l₂ → (l₁.NodupKeys ↔ l₂.NodupKeys)

theorem List.nodupKeys_flatten E1 #

∀ {α : Type u} {β : α → Type v} {L : List (List (Sigma β))},
  L.flatten.NodupKeys ↔ (∀ l ∈ L, l.NodupKeys) ∧ List.Pairwise List.Disjoint (List.map List.keys L)

theorem List.nodup_zipIdx_map_snd E1 #

∀ {α : Type u} (l : List α), (List.map Prod.snd l.zipIdx).Nodup

theorem List.mem_ext E0 #

∀ {α : Type u} {β : α → Type v} {l₀ l₁ : List (Sigma β)},
  l₀.Nodup → l₁.Nodup → (∀ (x : Sigma β), x ∈ l₀ ↔ x ∈ l₁) → l₀.Perm l₁

def List.dlookup E1 #

{α : Type u} → {β : α → Type v} → [DecidableEq α] → (a : α) → List (Sigma β) → Option (β a)

dlookup a l is the first value in l corresponding to the key a, or none if no such element exists.

theorem List.dlookup_nil E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α), List.dlookup a [] = none

theorem List.dlookup_cons_eq E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (l : List (Sigma β)) (a : α) (b : β a),
  List.dlookup a (⟨a, b⟩ :: l) = some b

theorem List.dlookup_cons_ne E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (l : List (Sigma β)) {a : α} (s : Sigma β),
  a ≠ s.fst → List.dlookup a (s :: l) = List.dlookup a l

theorem List.dlookup_isSome E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {l : List (Sigma β)},
  (List.dlookup a l).isSome = true ↔ a ∈ l.keys

theorem List.dlookup_eq_none E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {l : List (Sigma β)},
  List.dlookup a l = none ↔ a ∉ l.keys

theorem List.of_mem_dlookup E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {b : β a} {l : List (Sigma β)},
  b ∈ List.dlookup a l → ⟨a, b⟩ ∈ l

theorem List.mem_dlookup E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {b : β a} {l : List (Sigma β)},
  l.NodupKeys → ⟨a, b⟩ ∈ l → b ∈ List.dlookup a l

theorem List.map_dlookup_eq_find E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) (l : List (Sigma β)),
  Option.map (Sigma.mk a) (List.dlookup a l) = List.find? (fun s ↦ decide (a = s.fst)) l

theorem List.mem_dlookup_iff E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {b : β a} {l : List (Sigma β)},
  l.NodupKeys → (b ∈ List.dlookup a l ↔ ⟨a, b⟩ ∈ l)

theorem List.perm_dlookup E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) {l₁ l₂ : List (Sigma β)},
  l₁.NodupKeys → l₁.Perm l₂ → List.dlookup a l₁ = List.dlookup a l₂

theorem List.lookup_ext E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {l₀ l₁ : List (Sigma β)},
  l₀.NodupKeys → l₁.NodupKeys → (∀ (x : α) (y : β x), y ∈ List.dlookup x l₀ ↔ y ∈ List.dlookup x l₁) → l₀.Perm l₁

theorem List.dlookup_map E1 #

∀ {α : Type u} {α' : Type u'} {β : α → Type v} {β' : α' → Type v'} [inst : DecidableEq α] [inst_1 : DecidableEq α']
  (l : List (Sigma β)) {f : α → α'},
  Function.Injective f →
    ∀ (g : (a : α) → β a → β' (f a)) (a : α),
      List.dlookup (f a) (List.map (Sigma.map f g) l) = Option.map (g a) (List.dlookup a l)

theorem List.dlookup_map₁ E1 #

∀ {α : Type u} {α' : Type u'} [inst : DecidableEq α] [inst_1 : DecidableEq α'] {β : Type v} (l : List ((_ : α) × β))
  {f : α → α'},
  Function.Injective f → ∀ (a : α), List.dlookup (f a) (List.map (Sigma.map f fun x ↦ id) l) = List.dlookup a l

theorem List.dlookup_map₂ E1 #

∀ {α : Type u} [inst : DecidableEq α] {γ : α → Type u_1} {δ : α → Type u_2} {l : List ((a : α) × γ a)}
  {f : (a : α) → γ a → δ a} (a : α), List.dlookup a (List.map (Sigma.map id f) l) = Option.map (f a) (List.dlookup a l)

theorem List.NodupKeys.map₁ E1 #

∀ {α : Type u} {α' : Type u'} {β : Type v} (f : α → α'),
  Function.Injective f → ∀ {l : List ((_ : α) × β)}, l.NodupKeys → (List.map (Sigma.map f fun x ↦ id) l).NodupKeys

theorem List.map₂_keys E1 #

∀ {α : Type u} {β : α → Type u_1} {β' : α → Type u_2} (f : (a : α) → β a → β' a) (l : List ((a : α) × β a)),
  (List.map (Sigma.map id f) l).keys = l.keys

theorem List.NodupKeys.map₂ E1 #

∀ {α : Type u} {β : α → Type u_1} {β' : α → Type u_2} (f : (a : α) → β a → β' a) (l : List ((a : α) × β a)),
  l.NodupKeys → (List.map (Sigma.map id f) l).NodupKeys

theorem List.dlookup_append E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (l₁ l₂ : List (Sigma β)) (a : α),
  List.dlookup a (l₁ ++ l₂) = (List.dlookup a l₁).or (List.dlookup a l₂)

theorem List.sublist_dlookup E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {l₁ l₂ : List (Sigma β)} {a : α} {b : β a},
  l₂.NodupKeys → l₁.Sublist l₂ → b ∈ List.dlookup a l₁ → b ∈ List.dlookup a l₂

def List.lookupAll E1 #

{α : Type u} → {β : α → Type v} → [DecidableEq α] → (a : α) → List (Sigma β) → List (β a)

lookup_all a l is the list of all values in l corresponding to the key a.

theorem List.lookupAll_nil E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α), List.lookupAll a [] = []

theorem List.lookupAll_cons_eq E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (l : List (Sigma β)) (a : α) (b : β a),
  List.lookupAll a (⟨a, b⟩ :: l) = b :: List.lookupAll a l

theorem List.lookupAll_cons_ne E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (l : List (Sigma β)) {a : α} (s : Sigma β),
  a ≠ s.fst → List.lookupAll a (s :: l) = List.lookupAll a l

theorem List.lookupAll_eq_nil E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {l : List (Sigma β)},
  List.lookupAll a l = [] ↔ ∀ (b : β a), ⟨a, b⟩ ∉ l

theorem List.head?_lookupAll E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) (l : List (Sigma β)),
  (List.lookupAll a l).head? = List.dlookup a l

theorem List.mem_lookupAll E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {b : β a} {l : List (Sigma β)},
  b ∈ List.lookupAll a l ↔ ⟨a, b⟩ ∈ l

theorem List.lookupAll_sublist E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) (l : List (Sigma β)),
  (List.map (Sigma.mk a) (List.lookupAll a l)).Sublist l

theorem List.lookupAll_length_le_one E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) {l : List (Sigma β)},
  l.NodupKeys → (List.lookupAll a l).length ≤ 1

theorem List.lookupAll_eq_dlookup E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) {l : List (Sigma β)},
  l.NodupKeys → List.lookupAll a l = (List.dlookup a l).toList

theorem List.lookupAll_nodup E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) {l : List (Sigma β)},
  l.NodupKeys → (List.lookupAll a l).Nodup

theorem List.perm_lookupAll E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) {l₁ l₂ : List (Sigma β)},
  l₁.NodupKeys → l₁.Perm l₂ → List.lookupAll a l₁ = List.lookupAll a l₂

def List.kreplace E3 #

{α : Type u} → {β : α → Type v} → [DecidableEq α] → (a : α) → β a → List (Sigma β) → List (Sigma β)

Replaces the first value with key a by b.

theorem List.kreplace_of_forall_not E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) (b : β a) {l : List (Sigma β)},
  (∀ (b : β a), ⟨a, b⟩ ∉ l) → List.kreplace a b l = l

theorem List.kreplace_self E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {b : β a} {l : List (Sigma β)},
  l.NodupKeys → ⟨a, b⟩ ∈ l → List.kreplace a b l = l

theorem List.keys_kreplace E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) (b : β a) (l : List (Sigma β)),
  (List.kreplace a b l).keys = l.keys

theorem List.kreplace_nodupKeys E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) (b : β a) {l : List (Sigma β)},
  (List.kreplace a b l).NodupKeys ↔ l.NodupKeys

theorem List.Perm.kreplace E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {b : β a} {l₁ l₂ : List (Sigma β)},
  l₁.NodupKeys → l₁.Perm l₂ → (List.kreplace a b l₁).Perm (List.kreplace a b l₂)

def List.kerase E3 #

{α : Type u} → {β : α → Type v} → [DecidableEq α] → α → List (Sigma β) → List (Sigma β)

Remove the first pair with the key a.

theorem List.kerase_nil E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α}, List.kerase a [] = []

theorem List.kerase_cons_eq E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {s : Sigma β} {l : List (Sigma β)},
  a = s.fst → List.kerase a (s :: l) = l

theorem List.kerase_cons_ne E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {s : Sigma β} {l : List (Sigma β)},
  a ≠ s.fst → List.kerase a (s :: l) = s :: List.kerase a l

theorem List.kerase_of_notMem_keys E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {l : List (Sigma β)}, a ∉ l.keys → List.kerase a l = l

theorem List.kerase_sublist E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) (l : List (Sigma β)), (List.kerase a l).Sublist l

theorem List.kerase_keys_subset E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) (l : List (Sigma β)), (List.kerase a l).keys ⊆ l.keys

theorem List.mem_keys_of_mem_keys_kerase E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a₁ a₂ : α} {l : List (Sigma β)},
  a₁ ∈ (List.kerase a₂ l).keys → a₁ ∈ l.keys

theorem List.exists_of_kerase E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {l : List (Sigma β)},
  a ∈ l.keys → ∃ b l₁ l₂, a ∉ l₁.keys ∧ l = l₁ ++ ⟨a, b⟩ :: l₂ ∧ List.kerase a l = l₁ ++ l₂

theorem List.mem_keys_kerase_of_ne E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a₁ a₂ : α} {l : List (Sigma β)},
  a₁ ≠ a₂ → (a₁ ∈ (List.kerase a₂ l).keys ↔ a₁ ∈ l.keys)

theorem List.keys_kerase E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {l : List (Sigma β)},
  (List.kerase a l).keys = l.keys.erase a

theorem List.kerase_kerase E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a a' : α} {l : List (Sigma β)},
  List.kerase a (List.kerase a' l) = List.kerase a' (List.kerase a l)

theorem List.NodupKeys.kerase E1 #

∀ {α : Type u} {β : α → Type v} {l : List (Sigma β)} [inst : DecidableEq α] (a : α),
  l.NodupKeys → (List.kerase a l).NodupKeys

theorem List.Perm.kerase E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {l₁ l₂ : List (Sigma β)},
  l₁.NodupKeys → l₁.Perm l₂ → (List.kerase a l₁).Perm (List.kerase a l₂)

theorem List.notMem_keys_kerase E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) {l : List (Sigma β)},
  l.NodupKeys → a ∉ (List.kerase a l).keys

theorem List.dlookup_kerase E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) {l : List (Sigma β)},
  l.NodupKeys → List.dlookup a (List.kerase a l) = none

theorem List.dlookup_kerase_ne E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a a' : α} {l : List (Sigma β)},
  a ≠ a' → List.dlookup a (List.kerase a' l) = List.dlookup a l

theorem List.kerase_append_left E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {l₁ l₂ : List (Sigma β)},
  a ∈ l₁.keys → List.kerase a (l₁ ++ l₂) = List.kerase a l₁ ++ l₂

theorem List.kerase_append_right E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {l₁ l₂ : List (Sigma β)},
  a ∉ l₁.keys → List.kerase a (l₁ ++ l₂) = l₁ ++ List.kerase a l₂

theorem List.kerase_comm E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a₁ a₂ : α) (l : List (Sigma β)),
  List.kerase a₂ (List.kerase a₁ l) = List.kerase a₁ (List.kerase a₂ l)

theorem List.sizeOf_kerase E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] [inst_1 : SizeOf (Sigma β)] (x : α) (xs : List (Sigma β)),
  sizeOf (List.kerase x xs) ≤ sizeOf xs

def List.kinsert E3 #

{α : Type u} → {β : α → Type v} → [DecidableEq α] → (a : α) → β a → List (Sigma β) → List (Sigma β)

Insert the pair ⟨a, b⟩ and erase the first pair with the key a.

theorem List.kinsert_def E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {b : β a} {l : List (Sigma β)},
  List.kinsert a b l = ⟨a, b⟩ :: List.kerase a l

theorem List.mem_keys_kinsert E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a a' : α} {b' : β a'} {l : List (Sigma β)},
  a ∈ (List.kinsert a' b' l).keys ↔ a = a' ∨ a ∈ l.keys

theorem List.kinsert_nodupKeys E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) (b : β a) {l : List (Sigma β)},
  l.NodupKeys → (List.kinsert a b l).NodupKeys

theorem List.Perm.kinsert E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {b : β a} {l₁ l₂ : List (Sigma β)},
  l₁.NodupKeys → l₁.Perm l₂ → (List.kinsert a b l₁).Perm (List.kinsert a b l₂)

theorem List.dlookup_kinsert E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {b : β a} (l : List (Sigma β)),
  List.dlookup a (List.kinsert a b l) = some b

theorem List.dlookup_kinsert_ne E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a a' : α} {b' : β a'} {l : List (Sigma β)},
  a ≠ a' → List.dlookup a (List.kinsert a' b' l) = List.dlookup a l

def List.kextract E3 #

{α : Type u} → {β : α → Type v} → [DecidableEq α] → (a : α) → List (Sigma β) → Option (β a) × List (Sigma β)

Finds the first entry with a given key a and returns its value (as an Option because there might be no entry with key a) alongside with the rest of the entries.

theorem List.kextract_eq_dlookup_kerase E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) (l : List (Sigma β)),
  List.kextract a l = (List.dlookup a l, List.kerase a l)

def List.dedupKeys E1 #

{α : Type u} → {β : α → Type v} → [DecidableEq α] → List (Sigma β) → List (Sigma β)

Remove entries with duplicate keys from l : List (Sigma β).

theorem List.dedupKeys_cons E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {x : Sigma β} (l : List (Sigma β)),
  (x :: l).dedupKeys = List.kinsert x.fst x.snd l.dedupKeys

theorem List.nodupKeys_dedupKeys E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (l : List (Sigma β)), l.dedupKeys.NodupKeys

theorem List.dlookup_dedupKeys E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (a : α) (l : List (Sigma β)),
  List.dlookup a l.dedupKeys = List.dlookup a l

theorem List.sizeOf_cons_le_sizeOf_cons E1 #

∀ {α : Type u_1} [inst : SizeOf α] {l r : List α} (a : α), sizeOf l ≤ sizeOf r → sizeOf (a :: l) ≤ sizeOf (a :: r)

theorem List.sizeOf_dedupKeys E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] [inst_1 : SizeOf (Sigma β)] (xs : List (Sigma β)),
  sizeOf xs.dedupKeys ≤ sizeOf xs

def List.kunion E3 #

{α : Type u} → {β : α → Type v} → [DecidableEq α] → List (Sigma β) → List (Sigma β) → List (Sigma β)

kunion l₁ l₂ is the append to l₁ of l₂ after, for each key in l₁, the first matching pair in l₂ is erased.

theorem List.nil_kunion E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {l : List (Sigma β)}, [].kunion l = l

theorem List.kunion_nil E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {l : List (Sigma β)}, l.kunion [] = l

theorem List.kunion_cons E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {s : Sigma β} {l₁ l₂ : List (Sigma β)},
  (s :: l₁).kunion l₂ = s :: l₁.kunion (List.kerase s.fst l₂)

theorem List.mem_keys_kunion E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {l₁ l₂ : List (Sigma β)},
  a ∈ (l₁.kunion l₂).keys ↔ a ∈ l₁.keys ∨ a ∈ l₂.keys

theorem List.kunion_kerase E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {l₁ l₂ : List (Sigma β)},
  (List.kerase a l₁).kunion (List.kerase a l₂) = List.kerase a (l₁.kunion l₂)

theorem List.NodupKeys.kunion E1 #

∀ {α : Type u} {β : α → Type v} {l₁ l₂ : List (Sigma β)} [inst : DecidableEq α],
  l₁.NodupKeys → l₂.NodupKeys → (l₁.kunion l₂).NodupKeys

theorem List.Perm.kunion_right E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {l₁ l₂ : List (Sigma β)},
  l₁.Perm l₂ → ∀ (l : List (Sigma β)), (l₁.kunion l).Perm (l₂.kunion l)

theorem List.Perm.kunion_left E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] (l : List (Sigma β)) {l₁ l₂ : List (Sigma β)},
  l₁.NodupKeys → l₁.Perm l₂ → (l.kunion l₁).Perm (l.kunion l₂)

theorem List.Perm.kunion E1 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {l₁ l₂ l₃ l₄ : List (Sigma β)},
  l₃.NodupKeys → l₁.Perm l₂ → l₃.Perm l₄ → (l₁.kunion l₃).Perm (l₂.kunion l₄)

theorem List.dlookup_kunion_left E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {l₁ l₂ : List (Sigma β)},
  a ∈ l₁.keys → List.dlookup a (l₁.kunion l₂) = List.dlookup a l₁

theorem List.dlookup_kunion_right E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {l₁ l₂ : List (Sigma β)},
  a ∉ l₁.keys → List.dlookup a (l₁.kunion l₂) = List.dlookup a l₂

theorem List.mem_dlookup_kunion E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {b : β a} {l₁ l₂ : List (Sigma β)},
  b ∈ List.dlookup a (l₁.kunion l₂) ↔ b ∈ List.dlookup a l₁ ∨ a ∉ l₁.keys ∧ b ∈ List.dlookup a l₂

theorem List.dlookup_kunion_eq_some E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {b : β a} {l₁ l₂ : List (Sigma β)},
  List.dlookup a (l₁.kunion l₂) = some b ↔ List.dlookup a l₁ = some b ∨ a ∉ l₁.keys ∧ List.dlookup a l₂ = some b

theorem List.mem_dlookup_kunion_middle E0 #

∀ {α : Type u} {β : α → Type v} [inst : DecidableEq α] {a : α} {b : β a} {l₁ l₂ l₃ : List (Sigma β)},
  b ∈ List.dlookup a (l₁.kunion l₃) → a ∉ l₂.keys → b ∈ List.dlookup a ((l₁.kunion l₂).kunion l₃)