Mercurial > hg > Members > Moririn
annotate hoareBinaryTree.agda @ 651:7b9d35f7c033
fix stack top and replaced tree
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 20 Nov 2021 14:24:22 +0900 |
parents | 11388cab162f |
children | 8c7446829b99 |
rev | line source |
---|---|
586
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
1 module hoareBinaryTree where |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
2 |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
3 open import Level renaming (zero to Z ; suc to succ) |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
4 |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
5 open import Data.Nat hiding (compare) |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
6 open import Data.Nat.Properties as NatProp |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
7 open import Data.Maybe |
588 | 8 -- open import Data.Maybe.Properties |
586
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
9 open import Data.Empty |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
10 open import Data.List |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
11 open import Data.Product |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
12 |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
13 open import Function as F hiding (const) |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
14 |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
15 open import Relation.Binary |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
16 open import Relation.Binary.PropositionalEquality |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
17 open import Relation.Nullary |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
18 open import logic |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
19 |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
20 |
588 | 21 _iso_ : {n : Level} {a : Set n} → ℕ → ℕ → Set |
22 d iso d' = (¬ (suc d ≤ d')) ∧ (¬ (suc d' ≤ d)) | |
23 | |
24 iso-intro : {n : Level} {a : Set n} {x y : ℕ} → ¬ (suc x ≤ y) → ¬ (suc y ≤ x) → _iso_ {n} {a} x y | |
25 iso-intro = λ z z₁ → record { proj1 = z ; proj2 = z₁ } | |
26 | |
590 | 27 -- |
28 -- | |
29 -- no children , having left node , having right node , having both | |
30 -- | |
597 | 31 data bt {n : Level} (A : Set n) : Set n where |
604 | 32 leaf : bt A |
33 node : (key : ℕ) → (value : A) → | |
610 | 34 (left : bt A ) → (right : bt A ) → bt A |
600 | 35 |
620 | 36 node-key : {n : Level} {A : Set n} → bt A → Maybe ℕ |
37 node-key (node key _ _ _) = just key | |
38 node-key _ = nothing | |
39 | |
40 node-value : {n : Level} {A : Set n} → bt A → Maybe A | |
41 node-value (node _ value _ _) = just value | |
42 node-value _ = nothing | |
43 | |
609
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
44 bt-depth : {n : Level} {A : Set n} → (tree : bt A ) → ℕ |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
45 bt-depth leaf = 0 |
618 | 46 bt-depth (node key value t t₁) = suc (Data.Nat._⊔_ (bt-depth t ) (bt-depth t₁ )) |
606 | 47 |
609
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
48 find : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (tree : bt A ) → List (bt A) |
604 | 49 → (next : bt A → List (bt A) → t ) → (exit : bt A → List (bt A) → t ) → t |
50 find key leaf st _ exit = exit leaf st | |
632 | 51 find key (node key₁ v1 tree tree₁) st next exit with <-cmp key key₁ |
604 | 52 find key n st _ exit | tri≈ ¬a b ¬c = exit n st |
632 | 53 find key n@(node key₁ v1 tree tree₁) st next _ | tri< a ¬b ¬c = next tree (n ∷ st) |
54 find key n@(node key₁ v1 tree tree₁) st next _ | tri> ¬a ¬b c = next tree₁ (n ∷ st) | |
597 | 55 |
604 | 56 {-# TERMINATING #-} |
609
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
57 find-loop : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → bt A → List (bt A) → (exit : bt A → List (bt A) → t) → t |
611 | 58 find-loop {n} {m} {A} {t} key tree st exit = find-loop1 tree st where |
604 | 59 find-loop1 : bt A → List (bt A) → t |
60 find-loop1 tree st = find key tree st find-loop1 exit | |
600 | 61 |
611 | 62 replaceNode : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (value : A) → bt A → (bt A → t) → t |
632 | 63 replaceNode k v1 leaf next = next (node k v1 leaf leaf) |
64 replaceNode k v1 (node key value t t₁) next = next (node k v1 t t₁) | |
611 | 65 |
609
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
66 replace : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (value : A) → bt A → List (bt A) → (next : ℕ → A → bt A → List (bt A) → t ) → (exit : bt A → t) → t |
604 | 67 replace key value tree [] next exit = exit tree |
647 | 68 replace key value tree (leaf ∷ []) next exit = exit (node key value leaf leaf) |
69 replace key value tree (leaf ∷ leaf ∷ st) next exit = exit (node key value leaf leaf) | |
70 replace key value tree (leaf ∷ node key₁ value₁ left right ∷ st) next exit with <-cmp key key₁ | |
71 ... | tri< a ¬b ¬c = next key value (node key₁ value₁ (node key value leaf leaf) right ) st | |
72 ... | tri≈ ¬a b ¬c = next key value (node key₁ value left right ) st | |
73 ... | tri> ¬a ¬b c = next key value (node key₁ value₁ left (node key value leaf leaf) ) st | |
604 | 74 replace key value tree (node key₁ value₁ left right ∷ st) next exit with <-cmp key key₁ |
75 ... | tri< a ¬b ¬c = next key value (node key₁ value₁ tree right ) st | |
76 ... | tri≈ ¬a b ¬c = next key value (node key₁ value left right ) st | |
77 ... | tri> ¬a ¬b c = next key value (node key₁ value₁ left tree ) st | |
586
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
78 |
604 | 79 {-# TERMINATING #-} |
609
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
80 replace-loop : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (value : A) → bt A → List (bt A) → (exit : bt A → t) → t |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
81 replace-loop {_} {_} {A} {t} key value tree st exit = replace-loop1 key value tree st where |
604 | 82 replace-loop1 : (key : ℕ) → (value : A) → bt A → List (bt A) → t |
83 replace-loop1 key value tree st = replace key value tree st replace-loop1 exit | |
586
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff
changeset
|
84 |
609
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
85 insertTree : {n m : Level} {A : Set n} {t : Set m} → (tree : bt A) → (key : ℕ) → (value : A) → (next : bt A → t ) → t |
611 | 86 insertTree tree key value exit = find-loop key tree [] $ λ t st → replaceNode key value t $ λ t1 → replace-loop key value t1 st exit |
587 | 87 |
604 | 88 insertTest1 = insertTree leaf 1 1 (λ x → x ) |
611 | 89 insertTest2 = insertTree insertTest1 2 1 (λ x → x ) |
587 | 90 |
605 | 91 open import Data.Unit hiding ( _≟_ ; _≤?_ ; _≤_) |
92 | |
620 | 93 data treeInvariant {n : Level} {A : Set n} : (tree : bt A) → Set n where |
94 t-leaf : treeInvariant leaf | |
632 | 95 t-single : (key : ℕ) → (value : A) → treeInvariant (node key value leaf leaf) |
96 t-right : {key key₁ : ℕ} → {value value₁ : A} → {t₁ t₂ : bt A} → (key < key₁) → treeInvariant (node key₁ value₁ t₁ t₂) | |
97 → treeInvariant (node key value leaf (node key₁ value₁ t₁ t₂)) | |
98 t-left : {key key₁ : ℕ} → {value value₁ : A} → {t₁ t₂ : bt A} → (key₁ < key) → treeInvariant (node key value t₁ t₂) | |
99 → treeInvariant (node key₁ value₁ (node key value t₁ t₂) leaf ) | |
620 | 100 t-node : {key key₁ key₂ : ℕ} → {value value₁ value₂ : A} → {t₁ t₂ t₃ t₄ : bt A} → (key < key₁) → (key₁ < key₂) |
101 → treeInvariant (node key value t₁ t₂) | |
102 → treeInvariant (node key₂ value₂ t₃ t₄) | |
103 → treeInvariant (node key₁ value₁ (node key value t₁ t₂) (node key₂ value₂ t₃ t₄)) | |
605 | 104 |
645 | 105 data stackInvariant {n : Level} {A : Set n} (key : ℕ) : (tree tree0 : bt A) → (stack : List (bt A)) → Set n where |
106 s-single : (tree : bt A) → stackInvariant key tree tree (tree ∷ [] ) | |
107 s-right : {tree0 tree tree₁ : bt A} → {key₁ : ℕ } → {v1 : A } → {st : List (bt A)} | |
108 → key₁ < key → stackInvariant key (node key₁ v1 tree tree₁) tree0 st → stackInvariant key tree₁ tree0 (tree₁ ∷ st) | |
109 s-left : {tree0 tree tree₁ : bt A} → {key₁ : ℕ } → {v1 : A } → {st : List (bt A)} | |
110 → key < key₁ → stackInvariant key (node key₁ v1 tree tree₁) tree0 st → stackInvariant key tree tree0 (tree ∷ st) | |
639 | 111 |
112 data replacedTree {n : Level} {A : Set n} (key : ℕ) (value : A) : (tree tree1 : bt A ) → Set n where | |
113 r-leaf : replacedTree key value leaf (node key value leaf leaf) | |
114 r-node : {value₁ : A} → {t t₁ : bt A} → replacedTree key value (node key value₁ t t₁) (node key value t t₁) | |
115 r-right : {k : ℕ } {v1 : A} → {t t1 t2 : bt A} | |
650 | 116 → k < key → replacedTree key value t1 t2 → replacedTree key value (node k v1 t t1) (node k v1 t t2) |
639 | 117 r-left : {k : ℕ } {v1 : A} → {t t1 t2 : bt A} |
650 | 118 → k > key → replacedTree key value t1 t2 → replacedTree key value (node k v1 t1 t) (node k v1 t2 t) |
639 | 119 |
632 | 120 add< : { i : ℕ } (j : ℕ ) → i < suc i + j |
121 add< {i} j = begin | |
122 suc i ≤⟨ m≤m+n (suc i) j ⟩ | |
123 suc i + j ∎ where open ≤-Reasoning | |
124 | |
125 treeTest1 : bt ℕ | |
126 treeTest1 = node 1 0 leaf (node 3 1 (node 2 5 (node 4 7 leaf leaf ) leaf) (node 5 5 leaf leaf)) | |
127 treeTest2 : bt ℕ | |
128 treeTest2 = node 3 1 (node 2 5 (node 4 7 leaf leaf ) leaf) (node 5 5 leaf leaf) | |
129 | |
130 treeInvariantTest1 : treeInvariant treeTest1 | |
131 treeInvariantTest1 = t-right (m≤m+n _ 1) (t-node (add< 0) (add< 1) (t-left (add< 1) (t-single 4 7)) (t-single 5 5) ) | |
605 | 132 |
639 | 133 stack-top : {n : Level} {A : Set n} (stack : List (bt A)) → Maybe (bt A) |
134 stack-top [] = nothing | |
135 stack-top (x ∷ s) = just x | |
606 | 136 |
639 | 137 stack-last : {n : Level} {A : Set n} (stack : List (bt A)) → Maybe (bt A) |
138 stack-last [] = nothing | |
139 stack-last (x ∷ []) = just x | |
140 stack-last (x ∷ s) = stack-last s | |
632 | 141 |
645 | 142 stackInvariantTest1 : stackInvariant 2 treeTest2 treeTest1 ( treeTest2 ∷ treeTest1 ∷ [] ) |
143 stackInvariantTest1 = s-right (add< 0) (s-single treeTest1 ) | |
632 | 144 |
645 | 145 si-property1 : {n : Level} {A : Set n} (key : ℕ) (tree tree0 : bt A) → (stack : List (bt A)) → stackInvariant key tree tree0 stack |
639 | 146 → stack-top stack ≡ just tree |
645 | 147 si-property1 key t t0 (x ∷ .[]) (s-single .x) = refl |
148 si-property1 key t t0 (t ∷ st) (s-right _ si) = refl | |
149 si-property1 key t t0 (t ∷ st) (s-left _ si) = refl | |
639 | 150 |
645 | 151 si-property-last : {n : Level} {A : Set n} (key : ℕ) (tree tree0 : bt A) → (stack : List (bt A)) → stackInvariant key tree tree0 stack |
639 | 152 → stack-last stack ≡ just tree0 |
645 | 153 si-property-last key t t0 (x ∷ []) (s-single .x) = refl |
154 si-property-last key t t0 (.t ∷ x ∷ st) (s-right _ si) with si-property1 key _ _ (x ∷ st) si | |
155 ... | refl = si-property-last key x t0 (x ∷ st) si | |
156 si-property-last key t t0 (.t ∷ x ∷ st) (s-left _ si) with si-property1 key _ _ (x ∷ st) si | |
157 ... | refl = si-property-last key x t0 (x ∷ st) si | |
639 | 158 |
642 | 159 ti-right : {n : Level} {A : Set n} {tree₁ repl : bt A} → {key₁ : ℕ} → {v1 : A} → treeInvariant (node key₁ v1 tree₁ repl) → treeInvariant repl |
160 ti-right {_} {_} {.leaf} {_} {key₁} {v1} (t-single .key₁ .v1) = t-leaf | |
161 ti-right {_} {_} {.leaf} {_} {key₁} {v1} (t-right x ti) = ti | |
162 ti-right {_} {_} {.(node _ _ _ _)} {_} {key₁} {v1} (t-left x ti) = t-leaf | |
163 ti-right {_} {_} {.(node _ _ _ _)} {_} {key₁} {v1} (t-node x x₁ ti ti₁) = ti₁ | |
164 | |
165 ti-left : {n : Level} {A : Set n} {tree₁ repl : bt A} → {key₁ : ℕ} → {v1 : A} → treeInvariant (node key₁ v1 repl tree₁ ) → treeInvariant repl | |
166 ti-left {_} {_} {.leaf} {_} {key₁} {v1} (t-single .key₁ .v1) = t-leaf | |
167 ti-left {_} {_} {_} {_} {key₁} {v1} (t-right x ti) = t-leaf | |
168 ti-left {_} {_} {_} {_} {key₁} {v1} (t-left x ti) = ti | |
169 ti-left {_} {_} {.(node _ _ _ _)} {_} {key₁} {v1} (t-node x x₁ ti ti₁) = ti | |
170 | |
645 | 171 stackTreeInvariant : {n : Level} {A : Set n} (key : ℕ) (repl tree : bt A) → (stack : List (bt A)) |
172 → treeInvariant tree → stackInvariant key repl tree stack → treeInvariant repl | |
173 stackTreeInvariant key repl .repl .(repl ∷ []) ti (s-single .repl) = ti | |
174 stackTreeInvariant {_} {A} key repl tree (repl ∷ st) ti (s-right _ si) = ti-right (si1 si) where | |
175 si1 : {tree₁ : bt A} → {key₁ : ℕ} → {v1 : A} → stackInvariant key (node key₁ v1 tree₁ repl) tree st → treeInvariant (node key₁ v1 tree₁ repl) | |
176 si1 {tree₁ } {key₁ } {v1 } si = stackTreeInvariant key (node key₁ v1 tree₁ repl) tree st ti si | |
177 stackTreeInvariant {_} {A} key repl tree (repl ∷ st) ti (s-left _ si) = ti-left ( si2 si ) where | |
178 si2 : {tree₁ : bt A} → {key₁ : ℕ} → {v1 : A} → stackInvariant key (node key₁ v1 repl tree₁ ) tree st → treeInvariant (node key₁ v1 repl tree₁ ) | |
179 si2 {tree₁ } {key₁ } {v1 } si = stackTreeInvariant key (node key₁ v1 repl tree₁ ) tree st ti si | |
640 | 180 |
639 | 181 rt-property1 : {n : Level} {A : Set n} (key : ℕ) (value : A) (tree tree1 : bt A ) → replacedTree key value tree tree1 → ¬ ( tree1 ≡ leaf ) |
182 rt-property1 {n} {A} key value .leaf .(node key value leaf leaf) r-leaf () | |
183 rt-property1 {n} {A} key value .(node key _ _ _) .(node key value _ _) r-node () | |
184 rt-property1 {n} {A} key value .(node _ _ _ _) .(node _ _ _ _) (r-right x rt) () | |
185 rt-property1 {n} {A} key value .(node _ _ _ _) .(node _ _ _ _) (r-left x rt) () | |
186 | |
632 | 187 depth-1< : {i j : ℕ} → suc i ≤ suc (i Data.Nat.⊔ j ) |
188 depth-1< {i} {j} = s≤s (m≤m⊔n _ j) | |
189 | |
190 depth-2< : {i j : ℕ} → suc i ≤ suc (j Data.Nat.⊔ i ) | |
650 | 191 depth-2< {i} {j} = s≤s (m≤n⊔m j i) |
611 | 192 |
649 | 193 depth-3< : {i : ℕ } → suc i ≤ suc (suc i) |
194 depth-3< {zero} = s≤s ( z≤n ) | |
195 depth-3< {suc i} = s≤s (depth-3< {i} ) | |
196 | |
197 | |
634 | 198 treeLeftDown : {n : Level} {A : Set n} {k : ℕ} {v1 : A} → (tree tree₁ : bt A ) |
199 → treeInvariant (node k v1 tree tree₁) | |
200 → treeInvariant tree | |
201 treeLeftDown {n} {A} {_} {v1} leaf leaf (t-single k1 v1) = t-leaf | |
202 treeLeftDown {n} {A} {_} {v1} .leaf .(node _ _ _ _) (t-right x ti) = t-leaf | |
203 treeLeftDown {n} {A} {_} {v1} .(node _ _ _ _) .leaf (t-left x ti) = ti | |
204 treeLeftDown {n} {A} {_} {v1} .(node _ _ _ _) .(node _ _ _ _) (t-node x x₁ ti ti₁) = ti | |
205 | |
206 treeRightDown : {n : Level} {A : Set n} {k : ℕ} {v1 : A} → (tree tree₁ : bt A ) | |
207 → treeInvariant (node k v1 tree tree₁) | |
208 → treeInvariant tree₁ | |
209 treeRightDown {n} {A} {_} {v1} .leaf .leaf (t-single _ .v1) = t-leaf | |
210 treeRightDown {n} {A} {_} {v1} .leaf .(node _ _ _ _) (t-right x ti) = ti | |
211 treeRightDown {n} {A} {_} {v1} .(node _ _ _ _) .leaf (t-left x ti) = t-leaf | |
212 treeRightDown {n} {A} {_} {v1} .(node _ _ _ _) .(node _ _ _ _) (t-node x x₁ ti ti₁) = ti₁ | |
213 | |
633 | 214 |
215 open _∧_ | |
216 | |
615 | 217 findP : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (tree tree0 : bt A ) → (stack : List (bt A)) |
645 | 218 → treeInvariant tree ∧ stackInvariant key tree tree0 stack |
219 → (next : (tree1 tree0 : bt A) → (stack : List (bt A)) → treeInvariant tree1 ∧ stackInvariant key tree1 tree0 stack → bt-depth tree1 < bt-depth tree → t ) | |
220 → (exit : (tree1 tree0 : bt A) → (stack : List (bt A)) → treeInvariant tree1 ∧ stackInvariant key tree1 tree0 stack | |
638 | 221 → (tree1 ≡ leaf ) ∨ ( node-key tree1 ≡ just key ) → t ) → t |
222 findP key leaf tree0 st Pre _ exit = exit leaf tree0 st Pre (case1 refl) | |
632 | 223 findP key (node key₁ v1 tree tree₁) tree0 st Pre next exit with <-cmp key key₁ |
638 | 224 findP key n tree0 st Pre _ exit | tri≈ ¬a refl ¬c = exit n tree0 st Pre (case2 refl) |
637
e30dcd03c07f
stack invariant in findP
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
634
diff
changeset
|
225 findP key n@(node key₁ v1 tree tree₁) tree0 st Pre next _ | tri< a ¬b ¬c = next tree tree0 (tree ∷ st) ⟪ treeLeftDown tree tree₁ (proj1 Pre) , findP1 a (proj2 Pre) ⟫ depth-1< where |
645 | 226 findP1 : key < key₁ → stackInvariant key (node key₁ v1 tree tree₁) tree0 st → stackInvariant key tree tree0 (tree ∷ st) |
227 findP1 a si = s-left a si | |
228 findP key n@(node key₁ v1 tree tree₁) tree0 st Pre next _ | tri> ¬a ¬b c = next tree₁ tree0 (tree₁ ∷ st) ⟪ treeRightDown tree tree₁ (proj1 Pre) , s-right c (proj2 Pre) ⟫ depth-2< | |
632 | 229 |
606 | 230 |
638 | 231 replaceTree1 : {n : Level} {A : Set n} {t t₁ : bt A } → ( k : ℕ ) → (v1 value : A ) → treeInvariant (node k v1 t t₁) → treeInvariant (node k value t t₁) |
232 replaceTree1 k v1 value (t-single .k .v1) = t-single k value | |
233 replaceTree1 k v1 value (t-right x t) = t-right x t | |
234 replaceTree1 k v1 value (t-left x t) = t-left x t | |
235 replaceTree1 k v1 value (t-node x x₁ t t₁) = t-node x x₁ t t₁ | |
236 | |
649 | 237 open import Relation.Binary.Definitions |
238 | |
239 nat-≤> : { x y : ℕ } → x ≤ y → y < x → ⊥ | |
240 nat-≤> (s≤s x<y) (s≤s y<x) = nat-≤> x<y y<x | |
650 | 241 nat-<> : { x y : ℕ } → x < y → y < x → ⊥ |
242 nat-<> (s≤s x<y) (s≤s y<x) = nat-<> x<y y<x | |
649 | 243 lemma3 : {i j : ℕ} → 0 ≡ i → j < i → ⊥ |
244 lemma3 refl () | |
245 lemma5 : {i j : ℕ} → i < 1 → j < i → ⊥ | |
246 lemma5 (s≤s z≤n) () | |
247 | |
638 | 248 replaceNodeP : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (value : A) → (tree : bt A) |
249 → (tree ≡ leaf ) ∨ ( node-key tree ≡ just key ) | |
250 → (treeInvariant tree ) → ((tree1 : bt A) → treeInvariant tree1 → replacedTree key value tree tree1 → t) → t | |
251 replaceNodeP k v1 leaf C P next = next (node k v1 leaf leaf) (t-single k v1 ) r-leaf | |
252 replaceNodeP k v1 (node .k value t t₁) (case2 refl) P next = next (node k v1 t t₁) (replaceTree1 k value v1 P) r-node | |
606 | 253 |
609
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
254 replaceP : {n m : Level} {A : Set n} {t : Set m} |
651
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
255 → (key : ℕ) → (value : A) → {tree0 tree tree-st : bt A} ( repl : bt A) |
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
256 → (stack : List (bt A)) → treeInvariant tree0 ∧ stackInvariant key tree-st tree0 stack ∧ replacedTree key value tree repl |
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
257 → (next : ℕ → A → {tree0 tree1 tree-st : bt A } (repl : bt A) → (stack1 : List (bt A)) |
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
258 → treeInvariant tree0 ∧ stackInvariant key tree-st tree0 stack1 ∧ replacedTree key value tree1 repl → length stack1 < length stack → t) |
613 | 259 → (exit : (tree1 repl : bt A) → treeInvariant tree1 ∧ replacedTree key value tree1 repl → t) → t |
651
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
260 replaceP key value {tree0} {tree} {tree-st} repl [] Pre next exit with proj1 (proj2 Pre) |
645 | 261 ... | () |
651
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
262 replaceP {_} {_} {A} key value {tree0} {tree} {tree-st} repl (leaf ∷ []) Pre next exit = |
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
263 exit tree0 repl ⟪ proj1 Pre , subst (λ k → replacedTree key value k repl ) (repl4 (proj1 (proj2 Pre))) {!!} ⟫ where |
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
264 repl41 : tree-st ≡ tree |
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
265 repl41 = {!!} |
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
266 repl4 : stackInvariant key tree-st tree0 (leaf ∷ []) → tree-st ≡ tree0 |
648 | 267 repl4 (s-single .leaf) = refl |
651
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
268 replaceP key value {tree0} {tree} {tree-st} repl (leaf ∷ leaf ∷ st) Pre next exit = ⊥-elim ( repl3 (proj1 (proj2 Pre))) where -- can't happen |
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
269 repl3 : stackInvariant key tree-st tree0 (leaf ∷ leaf ∷ st) → ⊥ |
649 | 270 repl3 (s-right x ()) |
271 repl3 (s-left x ()) | |
651
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
272 replaceP {_} {_} {A} key value {tree0} {tree} {tree-st} repl (leaf ∷ node key₁ value₁ left right ∷ st) Pre next exit with <-cmp key key₁ |
650 | 273 ... | tri< a ¬b ¬c = next key value (node key₁ value₁ repl right ) (node key₁ value₁ tree right ∷ st) |
274 ⟪ proj1 Pre , ⟪ repl5 (proj1 (proj2 Pre)) , r-left a (proj2 (proj2 Pre)) ⟫ ⟫ ≤-refl where | |
651
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
275 repl5 : stackInvariant key tree-st tree0 (leaf ∷ node key₁ value₁ left right ∷ st) → stackInvariant key (node key₁ value₁ tree right) tree0 (node key₁ value₁ tree right ∷ st ) |
649 | 276 repl5 (s-right x si) with si-property1 _ _ _ _ si |
650 | 277 ... | refl = ⊥-elim (nat-<> a x) |
651
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
278 repl5 (s-left x si) with si-property1 _ _ _ _ si -- stackInvariant key (node key₁ value₁ leaf right) tree0 (node key₁ value₁ leaf right ∷ st) |
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
279 -- stackInvariant key (node key₁ value₁ tree right) tree0 (node key₁ value₁ tree right ∷ st) |
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
280 ... | refl = {!!} -- tree ≡ leaf |
649 | 281 ... | tri≈ ¬a b ¬c = next key value (node key₁ value left right) st {!!} depth-3< |
282 ... | tri> ¬a ¬b c = next key value (node key₁ value₁ repl right) st {!!} depth-3< | |
651
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
283 replaceP key value {tree0} {tree} {tree-st} repl (node key₁ value₁ left right ∷ st) Pre next exit with <-cmp key key₁ |
644 | 284 ... | tri> ¬a ¬b c = next key value (node key₁ value₁ repl right ) st {!!} ≤-refl |
285 ... | tri≈ ¬a b ¬c = next key value (node key value left right ) st {!!} ≤-refl where -- this case won't happen | |
651
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
286 ... | tri< a ¬b ¬c with proj1 (proj2 Pre) |
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
287 ... | s-single .(node key₁ value₁ left right) = {!!} |
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
288 ... | s-right x si1 = {!!} |
7b9d35f7c033
fix stack top and replaced tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
650
diff
changeset
|
289 ... | s-left x si1 = next key value (node key₁ value₁ repl right ) st ⟪ proj1 Pre , ⟪ si1 , r-left a (proj2 (proj2 Pre)) ⟫ ⟫ ≤-refl |
644 | 290 |
609
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
291 TerminatingLoopS : {l m : Level} {t : Set l} (Index : Set m ) → {Invraiant : Index → Set m } → ( reduce : Index → ℕ) |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
292 → (r : Index) → (p : Invraiant r) |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
293 → (loop : (r : Index) → Invraiant r → (next : (r1 : Index) → Invraiant r1 → reduce r1 < reduce r → t ) → t) → t |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
294 TerminatingLoopS {_} {_} {t} Index {Invraiant} reduce r p loop with <-cmp 0 (reduce r) |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
295 ... | tri≈ ¬a b ¬c = loop r p (λ r1 p1 lt → ⊥-elim (lemma3 b lt) ) |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
296 ... | tri< a ¬b ¬c = loop r p (λ r1 p1 lt1 → TerminatingLoop1 (reduce r) r r1 (≤-step lt1) p1 lt1 ) where |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
297 TerminatingLoop1 : (j : ℕ) → (r r1 : Index) → reduce r1 < suc j → Invraiant r1 → reduce r1 < reduce r → t |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
298 TerminatingLoop1 zero r r1 n≤j p1 lt = loop r1 p1 (λ r2 p1 lt1 → ⊥-elim (lemma5 n≤j lt1)) |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
299 TerminatingLoop1 (suc j) r r1 n≤j p1 lt with <-cmp (reduce r1) (suc j) |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
300 ... | tri< a ¬b ¬c = TerminatingLoop1 j r r1 a p1 lt |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
301 ... | tri≈ ¬a b ¬c = loop r1 p1 (λ r2 p2 lt1 → TerminatingLoop1 j r1 r2 (subst (λ k → reduce r2 < k ) b lt1 ) p2 lt1 ) |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
302 ... | tri> ¬a ¬b c = ⊥-elim ( nat-≤> c n≤j ) |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
303 |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
304 open _∧_ |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
305 |
615 | 306 RTtoTI0 : {n : Level} {A : Set n} → (tree repl : bt A) → (key : ℕ) → (value : A) → treeInvariant tree |
307 → replacedTree key value tree repl → treeInvariant repl | |
308 RTtoTI0 = {!!} | |
309 | |
310 RTtoTI1 : {n : Level} {A : Set n} → (tree repl : bt A) → (key : ℕ) → (value : A) → treeInvariant repl | |
311 → replacedTree key value tree repl → treeInvariant tree | |
312 RTtoTI1 = {!!} | |
614 | 313 |
611 | 314 insertTreeP : {n m : Level} {A : Set n} {t : Set m} → (tree : bt A) → (key : ℕ) → (value : A) → treeInvariant tree |
613 | 315 → (exit : (tree repl : bt A) → treeInvariant tree ∧ replacedTree key value tree repl → t ) → t |
610 | 316 insertTreeP {n} {m} {A} {t} tree key value P exit = |
645 | 317 TerminatingLoopS (bt A ∧ List (bt A) ) {λ p → treeInvariant (proj1 p) ∧ stackInvariant key (proj1 p) tree (proj2 p) } (λ p → bt-depth (proj1 p)) ⟪ tree , [] ⟫ ⟪ P , {!!} ⟫ |
615 | 318 $ λ p P loop → findP key (proj1 p) tree (proj2 p) {!!} (λ t _ s P1 lt → loop ⟪ t , s ⟫ {!!} lt ) |
638 | 319 $ λ t _ s P C → replaceNodeP key value t C (proj1 P) |
614 | 320 $ λ t1 P1 R → TerminatingLoopS (List (bt A) ∧ (bt A ∧ bt A )) |
645 | 321 {λ p → treeInvariant (proj1 (proj2 p)) ∧ stackInvariant key (proj1 (proj2 p)) tree (proj1 p) ∧ replacedTree key value (proj1 (proj2 p)) (proj2 (proj2 p)) } |
639 | 322 (λ p → length (proj1 p)) ⟪ s , ⟪ t , t1 ⟫ ⟫ ⟪ proj1 P , ⟪ {!!} , R ⟫ ⟫ |
644 | 323 $ λ p P1 loop → replaceP key value (proj2 (proj2 p)) (proj1 p) {!!} |
324 (λ key value repl1 stack P2 lt → loop ⟪ stack , ⟪ {!!} , repl1 ⟫ ⟫ {!!} lt ) exit | |
614 | 325 |
609
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
326 top-value : {n : Level} {A : Set n} → (tree : bt A) → Maybe A |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
327 top-value leaf = nothing |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
328 top-value (node key value tree tree₁) = just value |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
329 |
612 | 330 insertTreeSpec0 : {n : Level} {A : Set n} → (tree : bt A) → (value : A) → top-value tree ≡ just value → ⊤ |
609
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
331 insertTreeSpec0 _ _ _ = tt |
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
606
diff
changeset
|
332 |
627 | 333 record findPR {n : Level} {A : Set n} (key : ℕ) (tree : bt A ) (stack : List (bt A)) (C : bt A → List (bt A) → Set n) : Set n where |
618 | 334 field |
619 | 335 tree0 : bt A |
622 | 336 ti : treeInvariant tree0 |
645 | 337 si : stackInvariant key tree tree0 stack |
631 | 338 ci : C tree stack -- data continuation |
618 | 339 |
616 | 340 findPP : {n m : Level} {A : Set n} {t : Set m} |
341 → (key : ℕ) → (tree : bt A ) → (stack : List (bt A)) | |
627 | 342 → (Pre : findPR key tree stack (λ t s → Lift n ⊤)) |
343 → (next : (tree1 : bt A) → (stack1 : List (bt A)) → findPR key tree1 stack1 (λ t s → Lift n ⊤) → bt-depth tree1 < bt-depth tree → t ) | |
344 → (exit : (tree1 : bt A) → (stack1 : List (bt A)) → ( tree1 ≡ leaf ) ∨ ( node-key tree1 ≡ just key) → findPR key tree1 stack1 (λ t s → Lift n ⊤) → t) → t | |
625 | 345 findPP key leaf st Pre next exit = exit leaf st (case1 refl) Pre |
632 | 346 findPP key (node key₁ v1 tree tree₁) st Pre next exit with <-cmp key key₁ |
625 | 347 findPP key n st P next exit | tri≈ ¬a b ¬c = exit n st (case2 {!!}) P |
632 | 348 findPP {_} {_} {A} key n@(node key₁ v1 tree tree₁) st Pre next exit | tri< a ¬b ¬c = |
624 | 349 next tree (n ∷ st) (record {ti = findPR.ti Pre ; si = findPP2 st (findPR.si Pre) ; ci = lift tt} ) findPP1 where |
621 | 350 tree0 = findPR.tree0 Pre |
645 | 351 findPP2 : (st : List (bt A)) → stackInvariant key {!!} tree0 st → stackInvariant key {!!} tree0 (node key₁ v1 tree tree₁ ∷ st) |
623 | 352 findPP2 = {!!} |
618 | 353 findPP1 : suc ( bt-depth tree ) ≤ suc (bt-depth tree Data.Nat.⊔ bt-depth tree₁) |
634 | 354 findPP1 = depth-1< |
632 | 355 findPP key n@(node key₁ v1 tree tree₁) st Pre next exit | tri> ¬a ¬b c = next tree₁ (n ∷ st) {!!} findPP2 where -- Cond n st → Cond tree₁ (n ∷ st) |
618 | 356 findPP2 : suc (bt-depth tree₁) ≤ suc (bt-depth tree Data.Nat.⊔ bt-depth tree₁) |
634 | 357 findPP2 = depth-2< |
616 | 358 |
618 | 359 insertTreePP : {n m : Level} {A : Set n} {t : Set m} → (tree : bt A) → (key : ℕ) → (value : A) → treeInvariant tree |
360 → (exit : (tree repl : bt A) → treeInvariant tree ∧ replacedTree key value tree repl → t ) → t | |
624 | 361 insertTreePP {n} {m} {A} {t} tree key value P exit = |
627 | 362 TerminatingLoopS (bt A ∧ List (bt A) ) {λ p → findPR key (proj1 p) (proj2 p) (λ t s → Lift n ⊤) } (λ p → bt-depth (proj1 p)) ⟪ tree , [] ⟫ {!!} |
630 | 363 $ λ p P loop → findPP key (proj1 p) (proj2 p) P (λ t s P1 lt → loop ⟪ t , s ⟫ P1 lt ) |
638 | 364 $ λ t s _ P → replaceNodeP key value t {!!} {!!} |
618 | 365 $ λ t1 P1 R → TerminatingLoopS (List (bt A) ∧ (bt A ∧ bt A )) |
645 | 366 {λ p → treeInvariant (proj1 (proj2 p)) ∧ stackInvariant key (proj1 (proj2 p)) tree (proj1 p) ∧ replacedTree key value (proj1 (proj2 p)) (proj2 (proj2 p)) } |
639 | 367 (λ p → length (proj1 p)) ⟪ s , ⟪ t , t1 ⟫ ⟫ ⟪ {!!} , ⟪ {!!} , R ⟫ ⟫ |
644 | 368 $ λ p P1 loop → replaceP key value (proj2 (proj2 p)) (proj1 p) {!!} |
369 (λ key value repl1 stack P2 lt → loop ⟪ stack , ⟪ {!!} , repl1 ⟫ ⟫ {!!} lt ) exit | |
618 | 370 |
629 | 371 record findPC {n : Level} {A : Set n} (key1 : ℕ) (value1 : A) (tree : bt A ) (stack : List (bt A)) : Set n where |
616 | 372 field |
373 tree1 : bt A | |
617 | 374 ci : replacedTree key1 value1 tree tree1 |
616 | 375 |
624 | 376 findPPC : {n m : Level} {A : Set n} {t : Set m} |
628 | 377 → (key : ℕ) → (value : A) → (tree : bt A ) → (stack : List (bt A)) |
629 | 378 → (Pre : findPR key tree stack (findPC key value)) |
379 → (next : (tree1 : bt A) → (stack1 : List (bt A)) → findPR key tree1 stack1 (findPC key value) → bt-depth tree1 < bt-depth tree → t ) | |
380 → (exit : (tree1 : bt A) → (stack1 : List (bt A)) → ( tree1 ≡ leaf ) ∨ ( node-key tree1 ≡ just key) → findPR key tree1 stack1 (findPC key value) → t) → t | |
381 findPPC key value leaf st Pre next exit = exit leaf st (case1 refl) Pre | |
632 | 382 findPPC key value (node key₁ v1 tree tree₁) st Pre next exit with <-cmp key key₁ |
629 | 383 findPPC key value n st P next exit | tri≈ ¬a b ¬c = exit n st (case2 {!!}) P |
632 | 384 findPPC {_} {_} {A} key value n@(node key₁ v1 tree tree₁) st Pre next exit | tri< a ¬b ¬c = |
629 | 385 next tree (n ∷ st) (record {ti = findPR.ti Pre ; si = {!!} ; ci = {!!} } ) {!!} |
386 findPPC key value n st P next exit | tri> ¬a ¬b c = {!!} | |
624 | 387 |
618 | 388 containsTree : {n m : Level} {A : Set n} {t : Set m} → (tree tree1 : bt A) → (key : ℕ) → (value : A) → treeInvariant tree1 → replacedTree key value tree1 tree → ⊤ |
615 | 389 containsTree {n} {m} {A} {t} tree tree1 key value P RT = |
617 | 390 TerminatingLoopS (bt A ∧ List (bt A) ) |
634 | 391 {λ p → findPR key (proj1 p) (proj2 p) (findPC key value ) } (λ p → bt-depth (proj1 p)) -- findPR key tree1 [] (findPC key value) |
392 ⟪ tree1 , [] ⟫ record { tree0 = tree ; ti = {!!} ; si = {!!} ; ci = record { tree1 = tree ; ci = RT } } | |
630 | 393 $ λ p P loop → findPPC key value (proj1 p) (proj2 p) P (λ t s P1 lt → loop ⟪ t , s ⟫ P1 lt ) |
629 | 394 $ λ t1 s1 found? P2 → insertTreeSpec0 t1 value (lemma6 t1 s1 found? P2) where |
395 lemma6 : (t1 : bt A) (s1 : List (bt A)) (found? : (t1 ≡ leaf) ∨ (node-key t1 ≡ just key)) (P2 : findPR key t1 s1 (findPC key value)) → top-value t1 ≡ just value | |
396 lemma6 t1 s1 found? P2 = lemma7 t1 s1 (findPR.tree0 P2) ( findPC.tree1 (findPR.ci P2)) ( findPC.ci (findPR.ci P2)) (findPR.si P2) found? where | |
397 lemma7 : (t1 : bt A) ( s1 : List (bt A) ) (tree0 tree1 : bt A) → | |
645 | 398 replacedTree key value t1 tree1 → stackInvariant key t1 tree0 s1 → ( t1 ≡ leaf ) ∨ ( node-key t1 ≡ just key) → top-value t1 ≡ just value |
629 | 399 lemma7 = {!!} |
615 | 400 |