src/HOL/IMP/Small_Step.thy
changeset 45015 fdac1e9880eb
parent 44036 d03f9f28d01d
child 45114 fa3715b35370
equal deleted inserted replaced
45014:0e847655b2d8 45015:fdac1e9880eb
    69 
    69 
    70 
    70 
    71 text{* A simple property: *}
    71 text{* A simple property: *}
    72 lemma deterministic:
    72 lemma deterministic:
    73   "cs \<rightarrow> cs' \<Longrightarrow> cs \<rightarrow> cs'' \<Longrightarrow> cs'' = cs'"
    73   "cs \<rightarrow> cs' \<Longrightarrow> cs \<rightarrow> cs'' \<Longrightarrow> cs'' = cs'"
    74 apply(induct arbitrary: cs'' rule: small_step.induct)
    74 apply(induction arbitrary: cs'' rule: small_step.induct)
    75 apply blast+
    75 apply blast+
    76 done
    76 done
    77 
    77 
    78 
    78 
    79 subsection "Equivalence with big-step semantics"
    79 subsection "Equivalence with big-step semantics"
    80 
    80 
    81 lemma star_semi2: "(c1,s) \<rightarrow>* (c1',s') \<Longrightarrow> (c1;c2,s) \<rightarrow>* (c1';c2,s')"
    81 lemma star_semi2: "(c1,s) \<rightarrow>* (c1',s') \<Longrightarrow> (c1;c2,s) \<rightarrow>* (c1';c2,s')"
    82 proof(induct rule: star_induct)
    82 proof(induction rule: star_induct)
    83   case refl thus ?case by simp
    83   case refl thus ?case by simp
    84 next
    84 next
    85   case step
    85   case step
    86   thus ?case by (metis Semi2 star.step)
    86   thus ?case by (metis Semi2 star.step)
    87 qed
    87 qed
    96 also/finally proof steps do: they compose chains, implicitly using the rules
    96 also/finally proof steps do: they compose chains, implicitly using the rules
    97 declared with attribute [trans] above. *}
    97 declared with attribute [trans] above. *}
    98 
    98 
    99 lemma big_to_small:
    99 lemma big_to_small:
   100   "cs \<Rightarrow> t \<Longrightarrow> cs \<rightarrow>* (SKIP,t)"
   100   "cs \<Rightarrow> t \<Longrightarrow> cs \<rightarrow>* (SKIP,t)"
   101 proof (induct rule: big_step.induct)
   101 proof (induction rule: big_step.induct)
   102   fix s show "(SKIP,s) \<rightarrow>* (SKIP,s)" by simp
   102   fix s show "(SKIP,s) \<rightarrow>* (SKIP,s)" by simp
   103 next
   103 next
   104   fix x a s show "(x ::= a,s) \<rightarrow>* (SKIP, s(x := aval a s))" by auto
   104   fix x a s show "(x ::= a,s) \<rightarrow>* (SKIP, s(x := aval a s))" by auto
   105 next
   105 next
   106   fix c1 c2 s1 s2 s3
   106   fix c1 c2 s1 s2 s3
   138   finally show "(WHILE b DO c,s) \<rightarrow>* (SKIP,t)" by auto
   138   finally show "(WHILE b DO c,s) \<rightarrow>* (SKIP,t)" by auto
   139 qed
   139 qed
   140 
   140 
   141 text{* Each case of the induction can be proved automatically: *}
   141 text{* Each case of the induction can be proved automatically: *}
   142 lemma  "cs \<Rightarrow> t \<Longrightarrow> cs \<rightarrow>* (SKIP,t)"
   142 lemma  "cs \<Rightarrow> t \<Longrightarrow> cs \<rightarrow>* (SKIP,t)"
   143 proof (induct rule: big_step.induct)
   143 proof (induction rule: big_step.induct)
   144   case Skip show ?case by blast
   144   case Skip show ?case by blast
   145 next
   145 next
   146   case Assign show ?case by blast
   146   case Assign show ?case by blast
   147 next
   147 next
   148   case Semi thus ?case by (blast intro: semi_comp)
   148   case Semi thus ?case by (blast intro: semi_comp)
   159     by(metis While semi_comp small_step.IfTrue step[of small_step])
   159     by(metis While semi_comp small_step.IfTrue step[of small_step])
   160 qed
   160 qed
   161 
   161 
   162 lemma small1_big_continue:
   162 lemma small1_big_continue:
   163   "cs \<rightarrow> cs' \<Longrightarrow> cs' \<Rightarrow> t \<Longrightarrow> cs \<Rightarrow> t"
   163   "cs \<rightarrow> cs' \<Longrightarrow> cs' \<Rightarrow> t \<Longrightarrow> cs \<Rightarrow> t"
   164 apply (induct arbitrary: t rule: small_step.induct)
   164 apply (induction arbitrary: t rule: small_step.induct)
   165 apply auto
   165 apply auto
   166 done
   166 done
   167 
   167 
   168 lemma small_big_continue:
   168 lemma small_big_continue:
   169   "cs \<rightarrow>* cs' \<Longrightarrow> cs' \<Rightarrow> t \<Longrightarrow> cs \<Rightarrow> t"
   169   "cs \<rightarrow>* cs' \<Longrightarrow> cs' \<Rightarrow> t \<Longrightarrow> cs \<Rightarrow> t"
   170 apply (induct rule: star.induct)
   170 apply (induction rule: star.induct)
   171 apply (auto intro: small1_big_continue)
   171 apply (auto intro: small1_big_continue)
   172 done
   172 done
   173 
   173 
   174 lemma small_to_big: "cs \<rightarrow>* (SKIP,t) \<Longrightarrow> cs \<Rightarrow> t"
   174 lemma small_to_big: "cs \<rightarrow>* (SKIP,t) \<Longrightarrow> cs \<Rightarrow> t"
   175 by (metis small_big_continue Skip)
   175 by (metis small_big_continue Skip)
   186 
   186 
   187 definition "final cs \<longleftrightarrow> \<not>(EX cs'. cs \<rightarrow> cs')"
   187 definition "final cs \<longleftrightarrow> \<not>(EX cs'. cs \<rightarrow> cs')"
   188 
   188 
   189 lemma finalD: "final (c,s) \<Longrightarrow> c = SKIP"
   189 lemma finalD: "final (c,s) \<Longrightarrow> c = SKIP"
   190 apply(simp add: final_def)
   190 apply(simp add: final_def)
   191 apply(induct c)
   191 apply(induction c)
   192 apply blast+
   192 apply blast+
   193 done
   193 done
   194 
   194 
   195 lemma final_iff_SKIP: "final (c,s) = (c = SKIP)"
   195 lemma final_iff_SKIP: "final (c,s) = (c = SKIP)"
   196 by (metis SkipE finalD final_def)
   196 by (metis SkipE finalD final_def)