@@ -201,7 +201,7 @@ theorem toListModel_updateAllBuckets {m : Raw₀ α β} {f : AssocList α β →
201
201
omega
202
202
rw [updateAllBuckets, toListModel, Array.toList_map, List.flatMap_eq_foldl, List.foldl_map,
203
203
toListModel, List.flatMap_eq_foldl]
204
- suffices ∀ (l : List (AssocList α β)) (l' : List ((a: α) × δ a)) (l'' : List ((a : α) × β a)),
204
+ suffices ∀ (l : List (AssocList α β)) (l' : List ((a : α) × δ a)) (l'' : List ((a : α) × β a)),
205
205
Perm (g l'') l' →
206
206
Perm (l.foldl (fun acc a => acc ++ (f a).toList) l')
207
207
(g (l.foldl (fun acc a => acc ++ a.toList) l'')) by
@@ -378,6 +378,12 @@ def mapₘ (m : Raw₀ α β) (f : (a : α) → β a → δ a) : Raw₀ α δ :=
378
378
def filterₘ (m : Raw₀ α β) (f : (a : α) → β a → Bool) : Raw₀ α β :=
379
379
⟨withComputedSize (updateAllBuckets m.1 .buckets fun l => l.filter f), by simpa using m.2 ⟩
380
380
381
+ /-- Internal implementation detail of the hash map -/
382
+ def insertListₘ [BEq α] [Hashable α] (m : Raw₀ α β) (l : List ((a : α) × β a)) : Raw₀ α β :=
383
+ match l with
384
+ | .nil => m
385
+ | .cons hd tl => insertListₘ (m.insert hd.1 hd.2 ) tl
386
+
381
387
section
382
388
383
389
variable {β : Type v}
@@ -398,6 +404,20 @@ def Const.getDₘ [BEq α] [Hashable α] (m : Raw₀ α (fun _ => β)) (a : α)
398
404
def Const.get!ₘ [BEq α] [Hashable α] [Inhabited β] (m : Raw₀ α (fun _ => β)) (a : α) : β :=
399
405
(Const.get?ₘ m a).get!
400
406
407
+ /-- Internal implementation detail of the hash map -/
408
+ def Const.insertListₘ [BEq α] [Hashable α] (m : Raw₀ α (fun _ => β)) (l: List (α × β)) :
409
+ Raw₀ α (fun _ => β) :=
410
+ match l with
411
+ | .nil => m
412
+ | .cons hd tl => insertListₘ (m.insert hd.1 hd.2 ) tl
413
+
414
+ /-- Internal implementation detail of the hash map -/
415
+ def Const.insertListIfNewUnitₘ [BEq α] [Hashable α] (m : Raw₀ α (fun _ => Unit)) (l: List α) :
416
+ Raw₀ α (fun _ => Unit) :=
417
+ match l with
418
+ | .nil => m
419
+ | .cons hd tl => insertListIfNewUnitₘ (m.insertIfNew hd ()) tl
420
+
401
421
end
402
422
403
423
/-! # Equivalence between model functions and real implementations -/
@@ -569,6 +589,19 @@ theorem map_eq_mapₘ (m : Raw₀ α β) (f : (a : α) → β a → δ a) :
569
589
theorem filter_eq_filterₘ (m : Raw₀ α β) (f : (a : α) → β a → Bool) :
570
590
m.filter f = m.filterₘ f := rfl
571
591
592
+ theorem insertMany_eq_insertListₘ [BEq α] [Hashable α](m : Raw₀ α β) (l : List ((a : α) × β a)) : insertMany m l = insertListₘ m l := by
593
+ simp only [insertMany, Id.run, Id.pure_eq, Id.bind_eq, List.forIn_yield_eq_foldl]
594
+ suffices ∀ (t : { m' // ∀ (P : Raw₀ α β → Prop ),
595
+ (∀ {m'' : Raw₀ α β} {a : α} {b : β a}, P m'' → P (m''.insert a b)) → P m → P m' }),
596
+ (List.foldl (fun m' p => ⟨m'.val.insert p.1 p.2 , fun P h₁ h₂ => h₁ (m'.2 _ h₁ h₂)⟩) t l).val =
597
+ t.val.insertListₘ l from this _
598
+ intro t
599
+ induction l generalizing m with
600
+ | nil => simp [insertListₘ]
601
+ | cons hd tl ih =>
602
+ simp only [List.foldl_cons, insertListₘ]
603
+ apply ih
604
+
572
605
section
573
606
574
607
variable {β : Type v}
@@ -599,6 +632,36 @@ theorem Const.getThenInsertIfNew?_eq_get?ₘ [BEq α] [Hashable α] (m : Raw₀
599
632
dsimp only [Array.ugetElem_eq_getElem, Array.uset]
600
633
split <;> simp_all [-getValue?_eq_none]
601
634
635
+ theorem Const.insertMany_eq_insertListₘ [BEq α] [Hashable α] (m : Raw₀ α (fun _ => β))
636
+ (l: List (α × β)):
637
+ (Const.insertMany m l).1 = Const.insertListₘ m l := by
638
+ simp only [insertMany, Id.run, Id.pure_eq, Id.bind_eq, List.forIn_yield_eq_foldl]
639
+ suffices ∀ (t : { m' // ∀ (P : Raw₀ α (fun _ => β) → Prop ),
640
+ (∀ {m'' : Raw₀ α (fun _ => β)} {a : α} {b : β}, P m'' → P (m''.insert a b)) → P m → P m' }),
641
+ (List.foldl (fun m' p => ⟨m'.val.insert p.1 p.2 , fun P h₁ h₂ => h₁ (m'.2 _ h₁ h₂)⟩) t l).val =
642
+ Const.insertListₘ t.val l from this _
643
+ intro t
644
+ induction l generalizing m with
645
+ | nil => simp [insertListₘ]
646
+ | cons hd tl ih =>
647
+ simp only [List.foldl_cons, insertListₘ]
648
+ apply ih
649
+
650
+ theorem Const.insertManyIfNewUnit_eq_insertListIfNewUnitₘ [BEq α] [Hashable α]
651
+ (m : Raw₀ α (fun _ => Unit)) (l: List α):
652
+ (Const.insertManyIfNewUnit m l).1 = Const.insertListIfNewUnitₘ m l := by
653
+ simp only [insertManyIfNewUnit, Id.run, Id.pure_eq, Id.bind_eq, List.forIn_yield_eq_foldl]
654
+ suffices ∀ (t : { m' // ∀ (P : Raw₀ α (fun _ => Unit) → Prop ),
655
+ (∀ {m'' a b}, P m'' → P (m''.insertIfNew a b)) → P m → P m'}),
656
+ (List.foldl (fun m' p => ⟨m'.val.insertIfNew p (), fun P h₁ h₂ => h₁ (m'.2 _ h₁ h₂)⟩) t l).val =
657
+ Const.insertListIfNewUnitₘ t.val l from this _
658
+ intro t
659
+ induction l generalizing m with
660
+ | nil => simp [insertListIfNewUnitₘ]
661
+ | cons hd tl ih =>
662
+ simp only [List.foldl_cons, insertListIfNewUnitₘ]
663
+ apply ih
664
+
602
665
end
603
666
604
667
end Raw₀
0 commit comments