Mercurial > hg > Members > ryokka > HoareLogic
view whileTestGears.agda @ 5:17e4f3b58148
add future code proofGears
author | ryokka |
---|---|
date | Fri, 14 Dec 2018 19:51:54 +0900 |
parents | 64bd5c236002 |
children | 28e80739eed6 |
line wrap: on
line source
module whileTestGears where open import Function open import Data.Nat open import Data.Bool hiding ( _≟_ ; _∧_) open import Level renaming ( suc to succ ; zero to Zero ) open import Relation.Nullary using (¬_; Dec; yes; no) open import Relation.Binary.PropositionalEquality record Env : Set where field varn : ℕ vari : ℕ open Env _-_ : ℕ -> ℕ -> ℕ x - zero = x zero - _ = zero (suc x) - (suc y) = x - y record _∧_ {n : Level } (a : Set n) (b : Set n): Set n where field pi1 : a pi2 : b lt : ℕ -> ℕ -> Bool lt x y with (suc x ) ≤? y lt x y | yes p = true lt x y | no ¬p = false Equal : ℕ -> ℕ -> Bool Equal x y with x ≟ y Equal x y | yes p = true Equal x y | no ¬p = false whileTest : {l : Level} {t : Set l} -> (Code : Env -> t) -> t whileTest next = next (record {varn = 10 ; vari = 0} ) {-# TERMINATING #-} whileLoop : {l : Level} {t : Set l} -> Env -> (Code : Env -> t) -> t whileLoop env next with lt 0 (varn env) whileLoop env next | false = next env whileLoop env next | true = whileLoop (record {varn = (varn env) - 1 ; vari = (vari env) + 1}) next test1 : Env test1 = whileTest (λ env → whileLoop env (λ env1 → env1 )) proof1 : whileTest (λ env → whileLoop env (λ e → (vari e) ≡ 10 )) proof1 = refl record EnvWithCond : Set (succ Zero) where field input : Env condition : Set proof : condition open EnvWithCond -- stmt2Cond : {l : Level} → EnvWithCond {l} → -- stmt2Cond env = (Equal (varn' env) 10) ∧ (Equal (vari' env) 0) whileTest' : {l : Level} {t : Set l} -> (Code : (env : Env) -> ((vari env) ≡ 0) ∧ ((varn env) ≡ 10) -> t) -> t whileTest' next = next env proof2 where env : Env env = record {vari = 0 ; varn = 10} proof2 : ((vari env) ≡ 0) ∧ ((varn env) ≡ 10) proof2 = record {pi1 = refl ; pi2 = refl} {-# TERMINATING #-} whileLoop' : {l : Level} {t : Set l} -> (env : Env) -> ((varn env) + (vari env) ≡ 10) -> (Code : Env -> t) -> t whileLoop' env proof next with lt 0 (varn env) whileLoop' env proof next | false = next env whileLoop' env proof next | true = whileLoop' env1 proof3 next where env1 = record {varn = (varn env) - 1 ; vari = (vari env) + 1} proof3 : varn env1 + vari env1 ≡ 10 proof3 = {!!} conversion1 : {l : Level} {t : Set l } → (env : Env) -> ((vari env) ≡ 0) ∧ ((varn env) ≡ 10) -> (Code : (env1 : Env) -> (varn env1 + vari env1 ≡ 10) -> t) -> t conversion1 = {!!} proofGears : whileTest' (λ n → conversion1 n {!!} (λ n1 → whileLoop' n1 {!!} (λ n2 → (vari n2) ≡ 10))) proofGears = {!!}