Skip to content
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
e7c3a35
push code
wkrozowski Oct 14, 2025
4b4aba5
stash work
wkrozowski Oct 14, 2025
fb6192e
push intermediate work
wkrozowski Oct 14, 2025
02b00a4
push intermediate work
wkrozowski Oct 15, 2025
7d1fc8e
First slice iterator correct
wkrozowski Oct 16, 2025
8767892
further verification work
wkrozowski Oct 16, 2025
71fecdd
progress
wkrozowski Oct 16, 2025
e957481
end of day push
wkrozowski Oct 16, 2025
05ba72e
left open iterator work
wkrozowski Oct 17, 2025
41780f7
Rcc slice
wkrozowski Oct 17, 2025
9f131d4
some golfing
wkrozowski Oct 17, 2025
87b9017
Add rxo iterator
wkrozowski Oct 17, 2025
c0e9549
Add Raw iterators
wkrozowski Oct 20, 2025
3c3bed7
minor changes
wkrozowski Oct 20, 2025
e6821e0
Add productiveness relation
wkrozowski Oct 20, 2025
e14d54c
Add `DTreeMap` iterators
wkrozowski Oct 20, 2025
83c2127
Add productiveness relation for the ordinary zipper
wkrozowski Oct 20, 2025
fe870d6
fix
wkrozowski Oct 20, 2025
a573195
Further refactor
wkrozowski Oct 21, 2025
0e59f32
Add rco
wkrozowski Oct 21, 2025
8618bca
add roc
wkrozowski Oct 21, 2025
e8e797b
Add rci
wkrozowski Oct 21, 2025
76f4f44
Add roi
wkrozowski Oct 21, 2025
c56bab2
Rii slice now works
wkrozowski Oct 21, 2025
f51bed2
module system issues
wkrozowski Oct 21, 2025
1568a15
see if it buiilds
wkrozowski Oct 21, 2025
72f6450
and slices for raw dtreemaps and their correctenss lemmas
wkrozowski Oct 21, 2025
fa7fcb8
chore: add imports to `Raw.lean`
wkrozowski Oct 21, 2025
5c3750d
Add 'DTreeMap' slices
wkrozowski Oct 21, 2025
9ef6ac3
some imports editing
wkrozowski Oct 21, 2025
351c2c1
dirty fix
wkrozowski Oct 21, 2025
123dcb1
Fix some imports
wkrozowski Oct 22, 2025
fcce3fa
Add imports to Raw
wkrozowski Oct 22, 2025
166f413
chore: rewrite map lemma
wkrozowski Oct 27, 2025
619cf51
minor cleanup
wkrozowski Oct 27, 2025
06ce30a
Rename correctness lemmas names
wkrozowski Oct 27, 2025
80727b5
Add simp lemmas to non-raw slice instances
wkrozowski Oct 27, 2025
bd4afe1
chore: refactor
wkrozowski Oct 27, 2025
b0cf25d
chore: rearrange files a bit
wkrozowski Oct 27, 2025
9278457
chore: further refactor
wkrozowski Oct 27, 2025
816e158
chore: remove productiveness instances
wkrozowski Oct 27, 2025
3e439f7
chore : fix user facing instances
wkrozowski Oct 27, 2025
b41c25e
chore: add comments
wkrozowski Oct 27, 2025
a7b5efc
chore: further renaming
wkrozowski Oct 27, 2025
c4dc8c7
Fix imports
wkrozowski Oct 28, 2025
465b91f
Add TreeMap iterators
wkrozowski Oct 28, 2025
f32d394
fix imports
wkrozowski Oct 28, 2025
8a91d04
push
wkrozowski Oct 28, 2025
298b7eb
chore: refactor
wkrozowski Oct 30, 2025
b9e7575
chore: refactor
wkrozowski Oct 30, 2025
008adc4
chore: refactor
wkrozowski Oct 30, 2025
f19e38b
Yet another const iterator is done
wkrozowski Oct 30, 2025
5d29dd6
chore: get const rco iterator working
wkrozowski Oct 30, 2025
0da49e9
TreeMap Raw slices are done
wkrozowski Oct 30, 2025
265ece2
chore TreeMap slices are done
wkrozowski Oct 30, 2025
a0e9f7c
chore: slices are done for treemaps
wkrozowski Oct 30, 2025
da87f95
TreeSet iterators
wkrozowski Oct 30, 2025
ddd85ef
feat: add `TreeSet` slices
wkrozowski Oct 30, 2025
9986361
chore: add iterator tests
wkrozowski Oct 30, 2025
8731535
Add slice unit tests
wkrozowski Oct 30, 2025
5f791c9
chore: address Markus' comments
wkrozowski Oct 31, 2025
6f3f00f
Fix some minor issues
wkrozowski Nov 10, 2025
d586985
Fix WF impliciteness
wkrozowski Nov 10, 2025
980a18b
Update src/Std/Data/TreeSet/Iterator.lean
wkrozowski Nov 11, 2025
95f5d36
Merge branch 'master' into wojciech/treemap_iterators
wkrozowski Nov 11, 2025
af9c7ed
chore: merge with master
wkrozowski Nov 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Std/Data/DTreeMap/Internal/Def.lean
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,11 @@ def toListModel : Impl α β → List ((a : α) × β a)
@[simp] theorem toListModel_inner {sz k v l r} :
(.inner sz k v l r : Impl α β).toListModel = l.toListModel ++ ⟨k, v⟩ :: r.toListModel := rfl

/--
Computes the size of the tree. Used for verification of iterators.
-/
def treeSize : Internal.Impl α β → Nat
| .leaf => 0
| .inner _ _ _ l r => 1 + l.treeSize + treeSize r

end Std.DTreeMap.Internal.Impl
110 changes: 110 additions & 0 deletions src/Std/Data/DTreeMap/Internal/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -7945,4 +7945,114 @@ end Const

end map

theorem prune_LE_eq_filter {α β} [Ord α] [TransOrd α] (t : Internal.Impl α β) (ord_t : t.Ordered) (lower_bound : α) :
(t.prune_LE ord_t lower_bound).toList = t.toList.filter (fun e => (compare e.fst lower_bound).isGE) := by
induction t
case leaf =>
simp only [prune_LE, toList_eq_toListModel, toListModel_leaf, List.filter_nil]
case inner _ k v l r l_ih r_ih =>
simp only [prune_LE, toList_eq_toListModel, toListModel_inner, List.filter_append]
generalize heq : compare lower_bound k = x
cases x
case lt =>
simp only [toListModel_inner]
specialize l_ih (Internal.Impl.Ordered.left ord_t)
rw [toList_eq_toListModel] at l_ih
simp only [l_ih, toList_eq_toListModel, List.filter, List.append_cancel_left_eq]
rw [OrientedOrd.eq_swap, Ordering.swap_eq_lt] at heq
simp only [heq, Ordering.isGE_gt, List.cons.injEq, true_and]
symm
apply List.filter_eq_self.2
intro a mem
apply Ordering.isGE_of_eq_gt
apply TransCmp.gt_trans ?_ heq
rw [OrientedOrd.eq_swap, Ordering.swap_eq_gt]
exact Internal.Impl.Ordered.compare_right ord_t mem
case eq =>
simp only [toListModel_inner, toListModel_leaf, List.nil_append, List.filter]
rw [OrientedCmp.eq_comm] at heq
simp only [heq, Ordering.isGE_eq]
suffices new_goal : List.filter (fun e => (compare e.fst lower_bound).isGE) l.toListModel = [] from by
simp only [new_goal, List.nil_append, List.cons.injEq, true_and]
symm
apply List.filter_eq_self.2
intro a mem
apply Ordering.isGE_of_eq_gt
apply TransCmp.gt_of_gt_of_eq ?_ heq
rw [OrientedOrd.eq_swap, Ordering.swap_eq_gt]
apply Internal.Impl.Ordered.compare_right ord_t mem
rw [List.filter_eq_nil_iff]
intro a mem
simp only [Bool.not_eq_true, Ordering.isGE_eq_false]
exact TransCmp.lt_of_lt_of_eq (Internal.Impl.Ordered.compare_left ord_t mem) heq
case gt =>
simp only [List.filter]
rw [OrientedOrd.eq_swap, Ordering.swap_eq_gt] at heq
rw [heq]
suffices new_goal : List.filter (fun e => (compare e.fst lower_bound).isGE) l.toListModel = [] from by
simp only [new_goal, Ordering.isGE_lt, List.nil_append]
simp only [toList_eq_toListModel] at r_ih
apply r_ih
rw [List.filter_eq_nil_iff]
intro a mem
simp only [Bool.not_eq_true, Ordering.isGE_eq_false]
exact TransCmp.lt_trans (Internal.Impl.Ordered.compare_left ord_t mem) heq

theorem prune_LT_eq_filter {α β} [Ord α] [TransOrd α] (t : Internal.Impl α β) (ord_t : t.Ordered) (lower_bound : α) :
(t.prune_LT ord_t lower_bound).toList = t.toList.filter (fun e => (compare e.fst lower_bound).isGT) := by
induction t
case leaf =>
simp only [prune_LT, toList_eq_toListModel, toListModel_leaf, List.filter_nil]
case inner _ k v l r l_ih r_ih =>
simp only [prune_LT, toList_eq_toListModel, toListModel_inner, List.filter_append]
generalize heq : compare lower_bound k = x
cases x
case lt =>
simp
specialize l_ih (Internal.Impl.Ordered.left ord_t)
rw [toList_eq_toListModel] at l_ih
simp only [l_ih, toList_eq_toListModel, List.filter, List.append_cancel_left_eq]
rw [OrientedOrd.eq_swap, Ordering.swap_eq_lt] at heq
simp only [heq, Ordering.isGT_gt, List.cons.injEq, true_and]
symm
apply List.filter_eq_self.2
intro a mem
rw [Ordering.isGT_iff_eq_gt]
apply TransCmp.gt_trans ?_ heq
rw [OrientedOrd.eq_swap, Ordering.swap_eq_gt]
exact Internal.Impl.Ordered.compare_right ord_t mem
case eq =>
simp only [List.filter]
rw [OrientedCmp.eq_comm] at heq
rw [heq]
suffices new_goal : List.filter (fun e => (compare e.fst lower_bound).isGT) l.toListModel = [] ∧
List.filter (fun e => (compare e.fst lower_bound).isGT) r.toListModel = r.toListModel from by
simp only [new_goal, Ordering.isGT_eq, List.nil_append]
apply And.intro
. rw [List.filter_eq_nil_iff]
intro a mem
simp only [Ordering.isGT_iff_eq_gt, ← Ordering.isLE_iff_ne_gt]
apply TransOrd.isLE_trans _ (Ordering.isLE_of_eq_eq heq)
apply Ordering.isLE_of_eq_lt
exact Internal.Impl.Ordered.compare_left ord_t mem
. apply List.filter_eq_self.2
intro a mem
rw [Ordering.isGT_iff_eq_gt]
apply TransCmp.gt_of_gt_of_eq ?_ heq
rw [OrientedOrd.eq_swap, Ordering.swap_eq_gt]
exact Internal.Impl.Ordered.compare_right ord_t mem
case gt =>
simp only [List.filter]
rw [OrientedOrd.eq_swap] at heq
rw [Ordering.swap_eq_gt] at heq
simp only [heq, Ordering.isGT_lt]
specialize r_ih (Ordered.right ord_t)
rw [toList_eq_toListModel] at r_ih
simp only [r_ih, toList_eq_toListModel, List.self_eq_append_left, List.filter_eq_nil_iff,
Ordering.isGT_iff_eq_gt]
intro a mem
rw [← Ordering.isLE_iff_ne_gt]
apply Ordering.isLE_of_eq_lt
exact TransCmp.lt_trans (Internal.Impl.Ordered.compare_left ord_t mem) heq

end Std.DTreeMap.Internal.Impl
32 changes: 32 additions & 0 deletions src/Std/Data/DTreeMap/Internal/Operations.lean
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,38 @@ def insertMany! [Ord α] {ρ : Type w} [ForIn Id ρ ((a : α) × β a)] (t : Imp
r := ⟨r.val.insert! a b, fun h₀ h₁ => h₁ _ _ _ (r.2 h₀ h₁)⟩
return r

/-!
## Operations for verification of iterators and slices
-/

/--
Removes all elements with key less than or equal to `lower_bound`.
Does not modify size information stored in the tree.
-/
def prune_LE {α β} [Ord α] (t : Internal.Impl α β)
(ord_t : t.Ordered) (lower_bound : α) : Internal.Impl α β :=
match t with
| .leaf => .leaf
| .inner sz k v l r =>
match compare lower_bound k with
| .lt => .inner sz k v (l.prune_LE (Internal.Impl.Ordered.left ord_t) lower_bound) r
| .eq => .inner sz k v .leaf r
| .gt => r.prune_LE (Internal.Impl.Ordered.right ord_t) lower_bound

/--
Removes all elements with key less than to `lower_bound`.
Does not modify size information stored in the tree.
-/
def prune_LT {α β} [Ord α] (t : Internal.Impl α β)
(ord_t : t.Ordered) (lower_bound : α) : Internal.Impl α β :=
match t with
| .leaf => .leaf
| .inner sz k v l r =>
match compare lower_bound k with
| .lt => .inner sz k v (l.prune_LT (Internal.Impl.Ordered.left ord_t) lower_bound) r
| .eq => r
| .gt => r.prune_LT (Internal.Impl.Ordered.right ord_t) lower_bound

namespace Const

variable {β : Type v}
Expand Down
Loading
Loading