Mercurial > hg > Gears > GearsAgda
changeset 653:a8e7d1f20ce6
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 21 Nov 2021 09:22:59 +0900 |
parents | 8c7446829b99 |
children | 48c6e6961ea5 |
files | hoareBinaryTree.agda |
diffstat | 1 files changed, 19 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/hoareBinaryTree.agda Sun Nov 21 07:23:08 2021 +0900 +++ b/hoareBinaryTree.agda Sun Nov 21 09:22:59 2021 +0900 @@ -103,14 +103,14 @@ → 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-left0 : {tree tree₁ : bt A} → {key₁ : ℕ } → {v1 : A } + → key < key₁ → stackInvariant key (node key₁ v1 tree tree₁) (node key₁ v1 tree tree₁) (node key₁ v1 tree tree₁ ∷ []) s-right0 : {tree₁ tree : bt A} → {key₁ : ℕ } → {v1 : A } - → key₁ > key → stackInvariant key (node key₁ v1 tree tree₁) (node key₁ v1 tree tree₁) (node key₁ v1 tree tree₁ ∷ []) - s-left0 : {tree tree₁ : bt A} → {key₁ : ℕ } → {v1 : A } - → key > key₁ → stackInvariant key (node key₁ v1 tree tree₁) (node key₁ v1 tree tree₁) (node key₁ v1 tree tree₁ ∷ []) - 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 → stackInvariant key tree₁ tree0 (tree₁ ∷ st) - s-left : {tree tree0 tree₁ : bt A} → {key₁ : ℕ } → {v1 : A } → {st : List (bt A)} - → key > key₁ → stackInvariant key (node key₁ v1 tree₁ tree) tree0 st → stackInvariant key tree tree0 (tree ∷ st) + → key₁ < key → stackInvariant key (node key₁ v1 tree tree₁) (node key₁ v1 tree tree₁) (node key₁ v1 tree tree₁ ∷ []) + 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 → stackInvariant key tree tree0 (tree ∷ st) + s-left : {tree₁ tree0 tree : bt A} → {key₁ : ℕ } → {v1 : A } → {st : List (bt A)} + → key < key₁ → stackInvariant key (node key₁ v1 tree₁ tree) tree0 st → stackInvariant key tree₁ tree0 (tree₁ ∷ st) data replacedTree {n : Level} {A : Set n} (key : ℕ) (value : A) : (tree tree1 : bt A ) → Set n where r-leaf : replacedTree key value leaf (node key value leaf leaf) @@ -155,7 +155,7 @@ stack-last (x ∷ s) = stack-last s stackInvariantTest1 : stackInvariant 4 treeTest2 treeTest1 ( treeTest2 ∷ treeTest1 ∷ [] ) -stackInvariantTest1 = s-left (add< 2) (s-left0 (add< 2)) +stackInvariantTest1 = s-right (add< 2) (s-right0 (add< 2)) si-property1 : {n : Level} {A : Set n} (key : ℕ) (tree tree0 : bt A) → (stack : List (bt A)) → stackInvariant key tree tree0 stack → stack-top stack ≡ just tree @@ -167,7 +167,7 @@ si-property-last : {n : Level} {A : Set n} (key : ℕ) (tree tree0 : bt A) → (stack : List (bt A)) → stackInvariant key tree tree0 stack → stack-last stack ≡ just tree0 si-property-last key t t0 (.t ∷ []) (s-right0 _ ) = refl -si-property-last key t t0 (.t ∷ []) (s-left0 _ ) = {!!} +si-property-last key t t0 (.t ∷ []) (s-left0 _ ) = refl si-property-last key t t0 (.t ∷ x ∷ st) (s-right _ si) with si-property1 key _ _ (x ∷ st) si ... | refl = si-property-last key x t0 (x ∷ st) si si-property-last key t t0 (.t ∷ x ∷ st) (s-left _ si) with si-property1 key _ _ (x ∷ st) si @@ -185,14 +185,16 @@ ti-left {_} {_} {_} {_} {key₁} {v1} (t-left x ti) = ti ti-left {_} {_} {.(node _ _ _ _)} {_} {key₁} {v1} (t-node x x₁ ti ti₁) = ti -stackTreeInvariant : {n : Level} {A : Set n} (key : ℕ) (repl tree : bt A) → (stack : List (bt A)) - → treeInvariant tree → stackInvariant key repl tree stack → treeInvariant repl -stackTreeInvariant {_} {A} key repl tree (repl ∷ st) ti (s-right _ si) = ti-right (si1 {!!}) where - si1 : {tree₁ : bt A} → {key₁ : ℕ} → {v1 : A} → stackInvariant key (node key₁ v1 tree₁ repl) tree st → treeInvariant (node key₁ v1 tree₁ repl) - si1 {tree₁ } {key₁ } {v1 } si = stackTreeInvariant key (node key₁ v1 tree₁ repl) tree st ti si -stackTreeInvariant {_} {A} key repl tree (repl ∷ st) ti (s-left _ si) = ti-left ( si2 {!!} ) where - si2 : {tree₁ : bt A} → {key₁ : ℕ} → {v1 : A} → stackInvariant key (node key₁ v1 repl tree₁ ) tree st → treeInvariant (node key₁ v1 repl tree₁ ) - si2 {tree₁ } {key₁ } {v1 } si = stackTreeInvariant key (node key₁ v1 repl tree₁ ) tree st ti si +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 (sub ∷ []) ti (s-right0 _ ) = ti +stackTreeInvariant {_} {A} key sub tree (sub ∷ []) ti (s-left0 _ ) = ti +stackTreeInvariant {_} {A} key sub tree (sub ∷ st) ti (s-right _ si) = 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 + 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 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 ()