annotate hoareBinaryTree.agda @ 600:016a8deed93d

fix old binary tree
author ryokka
date Wed, 04 Mar 2020 17:51:05 +0900
parents 89fd7cf09b2a
children 803c423c2855
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
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
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
21 SingleLinkedStack = List
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
22
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
23 emptySingleLinkedStack : {n : Level } {Data : Set n} -> SingleLinkedStack Data
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
24 emptySingleLinkedStack = []
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
25
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
26 clearSingleLinkedStack : {n m : Level } {Data : Set n} {t : Set m} -> SingleLinkedStack Data → ( SingleLinkedStack Data → t) → t
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
27 clearSingleLinkedStack [] cg = cg []
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
28 clearSingleLinkedStack (x ∷ as) cg = cg []
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
29
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
30 pushSingleLinkedStack : {n m : Level } {t : Set m } {Data : Set n} -> List Data -> Data -> (Code : SingleLinkedStack Data -> t) -> t
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
31 pushSingleLinkedStack stack datum next = next ( datum ∷ stack )
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
32
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
33
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
34 popSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} -> SingleLinkedStack a -> (Code : SingleLinkedStack a -> (Maybe a) -> t) -> t
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
35 popSingleLinkedStack [] cs = cs [] nothing
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
36 popSingleLinkedStack (data1 ∷ s) cs = cs s (just data1)
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
37
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
38
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
39
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
40 emptySigmaStack : {n : Level } { Data : Set n} → List Data
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
41 emptySigmaStack = []
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
42
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
43 pushSigmaStack : {n m : Level} {d d2 : Set n} {t : Set m} → d2 → List d → (List (d × d2) → t) → t
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
44 pushSigmaStack {n} {m} {d} d2 st next = next (Data.List.zip (st) (d2 ∷ []) )
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
45
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
46 tt = pushSigmaStack 3 (true ∷ []) (λ st → st)
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
47
588
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
48 _iso_ : {n : Level} {a : Set n} → ℕ → ℕ → Set
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
49 d iso d' = (¬ (suc d ≤ d')) ∧ (¬ (suc d' ≤ d))
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
50
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
51 iso-intro : {n : Level} {a : Set n} {x y : ℕ} → ¬ (suc x ≤ y) → ¬ (suc y ≤ x) → _iso_ {n} {a} x y
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
52 iso-intro = λ z z₁ → record { proj1 = z ; proj2 = z₁ }
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
53
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
54
590
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 589
diff changeset
55 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 589
diff changeset
56 --
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 589
diff changeset
57 -- no children , having left node , having right node , having both
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 589
diff changeset
58 --
597
ryokka
parents: 596
diff changeset
59 data bt {n : Level} (A : Set n) : Set n where
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
60 L : bt A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
61 N : (key : ℕ) →
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
62 (ltree : bt A ) → (rtree : bt A ) → bt A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
63
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
64
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
65 -- data bt-path {n : Level} (A : Set n) : Set n where
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
66 -- bt-left : (key : ℕ) → (bt A ) → bt-path A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
67 -- bt-right : (key : ℕ) → (bt A ) → bt-path A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
68
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
69 data bt-path' {n : Level} (A : Set n) : Set n where
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
70 left : (bt A) → bt-path' A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
71 right : (bt A) → bt-path' A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
72
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
73
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
74
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
75 tree->key : {n : Level} {A : Set n} → (tree : bt A) → ℕ
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
76 tree->key {n} L = zero
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
77 tree->key {n} (N key tree tree₁) = key
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
78
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
79 -- path2tree : {n : Level} {A : Set n} → (bt-path' {n} A) → bt A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
80 -- path2tree {n} {A} (left x) = x
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
81 -- path2tree {n} {A} (right x) = x
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
82
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
83
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
84 -- bt-find : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (tree : bt A ) → List (bt-path A)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
85 -- → ( bt A → List (bt-path A) → t ) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
86 -- bt-find {n} {m} {A} {t} key leaf@(L) stack exit = exit leaf stack
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
87 -- bt-find {n} {m} {A} {t} key (N key₁ tree tree₁) stack next with <-cmp key key₁
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
88 -- bt-find {n} {m} {A} {t} key node@(N key₁ tree tree₁) stack exit | tri≈ ¬a b ¬c = exit node stack
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
89 -- bt-find {n} {m} {A} {t} key node@(N key₁ ltree rtree) stack next | tri< a ¬b ¬c = bt-find key ltree (bt-left key node ∷ stack) next
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
90 -- bt-find {n} {m} {A} {t} key node@(N key₁ ltree rtree) stack next | tri> ¬a ¬b c = bt-find key rtree (bt-right key node ∷ stack) next
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
91
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
92
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
93 -- bt-find' : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (tree : bt A ) → List (bt-path' A) → ( bt A → List (bt-path' A) → t ) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
94 -- bt-find' key leaf@(L) stack exit = exit leaf stack
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
95 -- bt-find' key node@(N key1 lnode rnode) stack exit with <-cmp key key1
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
96 -- bt-find' key node@(N key1 lnode rnode) stack exit | tri≈ ¬a b ¬c = exit node stack
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
97 -- bt-find' key node@(N key1 lnode rnode) stack next | tri< a ¬b ¬c = bt-find' key lnode ((left node) ∷ stack) next
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
98 -- bt-find' key node@(N key1 lnode rnode) stack next | tri> ¬a ¬b c = bt-find' key rnode ((right node) ∷ stack) next
597
ryokka
parents: 596
diff changeset
99
ryokka
parents: 596
diff changeset
100
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
101 -- find-next : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (tree : bt A ) → List (bt-path' A)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
102 -- → (next : bt A → List (bt-path' A) → t ) → (exit : bt A → List (bt-path' A) → t ) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
103 -- find-next key leaf@(L) st _ exit = exit leaf st
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
104 -- find-next key (N key₁ tree tree₁) st next exit with <-cmp key key₁
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
105 -- find-next key node@(N key₁ tree tree₁) st _ exit | tri≈ ¬a b ¬c = exit node st
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
106 -- find-next key node@(N key₁ tree tree₁) st next _ | tri< a ¬b ¬c = next tree ((left node) ∷ st)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
107 -- find-next key node@(N key₁ tree tree₁) st next _ | tri> ¬a ¬b c = next tree₁ ((right node) ∷ st)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
108
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
109 -- find-loop は bt-find' とだいたい一緒(induction してるくらい)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
110 -- これも多分 Zコンビネータの一種?
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
111 -- loop で induction してる hight は現在の木の最大長より大きければよい(find-next が抜けきるため)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
112 -- 逆に木の最大長より小さい(たどるルートより小さい)場合は途中経過の値が返る
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
113
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
114 -- find-loop : {n m : Level} {A : Set n} {t : Set m} → (hight key : ℕ) → (tree : bt A ) → List (bt-path' A) → (exit : bt A → List (bt-path' A) → t) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
115 -- find-loop zero key tree st exit = exit tree st
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
116 -- find-loop (suc h) key lf@(L) st exit = exit lf st
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
117 -- find-loop (suc h) key tr@(N key₁ tree tree₁) st exit = find-next key tr st ((λ tr1 st1 → find-loop h key tr1 st1 exit)) exit
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
118
597
ryokka
parents: 596
diff changeset
119
ryokka
parents: 596
diff changeset
120
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
121 node-ex : {n : Level} {A : Set n} → bt A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
122 node-ex {n} {A} = (N zero (L) (L))
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
123
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
124 ex : {n : Level} {A : Set n} → bt A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
125 ex {n} {A} = (N {n} {A} 8 (N 6 (N 2 (N 1 L L) (N 3 L L)) (N 7 L L)) (N 9 L L))
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
126
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
127 exLR : {n : Level} {A : Set n} → bt A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
128 exLR {n} {A} = (N {n} {A} 4 (N 2 L (N 3 L L)) (N 5 L L))
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
129
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
130 exRL : {n : Level} {A : Set n} → bt A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
131 exRL {n} {A} = (N {n} {A} 3 L (N 5 (N 4 L L) L))
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
132
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
133
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
134
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
135
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
136 leaf-ex : {n : Level} {A : Set n} → bt A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
137 leaf-ex {n} {A} = L
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
138
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
139
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
140
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
141
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
142
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
143
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
144 findLoopInv : {n m : Level} {A : Set n} {t : Set m} → (orig : bt A) → (modify : bt A )
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
145 → (stack : List (bt-path' A)) → Set n
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
146 -- findLoopInv {n} {m} {A} {t} tree mtree [] = tree ≡ mtree
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
147 -- findLoopInv {n} {m} {A} {t} tree mtree (left (L) ∷ st) = mtree ≡ (L)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
148 -- findLoopInv {n} {m} {A} {t} tree mtree (right (L) ∷ st) = mtree ≡ (L)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
149 findLoopInv {n} {m} {A} {t} tree mtree [] = tree ≡ mtree
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
150 findLoopInv {n} {m} {A} {t} tree mtree (left L ∷ st) = mtree ≡ (L)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
151 findLoopInv {n} {m} {A} {t} tree mtree (right L ∷ st) = mtree ≡ (L)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
152 findLoopInv {n} {m} {A} {t} tree mtree (left (N key x x₁) ∷ st) = mtree ≡ x
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
153 findLoopInv {n} {m} {A} {t} tree mtree (right (N key x x₁) ∷ st) = mtree ≡ x₁
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
154
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
155
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
156
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
157
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
158
597
ryokka
parents: 596
diff changeset
159
588
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
160
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
161
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
162
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
163 hightMerge : {n m : Level} {A : Set n} {t : Set m} → (l r : ℕ) → (ℕ → t) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
164 hightMerge lh rh next with <-cmp lh rh
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
165 hightMerge lh rh next | tri< a ¬b ¬c = next rh
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
166 hightMerge lh rh next | tri≈ ¬a b ¬c = next lh
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
167 hightMerge lh rh next | tri> ¬a ¬b c = next lh
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
168
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
169 isHightL : {n m : Level} {A : Set n} {t : Set m} → bt A → (ℕ → t) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
170 isHightL L next = next zero
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
171 isHightL {n} {_} {A} (N key tree tree₁) next = isHightL tree λ x → next (suc x)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
172
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
173 isHightR : {n m : Level} {A : Set n} {t : Set m} → bt A → (ℕ → t) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
174 isHightR L next = next zero
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
175 isHightR {n} {_} {A} (N key tree tree₁) next = isHightR tree₁ λ x → next (suc x)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
176
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
177 isHight : {n m : Level} {A : Set n} {t : Set m} → bt A → (ℕ → t) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
178 isHight L next = next zero
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
179 isHight {n} {_} {A} tr@(N key tree tree₁) next = isHightL tr (λ lh → isHightR tr λ rh → hightMerge {n} {_} {A} (suc lh) (suc rh) next)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
180
597
ryokka
parents: 596
diff changeset
181
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
182 treeHight : {n m : Level} {A : Set n} {t : Set m} → bt A → (ℕ → t) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
183 treeHight L next = next zero
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
184 treeHight {n} {_} {A} (N key tree tree₁) next = isHight tree (λ lh → isHight tree₁ (λ rh → hightMerge {n} {_} {A} (lh) (rh) next))
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
185
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
186 rhight : {n : Level} {A : Set n} → bt A → ℕ
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
187 rhight L = zero
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
188 rhight (N key tree tree₁) with <-cmp (rhight tree) (rhight tree₁)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
189 rhight (N key tree tree₁) | tri< a ¬b ¬c = suc (rhight tree₁)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
190 rhight (N key tree tree₁) | tri≈ ¬a b ¬c = suc (rhight tree₁)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
191 rhight (N key tree tree₁) | tri> ¬a ¬b c = suc (rhight tree)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
192
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
193 leaf≠node : {n : Level} {A : Set n} {a : ℕ} {l r : bt A} → ((N {n} {A} a l r) ≡ L) → ⊥
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
194 leaf≠node ()
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
195
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
196 leafIsNoHight : {n : Level} {A : Set n} (tree : bt A) → tree ≡ L → (treeHight tree (λ x → x) ≡ 0)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
197 leafIsNoHight L refl = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
198
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
199
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
200
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
201 hight-tree : {n : Level} {A : Set n} {k : ℕ} {l r : bt A} → ℕ → (tree : bt A) → Set n
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
202 hight-tree zero tree = tree ≡ L
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
203 hight-tree {n} {A} {k} {l} {r} (suc h) tree = tree ≡ (N k l r)
597
ryokka
parents: 596
diff changeset
204
ryokka
parents: 596
diff changeset
205
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
206 hightIsNotLeaf : {n : Level} {A : Set n} (h : ℕ) → (tree : bt A) → (h ≡ 0 ) ∧ (h ≡ treeHight tree (λ x → x)) → (tree ≡ L)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
207 hightIsNotLeaf .0 tree record { proj1 = refl ; proj2 = p2 } = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
208
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
209 -- leaf≡0 : {n : Level} {A : Set n} (tree : bt A) → (rhight tree ≡ 0) → tree ≡ L
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
210 -- leaf≡0 L _ = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
211
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
212
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
213
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
214
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
215
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
216
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
217
597
ryokka
parents: 596
diff changeset
218
ryokka
parents: 596
diff changeset
219
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
220 find-hoare-next : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (tree mt : bt A ) → (st : List (bt-path' A)) → (findLoopInv {n} {m} {A} {t} tree mt st)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
221 → (next : (nt : bt A) → (ns : List (bt-path' A)) → (findLoopInv {n} {m} {A} {t} tree nt ns) → t )
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
222 → (exit : (nt : bt A) → (ns : List (bt-path' A)) → (nt ≡ L) ∨ (key ≡ tree->key nt) → t ) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
223 find-hoare-next key leaf@(L) mt st eq _ exit = exit leaf st (case1 refl)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
224 find-hoare-next key (N key₁ tree tree₁) mt st eq next exit with <-cmp key key₁
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
225 find-hoare-next key node@(N key₁ tree tree₁) mt st eq _ exit | tri≈ ¬a b ¬c = exit node st (case2 b)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
226 find-hoare-next key node@(N key₁ tree tree₁) mt st eq next _ | tri< a ¬b ¬c = next tree ((left node) ∷ st) refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
227 find-hoare-next key node@(N key₁ tree tree₁) mt st eq next _ | tri> ¬a ¬b c = next tree₁ ((right node) ∷ st) refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
228
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
229 find-hoare-loop : {n m : Level} {A : Set n} {t : Set m} → (hight key : ℕ) → (tree mt : bt A ) → (st : List (bt-path' A)) → (findLoopInv {n} {m} {A} {t} tree mt st)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
230 → (exit : (nt : bt A) → (ns : List (bt-path' A)) → (nt ≡ L) ∨ (key ≡ tree->key nt) → t) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
231 find-hoare-loop zero key tree mt st eq exit with key ≟ (tree->key tree)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
232 find-hoare-loop zero key tree mt st eq exit | yes p = exit tree st (case2 p)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
233 find-hoare-loop zero key tree mt st eq exit | no ¬p = exit tree st (case1 {!!})
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
234
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
235 find-hoare-loop (suc h) key otr lf@(L) st eq exit = exit lf st (case1 refl)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
236 find-hoare-loop (suc h) key otr tr@(N key₁ tree tree₁) st eq exit = find-hoare-next key otr tr st {!!} ((λ tr1 st1 eq → find-hoare-loop h key otr tr1 st1 {!!} exit)) exit
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
237
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
238
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
239 -- bt-replace : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → bt A → List (bt-path A) → (bt A → t ) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
240 -- bt-replace {n} {m} {A} {t} ikey otree stack next = bt-replace0 otree where
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
241 -- bt-replace1 : bt A → List (bt-path A) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
242 -- bt-replace1 tree [] = next tree
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
243 -- bt-replace1 node (bt-left key (L) ∷ stack) = bt-replace1 node stack
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
244 -- bt-replace1 node (bt-right key (L) ∷ stack) = bt-replace1 node stack
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
245 -- bt-replace1 node (bt-left key (N key₁ x x₁) ∷ stack) = bt-replace1 (N key₁ node x₁) stack
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
246 -- bt-replace1 node (bt-right key (N key₁ x x₁) ∷ stack) = bt-replace1 (N key₁ x node) stack
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
247 -- bt-replace0 : (tree : bt A) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
248 -- bt-replace0 tree@(N key ltr rtr) = bt-replace1 tree stack -- find case
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
249 -- bt-replace0 (L) = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
250
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
251
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
252
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
253 -- bt-insert : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → bt A → (bt A → t ) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
254 -- bt-insert {n} {m} {A} {t} key tree next = bt-find key tree [] (λ tr st → bt-replace key tr st (λ new → next new))
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
255
597
ryokka
parents: 596
diff changeset
256
ryokka
parents: 596
diff changeset
257 {--
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
258 [ok] find でステップ毎にみている node と stack の top を一致させる
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
259 [ok] find 中はnode と stack の top が一致する(pre は stack の中身がなく, post は stack の top とずれる)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
260
597
ryokka
parents: 596
diff changeset
261 tree+stack≡tree は find 後の tree と stack をもって
ryokka
parents: 596
diff changeset
262 reverse した stack を使って find をチェックするかんじ?
ryokka
parents: 596
diff changeset
263 --}
588
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
264
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
265 {--
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
266 tree+stack は tree と stack を受け取ってひとしさ(関係)を返すやつ
588
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
267
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
268 --}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
269
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
270 -- tree+stack : {n m : Level} {A : Set n} {t : Set m} → (tree mtree : bt A )
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
271 -- → (stack : List (bt-path A)) → Set n
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
272 -- tree+stack tree mtree [] = tree ≡ mtree -- fin case
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
273 -- tree+stack {n} {m} {A} {t} tree mtree@(L) (bt-left key x ∷ stack) = (mtree ≡ x) -- unknow case
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
274 -- tree+stack {n} {m} {A} {t} tree mtree@(L) (bt-right key x ∷ stack) = (mtree ≡ x) -- we nofound leaf's left, right node
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
275 -- tree+stack {n} {m} {A} {t} tree mtree@(N key1 ltree rtree) (bt-left key x ∷ stack) = (mtree ≡ x) ∧ (tree+stack {n} {m} {_} {t} tree ltree stack) -- correct case
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
276 -- tree+stack {n} {m} {A} {t} tree mtree@(N key₁ ltree rtree) (bt-right key x ∷ stack) = (mtree ≡ x) ∧ (tree+stack {n} {m} {_} {t} tree rtree stack)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
277
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
278 {--
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
279 tree+stack
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
280 2. find loop → "top of reverse stack" ≡ "find route orig tree"
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
281 --}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
282
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
283 -- s+t≡t : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (tree : bt A ) → (stack : List (bt-path' {n} A)) → bt-find' key tree stack (λ mt st → s+t {n} {A} tree mt st)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
284 -- s+t≡t {n} {m} {A} {t} key (L) [] = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
285 -- s+t≡t {n} {m} {A} {t} key (L) (left x ∷ []) = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
286 -- s+t≡t {n} {m} {A} {t} key (L) (left x ∷ x₁ ∷ stack) = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
287 -- s+t≡t {n} {m} {A} {t} key (L) (right x ∷ []) = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
288 -- s+t≡t {n} {m} {A} {t} key (L) (right x ∷ x₁ ∷ stack) = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
289 -- s+t≡t {n} {m} {A} {t} key (N key₁ tree tree₁) [] with <-cmp key key₁
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
290 -- s+t≡t {n} {m} {A} {t} key (N key₁ tree tree₁) [] | tri≈ ¬a b ¬c = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
291 -- s+t≡t {n} {m} {A} {t} key (N key₁ tree tree₁) [] | tri< a ¬b ¬c = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
292 -- s+t≡t {n} {m} {A} {t} key (N key₁ tree tree₁) [] | tri> ¬a ¬b c = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
293 -- s+t≡t {n} {m} {A} {t} key (N key₁ tree tree₁) (x ∷ stack) = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
294
597
ryokka
parents: 596
diff changeset
295
ryokka
parents: 596
diff changeset
296
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
297 -- s+t : {n : Level} {A : Set n} → (tree mtree : bt A ) → (stack : List (bt-path' {n} A)) → Set n
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
298 -- s+t tree mtree [] = tree ≡ mtree
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
299 -- s+t tree mtree (x ∷ []) = tree ≡ mtree
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
300 -- s+t tr@(L) mt (left x ∷ x₁ ∷ stack) = tr ≡ mt
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
301 -- s+t {n} {A} tr@(N key tree tree₁) mt (left x ∷ x₁ ∷ stack) = (mt ≡ x) ∧ (s+t {n} {A} tree (path2tree x₁) stack)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
302 -- s+t tr@(L) mt (right x ∷ x₁ ∷ stack) = tr ≡ mt
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
303 -- s+t {n} {A} tr@(N key tree tree₁) mt (right x ∷ x₁ ∷ stack) = (mt ≡ x) ∧ (s+t {n} {A} tree₁ (path2tree x₁) stack)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
304
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
305 -- data treeType {n : Level} (A : Set n) : Set n where
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
306 -- leaf-t : treeType A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
307 -- node-t : treeType A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
308
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
309 -- isType : {n : Level} {A : Set n} → bt A → treeType A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
310 -- isType (L) = leaf-t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
311 -- isType (N key tree tree₁) = node-t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
312
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
313 -- data findState : Set where
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
314 -- s1 : findState
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
315 -- s2 : findState
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
316 -- sf : findState
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
317
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
318 -- findStateP : {n : Level} {A : Set n} → findState → ℕ → bt A → (mnode : bt A) → List (bt-path' A) → Set n
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
319 -- findStateP s1 key node mnode stack = stack ≡ []
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
320 -- findStateP s2 key node mnode stack = (s+t node mnode (reverse stack))
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
321 -- findStateP sf key node mnode stack = (key ≡ (tree->key mnode)) ∨ ((isType mnode) ≡ leaf-t)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
322
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
323 -- findStartPwP : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (tree mtree : bt A ) → (findStateP s1 key tree mtree [] → t) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
324 -- findStartPwP key tree mtree next = next refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
325
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
326
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
327
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
328 -- findLoopPwP : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (tree mtree : bt A ) → (st : List (bt-path' A))
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
329 -- → (findStateP s2 key tree mtree st)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
330 -- → (next : (tr : bt A) → (st : List (bt-path' A)) → (findStateP s2 key tree mtree st) → t)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
331 -- → (exit : (tr : bt A) → (st : List (bt-path' A)) → (findStateP sf key tree mtree st) → t ) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
332 -- findLoopPwP key tree (L) [] state next exit = exit tree [] (case2 refl)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
333 -- findLoopPwP key tree (N key₁ mtree mtree₁) [] state next exit = next tree [] {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
334 -- findLoopPwP key tree mtree (x ∷ []) state next exit = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
335 -- findLoopPwP key tree (L) (x ∷ x₁ ∷ stack) state next exit = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
336 -- findLoopPwP key tree (N key₁ mtree mtree₁) (left x ∷ x₁ ∷ stack) state next exit =
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
337 -- next {!!} {!!} {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
338 -- findLoopPwP key tree (N key₁ mtree mtree₁) (right x ∷ x₁ ∷ stack) state next exit = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
339
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
340
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
341 -- -- tree+stack' {n} {m} {A} {t} (N key ltree rtree) mtree@(N key₁ lmtree rmtree) (x ∷ stack) with <-cmp key key₁
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
342 -- tree+stack' {n} {m} {A} {t} tt@(N key ltree rtree) mt@(N key₁ lmtree rmtree) (x ∷ stack) | tri≈ ¬a b ¬c = tt ≡ mt
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
343 -- tree+stack' {n} {m} {A} {t} tt@(N key ltree rtree) mt@(N key₁ lmtree rmtree) st@(x ∷ stack) | tri< a ¬b ¬c = (mt ≡ x) ∧ tree+stack' {n} {m} {A} {t} tt lmtree (mt ∷ st)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
344 -- tree+stack' {n} {m} {A} {t} tt@(N key ltree rtree) mt@(N key₁ lmtree rmtree) st@(x ∷ stack) | tri> ¬a ¬b c = (mt ≡ x) ∧ tree+stack' {n} {m} {A} {t} tt rmtree (mt ∷ st)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
345
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
346
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
347
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
348 -- tree+stack≡tree : {n m : Level} {A : Set n} {t : Set m} → (tree mtree : bt A )
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
349 -- → (stack : List (bt-path A )) → tree+stack {_} {m} {_} {t} tree mtree (reverse stack)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
350 -- tree+stack≡tree tree (L key) stack = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
351 -- tree+stack≡tree tree (N key rtree ltree) stack = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
352
597
ryokka
parents: 596
diff changeset
353
ryokka
parents: 596
diff changeset
354
ryokka
parents: 596
diff changeset
355 -- loop はきっと start, running, stop の3つに分けて考えるといいよね
ryokka
parents: 596
diff changeset
356 {-- find status
ryokka
parents: 596
diff changeset
357 1. find start → stack empty
ryokka
parents: 596
diff changeset
358 2. find loop → stack Not empty ∧ node Not empty
ryokka
parents: 596
diff changeset
359 or "in reverse stack" ≡ "find route orig tree"
ryokka
parents: 596
diff changeset
360 3. find fin → "stack Not empty ∧ current node is leaf"
ryokka
parents: 596
diff changeset
361 or "stack Not empty ∧ current node key ≡ find-key"
ryokka
parents: 596
diff changeset
362 --}
ryokka
parents: 596
diff changeset
363
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
364 -- find-step : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (tree : bt A) → (stack : List (bt A))
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
365 -- → (next : (mtree : bt A) → (stack1 : List (bt A)) → (tree+stack' {n} {m} {A} {t} tree mtree stack1 ) → t)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
366 -- → (exit : (mtree : bt A) → List (bt A) → (tree ≡ L (tree->key mtree )) ∨ (key ≡ (tree->key mtree)) → t) → t
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
367 -- find-step {n} {m} {A} {t} key (L) stack next exit = exit (L) stack (case1 refl)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
368 -- find-step {n} {m} {A} {t} key (N key₁ node node₁) stack next exit with <-cmp key key₁
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
369 -- find-step {n} {m} {A} {t} key (N key₁ node node₁) stack next exit | tri≈ ¬a b ¬c = exit (N key₁ node node₁) stack (case2 b)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
370 -- find-step {n} {m} {A} {t} key (N key₁ node node₁) stack next exit | tri< a ¬b ¬c = next node stack {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
371 -- find-step {n} {m} {A} {t} key (N key₁ node node₁) stack next exit | tri> ¬a ¬b c = next node₁ stack {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
372
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
373
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
374 -- find-check : {n m : Level} {A : Set n} {t : Set m} → (k : ℕ) → (tree : bt A )
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
375 -- → (stack : List (bt-path A )) → bt-find k tree [] (λ mtree mstack → tree+stack {_} {m} {_} {t} tree mtree (reverse mstack))
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
376 -- find-check {n} {m} {A} {t} key (L) [] = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
377 -- find-check {n} {m} {A} {t} key (N key₁ tree tree₁) [] with <-cmp key key₁
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
378 -- find-check {n} {m} {A} {t} key (N key₁ tree tree₁) [] | tri≈ ¬a b ¬c = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
379 -- find-check {n} {m} {A} {t} key (N key₁ tree tree₁) [] | tri< a ¬b ¬c = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
380 -- find-check {n} {m} {A} {t} key (N key₁ tree tree₁) [] | tri> ¬a ¬b c = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
381 -- find-check {n} {m} {A} {t} key tree (x ∷ stack) = {!!}
597
ryokka
parents: 596
diff changeset
382
ryokka
parents: 596
diff changeset
383
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
384 -- module ts where
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
385 -- tbt : {n : Level} {A : Set n} → bt A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
386 -- tbt {n} {A} = N {n} {A} 8 (N 6 (N 2 (L) (L)) (L)) (L)
597
ryokka
parents: 596
diff changeset
387
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
388 -- find : {n : Level} {A : Set n} → ℕ → List (bt-path A)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
389 -- find {n} {A} key = bt-find key tbt [] (λ x y → y )
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
390
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
391 -- find' : {n : Level} {A : Set n} → ℕ → bt A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
392 -- find' {n} {A} key = bt-find' key tbt [] (λ x y → x )
597
ryokka
parents: 596
diff changeset
393
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
394 -- rep : {n m : Level} {A : Set n} {t : Set m} → ℕ → bt A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
395 -- rep {n} {m} {A} {t} key = bt-find {n} {_} {A} key tbt [] (λ tr st → bt-replace key tr st (λ mtr → mtr))
597
ryokka
parents: 596
diff changeset
396
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
397 -- ins : {n m : Level} {A : Set n} {t : Set m} → ℕ → bt A
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
398 -- ins {n} {m} {A} {t} key = bt-insert key tbt (λ tr → tr)
597
ryokka
parents: 596
diff changeset
399
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
400 -- test : {n m : Level} {A : Set n} {t : Set m} (key : ℕ)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
401 -- → bt-find {n} {_} {A} {_} key tbt [] (λ x y → tree+stack {n} {m} {A} {t} tbt x y)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
402 -- test key = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
403 -- --
597
ryokka
parents: 596
diff changeset
404 --
ryokka
parents: 596
diff changeset
405 -- no children , having left node , having right node , having both
ryokka
parents: 596
diff changeset
406 --
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
407 data bt' {n : Level} (A : Set n) : (key : ℕ) → Set n where -- (a : Setn)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
408 bt'-leaf : (key : ℕ) → bt' A key
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
409 bt'-node : { l r : ℕ } → (key : ℕ) → (value : A) →
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
410 bt' A l → bt' A r → l ≤ key → key ≤ r → bt' A key
597
ryokka
parents: 596
diff changeset
411
ryokka
parents: 596
diff changeset
412 -- data bt'-path {n : Level} (A : Set n) : ℕ → Set n where -- (a : Setn)
ryokka
parents: 596
diff changeset
413 -- bt'-left : (key : ℕ) → {left-key : ℕ} → (bt' A left-key ) → (key ≤ left-key) → bt'-path A left-key
ryokka
parents: 596
diff changeset
414 -- bt'-right : (key : ℕ) → {right-key : ℕ} → (bt' A right-key ) → (right-key ≤ key) → bt'-path A right-key
ryokka
parents: 596
diff changeset
415
ryokka
parents: 596
diff changeset
416
ryokka
parents: 596
diff changeset
417 -- test = bt'-left {Z} {ℕ} 3 {5} (bt'-leaf 5) (s≤s (s≤s (s≤s z≤n)))
588
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
418
594
4bbeb8d9e250 add comment
ryokka
parents: 593
diff changeset
419
4bbeb8d9e250 add comment
ryokka
parents: 593
diff changeset
420
4bbeb8d9e250 add comment
ryokka
parents: 593
diff changeset
421 -- reverse1 : List (bt' A tn) → List (bt' A tn) → List (bt' A tn)
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
422 -- reverse1 [] s1 = s1+
594
4bbeb8d9e250 add comment
ryokka
parents: 593
diff changeset
423 -- reverse1 (x ∷ s0) s1 with reverse1 s0 (x ∷ s1)
4bbeb8d9e250 add comment
ryokka
parents: 593
diff changeset
424 -- ... | as = {!!}
4bbeb8d9e250 add comment
ryokka
parents: 593
diff changeset
425
4bbeb8d9e250 add comment
ryokka
parents: 593
diff changeset
426
596
ryokka
parents: 595
diff changeset
427
597
ryokka
parents: 596
diff changeset
428 -- bt-find' : {n m : Level} {A : Set n} {t : Set m} {tn : ℕ} → (key : ℕ) → (tree : bt' A tn ) → List (bt'-path A tn)
ryokka
parents: 596
diff changeset
429 -- → ( {key1 : ℕ } → bt' A key1 → List (bt'-path A key1) → t ) → t
ryokka
parents: 596
diff changeset
430 -- bt-find' key tr@(bt'-leaf key₁) stack next = next tr stack -- no key found
ryokka
parents: 596
diff changeset
431 -- bt-find' key (bt'-node key₁ value tree tree₁ x x₁) stack next with <-cmp key key₁
ryokka
parents: 596
diff changeset
432 -- bt-find' key tr@(bt'-node {l} {r} key₁ value tree tree₁ x x₁) stack next | tri< a ¬b ¬c =
ryokka
parents: 596
diff changeset
433 -- bt-find' key tree ( (bt'-left key {!!} ({!!}) ) ∷ {!!}) next
ryokka
parents: 596
diff changeset
434 -- bt-find' key found@(bt'-node key₁ value tree tree₁ x x₁) stack next | tri≈ ¬a b ¬c = next found stack
ryokka
parents: 596
diff changeset
435 -- bt-find' key tr@(bt'-node key₁ value tree tree₁ x x₁) stack next | tri> ¬a ¬b c =
ryokka
parents: 596
diff changeset
436 -- bt-find' key tree ( (bt'-right key {!!} {!!} ) ∷ {!!}) next
588
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
437
594
4bbeb8d9e250 add comment
ryokka
parents: 593
diff changeset
438
597
ryokka
parents: 596
diff changeset
439 -- bt-find-step : {n m : Level} {A : Set n} {t : Set m} {tn : ℕ} → (key : ℕ) → (tree : bt' A tn ) → List (bt'-path A tn)
ryokka
parents: 596
diff changeset
440 -- → ( {key1 : ℕ } → bt' A key1 → List (bt'-path A key1) → t ) → t
ryokka
parents: 596
diff changeset
441 -- bt-find-step key tr@(bt'-leaf key₁) stack exit = exit tr stack -- no key found
ryokka
parents: 596
diff changeset
442 -- bt-find-step key (bt'-node key₁ value tree tree₁ x x₁) stack next = {!!}
594
4bbeb8d9e250 add comment
ryokka
parents: 593
diff changeset
443
597
ryokka
parents: 596
diff changeset
444 -- a<sa : { a : ℕ } → a < suc a
ryokka
parents: 596
diff changeset
445 -- a<sa {zero} = s≤s z≤n
ryokka
parents: 596
diff changeset
446 -- a<sa {suc a} = s≤s a<sa
588
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
447
597
ryokka
parents: 596
diff changeset
448 -- a≤sa : { a : ℕ } → a ≤ suc a
ryokka
parents: 596
diff changeset
449 -- a≤sa {zero} = z≤n
ryokka
parents: 596
diff changeset
450 -- a≤sa {suc a} = s≤s a≤sa
592
ryokka
parents: 591
diff changeset
451
597
ryokka
parents: 596
diff changeset
452 -- pa<a : { a : ℕ } → pred (suc a) < suc a
ryokka
parents: 596
diff changeset
453 -- pa<a {zero} = s≤s z≤n
ryokka
parents: 596
diff changeset
454 -- pa<a {suc a} = s≤s pa<a
590
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 589
diff changeset
455
597
ryokka
parents: 596
diff changeset
456 -- bt-replace' : {n m : Level} {A : Set n} {t : Set m} {tn : ℕ} → (key : ℕ) → (value : A ) → (tree : bt' A tn ) → List (bt'-path A {!!})
ryokka
parents: 596
diff changeset
457 -- → ({key1 : ℕ } → bt' A key1 → t ) → t
ryokka
parents: 596
diff changeset
458 -- bt-replace' {n} {m} {A} {t} {tn} key value node stack next = bt-replace1 tn node where
ryokka
parents: 596
diff changeset
459 -- bt-replace0 : {tn : ℕ } (node : bt' A tn ) → List (bt'-path A {!!}) → t
ryokka
parents: 596
diff changeset
460 -- bt-replace0 node [] = next node
ryokka
parents: 596
diff changeset
461 -- bt-replace0 node (bt'-left key (bt'-leaf key₁) x₁ ∷ stack) = {!!}
ryokka
parents: 596
diff changeset
462 -- bt-replace0 {tn} node (bt'-left key (bt'-node key₁ value x x₂ x₃ x₄) x₁ ∷ stack) = bt-replace0 {key₁} (bt'-node key₁ value node x₂ {!!} x₄ ) stack
ryokka
parents: 596
diff changeset
463 -- bt-replace0 node (bt'-right key x x₁ ∷ stack) = {!!}
ryokka
parents: 596
diff changeset
464 -- bt-replace1 : (tn : ℕ ) (tree : bt' A tn ) → t
ryokka
parents: 596
diff changeset
465 -- bt-replace1 tn (bt'-leaf key0) = bt-replace0 (bt'-node tn value
ryokka
parents: 596
diff changeset
466 -- (bt'-leaf (pred tn)) (bt'-leaf (suc tn) ) (≤⇒pred≤ ≤-refl) a≤sa) stack
ryokka
parents: 596
diff changeset
467 -- bt-replace1 tn (bt'-node key value node node₁ x x₁) = bt-replace0 (bt'-node key value node node₁ x x₁) stack
588
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
468
597
ryokka
parents: 596
diff changeset
469 -- tree->key : {n : Level} {tn : ℕ} → (A : Set n) → (tree : bt' A tn ) → ℕ
ryokka
parents: 596
diff changeset
470 -- tree->key {n} {.key} (A) (bt'-leaf key) = key
ryokka
parents: 596
diff changeset
471 -- tree->key {n} {.key} (A) (bt'-node key value tree tree₁ x x₁) = key
593
063274f64a77 bt-replace-hoare
kono
parents: 592
diff changeset
472
063274f64a77 bt-replace-hoare
kono
parents: 592
diff changeset
473
597
ryokka
parents: 596
diff changeset
474 -- bt-find'-assert1 : {n m : Level} {A : Set n} {t : Set m} {tn : ℕ} → (tree : bt' A tn ) → Set n
ryokka
parents: 596
diff changeset
475 -- bt-find'-assert1 {n} {m} {A} {t} {tn} tree = (key : ℕ) → (val : A) → bt-find' key tree [] (λ tree1 stack → key ≡ (tree->key A tree1))
593
063274f64a77 bt-replace-hoare
kono
parents: 592
diff changeset
476
063274f64a77 bt-replace-hoare
kono
parents: 592
diff changeset
477
597
ryokka
parents: 596
diff changeset
478 -- bt-replace-hoare : {n m : Level} {A : Set n} {t : Set m} {tn : ℕ} → (key : ℕ) → (value : A ) → (tree : bt' A tn )
ryokka
parents: 596
diff changeset
479 -- → (pre : bt-find'-assert1 {n} {m} {A} {t} tree → bt-replace' {!!} {!!} {!!} {!!} {!!}) → t
ryokka
parents: 596
diff changeset
480 -- bt-replace-hoare key value tree stack = {!!}
593
063274f64a77 bt-replace-hoare
kono
parents: 592
diff changeset
481
588
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
482
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
483
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
484 -- find'-support : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → (d : ℕ) → (tree : bt' {n} {a} ) → SingleLinkedStack (bt' {n} {a} ) → ( (bt' {n} {a} ) → SingleLinkedStack (bt' {n} {a} ) → Maybe (Σ ℕ (λ d' → _iso_ {n} {a} d d')) → t ) → t
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
485
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
486 -- find'-support {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key leaf@(bt'-leaf x) st cg = cg leaf st nothing
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
487 -- find'-support {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key (bt'-node d tree₁ tree₂ x x₁) st cg with <-cmp key d
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
488 -- find'-support {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key node@(bt'-node d tree₁ tree₂ x x₁) st cg | tri≈ ¬a b ¬c = cg node st (just (d , iso-intro {n} {a} ¬a ¬c))
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
489
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
490 -- find'-support {n} {m} {a} {t} key node@(bt'-node ⦃ nl ⦄ ⦃ l' ⦄ ⦃ nu ⦄ ⦃ u' ⦄ d L R x x₁) st cg | tri< a₁ ¬b ¬c =
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
491 -- pushSingleLinkedStack st node
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
492 -- (λ st2 → find'-support {n} {m} {a} {t} {{l'}} {{d}} key L st2 cg)
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
493
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
494 -- find'-support {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key node@(bt'-node ⦃ ll ⦄ ⦃ ll' ⦄ ⦃ lr ⦄ ⦃ lr' ⦄ d L R x x₁) st cg | tri> ¬a ¬b c = pushSingleLinkedStack st node
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
495 -- (λ st2 → find'-support {n} {m} {a} {t} {{d}} {{lr'}} key R st2 cg)
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
496
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
497
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
498
597
ryokka
parents: 596
diff changeset
499 -- lleaf : {n : Level} {a : Set n} → bt {n} {a}
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
500 -- lleaf = (L ⦃ 0 ⦄ ⦃ 3 ⦄ z≤n)
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
501
597
ryokka
parents: 596
diff changeset
502 -- lleaf1 : {n : Level} {A : Set n} → (0 < 3) → (a : A) → (d : ℕ ) → bt' {n} A d
ryokka
parents: 596
diff changeset
503 -- lleaf1 0<3 a d = bt'-leaf d
588
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
504
597
ryokka
parents: 596
diff changeset
505 -- test-node1 : bt' ℕ 3
ryokka
parents: 596
diff changeset
506 -- test-node1 = bt'-node (3) 3 (bt'-leaf 2) (bt'-leaf 4) (s≤s (s≤s {!!})) (s≤s (s≤s (s≤s {!!})))
588
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
507
8627d35d4bff add data bt', and some function
ryokka
parents: 587
diff changeset
508
597
ryokka
parents: 596
diff changeset
509 -- rleaf : {n : Level} {a : Set n} → bt {n} {a}
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
510 -- rleaf = (L ⦃ 3 ⦄ ⦃ 3 ⦄ (s≤s (s≤s (s≤s z≤n))))
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
511
597
ryokka
parents: 596
diff changeset
512 -- test-node : {n : Level} {a : Set n} → bt {n} {a}
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
513 -- test-node {n} {a} = (N ⦃ 0 ⦄ ⦃ 0 ⦄ ⦃ 4 ⦄ ⦃ 4 ⦄ 3 lleaf rleaf z≤n ≤-refl )
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
514
597
ryokka
parents: 596
diff changeset
515 -- -- stt : {n m : Level} {a : Set n} {t : Set m} → {!!}
ryokka
parents: 596
diff changeset
516 -- -- stt {n} {m} {a} {t} = pushSingleLinkedStack [] (test-node ) (λ st → pushSingleLinkedStack st lleaf (λ st2 → st2) )
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
517
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
518
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
519
597
ryokka
parents: 596
diff changeset
520 -- -- search の {{ l }} {{ u }} はその時みている node の 大小。 l が小さく u が大きい
ryokka
parents: 596
diff changeset
521 -- -- ここでは d が現在の node のkey値なので比較後のsearch では値が変わる
ryokka
parents: 596
diff changeset
522 -- bt-search : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → (d : ℕ) → bt {n} {a} → (Maybe (Σ ℕ (λ d' → _iso_ {n} {a} d d')) → t ) → t
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
523 -- bt-search {n} {m} {a} {t} key (L x) cg = cg nothing
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
524 -- bt-search {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key (N ⦃ ll ⦄ ⦃ l' ⦄ ⦃ uu ⦄ ⦃ u' ⦄ d L R x x₁) cg with <-cmp key d
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
525 -- bt-search {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key (N ⦃ ll ⦄ ⦃ l' ⦄ ⦃ uu ⦄ ⦃ u' ⦄ d L R x x₁) cg | tri< a₁ ¬b ¬c = bt-search ⦃ l' ⦄ ⦃ d ⦄ key L cg
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
526 -- bt-search {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key (N ⦃ ll ⦄ ⦃ l' ⦄ ⦃ uu ⦄ ⦃ u' ⦄ d L R x x₁) cg | tri≈ ¬a b ¬c = cg (just (d , iso-intro {n} {a} ¬a ¬c))
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
527 -- bt-search {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key (N ⦃ ll ⦄ ⦃ l' ⦄ ⦃ uu ⦄ ⦃ u' ⦄ d L R x x₁) cg | tri> ¬a ¬b c = bt-search ⦃ d ⦄ ⦃ u' ⦄ key R cg
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
528
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
529 -- -- bt-search {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key (N ⦃ l ⦄ ⦃ l' ⦄ ⦃ u ⦄ ⦃ u' ⦄ d L R x x₁) cg | tri< a₁ ¬b ¬c = ? -- bt-search ⦃ l' ⦄ ⦃ d ⦄ key L cg
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
530 -- -- bt-search {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key (N d L R x x₁) cg | tri≈ ¬a b ¬c = cg (just (d , iso-intro {n} {a} ¬a ¬c))
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
531 -- -- bt-search {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key (N ⦃ l ⦄ ⦃ l' ⦄ ⦃ u ⦄ ⦃ u' ⦄ d L R x x₁) cg | tri> ¬a ¬b c = bt-search ⦃ d ⦄ ⦃ u' ⦄ key R cg
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
532
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
533
597
ryokka
parents: 596
diff changeset
534 -- -- この辺の test を書くときは型を考えるのがやや面倒なので先に動作を書いてから型を ? から補間するとよさそう
ryokka
parents: 596
diff changeset
535 -- bt-search-test : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → (x : (x₁ : Maybe (Σ ℕ (λ z → ((x₂ : 4 ≤ z) → ⊥) ∧ ((x₂ : suc z ≤ 3) → ⊥)))) → t) → t
ryokka
parents: 596
diff changeset
536 -- bt-search-test {n} {m} {a} {t} = bt-search {n} {m} {a} {t} ⦃ zero ⦄ ⦃ 4 ⦄ 3 test-node
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
537
597
ryokka
parents: 596
diff changeset
538 -- bt-search-test-bad : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → (x : (x₁ : Maybe (Σ ℕ (λ z → ((x₂ : 8 ≤ z) → ⊥) ∧ ((x₂ : suc z ≤ 7) → ⊥)))) → t) → t
ryokka
parents: 596
diff changeset
539 -- bt-search-test-bad {n} {m} {a} {t} = bt-search {n} {m} {a} {t} ⦃ zero ⦄ ⦃ 4 ⦄ 7 test-node
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
540
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
541
597
ryokka
parents: 596
diff changeset
542 -- -- up-some : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ {d : ℕ} → (Maybe (Σ ℕ (λ d' → _iso_ {n} {a} d d'))) → (Maybe ℕ)
ryokka
parents: 596
diff changeset
543 -- -- up-some (just (fst , snd)) = just fst
ryokka
parents: 596
diff changeset
544 -- -- up-some nothing = nothing
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
545
597
ryokka
parents: 596
diff changeset
546 -- search-lem : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → (key : ℕ) → (tree : bt {n} {a} ) → bt-search ⦃ l ⦄ ⦃ u ⦄ key tree (λ gdata → gdata ≡ gdata)
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
547 -- search-lem {n} {m} {a} {t} key (L x) = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
548 -- search-lem {n} {m} {a} {t} key (N d tree₁ tree₂ x x₁) with <-cmp key d
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
549 -- search-lem {n} {m} {a} {t} key (N ⦃ ll ⦄ ⦃ ll' ⦄ ⦃ lr ⦄ ⦃ lr' ⦄ d tree₁ tree₂ x x₁) | tri< lt ¬eq ¬gt = search-lem {n} {m} {a} {t} ⦃ ll' ⦄ ⦃ d ⦄ key tree₁
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
550 -- search-lem {n} {m} {a} {t} key (N d tree₁ tree₂ x x₁) | tri≈ ¬lt eq ¬gt = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
551 -- search-lem {n} {m} {a} {t} key (N ⦃ ll ⦄ ⦃ ll' ⦄ ⦃ lr ⦄ ⦃ lr' ⦄ d tree₁ tree₂ x x₁) | tri> ¬lt ¬eq gt = search-lem {n} {m} {a} {t} ⦃ d ⦄ ⦃ lr' ⦄ key tree₂
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
552
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
553
597
ryokka
parents: 596
diff changeset
554 -- -- bt-find
ryokka
parents: 596
diff changeset
555 -- find-support : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → (d : ℕ) → (tree : bt {n} {a} ) → SingleLinkedStack (bt {n} {a} ) → ( (bt {n} {a} ) → SingleLinkedStack (bt {n} {a} ) → Maybe (Σ ℕ (λ d' → _iso_ {n} {a} d d')) → t ) → t
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
556
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
557 -- find-support {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key leaf@(L x) st cg = cg leaf st nothing
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
558 -- find-support {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key (N d tree₁ tree₂ x x₁) st cg with <-cmp key d
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
559 -- find-support {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key node@(N d tree₁ tree₂ x x₁) st cg | tri≈ ¬a b ¬c = cg node st (just (d , iso-intro {n} {a} ¬a ¬c))
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
560
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
561 -- find-support {n} {m} {a} {t} key node@(N ⦃ nl ⦄ ⦃ l' ⦄ ⦃ nu ⦄ ⦃ u' ⦄ d L R x x₁) st cg | tri< a₁ ¬b ¬c =
597
ryokka
parents: 596
diff changeset
562 -- pushSingleLinkedStack st node
ryokka
parents: 596
diff changeset
563 -- (λ st2 → find-support {n} {m} {a} {t} {{l'}} {{d}} key L st2 cg)
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
564
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
565 -- find-support {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key node@(N ⦃ ll ⦄ ⦃ ll' ⦄ ⦃ lr ⦄ ⦃ lr' ⦄ d L R x x₁) st cg | tri> ¬a ¬b c = pushSingleLinkedStack st node
597
ryokka
parents: 596
diff changeset
566 -- (λ st2 → find-support {n} {m} {a} {t} {{d}} {{lr'}} key R st2 cg)
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
567
597
ryokka
parents: 596
diff changeset
568 -- bt-find : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → (d : ℕ) → (tree : bt {n} {a} ) → SingleLinkedStack (bt {n} {a} ) → ( (bt {n} {a} ) → SingleLinkedStack (bt {n} {a} ) → Maybe (Σ ℕ (λ d' → _iso_ {n} {a} d d')) → t ) → t
ryokka
parents: 596
diff changeset
569 -- bt-find {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ key tr st cg = clearSingleLinkedStack st
ryokka
parents: 596
diff changeset
570 -- (λ cst → find-support ⦃ l ⦄ ⦃ u ⦄ key tr cst cg)
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
571
597
ryokka
parents: 596
diff changeset
572 -- find-test : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → List bt -- ?
ryokka
parents: 596
diff changeset
573 -- find-test {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ = bt-find {n} {_} {a} ⦃ l ⦄ ⦃ u ⦄ 3 test-node [] (λ tt st ad → st)
ryokka
parents: 596
diff changeset
574 -- {-- result
ryokka
parents: 596
diff changeset
575 -- λ {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ →
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
576 -- N 3 (L z≤n) (L (s≤s (s≤s (s≤s z≤n)))) z≤n (s≤s (s≤s (s≤s (s≤s z≤n)))) ∷ []
597
ryokka
parents: 596
diff changeset
577 -- --}
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
578
597
ryokka
parents: 596
diff changeset
579 -- find-lem : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → (d : ℕ) → (tree : bt {n} {a}) → (st : List (bt {n} {a})) → find-support {{l}} {{u}} d tree st (λ ta st ad → ta ≡ ta)
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
580 -- find-lem d (L x) st = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
581 -- find-lem d (N d₁ tree tree₁ x x₁) st with <-cmp d d₁
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
582 -- find-lem d (N d₁ tree tree₁ x x₁) st | tri≈ ¬a b ¬c = refl
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
583
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
584
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
585 -- find-lem d (N d₁ tree tree₁ x x₁) st | tri< a ¬b ¬c with tri< a ¬b ¬c
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
586 -- find-lem {n} {m} {a} {t} {{l}} {{u}} d (N d₁ tree tree₁ x x₁) st | tri< lt ¬b ¬c | tri< a₁ ¬b₁ ¬c₁ = find-lem {n} {m} {a} {t} {{l}} {{u}} d tree {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
587 -- find-lem d (N d₁ tree tree₁ x x₁) st | tri< a ¬b ¬c | tri≈ ¬a b ¬c₁ = {!!}
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
588 -- find-lem d (N d₁ tree tree₁ x x₁) st | tri< a ¬b ¬c | tri> ¬a ¬b₁ c = {!!}
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
589
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
590 -- find-lem d (N d₁ tree tree₁ x x₁) st | tri> ¬a ¬b c = {!!}
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
591
597
ryokka
parents: 596
diff changeset
592 -- bt-singleton :{n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → (d : ℕ) → ( (bt {n} {a} ) → t ) → t
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
593 -- bt-singleton {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ d cg = cg (N ⦃ 0 ⦄ ⦃ 0 ⦄ ⦃ d ⦄ ⦃ d ⦄ d (L ⦃ 0 ⦄ ⦃ d ⦄ z≤n ) (L ⦃ d ⦄ ⦃ d ⦄ ≤-refl) z≤n ≤-refl)
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
594
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
595
597
ryokka
parents: 596
diff changeset
596 -- singleton-test : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → bt -- ?
ryokka
parents: 596
diff changeset
597 -- singleton-test {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ = bt-singleton {n} {_} {a} ⦃ l ⦄ ⦃ u ⦄ 10 λ x → x
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
598
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
599
597
ryokka
parents: 596
diff changeset
600 -- replace-helper : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → (tree : bt {n} {a} ) → SingleLinkedStack (bt {n} {a} ) → ( (bt {n} {a} ) → t ) → t
ryokka
parents: 596
diff changeset
601 -- replace-helper {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ tree [] cg = cg tree
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
602 -- replace-helper {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ tree@(N d L R x₁ x₂) (L x ∷ st) cg = replace-helper ⦃ l ⦄ ⦃ u ⦄ tree st cg -- Unknown Case
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
603 -- replace-helper {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ (N d tree tree₁ x₁ x₂) (N d₁ x x₃ x₄ x₅ ∷ st) cg with <-cmp d d₁
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
604 -- replace-helper {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ subt@(N d tree tree₁ x₁ x₂) (N d₁ x x₃ x₄ x₅ ∷ st) cg | tri< a₁ ¬b ¬c = replace-helper ⦃ l ⦄ ⦃ u ⦄ (N d₁ subt x₃ x₄ x₅) st cg
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
605 -- replace-helper {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ subt@(N d tree tree₁ x₁ x₂) (N d₁ x x₃ x₄ x₅ ∷ st) cg | tri≈ ¬a b ¬c = replace-helper ⦃ l ⦄ ⦃ u ⦄ (N d₁ subt x₃ x₄ x₅) st cg
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
606 -- replace-helper {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ subt@(N d tree tree₁ x₁ x₂) (N d₁ x x₃ x₄ x₅ ∷ st) cg | tri> ¬a ¬b c = replace-helper ⦃ l ⦄ ⦃ u ⦄ (N d₁ x₃ subt x₄ x₅) st cg
597
ryokka
parents: 596
diff changeset
607 -- replace-helper {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ tree (x ∷ st) cg = replace-helper ⦃ l ⦄ ⦃ u ⦄ tree st cg -- Unknown Case
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
608
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
609
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
610
597
ryokka
parents: 596
diff changeset
611 -- bt-replace : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄
ryokka
parents: 596
diff changeset
612 -- → (d : ℕ) → (bt {n} {a} ) → SingleLinkedStack (bt {n} {a} )
ryokka
parents: 596
diff changeset
613 -- → Maybe (Σ ℕ (λ d' → _iso_ {n} {a} d d')) → ( (bt {n} {a} ) → t ) → t
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
614 -- bt-replace {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ d tree st eqP cg = replace-helper {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ ((N ⦃ 0 ⦄ ⦃ 0 ⦄ ⦃ d ⦄ ⦃ d ⦄ d (L ⦃ 0 ⦄ ⦃ d ⦄ z≤n ) (L ⦃ d ⦄ ⦃ d ⦄ ≤-refl) z≤n ≤-refl)) st cg
586
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
615
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
616
0ddfa505d612 isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
diff changeset
617
597
ryokka
parents: 596
diff changeset
618 -- -- 証明に insert がはいっててほしい
ryokka
parents: 596
diff changeset
619 -- bt-insert : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → (d : ℕ) → (tree : bt {n} {a})
ryokka
parents: 596
diff changeset
620 -- → ((bt {n} {a}) → t) → t
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
621
597
ryokka
parents: 596
diff changeset
622 -- bt-insert {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ d tree cg = bt-find {n} {_} {a} ⦃ l ⦄ ⦃ u ⦄ d tree [] (λ tt st ad → bt-replace ⦃ l ⦄ ⦃ u ⦄ d tt st ad cg )
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
623
597
ryokka
parents: 596
diff changeset
624 -- pickKey : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → (tree : bt {n} {a}) → Maybe ℕ
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
625 -- pickKey (L x) = nothing
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
626 -- pickKey (N d tree tree₁ x x₁) = just d
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
627
597
ryokka
parents: 596
diff changeset
628 -- insert-test : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → bt -- ?
ryokka
parents: 596
diff changeset
629 -- insert-test {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ = bt-insert {n} {_} {a} ⦃ l ⦄ ⦃ u ⦄ 1 test-node λ x → x
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
630
597
ryokka
parents: 596
diff changeset
631 -- insert-test-l : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → bt -- ?
ryokka
parents: 596
diff changeset
632 -- insert-test-l {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ = bt-insert {n} {_} {a} ⦃ l ⦄ ⦃ u ⦄ 1 (lleaf) λ x → x
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
633
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
634
597
ryokka
parents: 596
diff changeset
635 -- insert-lem : {n m : Level} {a : Set n} {t : Set m} ⦃ l u : ℕ ⦄ → (d : ℕ) → (tree : bt {n} {a})
ryokka
parents: 596
diff changeset
636 -- → bt-insert {n} {_} {a} ⦃ l ⦄ ⦃ u ⦄ d tree (λ tree1 → bt-find ⦃ l ⦄ ⦃ u ⦄ d tree1 []
ryokka
parents: 596
diff changeset
637 -- (λ tt st ad → (pickKey {n} {m} {a} {t} ⦃ l ⦄ ⦃ u ⦄ tt) ≡ just d ) )
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
638
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
639
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
640 -- insert-lem d (L x) with <-cmp d d -- bt-insert d (L x) (λ tree1 → {!!})
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
641 -- insert-lem d (L x) | tri< a ¬b ¬c = ⊥-elim (¬b refl)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
642 -- insert-lem d (L x) | tri≈ ¬a b ¬c = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
643 -- insert-lem d (L x) | tri> ¬a ¬b c = ⊥-elim (¬b refl)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
644 -- insert-lem d (N d₁ tree tree₁ x x₁) with <-cmp d d₁
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
645 -- -- bt-insert d (N d₁ tree tree₁ x x₁) (λ tree1 → {!!})
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
646 -- insert-lem d (N d₁ tree tree₁ x x₁) | tri≈ ¬a b ¬c with <-cmp d d
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
647 -- insert-lem d (N d₁ tree tree₁ x x₁) | tri≈ ¬a b ¬c | tri< a ¬b ¬c₁ = ⊥-elim (¬b refl)
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
648 -- insert-lem d (N d₁ tree tree₁ x x₁) | tri≈ ¬a b ¬c | tri≈ ¬a₁ b₁ ¬c₁ = refl
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
649 -- insert-lem d (N d₁ tree tree₁ x x₁) | tri≈ ¬a b ¬c | tri> ¬a₁ ¬b c = ⊥-elim (¬b refl)
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
650
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
651 -- insert-lem d (N d₁ tree tree₁ x x₁) | tri< a ¬b ¬c = {!!}
597
ryokka
parents: 596
diff changeset
652 -- where
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
653 -- lem-helper : find-support ⦃ {!!} ⦄ ⦃ {!!} ⦄ d tree (N d₁ tree tree₁ x x₁ ∷ []) (λ tt₁ st ad → replace-helper ⦃ {!!} ⦄ ⦃ {!!} ⦄ (N ⦃ {!!} ⦄ ⦃ {!!} ⦄ ⦃ {!!} ⦄ ⦃ {!!} ⦄ d (L ⦃ 0 ⦄ ⦃ d ⦄ z≤n) (L ⦃ {!!} ⦄ ⦃ {!!} ⦄ (≤-reflexive refl)) z≤n (≤-reflexive refl)) st (λ tree1 → find-support ⦃ {!!} ⦄ ⦃ {!!} ⦄ d tree1 [] (λ tt₂ st₁ ad₁ → pickKey {{!!}} {{!!}} {{!!}} {{!!}} ⦃ {!!} ⦄ ⦃ {!!} ⦄ tt₂ ≡ just d)))
597
ryokka
parents: 596
diff changeset
654 -- lem-helper = {!!}
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
655
600
016a8deed93d fix old binary tree
ryokka
parents: 597
diff changeset
656 -- insert-lem d (N d₁ tree tree₁ x x₁) | tri> ¬a ¬b c = {!!}
587
f103f07c0552 add insert code
ryokka
parents: 586
diff changeset
657