changeset 11:f34066c435cd

finish
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 15 Dec 2018 17:24:20 +0900
parents bc819bdda374
children 247ce3e67b5f
files whileTestGears.agda
diffstat 1 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/whileTestGears.agda	Sat Dec 15 16:59:52 2018 +0900
+++ b/whileTestGears.agda	Sat Dec 15 17:24:20 2018 +0900
@@ -40,7 +40,11 @@
     env = record {vari = 0 ; varn = 10}
     proof2 : ((vari env) ≡ 0) /\ ((varn env) ≡ 10)
     proof2 = record {pi1 = refl ; pi2 = refl}
-    
+
+open import Data.Empty
+open import Data.Nat.Properties
+
+
 {-# 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) )
@@ -48,10 +52,25 @@
 whileLoop' env proof next | yes p = whileLoop' env1 (proof3 p ) next
     where
       env1 = record {varn = (varn  env) - 1 ; vari = (vari env) + 1}
+      1<0 : 1 ≤ zero → ⊥
+      1<0 ()
       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 = {!!}
+      proof3 (s≤s z≤n) | zero = ⊥-elim (1<0 p)
+      proof3 (s≤s (z≤n {n'}) ) | suc n =  let open ≡-Reasoning  in
+          begin
+             n' + (vari env + 1) 
+          ≡⟨ cong ( λ z → n' + z ) ( +-sym  {vari env} {1} )  ⟩
+             n' + (1 + vari env ) 
+          ≡⟨ sym ( +-assoc (n')  1 (vari env) ) ⟩
+             (n' + 1 ) + vari env 
+          ≡⟨ cong ( λ z → z + vari env )  +1≡suc  ⟩
+             (suc n' ) + vari env 
+          ≡⟨⟩
+             varn env + vari env
+          ≡⟨ proof  ⟩
+             10
+          ∎
 
 
 conversion1 : {l : Level} {t : Set l } → (env : Env) -> ((vari env) ≡ 0) /\ ((varn env) ≡ 10)