Mercurial > hg > Gears > GearsAgda
changeset 660:712e2998c76b
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 21 Nov 2021 19:03:22 +0900 |
parents | afcccfaea264 |
children | 323533798054 |
files | hoareBinaryTree.agda |
diffstat | 1 files changed, 18 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/hoareBinaryTree.agda Sun Nov 21 17:24:40 2021 +0900 +++ b/hoareBinaryTree.agda Sun Nov 21 19:03:22 2021 +0900 @@ -103,8 +103,8 @@ → treeInvariant (node key₁ value₁ (node key value t₁ t₂) (node key₂ value₂ t₃ t₄)) data stackInvariant {n : Level} {A : Set n} (key : ℕ) : (top orig : bt A) → (stack : List (bt A)) → Set n where - s-nil : {tree : bt A} → stackInvariant key tree tree [] - s-single : {tree tree0 : bt A} → stackInvariant key tree tree0 [] → stackInvariant key tree tree0 (tree ∷ []) + s-nil : {tree tree0 : bt A} → stackInvariant key tree tree0 [] + s-single : {tree tree0 : bt A} → stackInvariant key tree tree0 [] → stackInvariant key tree0 tree0 (tree0 ∷ []) s-right : {tree tree0 tree₁ : bt A} → {key₁ : ℕ } → {v1 : A } → {st : List (bt A)} → key₁ < key → stackInvariant key (node key₁ v1 tree₁ tree) tree0 st → ¬ (st ≡ []) → stackInvariant key tree tree0 (tree ∷ st) s-left : {tree₁ tree0 tree : bt A} → {key₁ : ℕ } → {v1 : A } → {st : List (bt A)} @@ -149,9 +149,6 @@ stackInvariantTest1 : stackInvariant 4 treeTest2 treeTest1 ( treeTest2 ∷ treeTest1 ∷ [] ) stackInvariantTest1 = s-right (add< 2) (s-single s-nil) (λ ()) -si-nil : {n : Level} {A : Set n} {key : ℕ} {tree tree0 : bt A} → (si : stackInvariant key tree tree0 []) → tree ≡ tree0 -si-nil s-nil = refl - si-property1 : {n : Level} {A : Set n} (key : ℕ) (tree tree0 : bt A) → (stack : List (bt A)) → ¬ (stack ≡ []) → stackInvariant key tree tree0 stack → stack-top stack ≡ just tree si-property1 key t t0 [] ne (s-nil ) = ⊥-elim ( ne refl ) @@ -183,15 +180,15 @@ ti-left {_} {_} {.(node _ _ _ _)} {_} {key₁} {v1} (t-node x x₁ ti ti₁) = ti stackTreeInvariant : {n : Level} {A : Set n} (key : ℕ) (sub tree : bt A) → (stack : List (bt A)) - → treeInvariant tree → stackInvariant key sub tree stack → treeInvariant sub -stackTreeInvariant {_} {A} key sub tree [] ti s-nil = ti -stackTreeInvariant {_} {A} key sub tree (sub ∷ []) ti (s-single s-nil ) = ti -stackTreeInvariant {_} {A} key sub tree (sub ∷ st) ti (s-right _ si _) = ti-right (si1 si) where + → treeInvariant tree → stackInvariant key sub tree stack → ¬ (stack ≡ []) → treeInvariant sub +stackTreeInvariant {_} {A} key sub tree [] ti s-nil ne = ⊥-elim ( ne refl ) +stackTreeInvariant {_} {A} key sub tree (sub ∷ []) ti (s-single s-nil ) _ = ti +stackTreeInvariant {_} {A} key sub tree (sub ∷ st) ti (s-right _ si ne) _ = ti-right (si1 si) where si1 : {tree₁ : bt A} → {key₁ : ℕ} → {v1 : A} → stackInvariant key (node key₁ v1 tree₁ sub ) tree st → treeInvariant (node key₁ v1 tree₁ sub ) - si1 {tree₁ } {key₁ } {v1 } si = stackTreeInvariant key (node key₁ v1 tree₁ sub ) tree st ti si -stackTreeInvariant {_} {A} key sub tree (sub ∷ st) ti (s-left _ si _) = ti-left ( si2 si) where + si1 {tree₁ } {key₁ } {v1 } si = stackTreeInvariant key (node key₁ v1 tree₁ sub ) tree st ti si ne +stackTreeInvariant {_} {A} key sub tree (sub ∷ st) ti (s-left _ si ne) _ = ti-left ( si2 si) where si2 : {tree₁ : bt A} → {key₁ : ℕ} → {v1 : A} → stackInvariant key (node key₁ v1 sub tree₁ ) tree st → treeInvariant (node key₁ v1 sub tree₁ ) - si2 {tree₁ } {key₁ } {v1 } si = stackTreeInvariant key (node key₁ v1 sub tree₁ ) tree st ti si + si2 {tree₁ } {key₁ } {v1 } si = stackTreeInvariant key (node key₁ v1 sub tree₁ ) tree st ti si ne rt-property1 : {n : Level} {A : Set n} (key : ℕ) (value : A) (tree tree1 : bt A ) → replacedTree key value tree tree1 → ¬ ( tree1 ≡ leaf ) rt-property1 {n} {A} key value .leaf .(node key value leaf leaf) r-leaf () @@ -230,22 +227,20 @@ open _∧_ findP : {n m : Level} {A : Set n} {t : Set m} → (key : ℕ) → (tree tree0 : bt A ) → (stack : List (bt A)) - → treeInvariant tree ∧ stackInvariant key tree tree0 stack - → (next : (tree1 tree0 : bt A) → (stack : List (bt A)) → treeInvariant tree1 ∧ stackInvariant key tree1 tree0 stack → bt-depth tree1 < bt-depth tree → t ) - → (exit : (tree1 tree0 : bt A) → (stack : List (bt A)) → treeInvariant tree1 ∧ stackInvariant key tree1 tree0 stack + → treeInvariant tree ∧ ((¬ (stack ≡ []) → stackInvariant key tree tree0 stack )) + → (next : (tree1 tree0 : bt A) → (stack : List (bt A)) → treeInvariant tree1 ∧ ((¬ (stack ≡ []) → stackInvariant key tree1 tree0 stack)) → bt-depth tree1 < bt-depth tree → t ) + → (exit : (tree1 tree0 : bt A) → (stack : List (bt A)) → treeInvariant tree1 ∧ ((¬ (stack ≡ []) → stackInvariant key tree1 tree0 stack)) → (tree1 ≡ leaf ) ∨ ( node-key tree1 ≡ just key ) → t ) → t findP key leaf tree0 st Pre _ exit = exit leaf tree0 st Pre (case1 refl) findP key (node key₁ v1 tree tree₁) tree0 st Pre next exit with <-cmp key key₁ findP key n tree0 st Pre _ exit | tri≈ ¬a refl ¬c = exit n tree0 st Pre (case2 refl) findP {n} {_} {A} key (node key₁ v1 tree tree₁) tree0 st Pre next _ | tri< a ¬b ¬c = next tree tree0 (tree ∷ st) - ⟪ treeLeftDown tree tree₁ (proj1 Pre) , ? ⟫ depth-1< where - findP0 : key < key₁ → (st : List (bt A)) → stackInvariant key (node key₁ v1 tree tree₁) tree0 st → Set n - findP0 a [] si = stackInvariant key tree0 tree0 (tree0 ∷ []) - findP0 a (x ∷ st) si = stackInvariant key tree tree0 (tree ∷ x ∷ st) - findP1 : (a : key < key₁ ) → (st : List (bt A)) → (si : stackInvariant key (node key₁ v1 tree tree₁) tree0 st) → findP0 a st si - findP1 a (x ∷ st) si = s-left a si (λ ()) - findP1 a [] s-nil = s-single s-nil -findP key n@(node key₁ v1 tree tree₁) tree0 st Pre next _ | tri> ¬a ¬b c = next tree₁ tree0 (tree₁ ∷ st) ⟪ treeRightDown tree tree₁ (proj1 Pre) , s-right c (proj2 Pre) {!!} ⟫ depth-2< + ⟪ treeLeftDown tree tree₁ (proj1 Pre) , (λ ne → findP1 a st (proj2 Pre )) ⟫ depth-1< where + findP1 : key < key₁ → (st : List (bt A)) → ( ¬ (st ≡ [] ) → stackInvariant key (node key₁ v1 tree tree₁) tree0 st ) → stackInvariant key tree tree0 (tree ∷ st) + findP1 a [] si = {!!} -- s-single s-nil + findP1 a (x ∷ st) si with si {!!} + ... | t = s-left a t {!!} +findP key n@(node key₁ v1 tree tree₁) tree0 st Pre next _ | tri> ¬a ¬b c = next tree₁ tree0 (tree₁ ∷ st) ⟪ treeRightDown tree tree₁ (proj1 Pre) , {!!} ⟫ depth-2< replaceTree1 : {n : Level} {A : Set n} {t t₁ : bt A } → ( k : ℕ ) → (v1 value : A ) → treeInvariant (node k v1 t t₁) → treeInvariant (node k value t t₁) replaceTree1 k v1 value (t-single .k .v1) = t-single k value