annotate redBlackTreeTest.agda @ 575:73fc32092b64

push local rbtree
author ryokka
date Fri, 01 Nov 2019 17:42:51 +0900
parents 70b09cbefd45
children 7bacba816277
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
537
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
1 module redBlackTreeTest where
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
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
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
4
553
7d9af1d4b5af add compareTri
ryokka
parents: 552
diff changeset
5 open import Data.Empty
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
6 open import Data.List
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
7 open import Data.Maybe
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
8 open import Data.Bool
537
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
9 open import Data.Nat
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
10 open import Data.Nat.Properties as NatProp
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
11
553
7d9af1d4b5af add compareTri
ryokka
parents: 552
diff changeset
12 open import Relation.Nullary
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
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
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
16
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
17 open import RedBlackTree
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
18 open import stack
564
40ab3d39e49d using strict total order
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 563
diff changeset
19
537
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
20 open Tree
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
21 open Node
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
22 open RedBlackTree.RedBlackTree
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
23 open Stack
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
24
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
25 -- tests
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
26
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
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
1595dd84fc3e fix use SingleLinkedStack
ryokka
parents: 542
diff changeset
28 putTree1 {n} {m} {a} {k} {t} tree k1 value next with (root tree)
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
29 ... | nothing = next (record tree {root = just (leafNode k1 value) })
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
30 ... | just n2 = clearSingleLinkedStack (nodeStack tree) (λ s → findNode tree s (leafNode k1 value) n2 (λ tree1 s n1 → replaceNode tree1 s n1 next))
537
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
31
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
32 open import Relation.Binary.PropositionalEquality
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
33 open import Relation.Binary.Core
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
34 open import Function
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
35
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
36
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
37 -- check1 : {m : Level } (n : Maybe (Node ℕ ℕ)) → ℕ → Bool
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
38 -- check1 nothing _ = false
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
39 -- check1 (just n) x with Data.Nat.compare (value n) x
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
40 -- ... | equal _ = true
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
41 -- ... | _ = false
537
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
42
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
43 check2 : {m : Level } (n : Maybe (Node ℕ ℕ)) → ℕ → Bool
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
44 check2 nothing _ = false
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
45 check2 (just n) x with compare2 (value n) x
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
46 ... | EQ = true
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
47 ... | _ = false
549
bc3208d510cd add some
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 548
diff changeset
48
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
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 ))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
50 test1 = {!!}
537
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
51
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
52 -- test2 : {m : Level} → putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 (
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
53 -- λ t → putTree1 t 2 2 (
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
54 -- λ t → getRedBlackTree t 1 (
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
55 -- λ t x → check2 {m} x 1 ≡ true )))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
56 -- test2 = refl
537
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
57
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
58 -- open ≡-Reasoning
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
59 -- test3 : {m : Level} → putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero}) 1 1
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
60 -- $ λ t → putTree1 t 2 2
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
61 -- $ λ t → putTree1 t 3 3
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
62 -- $ λ t → putTree1 t 4 4
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
63 -- $ λ t → getRedBlackTree t 1
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
64 -- $ λ t x → check2 {m} x 1 ≡ true
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
65 -- test3 {m} = begin
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
66 -- check2 {m} (just (record {key = 1 ; value = 1 ; color = Black ; left = nothing ; right = just (leafNode 2 2)})) 1
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
67 -- ≡⟨ refl ⟩
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
68 -- true
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
69 -- ∎
542
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
70
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
71 -- test31 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 1 1
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
72 -- $ λ t → putTree1 t 2 2
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
73 -- $ λ t → putTree1 t 3 3
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
74 -- $ λ t → putTree1 t 4 4
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
75 -- $ λ t → getRedBlackTree t 4
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
76 -- $ λ t x → x
538
5c001e8ba0d5 add redBlackTreeTest.agda test5,test51. but not work
ryokka
parents: 537
diff changeset
77
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
78 -- -- test5 : Maybe (Node ℕ ℕ)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
79 -- test5 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 4 4
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
80 -- $ λ t → putTree1 t 6 6
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
81 -- $ λ t0 → clearSingleLinkedStack (nodeStack t0)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
82 -- $ λ s → findNode1 t0 s (leafNode 3 3) ( root t0 )
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
83 -- $ λ t1 s n1 → replaceNode t1 s n1
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
84 -- $ λ t → getRedBlackTree t 3
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
85 -- -- $ λ t x → SingleLinkedStack.top (stack s)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
86 -- -- $ λ t x → n1
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
87 -- $ λ t x → root t
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
88 -- where
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
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
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
90 -- findNode1 t s n1 nothing next = next t s n1
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
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
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
93 -- -- test51 : putTree1 {_} {_} {ℕ} {ℕ} {_} {Maybe (Node ℕ ℕ)} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 $ λ t →
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
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} )
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
95 -- -- test51 = refl
539
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
96
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
97 -- test6 : Maybe (Node ℕ ℕ)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
98 -- test6 = root (createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)})
539
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
99
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
100
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
101 -- test7 : Maybe (Node ℕ ℕ)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
102 -- test7 = clearSingleLinkedStack (nodeStack tree2) (λ s → replaceNode tree2 s n2 (λ t → root t))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
103 -- where
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
104 -- tree2 = createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
105 -- k1 = 1
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
106 -- n2 = leafNode 0 0
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
107 -- value1 = 1
539
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
108
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
109 -- test8 : Maybe (Node ℕ ℕ)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
110 -- test8 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 1 1
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
111 -- $ λ t → putTree1 t 2 2 (λ t → root t)
544
4f692df9b3db add reference
ryokka
parents: 543
diff changeset
112
4f692df9b3db add reference
ryokka
parents: 543
diff changeset
113
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
114 -- test9 : {m : Level} → putRedBlackTree {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( λ t → getRedBlackTree t 1 ( λ t x → check2 {m} x 1 ≡ true ))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
115 -- test9 = refl
544
4f692df9b3db add reference
ryokka
parents: 543
diff changeset
116
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
117 -- test10 : {m : Level} → putRedBlackTree {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 (
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
118 -- λ t → putRedBlackTree t 2 2 (
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
119 -- λ t → getRedBlackTree t 1 (
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
120 -- λ t x → check2 {m} x 1 ≡ true )))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
121 -- test10 = refl
545
b180dc78abcf add someTest
ryokka
parents: 544
diff changeset
122
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
123 -- test11 = putRedBlackTree {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 1 1
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
124 -- $ λ t → putRedBlackTree t 2 2
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
125 -- $ λ t → putRedBlackTree t 3 3
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
126 -- $ λ t → getRedBlackTree t 2
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
127 -- $ λ t x → root t
545
b180dc78abcf add someTest
ryokka
parents: 544
diff changeset
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
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
131 compTri = IsStrictTotalOrder.compare (Relation.Binary.StrictTotalOrder.isStrictTotalOrder <-strictTotalOrder)
565
ba7c5f1c2937 this slightly better
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 564
diff changeset
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
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
134 checkT : {m : Level } (n : Maybe (Node ℕ ℕ)) → ℕ → Bool
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
135 checkT nothing _ = false
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
136 checkT (just n) x with compTri (value n) x
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
137 ... | tri≈ _ _ _ = true
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
138 ... | _ = false
564
40ab3d39e49d using strict total order
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 563
diff changeset
139
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
140 checkEQ : {m : Level } ( x : ℕ ) -> ( n : Node ℕ ℕ ) -> (value n ) ≡ x -> checkT {m} (just n) x ≡ true
565
ba7c5f1c2937 this slightly better
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 564
diff changeset
141 checkEQ x n refl with compTri (value n) x
566
d9ef8333ff79 use ⊥-elim (neq refl)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 565
diff changeset
142 ... | tri≈ _ refl _ = refl
d9ef8333ff79 use ⊥-elim (neq refl)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 565
diff changeset
143 ... | tri> _ neq gt = ⊥-elim (neq refl)
d9ef8333ff79 use ⊥-elim (neq refl)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 565
diff changeset
144 ... | tri< lt neq _ = ⊥-elim (neq refl)
565
ba7c5f1c2937 this slightly better
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 564
diff changeset
145
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
146 -- checkEQ' : {m : Level } ( x y : ℕ ) -> ( eq : x ≡ y ) -> ( x ≟ y ) ≡ yes eq
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
147 -- checkEQ' x y refl with x ≟ y
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
148 -- ... | yes refl = refl
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
149 -- ... | no neq = ⊥-elim ( neq refl )
546
b654ce34c894 add putTest1Lemma1, putTest1
ryokka
parents: 545
diff changeset
150
571
1eccf1f18a59 add more detail
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 570
diff changeset
151 --- search -> checkEQ
1eccf1f18a59 add more detail
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 570
diff changeset
152 --- findNode -> search
1eccf1f18a59 add more detail
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 570
diff changeset
153
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
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 ℕ
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
155 redBlackInSomeState {m} a n {t} = record { root = n ; nodeStack = emptySingleLinkedStack ; nodeComp = λ x x₁ → {!!} } -- record { root = n ; nodeStack = emptySingleLinkedStack ; compare = compTri }
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
156
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
157
573
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 572
diff changeset
158 open stack.SingleLinkedStack
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 572
diff changeset
159 open stack.Element
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 572
diff changeset
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 572
diff changeset
161 {-# TERMINATING #-}
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
162 inStack : {l : Level} (n : Node ℕ ℕ) (s : SingleLinkedStack (Node ℕ ℕ) ) → Bool
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
163 inStack {l} n s with ( top s )
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
164 ... | nothing = true
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
165 ... | just n1 with compTri (key n) (key (datum n1))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
166 ... | tri> _ neq _ = inStack {l} n ( record { top = next n1 } )
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
167 ... | tri< _ neq _ = inStack {l} n ( record { top = next n1 } )
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
168 ... | tri≈ _ refl _ = false
573
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 572
diff changeset
169
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 572
diff changeset
170 record StackTreeInvariant ( n : Node ℕ ℕ )
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
171 ( s : SingleLinkedStack (Node ℕ ℕ) ) ( t : RedBlackTree ℕ ℕ ) : Set where
573
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 572
diff changeset
172 field
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
173 sti : {m : Level} → replaceNode t s n $ λ t1 → getRedBlackTree t1 (key n) (λ t2 x1 → checkT {m} x1 (value n) ≡ true)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
174 notInStack : {m : Level} → inStack {m} n s ≡ true → ⊥
573
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 572
diff changeset
175
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 572
diff changeset
176 open StackTreeInvariant
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 572
diff changeset
177
575
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
178
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
179 -- testn : {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
180 -- testn = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 2 2
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
181 -- $ λ t → putTree1 t 1 1
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
182 -- $ λ t → putTree1 t 3 3 (λ ta → record {root = root ta ; nodeStack = nodeStack ta })
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
183
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
184
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
185 -- List と Node で書こうとしたがなんだかんだListに直したほうが楽そうだった
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
186
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
187 nullNode = (record {key = 0 ; value = 0 ; right = nothing ; left = nothing ; color = Red})
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
188
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
189 -- treeTotal : { m : Level } {t : Set m} → ( s : List ℕ ) → ( tr : (Node ℕ ℕ) ) → (List ℕ → t) → t
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
190 -- treeTotal {m} {t} s tr next with (left tr) | (right tr)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
191 -- treeTotal {m} {t} s tr next | nothing | nothing = next ((key tr) ∷ [])
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
192 -- treeTotal {m} {t} s tr next | nothing | just x = treeTotal {m} {t} s x (λ li → next ((key tr) ∷ li))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
193 -- treeTotal {m} {t} s tr next | just x | nothing = treeTotal {m} {t} s x (λ li → next ((key tr) ∷ li))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
194 -- 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)))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
195 treeTotal : { n m : Level } {a : Set n} {t : Set m} → ( s : List a ) → ( tr : (Node a a) ) → List a
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
196 treeTotal {n} {m} {a} {t} s tr with (left tr) | (right tr)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
197 treeTotal {n} {m} {a} {t} s tr | nothing | nothing = (key tr) ∷ []
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
198 treeTotal {n} {m} {a} {t} s tr | nothing | just x = (key tr) ∷ (treeTotal {n} {m} {a} {t} s x)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
199 treeTotal {n} {m} {a} {t} s tr | just x | nothing = (key tr) ∷ (treeTotal {n} {m} {a} {t} s x)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
200 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₁))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
201
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
202
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
203 -- treeTotalA : { m : Level } {t : Set m} → ( s : List ℕ ) → ( tr : (Node ℕ ℕ) ) → List ℕ
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
204
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
205 -- (treeTotal {_} {ℕ} ([]) (Data.Maybe.fromMaybe nullNode (root (putTree1 {_} {_} {ℕ} {ℕ} testn 5 5 {!!}))))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
206
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
207 -- exput : (treeTotal {_} {ℕ} (5 ∷ []) (Data.Maybe.fromMaybe nullNode (root (createEmptyRedBlackTreeℕ ℕ))) (λ total → {!!})) ≡ {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
208 -- exput = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
209
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
210
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
211 -- aaa = (treeTotal {_} {_} {ℕ} {_} (5 ∷ []) ((record { key = 4 ; value = 4 ; right = just (leafNode 6 6) ; left = just (leafNode 3 3) ; color = Black })))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
212
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
213
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
214 -- 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 )
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
215
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
216 -- nontree ++ 2 :: []
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
217
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
218 -- piyo = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 2 2 ( λ t1 → findNode t1 (record {top = nothing}) (leafNode 2 2) (Data.Maybe.fromMaybe nullNode (root t1)) (λ tree stack node → {!!}))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
219
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
220
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
221 -- exn2l : {!!} ≡ (treeTotal {_} {ℕ} ([]) (putTree1 {_} {_} {ℕ} {ℕ} {!!} 5 5 (λ t → {!!}))) -- (treeTotal {_} {ℕ} (5 ∷ []) (Data.Maybe.fromMaybe nullNode (root testn)))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
222 -- exn2l = refl
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
223
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
224
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
225
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
226
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
227
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
228 -- record FS {n m : Level } {a : Set n} {t : Set m} (oldTotal : List a) ( s : List a ) ( tr : (Node a a) ) : Set where
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
229 -- field
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
230 -- total : treeTotal {n} {m} {a} {t} s tr ≡ oldTotal
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
231 -- -- usage = FS.total -- relation
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
232
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
233 -- data P { n m : Level } { t : Set m } : Set where
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
234 -- P₀ : (old : List ℕ) ( s : List ℕ ) → (tr : (Node ℕ ℕ) ) → FS {m} {t} old s tr → P
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
235
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
236
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
237
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
238 -- ttt = putTree1 {_} {_} {ℕ} {ℕ}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
239
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
240 -- record TreeInterface {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set n where
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
241 -- field
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
242 -- tree : treeImpl
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
243 -- list : List ℕ
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
244 -- node : Node ℕ ℕ
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
245 -- putTreeHoare : (FS {_} {ℕ} list list node) → putTree1 {!!} {!!} {!!} {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
246
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
247 stack2list : {n m : Level} {t : Set m} {a : Set n} → (s : SingleLinkedStack a) → List a
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
248 stack2list stack with top stack
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
249 stack2list stack | just x = (datum x) ∷ (elm2list {_} {_} {ℕ} x)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
250 where
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
251 elm2list : {n m : Level} {t : Set m} {a : Set n} → (elm : (Element a)) → List a
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
252 elm2list el with next el
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
253 elm2list el | just x = (datum el) ∷ (elm2list {_} {_} {ℕ} x)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
254 elm2list el | nothing = (datum el) ∷ []
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
255 stack2list stack | nothing = []
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
256
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
257
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
258 -- list2element : {n m : Level} {t : Set m} {a : Set n} → (l : List a) → Maybe (Element a)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
259 -- list2element [] = nothing
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
260 -- list2element (x ∷ l) = just (cons x (list2element {_} {_} {ℕ} l))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
261
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
262 -- ltest = list2element (1 ∷ 2 ∷ 3 ∷ [])
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
263
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
264 list2stack : {n m : Level} {t : Set m} {a : Set n} {st : SingleLinkedStack a} → (l : List a) → SingleLinkedStack a
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
265 list2stack {n} {m} {t} {a} {s} (x ∷ l) = pushSingleLinkedStack s x (λ s1 → list2stack {n} {m} {t} {a} {s1} l )
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
266 list2stack {n} {m} {t} {a} {s} [] = s
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
267
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
268
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
269
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
270 -- stest = list2stack (1 ∷ 2 ∷ 3 ∷ [])
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
271
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
272 open Node
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
273
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
274 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) ) ))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
275 exfind dt node st with left node | right node
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
276 exfind dt node st | just x | just x₁ = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
277 exfind dt node st | just x | nothing = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
278 exfind dt node st | nothing | just x = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
279 exfind dt node st | nothing | nothing with (compTri dt (key node))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
280 exfind dt node st | nothing | nothing | tri< a ¬b ¬c = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
281 exfind dt node st | nothing | nothing | tri≈ ¬a b ¬c = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
282 exfind dt node st | nothing | nothing | tri> ¬a ¬b c = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
283
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
284 -- exput : (ni : ℕ) → (tn : Node ℕ ℕ) → (ts : List ℕ) → (treeTotal {_} {ℕ} (ni ∷ ts) tn)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
285 -- ≡ (treeTotal {_} {ℕ} (ts) (Data.Maybe.fromMaybe nullNode (root (putTree1 {_} {_} {ℕ} {ℕ} (record { root = just tn } ) ni ni (λ tt → tt)))))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
286 -- exput datum node [] with (right node) | (left node)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
287 -- exput datum node [] | nothing | nothing = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
288 -- exput datum node [] | just x | just x₁ = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
289 -- exput datum node [] | just x | nothing = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
290 -- exput datum node [] | nothing | just x = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
291 -- exput datum node (x ∷ stack₁) = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
292
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
293
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
294 -- 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 → {!!})
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
295 -- -- -- -- putTree1 tree key key (λ t → (FS {_} {ℕ} old stackl (Data.Maybe.fromMaybe nullNode (root tree))) )
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
296 -- proofTree old stack node fs t k = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
297
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
298 -- FS は 証明そのものになると思ってたけど実は違いそう
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
299 -- oldTotal と 現在の node, stack の組み合わせを比較する
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
300 -- oldTotal はどうやって作る? ><
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
301 -- treeTotal は list と node を受け取って それの total を出すのでそれで作る(list に put するデータなどを入れることで適当に作れる)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
302
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
303 -- 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))) {!!} {!!})
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
304 -- p stack node tree key = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
305
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
306 -- tt = (FS {_} {ℕ} [] [] (Data.Maybe.fromMaybe nullNode (root (createEmptyRedBlackTreeℕ {_} ℕ {ℕ}))))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
307
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
308 -- ttt : (a : P) → P
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
309 -- ttt a = P₀ {!!} {!!} (record { key = {!!} ; value = {!!} ; right = {!!} ; left = {!!} ; color = {!!} }) (record { total = {!!} })
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
310
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
311
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
312 -- FS では stack tree をあわせた整合性を示したい
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
313 -- そのためには...?
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
314 -- stack は前の node (というか一段上)が入ってる
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
315 -- tree は現在の node がある
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
316
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
317
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
318 -- tr(Node ℕ ℕ) s (List (Node))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
319 -- 3 []
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
320 -- / \
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
321 -- 2 5
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
322 -- / / \
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
323 -- 1 4 6
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
324
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
325 -- search 6 (6 > 3)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
326 -- tr(Node ℕ ℕ) s (List (Node))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
327 -- 5 just (node (1 2 nothing) 3 (4 5 6)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
328 -- / \ []
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
329 -- 4 6
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
330
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
331 -- search 6 (6 > 5)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
332 -- tr(Node ℕ ℕ) s (List (Node))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
333 -- 6 just (node (4 5 6))
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
334 -- just (node (1 2 nothing) 3 (4 5 6)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
335 -- []
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
336
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
337 -- just 6 → true みたいな感じ
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
338
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
339 -- stack に node ごと入れるのは間違い…?
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
340 -- 一応非破壊な感じがする(新しく作り直してる)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
341 -- どう釣り合いをとるか
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
342
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
343 -- stack+tree : {n m : Level} {t : Set m} → List (Node ℕ ℕ) → Node ℕ ℕ → Node ℕ ℕ → (Maybe (Node ℕ ℕ) → t) → t
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
344 -- stack+tree {n} stack mid org = st stack mid org where
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
345 -- st : List (Node ℕ ℕ) → Node ℕ ℕ → Node ℕ ℕ → Maybe (Node ℕ ℕ)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
346 -- st [] _ _ = nothing
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
347 -- st (x ∷ []) n n1 with Data.Nat.compare (key x) (key org) | Data.Nat.compare (value x) (value org)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
348 -- st (x ∷ []) n n1 | equal .(key x) | equal .(value x) = just org
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
349 -- st (x ∷ []) n n1 | _ | _ = nothing
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
350 -- st (x ∷ a) n n1 with st a n n1
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
351 -- st (x ∷ a) n n1 | just x₁ = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
352 -- st (x ∷ a) n n1 | nothing = nothing
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
353
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
354
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
355 -- stack+tree : {n m : Level} {t : Set m} → List (Node ℕ ℕ) → Node ℕ ℕ → Node ℕ ℕ → (Maybe (Node ℕ ℕ) → t) → t
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
356 -- stack+tree {n} stack mid org cg = st stack mid org
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
357 -- where
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
358 -- st : List (Node ℕ ℕ) → Node ℕ ℕ → Node ℕ ℕ → Maybe (Node ℕ ℕ)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
359 -- st [] _ _ = nothing
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
360 -- st (x ∷ []) n n1 with Data.Nat.compare (key x) (key org) | Data.Nat.compare (value x) (value org)
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
361 -- st (x ∷ []) n n1 | equal .(key x) | equal .(value x) = just org
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
362 -- st (x ∷ []) n n1 | _ | _ = nothing
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
363 -- st (x ∷ a) n n1 with st a n n1
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
364 -- st (x ∷ a) n n1 | just x₁ = {!!}
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
365 -- st (x ∷ a) n n1 | nothing = nothing
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
366
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
367 -- findNodePush : {n : Level} → (stack : List (Node ℕ ℕ)) → (mid : Node ℕ ℕ) → (org : Node ℕ ℕ) → stack+tree stack mid org ≡ just ?
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
368 -- → ? {return (? ∷ stack),mid'} → stack+tree (? ∷ stack) (mid') org ≡ just ?
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
369 -- findNodePush
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
370
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
371 -- stack+tree が just だって言えたらよい
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
372 -- {}2 は orig の どっちかのNode
73fc32092b64 push local rbtree
ryokka
parents: 574
diff changeset
373