formal
stringlengths 41
427k
| informal
stringclasses 1
value |
---|---|
Option.guard_eq_some ** α✝ : Type u_1 p : α✝ → Prop a b : α✝ inst✝ : DecidablePred p ⊢ guard p a = some b ↔ a = b ∧ p a ** by_cases h : p a <;> simp [Option.guard, h] ** Qed | |
Option.liftOrGet_eq_or_eq ** α : Type u_1 f : α → α → α h : ∀ (a b : α), f a b = a ∨ f a b = b a b : α ⊢ liftOrGet f (some a) (some b) = some a ∨ liftOrGet f (some a) (some b) = some b ** have := h a b ** α : Type u_1 f : α → α → α h : ∀ (a b : α), f a b = a ∨ f a b = b a b : α this : f a b = a ∨ f a b = b ⊢ liftOrGet f (some a) (some b) = some a ∨ liftOrGet f (some a) (some b) = some b ** simp [liftOrGet] at this ⊢ ** α : Type u_1 f : α → α → α h : ∀ (a b : α), f a b = a ∨ f a b = b a b : α this : f a b = a ∨ f a b = b ⊢ f a b = a ∨ f a b = b ** exact this ** Qed | |
Option.liftOrGet_none_left ** α : Type u_1 f : α → α → α b : Option α ⊢ liftOrGet f none b = b ** cases b <;> rfl ** Qed | |
Option.liftOrGet_none_right ** α : Type u_1 f : α → α → α a : Option α ⊢ liftOrGet f a none = a ** cases a <;> rfl ** Qed | |
Option.getD_map ** α : Type u_1 β : Type u_2 f : α → β x : α o : Option α ⊢ getD (Option.map f o) (f x) = f (getD o x) ** cases o <;> rfl ** Qed | |
Option.choice_eq ** α : Type u_1 inst✝ : Subsingleton α a : α ⊢ choice α = some a ** simp [choice] ** α : Type u_1 inst✝ : Subsingleton α a : α ⊢ (if h : Nonempty α then some (Classical.choice h) else none) = some a ** rw [dif_pos (⟨a⟩ : Nonempty α)] ** α : Type u_1 inst✝ : Subsingleton α a : α ⊢ some (Classical.choice (_ : Nonempty α)) = some a ** simp ** α : Type u_1 inst✝ : Subsingleton α a : α ⊢ Classical.choice (_ : Nonempty α) = a ** apply Subsingleton.elim ** Qed | |
Option.choice_isSome_iff_nonempty ** α : Type u_1 h : Nonempty α ⊢ isSome (choice α) = true ** simp only [choice, dif_pos h, isSome_some] ** Qed | |
Std.HashMap.Imp.WF.empty ** α : Type u_1 β : Type u_2 n : Nat inst✝¹ : BEq α inst✝ : Hashable α ⊢ WF (Imp.empty n) ** unfold empty ** α : Type u_1 β : Type u_2 n : Nat inst✝¹ : BEq α inst✝ : Hashable α ⊢ WF (let nbuckets := numBucketsForCapacity n; let n_1 := if h : nbuckets = 0 then { val := 8, property := empty.proof_1 } else { val := nbuckets, property := (_ : 0 < nbuckets) }; Imp.empty' n_1.val) ** apply empty' ** Qed | |
Array.size_toArray ** α : Type u_1 as : List α ⊢ size (List.toArray as) = List.length as ** simp [size] ** Qed | |
Array.size_mk ** α : Type u_1 as : List α ⊢ size { data := as } = List.length as ** simp [size] ** Qed | |
Array.getElem_eq_data_get ** α : Type u_1 i : Nat a : Array α h : i < size a ⊢ a[i] = List.get a.data { val := i, isLt := h } ** by_cases i < a.size <;> (try simp [*]) <;> rfl ** Qed | |
Array.foldlM_eq_foldlM_data.aux ** m : Type u_1 → Type u_2 β : Type u_1 α : Type u_3 inst✝ : Monad m f : β → α → m β arr : Array α i j : Nat H : size arr ≤ i + j b : β ⊢ foldlM.loop f arr (size arr) (_ : size arr ≤ size arr) i j b = List.foldlM f b (List.drop j arr.data) ** unfold foldlM.loop ** m : Type u_1 → Type u_2 β : Type u_1 α : Type u_3 inst✝ : Monad m f : β → α → m β arr : Array α i j : Nat H : size arr ≤ i + j b : β ⊢ (if hlt : j < size arr then match i with | 0 => pure b | Nat.succ i' => let_fun this := (_ : j < size arr); do let __do_lift ← f b arr[j] foldlM.loop f arr (size arr) (_ : size arr ≤ size arr) i' (j + 1) __do_lift else pure b) = List.foldlM f b (List.drop j arr.data) ** split ** case inl m : Type u_1 → Type u_2 β : Type u_1 α : Type u_3 inst✝ : Monad m f : β → α → m β arr : Array α i j : Nat H : size arr ≤ i + j b : β h✝ : j < size arr ⊢ (match i with | 0 => pure b | Nat.succ i' => let_fun this := (_ : j < size arr); do let __do_lift ← f b arr[j] foldlM.loop f arr (size arr) (_ : size arr ≤ size arr) i' (j + 1) __do_lift) = List.foldlM f b (List.drop j arr.data) case inr m : Type u_1 → Type u_2 β : Type u_1 α : Type u_3 inst✝ : Monad m f : β → α → m β arr : Array α i j : Nat H : size arr ≤ i + j b : β h✝ : ¬j < size arr ⊢ pure b = List.foldlM f b (List.drop j arr.data) ** split ** case inl.h_1 m : Type u_1 → Type u_2 β : Type u_1 α : Type u_3 inst✝ : Monad m f : β → α → m β arr : Array α j : Nat b : β h✝ : j < size arr i✝ : Nat H : size arr ≤ 0 + j ⊢ pure b = List.foldlM f b (List.drop j arr.data) ** cases Nat.not_le_of_gt ‹_› (Nat.zero_add _ ▸ H) ** case inl.h_2 m : Type u_1 → Type u_2 β : Type u_1 α : Type u_3 inst✝ : Monad m f : β → α → m β arr : Array α j : Nat b : β h✝ : j < size arr i✝ i'✝ : Nat H : size arr ≤ Nat.succ i'✝ + j ⊢ (let_fun this := (_ : j < size arr); do let __do_lift ← f b arr[j] foldlM.loop f arr (size arr) (_ : size arr ≤ size arr) i'✝ (j + 1) __do_lift) = List.foldlM f b (List.drop j arr.data) ** rename_i i ** case inl.h_2 m : Type u_1 → Type u_2 β : Type u_1 α : Type u_3 inst✝ : Monad m f : β → α → m β arr : Array α j : Nat b : β h✝ : j < size arr i✝ i : Nat H : size arr ≤ Nat.succ i + j ⊢ (let_fun this := (_ : j < size arr); do let __do_lift ← f b arr[j] foldlM.loop f arr (size arr) (_ : size arr ≤ size arr) i (j + 1) __do_lift) = List.foldlM f b (List.drop j arr.data) ** rw [Nat.succ_add] at H ** case inl.h_2 m : Type u_1 → Type u_2 β : Type u_1 α : Type u_3 inst✝ : Monad m f : β → α → m β arr : Array α j : Nat b : β h✝ : j < size arr i✝ i : Nat H : size arr ≤ Nat.succ (i + j) ⊢ (let_fun this := (_ : j < size arr); do let __do_lift ← f b arr[j] foldlM.loop f arr (size arr) (_ : size arr ≤ size arr) i (j + 1) __do_lift) = List.foldlM f b (List.drop j arr.data) ** simp [foldlM_eq_foldlM_data.aux f arr i (j+1) H] ** case inl.h_2 m : Type u_1 → Type u_2 β : Type u_1 α : Type u_3 inst✝ : Monad m f : β → α → m β arr : Array α j : Nat b : β h✝ : j < size arr i✝ i : Nat H : size arr ≤ Nat.succ (i + j) ⊢ (do let __do_lift ← f b arr[j] List.foldlM f __do_lift (List.drop (j + 1) arr.data)) = List.foldlM f b (List.drop j arr.data) ** conv => rhs; rw [← List.get_drop_eq_drop _ _ ‹_›] ** case inr m : Type u_1 → Type u_2 β : Type u_1 α : Type u_3 inst✝ : Monad m f : β → α → m β arr : Array α i j : Nat H : size arr ≤ i + j b : β h✝ : ¬j < size arr ⊢ pure b = List.foldlM f b (List.drop j arr.data) ** rw [List.drop_length_le (Nat.ge_of_not_lt ‹_›)] ** case inr m : Type u_1 → Type u_2 β : Type u_1 α : Type u_3 inst✝ : Monad m f : β → α → m β arr : Array α i j : Nat H : size arr ≤ i + j b : β h✝ : ¬j < size arr ⊢ pure b = List.foldlM f b [] ** rfl ** Qed | |
Array.foldrM_eq_foldrM_data ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝ : Monad m f : α → β → m β init : β arr : Array α ⊢ foldrM f init arr (size arr) = List.foldrM f init arr.data ** rw [foldrM_eq_reverse_foldlM_data, List.foldlM_reverse] ** Qed | |
Array.push_data ** α : Type u_1 arr : Array α a : α ⊢ (push arr a).data = arr.data ++ [a] ** simp [push, List.concat_eq_append] ** Qed | |
Array.foldrM_push ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝ : Monad m f : α → β → m β init : β arr : Array α a : α ⊢ foldrM f init (push arr a) (size (push arr a)) = do let init ← f a init foldrM f init arr (size arr) ** simp [foldrM_eq_reverse_foldlM_data, -size_push] ** Qed | |
Array.foldrM_push' ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝ : Monad m f : α → β → m β init : β arr : Array α a : α ⊢ foldrM f init (push arr a) (size arr + 1) = do let init ← f a init foldrM f init arr (size arr) ** simp [← foldrM_push] ** Qed | |
Array.toList_eq ** α : Type u_1 arr : Array α ⊢ toList arr = arr.data ** simp [toList, foldr_eq_foldr_data] ** Qed | |
Array.SatisfiesM_foldlM ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → m β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → SatisfiesM (motive (i.val + 1)) (f b as[i]) ⊢ SatisfiesM (motive (size as)) (foldlM f init as 0 (size as)) ** simp [foldlM] ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → m β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → SatisfiesM (motive (i.val + 1)) (f b as[i]) ⊢ SatisfiesM (motive (size as)) (foldlM.loop f as (size as) (_ : size as ≤ size as) (size as) 0 init) ** exact go (Nat.zero_le _) (Nat.le_refl _) h0 ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → m β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → SatisfiesM (motive (i.val + 1)) (f b as[i]) i j : Nat b : β h₁ : j ≤ size as h₂ : size as ≤ i + j H : motive j b ⊢ SatisfiesM (motive (size as)) (foldlM.loop f as (size as) (_ : size as ≤ size as) i j b) ** unfold foldlM.loop ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → m β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → SatisfiesM (motive (i.val + 1)) (f b as[i]) i j : Nat b : β h₁ : j ≤ size as h₂ : size as ≤ i + j H : motive j b ⊢ SatisfiesM (motive (size as)) (if hlt : j < size as then match i with | 0 => pure b | Nat.succ i' => let_fun this := (_ : j < size as); do let __do_lift ← f b as[j] foldlM.loop f as (size as) (_ : size as ≤ size as) i' (j + 1) __do_lift else pure b) ** split ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → m β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → SatisfiesM (motive (i.val + 1)) (f b as[i]) i j : Nat b : β h₁ : j ≤ size as h₂ : size as ≤ i + j H : motive j b hj : j < size as ⊢ SatisfiesM (motive (size as)) (match i with | 0 => pure b | Nat.succ i' => let_fun this := (_ : j < size as); do let __do_lift ← f b as[j] foldlM.loop f as (size as) (_ : size as ≤ size as) i' (j + 1) __do_lift) ** split ** case h_1 m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → m β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → SatisfiesM (motive (i.val + 1)) (f b as[i]) j : Nat b : β h₁ : j ≤ size as H : motive j b hj : j < size as i✝ : Nat h₂ : size as ≤ 0 + j ⊢ SatisfiesM (motive (size as)) (pure b) ** cases Nat.not_le_of_gt (by simp [hj]) h₂ ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → m β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → SatisfiesM (motive (i.val + 1)) (f b as[i]) j : Nat b : β h₁ : j ≤ size as H : motive j b hj : j < size as i✝ : Nat h₂ : size as ≤ 0 + j ⊢ size as > 0 + j ** simp [hj] ** case h_2 m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → m β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → SatisfiesM (motive (i.val + 1)) (f b as[i]) j : Nat b : β h₁ : j ≤ size as H : motive j b hj : j < size as i✝ i'✝ : Nat h₂ : size as ≤ Nat.succ i'✝ + j ⊢ SatisfiesM (motive (size as)) (let_fun this := (_ : j < size as); do let __do_lift ← f b as[j] foldlM.loop f as (size as) (_ : size as ≤ size as) i'✝ (j + 1) __do_lift) ** exact (hf ⟨j, hj⟩ b H).bind fun _ => go hj (by rwa [Nat.succ_add] at h₂) ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → m β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → SatisfiesM (motive (i.val + 1)) (f b as[i]) j : Nat b : β h₁ : j ≤ size as H : motive j b hj : j < size as i✝ i'✝ : Nat h₂ : size as ≤ Nat.succ i'✝ + j x✝ : β ⊢ size as ≤ i'✝ + ({ val := j, isLt := hj }.val + 1) ** rwa [Nat.succ_add] at h₂ ** case inr m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → m β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → SatisfiesM (motive (i.val + 1)) (f b as[i]) i j : Nat b : β h₁ : j ≤ size as h₂ : size as ≤ i + j H : motive j b h✝ : ¬j < size as ⊢ SatisfiesM (motive (size as)) (pure b) ** next hj => exact Nat.le_antisymm h₁ (Nat.ge_of_not_lt hj) ▸ .pure H ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → m β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → SatisfiesM (motive (i.val + 1)) (f b as[i]) i j : Nat b : β h₁ : j ≤ size as h₂ : size as ≤ i + j H : motive j b hj : ¬j < size as ⊢ SatisfiesM (motive (size as)) (pure b) ** exact Nat.le_antisymm h₁ (Nat.ge_of_not_lt hj) ▸ .pure H ** Qed | |
Array.foldl_induction ** α : Type u_1 β : Type u_2 as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → motive (i.val + 1) (f b as[i]) ⊢ motive (size as) (foldl f init as 0 (size as)) ** have := SatisfiesM_foldlM (m := Id) (as := as) (f := f) motive h0 ** α : Type u_1 β : Type u_2 as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → motive (i.val + 1) (f b as[i]) this : (∀ (i : Fin (size as)) (b : β), motive i.val b → SatisfiesM (motive (i.val + 1)) (f b as[i])) → SatisfiesM (motive (size as)) (foldlM f init as 0 (size as)) ⊢ motive (size as) (foldl f init as 0 (size as)) ** simp [SatisfiesM_Id_eq] at this ** α : Type u_1 β : Type u_2 as : Array α motive : Nat → β → Prop init : β h0 : motive 0 init f : β → α → β hf : ∀ (i : Fin (size as)) (b : β), motive i.val b → motive (i.val + 1) (f b as[i]) this : (∀ (i : Fin (size as)) (b : β), motive i.val b → motive (i.val + 1) (f b as[i])) → motive (size as) (foldlM f init as 0 (size as)) ⊢ motive (size as) (foldl f init as 0 (size as)) ** exact this hf ** Qed | |
Array.get_push_eq ** α : Type u_1 a : Array α x : α ⊢ (push a x)[size a] = x ** simp only [push, getElem_eq_data_get, List.concat_eq_append] ** α : Type u_1 a : Array α x : α ⊢ List.get (a.data ++ [x]) { val := size a, isLt := (_ : (fun xs i => i < size xs) { data := a.data ++ [x] } (size a)) } = x ** rw [List.get_append_right] <;> simp [getElem_eq_data_get] ** Qed | |
Array.get_push ** α : Type u_1 a : Array α x : α i : Nat h : i < size (push a x) ⊢ (push a x)[i] = if h : i < size a then a[i] else x ** if h' : i < a.size then
simp [get_push_lt, h']
else
simp at h
simp [get_push_lt, Nat.le_antisymm (Nat.le_of_lt_succ h) (Nat.ge_of_not_lt h')] ** α : Type u_1 a : Array α x : α i : Nat h : i < size (push a x) h' : i < size a ⊢ (push a x)[i] = if h : i < size a then a[i] else x ** simp [get_push_lt, h'] ** α : Type u_1 a : Array α x : α i : Nat h : i < size (push a x) h' : ¬i < size a ⊢ (push a x)[i] = if h : i < size a then a[i] else x ** simp at h ** α : Type u_1 a : Array α x : α i : Nat h✝ : i < size (push a x) h' : ¬i < size a h : i < size a + 1 ⊢ (push a x)[i] = if h : i < size a then a[i] else x ** simp [get_push_lt, Nat.le_antisymm (Nat.le_of_lt_succ h) (Nat.ge_of_not_lt h')] ** Qed | |
Array.mapM_eq_foldlM ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m f : α → m β arr : Array α ⊢ mapM f arr = foldlM (fun bs a => push bs <$> f a) #[] arr 0 (size arr) ** rw [mapM, aux, foldlM_eq_foldlM_data] ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m f : α → m β arr : Array α ⊢ List.foldlM (fun bs a => push bs <$> f a) (mkEmpty (size arr)) (List.drop 0 arr.data) = List.foldlM (fun bs a => push bs <$> f a) #[] arr.data ** rfl ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m f : α → m β arr : Array α i : Nat r : Array β ⊢ mapM.map f arr i r = List.foldlM (fun bs a => push bs <$> f a) r (List.drop i arr.data) ** unfold mapM.map ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m f : α → m β arr : Array α i : Nat r : Array β ⊢ (if hlt : i < size arr then do let __do_lift ← f arr[i] mapM.map f arr (i + 1) (push r __do_lift) else pure r) = List.foldlM (fun bs a => push bs <$> f a) r (List.drop i arr.data) ** split ** case inl m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m f : α → m β arr : Array α i : Nat r : Array β h✝ : i < size arr ⊢ (do let __do_lift ← f arr[i] mapM.map f arr (i + 1) (push r __do_lift)) = List.foldlM (fun bs a => push bs <$> f a) r (List.drop i arr.data) ** rw [← List.get_drop_eq_drop _ i ‹_›] ** case inl m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m f : α → m β arr : Array α i : Nat r : Array β h✝ : i < size arr ⊢ (do let __do_lift ← f arr[i] mapM.map f arr (i + 1) (push r __do_lift)) = List.foldlM (fun bs a => push bs <$> f a) r (arr.data[i] :: List.drop (i + 1) arr.data) ** simp [aux (i+1), map_eq_pure_bind] ** case inl m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m f : α → m β arr : Array α i : Nat r : Array β h✝ : i < size arr ⊢ (do let __do_lift ← f arr[i] List.foldlM (fun bs a => do let a ← f a pure (push bs a)) (push r __do_lift) (List.drop (i + 1) arr.data)) = do let __do_lift ← f arr.data[i] List.foldlM (fun bs a => do let a ← f a pure (push bs a)) (push r __do_lift) (List.drop (i + 1) arr.data) ** rfl ** case inr m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m f : α → m β arr : Array α i : Nat r : Array β h✝ : ¬i < size arr ⊢ pure r = List.foldlM (fun bs a => push bs <$> f a) r (List.drop i arr.data) ** rw [List.drop_length_le (Nat.ge_of_not_lt ‹_›)] ** case inr m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m f : α → m β arr : Array α i : Nat r : Array β h✝ : ¬i < size arr ⊢ pure r = List.foldlM (fun bs a => push bs <$> f a) r [] ** rfl ** Qed | |
Array.size_map ** α : Type u_1 β : Type u_2 f : α → β arr : Array α ⊢ size (map f arr) = size arr ** simp [size] ** Qed | |
Array.getElem_map ** α : Type u_1 β : Type u_2 f : α → β arr : Array α i : Nat h : i < size (map f arr) ⊢ (map f arr)[i] = f arr[i] ** have := SatisfiesM_mapM' (m := Id) arr f (fun i b => b = f (arr[i])) ** α : Type u_1 β : Type u_2 f : α → β arr : Array α i : Nat h : i < size (map f arr) this : (∀ (i : Fin (size arr)), SatisfiesM (fun b => b = f arr[i]) (f arr[i])) → SatisfiesM (fun arr_1 => ∃ eq, ∀ (i : Nat) (h : i < size arr), arr_1[i] = f arr[{ val := i, isLt := h }]) (mapM f arr) ⊢ (map f arr)[i] = f arr[i] ** simp [SatisfiesM_Id_eq] at this ** α : Type u_1 β : Type u_2 f : α → β arr : Array α i : Nat h : i < size (map f arr) this : ∃ eq, ∀ (i : Nat) (h : i < size arr), (mapM f arr)[i] = f arr[{ val := i, isLt := h }] ⊢ (map f arr)[i] = f arr[i] ** exact this.2 i (size_map .. ▸ h) ** Qed | |
Array.foldl_data_eq_bind ** α : Type u_1 β : Type u_2 l : List α acc : Array β F : Array β → α → Array β G : α → List β H : ∀ (acc : Array β) (a : α), (F acc a).data = acc.data ++ G a ⊢ (List.foldl F acc l).data = acc.data ++ List.bind l G ** induction l generalizing acc <;> simp [*, List.bind] ** Qed | |
Array.foldl_data_eq_map ** α : Type u_1 β : Type u_2 l : List α acc : Array β G : α → β ⊢ (List.foldl (fun acc a => push acc (G a)) acc l).data = acc.data ++ List.map G l ** induction l generalizing acc <;> simp [*] ** Qed | |
List.countP_go_eq_add ** α : Type u_1 p q : α → Bool n : Nat l : List α ⊢ countP.go p l n = n + countP.go p l 0 ** induction l generalizing n with
| nil => rfl
| cons head tail ih =>
unfold countP.go
rw [ih (n := n + 1), ih (n := n), ih (n := 1)]
if h : p head then simp [h, Nat.add_assoc] else simp [h] ** case nil α : Type u_1 p q : α → Bool n : Nat ⊢ countP.go p [] n = n + countP.go p [] 0 ** rfl ** case cons α : Type u_1 p q : α → Bool head : α tail : List α ih : ∀ {n : Nat}, countP.go p tail n = n + countP.go p tail 0 n : Nat ⊢ countP.go p (head :: tail) n = n + countP.go p (head :: tail) 0 ** unfold countP.go ** case cons α : Type u_1 p q : α → Bool head : α tail : List α ih : ∀ {n : Nat}, countP.go p tail n = n + countP.go p tail 0 n : Nat ⊢ (bif p head then countP.go p tail (n + 1) else countP.go p tail n) = n + bif p head then countP.go p tail (0 + 1) else countP.go p tail 0 ** rw [ih (n := n + 1), ih (n := n), ih (n := 1)] ** case cons α : Type u_1 p q : α → Bool head : α tail : List α ih : ∀ {n : Nat}, countP.go p tail n = n + countP.go p tail 0 n : Nat ⊢ (bif p head then n + 1 + countP.go p tail 0 else n + countP.go p tail 0) = n + bif p head then 1 + countP.go p tail 0 else countP.go p tail 0 ** if h : p head then simp [h, Nat.add_assoc] else simp [h] ** α : Type u_1 p q : α → Bool head : α tail : List α ih : ∀ {n : Nat}, countP.go p tail n = n + countP.go p tail 0 n : Nat h : p head = true ⊢ (bif p head then n + 1 + countP.go p tail 0 else n + countP.go p tail 0) = n + bif p head then 1 + countP.go p tail 0 else countP.go p tail 0 ** simp [h, Nat.add_assoc] ** α : Type u_1 p q : α → Bool head : α tail : List α ih : ∀ {n : Nat}, countP.go p tail n = n + countP.go p tail 0 n : Nat h : ¬p head = true ⊢ (bif p head then n + 1 + countP.go p tail 0 else n + countP.go p tail 0) = n + bif p head then 1 + countP.go p tail 0 else countP.go p tail 0 ** simp [h] ** Qed | |
List.countP_cons_of_neg ** α : Type u_1 p q : α → Bool a : α l : List α pa : ¬p a = true ⊢ countP p (a :: l) = countP p l ** simp [countP, countP.go, pa] ** Qed | |
List.countP_cons ** α : Type u_1 p q : α → Bool a : α l : List α ⊢ countP p (a :: l) = countP p l + if p a = true then 1 else 0 ** by_cases h : p a <;> simp [h] ** Qed | |
List.length_eq_countP_add_countP ** case nil α : Type u_1 p q : α → Bool ⊢ length [] = countP p [] + countP (fun a => decide ¬p a = true) [] ** rfl ** α : Type u_1 p q : α → Bool x : α h✝ : List α ih : length h✝ = countP p h✝ + countP (fun a => decide ¬p a = true) h✝ h : p x = true ⊢ length (x :: h✝) = countP p (x :: h✝) + countP (fun a => decide ¬p a = true) (x :: h✝) ** rw [countP_cons_of_pos _ _ h, countP_cons_of_neg _ _ _, length, ih] ** α : Type u_1 p q : α → Bool x : α h✝ : List α ih : length h✝ = countP p h✝ + countP (fun a => decide ¬p a = true) h✝ h : p x = true ⊢ countP p h✝ + countP (fun a => decide ¬p a = true) h✝ + 1 = countP p h✝ + 1 + countP (fun a => decide ¬p a = true) h✝ ** rw [Nat.add_assoc, Nat.add_comm _ 1, Nat.add_assoc] ** α : Type u_1 p q : α → Bool x : α h✝ : List α ih : length h✝ = countP p h✝ + countP (fun a => decide ¬p a = true) h✝ h : p x = true ⊢ ¬(decide ¬p x = true) = true ** simp only [h] ** α : Type u_1 p q : α → Bool x : α h✝ : List α ih : length h✝ = countP p h✝ + countP (fun a => decide ¬p a = true) h✝ h : ¬p x = true ⊢ length (x :: h✝) = countP p (x :: h✝) + countP (fun a => decide ¬p a = true) (x :: h✝) ** rw [countP_cons_of_pos (fun a => ¬p a) _ _, countP_cons_of_neg _ _ h, length, ih] ** α : Type u_1 p q : α → Bool x : α h✝ : List α ih : length h✝ = countP p h✝ + countP (fun a => decide ¬p a = true) h✝ h : ¬p x = true ⊢ countP p h✝ + countP (fun a => decide ¬p a = true) h✝ + 1 = countP p h✝ + (countP (fun a => decide ¬p a = true) h✝ + 1) ** rfl ** α : Type u_1 p q : α → Bool x : α h✝ : List α ih : length h✝ = countP p h✝ + countP (fun a => decide ¬p a = true) h✝ h : ¬p x = true ⊢ (fun a => decide ¬p a = true) x = true ** simp only [h] ** Qed | |
List.countP_eq_length_filter ** α : Type u_1 p q : α → Bool l : List α ⊢ countP p l = length (filter p l) ** induction l with
| nil => rfl
| cons x l ih =>
if h : p x
then rw [countP_cons_of_pos p l h, ih, filter_cons_of_pos l h, length]
else rw [countP_cons_of_neg p l h, ih, filter_cons_of_neg l h] ** case nil α : Type u_1 p q : α → Bool ⊢ countP p [] = length (filter p []) ** rfl ** case cons α : Type u_1 p q : α → Bool x : α l : List α ih : countP p l = length (filter p l) ⊢ countP p (x :: l) = length (filter p (x :: l)) ** if h : p x
then rw [countP_cons_of_pos p l h, ih, filter_cons_of_pos l h, length]
else rw [countP_cons_of_neg p l h, ih, filter_cons_of_neg l h] ** α : Type u_1 p q : α → Bool x : α l : List α ih : countP p l = length (filter p l) h : p x = true ⊢ countP p (x :: l) = length (filter p (x :: l)) ** rw [countP_cons_of_pos p l h, ih, filter_cons_of_pos l h, length] ** α : Type u_1 p q : α → Bool x : α l : List α ih : countP p l = length (filter p l) h : ¬p x = true ⊢ countP p (x :: l) = length (filter p (x :: l)) ** rw [countP_cons_of_neg p l h, ih, filter_cons_of_neg l h] ** Qed | |
List.countP_le_length ** α : Type u_1 p q : α → Bool l : List α ⊢ countP p l ≤ length l ** simp only [countP_eq_length_filter] ** α : Type u_1 p q : α → Bool l : List α ⊢ length (filter p l) ≤ length l ** apply length_filter_le ** Qed | |
List.countP_append ** α : Type u_1 p q : α → Bool l₁ l₂ : List α ⊢ countP p (l₁ ++ l₂) = countP p l₁ + countP p l₂ ** simp only [countP_eq_length_filter, filter_append, length_append] ** Qed | |
List.countP_pos ** α : Type u_1 p q : α → Bool l : List α ⊢ 0 < countP p l ↔ ∃ a, a ∈ l ∧ p a = true ** simp only [countP_eq_length_filter, length_pos_iff_exists_mem, mem_filter, exists_prop] ** Qed | |
List.countP_eq_zero ** α : Type u_1 p q : α → Bool l : List α ⊢ countP p l = 0 ↔ ∀ (a : α), a ∈ l → ¬p a = true ** simp only [countP_eq_length_filter, length_eq_zero, filter_eq_nil] ** Qed | |
List.Sublist.countP_le ** α : Type u_1 p q : α → Bool l₁ l₂ : List α s : l₁ <+ l₂ ⊢ countP p l₁ ≤ countP p l₂ ** simp only [countP_eq_length_filter] ** α : Type u_1 p q : α → Bool l₁ l₂ : List α s : l₁ <+ l₂ ⊢ length (List.filter p l₁) ≤ length (List.filter p l₂) ** apply s.filter _ |>.length_le ** Qed | |
List.countP_filter ** α : Type u_1 p q : α → Bool l : List α ⊢ countP p (filter q l) = countP (fun a => decide (p a = true ∧ q a = true)) l ** simp only [countP_eq_length_filter, filter_filter] ** Qed | |
List.countP_true ** α : Type u_1 p q : α → Bool l : List α ⊢ countP (fun x => true) l = length l ** rw [countP_eq_length] ** α : Type u_1 p q : α → Bool l : List α ⊢ ∀ (a : α), a ∈ l → true = true ** simp ** Qed | |
List.countP_false ** α : Type u_1 p q : α → Bool l : List α ⊢ countP (fun x => false) l = 0 ** rw [countP_eq_zero] ** α : Type u_1 p q : α → Bool l : List α ⊢ ∀ (a : α), a ∈ l → ¬false = true ** simp ** Qed | |
List.countP_map ** α : Type u_2 p✝ q : α → Bool β : Type u_1 p : β → Bool f : α → β a : α l : List α ⊢ countP p (map f (a :: l)) = countP (p ∘ f) (a :: l) ** rw [map_cons, countP_cons, countP_cons, countP_map p f l] ** α : Type u_2 p✝ q : α → Bool β : Type u_1 p : β → Bool f : α → β a : α l : List α ⊢ (countP (p ∘ f) l + if p (f a) = true then 1 else 0) = countP (p ∘ f) l + if (p ∘ f) a = true then 1 else 0 ** rfl ** Qed | |
List.countP_mono_left ** α : Type u_1 p q : α → Bool l : List α h : ∀ (x : α), x ∈ l → p x = true → q x = true ⊢ countP p l ≤ countP q l ** induction l with
| nil => apply Nat.le_refl
| cons a l ihl =>
rw [forall_mem_cons] at h
have ⟨ha, hl⟩ := h
simp [countP_cons]
cases h : p a
. simp
apply Nat.le_trans ?_ (Nat.le_add_right _ _)
apply ihl hl
. simp [ha h, Nat.add_one]
apply Nat.succ_le_succ
apply ihl hl ** case nil α : Type u_1 p q : α → Bool h : ∀ (x : α), x ∈ [] → p x = true → q x = true ⊢ countP p [] ≤ countP q [] ** apply Nat.le_refl ** case cons α : Type u_1 p q : α → Bool a : α l : List α ihl : (∀ (x : α), x ∈ l → p x = true → q x = true) → countP p l ≤ countP q l h : ∀ (x : α), x ∈ a :: l → p x = true → q x = true ⊢ countP p (a :: l) ≤ countP q (a :: l) ** rw [forall_mem_cons] at h ** case cons α : Type u_1 p q : α → Bool a : α l : List α ihl : (∀ (x : α), x ∈ l → p x = true → q x = true) → countP p l ≤ countP q l h : (p a = true → q a = true) ∧ ∀ (x : α), x ∈ l → p x = true → q x = true ⊢ countP p (a :: l) ≤ countP q (a :: l) ** have ⟨ha, hl⟩ := h ** case cons α : Type u_1 p q : α → Bool a : α l : List α ihl : (∀ (x : α), x ∈ l → p x = true → q x = true) → countP p l ≤ countP q l h : (p a = true → q a = true) ∧ ∀ (x : α), x ∈ l → p x = true → q x = true ha : p a = true → q a = true hl : ∀ (x : α), x ∈ l → p x = true → q x = true ⊢ countP p (a :: l) ≤ countP q (a :: l) ** simp [countP_cons] ** case cons α : Type u_1 p q : α → Bool a : α l : List α ihl : (∀ (x : α), x ∈ l → p x = true → q x = true) → countP p l ≤ countP q l h : (p a = true → q a = true) ∧ ∀ (x : α), x ∈ l → p x = true → q x = true ha : p a = true → q a = true hl : ∀ (x : α), x ∈ l → p x = true → q x = true ⊢ (countP p l + if p a = true then 1 else 0) ≤ countP q l + if q a = true then 1 else 0 ** cases h : p a ** case cons.false α : Type u_1 p q : α → Bool a : α l : List α ihl : (∀ (x : α), x ∈ l → p x = true → q x = true) → countP p l ≤ countP q l h✝ : (p a = true → q a = true) ∧ ∀ (x : α), x ∈ l → p x = true → q x = true ha : p a = true → q a = true hl : ∀ (x : α), x ∈ l → p x = true → q x = true h : p a = false ⊢ (countP p l + if false = true then 1 else 0) ≤ countP q l + if q a = true then 1 else 0 case cons.true α : Type u_1 p q : α → Bool a : α l : List α ihl : (∀ (x : α), x ∈ l → p x = true → q x = true) → countP p l ≤ countP q l h✝ : (p a = true → q a = true) ∧ ∀ (x : α), x ∈ l → p x = true → q x = true ha : p a = true → q a = true hl : ∀ (x : α), x ∈ l → p x = true → q x = true h : p a = true ⊢ (countP p l + if true = true then 1 else 0) ≤ countP q l + if q a = true then 1 else 0 ** . simp
apply Nat.le_trans ?_ (Nat.le_add_right _ _)
apply ihl hl ** case cons.true α : Type u_1 p q : α → Bool a : α l : List α ihl : (∀ (x : α), x ∈ l → p x = true → q x = true) → countP p l ≤ countP q l h✝ : (p a = true → q a = true) ∧ ∀ (x : α), x ∈ l → p x = true → q x = true ha : p a = true → q a = true hl : ∀ (x : α), x ∈ l → p x = true → q x = true h : p a = true ⊢ (countP p l + if true = true then 1 else 0) ≤ countP q l + if q a = true then 1 else 0 ** . simp [ha h, Nat.add_one]
apply Nat.succ_le_succ
apply ihl hl ** case cons.false α : Type u_1 p q : α → Bool a : α l : List α ihl : (∀ (x : α), x ∈ l → p x = true → q x = true) → countP p l ≤ countP q l h✝ : (p a = true → q a = true) ∧ ∀ (x : α), x ∈ l → p x = true → q x = true ha : p a = true → q a = true hl : ∀ (x : α), x ∈ l → p x = true → q x = true h : p a = false ⊢ (countP p l + if false = true then 1 else 0) ≤ countP q l + if q a = true then 1 else 0 ** simp ** case cons.false α : Type u_1 p q : α → Bool a : α l : List α ihl : (∀ (x : α), x ∈ l → p x = true → q x = true) → countP p l ≤ countP q l h✝ : (p a = true → q a = true) ∧ ∀ (x : α), x ∈ l → p x = true → q x = true ha : p a = true → q a = true hl : ∀ (x : α), x ∈ l → p x = true → q x = true h : p a = false ⊢ countP p l ≤ countP q l + if q a = true then 1 else 0 ** apply Nat.le_trans ?_ (Nat.le_add_right _ _) ** α : Type u_1 p q : α → Bool a : α l : List α ihl : (∀ (x : α), x ∈ l → p x = true → q x = true) → countP p l ≤ countP q l h✝ : (p a = true → q a = true) ∧ ∀ (x : α), x ∈ l → p x = true → q x = true ha : p a = true → q a = true hl : ∀ (x : α), x ∈ l → p x = true → q x = true h : p a = false ⊢ countP p l ≤ countP q l ** apply ihl hl ** case cons.true α : Type u_1 p q : α → Bool a : α l : List α ihl : (∀ (x : α), x ∈ l → p x = true → q x = true) → countP p l ≤ countP q l h✝ : (p a = true → q a = true) ∧ ∀ (x : α), x ∈ l → p x = true → q x = true ha : p a = true → q a = true hl : ∀ (x : α), x ∈ l → p x = true → q x = true h : p a = true ⊢ (countP p l + if true = true then 1 else 0) ≤ countP q l + if q a = true then 1 else 0 ** simp [ha h, Nat.add_one] ** case cons.true α : Type u_1 p q : α → Bool a : α l : List α ihl : (∀ (x : α), x ∈ l → p x = true → q x = true) → countP p l ≤ countP q l h✝ : (p a = true → q a = true) ∧ ∀ (x : α), x ∈ l → p x = true → q x = true ha : p a = true → q a = true hl : ∀ (x : α), x ∈ l → p x = true → q x = true h : p a = true ⊢ succ (countP p l) ≤ succ (countP q l) ** apply Nat.succ_le_succ ** case cons.true.a α : Type u_1 p q : α → Bool a : α l : List α ihl : (∀ (x : α), x ∈ l → p x = true → q x = true) → countP p l ≤ countP q l h✝ : (p a = true → q a = true) ∧ ∀ (x : α), x ∈ l → p x = true → q x = true ha : p a = true → q a = true hl : ∀ (x : α), x ∈ l → p x = true → q x = true h : p a = true ⊢ countP p l ≤ countP q l ** apply ihl hl ** Qed | |
List.count_cons ** α : Type u_1 inst✝ : DecidableEq α a b : α l : List α ⊢ count a (b :: l) = count a l + if a = b then 1 else 0 ** simp [count, countP_cons, eq_comm (a := a)] ** Qed | |
List.count_cons_self ** α : Type u_1 inst✝ : DecidableEq α a : α l : List α ⊢ count a (a :: l) = count a l + 1 ** simp [count_cons] ** Qed | |
List.count_cons_of_ne ** α : Type u_1 inst✝ : DecidableEq α a b : α h : a ≠ b l : List α ⊢ count a (b :: l) = count a l ** simp [count_cons, h] ** Qed | |
List.count_tail ** α : Type u_1 inst✝ : DecidableEq α head : α tail : List α a : α h : 0 < length (head :: tail) ⊢ count a (List.tail (head :: tail)) = count a (head :: tail) - if a = get (head :: tail) { val := 0, isLt := h } then 1 else 0 ** simp [count_cons] ** Qed | |
List.count_singleton ** α : Type u_1 inst✝ : DecidableEq α a : α ⊢ count a [a] = 1 ** simp ** Qed | |
List.count_singleton' ** α : Type u_1 inst✝ : DecidableEq α a b : α ⊢ count a [b] = if a = b then 1 else 0 ** simp [count_cons] ** Qed | |
List.count_concat ** α : Type u_1 inst✝ : DecidableEq α a : α l : List α ⊢ count a (concat l a) = succ (count a l) ** simp ** Qed | |
List.count_pos_iff_mem ** α : Type u_1 inst✝ : DecidableEq α a : α l : List α ⊢ 0 < count a l ↔ a ∈ l ** simp only [count, countP_pos, beq_iff_eq, exists_eq_right] ** Qed | |
List.count_eq_length ** α : Type u_1 inst✝ : DecidableEq α a : α l : List α ⊢ count a l = length l ↔ ∀ (b : α), b ∈ l → a = b ** rw [count, countP_eq_length] ** α : Type u_1 inst✝ : DecidableEq α a : α l : List α ⊢ (∀ (a_1 : α), a_1 ∈ l → (a_1 == a) = true) ↔ ∀ (b : α), b ∈ l → a = b ** refine ⟨fun h b hb => Eq.symm ?_, fun h b hb => ?_⟩ ** case refine_1 α : Type u_1 inst✝ : DecidableEq α a : α l : List α h : ∀ (a_1 : α), a_1 ∈ l → (a_1 == a) = true b : α hb : b ∈ l ⊢ b = a ** simpa using h b hb ** case refine_2 α : Type u_1 inst✝ : DecidableEq α a : α l : List α h : ∀ (b : α), b ∈ l → a = b b : α hb : b ∈ l ⊢ (b == a) = true ** rw [h b hb, beq_self_eq_true] ** Qed | |
List.count_replicate ** α : Type u_1 inst✝ : DecidableEq α a b : α n : Nat ⊢ count a (replicate n b) = if a = b then n else 0 ** split ** case inl α : Type u_1 inst✝ : DecidableEq α a b : α n : Nat h✝ : a = b ⊢ count a (replicate n b) = n case inr α : Type u_1 inst✝ : DecidableEq α a b : α n : Nat h✝ : ¬a = b ⊢ count a (replicate n b) = 0 ** exacts [‹a = b› ▸ count_replicate_self .., count_eq_zero.2 <| mt eq_of_mem_replicate ‹a ≠ b›] ** Qed | |
List.filter_beq' ** α : Type u_1 inst✝ : DecidableEq α l : List α a : α ⊢ filter (fun x => x == a) l = replicate (count a l) a ** simp only [count, countP_eq_length_filter, eq_replicate, mem_filter, beq_iff_eq] ** α : Type u_1 inst✝ : DecidableEq α l : List α a : α ⊢ True ∧ ∀ (b : α), b ∈ l ∧ b = a → b = a ** exact ⟨trivial, fun _ h => h.2⟩ ** Qed | |
List.filter_eq ** α : Type u_1 inst✝ : DecidableEq α l : List α a : α ⊢ filter (fun x => decide (a = x)) l = replicate (count a l) a ** simpa only [eq_comm] using filter_eq' l a ** Qed | |
List.le_count_iff_replicate_sublist ** α : Type u_1 inst✝ : DecidableEq α n : Nat a : α l : List α ⊢ n ≤ count a l ↔ replicate n a <+ l ** refine ⟨fun h => ?_, fun h => ?_⟩ ** case refine_1 α : Type u_1 inst✝ : DecidableEq α n : Nat a : α l : List α h : n ≤ count a l ⊢ replicate n a <+ l ** exact ((replicate_sublist_replicate a).2 h).trans <| filter_eq l a ▸ filter_sublist _ ** case refine_2 α : Type u_1 inst✝ : DecidableEq α n : Nat a : α l : List α h : replicate n a <+ l ⊢ n ≤ count a l ** simpa only [count_replicate_self] using h.count_le a ** Qed | |
List.count_le_count_map ** α : Type u_2 inst✝¹ : DecidableEq α β : Type u_1 inst✝ : DecidableEq β l : List α f : α → β x : α ⊢ count x l ≤ count (f x) (map f l) ** rw [count, count, countP_map] ** α : Type u_2 inst✝¹ : DecidableEq α β : Type u_1 inst✝ : DecidableEq β l : List α f : α → β x : α ⊢ countP (fun x_1 => x_1 == x) l ≤ countP ((fun x_1 => x_1 == f x) ∘ f) l ** apply countP_mono_left ** case h α : Type u_2 inst✝¹ : DecidableEq α β : Type u_1 inst✝ : DecidableEq β l : List α f : α → β x : α ⊢ ∀ (x_1 : α), x_1 ∈ l → (x_1 == x) = true → ((fun x_2 => x_2 == f x) ∘ f) x_1 = true ** simp (config := { contextual := true }) ** Qed | |
List.count_erase ** α : Type u_1 inst✝ : DecidableEq α a b : α ⊢ count a (List.erase [] b) = count a [] - if a = b then 1 else 0 ** simp ** α : Type u_1 inst✝ : DecidableEq α a b c : α l : List α ⊢ count a (List.erase (c :: l) b) = count a (c :: l) - if a = b then 1 else 0 ** rw [erase_cons] ** α : Type u_1 inst✝ : DecidableEq α a b c : α l : List α ⊢ count a (if c = b then l else c :: List.erase l b) = count a (c :: l) - if a = b then 1 else 0 ** if hc : c = b then
rw [if_pos hc, hc, count_cons, Nat.add_sub_cancel]
else
rw [if_neg hc, count_cons, count_cons, count_erase a b l]
if ha : a = b then
rw [← ha, eq_comm] at hc
rw [if_pos ha, if_neg hc, Nat.add_zero, Nat.add_zero]
else
rw [if_neg ha, Nat.sub_zero, Nat.sub_zero] ** α : Type u_1 inst✝ : DecidableEq α a b c : α l : List α hc : c = b ⊢ count a (if c = b then l else c :: List.erase l b) = count a (c :: l) - if a = b then 1 else 0 ** rw [if_pos hc, hc, count_cons, Nat.add_sub_cancel] ** α : Type u_1 inst✝ : DecidableEq α a b c : α l : List α hc : ¬c = b ⊢ count a (if c = b then l else c :: List.erase l b) = count a (c :: l) - if a = b then 1 else 0 ** rw [if_neg hc, count_cons, count_cons, count_erase a b l] ** α : Type u_1 inst✝ : DecidableEq α a b c : α l : List α hc : ¬c = b ⊢ ((count a l - if a = b then 1 else 0) + if a = c then 1 else 0) = (count a l + if a = c then 1 else 0) - if a = b then 1 else 0 ** if ha : a = b then
rw [← ha, eq_comm] at hc
rw [if_pos ha, if_neg hc, Nat.add_zero, Nat.add_zero]
else
rw [if_neg ha, Nat.sub_zero, Nat.sub_zero] ** α : Type u_1 inst✝ : DecidableEq α a b c : α l : List α hc : ¬c = b ha : a = b ⊢ ((count a l - if a = b then 1 else 0) + if a = c then 1 else 0) = (count a l + if a = c then 1 else 0) - if a = b then 1 else 0 ** rw [← ha, eq_comm] at hc ** α : Type u_1 inst✝ : DecidableEq α a b c : α l : List α hc : ¬a = c ha : a = b ⊢ ((count a l - if a = b then 1 else 0) + if a = c then 1 else 0) = (count a l + if a = c then 1 else 0) - if a = b then 1 else 0 ** rw [if_pos ha, if_neg hc, Nat.add_zero, Nat.add_zero] ** α : Type u_1 inst✝ : DecidableEq α a b c : α l : List α hc : ¬c = b ha : ¬a = b ⊢ ((count a l - if a = b then 1 else 0) + if a = c then 1 else 0) = (count a l + if a = c then 1 else 0) - if a = b then 1 else 0 ** rw [if_neg ha, Nat.sub_zero, Nat.sub_zero] ** Qed | |
List.count_erase_self ** α : Type u_1 inst✝ : DecidableEq α a : α l : List α ⊢ count a (List.erase l a) = count a l - 1 ** rw [count_erase, if_pos rfl] ** Qed | |
List.count_erase_of_ne ** α : Type u_1 inst✝ : DecidableEq α a b : α ab : a ≠ b l : List α ⊢ count a (List.erase l b) = count a l ** rw [count_erase, if_neg ab, Nat.sub_zero] ** Qed | |
Std.RBNode.Path.zoom_ins ** α : Type u_1 v : α path : Path α t' : RBNode α path' : Path α t : RBNode α cmp : α → α → Ordering ⊢ zoom (cmp v) t path = (t', path') → ins path (RBNode.ins cmp v t) = ins path' (setRoot v t') ** unfold RBNode.ins ** α : Type u_1 v : α path : Path α t' : RBNode α path' : Path α t : RBNode α cmp : α → α → Ordering ⊢ zoom (cmp v) t path = (t', path') → ins path (match t with | nil => node red nil v nil | node red a y b => match cmp v y with | Ordering.lt => node red (RBNode.ins cmp v a) y b | Ordering.gt => node red a y (RBNode.ins cmp v b) | Ordering.eq => node red a v b | node black a y b => match cmp v y with | Ordering.lt => balance1 (RBNode.ins cmp v a) y b | Ordering.gt => balance2 a y (RBNode.ins cmp v b) | Ordering.eq => node black a v b) = ins path' (setRoot v t') ** split <;> simp [zoom] ** case h_1 α : Type u_1 v : α path : Path α t' : RBNode α path' : Path α cmp : α → α → Ordering x✝ : RBNode α ⊢ nil = t' → path = path' → ins path (node red nil v nil) = ins path' (setRoot v t') ** intro | rfl, rfl => rfl ** α : Type u_1 v : α path : Path α t' : RBNode α path' : Path α cmp : α → α → Ordering x✝² : RBNode α x✝¹ : nil = t' x✝ : path = path' ⊢ ins path (node red nil v nil) = ins path (setRoot v nil) ** rfl ** case h_3 α : Type u_1 v : α path : Path α t' : RBNode α path' : Path α cmp : α → α → Ordering x✝ a✝ : RBNode α y✝ : α b✝ : RBNode α ⊢ (match cmp v y✝ with | Ordering.lt => zoom (cmp v) a✝ (left black path y✝ b✝) | Ordering.gt => zoom (cmp v) b✝ (right black a✝ y✝ path) | Ordering.eq => (node black a✝ y✝ b✝, path)) = (t', path') → ins path (match cmp v y✝ with | Ordering.lt => balance1 (RBNode.ins cmp v a✝) y✝ b✝ | Ordering.gt => balance2 a✝ y✝ (RBNode.ins cmp v b✝) | Ordering.eq => node black a✝ v b✝) = ins path' (setRoot v t') ** split ** case h_3.h_1 α : Type u_1 v : α path : Path α t' : RBNode α path' : Path α cmp : α → α → Ordering x✝¹ a✝ : RBNode α y✝ : α b✝ : RBNode α x✝ : Ordering heq✝ : cmp v y✝ = Ordering.lt ⊢ zoom (cmp v) a✝ (left black path y✝ b✝) = (t', path') → ins path (balance1 (RBNode.ins cmp v a✝) y✝ b✝) = ins path' (setRoot v t') ** exact zoom_ins ** case h_3.h_2 α : Type u_1 v : α path : Path α t' : RBNode α path' : Path α cmp : α → α → Ordering x✝¹ a✝ : RBNode α y✝ : α b✝ : RBNode α x✝ : Ordering heq✝ : cmp v y✝ = Ordering.gt ⊢ zoom (cmp v) b✝ (right black a✝ y✝ path) = (t', path') → ins path (balance2 a✝ y✝ (RBNode.ins cmp v b✝)) = ins path' (setRoot v t') ** exact zoom_ins ** case h_3.h_3 α : Type u_1 v : α path : Path α t' : RBNode α path' : Path α cmp : α → α → Ordering x✝¹ a✝ : RBNode α y✝ : α b✝ : RBNode α x✝ : Ordering heq✝ : cmp v y✝ = Ordering.eq ⊢ (node black a✝ y✝ b✝, path) = (t', path') → ins path (node black a✝ v b✝) = ins path' (setRoot v t') ** intro | rfl => rfl ** α : Type u_1 v : α path : Path α t' : RBNode α path' : Path α cmp : α → α → Ordering x✝² a✝ : RBNode α y✝ : α b✝ : RBNode α x✝¹ : Ordering heq✝ : cmp v y✝ = Ordering.eq x✝ : (node black a✝ y✝ b✝, path) = (t', path') ⊢ ins path (node black a✝ v b✝) = ins path (setRoot v (node black a✝ y✝ b✝)) ** rfl ** Qed | |
Std.RBNode.Path.zoom_del ** α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α t : RBNode α ⊢ zoom cut t path = (t', path') → del path (RBNode.del cut t) (match t with | node c l v r => c | x => red) = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ** unfold RBNode.del ** α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α t : RBNode α ⊢ zoom cut t path = (t', path') → del path (match t with | nil => nil | node c a y b => match cut y with | Ordering.lt => match isBlack a with | black => balLeft (RBNode.del cut a) y b | red => node red (RBNode.del cut a) y b | Ordering.gt => match isBlack b with | black => balRight a y (RBNode.del cut b) | red => node red a y (RBNode.del cut b) | Ordering.eq => append a b) (match t with | node c l v r => c | x => red) = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ** split <;> simp [zoom] ** case h_1 α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝ : RBNode α ⊢ nil = t' → path = path' → del path nil red = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ** intro | rfl, rfl => rfl ** α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝² : RBNode α x✝¹ : nil = t' x✝ : path = path' ⊢ del path nil red = del path (delRoot nil) (match nil with | node c l v r => c | x => red) ** rfl ** α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝ : RBNode α c : RBColor a : RBNode α y : α b : RBNode α ⊢ (match cut y with | Ordering.lt => zoom cut a (left c path y b) | Ordering.gt => zoom cut b (right c a y path) | Ordering.eq => (node c a y b, path)) = (t', path') → del path (match cut y with | Ordering.lt => match isBlack a with | black => balLeft (RBNode.del cut a) y b | red => node red (RBNode.del cut a) y b | Ordering.gt => match isBlack b with | black => balRight a y (RBNode.del cut b) | red => node red a y (RBNode.del cut b) | Ordering.eq => append a b) c = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ** split ** case h_1 α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝¹ : RBNode α c : RBColor a : RBNode α y : α b : RBNode α x✝ : Ordering heq✝ : cut y = Ordering.lt ⊢ zoom cut a (left c path y b) = (t', path') → del path (match isBlack a with | black => balLeft (RBNode.del cut a) y b | red => node red (RBNode.del cut a) y b) c = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ** have IH := @zoom_del (t := a) ** case h_1 α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝¹ : RBNode α c : RBColor a : RBNode α y : α b : RBNode α x✝ : Ordering heq✝ : cut y = Ordering.lt IH : ∀ (cut : α → Ordering) (path : Path α) (t' : RBNode α) (path' : Path α), zoom cut a path = (t', path') → del path (RBNode.del cut a) (match a with | node c l v r => c | x => red) = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ⊢ zoom cut a (left c path y b) = (t', path') → del path (match isBlack a with | black => balLeft (RBNode.del cut a) y b | red => node red (RBNode.del cut a) y b) c = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ** match a with
| nil => intro | rfl => rfl
| node black .. | node red .. => apply IH ** α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝¹ : RBNode α c : RBColor a : RBNode α y : α b : RBNode α x✝ : Ordering heq✝ : cut y = Ordering.lt IH : ∀ (cut : α → Ordering) (path : Path α) (t' : RBNode α) (path' : Path α), zoom cut nil path = (t', path') → del path (RBNode.del cut nil) (match nil with | node c l v r => c | x => red) = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ⊢ zoom cut nil (left c path y b) = (t', path') → del path (match isBlack nil with | black => balLeft (RBNode.del cut nil) y b | red => node red (RBNode.del cut nil) y b) c = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ** intro | rfl => rfl ** α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝² : RBNode α c : RBColor a : RBNode α y : α b : RBNode α x✝¹ : Ordering heq✝ : cut y = Ordering.lt IH : ∀ (cut : α → Ordering) (path : Path α) (t' : RBNode α) (path' : Path α), zoom cut nil path = (t', path') → del path (RBNode.del cut nil) (match nil with | node c l v r => c | x => red) = del path' (delRoot t') (match t' with | node c l v r => c | x => red) x✝ : zoom cut nil (left c path y b) = (t', path') ⊢ del path (match isBlack nil with | black => balLeft (RBNode.del cut nil) y b | red => node red (RBNode.del cut nil) y b) c = del (left c path y b) (delRoot nil) (match nil with | node c l v r => c | x => red) ** rfl ** α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝¹ : RBNode α c : RBColor a : RBNode α y : α b : RBNode α x✝ : Ordering heq✝ : cut y = Ordering.lt l✝ : RBNode α v✝ : α r✝ : RBNode α IH : ∀ (cut : α → Ordering) (path : Path α) (t' : RBNode α) (path' : Path α), zoom cut (node red l✝ v✝ r✝) path = (t', path') → del path (RBNode.del cut (node red l✝ v✝ r✝)) (match node red l✝ v✝ r✝ with | node c l v r => c | x => red) = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ⊢ zoom cut (node red l✝ v✝ r✝) (left c path y b) = (t', path') → del path (match isBlack (node red l✝ v✝ r✝) with | black => balLeft (RBNode.del cut (node red l✝ v✝ r✝)) y b | red => node red (RBNode.del cut (node red l✝ v✝ r✝)) y b) c = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ** apply IH ** case h_2 α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝¹ : RBNode α c : RBColor a : RBNode α y : α b : RBNode α x✝ : Ordering heq✝ : cut y = Ordering.gt ⊢ zoom cut b (right c a y path) = (t', path') → del path (match isBlack b with | black => balRight a y (RBNode.del cut b) | red => node red a y (RBNode.del cut b)) c = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ** have IH := @zoom_del (t := b) ** case h_2 α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝¹ : RBNode α c : RBColor a : RBNode α y : α b : RBNode α x✝ : Ordering heq✝ : cut y = Ordering.gt IH : ∀ (cut : α → Ordering) (path : Path α) (t' : RBNode α) (path' : Path α), zoom cut b path = (t', path') → del path (RBNode.del cut b) (match b with | node c l v r => c | x => red) = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ⊢ zoom cut b (right c a y path) = (t', path') → del path (match isBlack b with | black => balRight a y (RBNode.del cut b) | red => node red a y (RBNode.del cut b)) c = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ** match b with
| nil => intro | rfl => rfl
| node black .. | node red .. => apply IH ** α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝¹ : RBNode α c : RBColor a : RBNode α y : α b : RBNode α x✝ : Ordering heq✝ : cut y = Ordering.gt IH : ∀ (cut : α → Ordering) (path : Path α) (t' : RBNode α) (path' : Path α), zoom cut nil path = (t', path') → del path (RBNode.del cut nil) (match nil with | node c l v r => c | x => red) = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ⊢ zoom cut nil (right c a y path) = (t', path') → del path (match isBlack nil with | black => balRight a y (RBNode.del cut nil) | red => node red a y (RBNode.del cut nil)) c = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ** intro | rfl => rfl ** α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝² : RBNode α c : RBColor a : RBNode α y : α b : RBNode α x✝¹ : Ordering heq✝ : cut y = Ordering.gt IH : ∀ (cut : α → Ordering) (path : Path α) (t' : RBNode α) (path' : Path α), zoom cut nil path = (t', path') → del path (RBNode.del cut nil) (match nil with | node c l v r => c | x => red) = del path' (delRoot t') (match t' with | node c l v r => c | x => red) x✝ : zoom cut nil (right c a y path) = (t', path') ⊢ del path (match isBlack nil with | black => balRight a y (RBNode.del cut nil) | red => node red a y (RBNode.del cut nil)) c = del (right c a y path) (delRoot nil) (match nil with | node c l v r => c | x => red) ** rfl ** α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝¹ : RBNode α c : RBColor a : RBNode α y : α b : RBNode α x✝ : Ordering heq✝ : cut y = Ordering.gt l✝ : RBNode α v✝ : α r✝ : RBNode α IH : ∀ (cut : α → Ordering) (path : Path α) (t' : RBNode α) (path' : Path α), zoom cut (node red l✝ v✝ r✝) path = (t', path') → del path (RBNode.del cut (node red l✝ v✝ r✝)) (match node red l✝ v✝ r✝ with | node c l v r => c | x => red) = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ⊢ zoom cut (node red l✝ v✝ r✝) (right c a y path) = (t', path') → del path (match isBlack (node red l✝ v✝ r✝) with | black => balRight a y (RBNode.del cut (node red l✝ v✝ r✝)) | red => node red a y (RBNode.del cut (node red l✝ v✝ r✝))) c = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ** apply IH ** case h_3 α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝¹ : RBNode α c : RBColor a : RBNode α y : α b : RBNode α x✝ : Ordering heq✝ : cut y = Ordering.eq ⊢ (node c a y b, path) = (t', path') → del path (append a b) c = del path' (delRoot t') (match t' with | node c l v r => c | x => red) ** intro | rfl => rfl ** α : Type u_1 cut : α → Ordering path : Path α t' : RBNode α path' : Path α x✝² : RBNode α c : RBColor a : RBNode α y : α b : RBNode α x✝¹ : Ordering heq✝ : cut y = Ordering.eq x✝ : (node c a y b, path) = (t', path') ⊢ del path (append a b) c = del path (delRoot (node c a y b)) (match node c a y b with | node c l v r => c | x => red) ** rfl ** Qed | |
Std.RBNode.Balanced.zoom ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n : Nat hp : Path.Balanced c₀ n₀ path black 0 e : zoom cut nil path = (t', path') ⊢ ∃ c n, Balanced t' c n ∧ Path.Balanced c₀ n₀ path' c n ** cases e ** case refl α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n : Nat hp : Path.Balanced c₀ n₀ path black 0 ⊢ ∃ c n, Balanced nil c n ∧ Path.Balanced c₀ n₀ path c n ** exact ⟨_, _, .nil, hp⟩ ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n✝ n : Nat x✝ y✝ : RBNode α✝ v✝ : α✝ ha : Balanced x✝ black n hb : Balanced y✝ black n hp : Path.Balanced c₀ n₀ path red n ⊢ zoom cut (node red x✝ v✝ y✝) path = (t', path') → ∃ c n, Balanced t' c n ∧ Path.Balanced c₀ n₀ path' c n ** unfold zoom ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n✝ n : Nat x✝ y✝ : RBNode α✝ v✝ : α✝ ha : Balanced x✝ black n hb : Balanced y✝ black n hp : Path.Balanced c₀ n₀ path red n ⊢ (match cut v✝ with | Ordering.lt => zoom cut x✝ (left red path v✝ y✝) | Ordering.gt => zoom cut y✝ (right red x✝ v✝ path) | Ordering.eq => (node red x✝ v✝ y✝, path)) = (t', path') → ∃ c n, Balanced t' c n ∧ Path.Balanced c₀ n₀ path' c n ** split ** case h_1 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n✝ n : Nat x✝¹ y✝ : RBNode α✝ v✝ : α✝ ha : Balanced x✝¹ black n hb : Balanced y✝ black n hp : Path.Balanced c₀ n₀ path red n x✝ : Ordering heq✝ : cut v✝ = Ordering.lt ⊢ zoom cut x✝¹ (left red path v✝ y✝) = (t', path') → ∃ c n, Balanced t' c n ∧ Path.Balanced c₀ n₀ path' c n ** exact ha.zoom (.redL hb hp) ** case h_2 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n✝ n : Nat x✝¹ y✝ : RBNode α✝ v✝ : α✝ ha : Balanced x✝¹ black n hb : Balanced y✝ black n hp : Path.Balanced c₀ n₀ path red n x✝ : Ordering heq✝ : cut v✝ = Ordering.gt ⊢ zoom cut y✝ (right red x✝¹ v✝ path) = (t', path') → ∃ c n, Balanced t' c n ∧ Path.Balanced c₀ n₀ path' c n ** exact hb.zoom (.redR ha hp) ** case h_3 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n✝ n : Nat x✝¹ y✝ : RBNode α✝ v✝ : α✝ ha : Balanced x✝¹ black n hb : Balanced y✝ black n hp : Path.Balanced c₀ n₀ path red n x✝ : Ordering heq✝ : cut v✝ = Ordering.eq ⊢ (node red x✝¹ v✝ y✝, path) = (t', path') → ∃ c n, Balanced t' c n ∧ Path.Balanced c₀ n₀ path' c n ** intro e ** case h_3 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n✝ n : Nat x✝¹ y✝ : RBNode α✝ v✝ : α✝ ha : Balanced x✝¹ black n hb : Balanced y✝ black n hp : Path.Balanced c₀ n₀ path red n x✝ : Ordering heq✝ : cut v✝ = Ordering.eq e : (node red x✝¹ v✝ y✝, path) = (t', path') ⊢ ∃ c n, Balanced t' c n ∧ Path.Balanced c₀ n₀ path' c n ** cases e ** case h_3.refl α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n✝ n : Nat x✝¹ y✝ : RBNode α✝ v✝ : α✝ ha : Balanced x✝¹ black n hb : Balanced y✝ black n hp : Path.Balanced c₀ n₀ path red n x✝ : Ordering heq✝ : cut v✝ = Ordering.eq ⊢ ∃ c n, Balanced (node red x✝¹ v✝ y✝) c n ∧ Path.Balanced c₀ n₀ path c n ** exact ⟨_, _, .red ha hb, hp⟩ ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n : Nat x✝ : RBNode α✝ c₁✝ : RBColor n✝ : Nat y✝ : RBNode α✝ c₂✝ : RBColor v✝ : α✝ ha : Balanced x✝ c₁✝ n✝ hb : Balanced y✝ c₂✝ n✝ hp : Path.Balanced c₀ n₀ path black (n✝ + 1) ⊢ zoom cut (node black x✝ v✝ y✝) path = (t', path') → ∃ c n, Balanced t' c n ∧ Path.Balanced c₀ n₀ path' c n ** unfold zoom ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n : Nat x✝ : RBNode α✝ c₁✝ : RBColor n✝ : Nat y✝ : RBNode α✝ c₂✝ : RBColor v✝ : α✝ ha : Balanced x✝ c₁✝ n✝ hb : Balanced y✝ c₂✝ n✝ hp : Path.Balanced c₀ n₀ path black (n✝ + 1) ⊢ (match cut v✝ with | Ordering.lt => zoom cut x✝ (left black path v✝ y✝) | Ordering.gt => zoom cut y✝ (right black x✝ v✝ path) | Ordering.eq => (node black x✝ v✝ y✝, path)) = (t', path') → ∃ c n, Balanced t' c n ∧ Path.Balanced c₀ n₀ path' c n ** split ** case h_1 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n : Nat x✝¹ : RBNode α✝ c₁✝ : RBColor n✝ : Nat y✝ : RBNode α✝ c₂✝ : RBColor v✝ : α✝ ha : Balanced x✝¹ c₁✝ n✝ hb : Balanced y✝ c₂✝ n✝ hp : Path.Balanced c₀ n₀ path black (n✝ + 1) x✝ : Ordering heq✝ : cut v✝ = Ordering.lt ⊢ zoom cut x✝¹ (left black path v✝ y✝) = (t', path') → ∃ c n, Balanced t' c n ∧ Path.Balanced c₀ n₀ path' c n ** exact ha.zoom (.blackL hb hp) ** case h_2 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n : Nat x✝¹ : RBNode α✝ c₁✝ : RBColor n✝ : Nat y✝ : RBNode α✝ c₂✝ : RBColor v✝ : α✝ ha : Balanced x✝¹ c₁✝ n✝ hb : Balanced y✝ c₂✝ n✝ hp : Path.Balanced c₀ n₀ path black (n✝ + 1) x✝ : Ordering heq✝ : cut v✝ = Ordering.gt ⊢ zoom cut y✝ (right black x✝¹ v✝ path) = (t', path') → ∃ c n, Balanced t' c n ∧ Path.Balanced c₀ n₀ path' c n ** exact hb.zoom (.blackR ha hp) ** case h_3 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n : Nat x✝¹ : RBNode α✝ c₁✝ : RBColor n✝ : Nat y✝ : RBNode α✝ c₂✝ : RBColor v✝ : α✝ ha : Balanced x✝¹ c₁✝ n✝ hb : Balanced y✝ c₂✝ n✝ hp : Path.Balanced c₀ n₀ path black (n✝ + 1) x✝ : Ordering heq✝ : cut v✝ = Ordering.eq ⊢ (node black x✝¹ v✝ y✝, path) = (t', path') → ∃ c n, Balanced t' c n ∧ Path.Balanced c₀ n₀ path' c n ** intro e ** case h_3 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n : Nat x✝¹ : RBNode α✝ c₁✝ : RBColor n✝ : Nat y✝ : RBNode α✝ c₂✝ : RBColor v✝ : α✝ ha : Balanced x✝¹ c₁✝ n✝ hb : Balanced y✝ c₂✝ n✝ hp : Path.Balanced c₀ n₀ path black (n✝ + 1) x✝ : Ordering heq✝ : cut v✝ = Ordering.eq e : (node black x✝¹ v✝ y✝, path) = (t', path') ⊢ ∃ c n, Balanced t' c n ∧ Path.Balanced c₀ n₀ path' c n ** cases e ** case h_3.refl α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ c₀ : RBColor n₀ : Nat c : RBColor n : Nat x✝¹ : RBNode α✝ c₁✝ : RBColor n✝ : Nat y✝ : RBNode α✝ c₂✝ : RBColor v✝ : α✝ ha : Balanced x✝¹ c₁✝ n✝ hb : Balanced y✝ c₂✝ n✝ hp : Path.Balanced c₀ n₀ path black (n✝ + 1) x✝ : Ordering heq✝ : cut v✝ = Ordering.eq ⊢ ∃ c n, Balanced (node black x✝¹ v✝ y✝) c n ∧ Path.Balanced c₀ n₀ path c n ** exact ⟨_, _, .black ha hb, hp⟩ ** Qed | |
Std.RBNode.Path.Balanced.ins ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat t : RBNode α path : Path α hp : Path.Balanced c₀ n₀ path c n ht : RedRed (c = red) t n ⊢ ∃ n, Balanced (ins path t) black n ** induction hp generalizing t with
| root => exact ht.setBlack
| redL hr hp ih => match ht with
| .balanced .nil => exact ih (.balanced (.red .nil hr))
| .balanced (.red ha hb) => exact ih (.redred rfl (.red ha hb) hr)
| .balanced (.black ha hb) => exact ih (.balanced (.red (.black ha hb) hr))
| redR hl hp ih => match ht with
| .balanced .nil => exact ih (.balanced (.red hl .nil))
| .balanced (.red ha hb) => exact ih (.redred rfl hl (.red ha hb))
| .balanced (.black ha hb) => exact ih (.balanced (.red hl (.black ha hb)))
| blackL hr hp ih => exact have ⟨c, h⟩ := ht.balance1 hr; ih (.balanced h)
| blackR hl hp ih => exact have ⟨c, h⟩ := ht.balance2 hl; ih (.balanced h) ** case root α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat path : Path α t : RBNode α ht : RedRed (c₀ = red) t n₀ ⊢ ∃ n, Balanced (ins root t) black n ** exact ht.setBlack ** case redL α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat path : Path α y✝ : RBNode α n✝ : Nat parent✝ : Path α v✝ : α hr : Balanced y✝ black n✝ hp : Path.Balanced c₀ n₀ parent✝ red n✝ ih : ∀ {t : RBNode α}, RedRed (red = red) t n✝ → ∃ n, Balanced (ins parent✝ t) black n t : RBNode α ht : RedRed (black = red) t n✝ ⊢ ∃ n, Balanced (ins (left red parent✝ v✝ y✝) t) black n ** match ht with
| .balanced .nil => exact ih (.balanced (.red .nil hr))
| .balanced (.red ha hb) => exact ih (.redred rfl (.red ha hb) hr)
| .balanced (.black ha hb) => exact ih (.balanced (.red (.black ha hb) hr)) ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat path : Path α y✝ : RBNode α n✝ : Nat parent✝ : Path α v✝ : α t : RBNode α ht : RedRed (black = red) t n✝ hr : Balanced y✝ black 0 hp : Path.Balanced c₀ n₀ parent✝ red 0 ih : ∀ {t : RBNode α}, RedRed (red = red) t 0 → ∃ n, Balanced (ins parent✝ t) black n ⊢ ∃ n, Balanced (ins (left red parent✝ v✝ y✝) nil) black n ** exact ih (.balanced (.red .nil hr)) ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat path : Path α y✝ : RBNode α n✝ : Nat parent✝ : Path α v✝¹ : α t : RBNode α ht : RedRed (black = red) t n✝ x✝ : Nat l✝ : RBNode α v✝ : α r✝ : RBNode α ha : Balanced l✝ black x✝ hb : Balanced r✝ black x✝ hr : Balanced y✝ black x✝ hp : Path.Balanced c₀ n₀ parent✝ red x✝ ih : ∀ {t : RBNode α}, RedRed (red = red) t x✝ → ∃ n, Balanced (ins parent✝ t) black n ⊢ ∃ n, Balanced (ins (left red parent✝ v✝¹ y✝) (node red l✝ v✝ r✝)) black n ** exact ih (.redred rfl (.red ha hb) hr) ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat path : Path α y✝ : RBNode α n✝¹ : Nat parent✝ : Path α v✝¹ : α t : RBNode α ht : RedRed (black = red) t n✝¹ l✝ : RBNode α v✝ : α r✝ : RBNode α n✝ : Nat c₁✝ c₂✝ : RBColor ha : Balanced l✝ c₁✝ n✝ hb : Balanced r✝ c₂✝ n✝ hr : Balanced y✝ black (n✝ + 1) hp : Path.Balanced c₀ n₀ parent✝ red (n✝ + 1) ih : ∀ {t : RBNode α}, RedRed (red = red) t (n✝ + 1) → ∃ n, Balanced (ins parent✝ t) black n ⊢ ∃ n, Balanced (ins (left red parent✝ v✝¹ y✝) (node black l✝ v✝ r✝)) black n ** exact ih (.balanced (.red (.black ha hb) hr)) ** case redR α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat path : Path α x✝ : RBNode α n✝ : Nat v✝ : α parent✝ : Path α hl : Balanced x✝ black n✝ hp : Path.Balanced c₀ n₀ parent✝ red n✝ ih : ∀ {t : RBNode α}, RedRed (red = red) t n✝ → ∃ n, Balanced (ins parent✝ t) black n t : RBNode α ht : RedRed (black = red) t n✝ ⊢ ∃ n, Balanced (ins (right red x✝ v✝ parent✝) t) black n ** match ht with
| .balanced .nil => exact ih (.balanced (.red hl .nil))
| .balanced (.red ha hb) => exact ih (.redred rfl hl (.red ha hb))
| .balanced (.black ha hb) => exact ih (.balanced (.red hl (.black ha hb))) ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat path : Path α x✝ : RBNode α n✝ : Nat v✝ : α parent✝ : Path α t : RBNode α ht : RedRed (black = red) t n✝ hl : Balanced x✝ black 0 hp : Path.Balanced c₀ n₀ parent✝ red 0 ih : ∀ {t : RBNode α}, RedRed (red = red) t 0 → ∃ n, Balanced (ins parent✝ t) black n ⊢ ∃ n, Balanced (ins (right red x✝ v✝ parent✝) nil) black n ** exact ih (.balanced (.red hl .nil)) ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat path : Path α x✝¹ : RBNode α n✝ : Nat v✝¹ : α parent✝ : Path α t : RBNode α ht : RedRed (black = red) t n✝ x✝ : Nat l✝ : RBNode α v✝ : α r✝ : RBNode α ha : Balanced l✝ black x✝ hb : Balanced r✝ black x✝ hl : Balanced x✝¹ black x✝ hp : Path.Balanced c₀ n₀ parent✝ red x✝ ih : ∀ {t : RBNode α}, RedRed (red = red) t x✝ → ∃ n, Balanced (ins parent✝ t) black n ⊢ ∃ n, Balanced (ins (right red x✝¹ v✝¹ parent✝) (node red l✝ v✝ r✝)) black n ** exact ih (.redred rfl hl (.red ha hb)) ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat path : Path α x✝ : RBNode α n✝¹ : Nat v✝¹ : α parent✝ : Path α t : RBNode α ht : RedRed (black = red) t n✝¹ l✝ : RBNode α v✝ : α r✝ : RBNode α n✝ : Nat c₁✝ c₂✝ : RBColor ha : Balanced l✝ c₁✝ n✝ hb : Balanced r✝ c₂✝ n✝ hl : Balanced x✝ black (n✝ + 1) hp : Path.Balanced c₀ n₀ parent✝ red (n✝ + 1) ih : ∀ {t : RBNode α}, RedRed (red = red) t (n✝ + 1) → ∃ n, Balanced (ins parent✝ t) black n ⊢ ∃ n, Balanced (ins (right red x✝ v✝¹ parent✝) (node black l✝ v✝ r✝)) black n ** exact ih (.balanced (.red hl (.black ha hb))) ** case blackL α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat path : Path α y✝ : RBNode α c₂✝ : RBColor n✝ : Nat parent✝ : Path α v✝ : α c₁✝ : RBColor hr : Balanced y✝ c₂✝ n✝ hp : Path.Balanced c₀ n₀ parent✝ black (n✝ + 1) ih : ∀ {t : RBNode α}, RedRed (black = red) t (n✝ + 1) → ∃ n, Balanced (ins parent✝ t) black n t : RBNode α ht : RedRed (c₁✝ = red) t n✝ ⊢ ∃ n, Balanced (ins (left black parent✝ v✝ y✝) t) black n ** exact have ⟨c, h⟩ := ht.balance1 hr; ih (.balanced h) ** case blackR α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat path : Path α x✝ : RBNode α c₁✝ : RBColor n✝ : Nat v✝ : α parent✝ : Path α c₂✝ : RBColor hl : Balanced x✝ c₁✝ n✝ hp : Path.Balanced c₀ n₀ parent✝ black (n✝ + 1) ih : ∀ {t : RBNode α}, RedRed (black = red) t (n✝ + 1) → ∃ n, Balanced (ins parent✝ t) black n t : RBNode α ht : RedRed (c₂✝ = red) t n✝ ⊢ ∃ n, Balanced (ins (right black x✝ v✝ parent✝) t) black n ** exact have ⟨c, h⟩ := ht.balance2 hl; ih (.balanced h) ** Qed | |
Std.RBNode.Path.Balanced.del ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat c' : RBColor t : RBNode α path : Path α hp : Path.Balanced c₀ n₀ path c n ht : DelProp c' t n hc : c = black → c' ≠ red ⊢ ∃ n, Balanced (del path t c') black n ** induction hp generalizing t c' with
| root => match c', ht with
| red, ⟨_, h⟩ | black, ⟨_, _, h⟩ => exact h.setBlack
| @redL _ n _ _ hb hp ih => match c', n, ht with
| red, _, _ => cases hc rfl rfl
| black, _, ⟨_, rfl, ha⟩ => exact ih ((hb.balLeft ha).of_false (fun.)) (fun.)
| @redR _ n _ _ ha hp ih => match c', n, ht with
| red, _, _ => cases hc rfl rfl
| black, _, ⟨_, rfl, hb⟩ => exact ih ((ha.balRight hb).of_false (fun.)) (fun.)
| @blackL _ _ n _ _ _ hb hp ih => match c', n, ht with
| red, _, ⟨_, ha⟩ => exact ih ⟨_, rfl, .redred ⟨⟩ ha hb⟩ (fun.)
| black, _, ⟨_, rfl, ha⟩ => exact ih ⟨_, rfl, (hb.balLeft ha).imp fun _ => ⟨⟩⟩ (fun.)
| @blackR _ _ n _ _ _ ha hp ih => match c', n, ht with
| red, _, ⟨_, hb⟩ => exact ih ⟨_, rfl, .redred ⟨⟩ ha hb⟩ (fun.)
| black, _, ⟨_, rfl, hb⟩ => exact ih ⟨_, rfl, (ha.balRight hb).imp fun _ => ⟨⟩⟩ (fun.) ** case root α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat path : Path α c' : RBColor t : RBNode α ht : DelProp c' t n₀ hc : c₀ = black → c' ≠ red ⊢ ∃ n, Balanced (del root t c') black n ** match c', ht with
| red, ⟨_, h⟩ | black, ⟨_, _, h⟩ => exact h.setBlack ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n : Nat path : Path α c' : RBColor t : RBNode α ht : DelProp c' t n₀ w✝ : Nat left✝ : n₀ = w✝ + 1 h : RedRed True t w✝ hc : c₀ = black → black ≠ red ⊢ ∃ n, Balanced (del root t black) black n ** exact h.setBlack ** case redL α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n✝ : Nat path : Path α y✝ : RBNode α n : Nat parent✝ : Path α v✝ : α hb : Balanced y✝ black n hp : Path.Balanced c₀ n₀ parent✝ red n ih : ∀ {c' : RBColor} {t : RBNode α}, DelProp c' t n → (red = black → c' ≠ red) → ∃ n, Balanced (del parent✝ t c') black n c' : RBColor t : RBNode α ht : DelProp c' t n hc : black = black → c' ≠ red ⊢ ∃ n, Balanced (del (left red parent✝ v✝ y✝) t c') black n ** match c', n, ht with
| red, _, _ => cases hc rfl rfl
| black, _, ⟨_, rfl, ha⟩ => exact ih ((hb.balLeft ha).of_false (fun.)) (fun.) ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n✝ : Nat path : Path α y✝ : RBNode α n : Nat parent✝ : Path α v✝ : α c' : RBColor t : RBNode α ht : DelProp c' t n x✝¹ : Nat x✝ : DelProp red t x✝¹ hb : Balanced y✝ black x✝¹ hp : Path.Balanced c₀ n₀ parent✝ red x✝¹ ih : ∀ {c' : RBColor} {t : RBNode α}, DelProp c' t x✝¹ → (red = black → c' ≠ red) → ∃ n, Balanced (del parent✝ t c') black n hc : black = black → red ≠ red ⊢ ∃ n, Balanced (del (left red parent✝ v✝ y✝) t red) black n ** cases hc rfl rfl ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n✝ : Nat path : Path α y✝ : RBNode α n : Nat parent✝ : Path α v✝ : α c' : RBColor t : RBNode α ht : DelProp c' t n w✝ : Nat ha : RedRed True t w✝ hb : Balanced y✝ black (w✝ + 1) hp : Path.Balanced c₀ n₀ parent✝ red (w✝ + 1) ih : ∀ {c' : RBColor} {t : RBNode α}, DelProp c' t (w✝ + 1) → (red = black → c' ≠ red) → ∃ n, Balanced (del parent✝ t c') black n hc : black = black → black ≠ red ⊢ ∃ n, Balanced (del (left red parent✝ v✝ y✝) t black) black n ** exact ih ((hb.balLeft ha).of_false (fun.)) (fun.) ** case redR α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n✝ : Nat path : Path α x✝ : RBNode α n : Nat v✝ : α parent✝ : Path α ha : Balanced x✝ black n hp : Path.Balanced c₀ n₀ parent✝ red n ih : ∀ {c' : RBColor} {t : RBNode α}, DelProp c' t n → (red = black → c' ≠ red) → ∃ n, Balanced (del parent✝ t c') black n c' : RBColor t : RBNode α ht : DelProp c' t n hc : black = black → c' ≠ red ⊢ ∃ n, Balanced (del (right red x✝ v✝ parent✝) t c') black n ** match c', n, ht with
| red, _, _ => cases hc rfl rfl
| black, _, ⟨_, rfl, hb⟩ => exact ih ((ha.balRight hb).of_false (fun.)) (fun.) ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n✝ : Nat path : Path α x✝² : RBNode α n : Nat v✝ : α parent✝ : Path α c' : RBColor t : RBNode α ht : DelProp c' t n x✝¹ : Nat x✝ : DelProp red t x✝¹ ha : Balanced x✝² black x✝¹ hp : Path.Balanced c₀ n₀ parent✝ red x✝¹ ih : ∀ {c' : RBColor} {t : RBNode α}, DelProp c' t x✝¹ → (red = black → c' ≠ red) → ∃ n, Balanced (del parent✝ t c') black n hc : black = black → red ≠ red ⊢ ∃ n, Balanced (del (right red x✝² v✝ parent✝) t red) black n ** cases hc rfl rfl ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n✝ : Nat path : Path α x✝ : RBNode α n : Nat v✝ : α parent✝ : Path α c' : RBColor t : RBNode α ht : DelProp c' t n w✝ : Nat hb : RedRed True t w✝ ha : Balanced x✝ black (w✝ + 1) hp : Path.Balanced c₀ n₀ parent✝ red (w✝ + 1) ih : ∀ {c' : RBColor} {t : RBNode α}, DelProp c' t (w✝ + 1) → (red = black → c' ≠ red) → ∃ n, Balanced (del parent✝ t c') black n hc : black = black → black ≠ red ⊢ ∃ n, Balanced (del (right red x✝ v✝ parent✝) t black) black n ** exact ih ((ha.balRight hb).of_false (fun.)) (fun.) ** case blackL α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n✝ : Nat path : Path α y✝ : RBNode α c₂✝ : RBColor n : Nat parent✝ : Path α v✝ : α c₁✝ : RBColor hb : Balanced y✝ c₂✝ n hp : Path.Balanced c₀ n₀ parent✝ black (n + 1) ih : ∀ {c' : RBColor} {t : RBNode α}, DelProp c' t (n + 1) → (black = black → c' ≠ red) → ∃ n, Balanced (del parent✝ t c') black n c' : RBColor t : RBNode α ht : DelProp c' t n hc : c₁✝ = black → c' ≠ red ⊢ ∃ n, Balanced (del (left black parent✝ v✝ y✝) t c') black n ** match c', n, ht with
| red, _, ⟨_, ha⟩ => exact ih ⟨_, rfl, .redred ⟨⟩ ha hb⟩ (fun.)
| black, _, ⟨_, rfl, ha⟩ => exact ih ⟨_, rfl, (hb.balLeft ha).imp fun _ => ⟨⟩⟩ (fun.) ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n✝ : Nat path : Path α y✝ : RBNode α c₂✝ : RBColor n : Nat parent✝ : Path α v✝ : α c₁✝ c' : RBColor t : RBNode α ht : DelProp c' t n x✝ : Nat w✝ : RBColor ha : Balanced t w✝ x✝ hb : Balanced y✝ c₂✝ x✝ hp : Path.Balanced c₀ n₀ parent✝ black (x✝ + 1) ih : ∀ {c' : RBColor} {t : RBNode α}, DelProp c' t (x✝ + 1) → (black = black → c' ≠ red) → ∃ n, Balanced (del parent✝ t c') black n hc : c₁✝ = black → red ≠ red ⊢ ∃ n, Balanced (del (left black parent✝ v✝ y✝) t red) black n ** exact ih ⟨_, rfl, .redred ⟨⟩ ha hb⟩ (fun.) ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n✝ : Nat path : Path α y✝ : RBNode α c₂✝ : RBColor n : Nat parent✝ : Path α v✝ : α c₁✝ c' : RBColor t : RBNode α ht : DelProp c' t n w✝ : Nat ha : RedRed True t w✝ hb : Balanced y✝ c₂✝ (w✝ + 1) hp : Path.Balanced c₀ n₀ parent✝ black (w✝ + 1 + 1) ih : ∀ {c' : RBColor} {t : RBNode α}, DelProp c' t (w✝ + 1 + 1) → (black = black → c' ≠ red) → ∃ n, Balanced (del parent✝ t c') black n hc : c₁✝ = black → black ≠ red ⊢ ∃ n, Balanced (del (left black parent✝ v✝ y✝) t black) black n ** exact ih ⟨_, rfl, (hb.balLeft ha).imp fun _ => ⟨⟩⟩ (fun.) ** case blackR α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n✝ : Nat path : Path α x✝ : RBNode α c₁✝ : RBColor n : Nat v✝ : α parent✝ : Path α c₂✝ : RBColor ha : Balanced x✝ c₁✝ n hp : Path.Balanced c₀ n₀ parent✝ black (n + 1) ih : ∀ {c' : RBColor} {t : RBNode α}, DelProp c' t (n + 1) → (black = black → c' ≠ red) → ∃ n, Balanced (del parent✝ t c') black n c' : RBColor t : RBNode α ht : DelProp c' t n hc : c₂✝ = black → c' ≠ red ⊢ ∃ n, Balanced (del (right black x✝ v✝ parent✝) t c') black n ** match c', n, ht with
| red, _, ⟨_, hb⟩ => exact ih ⟨_, rfl, .redred ⟨⟩ ha hb⟩ (fun.)
| black, _, ⟨_, rfl, hb⟩ => exact ih ⟨_, rfl, (ha.balRight hb).imp fun _ => ⟨⟩⟩ (fun.) ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n✝ : Nat path : Path α x✝¹ : RBNode α c₁✝ : RBColor n : Nat v✝ : α parent✝ : Path α c₂✝ c' : RBColor t : RBNode α ht : DelProp c' t n x✝ : Nat w✝ : RBColor hb : Balanced t w✝ x✝ ha : Balanced x✝¹ c₁✝ x✝ hp : Path.Balanced c₀ n₀ parent✝ black (x✝ + 1) ih : ∀ {c' : RBColor} {t : RBNode α}, DelProp c' t (x✝ + 1) → (black = black → c' ≠ red) → ∃ n, Balanced (del parent✝ t c') black n hc : c₂✝ = black → red ≠ red ⊢ ∃ n, Balanced (del (right black x✝¹ v✝ parent✝) t red) black n ** exact ih ⟨_, rfl, .redred ⟨⟩ ha hb⟩ (fun.) ** α : Type u_1 c₀ : RBColor n₀ : Nat c : RBColor n✝ : Nat path : Path α x✝ : RBNode α c₁✝ : RBColor n : Nat v✝ : α parent✝ : Path α c₂✝ c' : RBColor t : RBNode α ht : DelProp c' t n w✝ : Nat hb : RedRed True t w✝ ha : Balanced x✝ c₁✝ (w✝ + 1) hp : Path.Balanced c₀ n₀ parent✝ black (w✝ + 1 + 1) ih : ∀ {c' : RBColor} {t : RBNode α}, DelProp c' t (w✝ + 1 + 1) → (black = black → c' ≠ red) → ∃ n, Balanced (del parent✝ t c') black n hc : c₂✝ = black → black ≠ red ⊢ ∃ n, Balanced (del (right black x✝ v✝ parent✝) t black) black n ** exact ih ⟨_, rfl, (ha.balRight hb).imp fun _ => ⟨⟩⟩ (fun.) ** Qed | |
Std.RBNode.Path.zoom_zoomed₁ ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e✝ : zoom cut t path = (t'✝, path'✝) path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ e : zoom cut (node c✝ l✝ v✝ r✝) path = (t', path') ⊢ OnRoot (fun x => cut x = Ordering.eq) t' ** revert e ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e : zoom cut t path = (t'✝, path'✝) path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ ⊢ zoom cut (node c✝ l✝ v✝ r✝) path = (t', path') → OnRoot (fun x => cut x = Ordering.eq) t' ** unfold zoom ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e : zoom cut t path = (t'✝, path'✝) path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ ⊢ (match cut v✝ with | Ordering.lt => zoom cut l✝ (left c✝ path v✝ r✝) | Ordering.gt => zoom cut r✝ (right c✝ l✝ v✝ path) | Ordering.eq => (node c✝ l✝ v✝ r✝, path)) = (t', path') → OnRoot (fun x => cut x = Ordering.eq) t' ** split ** case h_1 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e : zoom cut t path = (t'✝, path'✝) path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ x✝ : Ordering heq✝ : cut v✝ = Ordering.lt ⊢ zoom cut l✝ (left c✝ path v✝ r✝) = (t', path') → OnRoot (fun x => cut x = Ordering.eq) t' ** exact zoom_zoomed₁ ** case h_2 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e : zoom cut t path = (t'✝, path'✝) path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ x✝ : Ordering heq✝ : cut v✝ = Ordering.gt ⊢ zoom cut r✝ (right c✝ l✝ v✝ path) = (t', path') → OnRoot (fun x => cut x = Ordering.eq) t' ** exact zoom_zoomed₁ ** case h_3 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e : zoom cut t path = (t'✝, path'✝) path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ x✝ : Ordering heq✝ : cut v✝ = Ordering.eq ⊢ (node c✝ l✝ v✝ r✝, path) = (t', path') → OnRoot (fun x => cut x = Ordering.eq) t' ** next H => intro e; cases e; exact H ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e : zoom cut t path = (t'✝, path'✝) path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ x✝ : Ordering H : cut v✝ = Ordering.eq ⊢ (node c✝ l✝ v✝ r✝, path) = (t', path') → OnRoot (fun x => cut x = Ordering.eq) t' ** intro e ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e✝ : zoom cut t path = (t'✝, path'✝) path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ x✝ : Ordering H : cut v✝ = Ordering.eq e : (node c✝ l✝ v✝ r✝, path) = (t', path') ⊢ OnRoot (fun x => cut x = Ordering.eq) t' ** cases e ** case refl α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ e : zoom cut t path = (t', path') c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ x✝ : Ordering H : cut v✝ = Ordering.eq ⊢ OnRoot (fun x => cut x = Ordering.eq) (node c✝ l✝ v✝ r✝) ** exact H ** Qed | |
Std.RBNode.Path.zoom_zoomed₂ ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e✝ : zoom cut t path = (t'✝, path'✝) hp : Zoomed cut path path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ e : zoom cut (node c✝ l✝ v✝ r✝) path = (t', path') ⊢ Zoomed cut path' ** revert e ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e : zoom cut t path = (t'✝, path'✝) hp : Zoomed cut path path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ ⊢ zoom cut (node c✝ l✝ v✝ r✝) path = (t', path') → Zoomed cut path' ** unfold zoom ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e : zoom cut t path = (t'✝, path'✝) hp : Zoomed cut path path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ ⊢ (match cut v✝ with | Ordering.lt => zoom cut l✝ (left c✝ path v✝ r✝) | Ordering.gt => zoom cut r✝ (right c✝ l✝ v✝ path) | Ordering.eq => (node c✝ l✝ v✝ r✝, path)) = (t', path') → Zoomed cut path' ** split ** case h_1 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e : zoom cut t path = (t'✝, path'✝) hp : Zoomed cut path path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ x✝ : Ordering heq✝ : cut v✝ = Ordering.lt ⊢ zoom cut l✝ (left c✝ path v✝ r✝) = (t', path') → Zoomed cut path' ** next h => exact fun e => zoom_zoomed₂ e ⟨h, hp⟩ ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e : zoom cut t path = (t'✝, path'✝) hp : Zoomed cut path path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ x✝ : Ordering h : cut v✝ = Ordering.lt ⊢ zoom cut l✝ (left c✝ path v✝ r✝) = (t', path') → Zoomed cut path' ** exact fun e => zoom_zoomed₂ e ⟨h, hp⟩ ** case h_2 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e : zoom cut t path = (t'✝, path'✝) hp : Zoomed cut path path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ x✝ : Ordering heq✝ : cut v✝ = Ordering.gt ⊢ zoom cut r✝ (right c✝ l✝ v✝ path) = (t', path') → Zoomed cut path' ** next h => exact fun e => zoom_zoomed₂ e ⟨h, hp⟩ ** α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e : zoom cut t path = (t'✝, path'✝) hp : Zoomed cut path path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ x✝ : Ordering h : cut v✝ = Ordering.gt ⊢ zoom cut r✝ (right c✝ l✝ v✝ path) = (t', path') → Zoomed cut path' ** exact fun e => zoom_zoomed₂ e ⟨h, hp⟩ ** case h_3 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e : zoom cut t path = (t'✝, path'✝) hp : Zoomed cut path path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ x✝ : Ordering heq✝ : cut v✝ = Ordering.eq ⊢ (node c✝ l✝ v✝ r✝, path) = (t', path') → Zoomed cut path' ** intro e ** case h_3 α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t'✝ : RBNode α✝ path'✝ : Path α✝ e✝ : zoom cut t path = (t'✝, path'✝) hp : Zoomed cut path path' : Path α✝ t' : RBNode α✝ c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ x✝ : Ordering heq✝ : cut v✝ = Ordering.eq e : (node c✝ l✝ v✝ r✝, path) = (t', path') ⊢ Zoomed cut path' ** cases e ** case h_3.refl α✝ : Type u_1 cut : α✝ → Ordering t : RBNode α✝ path : Path α✝ t' : RBNode α✝ path' : Path α✝ e : zoom cut t path = (t', path') hp : Zoomed cut path c✝ : RBColor l✝ : RBNode α✝ v✝ : α✝ r✝ : RBNode α✝ x✝ : Ordering heq✝ : cut v✝ = Ordering.eq ⊢ Zoomed cut path ** exact hp ** Qed | |
Std.RBNode.Path.Ordered.fill ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor parent✝ : Path α v✝ : α r✝ x✝ : RBNode α ⊢ RBNode.Ordered cmp (fill (left c✝ parent✝ v✝ r✝) x✝) ↔ Ordered cmp (left c✝ parent✝ v✝ r✝) ∧ RBNode.Ordered cmp x✝ ∧ All (RootOrdered cmp (left c✝ parent✝ v✝ r✝)) x✝ ** simp [Ordered.fill, RBNode.Ordered, Ordered, RootOrdered, All_and] ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor parent✝ : Path α v✝ : α r✝ x✝ : RBNode α ⊢ Ordered cmp parent✝ ∧ (All (fun x => cmpLT cmp x v✝) x✝ ∧ All (fun x => cmpLT cmp v✝ x) r✝ ∧ RBNode.Ordered cmp x✝ ∧ RBNode.Ordered cmp r✝) ∧ RootOrdered cmp parent✝ v✝ ∧ All (RootOrdered cmp parent✝) x✝ ∧ All (RootOrdered cmp parent✝) r✝ ↔ (Ordered cmp parent✝ ∧ All (fun x => cmpLT cmp v✝ x) r✝ ∧ RootOrdered cmp parent✝ v✝ ∧ All (RootOrdered cmp parent✝) r✝ ∧ RBNode.Ordered cmp r✝) ∧ RBNode.Ordered cmp x✝ ∧ All (fun x => cmpLT cmp x v✝) x✝ ∧ All (fun a => RootOrdered cmp parent✝ a) x✝ ** exact ⟨
fun ⟨hp, ⟨ax, xb, ha, hb⟩, ⟨xp, ap, bp⟩⟩ => ⟨⟨hp, xb, xp, bp, hb⟩, ha, ⟨ax, ap⟩⟩,
fun ⟨⟨hp, xb, xp, bp, hb⟩, ha, ⟨ax, ap⟩⟩ => ⟨hp, ⟨ax, xb, ha, hb⟩, ⟨xp, ap, bp⟩⟩⟩ ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor l✝ : RBNode α v✝ : α parent✝ : Path α x✝ : RBNode α ⊢ RBNode.Ordered cmp (fill (right c✝ l✝ v✝ parent✝) x✝) ↔ Ordered cmp (right c✝ l✝ v✝ parent✝) ∧ RBNode.Ordered cmp x✝ ∧ All (RootOrdered cmp (right c✝ l✝ v✝ parent✝)) x✝ ** simp [Ordered.fill, RBNode.Ordered, Ordered, RootOrdered, All_and] ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor l✝ : RBNode α v✝ : α parent✝ : Path α x✝ : RBNode α ⊢ Ordered cmp parent✝ ∧ (All (fun x => cmpLT cmp x v✝) l✝ ∧ All (fun x => cmpLT cmp v✝ x) x✝ ∧ RBNode.Ordered cmp l✝ ∧ RBNode.Ordered cmp x✝) ∧ RootOrdered cmp parent✝ v✝ ∧ All (RootOrdered cmp parent✝) l✝ ∧ All (RootOrdered cmp parent✝) x✝ ↔ (Ordered cmp parent✝ ∧ All (fun x => cmpLT cmp x v✝) l✝ ∧ RootOrdered cmp parent✝ v✝ ∧ All (RootOrdered cmp parent✝) l✝ ∧ RBNode.Ordered cmp l✝) ∧ RBNode.Ordered cmp x✝ ∧ All (fun x => cmpLT cmp v✝ x) x✝ ∧ All (fun a => RootOrdered cmp parent✝ a) x✝ ** exact ⟨
fun ⟨hp, ⟨ax, xb, ha, hb⟩, ⟨xp, ap, bp⟩⟩ => ⟨⟨hp, ax, xp, ap, ha⟩, hb, ⟨xb, bp⟩⟩,
fun ⟨⟨hp, ax, xp, ap, ha⟩, hb, ⟨xb, bp⟩⟩ => ⟨hp, ⟨ax, xb, ha, hb⟩, ⟨xp, ap, bp⟩⟩⟩ ** Qed | |
Std.RBNode.Path.Ordered.ins ** α : Type u_1 cmp : α → α → Ordering parent : Path α x : α b a : RBNode α ha : RBNode.Ordered cmp a hp : Ordered cmp parent xb : All (fun x_1 => cmpLT cmp x x_1) b xp : RootOrdered cmp parent x bp : All (RootOrdered cmp parent) b hb : RBNode.Ordered cmp b H : All (RootOrdered cmp (left red parent x b)) a ⊢ RBNode.Ordered cmp (Path.ins (left red parent x b) a) ** unfold ins ** α : Type u_1 cmp : α → α → Ordering parent : Path α x : α b a : RBNode α ha : RBNode.Ordered cmp a hp : Ordered cmp parent xb : All (fun x_1 => cmpLT cmp x x_1) b xp : RootOrdered cmp parent x bp : All (RootOrdered cmp parent) b hb : RBNode.Ordered cmp b H : All (RootOrdered cmp (left red parent x b)) a ⊢ RBNode.Ordered cmp (Path.ins parent (node red a x b)) ** have ⟨ax, ap⟩ := All_and.1 H ** α : Type u_1 cmp : α → α → Ordering parent : Path α x : α b a : RBNode α ha : RBNode.Ordered cmp a hp : Ordered cmp parent xb : All (fun x_1 => cmpLT cmp x x_1) b xp : RootOrdered cmp parent x bp : All (RootOrdered cmp parent) b hb : RBNode.Ordered cmp b H : All (RootOrdered cmp (left red parent x b)) a ax : All (fun a => cmpLT cmp a x) a ap : All (fun a => RootOrdered cmp parent a) a ⊢ RBNode.Ordered cmp (Path.ins parent (node red a x b)) ** exact hp.ins ⟨ax, xb, ha, hb⟩ ⟨xp, ap, bp⟩ ** α : Type u_1 cmp : α → α → Ordering a : RBNode α x : α parent : Path α b : RBNode α hb : RBNode.Ordered cmp b hp : Ordered cmp parent ax : All (fun x_1 => cmpLT cmp x_1 x) a xp : RootOrdered cmp parent x ap : All (RootOrdered cmp parent) a ha : RBNode.Ordered cmp a H : All (RootOrdered cmp (right red a x parent)) b ⊢ RBNode.Ordered cmp (Path.ins (right red a x parent) b) ** unfold ins ** α : Type u_1 cmp : α → α → Ordering a : RBNode α x : α parent : Path α b : RBNode α hb : RBNode.Ordered cmp b hp : Ordered cmp parent ax : All (fun x_1 => cmpLT cmp x_1 x) a xp : RootOrdered cmp parent x ap : All (RootOrdered cmp parent) a ha : RBNode.Ordered cmp a H : All (RootOrdered cmp (right red a x parent)) b ⊢ RBNode.Ordered cmp (Path.ins parent (node red a x b)) ** have ⟨xb, bp⟩ := All_and.1 H ** α : Type u_1 cmp : α → α → Ordering a : RBNode α x : α parent : Path α b : RBNode α hb : RBNode.Ordered cmp b hp : Ordered cmp parent ax : All (fun x_1 => cmpLT cmp x_1 x) a xp : RootOrdered cmp parent x ap : All (RootOrdered cmp parent) a ha : RBNode.Ordered cmp a H : All (RootOrdered cmp (right red a x parent)) b xb : All (fun a => cmpLT cmp x a) b bp : All (fun a => RootOrdered cmp parent a) b ⊢ RBNode.Ordered cmp (Path.ins parent (node red a x b)) ** exact hp.ins ⟨ax, xb, ha, hb⟩ ⟨xp, ap, bp⟩ ** α : Type u_1 cmp : α → α → Ordering parent : Path α x : α b a : RBNode α ha : RBNode.Ordered cmp a hp : Ordered cmp parent xb : All (fun x_1 => cmpLT cmp x x_1) b xp : RootOrdered cmp parent x bp : All (RootOrdered cmp parent) b hb : RBNode.Ordered cmp b H : All (RootOrdered cmp (left black parent x b)) a ⊢ RBNode.Ordered cmp (Path.ins (left black parent x b) a) ** unfold ins ** α : Type u_1 cmp : α → α → Ordering parent : Path α x : α b a : RBNode α ha : RBNode.Ordered cmp a hp : Ordered cmp parent xb : All (fun x_1 => cmpLT cmp x x_1) b xp : RootOrdered cmp parent x bp : All (RootOrdered cmp parent) b hb : RBNode.Ordered cmp b H : All (RootOrdered cmp (left black parent x b)) a ⊢ RBNode.Ordered cmp (Path.ins parent (balance1 a x b)) ** have ⟨ax, ap⟩ := All_and.1 H ** α : Type u_1 cmp : α → α → Ordering parent : Path α x : α b a : RBNode α ha : RBNode.Ordered cmp a hp : Ordered cmp parent xb : All (fun x_1 => cmpLT cmp x x_1) b xp : RootOrdered cmp parent x bp : All (RootOrdered cmp parent) b hb : RBNode.Ordered cmp b H : All (RootOrdered cmp (left black parent x b)) a ax : All (fun a => cmpLT cmp a x) a ap : All (fun a => RootOrdered cmp parent a) a ⊢ RBNode.Ordered cmp (Path.ins parent (balance1 a x b)) ** exact hp.ins (ha.balance1 ax xb hb) (balance1_All.2 ⟨xp, ap, bp⟩) ** α : Type u_1 cmp : α → α → Ordering a : RBNode α x : α parent : Path α b : RBNode α hb : RBNode.Ordered cmp b hp : Ordered cmp parent ax : All (fun x_1 => cmpLT cmp x_1 x) a xp : RootOrdered cmp parent x ap : All (RootOrdered cmp parent) a ha : RBNode.Ordered cmp a H : All (RootOrdered cmp (right black a x parent)) b ⊢ RBNode.Ordered cmp (Path.ins (right black a x parent) b) ** unfold ins ** α : Type u_1 cmp : α → α → Ordering a : RBNode α x : α parent : Path α b : RBNode α hb : RBNode.Ordered cmp b hp : Ordered cmp parent ax : All (fun x_1 => cmpLT cmp x_1 x) a xp : RootOrdered cmp parent x ap : All (RootOrdered cmp parent) a ha : RBNode.Ordered cmp a H : All (RootOrdered cmp (right black a x parent)) b ⊢ RBNode.Ordered cmp (Path.ins parent (balance2 a x b)) ** have ⟨xb, bp⟩ := All_and.1 H ** α : Type u_1 cmp : α → α → Ordering a : RBNode α x : α parent : Path α b : RBNode α hb : RBNode.Ordered cmp b hp : Ordered cmp parent ax : All (fun x_1 => cmpLT cmp x_1 x) a xp : RootOrdered cmp parent x ap : All (RootOrdered cmp parent) a ha : RBNode.Ordered cmp a H : All (RootOrdered cmp (right black a x parent)) b xb : All (fun a => cmpLT cmp x a) b bp : All (fun a => RootOrdered cmp parent a) b ⊢ RBNode.Ordered cmp (Path.ins parent (balance2 a x b)) ** exact hp.ins (ha.balance2 ax xb hb) (balance2_All.2 ⟨xp, ap, bp⟩) ** Qed | |
Std.RBNode.Path.Ordered.del ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor parent : Path α x : α b a : RBNode α ha : RBNode.Ordered cmp a hp : Ordered cmp parent xb : All (fun x_1 => cmpLT cmp x x_1) b xp : RootOrdered cmp parent x bp : All (RootOrdered cmp parent) b hb : RBNode.Ordered cmp b H : All (RootOrdered cmp (left c✝ parent x b)) a ⊢ RBNode.Ordered cmp (Path.del (left c✝ parent x b) a red) ** unfold del ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor parent : Path α x : α b a : RBNode α ha : RBNode.Ordered cmp a hp : Ordered cmp parent xb : All (fun x_1 => cmpLT cmp x x_1) b xp : RootOrdered cmp parent x bp : All (RootOrdered cmp parent) b hb : RBNode.Ordered cmp b H : All (RootOrdered cmp (left c✝ parent x b)) a ⊢ RBNode.Ordered cmp (Path.del parent (node red a x b) c✝) ** have ⟨ax, ap⟩ := All_and.1 H ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor parent : Path α x : α b a : RBNode α ha : RBNode.Ordered cmp a hp : Ordered cmp parent xb : All (fun x_1 => cmpLT cmp x x_1) b xp : RootOrdered cmp parent x bp : All (RootOrdered cmp parent) b hb : RBNode.Ordered cmp b H : All (RootOrdered cmp (left c✝ parent x b)) a ax : All (fun a => cmpLT cmp a x) a ap : All (fun a => RootOrdered cmp parent a) a ⊢ RBNode.Ordered cmp (Path.del parent (node red a x b) c✝) ** exact hp.del ⟨ax, xb, ha, hb⟩ ⟨xp, ap, bp⟩ ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor a : RBNode α x : α parent : Path α b : RBNode α hb : RBNode.Ordered cmp b hp : Ordered cmp parent ax : All (fun x_1 => cmpLT cmp x_1 x) a xp : RootOrdered cmp parent x ap : All (RootOrdered cmp parent) a ha : RBNode.Ordered cmp a H : All (RootOrdered cmp (right c✝ a x parent)) b ⊢ RBNode.Ordered cmp (Path.del (right c✝ a x parent) b red) ** unfold del ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor a : RBNode α x : α parent : Path α b : RBNode α hb : RBNode.Ordered cmp b hp : Ordered cmp parent ax : All (fun x_1 => cmpLT cmp x_1 x) a xp : RootOrdered cmp parent x ap : All (RootOrdered cmp parent) a ha : RBNode.Ordered cmp a H : All (RootOrdered cmp (right c✝ a x parent)) b ⊢ RBNode.Ordered cmp (Path.del parent (node red a x b) c✝) ** have ⟨xb, bp⟩ := All_and.1 H ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor a : RBNode α x : α parent : Path α b : RBNode α hb : RBNode.Ordered cmp b hp : Ordered cmp parent ax : All (fun x_1 => cmpLT cmp x_1 x) a xp : RootOrdered cmp parent x ap : All (RootOrdered cmp parent) a ha : RBNode.Ordered cmp a H : All (RootOrdered cmp (right c✝ a x parent)) b xb : All (fun a => cmpLT cmp x a) b bp : All (fun a => RootOrdered cmp parent a) b ⊢ RBNode.Ordered cmp (Path.del parent (node red a x b) c✝) ** exact hp.del ⟨ax, xb, ha, hb⟩ ⟨xp, ap, bp⟩ ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor parent : Path α x : α b a : RBNode α ha : RBNode.Ordered cmp a hp : Ordered cmp parent xb : All (fun x_1 => cmpLT cmp x x_1) b xp : RootOrdered cmp parent x bp : All (RootOrdered cmp parent) b hb : RBNode.Ordered cmp b H : All (RootOrdered cmp (left c✝ parent x b)) a ⊢ RBNode.Ordered cmp (Path.del (left c✝ parent x b) a black) ** unfold del ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor parent : Path α x : α b a : RBNode α ha : RBNode.Ordered cmp a hp : Ordered cmp parent xb : All (fun x_1 => cmpLT cmp x x_1) b xp : RootOrdered cmp parent x bp : All (RootOrdered cmp parent) b hb : RBNode.Ordered cmp b H : All (RootOrdered cmp (left c✝ parent x b)) a ⊢ RBNode.Ordered cmp (Path.del parent (balLeft a x b) c✝) ** have ⟨ax, ap⟩ := All_and.1 H ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor parent : Path α x : α b a : RBNode α ha : RBNode.Ordered cmp a hp : Ordered cmp parent xb : All (fun x_1 => cmpLT cmp x x_1) b xp : RootOrdered cmp parent x bp : All (RootOrdered cmp parent) b hb : RBNode.Ordered cmp b H : All (RootOrdered cmp (left c✝ parent x b)) a ax : All (fun a => cmpLT cmp a x) a ap : All (fun a => RootOrdered cmp parent a) a ⊢ RBNode.Ordered cmp (Path.del parent (balLeft a x b) c✝) ** exact hp.del (ha.balLeft ax xb hb) (ap.balLeft xp bp) ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor a : RBNode α x : α parent : Path α b : RBNode α hb : RBNode.Ordered cmp b hp : Ordered cmp parent ax : All (fun x_1 => cmpLT cmp x_1 x) a xp : RootOrdered cmp parent x ap : All (RootOrdered cmp parent) a ha : RBNode.Ordered cmp a H : All (RootOrdered cmp (right c✝ a x parent)) b ⊢ RBNode.Ordered cmp (Path.del (right c✝ a x parent) b black) ** unfold del ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor a : RBNode α x : α parent : Path α b : RBNode α hb : RBNode.Ordered cmp b hp : Ordered cmp parent ax : All (fun x_1 => cmpLT cmp x_1 x) a xp : RootOrdered cmp parent x ap : All (RootOrdered cmp parent) a ha : RBNode.Ordered cmp a H : All (RootOrdered cmp (right c✝ a x parent)) b ⊢ RBNode.Ordered cmp (Path.del parent (balRight a x b) c✝) ** have ⟨xb, bp⟩ := All_and.1 H ** α : Type u_1 cmp : α → α → Ordering c✝ : RBColor a : RBNode α x : α parent : Path α b : RBNode α hb : RBNode.Ordered cmp b hp : Ordered cmp parent ax : All (fun x_1 => cmpLT cmp x_1 x) a xp : RootOrdered cmp parent x ap : All (RootOrdered cmp parent) a ha : RBNode.Ordered cmp a H : All (RootOrdered cmp (right c✝ a x parent)) b xb : All (fun a => cmpLT cmp x a) b bp : All (fun a => RootOrdered cmp parent a) b ⊢ RBNode.Ordered cmp (Path.del parent (balRight a x b) c✝) ** exact hp.del (ha.balRight ax xb hb) (ap.balRight xp bp) ** Qed | |
Std.RBNode.Ordered.alter ** α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t ⊢ Ordered cmp (alter cut f t) ** simp [alter] ** α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t ⊢ Ordered cmp (match RBNode.zoom cut t Path.root with | (nil, path) => match f none with | none => t | some y => Path.insertNew path y | (node c a x b, path) => match f (some x) with | none => Path.del path (append a b) c | some y => Path.fill path (node c a y b)) ** split ** α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t x✝ : RBNode α × Path α path : Path α eq : RBNode.zoom cut t Path.root = (nil, path) ⊢ Ordered cmp (match f none with | none => t | some y => Path.insertNew path y) ** have ⟨_, hp, _, _⟩ := h.zoom eq ** α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t x✝ : RBNode α × Path α path : Path α eq : RBNode.zoom cut t Path.root = (nil, path) left✝¹ : Ordered cmp nil hp : Path.Ordered cmp path left✝ : All (Path.RootOrdered cmp path) nil right✝ : Path.Zoomed cut path ⊢ Ordered cmp (match f none with | none => t | some y => Path.insertNew path y) ** split ** case h_1 α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t x✝¹ : RBNode α × Path α path : Path α eq : RBNode.zoom cut t Path.root = (nil, path) left✝¹ : Ordered cmp nil hp : Path.Ordered cmp path left✝ : All (Path.RootOrdered cmp path) nil right✝ : Path.Zoomed cut path x✝ : Option α heq✝ : f none = none ⊢ Ordered cmp t ** exact h ** case h_2 α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t x✝¹ : RBNode α × Path α path : Path α eq : RBNode.zoom cut t Path.root = (nil, path) left✝¹ : Ordered cmp nil hp : Path.Ordered cmp path left✝ : All (Path.RootOrdered cmp path) nil right✝ : Path.Zoomed cut path x✝ : Option α y✝ : α heq✝ : f none = some y✝ ⊢ Ordered cmp (Path.insertNew path y✝) ** next hf => exact hp.insertNew (H eq hf).1 ** α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t x✝¹ : RBNode α × Path α path : Path α eq : RBNode.zoom cut t Path.root = (nil, path) left✝¹ : Ordered cmp nil hp : Path.Ordered cmp path left✝ : All (Path.RootOrdered cmp path) nil right✝ : Path.Zoomed cut path x✝ : Option α y✝ : α hf : f none = some y✝ ⊢ Ordered cmp (Path.insertNew path y✝) ** exact hp.insertNew (H eq hf).1 ** α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t x✝¹ : RBNode α × Path α c✝ : RBColor a✝ : RBNode α x✝ : α b✝ : RBNode α path : Path α eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝ b✝, path) ⊢ Ordered cmp (match f (some x✝) with | none => Path.del path (append a✝ b✝) c✝ | some y => Path.fill path (node c✝ a✝ y b✝)) ** have ⟨⟨ax, xb, ha, hb⟩, hp, ⟨_, ap, bp⟩, _⟩ := h.zoom eq ** α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t x✝¹ : RBNode α × Path α c✝ : RBColor a✝ : RBNode α x✝ : α b✝ : RBNode α path : Path α eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝ b✝, path) ax : All (fun x => cmpLT cmp x x✝) a✝ xb : All (fun x => cmpLT cmp x✝ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ hp : Path.Ordered cmp path left✝ : Path.RootOrdered cmp path x✝ ap : All (Path.RootOrdered cmp path) a✝ bp : All (Path.RootOrdered cmp path) b✝ right✝ : Path.Zoomed cut path ⊢ Ordered cmp (match f (some x✝) with | none => Path.del path (append a✝ b✝) c✝ | some y => Path.fill path (node c✝ a✝ y b✝)) ** split ** case h_1 α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t x✝² : RBNode α × Path α c✝ : RBColor a✝ : RBNode α x✝¹ : α b✝ : RBNode α path : Path α eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝¹ b✝, path) ax : All (fun x => cmpLT cmp x x✝¹) a✝ xb : All (fun x => cmpLT cmp x✝¹ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ hp : Path.Ordered cmp path left✝ : Path.RootOrdered cmp path x✝¹ ap : All (Path.RootOrdered cmp path) a✝ bp : All (Path.RootOrdered cmp path) b✝ right✝ : Path.Zoomed cut path x✝ : Option α heq✝ : f (some x✝¹) = none ⊢ Ordered cmp (Path.del path (append a✝ b✝) c✝) ** exact hp.del (ha.append ax xb hb) (ap.append bp) ** case h_2 α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t x✝² : RBNode α × Path α c✝ : RBColor a✝ : RBNode α x✝¹ : α b✝ : RBNode α path : Path α eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝¹ b✝, path) ax : All (fun x => cmpLT cmp x x✝¹) a✝ xb : All (fun x => cmpLT cmp x✝¹ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ hp : Path.Ordered cmp path left✝ : Path.RootOrdered cmp path x✝¹ ap : All (Path.RootOrdered cmp path) a✝ bp : All (Path.RootOrdered cmp path) b✝ right✝ : Path.Zoomed cut path x✝ : Option α y✝ : α heq✝ : f (some x✝¹) = some y✝ ⊢ Ordered cmp (Path.fill path (node c✝ a✝ y✝ b✝)) ** next hf =>
have ⟨yp, xy⟩ := H eq hf
apply Path.Ordered.fill.2
exact ⟨hp, ⟨ax.imp xy.lt_congr_right.2, xb.imp xy.lt_congr_left.2, ha, hb⟩, yp, ap, bp⟩ ** α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t x✝² : RBNode α × Path α c✝ : RBColor a✝ : RBNode α x✝¹ : α b✝ : RBNode α path : Path α eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝¹ b✝, path) ax : All (fun x => cmpLT cmp x x✝¹) a✝ xb : All (fun x => cmpLT cmp x✝¹ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ hp : Path.Ordered cmp path left✝ : Path.RootOrdered cmp path x✝¹ ap : All (Path.RootOrdered cmp path) a✝ bp : All (Path.RootOrdered cmp path) b✝ right✝ : Path.Zoomed cut path x✝ : Option α y✝ : α hf : f (some x✝¹) = some y✝ ⊢ Ordered cmp (Path.fill path (node c✝ a✝ y✝ b✝)) ** have ⟨yp, xy⟩ := H eq hf ** α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t x✝² : RBNode α × Path α c✝ : RBColor a✝ : RBNode α x✝¹ : α b✝ : RBNode α path : Path α eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝¹ b✝, path) ax : All (fun x => cmpLT cmp x x✝¹) a✝ xb : All (fun x => cmpLT cmp x✝¹ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ hp : Path.Ordered cmp path left✝ : Path.RootOrdered cmp path x✝¹ ap : All (Path.RootOrdered cmp path) a✝ bp : All (Path.RootOrdered cmp path) b✝ right✝ : Path.Zoomed cut path x✝ : Option α y✝ : α hf : f (some x✝¹) = some y✝ yp : Path.RootOrdered cmp path y✝ xy : OnRoot (cmpEq cmp y✝) (node c✝ a✝ x✝¹ b✝) ⊢ Ordered cmp (Path.fill path (node c✝ a✝ y✝ b✝)) ** apply Path.Ordered.fill.2 ** α : Type u_1 cut : α → Ordering f : Option α → Option α cmp : α → α → Ordering t : RBNode α H : ∀ {x : α} {t' : RBNode α} {p : Path α}, RBNode.zoom cut t Path.root = (t', p) → f (root? t') = some x → Path.RootOrdered cmp p x ∧ OnRoot (cmpEq cmp x) t' h : Ordered cmp t x✝² : RBNode α × Path α c✝ : RBColor a✝ : RBNode α x✝¹ : α b✝ : RBNode α path : Path α eq : RBNode.zoom cut t Path.root = (node c✝ a✝ x✝¹ b✝, path) ax : All (fun x => cmpLT cmp x x✝¹) a✝ xb : All (fun x => cmpLT cmp x✝¹ x) b✝ ha : Ordered cmp a✝ hb : Ordered cmp b✝ hp : Path.Ordered cmp path left✝ : Path.RootOrdered cmp path x✝¹ ap : All (Path.RootOrdered cmp path) a✝ bp : All (Path.RootOrdered cmp path) b✝ right✝ : Path.Zoomed cut path x✝ : Option α y✝ : α hf : f (some x✝¹) = some y✝ yp : Path.RootOrdered cmp path y✝ xy : OnRoot (cmpEq cmp y✝) (node c✝ a✝ x✝¹ b✝) ⊢ Path.Ordered cmp path ∧ Ordered cmp (node c✝ a✝ y✝ b✝) ∧ All (Path.RootOrdered cmp path) (node c✝ a✝ y✝ b✝) ** exact ⟨hp, ⟨ax.imp xy.lt_congr_right.2, xb.imp xy.lt_congr_left.2, ha, hb⟩, yp, ap, bp⟩ ** Qed | |
Std.RBNode.Balanced.alter ** α : Type u_1 c : RBColor n : Nat cut : α → Ordering f : Option α → Option α t : RBNode α h : Balanced t c n ⊢ ∃ c n, Balanced (alter cut f t) c n ** simp [alter] ** α : Type u_1 c : RBColor n : Nat cut : α → Ordering f : Option α → Option α t : RBNode α h : Balanced t c n ⊢ ∃ c n, Balanced (match zoom cut t Path.root with | (nil, path) => match f none with | none => t | some y => Path.insertNew path y | (node c a x b, path) => match f (some x) with | none => Path.del path (append a b) c | some y => Path.fill path (node c a y b)) c n ** split ** α : Type u_1 c : RBColor n : Nat cut : α → Ordering f : Option α → Option α t : RBNode α h : Balanced t c n x✝ : RBNode α × Path α path : Path α eq : zoom cut t Path.root = (nil, path) ⊢ ∃ c n, Balanced (match f none with | none => t | some y => Path.insertNew path y) c n ** split ** case h_1 α : Type u_1 c : RBColor n : Nat cut : α → Ordering f : Option α → Option α t : RBNode α h : Balanced t c n x✝¹ : RBNode α × Path α path : Path α eq : zoom cut t Path.root = (nil, path) x✝ : Option α heq✝ : f none = none ⊢ ∃ c n, Balanced t c n ** exact ⟨_, _, h⟩ ** case h_2 α : Type u_1 c : RBColor n : Nat cut : α → Ordering f : Option α → Option α t : RBNode α h : Balanced t c n x✝¹ : RBNode α × Path α path : Path α eq : zoom cut t Path.root = (nil, path) x✝ : Option α y✝ : α heq✝ : f none = some y✝ ⊢ ∃ c n, Balanced (Path.insertNew path y✝) c n ** have ⟨_, _, .nil, h⟩ := h.zoom .root eq ** case h_2 α : Type u_1 c : RBColor n : Nat cut : α → Ordering f : Option α → Option α t : RBNode α h✝ : Balanced t c n x✝¹ : RBNode α × Path α path : Path α eq : zoom cut t Path.root = (nil, path) x✝ : Option α y✝ : α heq✝ : f none = some y✝ h : Path.Balanced c n path black 0 ⊢ ∃ c n, Balanced (Path.insertNew path y✝) c n ** exact ⟨_, h.insertNew⟩ ** α : Type u_1 c : RBColor n : Nat cut : α → Ordering f : Option α → Option α t : RBNode α h : Balanced t c n x✝¹ : RBNode α × Path α c✝ : RBColor a✝ : RBNode α x✝ : α b✝ : RBNode α path : Path α eq : zoom cut t Path.root = (node c✝ a✝ x✝ b✝, path) ⊢ ∃ c n, Balanced (match f (some x✝) with | none => Path.del path (append a✝ b✝) c✝ | some y => Path.fill path (node c✝ a✝ y b✝)) c n ** have ⟨_, _, h, hp⟩ := h.zoom .root eq ** α : Type u_1 c : RBColor n : Nat cut : α → Ordering f : Option α → Option α t : RBNode α h✝ : Balanced t c n x✝¹ : RBNode α × Path α c✝ : RBColor a✝ : RBNode α x✝ : α b✝ : RBNode α path : Path α eq : zoom cut t Path.root = (node c✝ a✝ x✝ b✝, path) w✝¹ : RBColor w✝ : Nat h : Balanced (node c✝ a✝ x✝ b✝) w✝¹ w✝ hp : Path.Balanced c n path w✝¹ w✝ ⊢ ∃ c n, Balanced (match f (some x✝) with | none => Path.del path (append a✝ b✝) c✝ | some y => Path.fill path (node c✝ a✝ y b✝)) c n ** split ** α : Type u_1 c : RBColor n : Nat cut : α → Ordering f : Option α → Option α t : RBNode α h✝ : Balanced t c n x✝² : RBNode α × Path α c✝ : RBColor a✝ : RBNode α x✝¹ : α b✝ : RBNode α path : Path α w✝¹ : RBColor w✝ : Nat h : Balanced (node c✝ a✝ x✝¹ b✝) w✝¹ w✝ x✝ : Option α heq✝ : f (some x✝¹) = none c₁✝ : RBColor n✝ : Nat c₂✝ : RBColor ha : Balanced a✝ c₁✝ n✝ hb : Balanced b✝ c₂✝ n✝ eq : zoom cut t Path.root = (node black a✝ x✝¹ b✝, path) hp : Path.Balanced c n path black (n✝ + 1) ⊢ ∃ c n, Balanced (Path.del path (append a✝ b✝) black) c n ** exact ⟨_, hp.del ⟨_, rfl, (ha.append hb).imp fun _ => ⟨⟩⟩ (fun.)⟩ ** case h_2 α : Type u_1 c : RBColor n : Nat cut : α → Ordering f : Option α → Option α t : RBNode α h✝ : Balanced t c n x✝² : RBNode α × Path α c✝ : RBColor a✝ : RBNode α x✝¹ : α b✝ : RBNode α path : Path α eq : zoom cut t Path.root = (node c✝ a✝ x✝¹ b✝, path) w✝¹ : RBColor w✝ : Nat h : Balanced (node c✝ a✝ x✝¹ b✝) w✝¹ w✝ hp : Path.Balanced c n path w✝¹ w✝ x✝ : Option α y✝ : α heq✝ : f (some x✝¹) = some y✝ ⊢ ∃ c n, Balanced (Path.fill path (node c✝ a✝ y✝ b✝)) c n ** match h with
| .red ha hb => exact ⟨_, _, hp.fill (.red ha hb)⟩
| .black ha hb => exact ⟨_, _, hp.fill (.black ha hb)⟩ ** α : Type u_1 c : RBColor n : Nat cut : α → Ordering f : Option α → Option α t : RBNode α h✝ : Balanced t c n x✝³ : RBNode α × Path α c✝ : RBColor a✝ : RBNode α x✝² : α b✝ : RBNode α path : Path α w✝¹ : RBColor w✝ : Nat h : Balanced (node c✝ a✝ x✝² b✝) w✝¹ w✝ x✝¹ : Option α y✝ : α heq✝ : f (some x✝²) = some y✝ x✝ : Nat ha : Balanced a✝ black x✝ hb : Balanced b✝ black x✝ eq : zoom cut t Path.root = (node red a✝ x✝² b✝, path) hp : Path.Balanced c n path red x✝ ⊢ ∃ c n, Balanced (Path.fill path (node red a✝ y✝ b✝)) c n ** exact ⟨_, _, hp.fill (.red ha hb)⟩ ** α : Type u_1 c : RBColor n : Nat cut : α → Ordering f : Option α → Option α t : RBNode α h✝ : Balanced t c n x✝² : RBNode α × Path α c✝ : RBColor a✝ : RBNode α x✝¹ : α b✝ : RBNode α path : Path α w✝¹ : RBColor w✝ : Nat h : Balanced (node c✝ a✝ x✝¹ b✝) w✝¹ w✝ x✝ : Option α y✝ : α heq✝ : f (some x✝¹) = some y✝ c₁✝ : RBColor n✝ : Nat c₂✝ : RBColor ha : Balanced a✝ c₁✝ n✝ hb : Balanced b✝ c₂✝ n✝ eq : zoom cut t Path.root = (node black a✝ x✝¹ b✝, path) hp : Path.Balanced c n path black (n✝ + 1) ⊢ ∃ c n, Balanced (Path.fill path (node black a✝ y✝ b✝)) c n ** exact ⟨_, _, hp.fill (.black ha hb)⟩ ** Qed | |
Std.RBNode.modify_eq_alter ** α : Type u_1 cut : α → Ordering f : α → α t : RBNode α ⊢ modify cut f t = alter cut (Option.map f) t ** simp [modify, alter] ** α : Type u_1 cut : α → Ordering f : α → α t : RBNode α ⊢ (match zoom cut t Path.root with | (nil, snd) => t | (node c a x b, path) => Path.fill path (node c a (f x) b)) = match zoom cut t Path.root with | (nil, path) => match Option.map f none with | none => t | some y => Path.insertNew path y | (node c a x b, path) => match Option.map f (some x) with | none => Path.del path (append a b) c | some y => Path.fill path (node c a y b) ** split <;> simp [Option.map] ** Qed | |
Std.RBNode.Ordered.modify ** α : Type u_1 cut : α → Ordering cmp : α → α → Ordering f : α → α t : RBNode α H : OnRoot (fun x => cmpEq cmp (f x) x) (RBNode.zoom cut t Path.root).fst h : Ordered cmp t c✝ : RBColor l✝ : RBNode α v✝ : α r✝ : RBNode α x✝ : Path α eq : RBNode.zoom cut t Path.root = (node c✝ l✝ v✝ r✝, x✝) ⊢ Path.RootOrdered cmp x✝ (f v✝) ∧ OnRoot (cmpEq cmp (f v✝)) (node c✝ l✝ v✝ r✝) ** rw [eq] at H ** α : Type u_1 cut : α → Ordering cmp : α → α → Ordering f : α → α t : RBNode α h : Ordered cmp t c✝ : RBColor l✝ : RBNode α v✝ : α r✝ : RBNode α x✝ : Path α H : OnRoot (fun x => cmpEq cmp (f x) x) (node c✝ l✝ v✝ r✝, x✝).fst eq : RBNode.zoom cut t Path.root = (node c✝ l✝ v✝ r✝, x✝) ⊢ Path.RootOrdered cmp x✝ (f v✝) ∧ OnRoot (cmpEq cmp (f v✝)) (node c✝ l✝ v✝ r✝) ** exact ⟨H.RootOrdered_congr.2 (h.zoom eq).2.2.1.1, H⟩ ** Qed | |
Std.HashMap.Imp.Buckets.exists_of_update ** α : Type u_1 β : Type u_2 self : Buckets α β i : USize d : AssocList α β h : USize.toNat i < Array.size self.val ⊢ ∃ l₁ l₂, self.val.data = l₁ ++ self.val[i] :: l₂ ∧ List.length l₁ = USize.toNat i ∧ (update self i d h).val.data = l₁ ++ d :: l₂ ** simp [Array.getElem_eq_data_get] ** α : Type u_1 β : Type u_2 self : Buckets α β i : USize d : AssocList α β h : USize.toNat i < Array.size self.val ⊢ ∃ l₁ l₂, self.val.data = l₁ ++ List.get self.val.data { val := USize.toNat i, isLt := h } :: l₂ ∧ List.length l₁ = USize.toNat i ∧ (update self i d h).val.data = l₁ ++ d :: l₂ ** exact List.exists_of_set' h ** Qed | |
Std.HashMap.Imp.Buckets.mk_size ** α : Type u_1 β : Type u_2 n : Nat h : 0 < n ⊢ size (mk n) = 0 ** simp [Buckets.size_eq, Buckets.mk, mkArray] ** α : Type u_1 β : Type u_2 n : Nat h : 0 < n ⊢ Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.replicate n AssocList.nil)) = 0 ** clear h ** α : Type u_1 β : Type u_2 n : Nat ⊢ Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.replicate n AssocList.nil)) = 0 ** induction n <;> simp [*] ** Qed | |
Std.HashMap.Imp.Buckets.WF.mk' ** α : Type u_1 β : Type u_2 n : Nat inst✝¹ : BEq α inst✝ : Hashable α h : 0 < n ⊢ WF (Buckets.mk n) ** refine ⟨fun _ h => ?_, fun i h => ?_⟩ ** case refine_1 α : Type u_1 β : Type u_2 n : Nat inst✝³ : BEq α inst✝² : Hashable α h✝ : 0 < n inst✝¹ : LawfulHashable α inst✝ : PartialEquivBEq α x✝ : AssocList α β h : x✝ ∈ (Buckets.mk n).val.data ⊢ List.Pairwise (fun a b => ¬(a.fst == b.fst) = true) (AssocList.toList x✝) ** simp [Buckets.mk, empty', mkArray, List.mem_replicate] at h ** case refine_1 α : Type u_1 β : Type u_2 n : Nat inst✝³ : BEq α inst✝² : Hashable α h✝ : 0 < n inst✝¹ : LawfulHashable α inst✝ : PartialEquivBEq α x✝ : AssocList α β h : ¬n = 0 ∧ x✝ = AssocList.nil ⊢ List.Pairwise (fun a b => ¬(a.fst == b.fst) = true) (AssocList.toList x✝) ** simp [h, List.Pairwise.nil] ** case refine_2 α : Type u_1 β : Type u_2 n : Nat inst✝¹ : BEq α inst✝ : Hashable α h✝ : 0 < n i : Nat h : i < Array.size (Buckets.mk n).val ⊢ AssocList.All (fun k x => USize.toNat (UInt64.toUSize (hash k) % Array.size (Buckets.mk n).val) = i) (Buckets.mk n).val[i] ** simp [Buckets.mk, empty', mkArray, Array.getElem_eq_data_get, AssocList.All] ** Qed | |
Std.HashMap.Imp.reinsertAux_size ** α : Type u_1 β : Type u_2 inst✝ : Hashable α data : Buckets α β a : α b : β ⊢ Buckets.size (reinsertAux data a b) = Nat.succ (Buckets.size data) ** simp [Buckets.size_eq, reinsertAux] ** α : Type u_1 β : Type u_2 inst✝ : Hashable α data : Buckets α β a : α b : β ⊢ Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (Buckets.update data (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val (AssocList.cons a b data.val[USize.toNat (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val]) (_ : USize.toNat (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val < Array.size data.val)).val.data) = Nat.succ (Nat.sum (List.map (fun x => List.length (AssocList.toList x)) data.val.data)) ** refine have ⟨l₁, l₂, h₁, _, eq⟩ := Buckets.exists_of_update ..; eq ▸ ?_ ** α : Type u_1 β : Type u_2 inst✝ : Hashable α data : Buckets α β a : α b : β l₁ l₂ : List (AssocList α β) h₁ : data.val.data = l₁ ++ data.val[(mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val] :: l₂ left✝ : List.length l₁ = USize.toNat (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val eq : (Buckets.update data (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val (AssocList.cons a b data.val[USize.toNat (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val]) (_ : USize.toNat (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val < Array.size data.val)).val.data = l₁ ++ AssocList.cons a b data.val[USize.toNat (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val] :: l₂ ⊢ Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (l₁ ++ AssocList.cons a b data.val[USize.toNat (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val] :: l₂)) = Nat.succ (Nat.sum (List.map (fun x => List.length (AssocList.toList x)) data.val.data)) ** simp [h₁, Nat.succ_add] ** α : Type u_1 β : Type u_2 inst✝ : Hashable α data : Buckets α β a : α b : β l₁ l₂ : List (AssocList α β) h₁ : data.val.data = l₁ ++ data.val[(mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val] :: l₂ left✝ : List.length l₁ = USize.toNat (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val eq : (Buckets.update data (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val (AssocList.cons a b data.val[USize.toNat (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val]) (_ : USize.toNat (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val < Array.size data.val)).val.data = l₁ ++ AssocList.cons a b data.val[USize.toNat (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val] :: l₂ ⊢ Nat.sum (List.map (fun x => List.length (AssocList.toList x)) l₁) + Nat.succ (List.length (AssocList.toList data.val[USize.toNat (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val]) + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) l₂)) = Nat.succ (Nat.sum (List.map (fun x => List.length (AssocList.toList x)) l₁) + (List.length (AssocList.toList data.val[USize.toNat (mkIdx (_ : 0 < Array.size data.val) (UInt64.toUSize (hash a))).val]) + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) l₂))) ** rfl ** Qed | |
Std.HashMap.Imp.mem_replaceF ** case nil α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β ⊢ x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) [] → x.fst = k ∨ x ∈ [] ** exact .inr ** case cons α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l ⊢ x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) (a :: l) → x.fst = k ∨ x ∈ a :: l ** simp ** case cons α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l ⊢ (x ∈ match bif p a then some (k, f a) else none with | none => a :: List.replaceF (fun a => bif p a then some (k, f a) else none) l | some a => a :: l) → x.fst = k ∨ x = a ∨ x ∈ l ** generalize e : cond .. = z ** case cons α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l z : Option (α × β) e : (bif p a then some (k, f a) else none) = z ⊢ (x ∈ match z with | none => a :: List.replaceF (fun a => bif p a then some (k, f a) else none) l | some a => a :: l) → x.fst = k ∨ x = a ∨ x ∈ l ** revert e ** case cons α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l z : Option (α × β) ⊢ (bif p a then some (k, f a) else none) = z → (x ∈ match z with | none => a :: List.replaceF (fun a => bif p a then some (k, f a) else none) l | some a => a :: l) → x.fst = k ∨ x = a ∨ x ∈ l ** unfold cond ** case cons α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l z : Option (α × β) ⊢ (match p a with | true => some (k, f a) | false => none) = z → (x ∈ match z with | none => a :: List.replaceF (fun a => match p a with | true => some (k, f a) | false => none) l | some a => a :: l) → x.fst = k ∨ x = a ∨ x ∈ l ** split <;> (intro h; subst h; simp) ** case cons.h_2 α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l z : Option (α × β) c✝ : Bool heq✝ : p a = false ⊢ none = z → (x ∈ match z with | none => a :: List.replaceF (fun a => match p a with | true => some (k, f a) | false => none) l | some a => a :: l) → x.fst = k ∨ x = a ∨ x ∈ l ** intro h ** case cons.h_2 α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l z : Option (α × β) c✝ : Bool heq✝ : p a = false h : none = z ⊢ (x ∈ match z with | none => a :: List.replaceF (fun a => match p a with | true => some (k, f a) | false => none) l | some a => a :: l) → x.fst = k ∨ x = a ∨ x ∈ l ** subst h ** case cons.h_2 α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l c✝ : Bool heq✝ : p a = false ⊢ (x ∈ match none with | none => a :: List.replaceF (fun a => match p a with | true => some (k, f a) | false => none) l | some a => a :: l) → x.fst = k ∨ x = a ∨ x ∈ l ** simp ** case cons.h_1 α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l c✝ : Bool heq✝ : p a = true ⊢ x = (k, f a) ∨ x ∈ l → x.fst = k ∨ x = a ∨ x ∈ l ** intro
| .inl eq => exact eq ▸ .inl rfl
| .inr h => exact .inr (.inr h) ** α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l c✝ : Bool heq✝ : p a = true x✝ : x = (k, f a) ∨ x ∈ l eq : x = (k, f a) ⊢ x.fst = k ∨ x = a ∨ x ∈ l ** exact eq ▸ .inl rfl ** α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l c✝ : Bool heq✝ : p a = true x✝ : x = (k, f a) ∨ x ∈ l h : x ∈ l ⊢ x.fst = k ∨ x = a ∨ x ∈ l ** exact .inr (.inr h) ** case cons.h_2 α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l c✝ : Bool heq✝ : p a = false ⊢ x = a ∨ x ∈ List.replaceF (fun a => match p a with | true => some (k, f a) | false => none) l → x.fst = k ∨ x = a ∨ x ∈ l ** intro
| .inl eq => exact .inr (.inl eq)
| .inr h => exact (ih h).imp_right .inr ** α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l c✝ : Bool heq✝ : p a = false x✝ : x = a ∨ x ∈ List.replaceF (fun a => match p a with | true => some (k, f a) | false => none) l eq : x = a ⊢ x.fst = k ∨ x = a ∨ x ∈ l ** exact .inr (.inl eq) ** α : Type u_1 β : Type u_2 k : α x : α × β p : α × β → Bool f : α × β → β a : α × β l : List (α × β) ih : x ∈ List.replaceF (fun a => bif p a then some (k, f a) else none) l → x.fst = k ∨ x ∈ l c✝ : Bool heq✝ : p a = false x✝ : x = a ∨ x ∈ List.replaceF (fun a => match p a with | true => some (k, f a) | false => none) l h : x ∈ List.replaceF (fun a => match p a with | true => some (k, f a) | false => none) l ⊢ x.fst = k ∨ x = a ∨ x ∈ l ** exact (ih h).imp_right .inr ** Qed | |
Std.HashMap.Imp.erase_WF ** α : Type u_1 β : Type u_2 inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h : Buckets.WF m.buckets ⊢ Buckets.WF (erase m k).buckets ** dsimp [erase, cond] ** α : Type u_1 β : Type u_2 inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h : Buckets.WF m.buckets ⊢ Buckets.WF (match AssocList.contains k m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val] with | true => { size := m.size - 1, buckets := Buckets.update m.buckets (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val (AssocList.erase k m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) (_ : USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val < Array.size m.buckets.val) } | false => m).buckets ** split ** case h_1 α : Type u_1 β : Type u_2 inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h : Buckets.WF m.buckets c✝ : Bool heq✝ : AssocList.contains k m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val] = true ⊢ Buckets.WF { size := m.size - 1, buckets := Buckets.update m.buckets (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val (AssocList.erase k m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) (_ : USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val < Array.size m.buckets.val) }.buckets ** refine h.update (fun H => ?_) (fun H a h => ?_) <;> simp at h ⊢ ** case h_1.refine_1 α : Type u_1 β : Type u_2 inst✝³ : BEq α inst✝² : Hashable α m : Imp α β k : α h : Buckets.WF m.buckets c✝ : Bool heq✝ : AssocList.contains k m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val] = true inst✝¹ : PartialEquivBEq α inst✝ : LawfulHashable α H : List.Pairwise (fun a b => ¬(a.fst == b.fst) = true) (AssocList.toList m.buckets.val[(mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) ⊢ List.Pairwise (fun a b => ¬(a.fst == b.fst) = true) (List.eraseP (fun x => x.fst == k) (AssocList.toList m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val])) ** exact H.sublist (List.eraseP_sublist _) ** case h_1.refine_2 α : Type u_1 β : Type u_2 inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h✝ : Buckets.WF m.buckets c✝ : Bool heq✝ : AssocList.contains k m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val] = true H : AssocList.All (fun k_1 x => USize.toNat (UInt64.toUSize (hash k_1) % Array.size m.buckets.val) = USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val) m.buckets.val[(mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val] a : α × β h : a ∈ List.eraseP (fun x => x.fst == k) (AssocList.toList m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) ⊢ USize.toNat (UInt64.toUSize (hash a.fst) % Array.size m.buckets.val) = USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val ** exact H _ (List.mem_of_mem_eraseP h) ** case h_2 α : Type u_1 β : Type u_2 inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h : Buckets.WF m.buckets c✝ : Bool heq✝ : AssocList.contains k m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val] = false ⊢ Buckets.WF m.buckets ** exact h ** Qed | |
Std.HashMap.Imp.modify_size ** α : Type u_1 β : Type u_2 f : α → β → β inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h : m.size = Buckets.size m.buckets ⊢ (modify m k f).size = Buckets.size (modify m k f).buckets ** dsimp [modify, cond] ** α : Type u_1 β : Type u_2 f : α → β → β inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h : m.size = Buckets.size m.buckets ⊢ m.size = Buckets.size (Buckets.update (Buckets.update m.buckets (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val AssocList.nil (_ : USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val < Array.size m.buckets.val)) (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val (AssocList.modify k f m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) (_ : USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val < Array.size (Buckets.update m.buckets (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val AssocList.nil (_ : USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val < Array.size m.buckets.val)).val)) ** rw [Buckets.update_update] ** α : Type u_1 β : Type u_2 f : α → β → β inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h : m.size = Buckets.size m.buckets ⊢ m.size = Buckets.size (Buckets.update m.buckets (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val (AssocList.modify k f m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) (_ : USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val < Array.size m.buckets.val)) ** simp [h, Buckets.size] ** α : Type u_1 β : Type u_2 f : α → β → β inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h : m.size = Buckets.size m.buckets ⊢ Nat.sum (List.map (fun x => List.length (AssocList.toList x)) m.buckets.val.data) = Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (Buckets.update m.buckets (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val (AssocList.modify k f m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) (_ : USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val < Array.size m.buckets.val)).val.data) ** refine have ⟨_, _, h₁, _, eq⟩ := Buckets.exists_of_update ..; eq ▸ ?_ ** α : Type u_1 β : Type u_2 f : α → β → β inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h : m.size = Buckets.size m.buckets w✝¹ w✝ : List (AssocList α β) h₁ : m.buckets.val.data = w✝¹ ++ m.buckets.val[(mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val] :: w✝ left✝ : List.length w✝¹ = USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val eq : (Buckets.update m.buckets (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val (AssocList.modify k f m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) (_ : USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val < Array.size m.buckets.val)).val.data = w✝¹ ++ AssocList.modify k f m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val] :: w✝ ⊢ Nat.sum (List.map (fun x => List.length (AssocList.toList x)) m.buckets.val.data) = Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (w✝¹ ++ AssocList.modify k f m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val] :: w✝)) ** simp [h, h₁, Buckets.size_eq] ** Qed | |
Std.HashMap.Imp.modify_WF ** α : Type u_1 β : Type u_2 f : α → β → β inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h : Buckets.WF m.buckets ⊢ Buckets.WF (modify m k f).buckets ** dsimp [modify, cond] ** α : Type u_1 β : Type u_2 f : α → β → β inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h : Buckets.WF m.buckets ⊢ Buckets.WF (Buckets.update (Buckets.update m.buckets (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val AssocList.nil (_ : USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val < Array.size m.buckets.val)) (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val (AssocList.modify k f m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) (_ : USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val < Array.size (Buckets.update m.buckets (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val AssocList.nil (_ : USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val < Array.size m.buckets.val)).val)) ** rw [Buckets.update_update] ** α : Type u_1 β : Type u_2 f : α → β → β inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h : Buckets.WF m.buckets ⊢ Buckets.WF (Buckets.update m.buckets (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val (AssocList.modify k f m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) (_ : USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val < Array.size m.buckets.val)) ** refine h.update (fun H => ?_) (fun H a h => ?_) <;> simp at h ⊢ ** case refine_1 α : Type u_1 β : Type u_2 f : α → β → β inst✝³ : BEq α inst✝² : Hashable α m : Imp α β k : α h : Buckets.WF m.buckets inst✝¹ : PartialEquivBEq α inst✝ : LawfulHashable α H : List.Pairwise (fun a b => ¬(a.fst == b.fst) = true) (AssocList.toList m.buckets.val[(mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) ⊢ List.Pairwise (fun a b => ¬(a.fst == b.fst) = true) (List.replaceF (fun x => bif x.fst == k then some (k, f x.fst x.snd) else none) (AssocList.toList m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val])) ** exact pairwise_replaceF H ** case refine_2 α : Type u_1 β : Type u_2 f : α → β → β inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h✝ : Buckets.WF m.buckets H : AssocList.All (fun k_1 x => USize.toNat (UInt64.toUSize (hash k_1) % Array.size m.buckets.val) = USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val) m.buckets.val[(mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val] a : α × β h : a ∈ List.replaceF (fun x => bif x.fst == k then some (k, f x.fst x.snd) else none) (AssocList.toList m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) ⊢ USize.toNat (UInt64.toUSize (hash a.fst) % Array.size m.buckets.val) = USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val ** simp [AssocList.All] at H h ⊢ ** case refine_2 α : Type u_1 β : Type u_2 f : α → β → β inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β k : α h✝ : Buckets.WF m.buckets H : ∀ (a : α × β), a ∈ AssocList.toList m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val] → USize.toNat (UInt64.toUSize (hash a.fst) % Array.size m.buckets.val) = USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val a : α × β h : a ∈ List.replaceF (fun x => bif x.fst == k then some (k, f x.fst x.snd) else none) (AssocList.toList m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) ⊢ USize.toNat (UInt64.toUSize (hash a.fst) % Array.size m.buckets.val) = USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val ** match mem_replaceF h with
| .inl rfl => rfl
| .inr h => exact H _ h ** α : Type u_1 β : Type u_2 f : α → β → β inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β h✝ : Buckets.WF m.buckets a : α × β H : ∀ (a_1 : α × β), a_1 ∈ AssocList.toList m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash a.fst))).val] → USize.toNat (UInt64.toUSize (hash a_1.fst) % Array.size m.buckets.val) = USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash a.fst))).val h : a ∈ List.replaceF (fun x => bif x.fst == a.fst then some (a.fst, f x.fst x.snd) else none) (AssocList.toList m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash a.fst))).val]) ⊢ USize.toNat (UInt64.toUSize (hash a.fst) % Array.size m.buckets.val) = USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash a.fst))).val ** rfl ** α : Type u_1 β : Type u_2 f : α → β → β inst✝¹ : BEq α inst✝ : Hashable α m : Imp α β h✝¹ : Buckets.WF m.buckets a : α × β k : α h : a ∈ AssocList.toList m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val] H : ∀ (a : α × β), a ∈ AssocList.toList m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val] → USize.toNat (UInt64.toUSize (hash a.fst) % Array.size m.buckets.val) = USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val h✝ : a ∈ List.replaceF (fun x => bif x.fst == k then some (k, f x.fst x.snd) else none) (AssocList.toList m.buckets.val[USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val]) ⊢ USize.toNat (UInt64.toUSize (hash a.fst) % Array.size m.buckets.val) = USize.toNat (mkIdx (_ : 0 < Array.size m.buckets.val) (UInt64.toUSize (hash k))).val ** exact H _ h ** Qed | |
Array.get?_len_le ** α : Type u_1 a : Array α i : Nat h : size a ≤ i ⊢ a[i]? = none ** simp [getElem?_neg, h] ** Qed | |
Array.getElem_mem_data ** α : Type u_1 i : Nat a : Array α h : i < size a ⊢ a[i] ∈ a.data ** simp [getElem_eq_data_get, List.get_mem] ** Qed | |
Array.getElem?_eq_data_get? ** α : Type u_1 a : Array α i : Nat ⊢ a[i]? = List.get? a.data i ** by_cases i < a.size <;> simp_all [getElem?_pos, getElem?_neg, List.get?_eq_get, eq_comm] ** case pos α : Type u_1 a : Array α i : Nat h✝ : i < size a ⊢ List.get a.data { val := i, isLt := (_ : i < size a) } = a[i] ** rfl ** Qed | |
Array.back_eq_back? ** α : Type u_1 inst✝ : Inhabited α a : Array α ⊢ back a = Option.getD (back? a) default ** simp [back, back?] ** Qed | |
Array.back?_push ** α : Type u_1 x : α a : Array α ⊢ back? (push a x) = some x ** simp [back?, getElem?_eq_data_get?] ** Qed | |
Array.back_push ** α : Type u_1 x : α inst✝ : Inhabited α a : Array α ⊢ back (push a x) = x ** simp ** Qed | |
Array.get?_push_lt ** α : Type u_1 a : Array α x : α i : Nat h : i < size a ⊢ (push a x)[i]? = some a[i] ** rw [getElem?_pos, get_push_lt] ** Qed | |
Array.get_set_eq ** α : Type ?u.12801 a : Array α i : Fin (size a) v : α ⊢ i.val < size (set a i v) ** simp [i.2] ** α : Type u_1 a : Array α i : Fin (size a) v : α ⊢ (set a i v)[i.val] = v ** simp only [set, getElem_eq_data_get, List.get_set_eq] ** Qed | |
Array.get?_set_eq ** α : Type u_1 a : Array α i : Fin (size a) v : α ⊢ (set a i v)[i.val]? = some v ** simp [getElem?_pos, i.2] ** Qed | |
Array.get?_set_ne ** α : Type u_1 a : Array α i : Fin (size a) j : Nat v : α h : i.val ≠ j ⊢ (set a i v)[j]? = a[j]? ** by_cases j < a.size <;> simp [getElem?_pos, getElem?_neg, *] ** Qed | |
Array.get?_set ** α : Type u_1 a : Array α i : Fin (size a) j : Nat v : α ⊢ (set a i v)[j]? = if i.val = j then some v else a[j]? ** if h : i.1 = j then subst j; simp [*] else simp [*] ** α : Type u_1 a : Array α i : Fin (size a) j : Nat v : α h : i.val = j ⊢ (set a i v)[j]? = if i.val = j then some v else a[j]? ** subst j ** α : Type u_1 a : Array α i : Fin (size a) v : α ⊢ (set a i v)[i.val]? = if i.val = i.val then some v else a[i.val]? ** simp [*] ** α : Type u_1 a : Array α i : Fin (size a) j : Nat v : α h : ¬i.val = j ⊢ (set a i v)[j]? = if i.val = j then some v else a[j]? ** simp [*] ** Qed | |
Array.get_set ** α : Type ?u.16065 a : Array α i : Fin (size a) j : Nat hj : j < size a v : α ⊢ j < size (set a i v) ** simp [*] ** α : Type u_1 a : Array α i : Fin (size a) j : Nat hj : j < size a v : α ⊢ (set a i v)[j] = if i.val = j then v else a[j] ** if h : i.1 = j then subst j; simp [*] else simp [*] ** α : Type u_1 a : Array α i : Fin (size a) j : Nat hj : j < size a v : α h : i.val = j ⊢ (set a i v)[j] = if i.val = j then v else a[j] ** subst j ** α : Type u_1 a : Array α i : Fin (size a) v : α hj : i.val < size a ⊢ (set a i v)[i.val] = if i.val = i.val then v else a[i.val] ** simp [*] ** α : Type u_1 a : Array α i : Fin (size a) j : Nat hj : j < size a v : α h : ¬i.val = j ⊢ (set a i v)[j] = if i.val = j then v else a[j] ** simp [*] ** Qed | |
Array.fin_cast_val ** n n' : Nat e : n = n' i : Fin n ⊢ e ▸ i = { val := i.val, isLt := (_ : i.val < n') } ** cases e ** case refl n : Nat i : Fin n ⊢ (_ : n = n) ▸ i = { val := i.val, isLt := (_ : i.val < n) } ** rfl ** Qed | |
Array.data_swap ** α : Type u_1 a : Array α i j : Fin (size a) ⊢ (swap a i j).data = List.set (List.set a.data i.val (get a j)) j.val (get a i) ** simp [swap_def] ** Qed | |
Array.data_pop ** α : Type u_1 a : Array α ⊢ (pop a).data = List.dropLast a.data ** simp [pop] ** Qed | |
Array.pop_push ** α : Type u_1 x : α a : Array α ⊢ pop (push a x) = a ** simp [pop] ** Qed | |
Array.SatisfiesM_foldrM ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) ⊢ SatisfiesM (motive 0) (foldrM f init as (size as)) ** simp [foldrM] ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) ⊢ SatisfiesM (motive 0) (if 0 < size as then foldrM.fold f as 0 (size as) (_ : size as ≤ size as) init else pure init) ** split ** case inl m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) h✝ : 0 < size as ⊢ SatisfiesM (motive 0) (foldrM.fold f as 0 (size as) (_ : size as ≤ size as) init) case inr m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) h✝ : ¬0 < size as ⊢ SatisfiesM (motive 0) (pure init) ** {exact go _ h0} ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) i : Nat b : β hi : i ≤ size as H : motive i b ⊢ SatisfiesM (motive 0) (foldrM.fold f as 0 i hi b) ** unfold foldrM.fold ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) i : Nat b : β hi : i ≤ size as H : motive i b ⊢ SatisfiesM (motive 0) (if (i == 0) = true then pure b else match i, hi with | 0, x => pure b | Nat.succ i, h => let_fun this := (_ : i < size as); do let __do_lift ← f as[i] b foldrM.fold f as 0 i (_ : i ≤ size as) __do_lift) ** simp ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) i : Nat b : β hi : i ≤ size as H : motive i b ⊢ SatisfiesM (motive 0) (if i = 0 then pure b else match i, hi with | 0, x => pure b | Nat.succ i, h => do let __do_lift ← f as[i] b foldrM.fold f as 0 i (_ : i ≤ size as) __do_lift) ** split ** case inl m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) i : Nat b : β hi : i ≤ size as H : motive i b h✝ : i = 0 ⊢ SatisfiesM (motive 0) (pure b) ** next hi => exact .pure (hi ▸ H) ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) i : Nat b : β hi✝ : i ≤ size as H : motive i b hi : i = 0 ⊢ SatisfiesM (motive 0) (pure b) ** exact .pure (hi ▸ H) ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) i : Nat b : β hi✝ : i ≤ size as H : motive i b hi : ¬i = 0 ⊢ SatisfiesM (motive 0) (match i, hi✝ with | 0, x => pure b | Nat.succ i, h => do let __do_lift ← f as[i] b foldrM.fold f as 0 i (_ : i ≤ size as) __do_lift) ** split ** case h_1 m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) b : β i✝ : Nat h✝ : i✝ ≤ size as x✝ : 0 ≤ size as H : motive 0 b hi : ¬0 = 0 ⊢ SatisfiesM (motive 0) (pure b) case h_2 m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) b : β i✝¹ : Nat h✝¹ : i✝¹ ≤ size as i✝ : Nat h✝ : i✝ + 1 ≤ size as H : motive (Nat.succ i✝) b hi : ¬Nat.succ i✝ = 0 ⊢ SatisfiesM (motive 0) do let __do_lift ← f as[i✝] b foldrM.fold f as 0 i✝ (_ : i✝ ≤ size as) __do_lift ** {simp at hi} ** case h_2 m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) b : β i✝¹ : Nat h✝¹ : i✝¹ ≤ size as i✝ : Nat h✝ : i✝ + 1 ≤ size as H : motive (Nat.succ i✝) b hi : ¬Nat.succ i✝ = 0 ⊢ SatisfiesM (motive 0) do let __do_lift ← f as[i✝] b foldrM.fold f as 0 i✝ (_ : i✝ ≤ size as) __do_lift ** next i hi' =>
exact (hf ⟨i, hi'⟩ b H).bind fun _ => go _ ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) b : β i✝ : Nat h✝ : i✝ ≤ size as i : Nat hi' : i + 1 ≤ size as H : motive (Nat.succ i) b hi : ¬Nat.succ i = 0 ⊢ SatisfiesM (motive 0) do let __do_lift ← f as[i] b foldrM.fold f as 0 i (_ : i ≤ size as) __do_lift ** exact (hf ⟨i, hi'⟩ b H).bind fun _ => go _ ** case inr m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) h✝ : ¬0 < size as ⊢ SatisfiesM (motive 0) (pure init) ** next h => exact .pure (Nat.eq_zero_of_nonpos _ h ▸ h0) ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α motive : Nat → β → Prop init : β h0 : motive (size as) init f : α → β → m β hf : ∀ (i : Fin (size as)) (b : β), motive (i.val + 1) b → SatisfiesM (motive i.val) (f as[i] b) h : ¬0 < size as ⊢ SatisfiesM (motive 0) (pure init) ** exact .pure (Nat.eq_zero_of_nonpos _ h ▸ h0) ** Qed | |
Array.SatisfiesM_mapIdxM ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) ⊢ SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (mapIdxM as f) ** simp [mapIdxM] ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) ⊢ SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (mapIdxM.map as f (size as) 0 (_ : size as + 0 = size as + 0) #[]) ** exact go rfl (fun.) h0 ** case zero m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) bs : Array β j : Nat h : Nat.zero + j = size as h₁ : j = size bs h₂ : ∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i] hm : motive j ⊢ SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (pure bs) ** have := (Nat.zero_add _).symm.trans h ** case zero m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) bs : Array β j : Nat h : Nat.zero + j = size as h₁ : j = size bs h₂ : ∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i] hm : motive j this : j = size as ⊢ SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (pure bs) ** exact .pure ⟨this ▸ hm, h₁ ▸ this, fun _ _ => h₂ ..⟩ ** case succ m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) i : Nat ih : ∀ {bs : Array β} {j : Nat} {h : i + j = size as}, j = size bs → (∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i]) → motive j → SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (mapIdxM.map as f i j h bs) bs : Array β j : Nat h : Nat.succ i + j = size as h₁ : j = size bs h₂ : ∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i] hm : motive j ⊢ SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) do let __do_lift ← f { val := j, isLt := (_ : j < size as) } as[j] mapIdxM.map as f i (j + 1) (_ : i + (j + 1) = size as) (push bs __do_lift) ** refine (hs _ (by exact hm)).bind fun b hb => ih (by simp [h₁]) (fun i hi hi' => ?_) hb.2 ** case succ m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) i✝ : Nat ih : ∀ {bs : Array β} {j : Nat} {h : i✝ + j = size as}, j = size bs → (∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i]) → motive j → SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (mapIdxM.map as f i✝ j h bs) bs : Array β j : Nat h : Nat.succ i✝ + j = size as h₁ : j = size bs h₂ : ∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i] hm : motive j b : β hb : p { val := j, isLt := (_ : j < size as) } b ∧ motive ({ val := j, isLt := (_ : j < size as) }.val + 1) i : Nat hi : i < size as hi' : i < size (push bs b) ⊢ p { val := i, isLt := hi } (push bs b)[i] ** simp at hi' ** case succ m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) i✝ : Nat ih : ∀ {bs : Array β} {j : Nat} {h : i✝ + j = size as}, j = size bs → (∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i]) → motive j → SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (mapIdxM.map as f i✝ j h bs) bs : Array β j : Nat h : Nat.succ i✝ + j = size as h₁ : j = size bs h₂ : ∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i] hm : motive j b : β hb : p { val := j, isLt := (_ : j < size as) } b ∧ motive ({ val := j, isLt := (_ : j < size as) }.val + 1) i : Nat hi : i < size as hi'✝ : i < size (push bs b) hi' : i < size bs + 1 ⊢ p { val := i, isLt := hi } (push bs b)[i] ** simp [get_push] ** case succ m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) i✝ : Nat ih : ∀ {bs : Array β} {j : Nat} {h : i✝ + j = size as}, j = size bs → (∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i]) → motive j → SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (mapIdxM.map as f i✝ j h bs) bs : Array β j : Nat h : Nat.succ i✝ + j = size as h₁ : j = size bs h₂ : ∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i] hm : motive j b : β hb : p { val := j, isLt := (_ : j < size as) } b ∧ motive ({ val := j, isLt := (_ : j < size as) }.val + 1) i : Nat hi : i < size as hi'✝ : i < size (push bs b) hi' : i < size bs + 1 ⊢ p { val := i, isLt := hi } (if h : i < size bs then bs[i] else b) ** split ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) i : Nat ih : ∀ {bs : Array β} {j : Nat} {h : i + j = size as}, j = size bs → (∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i]) → motive j → SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (mapIdxM.map as f i j h bs) bs : Array β j : Nat h : Nat.succ i + j = size as h₁ : j = size bs h₂ : ∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i] hm : motive j ⊢ motive { val := j, isLt := (_ : j < size as) }.val ** exact hm ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) i : Nat ih : ∀ {bs : Array β} {j : Nat} {h : i + j = size as}, j = size bs → (∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i]) → motive j → SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (mapIdxM.map as f i j h bs) bs : Array β j : Nat h : Nat.succ i + j = size as h₁ : j = size bs h₂ : ∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i] hm : motive j b : β hb : p { val := j, isLt := (_ : j < size as) } b ∧ motive ({ val := j, isLt := (_ : j < size as) }.val + 1) ⊢ j + 1 = size (push bs b) ** simp [h₁] ** case succ.inl m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) i✝ : Nat ih : ∀ {bs : Array β} {j : Nat} {h : i✝ + j = size as}, j = size bs → (∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i]) → motive j → SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (mapIdxM.map as f i✝ j h bs) bs : Array β j : Nat h : Nat.succ i✝ + j = size as h₁ : j = size bs h₂ : ∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i] hm : motive j b : β hb : p { val := j, isLt := (_ : j < size as) } b ∧ motive ({ val := j, isLt := (_ : j < size as) }.val + 1) i : Nat hi : i < size as hi'✝ : i < size (push bs b) hi' : i < size bs + 1 h✝ : i < size bs ⊢ p { val := i, isLt := hi } bs[i] ** next h => exact h₂ _ _ h ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) i✝ : Nat ih : ∀ {bs : Array β} {j : Nat} {h : i✝ + j = size as}, j = size bs → (∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i]) → motive j → SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (mapIdxM.map as f i✝ j h bs) bs : Array β j : Nat h✝ : Nat.succ i✝ + j = size as h₁ : j = size bs h₂ : ∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i] hm : motive j b : β hb : p { val := j, isLt := (_ : j < size as) } b ∧ motive ({ val := j, isLt := (_ : j < size as) }.val + 1) i : Nat hi : i < size as hi'✝ : i < size (push bs b) hi' : i < size bs + 1 h : i < size bs ⊢ p { val := i, isLt := hi } bs[i] ** exact h₂ _ _ h ** case succ.inr m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) i✝ : Nat ih : ∀ {bs : Array β} {j : Nat} {h : i✝ + j = size as}, j = size bs → (∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i]) → motive j → SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (mapIdxM.map as f i✝ j h bs) bs : Array β j : Nat h : Nat.succ i✝ + j = size as h₁ : j = size bs h₂ : ∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i] hm : motive j b : β hb : p { val := j, isLt := (_ : j < size as) } b ∧ motive ({ val := j, isLt := (_ : j < size as) }.val + 1) i : Nat hi : i < size as hi'✝ : i < size (push bs b) hi' : i < size bs + 1 h✝ : ¬i < size bs ⊢ p { val := i, isLt := hi } b ** next h => cases h₁.symm ▸ (Nat.le_or_eq_of_le_succ hi').resolve_left h; exact hb.1 ** m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) i✝ : Nat ih : ∀ {bs : Array β} {j : Nat} {h : i✝ + j = size as}, j = size bs → (∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i]) → motive j → SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (mapIdxM.map as f i✝ j h bs) bs : Array β j : Nat h✝ : Nat.succ i✝ + j = size as h₁ : j = size bs h₂ : ∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i] hm : motive j b : β hb : p { val := j, isLt := (_ : j < size as) } b ∧ motive ({ val := j, isLt := (_ : j < size as) }.val + 1) i : Nat hi : i < size as hi'✝ : i < size (push bs b) hi' : i < size bs + 1 h : ¬i < size bs ⊢ p { val := i, isLt := hi } b ** cases h₁.symm ▸ (Nat.le_or_eq_of_le_succ hi').resolve_left h ** case refl m : Type u_1 → Type u_2 α : Type u_3 β : Type u_1 inst✝¹ : Monad m inst✝ : LawfulMonad m as : Array α f : Fin (size as) → α → m β motive : Nat → Prop h0 : motive 0 p : Fin (size as) → β → Prop hs : ∀ (i : Fin (size as)), motive i.val → SatisfiesM (fun x => p i x ∧ motive (i.val + 1)) (f i as[i]) i : Nat ih : ∀ {bs : Array β} {j : Nat} {h : i + j = size as}, j = size bs → (∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i]) → motive j → SatisfiesM (fun arr => motive (size as) ∧ ∃ eq, ∀ (i : Nat) (h : i < size as), p { val := i, isLt := h } arr[i]) (mapIdxM.map as f i j h bs) bs : Array β j : Nat h✝ : Nat.succ i + j = size as h₁ : j = size bs h₂ : ∀ (i : Nat) (h : i < size as) (h' : i < size bs), p { val := i, isLt := h } bs[i] hm : motive j b : β hb : p { val := j, isLt := (_ : j < size as) } b ∧ motive ({ val := j, isLt := (_ : j < size as) }.val + 1) hi : j < size as hi'✝ : j < size (push bs b) hi' : j < size bs + 1 h : ¬j < size bs ⊢ p { val := j, isLt := hi } b ** exact hb.1 ** Qed | |
Array.getElem_mapIdx ** α : Type ?u.58055 β : Type ?u.58096 a : Array α f : Fin (size a) → α → β i : Nat h : i < size (mapIdx a f) ⊢ i < size a ** simp_all ** Qed | |
Array.size_reverse ** α : Type u_1 a : Array α ⊢ size (reverse a) = size a ** simp only [reverse] ** α : Type u_1 a : Array α ⊢ size (if h : size a ≤ 1 then a else reverse.loop a 0 { val := size a - 1, isLt := (_ : Nat.pred (Nat.sub (size a) 0) < Nat.sub (size a) 0) }) = size a ** split <;> simp [go] ** α : Type u_1 a as : Array α i : Nat j : Fin (size as) ⊢ size (reverse.loop as i j) = size as ** rw [reverse.loop] ** α : Type u_1 a as : Array α i : Nat j : Fin (size as) h : i < j.val ⊢ size (if h : i < j.val then let_fun this := (_ : j.val - 1 - (i + 1) < j.val - i); let as_1 := swap as { val := i, isLt := (_ : i < size as) } j; let_fun this := (_ : j.val - 1 < size as_1); reverse.loop as_1 (i + 1) { val := j.val - 1, isLt := this } else as) = size as ** have := reverse.termination h ** α : Type u_1 a as : Array α i : Nat j : Fin (size as) h : ¬i < j.val ⊢ size (if h : i < j.val then let_fun this := (_ : j.val - 1 - (i + 1) < j.val - i); let as_1 := swap as { val := i, isLt := (_ : i < size as) } j; let_fun this := (_ : j.val - 1 < size as_1); reverse.loop as_1 (i + 1) { val := j.val - 1, isLt := this } else as) = size as ** simp [h] ** Qed |