# HG changeset patch # User Shinji KONO # Date 1638614827 -32400 # Node ID 28e0f7f4777dae2958d2b52a547360d7666f7aa6 # Parent e5140faf1602bfea94e0f8c5141cda7e77be82fb ... diff -r e5140faf1602 -r 28e0f7f4777d hoareBinaryTree.agda --- a/hoareBinaryTree.agda Sat Dec 04 14:47:03 2021 +0900 +++ b/hoareBinaryTree.agda Sat Dec 04 19:47:07 2021 +0900 @@ -197,12 +197,23 @@ rt-property-leaf : {n : Level} {A : Set n} {key : ℕ} {value : A} {repl : bt A} → replacedTree key value leaf repl → repl ≡ node key value leaf leaf rt-property-leaf r-leaf = refl +rt-property-¬leaf : {n : Level} {A : Set n} {key : ℕ} {value : A} {tree : bt A} → ¬ replacedTree key value tree leaf +rt-property-¬leaf () + rt-property-key : {n : Level} {A : Set n} {key key₂ key₃ : ℕ} {value value₂ value₃ : A} {left left₁ right₂ right₃ : bt A} → replacedTree key value (node key₂ value₂ left right₂) (node key₃ value₃ left₁ right₃) → key₂ ≡ key₃ rt-property-key r-node = refl rt-property-key (r-right x ri) = refl rt-property-key (r-left x ri) = refl +nat-≤> : { x y : ℕ } → x ≤ y → y < x → ⊥ +nat-≤> (s≤s x x : { x y : ℕ } → x < y → y < x → ⊥ +nat-<> (s≤s x x : { x y : ℕ } → x ≤ y → y < x → ⊥ -nat-≤> (s≤s x x : { x y : ℕ } → x < y → y < x → ⊥ -nat-<> (s≤s x x x a) - findP2 | (r-left x ri) | node key value t t₁ = record { tree1 = t ; value = findPC.value (findPR.ci Pre) ; ci = {!!} } - findP2 | r-left x ri | leaf = {!!} - -- findP2 (r-left x ri) = subst₂ (λ j k → replacedTree key (findPC.value (findPR.ci Pre)) j k ) {!!} {!!} ri -findPPC key n@(node key₁ v1 tree tree₁) st Pre next _ | tri> ¬a ¬b c = next tree₁ (tree₁ ∷ st) + ; ci = findP2 } depth-1< where + findP2 : findPC key value tree (tree ∷ st) + findP2 with findPC.ci (findPR.ci Pre) | findPC.tree1 (findPR.ci Pre) | inspect findPC.tree1 (findPR.ci Pre) + findP2 | r-node | leaf | _ = ⊥-elim ( nat-≤> a ≤-refl ) + findP2 | r-node | node key value t t₁ | _ = ⊥-elim ( nat-≤> a ≤-refl ) + findP2 | (r-right x ri) | t | _ = ⊥-elim (nat-<> x a) + findP2 | (r-left x ri) | node key value t t₁ | record { eq = refl } = record { tree1 = t ; ci = ri } + findP2 | r-left x ri | leaf | record { eq = () } + findP2 | r-leaf | leaf | record { eq = eq } = ⊥-elim ( nat-≤> a ≤-refl ) +findPPC key value n@(node key₁ v1 tree tree₁) st Pre next _ | tri> ¬a ¬b c = next tree₁ (tree₁ ∷ st) record { tree0 = findPR.tree0 Pre ; ti0 = findPR.ti0 Pre ; ti = treeRightDown tree tree₁ (findPR.ti Pre) ; si = s-right c (findPR.si Pre) - ; ci = {!!} } depth-2< + ; ci = findP2 } depth-2< where + findP2 : findPC key value tree₁ (tree₁ ∷ st) + findP2 with findPC.ci (findPR.ci Pre) | findPC.tree1 (findPR.ci Pre) | inspect findPC.tree1 (findPR.ci Pre) + findP2 | r-node | node key value ti ti₁ | eq = ⊥-elim ( nat-≤> c ≤-refl ) + findP2 | r-left x ri | ti | eq = ⊥-elim ( nat-<> x c ) + findP2 | r-right x ri | node key value t t₁ | record { eq = refl } = record { tree1 = t₁ ; ci = ri } + findP2 | r-leaf | leaf | record { eq = eq } = ⊥-elim ( nat-≤> c ≤-refl ) 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 ) } (λ p → bt-depth (proj1 p)) -- findPR key tree1 [] (findPC key value) - ⟪ tree1 , [] ⟫ record { tree0 = tree ; ti0 = {!!} ; ti = {!!} ; si = {!!} ; ci = record { tree1 = tree ; ci = RT } } - $ λ p P loop → findPPC key (proj1 p) (proj2 p) P (λ t s P1 lt → loop ⟪ t , s ⟫ P1 lt ) + {λ p → findPR key (proj1 p) (proj2 p) (findPC key value ) } (λ p → bt-depth (proj1 p)) + ⟪ tree , tree ∷ [] ⟫ record { tree0 = tree ; ti0 = RTtoTI0 _ _ _ _ P RT ; ti = RTtoTI0 _ _ _ _ P RT ; si = s-single + ; ci = record { tree1 = tree1 ; ci = RT } } + $ λ p P loop → findPPC key value (proj1 p) (proj2 p) P (λ t s P1 lt → loop ⟪ t , s ⟫ P1 lt ) $ λ t1 s1 P2 found? → 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 )) → top-value t1 ≡ just value - lemma6 t1 s1 found? P2 = lemma7 t1 s1 (findPR.tree0 P2) ( findPC.tree1 (findPR.ci P2)) ( findPC.ci {!!} ) (findPR.si P2) found? where - lemma7 : (t1 : bt A) ( s1 : List (bt A) ) (tree0 tree1 : bt A) → - replacedTree key value t1 tree1 → stackInvariant key t1 tree0 s1 → ( t1 ≡ leaf ) ∨ ( node-key t1 ≡ just key) → top-value t1 ≡ just value - lemma7 = {!!} + 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 + lemma6 t1 s1 found? P2 = lemma7 t1 s1 (findPR.tree0 P2) ( findPC.tree1 (findPR.ci P2)) (findPC.ci (findPR.ci P2)) (findPR.si P2) found? where + lemma7 : (t1 : bt A) ( s1 : List (bt A) ) (tree0 tree1 : bt A) + → replacedTree key value tree1 t1 → stackInvariant key t1 tree0 s1 + → ( t1 ≡ leaf ) ∨ ( node-key t1 ≡ just key) → top-value t1 ≡ just value + lemma7 .leaf (.leaf ∷ []) .leaf tree1 () s-single (case1 refl) + lemma7 (node key value t1 t2) (.(node key value t1 t2) ∷ []) .(node key value t1 t2) tree1 ri s-single (case2 x) = {!!} + lemma7 (node key value t1 t2) (.(node key value t1 t2) ∷ x₁ ∷ s1) tree0 tree1 ri (s-right x si) found = ? + lemma7 (node key value t1 t2) (.(node key value t1 t2) ∷ x₁ ∷ s1) tree0 tree1 ri (s-left x si) found = ?