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 open import utilities open _/\_ record Env : Set where field varn : ℕ vari : ℕ open Env 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 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 ( suc zero ≤? (varn env) ) whileLoop' env proof next | no p = next env whileLoop' env proof next | yes p = whileLoop' env1 (proof3 p ) next where env1 = record {varn = (varn env) - 1 ; vari = (vari env) + 1} proof3 : (suc zero ≤ (varn env)) → varn env1 + vari env1 ≡ 10 proof3 (s≤s lt) with varn env proof3 (s≤s z≤n) | zero = {!!} proof3 (s≤s lt) | suc n = {!!} 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 env p1 next = next env proof4 where proof4 : varn env + vari env ≡ 10 proof4 = let open ≡-Reasoning in begin varn env + vari env ≡⟨ cong ( λ n → n + vari env ) (pi2 p1 ) ⟩ 10 + vari env ≡⟨ cong ( λ n → 10 + n ) (pi1 p1 ) ⟩ 10 + 0 ≡⟨⟩ 10 ∎ proofGears : Set proofGears = whileTest' (λ n p1 → conversion1 n p1 (λ n1 p2 → whileLoop' n1 p2 (λ n2 → ( vari n2 ≡ 10 )))) proofGearsMeta : whileTest' (λ n p1 → conversion1 n p1 (λ n1 p2 → whileLoop' n1 p2 (λ n2 → ( vari n2 ≡ 10 )))) proofGearsMeta = refl