Skip to content

Commit bd4afe1

Browse files
committed
chore: refactor
1 parent 80727b5 commit bd4afe1

File tree

5 files changed

+199
-182
lines changed

5 files changed

+199
-182
lines changed

src/Std/Data/DTreeMap/Internal/Lemmas.lean

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7945,14 +7945,14 @@ end Const
79457945

79467946
end map
79477947

7948-
theorem prune_LE_eq_filter {α β} [Ord α] [TransOrd α] (t : Internal.Impl α β) (ord_t : t.Ordered) (lower_bound : α) :
7949-
(t.prune_LE ord_t lower_bound).toList = t.toList.filter (fun e => (compare e.fst lower_bound).isGE) := by
7948+
theorem pruneLE_eq_filter {α β} [Ord α] [TransOrd α] (t : Internal.Impl α β) (ord_t : t.Ordered) (lowerBound : α) :
7949+
(t.pruneLE lowerBound).toList = t.toList.filter (fun e => (compare e.fst lowerBound).isGE) := by
79507950
induction t
79517951
case leaf =>
7952-
simp only [prune_LE, toList_eq_toListModel, toListModel_leaf, List.filter_nil]
7952+
simp only [pruneLE, toList_eq_toListModel, toListModel_leaf, List.filter_nil]
79537953
case inner _ k v l r l_ih r_ih =>
7954-
simp only [prune_LE, toList_eq_toListModel, toListModel_inner, List.filter_append]
7955-
generalize heq : compare lower_bound k = x
7954+
simp only [pruneLE, toList_eq_toListModel, toListModel_inner, List.filter_append]
7955+
generalize heq : compare lowerBound k = x
79567956
cases x
79577957
case lt =>
79587958
simp only [toListModel_inner]
@@ -7972,7 +7972,7 @@ theorem prune_LE_eq_filter {α β} [Ord α] [TransOrd α] (t : Internal.Impl α
79727972
simp only [toListModel_inner, toListModel_leaf, List.nil_append, List.filter]
79737973
rw [OrientedCmp.eq_comm] at heq
79747974
simp only [heq, Ordering.isGE_eq]
7975-
suffices new_goal : List.filter (fun e => (compare e.fst lower_bound).isGE) l.toListModel = [] from by
7975+
suffices new_goal : List.filter (fun e => (compare e.fst lowerBound).isGE) l.toListModel = [] from by
79767976
simp only [new_goal, List.nil_append, List.cons.injEq, true_and]
79777977
symm
79787978
apply List.filter_eq_self.2
@@ -7989,23 +7989,25 @@ theorem prune_LE_eq_filter {α β} [Ord α] [TransOrd α] (t : Internal.Impl α
79897989
simp only [List.filter]
79907990
rw [OrientedOrd.eq_swap, Ordering.swap_eq_gt] at heq
79917991
rw [heq]
7992-
suffices new_goal : List.filter (fun e => (compare e.fst lower_bound).isGE) l.toListModel = [] from by
7993-
simp only [new_goal, Ordering.isGE_lt, List.nil_append]
7992+
simp
7993+
suffices new_goal : List.filter (fun e => (compare e.fst lowerBound).isGE) l.toListModel = [] from by
7994+
simp only [new_goal, List.nil_append]
79947995
simp only [toList_eq_toListModel] at r_ih
79957996
apply r_ih
7997+
exact Internal.Impl.Ordered.right ord_t
79967998
rw [List.filter_eq_nil_iff]
79977999
intro a mem
79988000
simp only [Bool.not_eq_true, Ordering.isGE_eq_false]
79998001
exact TransCmp.lt_trans (Internal.Impl.Ordered.compare_left ord_t mem) heq
80008002

8001-
theorem prune_LT_eq_filter {α β} [Ord α] [TransOrd α] (t : Internal.Impl α β) (ord_t : t.Ordered) (lower_bound : α) :
8002-
(t.prune_LT ord_t lower_bound).toList = t.toList.filter (fun e => (compare e.fst lower_bound).isGT) := by
8003+
theorem pruneLT_eq_filter {α β} [Ord α] [TransOrd α] (t : Internal.Impl α β) (ord_t : t.Ordered) (lowerBound : α) :
8004+
(t.pruneLT lowerBound).toList = t.toList.filter (fun e => (compare e.fst lowerBound).isGT) := by
80038005
induction t
80048006
case leaf =>
8005-
simp only [prune_LT, toList_eq_toListModel, toListModel_leaf, List.filter_nil]
8007+
simp only [pruneLT, toList_eq_toListModel, toListModel_leaf, List.filter_nil]
80068008
case inner _ k v l r l_ih r_ih =>
8007-
simp only [prune_LT, toList_eq_toListModel, toListModel_inner, List.filter_append]
8008-
generalize heq : compare lower_bound k = x
8009+
simp only [pruneLT, toList_eq_toListModel, toListModel_inner, List.filter_append]
8010+
generalize heq : compare lowerBound k = x
80098011
cases x
80108012
case lt =>
80118013
simp
@@ -8025,8 +8027,8 @@ theorem prune_LT_eq_filter {α β} [Ord α] [TransOrd α] (t : Internal.Impl α
80258027
simp only [List.filter]
80268028
rw [OrientedCmp.eq_comm] at heq
80278029
rw [heq]
8028-
suffices new_goal : List.filter (fun e => (compare e.fst lower_bound).isGT) l.toListModel = [] ∧
8029-
List.filter (fun e => (compare e.fst lower_bound).isGT) r.toListModel = r.toListModel from by
8030+
suffices new_goal : List.filter (fun e => (compare e.fst lowerBound).isGT) l.toListModel = [] ∧
8031+
List.filter (fun e => (compare e.fst lowerBound).isGT) r.toListModel = r.toListModel from by
80308032
simp only [new_goal, Ordering.isGT_eq, List.nil_append]
80318033
apply And.intro
80328034
. rw [List.filter_eq_nil_iff]

src/Std/Data/DTreeMap/Internal/Operations.lean

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -517,32 +517,30 @@ def insertMany! [Ord α] {ρ : Type w} [ForIn Id ρ ((a : α) × β a)] (t : Imp
517517
-/
518518

519519
/--
520-
Removes all elements with key less than or equal to `lower_bound`.
520+
Removes all elements with key less than or equal to `lowerBound`.
521521
Does not modify size information stored in the tree.
522522
-/
523-
def prune_LE {α β} [Ord α] (t : Internal.Impl α β)
524-
(ord_t : t.Ordered) (lower_bound : α) : Internal.Impl α β :=
523+
def pruneLE {α β} [Ord α] (t : Internal.Impl α β) (lowerBound : α) : Internal.Impl α β :=
525524
match t with
526525
| .leaf => .leaf
527526
| .inner sz k v l r =>
528-
match compare lower_bound k with
529-
| .lt => .inner sz k v (l.prune_LE (Internal.Impl.Ordered.left ord_t) lower_bound) r
527+
match compare lowerBound k with
528+
| .lt => .inner sz k v (l.pruneLE lowerBound) r
530529
| .eq => .inner sz k v .leaf r
531-
| .gt => r.prune_LE (Internal.Impl.Ordered.right ord_t) lower_bound
530+
| .gt => r.pruneLE lowerBound
532531

533532
/--
534-
Removes all elements with key less than to `lower_bound`.
533+
Removes all elements with key less than to `lowerBound`.
535534
Does not modify size information stored in the tree.
536535
-/
537-
def prune_LT {α β} [Ord α] (t : Internal.Impl α β)
538-
(ord_t : t.Ordered) (lower_bound : α) : Internal.Impl α β :=
536+
def pruneLT {α β} [Ord α] (t : Internal.Impl α β) (lowerBound : α) : Internal.Impl α β :=
539537
match t with
540538
| .leaf => .leaf
541539
| .inner sz k v l r =>
542-
match compare lower_bound k with
543-
| .lt => .inner sz k v (l.prune_LT (Internal.Impl.Ordered.left ord_t) lower_bound) r
540+
match compare lowerBound k with
541+
| .lt => .inner sz k v (l.pruneLT lowerBound) r
544542
| .eq => r
545-
| .gt => r.prune_LT (Internal.Impl.Ordered.right ord_t) lower_bound
543+
| .gt => r.pruneLT lowerBound
546544

547545
namespace Const
548546

0 commit comments

Comments
 (0)