Mercurial > hg > Members > Moririn
annotate redBlackTreeTest.agda @ 628:ec2506b532ba
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Nov 2021 23:44:24 +0900 |
parents | 7bacba816277 |
children |
rev | line source |
---|---|
537 | 1 module redBlackTreeTest where |
2 | |
554
988c12d7f887
use another nat comparator
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
553
diff
changeset
|
3 open import Level hiding (zero) renaming ( suc to succ ) |
537 | 4 |
553 | 5 open import Data.Empty |
575 | 6 open import Data.List |
7 open import Data.Maybe | |
8 open import Data.Bool | |
537 | 9 open import Data.Nat |
575 | 10 open import Data.Nat.Properties as NatProp |
11 | |
553 | 12 open import Relation.Nullary |
575 | 13 open import Relation.Binary |
564
40ab3d39e49d
using strict total order
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
563
diff
changeset
|
14 |
40ab3d39e49d
using strict total order
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
563
diff
changeset
|
15 open import Algebra |
575 | 16 |
17 open import RedBlackTree | |
18 open import stack | |
564
40ab3d39e49d
using strict total order
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
563
diff
changeset
|
19 |
537 | 20 open Tree |
21 open Node | |
22 open RedBlackTree.RedBlackTree | |
23 open Stack | |
24 | |
25 -- tests | |
26 | |
575 | 27 putTree1 : {n m : Level } {a k : Set n} {t : Set m} → RedBlackTree {n} {m} {t} a k → k → a → ((RedBlackTree {n} {m} {t} a k) → t) → t |
543 | 28 putTree1 {n} {m} {a} {k} {t} tree k1 value next with (root tree) |
575 | 29 ... | nothing = next (record tree {root = just (leafNode k1 value) }) |
30 ... | just n2 = clearSingleLinkedStack (nodeStack tree) (λ s → findNode tree s (leafNode k1 value) n2 (λ tree1 s n1 → replaceNode tree1 s n1 next)) | |
537 | 31 |
32 open import Relation.Binary.PropositionalEquality | |
33 open import Relation.Binary.Core | |
34 open import Function | |
35 | |
36 | |
575 | 37 -- check1 : {m : Level } (n : Maybe (Node ℕ ℕ)) → ℕ → Bool |
38 -- check1 nothing _ = false | |
39 -- check1 (just n) x with Data.Nat.compare (value n) x | |
40 -- ... | equal _ = true | |
41 -- ... | _ = false | |
537 | 42 |
575 | 43 check2 : {m : Level } (n : Maybe (Node ℕ ℕ)) → ℕ → Bool |
44 check2 nothing _ = false | |
45 check2 (just n) x with compare2 (value n) x | |
46 ... | EQ = true | |
47 ... | _ = false | |
549 | 48 |
575 | 49 test1 : {m : Level} {A B C : Set} → putTree1 {Level.zero} {succ Level.zero} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ {!!} {!!} ) 1 1 ( λ t → getRedBlackTree t 1 ( λ t x → check2 {m} x 1 ≡ true )) |
50 test1 = {!!} | |
537 | 51 |
575 | 52 -- test2 : {m : Level} → putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( |
53 -- λ t → putTree1 t 2 2 ( | |
54 -- λ t → getRedBlackTree t 1 ( | |
55 -- λ t x → check2 {m} x 1 ≡ true ))) | |
56 -- test2 = refl | |
537 | 57 |
575 | 58 -- open ≡-Reasoning |
59 -- test3 : {m : Level} → putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero}) 1 1 | |
60 -- $ λ t → putTree1 t 2 2 | |
61 -- $ λ t → putTree1 t 3 3 | |
62 -- $ λ t → putTree1 t 4 4 | |
63 -- $ λ t → getRedBlackTree t 1 | |
64 -- $ λ t x → check2 {m} x 1 ≡ true | |
65 -- test3 {m} = begin | |
66 -- check2 {m} (just (record {key = 1 ; value = 1 ; color = Black ; left = nothing ; right = just (leafNode 2 2)})) 1 | |
67 -- ≡⟨ refl ⟩ | |
68 -- true | |
69 -- ∎ | |
542 | 70 |
575 | 71 -- test31 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 1 1 |
72 -- $ λ t → putTree1 t 2 2 | |
73 -- $ λ t → putTree1 t 3 3 | |
74 -- $ λ t → putTree1 t 4 4 | |
75 -- $ λ t → getRedBlackTree t 4 | |
76 -- $ λ t x → x | |
538
5c001e8ba0d5
add redBlackTreeTest.agda test5,test51. but not work
ryokka
parents:
537
diff
changeset
|
77 |
575 | 78 -- -- test5 : Maybe (Node ℕ ℕ) |
79 -- test5 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 4 4 | |
80 -- $ λ t → putTree1 t 6 6 | |
81 -- $ λ t0 → clearSingleLinkedStack (nodeStack t0) | |
82 -- $ λ s → findNode1 t0 s (leafNode 3 3) ( root t0 ) | |
83 -- $ λ t1 s n1 → replaceNode t1 s n1 | |
84 -- $ λ t → getRedBlackTree t 3 | |
85 -- -- $ λ t x → SingleLinkedStack.top (stack s) | |
86 -- -- $ λ t x → n1 | |
87 -- $ λ t x → root t | |
88 -- where | |
89 -- findNode1 : {n m : Level } {a k : Set n} {t : Set m} → RedBlackTree {n} {m} {t} a k → SingleLinkedStack (Node a k) → (Node a k) → (Maybe (Node a k)) → (RedBlackTree {n} {m} {t} a k → SingleLinkedStack (Node a k) → Node a k → t) → t | |
90 -- findNode1 t s n1 nothing next = next t s n1 | |
91 -- findNode1 t s n1 ( just n2 ) next = findNode t s n1 n2 next | |
538
5c001e8ba0d5
add redBlackTreeTest.agda test5,test51. but not work
ryokka
parents:
537
diff
changeset
|
92 |
575 | 93 -- -- test51 : putTree1 {_} {_} {ℕ} {ℕ} {_} {Maybe (Node ℕ ℕ)} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 $ λ t → |
94 -- -- putTree1 t 2 2 $ λ t → putTree1 t 3 3 $ λ t → root t ≡ just (record { key = 1; value = 1; left = just (record { key = 2 ; value = 2 } ); right = nothing} ) | |
95 -- -- test51 = refl | |
539 | 96 |
575 | 97 -- test6 : Maybe (Node ℕ ℕ) |
98 -- test6 = root (createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)}) | |
539 | 99 |
100 | |
575 | 101 -- test7 : Maybe (Node ℕ ℕ) |
102 -- test7 = clearSingleLinkedStack (nodeStack tree2) (λ s → replaceNode tree2 s n2 (λ t → root t)) | |
103 -- where | |
104 -- tree2 = createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)} | |
105 -- k1 = 1 | |
106 -- n2 = leafNode 0 0 | |
107 -- value1 = 1 | |
539 | 108 |
575 | 109 -- test8 : Maybe (Node ℕ ℕ) |
110 -- test8 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 1 1 | |
111 -- $ λ t → putTree1 t 2 2 (λ t → root t) | |
544 | 112 |
113 | |
575 | 114 -- test9 : {m : Level} → putRedBlackTree {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( λ t → getRedBlackTree t 1 ( λ t x → check2 {m} x 1 ≡ true )) |
115 -- test9 = refl | |
544 | 116 |
575 | 117 -- test10 : {m : Level} → putRedBlackTree {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( |
118 -- λ t → putRedBlackTree t 2 2 ( | |
119 -- λ t → getRedBlackTree t 1 ( | |
120 -- λ t x → check2 {m} x 1 ≡ true ))) | |
121 -- test10 = refl | |
545 | 122 |
575 | 123 -- test11 = putRedBlackTree {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 1 1 |
124 -- $ λ t → putRedBlackTree t 2 2 | |
125 -- $ λ t → putRedBlackTree t 3 3 | |
126 -- $ λ t → getRedBlackTree t 2 | |
127 -- $ λ t x → root t | |
545 | 128 |
564
40ab3d39e49d
using strict total order
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
563
diff
changeset
|
129 |
40ab3d39e49d
using strict total order
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
563
diff
changeset
|
130 compTri : ( x y : ℕ ) -> Tri (x < y) ( x ≡ y ) ( x > y ) |
575 | 131 compTri = IsStrictTotalOrder.compare (Relation.Binary.StrictTotalOrder.isStrictTotalOrder <-strictTotalOrder) |
565 | 132 where open import Relation.Binary |
564
40ab3d39e49d
using strict total order
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
563
diff
changeset
|
133 |
575 | 134 checkT : {m : Level } (n : Maybe (Node ℕ ℕ)) → ℕ → Bool |
135 checkT nothing _ = false | |
136 checkT (just n) x with compTri (value n) x | |
137 ... | tri≈ _ _ _ = true | |
138 ... | _ = false | |
564
40ab3d39e49d
using strict total order
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
563
diff
changeset
|
139 |
575 | 140 checkEQ : {m : Level } ( x : ℕ ) -> ( n : Node ℕ ℕ ) -> (value n ) ≡ x -> checkT {m} (just n) x ≡ true |
565 | 141 checkEQ x n refl with compTri (value n) x |
566 | 142 ... | tri≈ _ refl _ = refl |
143 ... | tri> _ neq gt = ⊥-elim (neq refl) | |
144 ... | tri< lt neq _ = ⊥-elim (neq refl) | |
565 | 145 |
575 | 146 -- checkEQ' : {m : Level } ( x y : ℕ ) -> ( eq : x ≡ y ) -> ( x ≟ y ) ≡ yes eq |
147 -- checkEQ' x y refl with x ≟ y | |
148 -- ... | yes refl = refl | |
149 -- ... | no neq = ⊥-elim ( neq refl ) | |
546 | 150 |
571 | 151 --- search -> checkEQ |
152 --- findNode -> search | |
153 | |
575 | 154 redBlackInSomeState : { m : Level } (a : Set Level.zero) (n : Maybe (Node a ℕ)) {t : Set m} {A B C : Set Level.zero } → RedBlackTree {Level.zero} {m} {t} {A} {B} {C} a ℕ |
155 redBlackInSomeState {m} a n {t} = record { root = n ; nodeStack = emptySingleLinkedStack ; nodeComp = λ x x₁ → {!!} } -- record { root = n ; nodeStack = emptySingleLinkedStack ; compare = compTri } | |
156 | |
157 | |
573 | 158 open stack.SingleLinkedStack |
159 open stack.Element | |
160 | |
578
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
161 |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
162 insertP : { a : Set } { t : Set } {P : Set } → ( f : ( a → t ) → t ) ( g : a → t ) ( g' : P → a → t ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
163 → ( p : P ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
164 → ( g ≡ g' p ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
165 → f ( λ x → g' p x ) ≡ f ( λ x → g x ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
166 insertP f g g' p refl = refl |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
167 |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
168 |
573 | 169 {-# TERMINATING #-} |
575 | 170 inStack : {l : Level} (n : Node ℕ ℕ) (s : SingleLinkedStack (Node ℕ ℕ) ) → Bool |
171 inStack {l} n s with ( top s ) | |
172 ... | nothing = true | |
173 ... | just n1 with compTri (key n) (key (datum n1)) | |
174 ... | tri> _ neq _ = inStack {l} n ( record { top = next n1 } ) | |
175 ... | tri< _ neq _ = inStack {l} n ( record { top = next n1 } ) | |
176 ... | tri≈ _ refl _ = false | |
573 | 177 |
178 record StackTreeInvariant ( n : Node ℕ ℕ ) | |
578
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
179 <<<<<<< working copy |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
180 ( s : SingleLinkedStack (Node ℕ ℕ) ) : Set where |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
181 ||||||| base |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
182 ( s : SingleLinkedStack (Node ℕ ℕ) ) ( t : RedBlackTree ℕ ℕ ) : Set where |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
183 ======= |
575 | 184 ( s : SingleLinkedStack (Node ℕ ℕ) ) ( t : RedBlackTree ℕ ℕ ) : Set where |
578
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
185 >>>>>>> destination |
573 | 186 field |
578
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
187 <<<<<<< working copy |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
188 -- sti : replaceNode t s n $ λ t1 → getRedBlackTree t1 (key n) (λ t2 x1 → checkT x1 (value n) ≡ True) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
189 notInStack : inStack n s ≡ True → ⊥ |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
190 ||||||| base |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
191 sti : replaceNode t s n $ λ t1 → getRedBlackTree t1 (key n) (λ t2 x1 → checkT x1 (value n) ≡ True) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
192 notInStack : inStack n s ≡ True → ⊥ |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
193 ======= |
575 | 194 sti : {m : Level} → replaceNode t s n $ λ t1 → getRedBlackTree t1 (key n) (λ t2 x1 → checkT {m} x1 (value n) ≡ true) |
195 notInStack : {m : Level} → inStack {m} n s ≡ true → ⊥ | |
578
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
196 >>>>>>> destination |
573 | 197 |
198 open StackTreeInvariant | |
199 | |
578
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
200 <<<<<<< working copy |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
201 putTest1 : (n : Maybe (Node ℕ ℕ)) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
202 → (k : ℕ) (x : ℕ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
203 → putTree1 {_} {_} {ℕ} {ℕ} (redBlackInSomeState {_} ℕ n {Set Level.zero}) k x |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
204 (λ t → getRedBlackTree t k (λ t x1 → checkT x1 x ≡ True)) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
205 putTest1 n k x with n |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
206 ... | Just n1 = lemma0 |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
207 where |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
208 tree0 : (n1 : Node ℕ ℕ) (s : SingleLinkedStack (Node ℕ ℕ) ) → RedBlackTree ℕ ℕ |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
209 tree0 n1 s = record { root = Just n1 ; nodeStack = s ; compare = compareT } |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
210 lemma2 : (n1 : Node ℕ ℕ) (s : SingleLinkedStack (Node ℕ ℕ) ) → StackTreeInvariant (leafNode k x) s |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
211 → findNode (tree0 n1 s) s (leafNode k x) n1 (λ tree1 s n1 → replaceNode tree1 s n1 |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
212 (λ t → getRedBlackTree t k (λ t x1 → checkT x1 x ≡ True))) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
213 lemma2 n1 s STI with compTri k (key n1) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
214 ... | tri> le eq gt with (right n1) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
215 ... | Just rightNode = {!!} -- ( lemma2 rightNode ( record { top = Just ( cons n1 (top s) ) } ) (record {notInStack = {!!} } ) ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
216 ... | Nothing with compTri k k |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
217 ... | tri≈ _ refl _ = {!!} |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
218 ... | tri< _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
219 ... | tri> _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
220 lemma2 n1 s STI | tri< le eq gt = {!!} |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
221 lemma2 n1 s STI | tri≈ le refl gt = lemma5 s ( tree0 n1 s ) n1 |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
222 where |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
223 lemma5 : (s : SingleLinkedStack (Node ℕ ℕ) ) → ( t : RedBlackTree ℕ ℕ ) → ( n : Node ℕ ℕ ) → popSingleLinkedStack ( record { top = Just (cons n (SingleLinkedStack.top s)) } ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
224 ( \ s1 _ -> (replaceNode (tree0 n1 s1) s1 (record n1 { key = k ; value = x } ) (λ t → |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
225 GetRedBlackTree.checkNode t (key n1) (λ t₁ x1 → checkT x1 x ≡ True) (root t))) ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
226 lemma5 s t n with (top s) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
227 ... | Just n2 with compTri k k |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
228 ... | tri< _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
229 ... | tri> _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
230 ... | tri≈ _ refl _ = ⊥-elim ( (notInStack STI) {!!} ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
231 lemma5 s t n | Nothing with compTri k k |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
232 ... | tri≈ _ refl _ = checkEQ x _ refl |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
233 ... | tri< _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
234 ... | tri> _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
235 lemma0 : clearSingleLinkedStack (record {top = Nothing}) (\s → findNode (tree0 n1 s) s (leafNode k x) n1 (λ tree1 s n1 → replaceNode tree1 s n1 |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
236 (λ t → getRedBlackTree t k (λ t x1 → checkT x1 x ≡ True)))) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
237 lemma0 = lemma2 n1 (record {top = Nothing}) ( record { notInStack = {!!} } ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
238 ... | Nothing = lemma1 |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
239 where |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
240 lemma1 : getRedBlackTree {_} {_} {ℕ} {ℕ} {Set Level.zero} ( record { root = Just ( record { |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
241 key = k ; value = x ; right = Nothing ; left = Nothing ; color = Red } ) ; nodeStack = record { top = Nothing } ; compare = λ x₁ y → compareT x₁ y } ) k |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
242 ( λ t x1 → checkT x1 x ≡ True) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
243 lemma1 with compTri k k |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
244 ... | tri≈ _ refl _ = checkEQ x _ refl |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
245 ... | tri< _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
246 ... | tri> _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
247 ||||||| base |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
248 putTest1 : (n : Maybe (Node ℕ ℕ)) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
249 → (k : ℕ) (x : ℕ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
250 → putTree1 {_} {_} {ℕ} {ℕ} (redBlackInSomeState {_} ℕ n {Set Level.zero}) k x |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
251 (λ t → getRedBlackTree t k (λ t x1 → checkT x1 x ≡ True)) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
252 putTest1 n k x with n |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
253 ... | Just n1 = lemma0 |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
254 where |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
255 tree0 : (s : SingleLinkedStack (Node ℕ ℕ) ) → RedBlackTree ℕ ℕ |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
256 tree0 s = record { root = Just n1 ; nodeStack = s ; compare = compareT } |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
257 lemma2 : (s : SingleLinkedStack (Node ℕ ℕ) ) → StackTreeInvariant (leafNode k x) s (tree0 s) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
258 → findNode (tree0 s) s (leafNode k x) n1 (λ tree1 s n1 → replaceNode tree1 s n1 |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
259 (λ t → getRedBlackTree t k (λ t x1 → checkT x1 x ≡ True))) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
260 lemma2 s STI with compTri k (key n1) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
261 ... | tri≈ le refl gt = lemma5 s ( tree0 s ) n1 |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
262 where |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
263 lemma5 : (s : SingleLinkedStack (Node ℕ ℕ) ) → ( t : RedBlackTree ℕ ℕ ) → ( n : Node ℕ ℕ ) → popSingleLinkedStack ( record { top = Just (cons n (SingleLinkedStack.top s)) } ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
264 ( \ s1 _ -> (replaceNode (tree0 s1) s1 (record n1 { key = k ; value = x } ) (λ t → |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
265 GetRedBlackTree.checkNode t (key n1) (λ t₁ x1 → checkT x1 x ≡ True) (root t))) ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
266 lemma5 s t n with (top s) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
267 ... | Just n2 with compTri k k |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
268 ... | tri< _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
269 ... | tri> _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
270 ... | tri≈ _ refl _ = ⊥-elim ( (notInStack STI) {!!} ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
271 lemma5 s t n | Nothing with compTri k k |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
272 ... | tri≈ _ refl _ = checkEQ x _ refl |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
273 ... | tri< _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
274 ... | tri> _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
275 ... | tri> le eq gt = sti ( record { sti = {!!} ; notInStack = {!!} } ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
276 ... | tri< le eq gt = {!!} |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
277 lemma0 : clearSingleLinkedStack (record {top = Nothing}) (\s → findNode (tree0 s) s (leafNode k x) n1 (λ tree1 s n1 → replaceNode tree1 s n1 |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
278 (λ t → getRedBlackTree t k (λ t x1 → checkT x1 x ≡ True)))) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
279 lemma0 = lemma2 (record {top = Nothing}) ( record { sti = {!!} ; notInStack = {!!} } ) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
280 ... | Nothing = lemma1 |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
281 where |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
282 lemma1 : getRedBlackTree {_} {_} {ℕ} {ℕ} {Set Level.zero} ( record { root = Just ( record { |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
283 key = k ; value = x ; right = Nothing ; left = Nothing ; color = Red } ) ; nodeStack = record { top = Nothing } ; compare = λ x₁ y → compareT x₁ y } ) k |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
284 ( λ t x1 → checkT x1 x ≡ True) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
285 lemma1 with compTri k k |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
286 ... | tri≈ _ refl _ = checkEQ x _ refl |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
287 ... | tri< _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
288 ... | tri> _ neq _ = ⊥-elim (neq refl) |
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
289 ======= |
575 | 290 |
291 -- testn : {!!} | |
292 -- testn = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 2 2 | |
293 -- $ λ t → putTree1 t 1 1 | |
294 -- $ λ t → putTree1 t 3 3 (λ ta → record {root = root ta ; nodeStack = nodeStack ta }) | |
295 | |
296 | |
297 -- List と Node で書こうとしたがなんだかんだListに直したほうが楽そうだった | |
298 | |
299 nullNode = (record {key = 0 ; value = 0 ; right = nothing ; left = nothing ; color = Red}) | |
300 | |
301 -- treeTotal : { m : Level } {t : Set m} → ( s : List ℕ ) → ( tr : (Node ℕ ℕ) ) → (List ℕ → t) → t | |
302 -- treeTotal {m} {t} s tr next with (left tr) | (right tr) | |
303 -- treeTotal {m} {t} s tr next | nothing | nothing = next ((key tr) ∷ []) | |
304 -- treeTotal {m} {t} s tr next | nothing | just x = treeTotal {m} {t} s x (λ li → next ((key tr) ∷ li)) | |
305 -- treeTotal {m} {t} s tr next | just x | nothing = treeTotal {m} {t} s x (λ li → next ((key tr) ∷ li)) | |
306 -- treeTotal {m} {t} s tr next | just x | just x₁ = treeTotal {m} {t} s x (λ li1 → treeTotal {m} {t} s x₁ (λ li2 → next (s ++ li1 ++ li2))) | |
307 treeTotal : { n m : Level } {a : Set n} {t : Set m} → ( s : List a ) → ( tr : (Node a a) ) → List a | |
308 treeTotal {n} {m} {a} {t} s tr with (left tr) | (right tr) | |
309 treeTotal {n} {m} {a} {t} s tr | nothing | nothing = (key tr) ∷ [] | |
310 treeTotal {n} {m} {a} {t} s tr | nothing | just x = (key tr) ∷ (treeTotal {n} {m} {a} {t} s x) | |
311 treeTotal {n} {m} {a} {t} s tr | just x | nothing = (key tr) ∷ (treeTotal {n} {m} {a} {t} s x) | |
312 treeTotal {n} {m} {a} {t} s tr | just x | just x₁ = s ++ ((key tr) ∷ (treeTotal {n} {m} {a} {t} s x) ++ (treeTotal {n} {m} {a} {t} s x₁)) | |
313 | |
314 | |
315 -- treeTotalA : { m : Level } {t : Set m} → ( s : List ℕ ) → ( tr : (Node ℕ ℕ) ) → List ℕ | |
316 | |
317 -- (treeTotal {_} {ℕ} ([]) (Data.Maybe.fromMaybe nullNode (root (putTree1 {_} {_} {ℕ} {ℕ} testn 5 5 {!!})))) | |
318 | |
319 -- exput : (treeTotal {_} {ℕ} (5 ∷ []) (Data.Maybe.fromMaybe nullNode (root (createEmptyRedBlackTreeℕ ℕ))) (λ total → {!!})) ≡ {!!} | |
320 -- exput = {!!} | |
321 | |
322 | |
323 -- aaa = (treeTotal {_} {_} {ℕ} {_} (5 ∷ []) ((record { key = 4 ; value = 4 ; right = just (leafNode 6 6) ; left = just (leafNode 3 3) ; color = Black }))) | |
324 | |
325 | |
326 -- fuga = putTree1 {_} {_} {ℕ} {ℕ} (record {root = just (record { key = 4 ; value = 4 ; right = just (leafNode 6 6) ; left = just (leafNode 3 3) ; color = Black }) ; nodeStack = ( record {top = nothing}) ; compare = (λ x x₁ → EQ) }) 5 5 (λ aaa → aaa ) | |
327 | |
328 -- nontree ++ 2 :: [] | |
329 | |
330 -- piyo = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 2 2 ( λ t1 → findNode t1 (record {top = nothing}) (leafNode 2 2) (Data.Maybe.fromMaybe nullNode (root t1)) (λ tree stack node → {!!})) | |
331 | |
332 | |
333 -- exn2l : {!!} ≡ (treeTotal {_} {ℕ} ([]) (putTree1 {_} {_} {ℕ} {ℕ} {!!} 5 5 (λ t → {!!}))) -- (treeTotal {_} {ℕ} (5 ∷ []) (Data.Maybe.fromMaybe nullNode (root testn))) | |
334 -- exn2l = refl | |
335 | |
336 | |
337 | |
338 | |
339 | |
340 -- record FS {n m : Level } {a : Set n} {t : Set m} (oldTotal : List a) ( s : List a ) ( tr : (Node a a) ) : Set where | |
341 -- field | |
342 -- total : treeTotal {n} {m} {a} {t} s tr ≡ oldTotal | |
343 -- -- usage = FS.total -- relation | |
344 | |
345 -- data P { n m : Level } { t : Set m } : Set where | |
346 -- P₀ : (old : List ℕ) ( s : List ℕ ) → (tr : (Node ℕ ℕ) ) → FS {m} {t} old s tr → P | |
347 | |
348 | |
349 | |
350 -- ttt = putTree1 {_} {_} {ℕ} {ℕ} | |
351 | |
352 -- record TreeInterface {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set n where | |
353 -- field | |
354 -- tree : treeImpl | |
355 -- list : List ℕ | |
356 -- node : Node ℕ ℕ | |
357 -- putTreeHoare : (FS {_} {ℕ} list list node) → putTree1 {!!} {!!} {!!} {!!} | |
358 | |
359 stack2list : {n m : Level} {t : Set m} {a : Set n} → (s : SingleLinkedStack a) → List a | |
360 stack2list stack with top stack | |
361 stack2list stack | just x = (datum x) ∷ (elm2list {_} {_} {ℕ} x) | |
362 where | |
363 elm2list : {n m : Level} {t : Set m} {a : Set n} → (elm : (Element a)) → List a | |
364 elm2list el with next el | |
365 elm2list el | just x = (datum el) ∷ (elm2list {_} {_} {ℕ} x) | |
366 elm2list el | nothing = (datum el) ∷ [] | |
367 stack2list stack | nothing = [] | |
368 | |
369 | |
370 -- list2element : {n m : Level} {t : Set m} {a : Set n} → (l : List a) → Maybe (Element a) | |
371 -- list2element [] = nothing | |
372 -- list2element (x ∷ l) = just (cons x (list2element {_} {_} {ℕ} l)) | |
373 | |
374 -- ltest = list2element (1 ∷ 2 ∷ 3 ∷ []) | |
375 | |
376 list2stack : {n m : Level} {t : Set m} {a : Set n} {st : SingleLinkedStack a} → (l : List a) → SingleLinkedStack a | |
377 list2stack {n} {m} {t} {a} {s} (x ∷ l) = pushSingleLinkedStack s x (λ s1 → list2stack {n} {m} {t} {a} {s1} l ) | |
378 list2stack {n} {m} {t} {a} {s} [] = s | |
379 | |
380 | |
381 | |
382 -- stest = list2stack (1 ∷ 2 ∷ 3 ∷ []) | |
383 | |
384 open Node | |
385 | |
386 exfind : { m : Level } { t : Set m} → (dt : ℕ) → (node : (Node ℕ ℕ)) → (st : List ℕ) → findNode {_} {_} {ℕ} {ℕ} (redBlackInSomeState ℕ (just node)) (emptySingleLinkedStack) (leafNode dt dt) (node) (λ t1 st1 n1 → (( treeTotal {_} {m} {ℕ} {t} (dt ∷ st) (node) ) ≡ ( treeTotal {_} {m} {ℕ} {t} (dt ∷ st) (node) ) )) | |
387 exfind dt node st with left node | right node | |
388 exfind dt node st | just x | just x₁ = {!!} | |
389 exfind dt node st | just x | nothing = {!!} | |
390 exfind dt node st | nothing | just x = {!!} | |
391 exfind dt node st | nothing | nothing with (compTri dt (key node)) | |
392 exfind dt node st | nothing | nothing | tri< a ¬b ¬c = {!!} | |
393 exfind dt node st | nothing | nothing | tri≈ ¬a b ¬c = {!!} | |
394 exfind dt node st | nothing | nothing | tri> ¬a ¬b c = {!!} | |
395 | |
396 -- exput : (ni : ℕ) → (tn : Node ℕ ℕ) → (ts : List ℕ) → (treeTotal {_} {ℕ} (ni ∷ ts) tn) | |
397 -- ≡ (treeTotal {_} {ℕ} (ts) (Data.Maybe.fromMaybe nullNode (root (putTree1 {_} {_} {ℕ} {ℕ} (record { root = just tn } ) ni ni (λ tt → tt))))) | |
398 -- exput datum node [] with (right node) | (left node) | |
399 -- exput datum node [] | nothing | nothing = {!!} | |
400 -- exput datum node [] | just x | just x₁ = {!!} | |
401 -- exput datum node [] | just x | nothing = {!!} | |
402 -- exput datum node [] | nothing | just x = {!!} | |
403 -- exput datum node (x ∷ stack₁) = {!!} | |
404 | |
405 | |
406 -- proofTree : {n m : Level} {t : Set m} {a : Set n} (old stackl : List ℕ) → (node : Node ℕ ℕ) → (FS {_} {ℕ} old stackl node) → (tree : RedBlackTree ℕ ℕ) → (key : ℕ) → findNode {{!!}} {{!!}} {{!!}} {{!!}} tree (list2stack {!!} (record {top = nothing})) (leafNode key key) node (λ tree1 stack1 datum → {!!}) | |
407 -- -- -- -- putTree1 tree key key (λ t → (FS {_} {ℕ} old stackl (Data.Maybe.fromMaybe nullNode (root tree))) ) | |
408 -- proofTree old stack node fs t k = {!!} | |
409 | |
410 -- FS は 証明そのものになると思ってたけど実は違いそう | |
411 -- oldTotal と 現在の node, stack の組み合わせを比較する | |
412 -- oldTotal はどうやって作る? >< | |
413 -- treeTotal は list と node を受け取って それの total を出すのでそれで作る(list に put するデータなどを入れることで適当に作れる) | |
414 | |
415 -- p : {n m : Level} {t : Set m} {a : Set n} → ( s : SingleLinkedStack ℕ ) ( tr : (Node ℕ ℕ) ) ( tree : RedBlackTree ℕ ℕ ) (k : ℕ) → (FS (treeTotal (k ∷ (stack2list s)) tr) (stack2list s) tr) → putTree1 tree k k (λ atree → FS (treeTotal (stack2list s) (Data.Maybe.fromMaybe (tr) (root atree))) {!!} {!!}) | |
416 -- p stack node tree key = {!!} | |
417 | |
418 -- tt = (FS {_} {ℕ} [] [] (Data.Maybe.fromMaybe nullNode (root (createEmptyRedBlackTreeℕ {_} ℕ {ℕ})))) | |
419 | |
420 -- ttt : (a : P) → P | |
421 -- ttt a = P₀ {!!} {!!} (record { key = {!!} ; value = {!!} ; right = {!!} ; left = {!!} ; color = {!!} }) (record { total = {!!} }) | |
422 | |
423 | |
424 -- FS では stack tree をあわせた整合性を示したい | |
425 -- そのためには...? | |
426 -- stack は前の node (というか一段上)が入ってる | |
427 -- tree は現在の node がある | |
428 | |
429 | |
430 -- tr(Node ℕ ℕ) s (List (Node)) | |
431 -- 3 [] | |
432 -- / \ | |
433 -- 2 5 | |
434 -- / / \ | |
435 -- 1 4 6 | |
436 | |
437 -- search 6 (6 > 3) | |
438 -- tr(Node ℕ ℕ) s (List (Node)) | |
439 -- 5 just (node (1 2 nothing) 3 (4 5 6) | |
440 -- / \ [] | |
441 -- 4 6 | |
442 | |
443 -- search 6 (6 > 5) | |
444 -- tr(Node ℕ ℕ) s (List (Node)) | |
445 -- 6 just (node (4 5 6)) | |
446 -- just (node (1 2 nothing) 3 (4 5 6) | |
447 -- [] | |
448 | |
449 -- just 6 → true みたいな感じ | |
450 | |
451 -- stack に node ごと入れるのは間違い…? | |
452 -- 一応非破壊な感じがする(新しく作り直してる) | |
453 -- どう釣り合いをとるか | |
454 | |
455 -- stack+tree : {n m : Level} {t : Set m} → List (Node ℕ ℕ) → Node ℕ ℕ → Node ℕ ℕ → (Maybe (Node ℕ ℕ) → t) → t | |
456 -- stack+tree {n} stack mid org = st stack mid org where | |
457 -- st : List (Node ℕ ℕ) → Node ℕ ℕ → Node ℕ ℕ → Maybe (Node ℕ ℕ) | |
458 -- st [] _ _ = nothing | |
459 -- st (x ∷ []) n n1 with Data.Nat.compare (key x) (key org) | Data.Nat.compare (value x) (value org) | |
460 -- st (x ∷ []) n n1 | equal .(key x) | equal .(value x) = just org | |
461 -- st (x ∷ []) n n1 | _ | _ = nothing | |
462 -- st (x ∷ a) n n1 with st a n n1 | |
463 -- st (x ∷ a) n n1 | just x₁ = {!!} | |
464 -- st (x ∷ a) n n1 | nothing = nothing | |
465 | |
466 | |
467 -- stack+tree : {n m : Level} {t : Set m} → List (Node ℕ ℕ) → Node ℕ ℕ → Node ℕ ℕ → (Maybe (Node ℕ ℕ) → t) → t | |
468 -- stack+tree {n} stack mid org cg = st stack mid org | |
469 -- where | |
470 -- st : List (Node ℕ ℕ) → Node ℕ ℕ → Node ℕ ℕ → Maybe (Node ℕ ℕ) | |
471 -- st [] _ _ = nothing | |
472 -- st (x ∷ []) n n1 with Data.Nat.compare (key x) (key org) | Data.Nat.compare (value x) (value org) | |
473 -- st (x ∷ []) n n1 | equal .(key x) | equal .(value x) = just org | |
474 -- st (x ∷ []) n n1 | _ | _ = nothing | |
475 -- st (x ∷ a) n n1 with st a n n1 | |
476 -- st (x ∷ a) n n1 | just x₁ = {!!} | |
477 -- st (x ∷ a) n n1 | nothing = nothing | |
478 | |
479 -- findNodePush : {n : Level} → (stack : List (Node ℕ ℕ)) → (mid : Node ℕ ℕ) → (org : Node ℕ ℕ) → stack+tree stack mid org ≡ just ? | |
480 -- → ? {return (? ∷ stack),mid'} → stack+tree (? ∷ stack) (mid') org ≡ just ? | |
481 -- findNodePush | |
482 | |
483 -- stack+tree が just だって言えたらよい | |
484 -- {}2 は orig の どっちかのNode | |
485 | |
578
7bacba816277
use list base simple stack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
575
diff
changeset
|
486 >>>>>>> destination |