changeset 644:a3fb9ffa3d60

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 19 Nov 2021 13:29:01 +0900
parents fbd2adb6d9c5
children 6340956f143e
files hoareBinaryTree.agda
diffstat 1 files changed, 29 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/hoareBinaryTree.agda	Thu Nov 18 17:16:07 2021 +0900
+++ b/hoareBinaryTree.agda	Fri Nov 19 13:29:01 2021 +0900
@@ -231,38 +231,39 @@
 replaceNodeP k v1 (node .k value t t₁) (case2 refl) P next = next (node k v1 t t₁) (replaceTree1 k value v1 P) r-node
 
 replaceP : {n m : Level} {A : Set n} {t : Set m}
-     → (key : ℕ) → (value : A) → (tree repl : bt A) → (stack : List (bt A)) → treeInvariant tree ∧ stackInvariant repl tree stack ∧ replacedTree key value tree repl
-     → (next : ℕ → A → (tree1 repl : bt A) → (stack1 : List (bt A))
-         → treeInvariant tree1 ∧ stackInvariant repl tree1 stack1 ∧ replacedTree key value tree1 repl → length stack1 < length stack → t)
+     → (key : ℕ) → (value : A) → {tree0 tree : bt A} ( repl : bt A)
+     → (stack : List (bt A)) → treeInvariant tree0 ∧ stackInvariant tree tree0 stack ∧ replacedTree key value tree repl
+     → (next : ℕ → A → {tree0 tree1 : bt A } (repl : bt A) → (stack1 : List (bt A))
+         → treeInvariant tree0 ∧ stackInvariant tree1 tree0 stack1 ∧ replacedTree key value tree1 repl → length stack1 < length stack → t)
      → (exit : (tree1 repl : bt A) → treeInvariant tree1 ∧ replacedTree key value tree1 repl → t) → t
-replaceP key value tree repl [] Pre next exit = exit tree repl ⟪ proj1 Pre , proj2 (proj2 Pre) ⟫
-replaceP key value tree repl (leaf ∷ st) Pre next exit with si-property1 _ _ _ (proj1 (proj2 Pre)) | rt-property1 _ _ _ _ (proj2 (proj2 Pre))
-... | refl | t1 = ⊥-elim ( t1 refl )
-replaceP key value tree repl (node key₁ value₁ left right ∷ st) Pre next exit with <-cmp key key₁
-... | tri< a ¬b ¬c = next key value (node key₁ value₁ tree right ) (node key₁ value₁ repl right ) st {!!}  ≤-refl
-... | tri≈ ¬a b ¬c = exit (node key₁ value₁  left right ) (node key₁ value  left right )  ⟪ repl1 , repl3 ⟫ where
-    repleq : repl ≡ node key₁ value₁ left right
+replaceP key value {tree0} {tree} repl [] Pre next exit = exit tree0 repl ⟪ proj1 Pre , {!!} ⟫ where
+    repleq : stackInvariant tree tree0 [] → tree ≡ tree0
+    repleq = {!!}
+    repl7 :  replacedTree key value tree repl → replacedTree key value tree0 repl
+    repl7 = {!!}
+replaceP key value {tree0} {tree} repl (leaf ∷ st) Pre next exit with si-property1 _ _ _ (proj1 (proj2 Pre)) | rt-property1 _ _ _ _ (proj2 (proj2 Pre))
+... | refl | t1 = ⊥-elim ( t1 {!!} )
+replaceP key value {tree0} {tree} repl (node key₁ value₁ left right ∷ st) Pre next exit with <-cmp key key₁
+... | tri> ¬a ¬b c = next key value  (node key₁ value₁ repl right ) st {!!}  ≤-refl
+... | tri≈ ¬a b ¬c = next key value  (node key value left right ) st {!!}  ≤-refl where -- this case won't happen
+    repleq : tree0 ≡ node key₁ value₁ left right
     repleq with si-property1 _ _ _ (proj1 (proj2 Pre))
-    ... | refl = refl
+    ... | refl = {!!}
     repl1 : treeInvariant (node key₁ value₁ left right) -- stackInvariant (node key₁ value₁ left right) tree st
     repl1 = stackTreeInvariant _ _ (node key₁ value₁ left right ∷ st) (proj1 Pre)
-        (subst (λ k → stackInvariant k tree (node key₁ value₁ left right ∷ st)) repleq (proj1 (proj2 Pre)))
+        {!!} -- (subst (λ k → stackInvariant k tree (node key₁ value₁ left right ∷ st)) repleq (proj1 (proj2 Pre)))
     repl3 : replacedTree key value (node key₁ value₁ left right) (node key₁ value left right)
     repl3 = subst (λ k → replacedTree k value (node key₁ value₁ left right) (node key₁ value left right) ) (sym b) r-node
-... | tri> ¬a ¬b c = next key value (node key₁ value₁ left tree ) (node key₁ value₁ left repl ) st ⟪ repl2 , ⟪ repl4 , repl5 ⟫ ⟫ ≤-refl  where
-    Pre1 :  treeInvariant tree ∧ stackInvariant repl tree (node key₁ value₁ left right ∷ st) ∧ replacedTree key value tree repl
-    Pre1 = Pre
+... | tri< a ¬b ¬c = next key value (node key₁ value₁ left repl)  st ⟪ proj1 Pre , ⟪ {!!} ,  r-right a (proj2 (proj2 Pre)) ⟫ ⟫ ≤-refl   where
     repleq : repl ≡ node key₁ value₁ left right
     repleq with si-property1 _ _ _ (proj1 (proj2 Pre))
-    ... | refl = refl
-    repl2 :  treeInvariant (node key₁ value₁ left tree)
-    repl2 = stackTreeInvariant _ _ (node key₁ value₁ left right ∷ st) (proj1 Pre)
-        (subst (λ k → stackInvariant k tree (node key₁ value₁ left right ∷ st)) {!!} (proj1 (proj2 Pre)))
-    repl4 : stackInvariant (node key₁ value₁ left repl) (node key₁ value₁ left tree) st
-    repl4 = ?
-    repl5 : replacedTree key value (node key₁ value₁ left tree) (node key₁ value₁ left repl)
-    repl5 with r-left c (proj2 (proj2 Pre))
-    ... | t = {!!}
+    ... | refl = {!!}
+    repl2 : stackInvariant tree tree0 (node key₁ value₁ left right ∷ st) → stackInvariant (node key₁ value₁ left tree) tree0 st
+    repl2 = {!!}
+
+
+--- ... next key value (node key₁ value₁ left tree ) (node key₁ value₁ left repl ) st  ≤-refl  where
+
 open import Relation.Binary.Definitions
 
 nat-≤> : { x y : ℕ } → x ≤ y → y < x → ⊥
@@ -304,8 +305,8 @@
        $ λ t1 P1 R → TerminatingLoopS (List (bt A) ∧ (bt A ∧ bt A ))
             {λ p → treeInvariant (proj1 (proj2 p)) ∧ stackInvariant (proj1 (proj2 p)) tree (proj1 p)  ∧ replacedTree key value (proj1 (proj2 p)) (proj2 (proj2 p)) }
                (λ p → length (proj1 p)) ⟪ s , ⟪ t , t1 ⟫ ⟫ ⟪ proj1 P , ⟪ {!!}  , R ⟫ ⟫
-       $  λ p P1 loop → replaceP key value (proj1 (proj2 p)) (proj2 (proj2 p)) (proj1 p) {!!}
-            (λ key value tree1 repl1 stack P2 lt → loop ⟪ stack , ⟪ tree1  , repl1  ⟫ ⟫ {!!} lt )  exit 
+       $  λ p P1 loop → replaceP key value  (proj2 (proj2 p)) (proj1 p) {!!}
+            (λ key value repl1 stack P2 lt → loop ⟪ stack , ⟪ {!!} , repl1  ⟫ ⟫ {!!} lt )  exit 
 
 top-value : {n : Level} {A : Set n} → (tree : bt A) →  Maybe A 
 top-value leaf = nothing
@@ -349,8 +350,8 @@
        $ λ t1 P1 R → TerminatingLoopS (List (bt A) ∧ (bt A ∧ bt A ))
             {λ p → treeInvariant (proj1 (proj2 p)) ∧ stackInvariant (proj1 (proj2 p)) tree (proj1 p)  ∧ replacedTree key value (proj1 (proj2 p)) (proj2 (proj2 p)) }
                (λ p → length (proj1 p)) ⟪ s , ⟪ t , t1 ⟫ ⟫ ⟪ {!!} , ⟪ {!!}  , R ⟫ ⟫
-       $  λ p P1 loop → replaceP key value (proj1 (proj2 p)) (proj2 (proj2 p)) (proj1 p) {!!}
-            (λ key value tree1 repl1 stack P2 lt → loop ⟪ stack , ⟪ tree1  , repl1  ⟫ ⟫ {!!} lt )  exit 
+       $  λ p P1 loop → replaceP key value  (proj2 (proj2 p)) (proj1 p) {!!}
+            (λ key value repl1 stack P2 lt → loop ⟪ stack , ⟪ {!!} , repl1  ⟫ ⟫ {!!} lt )  exit 
 
 record findPC {n : Level} {A : Set n} (key1 : ℕ) (value1 : A) (tree : bt A ) (stack : List (bt A)) : Set n where
    field