From 92cca5ed1b577a7bc7f73c5f6cd9a97040c80f76 Mon Sep 17 00:00:00 2001 From: Markus Himmel Date: Mon, 22 Jul 2024 15:39:00 +0100 Subject: [PATCH] chore: remove bif from hash map lemmas (#4791) The original idea was to use `bif` in computation contexts and `if` in propositional contexts, but this turned out to be really inconvenient in practice. --- .../DHashMap/Internal/List/Associative.lean | 116 +++++++++--------- src/Std/Data/DHashMap/Internal/RawLemmas.lean | 30 ++--- src/Std/Data/DHashMap/Internal/WF.lean | 3 +- src/Std/Data/DHashMap/Lemmas.lean | 39 +++--- src/Std/Data/DHashMap/RawLemmas.lean | 36 +++--- src/Std/Data/HashMap/Lemmas.lean | 24 ++-- src/Std/Data/HashMap/RawLemmas.lean | 24 ++-- src/Std/Data/HashSet/Lemmas.lean | 4 +- src/Std/Data/HashSet/RawLemmas.lean | 4 +- 9 files changed, 146 insertions(+), 134 deletions(-) diff --git a/src/Std/Data/DHashMap/Internal/List/Associative.lean b/src/Std/Data/DHashMap/Internal/List/Associative.lean index 4b6e4eb4479a..0f7b29d5cf55 100644 --- a/src/Std/Data/DHashMap/Internal/List/Associative.lean +++ b/src/Std/Data/DHashMap/Internal/List/Associative.lean @@ -579,7 +579,7 @@ theorem getEntry?_replaceEntry_of_true [BEq α] [PartialEquivBEq α] {l : List ( theorem getEntry?_replaceEntry [BEq α] [PartialEquivBEq α] {l : List ((a : α) × β a)} {a k : α} {v : β k} : - getEntry? a (replaceEntry k v l) = bif containsKey k l && k == a then some ⟨k, v⟩ else + getEntry? a (replaceEntry k v l) = if containsKey k l ∧ k == a then some ⟨k, v⟩ else getEntry? a l := by cases hl : containsKey k l · simp [getEntry?_replaceEntry_of_containsKey_eq_false hl] @@ -632,13 +632,11 @@ theorem getValueCast?_replaceEntry [BEq α] [LawfulBEq α] {l : List ((a : α) @[simp] theorem containsKey_replaceEntry [BEq α] [PartialEquivBEq α] {l : List ((a : α) × β a)} {a k : α} {v : β k} : containsKey a (replaceEntry k v l) = containsKey a l := by - cases h : containsKey k l && k == a - · rw [containsKey_eq_isSome_getEntry?, getEntry?_replaceEntry, h, cond_false, - containsKey_eq_isSome_getEntry?] - · rw [containsKey_eq_isSome_getEntry?, getEntry?_replaceEntry, h, cond_true, Option.isSome_some, - Eq.comm] - rw [Bool.and_eq_true] at h - exact containsKey_of_beq h.1 h.2 + by_cases h : (getEntry? k l).isSome ∧ k == a + · simp only [containsKey_eq_isSome_getEntry?, getEntry?_replaceEntry, h, and_self, ↓reduceIte, + Option.isSome_some, Bool.true_eq] + rw [← getEntry?_congr h.2, h.1] + · simp [containsKey_eq_isSome_getEntry?, getEntry?_replaceEntry, h] /-- Internal implementation detail of the hash map -/ def eraseKey [BEq α] (k : α) : List ((a : α) × β a) → List ((a : α) × β a) @@ -681,7 +679,7 @@ theorem sublist_eraseKey [BEq α] {l : List ((a : α) × β a)} {k : α} : · simpa using Sublist.cons_right Sublist.refl theorem length_eraseKey [BEq α] {l : List ((a : α) × β a)} {k : α} : - (eraseKey k l).length = bif containsKey k l then l.length - 1 else l.length := by + (eraseKey k l).length = if containsKey k l then l.length - 1 else l.length := by induction l using assoc_induction · simp · next k' v' t ih => @@ -690,7 +688,7 @@ theorem length_eraseKey [BEq α] {l : List ((a : α) × β a)} {k : α} : · rw [cond_false, Bool.false_or, List.length_cons, ih] cases h : containsKey k t · simp - · simp only [cond_true, Nat.succ_eq_add_one, List.length_cons, Nat.add_sub_cancel] + · simp only [Nat.succ_eq_add_one, List.length_cons, Nat.add_sub_cancel, if_true] rw [Nat.sub_add_cancel] cases t · simp at h @@ -855,7 +853,7 @@ theorem isEmpty_insertEntry [BEq α] {l : List ((a : α) × β a)} {k : α} {v : · rw [insertEntry_of_containsKey h, isEmpty_replaceEntry, isEmpty_eq_false_of_containsKey h] theorem length_insertEntry [BEq α] {l : List ((a : α) × β a)} {k : α} {v : β k} : - (insertEntry k v l).length = bif containsKey k l then l.length else l.length + 1 := by + (insertEntry k v l).length = if containsKey k l then l.length else l.length + 1 := by simp [insertEntry, Bool.apply_cond List.length] theorem length_le_length_insertEntry [BEq α] {l : List ((a : α) × β a)} {k : α} {v : β k} : @@ -886,23 +884,23 @@ theorem getValue?_insertEntry_of_false [BEq α] [PartialEquivBEq α] {l : List ( · rw [insertEntry_of_containsKey h', getValue?_replaceEntry_of_false h] theorem getValue?_insertEntry [BEq α] [PartialEquivBEq α] {l : List ((_ : α) × β)} {k a : α} - {v : β} : getValue? a (insertEntry k v l) = bif k == a then some v else getValue? a l := by + {v : β} : getValue? a (insertEntry k v l) = if k == a then some v else getValue? a l := by cases h : k == a · simp [getValue?_insertEntry_of_false h, h] · simp [getValue?_insertEntry_of_beq h, h] theorem getValue?_insertEntry_self [BEq α] [EquivBEq α] {l : List ((_ : α) × β)} {k : α} {v : β} : getValue? k (insertEntry k v l) = some v := by - rw [getValue?_insertEntry, Bool.cond_pos BEq.refl] + simp [getValue?_insertEntry] end theorem getEntry?_insertEntry [BEq α] [PartialEquivBEq α] {l : List ((a : α) × β a)} {k a : α} {v : β k} : - getEntry? a (insertEntry k v l) = bif k == a then some ⟨k, v⟩ else getEntry? a l := by + getEntry? a (insertEntry k v l) = if k == a then some ⟨k, v⟩ else getEntry? a l := by cases hl : containsKey k l - · rw [insertEntry_of_containsKey_eq_false hl, getEntry?_cons] - · rw [insertEntry_of_containsKey hl, getEntry?_replaceEntry, hl, Bool.true_and, BEq.comm] + · rw [insertEntry_of_containsKey_eq_false hl, getEntry?_cons, cond_eq_if] + · simp [insertEntry_of_containsKey hl, getEntry?_replaceEntry, hl] theorem getValueCast?_insertEntry [BEq α] [LawfulBEq α] {l : List ((a : α) × β a)} {k a : α} {v : β k} : getValueCast? a (insertEntry k v l) = @@ -938,21 +936,21 @@ theorem getValueCastD_insertEntry_self [BEq α] [LawfulBEq α] {l : List ((a : theorem getValue!_insertEntry {β : Type v} [BEq α] [PartialEquivBEq α] [Inhabited β] {l : List ((_ : α) × β)} {k a : α} {v : β} : - getValue! a (insertEntry k v l) = bif k == a then v else getValue! a l := by - simp [getValue!_eq_getValue?, getValue?_insertEntry, Bool.apply_cond Option.get!] + getValue! a (insertEntry k v l) = if k == a then v else getValue! a l := by + simp [getValue!_eq_getValue?, getValue?_insertEntry, apply_ite Option.get!] theorem getValue!_insertEntry_self {β : Type v} [BEq α] [EquivBEq α] [Inhabited β] {l : List ((_ : α) × β)} {k : α} {v : β} : getValue! k (insertEntry k v l) = v := by - rw [getValue!_insertEntry, BEq.refl, cond_true] + simp [getValue!_insertEntry, BEq.refl] theorem getValueD_insertEntry {β : Type v} [BEq α] [PartialEquivBEq α] {l : List ((_ : α) × β)} {k a : α} {fallback v : β} : getValueD a (insertEntry k v l) fallback = - bif k == a then v else getValueD a l fallback := by - simp [getValueD_eq_getValue?, getValue?_insertEntry, Bool.apply_cond (fun x => Option.getD x fallback)] + if k == a then v else getValueD a l fallback := by + simp [getValueD_eq_getValue?, getValue?_insertEntry, apply_ite (fun x => Option.getD x fallback)] theorem getValueD_insertEntry_self {β : Type v} [BEq α] [EquivBEq α] {l : List ((_ : α) × β)} {k : α} {fallback v : β} : getValueD k (insertEntry k v l) fallback = v := by - rw [getValueD_insertEntry, BEq.refl, cond_true] + simp [getValueD_insertEntry, BEq.refl] @[simp] theorem containsKey_insertEntry [BEq α] [PartialEquivBEq α] {l : List ((a : α) × β a)} {k a : α} @@ -991,7 +989,7 @@ theorem getValue_insertEntry {β : Type v} [BEq α] [PartialEquivBEq α] {l : Li if h' : k == a then v else getValue a l (containsKey_of_containsKey_insertEntry h (Bool.eq_false_iff.2 h')) := by rw [← Option.some_inj, ← getValue?_eq_some_getValue, apply_dite Option.some, - getValue?_insertEntry, cond_eq_if, ← dite_eq_ite] + getValue?_insertEntry, ← dite_eq_ite] simp only [← getValue?_eq_some_getValue] theorem getValue_insertEntry_self {β : Type v} [BEq α] [EquivBEq α] {l : List ((_ : α) × β)} {k : α} @@ -1020,7 +1018,7 @@ theorem isEmpty_insertEntryIfNew [BEq α] {l : List ((a : α) × β a)} {k : α} theorem getEntry?_insertEntryIfNew [BEq α] [PartialEquivBEq α] {l : List ((a : α) × β a)} {k a : α} {v : β k} : getEntry? a (insertEntryIfNew k v l) = - bif k == a && !containsKey k l then some ⟨k, v⟩ else getEntry? a l := by + if k == a && !containsKey k l then some ⟨k, v⟩ else getEntry? a l := by cases h : containsKey k l · simp [insertEntryIfNew_of_containsKey_eq_false h, getEntry?_cons] · simp [insertEntryIfNew_of_containsKey h] @@ -1036,18 +1034,22 @@ theorem getValueCast?_insertEntryIfNew [BEq α] [LawfulBEq α] {l : List ((a : theorem getValue?_insertEntryIfNew {β : Type v} [BEq α] [PartialEquivBEq α] {l : List ((_ : α) × β)} {k a : α} {v : β} : getValue? a (insertEntryIfNew k v l) = - bif k == a && !containsKey k l then some v else getValue? a l := by + if k == a ∧ containsKey k l = false then some v else getValue? a l := by simp [getValue?_eq_getEntry?, getEntry?_insertEntryIfNew, - Bool.apply_cond (Option.map (fun (y : ((_ : α) × β)) => y.2))] + apply_ite (Option.map (fun (y : ((_ : α) × β)) => y.2))] theorem containsKey_insertEntryIfNew [BEq α] [PartialEquivBEq α] {l : List ((a : α) × β a)} {k a : α} {v : β k} : containsKey a (insertEntryIfNew k v l) = ((k == a) || containsKey a l) := by - simp only [containsKey_eq_isSome_getEntry?, getEntry?_insertEntryIfNew, Bool.apply_cond Option.isSome, - Option.isSome_some, Bool.cond_true_left] + simp only [containsKey_eq_isSome_getEntry?, getEntry?_insertEntryIfNew, apply_ite Option.isSome, + Option.isSome_some, if_true_left] + simp only [Bool.and_eq_true, Bool.not_eq_true', Option.not_isSome, Option.isNone_iff_eq_none, + getEntry?_eq_none, Bool.if_true_left, Bool.decide_and, Bool.decide_eq_true, + Bool.decide_eq_false] cases h : k == a · simp - · rw [Bool.true_and, Bool.true_or, getEntry?_congr h, Bool.not_or_self] + · rw [containsKey_eq_isSome_getEntry?, getEntry?_congr h] + simp theorem containsKey_insertEntryIfNew_self [BEq α] [EquivBEq α] {l : List ((a : α) × β a)} {k : α} {v : β k} : containsKey k (insertEntryIfNew k v l) := by @@ -1085,7 +1087,7 @@ theorem getValue_insertEntryIfNew {β : Type v} [BEq α] [PartialEquivBEq α] {l if h' : k == a ∧ containsKey k l = false then v else getValue a l (containsKey_of_containsKey_insertEntryIfNew' h h') := by rw [← Option.some_inj, ← getValue?_eq_some_getValue, apply_dite Option.some, - getValue?_insertEntryIfNew, cond_eq_if, ← dite_eq_ite] + getValue?_insertEntryIfNew, ← dite_eq_ite] simp [← getValue?_eq_some_getValue] theorem getValueCast!_insertEntryIfNew [BEq α] [LawfulBEq α] {l : List ((a : α) × β a)} {k a : α} @@ -1096,8 +1098,8 @@ theorem getValueCast!_insertEntryIfNew [BEq α] [LawfulBEq α] {l : List ((a : theorem getValue!_insertEntryIfNew {β : Type v} [BEq α] [PartialEquivBEq α] [Inhabited β] {l : List ((_ : α) × β)} {k a : α} {v : β} : getValue! a (insertEntryIfNew k v l) = - bif k == a && !containsKey k l then v else getValue! a l := by - simp [getValue!_eq_getValue?, getValue?_insertEntryIfNew, Bool.apply_cond Option.get!] + if k == a ∧ containsKey k l = false then v else getValue! a l := by + simp [getValue!_eq_getValue?, getValue?_insertEntryIfNew, apply_ite Option.get!] theorem getValueCastD_insertEntryIfNew [BEq α] [LawfulBEq α] {l : List ((a : α) × β a)} {k a : α} {v : β k} {fallback : β a} : getValueCastD a (insertEntryIfNew k v l) fallback = @@ -1108,12 +1110,12 @@ theorem getValueCastD_insertEntryIfNew [BEq α] [LawfulBEq α] {l : List ((a : theorem getValueD_insertEntryIfNew {β : Type v} [BEq α] [PartialEquivBEq α] {l : List ((_ : α) × β)} {k a : α} {fallback v : β} : getValueD a (insertEntryIfNew k v l) fallback = - bif k == a && !containsKey k l then v else getValueD a l fallback := by + if k == a ∧ containsKey k l = false then v else getValueD a l fallback := by simp [getValueD_eq_getValue?, getValue?_insertEntryIfNew, - Bool.apply_cond (fun x => Option.getD x fallback)] + apply_ite (fun x => Option.getD x fallback)] theorem length_insertEntryIfNew [BEq α] {l : List ((a : α) × β a)} {k : α} {v : β k} : - (insertEntryIfNew k v l).length = bif containsKey k l then l.length else l.length + 1 := by + (insertEntryIfNew k v l).length = if containsKey k l then l.length else l.length + 1 := by simp [insertEntryIfNew, Bool.apply_cond List.length] theorem length_le_length_insertEntryIfNew [BEq α] {l : List ((a : α) × β a)} {k : α} {v : β k} : @@ -1169,7 +1171,7 @@ theorem getEntry?_eraseKey_of_false [BEq α] [PartialEquivBEq α] {l : List ((a theorem getEntry?_eraseKey [BEq α] [PartialEquivBEq α] {l : List ((a : α) × β a)} {k a : α} (hl : DistinctKeys l) : - getEntry? a (eraseKey k l) = bif k == a then none else getEntry? a l := by + getEntry? a (eraseKey k l) = if k == a then none else getEntry? a l := by cases h : k == a · simp [getEntry?_eraseKey_of_false h, h] · simp [getEntry?_eraseKey_of_beq hl h, h] @@ -1222,8 +1224,8 @@ theorem getValue?_eraseKey_of_false [BEq α] [PartialEquivBEq α] {l : List ((_ theorem getValue?_eraseKey [BEq α] [PartialEquivBEq α] {l : List ((_ : α) × β)} {k a : α} (hl : DistinctKeys l) : - getValue? a (eraseKey k l) = bif k == a then none else getValue? a l := by - simp [getValue?_eq_getEntry?, getEntry?_eraseKey hl, Bool.apply_cond (Option.map _)] + getValue? a (eraseKey k l) = if k == a then none else getValue? a l := by + simp [getValue?_eq_getEntry?, getEntry?_eraseKey hl, apply_ite (Option.map _)] end @@ -1241,25 +1243,25 @@ theorem containsKey_eraseKey_of_false [BEq α] [PartialEquivBEq α] {l : List (( theorem containsKey_eraseKey [BEq α] [PartialEquivBEq α] {l : List ((a : α) × β a)} {k a : α} (hl : DistinctKeys l) : containsKey a (eraseKey k l) = (!(k == a) && containsKey a l) := by - simp [containsKey_eq_isSome_getEntry?, getEntry?_eraseKey hl, Bool.apply_cond] + simp [containsKey_eq_isSome_getEntry?, getEntry?_eraseKey hl, apply_ite] theorem getValueCast?_eraseKey [BEq α] [LawfulBEq α] {l : List ((a : α) × β a)} {k a : α} (hl : DistinctKeys l) : - getValueCast? a (eraseKey k l) = bif k == a then none else getValueCast? a l := by + getValueCast? a (eraseKey k l) = if k == a then none else getValueCast? a l := by rw [getValueCast?_eq_getEntry?, Option.dmap_congr (getEntry?_eraseKey hl)] - rcases Bool.eq_false_or_eq_true (k == a) with h|h - · rw [Option.dmap_congr (Bool.cond_pos h), Option.dmap_none, Bool.cond_pos h] - · rw [Option.dmap_congr (Bool.cond_neg h), getValueCast?_eq_getEntry?] - exact (Bool.cond_neg h).symm + by_cases h : k == a + · rw [Option.dmap_congr (if_pos h), Option.dmap_none, if_pos h] + · rw [Option.dmap_congr (if_neg h), getValueCast?_eq_getEntry?] + exact (if_neg h).symm theorem getValueCast?_eraseKey_self [BEq α] [LawfulBEq α] {l : List ((a : α) × β a)} {k : α} (hl : DistinctKeys l) : getValueCast? k (eraseKey k l) = none := by - rw [getValueCast?_eraseKey hl, Bool.cond_pos BEq.refl] + rw [getValueCast?_eraseKey hl, if_pos BEq.refl] theorem getValueCast!_eraseKey [BEq α] [LawfulBEq α] {l : List ((a : α) × β a)} {k a : α} [Inhabited (β a)] (hl : DistinctKeys l) : - getValueCast! a (eraseKey k l) = bif k == a then default else getValueCast! a l := by - simp [getValueCast!_eq_getValueCast?, getValueCast?_eraseKey hl, Bool.apply_cond Option.get!] + getValueCast! a (eraseKey k l) = if k == a then default else getValueCast! a l := by + simp [getValueCast!_eq_getValueCast?, getValueCast?_eraseKey hl, apply_ite Option.get!] theorem getValueCast!_eraseKey_self [BEq α] [LawfulBEq α] {l : List ((a : α) × β a)} {k : α} [Inhabited (β k)] (hl : DistinctKeys l) : getValueCast! k (eraseKey k l) = default := by @@ -1267,9 +1269,9 @@ theorem getValueCast!_eraseKey_self [BEq α] [LawfulBEq α] {l : List ((a : α) theorem getValueCastD_eraseKey [BEq α] [LawfulBEq α] {l : List ((a : α) × β a)} {k a : α} {fallback : β a} (hl : DistinctKeys l) : getValueCastD a (eraseKey k l) fallback = - bif k == a then fallback else getValueCastD a l fallback := by + if k == a then fallback else getValueCastD a l fallback := by simp [getValueCastD_eq_getValueCast?, getValueCast?_eraseKey hl, - Bool.apply_cond (fun x => Option.getD x fallback)] + apply_ite (fun x => Option.getD x fallback)] theorem getValueCastD_eraseKey_self [BEq α] [LawfulBEq α] {l : List ((a : α) × β a)} {k : α} {fallback : β k} (hl : DistinctKeys l) : @@ -1278,8 +1280,8 @@ theorem getValueCastD_eraseKey_self [BEq α] [LawfulBEq α] {l : List ((a : α) theorem getValue!_eraseKey {β : Type v} [BEq α] [PartialEquivBEq α] [Inhabited β] {l : List ((_ : α) × β)} {k a : α} (hl : DistinctKeys l) : - getValue! a (eraseKey k l) = bif k == a then default else getValue! a l := by - simp [getValue!_eq_getValue?, getValue?_eraseKey hl, Bool.apply_cond Option.get!] + getValue! a (eraseKey k l) = if k == a then default else getValue! a l := by + simp [getValue!_eq_getValue?, getValue?_eraseKey hl, apply_ite Option.get!] theorem getValue!_eraseKey_self {β : Type v} [BEq α] [PartialEquivBEq α] [Inhabited β] {l : List ((_ : α) × β)} {k : α} (hl : DistinctKeys l) : @@ -1288,8 +1290,8 @@ theorem getValue!_eraseKey_self {β : Type v} [BEq α] [PartialEquivBEq α] [Inh theorem getValueD_eraseKey {β : Type v} [BEq α] [PartialEquivBEq α] {l : List ((_ : α) × β)} {k a : α} {fallback : β} (hl : DistinctKeys l) : getValueD a (eraseKey k l) fallback = - bif k == a then fallback else getValueD a l fallback := by - simp [getValueD_eq_getValue?, getValue?_eraseKey hl, Bool.apply_cond (fun x => Option.getD x fallback)] + if k == a then fallback else getValueD a l fallback := by + simp [getValueD_eq_getValue?, getValue?_eraseKey hl, apply_ite (fun x => Option.getD x fallback)] theorem getValueD_eraseKey_self {β : Type v} [BEq α] [PartialEquivBEq α] {l : List ((_ : α) × β)} {k : α} {fallback : β} (hl : DistinctKeys l) : @@ -1304,15 +1306,15 @@ theorem getValueCast_eraseKey [BEq α] [LawfulBEq α] {l : List ((a : α) × β (hl : DistinctKeys l) : getValueCast a (eraseKey k l) h = getValueCast a l (containsKey_of_containsKey_eraseKey hl h) := by rw [containsKey_eraseKey hl, Bool.and_eq_true, Bool.not_eq_true'] at h - rw [← Option.some_inj, ← getValueCast?_eq_some_getValueCast, getValueCast?_eraseKey hl, h.1, - cond_false, ← getValueCast?_eq_some_getValueCast] + rw [← Option.some_inj, ← getValueCast?_eq_some_getValueCast, getValueCast?_eraseKey hl, h.1] + simp [← getValueCast?_eq_some_getValueCast] theorem getValue_eraseKey {β : Type v} [BEq α] [PartialEquivBEq α] {l : List ((_ : α) × β)} {k a : α} {h} (hl : DistinctKeys l) : getValue a (eraseKey k l) h = getValue a l (containsKey_of_containsKey_eraseKey hl h) := by rw [containsKey_eraseKey hl, Bool.and_eq_true, Bool.not_eq_true'] at h - rw [← Option.some_inj, ← getValue?_eq_some_getValue, getValue?_eraseKey hl, h.1, cond_false, - ← getValue?_eq_some_getValue] + rw [← Option.some_inj, ← getValue?_eq_some_getValue, getValue?_eraseKey hl, h.1] + simp [← getValue?_eq_some_getValue] theorem getEntry?_of_perm [BEq α] [PartialEquivBEq α] {l l' : List ((a : α) × β a)} {a : α} (hl : DistinctKeys l) (h : Perm l l') : getEntry? a l = getEntry? a l' := by diff --git a/src/Std/Data/DHashMap/Internal/RawLemmas.lean b/src/Std/Data/DHashMap/Internal/RawLemmas.lean index a6e2b90df1e5..585326596508 100644 --- a/src/Std/Data/DHashMap/Internal/RawLemmas.lean +++ b/src/Std/Data/DHashMap/Internal/RawLemmas.lean @@ -145,7 +145,7 @@ theorem isEmpty_eq_size_eq_zero : m.1.isEmpty = (m.1.size == 0) := by simp [Raw.isEmpty] theorem size_insert [EquivBEq α] [LawfulHashable α] {k : α} {v : β k} : - (m.insert k v).1.size = bif m.contains k then m.1.size else m.1.size + 1 := by + (m.insert k v).1.size = if m.contains k then m.1.size else m.1.size + 1 := by simp_to_model using List.length_insertEntry theorem size_le_size_insert [EquivBEq α] [LawfulHashable α] {k : α} {v : β k} : @@ -169,7 +169,7 @@ theorem contains_of_contains_erase [EquivBEq α] [LawfulHashable α] {k a : α} simp_to_model using List.containsKey_of_containsKey_eraseKey theorem size_erase [EquivBEq α] [LawfulHashable α] {k : α} : - (m.erase k).1.size = bif m.contains k then m.1.size - 1 else m.1.size := by + (m.erase k).1.size = if m.contains k then m.1.size - 1 else m.1.size := by simp_to_model using List.length_eraseKey theorem size_erase_le [EquivBEq α] [LawfulHashable α] {k : α} : @@ -215,7 +215,7 @@ theorem get?_eq_none [LawfulBEq α] {a : α} : m.contains a = false → m.get? a simp_to_model using List.getValueCast?_eq_none theorem get?_erase [LawfulBEq α] {k a : α} : - (m.erase k).get? a = bif k == a then none else m.get? a := by + (m.erase k).get? a = if k == a then none else m.get? a := by simp_to_model using List.getValueCast?_eraseKey theorem get?_erase_self [LawfulBEq α] {k : α} : (m.erase k).get? k = none := by @@ -234,7 +234,7 @@ theorem get?_of_isEmpty [EquivBEq α] [LawfulHashable α] {a : α} : simp_to_model; empty theorem get?_insert [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} : - get? (m.insert k v) a = bif k == a then some v else get? m a := by + get? (m.insert k v) a = if k == a then some v else get? m a := by simp_to_model using List.getValue?_insertEntry theorem get?_insert_self [EquivBEq α] [LawfulHashable α] {k : α} {v : β} : @@ -250,7 +250,7 @@ theorem get?_eq_none [EquivBEq α] [LawfulHashable α] {a : α} : simp_to_model using List.getValue?_eq_none.2 theorem get?_erase [EquivBEq α] [LawfulHashable α] {k a : α} : - Const.get? (m.erase k) a = bif k == a then none else get? m a := by + Const.get? (m.erase k) a = if k == a then none else get? m a := by simp_to_model using List.getValue?_eraseKey theorem get?_erase_self [EquivBEq α] [LawfulHashable α] {k : α} : @@ -340,7 +340,7 @@ theorem get!_eq_default [LawfulBEq α] {a : α} [Inhabited (β a)] : simp_to_model using List.getValueCast!_eq_default theorem get!_erase [LawfulBEq α] {k a : α} [Inhabited (β a)] : - (m.erase k).get! a = bif k == a then default else m.get! a := by + (m.erase k).get! a = if k == a then default else m.get! a := by simp_to_model using List.getValueCast!_eraseKey theorem get!_erase_self [LawfulBEq α] {k : α} [Inhabited (β k)] : @@ -372,7 +372,7 @@ theorem get!_of_isEmpty [EquivBEq α] [LawfulHashable α] [Inhabited β] {a : α simp_to_model; empty theorem get!_insert [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} {v : β} : - get! (m.insert k v) a = bif k == a then v else get! m a := by + get! (m.insert k v) a = if k == a then v else get! m a := by simp_to_model using List.getValue!_insertEntry theorem get!_insert_self [EquivBEq α] [LawfulHashable α] [Inhabited β] {k : α} {v : β} : @@ -384,7 +384,7 @@ theorem get!_eq_default [EquivBEq α] [LawfulHashable α] [Inhabited β] {a : α simp_to_model using List.getValue!_eq_default theorem get!_erase [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} : - get! (m.erase k) a = bif k == a then default else get! m a := by + get! (m.erase k) a = if k == a then default else get! m a := by simp_to_model using List.getValue!_eraseKey theorem get!_erase_self [EquivBEq α] [LawfulHashable α] [Inhabited β] {k : α} : @@ -435,7 +435,7 @@ theorem getD_eq_fallback [LawfulBEq α] {a : α} {fallback : β a} : simp_to_model using List.getValueCastD_eq_fallback theorem getD_erase [LawfulBEq α] {k a : α} {fallback : β a} : - (m.erase k).getD a fallback = bif k == a then fallback else m.getD a fallback := by + (m.erase k).getD a fallback = if k == a then fallback else m.getD a fallback := by simp_to_model using List.getValueCastD_eraseKey theorem getD_erase_self [LawfulBEq α] {k : α} {fallback : β k} : @@ -471,7 +471,7 @@ theorem getD_of_isEmpty [EquivBEq α] [LawfulHashable α] {a : α} {fallback : simp_to_model; empty theorem getD_insert [EquivBEq α] [LawfulHashable α] {k a : α} {fallback v : β} : - getD (m.insert k v) a fallback = bif k == a then v else getD m a fallback := by + getD (m.insert k v) a fallback = if k == a then v else getD m a fallback := by simp_to_model using List.getValueD_insertEntry theorem getD_insert_self [EquivBEq α] [LawfulHashable α] {k : α} {fallback v : β} : @@ -483,7 +483,7 @@ theorem getD_eq_fallback [EquivBEq α] [LawfulHashable α] {a : α} {fallback : simp_to_model using List.getValueD_eq_fallback theorem getD_erase [EquivBEq α] [LawfulHashable α] {k a : α} {fallback : β} : - getD (m.erase k) a fallback = bif k == a then fallback else getD m a fallback := by + getD (m.erase k) a fallback = if k == a then fallback else getD m a fallback := by simp_to_model using List.getValueD_eraseKey theorem getD_erase_self [EquivBEq α] [LawfulHashable α] {k : α} {fallback : β} : @@ -539,7 +539,7 @@ theorem contains_of_contains_insertIfNew' [EquivBEq α] [LawfulHashable α] {k a simp_to_model using List.containsKey_of_containsKey_insertEntryIfNew' theorem size_insertIfNew [EquivBEq α] [LawfulHashable α] {k : α} {v : β k} : - (m.insertIfNew k v).1.size = bif m.contains k then m.1.size else m.1.size + 1 := by + (m.insertIfNew k v).1.size = if m.contains k then m.1.size else m.1.size + 1 := by simp_to_model using List.length_insertEntryIfNew theorem size_le_size_insertIfNew [EquivBEq α] [LawfulHashable α] {k : α} {v : β k} : @@ -575,7 +575,7 @@ namespace Const variable {β : Type v} (m : Raw₀ α (fun _ => β)) (h : m.1.WF) theorem get?_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} : - get? (m.insertIfNew k v) a = bif k == a && !m.contains k then some v else get? m a := by + get? (m.insertIfNew k v) a = if k == a ∧ m.contains k = false then some v else get? m a := by simp_to_model using List.getValue?_insertEntryIfNew theorem get_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} {h₁} : @@ -585,12 +585,12 @@ theorem get_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} {h simp_to_model using List.getValue_insertEntryIfNew theorem get!_insertIfNew [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} {v : β} : - get! (m.insertIfNew k v) a = bif k == a && !m.contains k then v else get! m a := by + get! (m.insertIfNew k v) a = if k == a ∧ m.contains k = false then v else get! m a := by simp_to_model using List.getValue!_insertEntryIfNew theorem getD_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {fallback v : β} : getD (m.insertIfNew k v) a fallback = - bif k == a && !m.contains k then v else getD m a fallback := by + if k == a ∧ m.contains k = false then v else getD m a fallback := by simp_to_model using List.getValueD_insertEntryIfNew end Const diff --git a/src/Std/Data/DHashMap/Internal/WF.lean b/src/Std/Data/DHashMap/Internal/WF.lean index 665871db313f..84e3dfac515c 100644 --- a/src/Std/Data/DHashMap/Internal/WF.lean +++ b/src/Std/Data/DHashMap/Internal/WF.lean @@ -472,7 +472,8 @@ theorem wfImp_eraseₘaux [BEq α] [Hashable α] [EquivBEq α] [LawfulHashable buckets_hash_self := isHashSelf_eraseₘaux m a h size_eq := by rw [(toListModel_eraseₘaux m a h).length_eq, eraseₘaux, length_eraseKey, - ← containsₘ_eq_containsKey h, h', cond_true, h.size_eq] + ← containsₘ_eq_containsKey h, h'] + simp [h.size_eq] distinct := h.distinct.eraseKey.perm (toListModel_eraseₘaux m a h) theorem toListModel_perm_eraseKey_of_containsₘ_eq_false [BEq α] [Hashable α] [EquivBEq α] diff --git a/src/Std/Data/DHashMap/Lemmas.lean b/src/Std/Data/DHashMap/Lemmas.lean index cf7661d8a083..f67c4c0e5ef3 100644 --- a/src/Std/Data/DHashMap/Lemmas.lean +++ b/src/Std/Data/DHashMap/Lemmas.lean @@ -102,7 +102,7 @@ theorem size_emptyc : (∅ : DHashMap α β).size = 0 := theorem isEmpty_eq_size_eq_zero : m.isEmpty = (m.size == 0) := rfl theorem size_insert [EquivBEq α] [LawfulHashable α] {k : α} {v : β k} : - (m.insert k v).size = bif m.contains k then m.size else m.size + 1 := + (m.insert k v).size = if k ∈ m then m.size else m.size + 1 := Raw₀.size_insert ⟨m.1, _⟩ m.2 theorem size_le_size_insert [EquivBEq α] [LawfulHashable α] {k : α} {v : β k} : @@ -140,7 +140,7 @@ theorem mem_of_mem_erase [EquivBEq α] [LawfulHashable α] {k a : α} : a ∈ m. simp theorem size_erase [EquivBEq α] [LawfulHashable α] {k : α} : - (m.erase k).size = bif m.contains k then m.size - 1 else m.size := + (m.erase k).size = if k ∈ m then m.size - 1 else m.size := Raw₀.size_erase _ m.2 theorem size_erase_le [EquivBEq α] [LawfulHashable α] {k : α} : (m.erase k).size ≤ m.size := @@ -194,7 +194,7 @@ theorem get?_eq_none [LawfulBEq α] {a : α} : ¬a ∈ m → m.get? a = none := simpa [mem_iff_contains] using get?_eq_none_of_contains_eq_false theorem get?_erase [LawfulBEq α] {k a : α} : - (m.erase k).get? a = bif k == a then none else m.get? a := + (m.erase k).get? a = if k == a then none else m.get? a := Raw₀.get?_erase ⟨m.1, _⟩ m.2 @[simp] @@ -218,7 +218,7 @@ theorem get?_of_isEmpty [EquivBEq α] [LawfulHashable α] {a : α} : Raw₀.Const.get?_of_isEmpty ⟨m.1, _⟩ m.2 theorem get?_insert [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} : - get? (m.insert k v) a = bif k == a then some v else get? m a := + get? (m.insert k v) a = if k == a then some v else get? m a := Raw₀.Const.get?_insert ⟨m.1, _⟩ m.2 @[simp] @@ -238,7 +238,7 @@ theorem get?_eq_none [EquivBEq α] [LawfulHashable α] {a : α } : ¬a ∈ m → simpa [mem_iff_contains] using get?_eq_none_of_contains_eq_false theorem get?_erase [EquivBEq α] [LawfulHashable α] {k a : α} : - Const.get? (m.erase k) a = bif k == a then none else get? m a := + Const.get? (m.erase k) a = if k == a then none else get? m a := Raw₀.Const.get?_erase ⟨m.1, _⟩ m.2 @[simp] @@ -339,7 +339,7 @@ theorem get!_eq_default [LawfulBEq α] {a : α} [Inhabited (β a)] : simpa [mem_iff_contains] using get!_eq_default_of_contains_eq_false theorem get!_erase [LawfulBEq α] {k a : α} [Inhabited (β a)] : - (m.erase k).get! a = bif k == a then default else m.get! a := + (m.erase k).get! a = if k == a then default else m.get! a := Raw₀.get!_erase ⟨m.1, _⟩ m.2 @[simp] @@ -381,7 +381,7 @@ theorem get!_of_isEmpty [EquivBEq α] [LawfulHashable α] [Inhabited β] {a : α Raw₀.Const.get!_of_isEmpty ⟨m.1, _⟩ m.2 theorem get!_insert [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} {v : β} : - get! (m.insert k v) a = bif k == a then v else get! m a := + get! (m.insert k v) a = if k == a then v else get! m a := Raw₀.Const.get!_insert ⟨m.1, _⟩ m.2 @[simp] @@ -398,7 +398,7 @@ theorem get!_eq_default [EquivBEq α] [LawfulHashable α] [Inhabited β] {a : α simpa [mem_iff_contains] using get!_eq_default_of_contains_eq_false theorem get!_erase [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} : - get! (m.erase k) a = bif k == a then default else get! m a := + get! (m.erase k) a = if k == a then default else get! m a := Raw₀.Const.get!_erase ⟨m.1, _⟩ m.2 @[simp] @@ -465,7 +465,7 @@ theorem getD_eq_fallback [LawfulBEq α] {a : α} {fallback : β a} : simpa [mem_iff_contains] using getD_eq_fallback_of_contains_eq_false theorem getD_erase [LawfulBEq α] {k a : α} {fallback : β a} : - (m.erase k).getD a fallback = bif k == a then fallback else m.getD a fallback := + (m.erase k).getD a fallback = if k == a then fallback else m.getD a fallback := Raw₀.getD_erase ⟨m.1, _⟩ m.2 @[simp] @@ -512,7 +512,7 @@ theorem getD_of_isEmpty [EquivBEq α] [LawfulHashable α] {a : α} {fallback : Raw₀.Const.getD_of_isEmpty ⟨m.1, _⟩ m.2 theorem getD_insert [EquivBEq α] [LawfulHashable α] {k a : α} {fallback v : β} : - getD (m.insert k v) a fallback = bif k == a then v else getD m a fallback := + getD (m.insert k v) a fallback = if k == a then v else getD m a fallback := Raw₀.Const.getD_insert ⟨m.1, _⟩ m.2 @[simp] @@ -529,7 +529,7 @@ theorem getD_eq_fallback [EquivBEq α] [LawfulHashable α] {a : α} {fallback : simpa [mem_iff_contains] using getD_eq_fallback_of_contains_eq_false theorem getD_erase [EquivBEq α] [LawfulHashable α] {k a : α} {fallback : β} : - getD (m.erase k) a fallback = bif k == a then fallback else getD m a fallback := + getD (m.erase k) a fallback = if k == a then fallback else getD m a fallback := Raw₀.Const.getD_erase ⟨m.1, _⟩ m.2 @[simp] @@ -611,7 +611,7 @@ theorem mem_of_mem_insertIfNew' [EquivBEq α] [LawfulHashable α] {k a : α} {v simpa [mem_iff_contains, -contains_insertIfNew] using contains_of_contains_insertIfNew' theorem size_insertIfNew [EquivBEq α] [LawfulHashable α] {k : α} {v : β k} : - (m.insertIfNew k v).size = bif m.contains k then m.size else m.size + 1 := + (m.insertIfNew k v).size = if k ∈ m then m.size else m.size + 1 := Raw₀.size_insertIfNew ⟨m.1, _⟩ m.2 theorem size_le_size_insertIfNew [EquivBEq α] [LawfulHashable α] {k : α} {v : β k} : @@ -647,8 +647,9 @@ namespace Const variable {β : Type v} {m : DHashMap α (fun _ => β)} theorem get?_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} : - get? (m.insertIfNew k v) a = bif k == a && !m.contains k then some v else get? m a := - Raw₀.Const.get?_insertIfNew ⟨m.1, _⟩ m.2 + get? (m.insertIfNew k v) a = if k == a ∧ ¬k ∈ m then some v else get? m a := by + simp only [mem_iff_contains, Bool.not_eq_true] + exact Raw₀.Const.get?_insertIfNew ⟨m.1, _⟩ m.2 theorem get_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} {h₁} : get (m.insertIfNew k v) a h₁ = @@ -657,13 +658,15 @@ theorem get_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} {h exact Raw₀.Const.get_insertIfNew ⟨m.1, _⟩ m.2 theorem get!_insertIfNew [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} {v : β} : - get! (m.insertIfNew k v) a = bif k == a && !m.contains k then v else get! m a := - Raw₀.Const.get!_insertIfNew ⟨m.1, _⟩ m.2 + get! (m.insertIfNew k v) a = if k == a ∧ ¬k ∈ m then v else get! m a := by + simp only [mem_iff_contains, Bool.not_eq_true] + exact Raw₀.Const.get!_insertIfNew ⟨m.1, _⟩ m.2 theorem getD_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {fallback v : β} : getD (m.insertIfNew k v) a fallback = - bif k == a && !m.contains k then v else getD m a fallback := - Raw₀.Const.getD_insertIfNew ⟨m.1, _⟩ m.2 + if k == a ∧ ¬k ∈ m then v else getD m a fallback := by + simp only [mem_iff_contains, Bool.not_eq_true] + exact Raw₀.Const.getD_insertIfNew ⟨m.1, _⟩ m.2 end Const diff --git a/src/Std/Data/DHashMap/RawLemmas.lean b/src/Std/Data/DHashMap/RawLemmas.lean index ec60c166a93c..9487f4749c6f 100644 --- a/src/Std/Data/DHashMap/RawLemmas.lean +++ b/src/Std/Data/DHashMap/RawLemmas.lean @@ -150,7 +150,8 @@ theorem isEmpty_eq_size_eq_zero : m.isEmpty = (m.size == 0) := by simp [isEmpty] theorem size_insert [EquivBEq α] [LawfulHashable α] {k : α} {v : β k} : - (m.insert k v).size = bif m.contains k then m.size else m.size + 1 := by + (m.insert k v).size = if k ∈ m then m.size else m.size + 1 := by + simp only [mem_iff_contains] simp_to_raw using Raw₀.size_insert theorem size_le_size_insert [EquivBEq α] [LawfulHashable α] {k : α} {v : β k} : @@ -189,7 +190,8 @@ theorem mem_of_mem_erase [EquivBEq α] [LawfulHashable α] {k a : α} : a ∈ m. simpa [mem_iff_contains] using contains_of_contains_erase h theorem size_erase [EquivBEq α] [LawfulHashable α] {k : α} : - (m.erase k).size = bif m.contains k then m.size - 1 else m.size := by + (m.erase k).size = if k ∈ m then m.size - 1 else m.size := by + simp only [mem_iff_contains] simp_to_raw using Raw₀.size_erase theorem size_erase_le [EquivBEq α] [LawfulHashable α] {k : α} : (m.erase k).size ≤ m.size := by @@ -243,7 +245,7 @@ theorem get?_eq_none [LawfulBEq α] {a : α} : ¬a ∈ m → m.get? a = none := simpa [mem_iff_contains] using get?_eq_none_of_contains_eq_false h theorem get?_erase [LawfulBEq α] {k a : α} : - (m.erase k).get? a = bif k == a then none else m.get? a := by + (m.erase k).get? a = if k == a then none else m.get? a := by simp_to_raw using Raw₀.get?_erase @[simp] @@ -267,7 +269,7 @@ theorem get?_of_isEmpty [EquivBEq α] [LawfulHashable α] {a : α} : simp_to_raw using Raw₀.Const.get?_of_isEmpty ⟨m, _⟩ theorem get?_insert [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} : - get? (m.insert k v) a = bif k == a then some v else get? m a := by + get? (m.insert k v) a = if k == a then some v else get? m a := by simp_to_raw using Raw₀.Const.get?_insert @[simp] @@ -287,7 +289,7 @@ theorem get?_eq_none [EquivBEq α] [LawfulHashable α] {a : α} : ¬a ∈ m → simpa [mem_iff_contains] using get?_eq_none_of_contains_eq_false h theorem get?_erase [EquivBEq α] [LawfulHashable α] {k a : α} : - Const.get? (m.erase k) a = bif k == a then none else get? m a := by + Const.get? (m.erase k) a = if k == a then none else get? m a := by simp_to_raw using Raw₀.Const.get?_erase @[simp] @@ -388,7 +390,7 @@ theorem get!_eq_default [LawfulBEq α] {a : α} [Inhabited (β a)] : simpa [mem_iff_contains] using get!_eq_default_of_contains_eq_false h theorem get!_erase [LawfulBEq α] {k a : α} [Inhabited (β a)] : - (m.erase k).get! a = bif k == a then default else m.get! a := by + (m.erase k).get! a = if k == a then default else m.get! a := by simp_to_raw using Raw₀.get!_erase @[simp] @@ -429,7 +431,7 @@ theorem get!_of_isEmpty [EquivBEq α] [LawfulHashable α] [Inhabited β] {a : α simp_to_raw using Raw₀.Const.get!_of_isEmpty ⟨m, _⟩ theorem get!_insert [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} {v : β} : - get! (m.insert k v) a = bif k == a then v else get! m a := by + get! (m.insert k v) a = if k == a then v else get! m a := by simp_to_raw using Raw₀.Const.get!_insert @[simp] @@ -446,7 +448,7 @@ theorem get!_eq_default [EquivBEq α] [LawfulHashable α] [Inhabited β] {a : α simpa [mem_iff_contains] using get!_eq_default_of_contains_eq_false h theorem get!_erase [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} : - get! (m.erase k) a = bif k == a then default else get! m a := by + get! (m.erase k) a = if k == a then default else get! m a := by simp_to_raw using Raw₀.Const.get!_erase @[simp] @@ -513,7 +515,7 @@ theorem getD_eq_fallback [LawfulBEq α] {a : α} {fallback : β a} : simpa [mem_iff_contains] using getD_eq_fallback_of_contains_eq_false h theorem getD_erase [LawfulBEq α] {k a : α} {fallback : β a} : - (m.erase k).getD a fallback = bif k == a then fallback else m.getD a fallback := by + (m.erase k).getD a fallback = if k == a then fallback else m.getD a fallback := by simp_to_raw using Raw₀.getD_erase @[simp] @@ -559,7 +561,7 @@ theorem getD_of_isEmpty [EquivBEq α] [LawfulHashable α] {a : α} {fallback : simp_to_raw using Raw₀.Const.getD_of_isEmpty ⟨m, _⟩ theorem getD_insert [EquivBEq α] [LawfulHashable α] {k a : α} {fallback v : β} : - getD (m.insert k v) a fallback = bif k == a then v else getD m a fallback := by + getD (m.insert k v) a fallback = if k == a then v else getD m a fallback := by simp_to_raw using Raw₀.Const.getD_insert @[simp] @@ -576,7 +578,7 @@ theorem getD_eq_fallback [EquivBEq α] [LawfulHashable α] {a : α} {fallback : simpa [mem_iff_contains] using getD_eq_fallback_of_contains_eq_false h theorem getD_erase [EquivBEq α] [LawfulHashable α] {k a : α} {fallback : β} : - getD (m.erase k) a fallback = bif k == a then fallback else getD m a fallback := by + getD (m.erase k) a fallback = if k == a then fallback else getD m a fallback := by simp_to_raw using Raw₀.Const.getD_erase @[simp] @@ -658,7 +660,8 @@ theorem mem_of_mem_insertIfNew' [EquivBEq α] [LawfulHashable α] {k a : α} {v simpa [mem_iff_contains] using contains_of_contains_insertIfNew' h theorem size_insertIfNew [EquivBEq α] [LawfulHashable α] {k : α} {v : β k} : - (m.insertIfNew k v).size = bif m.contains k then m.size else m.size + 1 := by + (m.insertIfNew k v).size = if k ∈ m then m.size else m.size + 1 := by + simp only [mem_iff_contains] simp_to_raw using Raw₀.size_insertIfNew theorem size_le_size_insertIfNew [EquivBEq α] [LawfulHashable α] {k : α} {v : β k} : @@ -697,7 +700,8 @@ namespace Const variable {β : Type v} {m : DHashMap.Raw α (fun _ => β)} (h : m.WF) theorem get?_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} : - get? (m.insertIfNew k v) a = bif k == a && !m.contains k then some v else get? m a := by + get? (m.insertIfNew k v) a = if k == a ∧ ¬k ∈ m then some v else get? m a := by + simp only [mem_iff_contains, Bool.not_eq_true] simp_to_raw using Raw₀.Const.get?_insertIfNew theorem get_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} {h₁} : @@ -708,12 +712,14 @@ theorem get_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} {h simp_to_raw using Raw₀.Const.get_insertIfNew ⟨m, _⟩ theorem get!_insertIfNew [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} {v : β} : - get! (m.insertIfNew k v) a = bif k == a && !m.contains k then v else get! m a := by + get! (m.insertIfNew k v) a = if k == a ∧ ¬k ∈ m then v else get! m a := by + simp only [mem_iff_contains, Bool.not_eq_true] simp_to_raw using Raw₀.Const.get!_insertIfNew theorem getD_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {fallback v : β} : getD (m.insertIfNew k v) a fallback = - bif k == a && !m.contains k then v else getD m a fallback := by + if k == a ∧ ¬k ∈ m then v else getD m a fallback := by + simp only [mem_iff_contains, Bool.not_eq_true] simp_to_raw using Raw₀.Const.getD_insertIfNew end Const diff --git a/src/Std/Data/HashMap/Lemmas.lean b/src/Std/Data/HashMap/Lemmas.lean index b271c7926321..88bd978a199f 100644 --- a/src/Std/Data/HashMap/Lemmas.lean +++ b/src/Std/Data/HashMap/Lemmas.lean @@ -110,7 +110,7 @@ theorem isEmpty_eq_size_eq_zero : m.isEmpty = (m.size == 0) := DHashMap.isEmpty_eq_size_eq_zero theorem size_insert [EquivBEq α] [LawfulHashable α] {k : α} {v : β} : - (m.insert k v).size = bif m.contains k then m.size else m.size + 1 := + (m.insert k v).size = if k ∈ m then m.size else m.size + 1 := DHashMap.size_insert theorem size_le_size_insert [EquivBEq α] [LawfulHashable α] {k : α} {v : β} : @@ -148,7 +148,7 @@ theorem mem_of_mem_erase [EquivBEq α] [LawfulHashable α] {k a : α} : a ∈ m. DHashMap.mem_of_mem_erase theorem size_erase [EquivBEq α] [LawfulHashable α] {k : α} : - (m.erase k).size = bif m.contains k then m.size - 1 else m.size := + (m.erase k).size = if k ∈ m then m.size - 1 else m.size := DHashMap.size_erase theorem size_erase_le [EquivBEq α] [LawfulHashable α] {k : α} : (m.erase k).size ≤ m.size := @@ -185,7 +185,7 @@ theorem getElem?_of_isEmpty [EquivBEq α] [LawfulHashable α] {a : α} : DHashMap.Const.get?_of_isEmpty theorem getElem?_insert [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} : - (m.insert k v)[a]? = bif k == a then some v else m[a]? := + (m.insert k v)[a]? = if k == a then some v else m[a]? := DHashMap.Const.get?_insert @[simp] @@ -205,7 +205,7 @@ theorem getElem?_eq_none [EquivBEq α] [LawfulHashable α] {a : α} : ¬a ∈ m DHashMap.Const.get?_eq_none theorem getElem?_erase [EquivBEq α] [LawfulHashable α] {k a : α} : - (m.erase k)[a]? = bif k == a then none else m[a]? := + (m.erase k)[a]? = if k == a then none else m[a]? := DHashMap.Const.get?_erase @[simp] @@ -251,7 +251,7 @@ theorem getElem!_of_isEmpty [EquivBEq α] [LawfulHashable α] [Inhabited β] {a DHashMap.Const.get!_of_isEmpty theorem getElem!_insert [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} {v : β} : - (m.insert k v)[a]! = bif k == a then v else m[a]! := + (m.insert k v)[a]! = if k == a then v else m[a]! := DHashMap.Const.get!_insert @[simp] @@ -268,7 +268,7 @@ theorem getElem!_eq_default [EquivBEq α] [LawfulHashable α] [Inhabited β] {a DHashMap.Const.get!_eq_default theorem getElem!_erase [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} : - (m.erase k)[a]! = bif k == a then default else m[a]! := + (m.erase k)[a]! = if k == a then default else m[a]! := DHashMap.Const.get!_erase @[simp] @@ -310,7 +310,7 @@ theorem getD_of_isEmpty [EquivBEq α] [LawfulHashable α] {a : α} {fallback : DHashMap.Const.getD_of_isEmpty theorem getD_insert [EquivBEq α] [LawfulHashable α] {k a : α} {fallback v : β} : - (m.insert k v).getD a fallback = bif k == a then v else m.getD a fallback := + (m.insert k v).getD a fallback = if k == a then v else m.getD a fallback := DHashMap.Const.getD_insert @[simp] @@ -327,7 +327,7 @@ theorem getD_eq_fallback [EquivBEq α] [LawfulHashable α] {a : α} {fallback : DHashMap.Const.getD_eq_fallback theorem getD_erase [EquivBEq α] [LawfulHashable α] {k a : α} {fallback : β} : - (m.erase k).getD a fallback = bif k == a then fallback else m.getD a fallback := + (m.erase k).getD a fallback = if k == a then fallback else m.getD a fallback := DHashMap.Const.getD_erase @[simp] @@ -403,7 +403,7 @@ theorem mem_of_mem_insertIfNew' [EquivBEq α] [LawfulHashable α] {k a : α} {v DHashMap.mem_of_mem_insertIfNew' theorem size_insertIfNew [EquivBEq α] [LawfulHashable α] {k : α} {v : β} : - (m.insertIfNew k v).size = bif m.contains k then m.size else m.size + 1 := + (m.insertIfNew k v).size = if k ∈ m then m.size else m.size + 1 := DHashMap.size_insertIfNew theorem size_le_size_insertIfNew [EquivBEq α] [LawfulHashable α] {k : α} {v : β} : @@ -411,7 +411,7 @@ theorem size_le_size_insertIfNew [EquivBEq α] [LawfulHashable α] {k : α} {v : DHashMap.size_le_size_insertIfNew theorem getElem?_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} : - (m.insertIfNew k v)[a]? = bif k == a && !m.contains k then some v else m[a]? := + (m.insertIfNew k v)[a]? = if k == a ∧ ¬k ∈ m then some v else m[a]? := DHashMap.Const.get?_insertIfNew theorem getElem_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} {h₁} : @@ -420,12 +420,12 @@ theorem getElem_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β DHashMap.Const.get_insertIfNew (h₁ := h₁) theorem getElem!_insertIfNew [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} {v : β} : - (m.insertIfNew k v)[a]! = bif k == a && !m.contains k then v else m[a]! := + (m.insertIfNew k v)[a]! = if k == a ∧ ¬k ∈ m then v else m[a]! := DHashMap.Const.get!_insertIfNew theorem getD_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {fallback v : β} : (m.insertIfNew k v).getD a fallback = - bif k == a && !m.contains k then v else m.getD a fallback := + if k == a ∧ ¬k ∈ m then v else m.getD a fallback := DHashMap.Const.getD_insertIfNew @[simp] diff --git a/src/Std/Data/HashMap/RawLemmas.lean b/src/Std/Data/HashMap/RawLemmas.lean index 96fea3069c9d..76a7adabd2cf 100644 --- a/src/Std/Data/HashMap/RawLemmas.lean +++ b/src/Std/Data/HashMap/RawLemmas.lean @@ -109,7 +109,7 @@ theorem isEmpty_eq_size_eq_zero : m.isEmpty = (m.size == 0) := DHashMap.Raw.isEmpty_eq_size_eq_zero theorem size_insert [EquivBEq α] [LawfulHashable α] {k : α} {v : β} : - (m.insert k v).size = bif m.contains k then m.size else m.size + 1 := + (m.insert k v).size = if k ∈ m then m.size else m.size + 1 := DHashMap.Raw.size_insert h.out theorem size_le_size_insert [EquivBEq α] [LawfulHashable α] {k : α} {v : β} : @@ -147,7 +147,7 @@ theorem mem_of_mem_erase [EquivBEq α] [LawfulHashable α] {k a : α} : a ∈ m. DHashMap.Raw.mem_of_mem_erase h.out theorem size_erase [EquivBEq α] [LawfulHashable α] {k : α} : - (m.erase k).size = bif m.contains k then m.size - 1 else m.size := + (m.erase k).size = if k ∈ m then m.size - 1 else m.size := DHashMap.Raw.size_erase h.out theorem size_erase_le [EquivBEq α] [LawfulHashable α] {k : α} : (m.erase k).size ≤ m.size := @@ -184,7 +184,7 @@ theorem getElem?_of_isEmpty [EquivBEq α] [LawfulHashable α] {a : α} : DHashMap.Raw.Const.get?_of_isEmpty h.out theorem getElem?_insert [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} : - (m.insert k v)[a]? = bif k == a then some v else m[a]? := + (m.insert k v)[a]? = if k == a then some v else m[a]? := DHashMap.Raw.Const.get?_insert h.out @[simp] @@ -204,7 +204,7 @@ theorem getElem?_eq_none [EquivBEq α] [LawfulHashable α] {a : α} : ¬a ∈ m DHashMap.Raw.Const.get?_eq_none h.out theorem getElem?_erase [EquivBEq α] [LawfulHashable α] {k a : α} : - (m.erase k)[a]? = bif k == a then none else m[a]? := + (m.erase k)[a]? = if k == a then none else m[a]? := DHashMap.Raw.Const.get?_erase h.out @[simp] @@ -250,7 +250,7 @@ theorem getElem!_of_isEmpty [EquivBEq α] [LawfulHashable α] [Inhabited β] {a DHashMap.Raw.Const.get!_of_isEmpty h.out theorem getElem!_insert [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} {v : β} : - (m.insert k v)[a]! = bif k == a then v else m[a]! := + (m.insert k v)[a]! = if k == a then v else m[a]! := DHashMap.Raw.Const.get!_insert h.out @[simp] @@ -267,7 +267,7 @@ theorem getElem!_eq_default [EquivBEq α] [LawfulHashable α] [Inhabited β] {a DHashMap.Raw.Const.get!_eq_default h.out theorem getElem!_erase [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} : - (m.erase k)[a]! = bif k == a then default else m[a]! := + (m.erase k)[a]! = if k == a then default else m[a]! := DHashMap.Raw.Const.get!_erase h.out @[simp] @@ -308,7 +308,7 @@ theorem getD_of_isEmpty [EquivBEq α] [LawfulHashable α] {a : α} {fallback : DHashMap.Raw.Const.getD_of_isEmpty h.out theorem getD_insert [EquivBEq α] [LawfulHashable α] {k a : α} {fallback v : β} : - (m.insert k v).getD a fallback = bif k == a then v else m.getD a fallback := + (m.insert k v).getD a fallback = if k == a then v else m.getD a fallback := DHashMap.Raw.Const.getD_insert h.out @[simp] @@ -325,7 +325,7 @@ theorem getD_eq_fallback [EquivBEq α] [LawfulHashable α] {a : α} {fallback : DHashMap.Raw.Const.getD_eq_fallback h.out theorem getD_erase [EquivBEq α] [LawfulHashable α] {k a : α} {fallback : β} : - (m.erase k).getD a fallback = bif k == a then fallback else m.getD a fallback := + (m.erase k).getD a fallback = if k == a then fallback else m.getD a fallback := DHashMap.Raw.Const.getD_erase h.out @[simp] @@ -401,7 +401,7 @@ theorem mem_of_mem_insertIfNew' [EquivBEq α] [LawfulHashable α] {k a : α} {v DHashMap.Raw.mem_of_mem_insertIfNew' h.out theorem size_insertIfNew [EquivBEq α] [LawfulHashable α] {k : α} {v : β} : - (m.insertIfNew k v).size = bif m.contains k then m.size else m.size + 1 := + (m.insertIfNew k v).size = if k ∈ m then m.size else m.size + 1 := DHashMap.Raw.size_insertIfNew h.out theorem size_le_size_insertIfNew [EquivBEq α] [LawfulHashable α] {k : α} {v : β} : @@ -409,7 +409,7 @@ theorem size_le_size_insertIfNew [EquivBEq α] [LawfulHashable α] {k : α} {v : DHashMap.Raw.size_le_size_insertIfNew h.out theorem getElem?_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} : - (m.insertIfNew k v)[a]? = bif k == a && !m.contains k then some v else m[a]? := + (m.insertIfNew k v)[a]? = if k == a ∧ ¬k ∈ m then some v else m[a]? := DHashMap.Raw.Const.get?_insertIfNew h.out theorem getElem_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β} {h₁} : @@ -418,12 +418,12 @@ theorem getElem_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {v : β DHashMap.Raw.Const.get_insertIfNew h.out (h₁ := h₁) theorem getElem!_insertIfNew [EquivBEq α] [LawfulHashable α] [Inhabited β] {k a : α} {v : β} : - (m.insertIfNew k v)[a]! = bif k == a && !m.contains k then v else m[a]! := + (m.insertIfNew k v)[a]! = if k == a ∧ ¬k ∈ m then v else m[a]! := DHashMap.Raw.Const.get!_insertIfNew h.out theorem getD_insertIfNew [EquivBEq α] [LawfulHashable α] {k a : α} {fallback v : β} : (m.insertIfNew k v).getD a fallback = - bif k == a && !m.contains k then v else m.getD a fallback := + if k == a ∧ ¬k ∈ m then v else m.getD a fallback := DHashMap.Raw.Const.getD_insertIfNew h.out @[simp] diff --git a/src/Std/Data/HashSet/Lemmas.lean b/src/Std/Data/HashSet/Lemmas.lean index 01f8356e2ab1..bee599c20d2d 100644 --- a/src/Std/Data/HashSet/Lemmas.lean +++ b/src/Std/Data/HashSet/Lemmas.lean @@ -102,7 +102,7 @@ theorem isEmpty_eq_size_eq_zero : m.isEmpty = (m.size == 0) := HashMap.isEmpty_eq_size_eq_zero theorem size_insert [EquivBEq α] [LawfulHashable α] {k : α} : - (m.insert k).size = bif m.contains k then m.size else m.size + 1 := + (m.insert k).size = if k ∈ m then m.size else m.size + 1 := HashMap.size_insertIfNew theorem size_le_size_insert [EquivBEq α] [LawfulHashable α] {k : α} : m.size ≤ (m.insert k).size := @@ -139,7 +139,7 @@ theorem mem_of_mem_erase [EquivBEq α] [LawfulHashable α] {k a : α} : a ∈ m. HashMap.mem_of_mem_erase theorem size_erase [EquivBEq α] [LawfulHashable α] {k : α} : - (m.erase k).size = bif m.contains k then m.size - 1 else m.size := + (m.erase k).size = if k ∈ m then m.size - 1 else m.size := HashMap.size_erase theorem size_erase_le [EquivBEq α] [LawfulHashable α] {k : α} : (m.erase k).size ≤ m.size := diff --git a/src/Std/Data/HashSet/RawLemmas.lean b/src/Std/Data/HashSet/RawLemmas.lean index de06cfe8d4b5..40e3315c380b 100644 --- a/src/Std/Data/HashSet/RawLemmas.lean +++ b/src/Std/Data/HashSet/RawLemmas.lean @@ -102,7 +102,7 @@ theorem isEmpty_eq_size_eq_zero : m.isEmpty = (m.size == 0) := HashMap.Raw.isEmpty_eq_size_eq_zero theorem size_insert [EquivBEq α] [LawfulHashable α] {k : α} : - (m.insert k).size = bif m.contains k then m.size else m.size + 1 := + (m.insert k).size = if k ∈ m then m.size else m.size + 1 := HashMap.Raw.size_insertIfNew h.out theorem size_le_size_insert [EquivBEq α] [LawfulHashable α] {k : α} : m.size ≤ (m.insert k).size := @@ -139,7 +139,7 @@ theorem mem_of_mem_erase [EquivBEq α] [LawfulHashable α] {k a : α} : a ∈ m. HashMap.Raw.mem_of_mem_erase h.out theorem size_erase [EquivBEq α] [LawfulHashable α] {k : α} : - (m.erase k).size = bif m.contains k then m.size - 1 else m.size := + (m.erase k).size = if k ∈ m then m.size - 1 else m.size := HashMap.Raw.size_erase h.out theorem size_erase_le [EquivBEq α] [LawfulHashable α] {k : α} : (m.erase k).size ≤ m.size :=