theory CCorresLemmas

lemma ccorres_from_vcg_throws_nofail:
  "\<forall>\<sigma>. \<Gamma>\<turnstile> {s. P \<sigma> \<and> s \<in> P' \<and> (\<sigma>, s) \<in> srel} c {},
  {s. \<not>snd (a \<sigma>) \<longrightarrow> (\<exists>(rv, \<sigma>')\<in>fst (a \<sigma>). (\<sigma>', s) \<in> srel \<and> arrel rv (axf s))} \<Longrightarrow>
  ccorres_underlying srel \<Gamma> r xf arrel axf P P' (SKIP # hs) a c" apply (rule ccorresI') apply (drule_tac x = s in spec) apply (drule hoare_sound) apply (simp add: HoarePartialDef.valid_def cvalid_def) apply (erule exec_handlers.cases) apply clarsimp apply (drule spec, drule spec, drule (1) mp) apply (clarsimp dest!: exec_handlers_SkipD
                     simp: split_def unif_rrel_simps elim!: bexI [rotated]) apply clarsimp apply (drule spec, drule spec, drule (1) mp) apply clarsimp apply simp done

(* Proof state trace *)
proof (prove)
goal (1 subgoal):
 1. \<forall>\<sigma>. \<Gamma>\<turnstile> {s. P \<sigma> \<and> s \<in> P' \<and> (\<sigma>, s) \<in> srel} c {},{s. \<not> snd (a \<sigma>) \<longrightarrow> (\<exists>(rv, \<sigma>')\<in>fst (a \<sigma>). (\<sigma>', s) \<in> srel \<and> arrel rv (axf s))} \<Longrightarrow> ccorres_underlying srel \<Gamma> r xf arrel axf P P' (SKIP # hs) a c proof (prove)
goal (1 subgoal):
 1. \<And>s s' n z. \<lbrakk>\<forall>\<sigma>. \<Gamma>\<turnstile> {s. P \<sigma> \<and> s \<in> P' \<and> (\<sigma>, s) \<in> srel} c {},{s. \<not> snd (a \<sigma>) \<longrightarrow> (\<exists>(rv, \<sigma>')\<in>fst (a \<sigma>). (\<sigma>', s) \<in> srel \<and> arrel rv (axf s))}; (s, s') \<in> srel; P s; s' \<in> P'; \<Gamma>\<turnstile>\<^sub>h \<langle>c # SKIP # hs,s'\<rangle> \<Rightarrow> (n, z); \<not> snd (a s)\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>(ra, t)\<in>fst (a s). (t, t') \<in> srel \<and> unif_rrel (n = length (SKIP # hs)) r xf arrel axf ra t') proof (prove)
goal (1 subgoal):
 1. \<And>s s' n z. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<Gamma>\<turnstile>\<^sub>h \<langle>c # SKIP # hs,s'\<rangle> \<Rightarrow> (n, z); \<not> snd (a s); \<Gamma>\<turnstile> {sa. P s \<and> sa \<in> P' \<and> (s, sa) \<in> srel} c {},{sa. \<not> snd (a s) \<longrightarrow> (\<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa))}\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>(ra, t)\<in>fst (a s). (t, t') \<in> srel \<and> unif_rrel (n = length (SKIP # hs)) r xf arrel axf ra t') proof (prove)
goal (1 subgoal):
 1. \<And>s s' n z. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<Gamma>\<turnstile>\<^sub>h \<langle>c # SKIP # hs,s'\<rangle> \<Rightarrow> (n, z); \<not> snd (a s); \<Gamma>,{}\<Turnstile>\<^bsub>/{}\<^esub> {sa. P s \<and> sa \<in> P' \<and> (s, sa) \<in> srel} c {},{sa. \<not> snd (a s) \<longrightarrow> (\<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa))}\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>(ra, t)\<in>fst (a s). (t, t') \<in> srel \<and> unif_rrel (n = length (SKIP # hs)) r xf arrel axf ra t') proof (prove)
goal (1 subgoal):
 1. \<And>s s' n z. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<Gamma>\<turnstile>\<^sub>h \<langle>c # SKIP # hs,s'\<rangle> \<Rightarrow> (n, z); \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (n = Suc (length hs)) r xf arrel axf ra t') proof (prove)
goal (3 subgoals):
 1. \<And>s s' n z h sa za hsa na t. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; s' = sa; c # SKIP # hs = h # hsa; n = na; z = t; \<Gamma>\<turnstile> \<langle>h,Normal sa\<rangle> \<Rightarrow> Abrupt za; \<Gamma>\<turnstile>\<^sub>h \<langle>hsa,za\<rangle> \<Rightarrow> (na, t)\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (n = Suc (length hs)) r xf arrel axf ra t')
 2. \<And>s s' n z h sa t hsa. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; s' = sa; c # SKIP # hs = h # hsa; n = length hsa; z = t; \<Gamma>\<turnstile> \<langle>h,Normal sa\<rangle> \<Rightarrow> t; \<not> isAbr t\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (n = Suc (length hs)) r xf arrel axf ra t')
 3. \<And>s s' n z sa. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; s' = sa; c # SKIP # hs = []; n = 0; z = Abrupt sa\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (n = Suc (length hs)) r xf arrel axf ra t') proof (prove)
goal (3 subgoals):
 1. \<And>s sa za na t. \<lbrakk>(s, sa) \<in> srel; P s; sa \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>x\<in>fst (a s). case x of (rv, \<sigma>') \<Rightarrow> (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; \<Gamma>\<turnstile> \<langle>c,Normal sa\<rangle> \<Rightarrow> Abrupt za; \<Gamma>\<turnstile>\<^sub>h \<langle>SKIP # hs,za\<rangle> \<Rightarrow> (na, t)\<rbrakk> \<Longrightarrow> \<exists>t'. t = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (na = Suc (length hs)) r xf arrel axf ra t')
 2. \<And>s s' n z h sa t hsa. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; s' = sa; c # SKIP # hs = h # hsa; n = length hsa; z = t; \<Gamma>\<turnstile> \<langle>h,Normal sa\<rangle> \<Rightarrow> t; \<not> isAbr t\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (n = Suc (length hs)) r xf arrel axf ra t')
 3. \<And>s s' n z sa. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; s' = sa; c # SKIP # hs = []; n = 0; z = Abrupt sa\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (n = Suc (length hs)) r xf arrel axf ra t') proof (prove)
goal (3 subgoals):
 1. \<And>s sa za na t. \<lbrakk>(s, sa) \<in> srel; P s; sa \<in> P'; \<not> snd (a s); \<Gamma>\<turnstile> \<langle>c,Normal sa\<rangle> \<Rightarrow> Abrupt za; \<Gamma>\<turnstile>\<^sub>h \<langle>SKIP # hs,za\<rangle> \<Rightarrow> (na, t); Normal sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> Abrupt za \<in> Abrupt ` {sa. \<exists>x\<in>fst (a s). case x of (rv, \<sigma>') \<Rightarrow> (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}\<rbrakk> \<Longrightarrow> \<exists>t'. t = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (na = Suc (length hs)) r xf arrel axf ra t')
 2. \<And>s s' n z h sa t hsa. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; s' = sa; c # SKIP # hs = h # hsa; n = length hsa; z = t; \<Gamma>\<turnstile> \<langle>h,Normal sa\<rangle> \<Rightarrow> t; \<not> isAbr t\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (n = Suc (length hs)) r xf arrel axf ra t')
 3. \<And>s s' n z sa. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; s' = sa; c # SKIP # hs = []; n = 0; z = Abrupt sa\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (n = Suc (length hs)) r xf arrel axf ra t') proof (prove)
goal (2 subgoals):
 1. \<And>s s' n z h sa t hsa. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; s' = sa; c # SKIP # hs = h # hsa; n = length hsa; z = t; \<Gamma>\<turnstile> \<langle>h,Normal sa\<rangle> \<Rightarrow> t; \<not> isAbr t\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (n = Suc (length hs)) r xf arrel axf ra t')
 2. \<And>s s' n z sa. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; s' = sa; c # SKIP # hs = []; n = 0; z = Abrupt sa\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (n = Suc (length hs)) r xf arrel axf ra t') proof (prove)
goal (2 subgoals):
 1. \<And>s sa t. \<lbrakk>(s, sa) \<in> srel; P s; sa \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>x\<in>fst (a s). case x of (rv, \<sigma>') \<Rightarrow> (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; \<Gamma>\<turnstile> \<langle>c,Normal sa\<rangle> \<Rightarrow> t; \<not> isAbr t\<rbrakk> \<Longrightarrow> \<exists>t'. t = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel True r xf arrel axf ra t')
 2. \<And>s s' n z sa. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; s' = sa; c # SKIP # hs = []; n = 0; z = Abrupt sa\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (n = Suc (length hs)) r xf arrel axf ra t') proof (prove)
goal (2 subgoals):
 1. \<And>s sa t. \<lbrakk>(s, sa) \<in> srel; P s; sa \<in> P'; \<not> snd (a s); \<Gamma>\<turnstile> \<langle>c,Normal sa\<rangle> \<Rightarrow> t; \<not> isAbr t; Normal sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>x\<in>fst (a s). case x of (rv, \<sigma>') \<Rightarrow> (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}\<rbrakk> \<Longrightarrow> \<exists>t'. t = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel True r xf arrel axf ra t')
 2. \<And>s s' n z sa. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; s' = sa; c # SKIP # hs = []; n = 0; z = Abrupt sa\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (n = Suc (length hs)) r xf arrel axf ra t') proof (prove)
goal (1 subgoal):
 1. \<And>s s' n z sa. \<lbrakk>(s, s') \<in> srel; P s; s' \<in> P'; \<not> snd (a s); \<forall>sa t. \<Gamma>\<turnstile> \<langle>c,sa\<rangle> \<Rightarrow> t \<longrightarrow> sa \<in> Normal ` {sa \<in> P'. (s, sa) \<in> srel} \<longrightarrow> t \<in> Abrupt ` {sa. \<exists>(rv, \<sigma>')\<in>fst (a s). (\<sigma>', sa) \<in> srel \<and> arrel rv (axf sa)}; s' = sa; c # SKIP # hs = []; n = 0; z = Abrupt sa\<rbrakk> \<Longrightarrow> \<exists>t'. z = Normal t' \<and> (\<exists>x\<in>fst (a s). case x of (ra, t) \<Rightarrow> (t, t') \<in> srel \<and> unif_rrel (n = Suc (length hs)) r xf arrel axf ra t') proof (prove)
goal:
No subgoals!