# HG changeset patch # User Shinji KONO # Date 1636700941 -32400 # Node ID 189cf03bda5f51d5bdf02a8b191ac4b951f291f4 # Parent 119f340c0b10464d75d04ab71fc2b93e0f06dce3 ... diff -r 119f340c0b10 -r 189cf03bda5f hoareBinaryTree.agda --- a/hoareBinaryTree.agda Thu Nov 11 15:57:19 2021 +0900 +++ b/hoareBinaryTree.agda Fri Nov 12 16:09:01 2021 +0900 @@ -138,11 +138,27 @@ depth-2< : {i j : ℕ} → suc i ≤ suc (j Data.Nat.⊔ i ) depth-2< {i} {j} = s≤s (m≤n⊔m _ i) -lemma11 : {n : Level} {A : Set n} {v1 : A} → (key key₁ : ℕ) → (tree tree₁ : bt A ) - → key < key₁ +treeLeftDown : {n : Level} {A : Set n} {k : ℕ} {v1 : A} → (tree tree₁ : bt A ) + → treeInvariant (node k v1 tree tree₁) + → treeInvariant tree +treeLeftDown {n} {A} {_} {v1} leaf leaf (t-single k1 v1) = t-leaf +treeLeftDown {n} {A} {_} {v1} .leaf .(node _ _ _ _) (t-right x ti) = t-leaf +treeLeftDown {n} {A} {_} {v1} .(node _ _ _ _) .leaf (t-left x ti) = ti +treeLeftDown {n} {A} {_} {v1} .(node _ _ _ _) .(node _ _ _ _) (t-node x x₁ ti ti₁) = ti + +treeRightDown : {n : Level} {A : Set n} {k : ℕ} {v1 : A} → (tree tree₁ : bt A ) + → treeInvariant (node k v1 tree tree₁) + → treeInvariant tree₁ +treeRightDown {n} {A} {_} {v1} .leaf .leaf (t-single _ .v1) = t-leaf +treeRightDown {n} {A} {_} {v1} .leaf .(node _ _ _ _) (t-right x ti) = ti +treeRightDown {n} {A} {_} {v1} .(node _ _ _ _) .leaf (t-left x ti) = t-leaf +treeRightDown {n} {A} {_} {v1} .(node _ _ _ _) .(node _ _ _ _) (t-node x x₁ ti ti₁) = ti₁ + +siConsLeft : {n : Level } {A : Set n} (key key₁ : ℕ) → { v1 : A } (tree tree₁ tree0 : bt A ) (st : List (bt A)) + → key < key₁ → stackInvariant key (node key₁ v1 tree tree₁) tree0 st → treeInvariant (node key₁ v1 tree tree₁) - → treeInvariant tree -lemma11 = {!!} + → stackInvariant key tree tree0 (node key₁ v1 tree tree₁ ∷ st) +siConsLeft {n} {A} k k1 {v1} t t1 t0 st k ¬a ¬b c = next tree₁ tree0 (n ∷ st) {!!} depth-2< @@ -248,10 +266,10 @@ findPP2 : (st : List (bt A)) → stackInvariant key {!!} tree0 st → stackInvariant key {!!} tree0 (node key₁ v1 tree tree₁ ∷ st) findPP2 = {!!} findPP1 : suc ( bt-depth tree ) ≤ suc (bt-depth tree Data.Nat.⊔ bt-depth tree₁) - findPP1 = {!!} + findPP1 = depth-1< findPP key n@(node key₁ v1 tree tree₁) st Pre next exit | tri> ¬a ¬b c = next tree₁ (n ∷ st) {!!} findPP2 where -- Cond n st → Cond tree₁ (n ∷ st) findPP2 : suc (bt-depth tree₁) ≤ suc (bt-depth tree Data.Nat.⊔ bt-depth tree₁) - findPP2 = {!!} + findPP2 = depth-2< insertTreePP : {n m : Level} {A : Set n} {t : Set m} → (tree : bt A) → (key : ℕ) → (value : A) → treeInvariant tree → (exit : (tree repl : bt A) → treeInvariant tree ∧ replacedTree key value tree repl → t ) → t @@ -285,8 +303,8 @@ containsTree : {n m : Level} {A : Set n} {t : Set m} → (tree tree1 : bt A) → (key : ℕ) → (value : A) → treeInvariant tree1 → replacedTree key value tree1 tree → ⊤ containsTree {n} {m} {A} {t} tree tree1 key value P RT = TerminatingLoopS (bt A ∧ List (bt A) ) - {λ p → findPR key (proj1 p) (proj2 p) (findPC key value ) } (λ p → bt-depth (proj1 p)) - ⟪ tree1 , [] ⟫ {!!} + {λ p → findPR key (proj1 p) (proj2 p) (findPC key value ) } (λ p → bt-depth (proj1 p)) -- findPR key tree1 [] (findPC key value) + ⟪ tree1 , [] ⟫ record { tree0 = tree ; ti = {!!} ; si = {!!} ; ci = record { tree1 = tree ; ci = RT } } $ λ p P loop → findPPC key value (proj1 p) (proj2 p) P (λ t s P1 lt → loop ⟪ t , s ⟫ P1 lt ) $ λ t1 s1 found? P2 → insertTreeSpec0 t1 value (lemma6 t1 s1 found? P2) where lemma6 : (t1 : bt A) (s1 : List (bt A)) (found? : (t1 ≡ leaf) ∨ (node-key t1 ≡ just key)) (P2 : findPR key t1 s1 (findPC key value)) → top-value t1 ≡ just value