src/HOL/IMP/Types.thy
changeset 45015 fdac1e9880eb
parent 44890 22f665a2e91c
child 45200 1f1897ac7877
equal deleted inserted replaced
45014:0e847655b2d8 45015:fdac1e9880eb
   117 definition styping :: "tyenv \<Rightarrow> state \<Rightarrow> bool" (infix "\<turnstile>" 50)
   117 definition styping :: "tyenv \<Rightarrow> state \<Rightarrow> bool" (infix "\<turnstile>" 50)
   118 where "\<Gamma> \<turnstile> s  \<longleftrightarrow>  (\<forall>x. type (s x) = \<Gamma> x)"
   118 where "\<Gamma> \<turnstile> s  \<longleftrightarrow>  (\<forall>x. type (s x) = \<Gamma> x)"
   119 
   119 
   120 lemma apreservation:
   120 lemma apreservation:
   121   "\<Gamma> \<turnstile> a : \<tau> \<Longrightarrow> taval a s v \<Longrightarrow> \<Gamma> \<turnstile> s \<Longrightarrow> type v = \<tau>"
   121   "\<Gamma> \<turnstile> a : \<tau> \<Longrightarrow> taval a s v \<Longrightarrow> \<Gamma> \<turnstile> s \<Longrightarrow> type v = \<tau>"
   122 apply(induct arbitrary: v rule: atyping.induct)
   122 apply(induction arbitrary: v rule: atyping.induct)
   123 apply (fastforce simp: styping_def)+
   123 apply (fastforce simp: styping_def)+
   124 done
   124 done
   125 
   125 
   126 lemma aprogress: "\<Gamma> \<turnstile> a : \<tau> \<Longrightarrow> \<Gamma> \<turnstile> s \<Longrightarrow> \<exists>v. taval a s v"
   126 lemma aprogress: "\<Gamma> \<turnstile> a : \<tau> \<Longrightarrow> \<Gamma> \<turnstile> s \<Longrightarrow> \<exists>v. taval a s v"
   127 proof(induct rule: atyping.induct)
   127 proof(induction rule: atyping.induct)
   128   case (Plus_ty \<Gamma> a1 t a2)
   128   case (Plus_ty \<Gamma> a1 t a2)
   129   then obtain v1 v2 where v: "taval a1 s v1" "taval a2 s v2" by blast
   129   then obtain v1 v2 where v: "taval a1 s v1" "taval a2 s v2" by blast
   130   show ?case
   130   show ?case
   131   proof (cases v1)
   131   proof (cases v1)
   132     case Iv
   132     case Iv
   133     with Plus_ty(1,3,5) v show ?thesis
   133     with Plus_ty v show ?thesis
   134       by(fastforce intro: taval.intros(4) dest!: apreservation)
   134       by(fastforce intro: taval.intros(4) dest!: apreservation)
   135   next
   135   next
   136     case Rv
   136     case Rv
   137     with Plus_ty(1,3,5) v show ?thesis
   137     with Plus_ty v show ?thesis
   138       by(fastforce intro: taval.intros(5) dest!: apreservation)
   138       by(fastforce intro: taval.intros(5) dest!: apreservation)
   139   qed
   139   qed
   140 qed (auto intro: taval.intros)
   140 qed (auto intro: taval.intros)
   141 
   141 
   142 lemma bprogress: "\<Gamma> \<turnstile> b \<Longrightarrow> \<Gamma> \<turnstile> s \<Longrightarrow> \<exists>v. tbval b s v"
   142 lemma bprogress: "\<Gamma> \<turnstile> b \<Longrightarrow> \<Gamma> \<turnstile> s \<Longrightarrow> \<exists>v. tbval b s v"
   143 proof(induct rule: btyping.induct)
   143 proof(induction rule: btyping.induct)
   144   case (Less_ty \<Gamma> a1 t a2)
   144   case (Less_ty \<Gamma> a1 t a2)
   145   then obtain v1 v2 where v: "taval a1 s v1" "taval a2 s v2"
   145   then obtain v1 v2 where v: "taval a1 s v1" "taval a2 s v2"
   146     by (metis aprogress)
   146     by (metis aprogress)
   147   show ?case
   147   show ?case
   148   proof (cases v1)
   148   proof (cases v1)
   156   qed
   156   qed
   157 qed (auto intro: tbval.intros)
   157 qed (auto intro: tbval.intros)
   158 
   158 
   159 theorem progress:
   159 theorem progress:
   160   "\<Gamma> \<turnstile> c \<Longrightarrow> \<Gamma> \<turnstile> s \<Longrightarrow> c \<noteq> SKIP \<Longrightarrow> \<exists>cs'. (c,s) \<rightarrow> cs'"
   160   "\<Gamma> \<turnstile> c \<Longrightarrow> \<Gamma> \<turnstile> s \<Longrightarrow> c \<noteq> SKIP \<Longrightarrow> \<exists>cs'. (c,s) \<rightarrow> cs'"
   161 proof(induct rule: ctyping.induct)
   161 proof(induction rule: ctyping.induct)
   162   case Skip_ty thus ?case by simp
   162   case Skip_ty thus ?case by simp
   163 next
   163 next
   164   case Assign_ty 
   164   case Assign_ty 
   165   thus ?case by (metis Assign aprogress)
   165   thus ?case by (metis Assign aprogress)
   166 next
   166 next
   180   case While_ty show ?case by (metis While)
   180   case While_ty show ?case by (metis While)
   181 qed
   181 qed
   182 
   182 
   183 theorem styping_preservation:
   183 theorem styping_preservation:
   184   "(c,s) \<rightarrow> (c',s') \<Longrightarrow> \<Gamma> \<turnstile> c \<Longrightarrow> \<Gamma> \<turnstile> s \<Longrightarrow> \<Gamma> \<turnstile> s'"
   184   "(c,s) \<rightarrow> (c',s') \<Longrightarrow> \<Gamma> \<turnstile> c \<Longrightarrow> \<Gamma> \<turnstile> s \<Longrightarrow> \<Gamma> \<turnstile> s'"
   185 proof(induct rule: small_step_induct)
   185 proof(induction rule: small_step_induct)
   186   case Assign thus ?case
   186   case Assign thus ?case
   187     by (auto simp: styping_def) (metis Assign(1,3) apreservation)
   187     by (auto simp: styping_def) (metis Assign(1,3) apreservation)
   188 qed auto
   188 qed auto
   189 
   189 
   190 theorem ctyping_preservation:
   190 theorem ctyping_preservation:
   195 where "x \<rightarrow>* y == star small_step x y"
   195 where "x \<rightarrow>* y == star small_step x y"
   196 
   196 
   197 theorem type_sound:
   197 theorem type_sound:
   198   "(c,s) \<rightarrow>* (c',s') \<Longrightarrow> \<Gamma> \<turnstile> c \<Longrightarrow> \<Gamma> \<turnstile> s \<Longrightarrow> c' \<noteq> SKIP
   198   "(c,s) \<rightarrow>* (c',s') \<Longrightarrow> \<Gamma> \<turnstile> c \<Longrightarrow> \<Gamma> \<turnstile> s \<Longrightarrow> c' \<noteq> SKIP
   199    \<Longrightarrow> \<exists>cs''. (c',s') \<rightarrow> cs''"
   199    \<Longrightarrow> \<exists>cs''. (c',s') \<rightarrow> cs''"
   200 apply(induct rule:star_induct)
   200 apply(induction rule:star_induct)
   201 apply (metis progress)
   201 apply (metis progress)
   202 by (metis styping_preservation ctyping_preservation)
   202 by (metis styping_preservation ctyping_preservation)
   203 
   203 
   204 end
   204 end