tuned the proof
authorurbanc
Mon Mar 19 19:28:27 2007 +0100 (2007-03-19)
changeset 22472bfd9c0fd70b1
parent 22471 7c51f1a799f3
child 22473 753123c89d72
tuned the proof
src/HOL/Nominal/Examples/SOS.thy
     1.1 --- a/src/HOL/Nominal/Examples/SOS.thy	Mon Mar 19 15:58:02 2007 +0100
     1.2 +++ b/src/HOL/Nominal/Examples/SOS.thy	Mon Mar 19 19:28:27 2007 +0100
     1.3 @@ -1,10 +1,12 @@
     1.4  (* "$Id$" *)
     1.5  (*                                                   *)
     1.6 -(* Formalisation of some typical SOS-proofs from a   *)
     1.7 -(* challenge suggested by Adam Chlipala.             *)
     1.8 +(* Formalisation of some typical SOS-proofs          *)
     1.9  (*                                                   *) 
    1.10 -(* We thank Nick Benton for hellping us with the     *) 
    1.11 -(* termination-proof for evaluation .                *)
    1.12 +(* This work arose from challenge suggested by Adam  *)
    1.13 +(* Chlipala suggested on the POPLmark mailing list.  *)
    1.14 +(*                                                   *) 
    1.15 +(* We thank Nick Benton for helping us with the      *) 
    1.16 +(* termination-proof for evaluation.                 *)
    1.17  
    1.18  theory SOS
    1.19    imports "Nominal"
    1.20 @@ -87,6 +89,8 @@
    1.21  by (induct rule: lookup.induct)
    1.22     (auto simp add: fresh_list_cons fresh_prod fresh_atm)
    1.23  
    1.24 +text {* Parallel Substitution *}
    1.25 +
    1.26  consts
    1.27    psubst :: "(name\<times>trm) list \<Rightarrow> trm \<Rightarrow> trm"  ("_<_>" [95,95] 105)
    1.28   
    1.29 @@ -101,20 +105,19 @@
    1.30    "\<theta><(InL e)> = InL (\<theta><e>)"
    1.31    "\<theta><(InR e)> = InR (\<theta><e>)"
    1.32    "\<lbrakk>y\<noteq>x; x\<sharp>(e,e\<^isub>2,\<theta>); y\<sharp>(e,e\<^isub>1,\<theta>)\<rbrakk> 
    1.33 -   \<Longrightarrow> \<theta><(Case e of inl x \<rightarrow> e\<^isub>1 | inr y \<rightarrow> e\<^isub>2)> =
    1.34 -                            (Case (\<theta><e>) of inl x \<rightarrow> (\<theta><e\<^isub>1>) | inr y \<rightarrow> (\<theta><e\<^isub>2>))"
    1.35 -  apply(finite_guess add: lookup_eqvt)+
    1.36 -  apply(rule TrueI)+
    1.37 -  apply(simp add: abs_fresh)+
    1.38 -  apply(fresh_guess add: fs_name1 lookup_eqvt)+
    1.39 -  done
    1.40 +   \<Longrightarrow> \<theta><Case e of inl x \<rightarrow> e\<^isub>1 | inr y \<rightarrow> e\<^isub>2> = (Case (\<theta><e>) of inl x \<rightarrow> (\<theta><e\<^isub>1>) | inr y \<rightarrow> (\<theta><e\<^isub>2>))"
    1.41 +apply(finite_guess add: lookup_eqvt)+
    1.42 +apply(rule TrueI)+
    1.43 +apply(simp add: abs_fresh)+
    1.44 +apply(fresh_guess add: fs_name1 lookup_eqvt)+
    1.45 +done
    1.46  
    1.47  lemma psubst_eqvt[eqvt]:
    1.48    fixes pi::"name prm" 
    1.49    and   t::"trm"
    1.50    shows "pi\<bullet>(\<theta><t>) = (pi\<bullet>\<theta>)<(pi\<bullet>t)>"
    1.51 -  by (nominal_induct t avoiding: \<theta> rule: trm.induct)
    1.52 -     (perm_simp add: fresh_bij lookup_eqvt)+
    1.53 +by (nominal_induct t avoiding: \<theta> rule: trm.induct)
    1.54 +   (perm_simp add: fresh_bij lookup_eqvt)+
    1.55  
    1.56  lemma fresh_psubst: 
    1.57    fixes z::"name"
    1.58 @@ -142,7 +145,7 @@
    1.59    and   "\<lbrakk>z\<noteq>x; x\<sharp>(y,e,e\<^isub>2,t'); z\<sharp>(y,e,e\<^isub>1,t')\<rbrakk> 
    1.60           \<Longrightarrow> (Case e of inl x \<rightarrow> e\<^isub>1 | inr z \<rightarrow> e\<^isub>2)[y::=t'] =
    1.61                     (Case (e[y::=t']) of inl x \<rightarrow> (e\<^isub>1[y::=t']) | inr z \<rightarrow> (e\<^isub>2[y::=t']))"
    1.62 -  by (simp_all add: fresh_list_cons fresh_list_nil)
    1.63 +by (simp_all add: fresh_list_cons fresh_list_nil)
    1.64  
    1.65  lemma subst_eqvt[eqvt]:
    1.66    fixes pi::"name prm" 
    1.67 @@ -151,60 +154,6 @@
    1.68    by (nominal_induct t avoiding: x t' rule: trm.induct)
    1.69       (perm_simp add: fresh_bij)+
    1.70  
    1.71 -
    1.72 -lemma subst_rename: 
    1.73 -  fixes c::"name"
    1.74 -  and   t\<^isub>1::"trm"
    1.75 -  assumes "c\<sharp>t\<^isub>1"
    1.76 -  shows "t\<^isub>1[a::=t\<^isub>2] = ([(c,a)]\<bullet>t\<^isub>1)[c::=t\<^isub>2]"
    1.77 -  using assms
    1.78 -  apply(nominal_induct t\<^isub>1 avoiding: a c t\<^isub>2 rule: trm.induct)
    1.79 -  apply(simp add: trm.inject calc_atm fresh_atm abs_fresh perm_nat_def)
    1.80 -  apply(simp add: trm.inject calc_atm fresh_atm abs_fresh perm_nat_def)
    1.81 -  apply(simp add: trm.inject calc_atm fresh_atm abs_fresh perm_nat_def)
    1.82 -  apply(simp add: trm.inject calc_atm fresh_atm abs_fresh perm_nat_def)
    1.83 -  apply(simp add: trm.inject calc_atm fresh_atm abs_fresh perm_nat_def)
    1.84 -  apply(simp add: trm.inject calc_atm fresh_atm abs_fresh perm_nat_def)
    1.85 -  apply(simp add: trm.inject calc_atm fresh_atm abs_fresh perm_nat_def)
    1.86 -  apply(simp add: trm.inject calc_atm fresh_atm abs_fresh perm_nat_def)
    1.87 -  apply(simp add: trm.inject calc_atm fresh_atm abs_fresh perm_nat_def) 
    1.88 -  apply(simp (no_asm_use))
    1.89 -  apply(rule sym)
    1.90 -  apply(rule trans)
    1.91 -  apply(rule subst)
    1.92 -  apply(simp add: perm_bij)
    1.93 -  apply(simp add: fresh_prod)
    1.94 -  apply(simp add: fresh_bij)
    1.95 -  apply(simp add: calc_atm fresh_atm)
    1.96 -  apply(simp add: fresh_prod)
    1.97 -  apply(simp add: fresh_bij)
    1.98 -  apply(simp add: calc_atm fresh_atm)
    1.99 -  apply(rule sym)
   1.100 -  apply(rule trans)
   1.101 -  apply(rule subst)
   1.102 -  apply(simp add: fresh_atm)
   1.103 -  apply(simp)
   1.104 -  apply(simp)
   1.105 -  apply(simp (no_asm_use) add: trm.inject)
   1.106 -  apply(rule conjI)
   1.107 -  apply(blast)
   1.108 -  apply(rule conjI)
   1.109 -  apply(rotate_tac 12)
   1.110 -  apply(drule_tac x="a" in meta_spec)
   1.111 -  apply(rotate_tac 14)
   1.112 -  apply(drule_tac x="c" in meta_spec)
   1.113 -  apply(rotate_tac 14)
   1.114 -  apply(drule_tac x="t\<^isub>2" in meta_spec)
   1.115 -  apply(simp add: calc_atm fresh_atm alpha abs_fresh)
   1.116 -  apply(rotate_tac 13)
   1.117 -  apply(drule_tac x="a" in meta_spec)
   1.118 -  apply(rotate_tac 14)
   1.119 -  apply(drule_tac x="c" in meta_spec)
   1.120 -  apply(rotate_tac 14)
   1.121 -  apply(drule_tac x="t\<^isub>2" in meta_spec)
   1.122 -  apply(simp add: calc_atm fresh_atm alpha abs_fresh)
   1.123 -  done
   1.124 -
   1.125  lemma fresh_subst:
   1.126    fixes z::"name"
   1.127    and   t\<^isub>1::"trm"
   1.128 @@ -234,24 +183,6 @@
   1.129    by (nominal_induct L avoiding: x P rule: trm.induct)
   1.130       (auto simp add: fresh_atm abs_fresh)
   1.131  
   1.132 -lemma subst_fun_eq:
   1.133 -  fixes u::trm
   1.134 -  assumes "[x].t\<^isub>1 = [y].t\<^isub>2"
   1.135 -  shows "t\<^isub>1[x::=u] = t\<^isub>2[y::=u]"
   1.136 -proof -
   1.137 -  { 
   1.138 -    assume "x=y" and "t\<^isub>1=t\<^isub>2"
   1.139 -    then have ?thesis using assms by simp
   1.140 -  }
   1.141 -  moreover 
   1.142 -  {
   1.143 -    assume h1:"x \<noteq> y" and h2:"t\<^isub>1=[(x,y)]\<bullet>t\<^isub>2" and h3:"x \<sharp> t\<^isub>2"
   1.144 -    then have "([(x,y)]\<bullet>t\<^isub>2)[x::=u] = t\<^isub>2[y::=u]" by (simp add: subst_rename)
   1.145 -    then have ?thesis using h2 by simp 
   1.146 -  }
   1.147 -  ultimately show ?thesis using alpha assms by blast
   1.148 -qed
   1.149 -
   1.150  lemma psubst_empty[simp]:
   1.151    shows "[]<t> = t"
   1.152    by (nominal_induct t rule: trm.induct, auto simp add:fresh_list_nil)
   1.153 @@ -271,7 +202,7 @@
   1.154  by (nominal_induct t avoiding: a e rule: trm.induct)
   1.155     (auto simp add: fresh_atm abs_fresh fresh_nat) 
   1.156  
   1.157 -text {* Typing *}
   1.158 +text {* Typing-Judgements *}
   1.159  
   1.160  inductive2
   1.161    valid :: "(name \<times> 'a::pt_name) list \<Rightarrow> bool"
   1.162 @@ -335,7 +266,7 @@
   1.163                     (x\<^isub>1,Data(S\<^isub>1))#\<Gamma> \<turnstile> e\<^isub>1 : T; (x\<^isub>2,Data(S\<^isub>2))#\<Gamma> \<turnstile> e\<^isub>2 : T\<rbrakk> 
   1.164                     \<Longrightarrow> \<Gamma> \<turnstile> (Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2) : T"
   1.165  
   1.166 -lemma typing_valid:
   1.167 +lemma typing_implies_valid:
   1.168    assumes "\<Gamma> \<turnstile> t : T"
   1.169    shows "valid \<Gamma>"
   1.170    using assms
   1.171 @@ -535,7 +466,7 @@
   1.172    have "[(x\<^isub>1',c)]\<bullet>((x\<^isub>1',Data \<sigma>\<^isub>1)# \<Gamma>) \<turnstile> [(x\<^isub>1',c)]\<bullet>e\<^isub>1' : T" using h1 typing_eqvt by blast
   1.173    then have x:"(c,Data \<sigma>\<^isub>1)#( [(x\<^isub>1',c)]\<bullet>\<Gamma>) \<turnstile> [(x\<^isub>1',c)]\<bullet>e\<^isub>1': T" using f' 
   1.174      by (auto simp add: fresh_atm calc_atm)
   1.175 -  have "x\<^isub>1' \<sharp> \<Gamma>" using h1 typing_valid by auto
   1.176 +  have "x\<^isub>1' \<sharp> \<Gamma>" using h1 typing_implies_valid by auto
   1.177    then have "(c,Data \<sigma>\<^isub>1)#\<Gamma> \<turnstile> [(x\<^isub>1 ,c)]\<bullet>e\<^isub>1 : T" using f' x e1' by (auto simp add: perm_fresh_fresh)
   1.178    then have "[(x\<^isub>1,c)]\<bullet>((c,Data \<sigma>\<^isub>1)#\<Gamma>) \<turnstile> [(x\<^isub>1,c)]\<bullet>[(x\<^isub>1 ,c)]\<bullet>e\<^isub>1 : T" using typing_eqvt by blast 
   1.179    then have "([(x\<^isub>1,c)]\<bullet>(c,Data \<sigma>\<^isub>1)) #\<Gamma> \<turnstile> [(x\<^isub>1,c)]\<bullet>[(x\<^isub>1 ,c)]\<bullet>e\<^isub>1 : T" using f f' 
   1.180 @@ -548,7 +479,7 @@
   1.181    have "[(x\<^isub>2',c)]\<bullet>((x\<^isub>2',Data \<sigma>\<^isub>2)# \<Gamma>) \<turnstile> [(x\<^isub>2',c)]\<bullet>e\<^isub>2' : T" using h2 typing_eqvt by blast
   1.182    then have x:"(c,Data \<sigma>\<^isub>2)#([(x\<^isub>2',c)]\<bullet>\<Gamma>) \<turnstile> [(x\<^isub>2',c)]\<bullet>e\<^isub>2': T" using f' 
   1.183      by (auto simp add: fresh_atm calc_atm)
   1.184 -  have "x\<^isub>2' \<sharp> \<Gamma>" using h2 typing_valid by auto
   1.185 +  have "x\<^isub>2' \<sharp> \<Gamma>" using h2 typing_implies_valid by auto
   1.186    then have "(c,Data \<sigma>\<^isub>2)#\<Gamma> \<turnstile> [(x\<^isub>2 ,c)]\<bullet>e\<^isub>2 : T" using f' x e2' by (auto simp add: perm_fresh_fresh)
   1.187    then have "[(x\<^isub>2,c)]\<bullet>((c,Data \<sigma>\<^isub>2)#\<Gamma>) \<turnstile> [(x\<^isub>2,c)]\<bullet>[(x\<^isub>2 ,c)]\<bullet>e\<^isub>2 : T" using typing_eqvt by blast 
   1.188    then have "([(x\<^isub>2,c)]\<bullet>(c,Data \<sigma>\<^isub>2))#\<Gamma> \<turnstile> [(x\<^isub>2,c)]\<bullet>[(x\<^isub>2 ,c)]\<bullet>e\<^isub>2 : T" using f f' 
   1.189 @@ -589,7 +520,7 @@
   1.190    assumes a: "(x\<^isub>1,T\<^isub>1)#(x\<^isub>2,T\<^isub>2)#\<Gamma> \<turnstile> e : T"
   1.191    shows "(x\<^isub>2,T\<^isub>2)#(x\<^isub>1,T\<^isub>1)#\<Gamma> \<turnstile> e : T"
   1.192  proof -
   1.193 -  from  a have "valid ((x\<^isub>1,T\<^isub>1)#(x\<^isub>2,T\<^isub>2)#\<Gamma>)" by (simp add: typing_valid)
   1.194 +  from  a have "valid ((x\<^isub>1,T\<^isub>1)#(x\<^isub>2,T\<^isub>2)#\<Gamma>)" by (simp add: typing_implies_valid)
   1.195    then have "x\<^isub>1\<noteq>x\<^isub>2" "x\<^isub>1\<sharp>\<Gamma>" "x\<^isub>2\<sharp>\<Gamma>" "valid \<Gamma>"
   1.196      by (auto simp: fresh_list_cons fresh_atm[symmetric])
   1.197    then have "valid ((x\<^isub>2,T\<^isub>2)#(x\<^isub>1,T\<^isub>1)#\<Gamma>)"
   1.198 @@ -607,7 +538,6 @@
   1.199    thus "t\<^isub>1=t\<^isub>2" by (simp only: type_unicity_in_context)
   1.200  qed
   1.201  
   1.202 -
   1.203  lemma typing_substitution: 
   1.204    fixes \<Gamma>::"(name \<times> ty) list"
   1.205    assumes "(x,T')#\<Gamma> \<turnstile> e : T" 
   1.206 @@ -630,7 +560,7 @@
   1.207      have "(y,T) \<in> set ((x,T')#\<Gamma>)" using h1 by auto
   1.208      then have "(y,T) \<in> set \<Gamma>" using as by auto
   1.209      moreover 
   1.210 -    have "valid \<Gamma>" using h2 by (simp only: typing_valid)
   1.211 +    have "valid \<Gamma>" using h2 by (simp only: typing_implies_valid)
   1.212      ultimately show "\<Gamma> \<turnstile> (Var y)[x::=e'] : T" using as by (simp add: t_Var)
   1.213    qed
   1.214  next
   1.215 @@ -642,7 +572,7 @@
   1.216      using vc by (auto simp add: fresh_list_cons)
   1.217    then have pr2'':"(x,T')#(y,T\<^isub>1)#\<Gamma> \<turnstile> t : T\<^isub>2" by (simp add: context_exchange)
   1.218    have ih: "\<lbrakk>(x,T')#(y,T\<^isub>1)#\<Gamma> \<turnstile> t : T\<^isub>2; (y,T\<^isub>1)#\<Gamma> \<turnstile> e' : T'\<rbrakk> \<Longrightarrow> (y,T\<^isub>1)#\<Gamma> \<turnstile> t[x::=e'] : T\<^isub>2" by fact
   1.219 -  have "valid \<Gamma>" using pr1 by (simp add: typing_valid)
   1.220 +  have "valid \<Gamma>" using pr1 by (simp add: typing_implies_valid)
   1.221    then have "valid ((y,T\<^isub>1)#\<Gamma>)" using vc by auto
   1.222    then have "(y,T\<^isub>1)#\<Gamma> \<turnstile> e' : T'" using pr1 by (auto intro: weakening)
   1.223    then have "(y,T\<^isub>1)#\<Gamma> \<turnstile> t[x::=e'] : T\<^isub>2" using ih pr2'' by simp
   1.224 @@ -667,11 +597,11 @@
   1.225    from h3 have h3': "(x,T')#(x\<^isub>2,Data S\<^isub>2)#\<Gamma> \<turnstile> t3 : T" by (rule context_exchange)
   1.226    have "\<Gamma> \<turnstile> t\<^isub>1[x::=e'] : Data (DSum S\<^isub>1 S\<^isub>2)" using h1 ih1 as1 by simp
   1.227    moreover
   1.228 -  have "valid ((x\<^isub>1,Data S\<^isub>1)#\<Gamma>)" using h2' by (auto dest: typing_valid)
   1.229 +  have "valid ((x\<^isub>1,Data S\<^isub>1)#\<Gamma>)" using h2' by (auto dest: typing_implies_valid)
   1.230    then have "(x\<^isub>1,Data S\<^isub>1)#\<Gamma> \<turnstile> e' : T'" using as1 by (auto simp add: weakening)
   1.231    then have "(x\<^isub>1,Data S\<^isub>1)#\<Gamma> \<turnstile> t\<^isub>2[x::=e'] : T" using ih2 h2' by simp
   1.232    moreover 
   1.233 -  have "valid ((x\<^isub>2,Data S\<^isub>2)#\<Gamma>)" using h3' by (auto dest: typing_valid)
   1.234 +  have "valid ((x\<^isub>2,Data S\<^isub>2)#\<Gamma>)" using h3' by (auto dest: typing_implies_valid)
   1.235    then have "(x\<^isub>2,Data S\<^isub>2)#\<Gamma> \<turnstile> e' : T'" using as1 by (auto simp add: weakening)
   1.236    then have "(x\<^isub>2,Data S\<^isub>2)#\<Gamma> \<turnstile> t3[x::=e'] : T" using ih3 h3' by simp
   1.237    ultimately have "\<Gamma> \<turnstile> Case (t\<^isub>1[x::=e']) of inl x\<^isub>1 \<rightarrow> (t\<^isub>2[x::=e']) | inr x\<^isub>2 \<rightarrow> (t3[x::=e']) : T"
   1.238 @@ -699,6 +629,27 @@
   1.239  
   1.240  nominal_inductive big
   1.241  
   1.242 +lemma big_eqvt[eqvt]:
   1.243 +  fixes pi::"name prm"
   1.244 +  assumes a: "t \<Down> t'"
   1.245 +  shows "(pi\<bullet>t) \<Down> (pi\<bullet>t')"
   1.246 +  using a
   1.247 +  apply(induct)
   1.248 +  apply(auto simp add: eqvt)
   1.249 +  apply(rule_tac x="pi\<bullet>x" in b_App)
   1.250 +  apply(auto simp add: eqvt fresh_bij fresh_prod)
   1.251 +  done
   1.252 +
   1.253 +lemma big_eqvt':
   1.254 +  fixes pi::"name prm"
   1.255 +  assumes a: "(pi\<bullet>t) \<Down> (pi\<bullet>t')"
   1.256 +  shows "t \<Down> t'"
   1.257 +using a
   1.258 +apply -
   1.259 +apply(drule_tac pi="rev pi" in big_eqvt)
   1.260 +apply(perm_simp)
   1.261 +done
   1.262 +
   1.263  lemma fresh_preserved:
   1.264    fixes x::name
   1.265    fixes t::trm
   1.266 @@ -732,24 +683,20 @@
   1.267      assumes a: "t \<Down> t'"
   1.268      and a1: "\<And>x e c. P c (Lam [x].e) (Lam [x].e)"
   1.269      and a2: "\<And>x e\<^isub>1 e\<^isub>2 e\<^isub>2' e' e\<^isub>1' c. 
   1.270 -             \<lbrakk>x\<sharp>(e\<^isub>1,e\<^isub>2,e',c); e\<^isub>1\<Down>Lam [x].e\<^isub>1'; (\<And>c. P c e\<^isub>1 (Lam [x].e\<^isub>1')); 
   1.271 -             e\<^isub>2\<Down>e\<^isub>2'; (\<And>c. P c e\<^isub>2 e\<^isub>2');  e\<^isub>1'[x::=e\<^isub>2']\<Down>e'; (\<And>c. P c (e\<^isub>1'[x::=e\<^isub>2']) e')\<rbrakk> 
   1.272 +             \<lbrakk>x\<sharp>(e\<^isub>1,e\<^isub>2,e',c); \<And>c. P c e\<^isub>1 (Lam [x].e\<^isub>1'); \<And>c. P c e\<^isub>2 e\<^isub>2'; \<And>c. P c (e\<^isub>1'[x::=e\<^isub>2']) e'\<rbrakk> 
   1.273               \<Longrightarrow> P c (App e\<^isub>1 e\<^isub>2) e'"
   1.274      and a3: "\<And>n c. P c (Const n) (Const n)"
   1.275 -    and a4: "\<And>e\<^isub>1 e\<^isub>1' e\<^isub>2 e\<^isub>2' c.
   1.276 -             \<lbrakk>e\<^isub>1 \<Down> e\<^isub>1'; (\<And>c. P c e\<^isub>1 e\<^isub>1'); e\<^isub>2 \<Down> e\<^isub>2'; (\<And>c. P c e\<^isub>2 e\<^isub>2')\<rbrakk>
   1.277 +    and a4: "\<And>e\<^isub>1 e\<^isub>1' e\<^isub>2 e\<^isub>2' c. \<lbrakk>\<And>c. P c e\<^isub>1 e\<^isub>1'; \<And>c. P c e\<^isub>2 e\<^isub>2'\<rbrakk>
   1.278               \<Longrightarrow> P c (Pr e\<^isub>1 e\<^isub>2) (Pr e\<^isub>1' e\<^isub>2')"
   1.279 -    and a5: "\<And>e e\<^isub>1 e\<^isub>2 c. \<lbrakk>e \<Down> Pr e\<^isub>1 e\<^isub>2; (\<And>c. P c e (Pr e\<^isub>1 e\<^isub>2))\<rbrakk> \<Longrightarrow> P c (Fst e) e\<^isub>1"
   1.280 -    and a6: "\<And>e e\<^isub>1 e\<^isub>2 c. \<lbrakk>e \<Down> Pr e\<^isub>1 e\<^isub>2; (\<And>c. P c e (Pr e\<^isub>1 e\<^isub>2))\<rbrakk> \<Longrightarrow> P c (Snd e) e\<^isub>2"
   1.281 -    and a7: "\<And>e e' c. \<lbrakk>e \<Down> e'; (\<And>c. P c e e')\<rbrakk> \<Longrightarrow> P c (InL e) (InL e')"
   1.282 -    and a8: "\<And>e e' c. \<lbrakk>e \<Down> e'; (\<And>c. P c e e')\<rbrakk> \<Longrightarrow> P c (InR e) (InR e')"
   1.283 +    and a5: "\<And>e e\<^isub>1 e\<^isub>2 c. \<lbrakk>\<And>c. P c e (Pr e\<^isub>1 e\<^isub>2)\<rbrakk> \<Longrightarrow> P c (Fst e) e\<^isub>1"
   1.284 +    and a6: "\<And>e e\<^isub>1 e\<^isub>2 c. \<lbrakk>\<And>c. P c e (Pr e\<^isub>1 e\<^isub>2)\<rbrakk> \<Longrightarrow> P c (Snd e) e\<^isub>2"
   1.285 +    and a7: "\<And>e e' c. \<lbrakk>\<And>c. P c e e'\<rbrakk> \<Longrightarrow> P c (InL e) (InL e')"
   1.286 +    and a8: "\<And>e e' c. \<lbrakk>\<And>c. P c e e'\<rbrakk> \<Longrightarrow> P c (InR e) (InR e')"
   1.287      and a9: "\<And>x\<^isub>1 e e\<^isub>2 e'' x\<^isub>2 e\<^isub>1 e' c.
   1.288 -             \<lbrakk>x\<^isub>1\<sharp>(e,e\<^isub>2,e'',x\<^isub>2,c); x\<^isub>2\<sharp>(e,e\<^isub>1,e'',x\<^isub>1,c);  e \<Down> InL e'; (\<And>c. P c e (InL e')); 
   1.289 -             e\<^isub>1[x\<^isub>1::=e'] \<Down> e''; (\<And>c. P c (e\<^isub>1[x\<^isub>1::=e']) e'')\<rbrakk>
   1.290 +             \<lbrakk>x\<^isub>1\<sharp>(e,e\<^isub>2,e'',x\<^isub>2,c); x\<^isub>2\<sharp>(e,e\<^isub>1,e'',x\<^isub>1,c);  \<And>c. P c e (InL e'); \<And>c. P c (e\<^isub>1[x\<^isub>1::=e']) e''\<rbrakk>
   1.291               \<Longrightarrow> P c (Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2) e''"
   1.292      and a10:"\<And>x\<^isub>1 e e\<^isub>2 e'' x\<^isub>2 e\<^isub>1 e' c.
   1.293 -             \<lbrakk>x\<^isub>1\<sharp>(e,e\<^isub>2,e'',x\<^isub>2,c); x\<^isub>2\<sharp>(e,e\<^isub>1,e'',x\<^isub>1,c); e \<Down> InR e'; (\<And>c. P c e (InR e')); 
   1.294 -             e\<^isub>2[x\<^isub>2::=e'] \<Down> e''; (\<And>c. P c (e\<^isub>2[x\<^isub>2::=e']) e'')\<rbrakk>
   1.295 +             \<lbrakk>x\<^isub>1\<sharp>(e,e\<^isub>2,e'',x\<^isub>2,c); x\<^isub>2\<sharp>(e,e\<^isub>1,e'',x\<^isub>1,c); \<And>c. P c e (InR e'); \<And>c. P c (e\<^isub>2[x\<^isub>2::=e']) e''\<rbrakk>
   1.296               \<Longrightarrow> P c (Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2) e''"
   1.297      shows "P c t t'"
   1.298  proof -
   1.299 @@ -767,16 +714,6 @@
   1.300      have f1: "(pi\<bullet>x)\<sharp>(pi\<bullet>e\<^isub>1,pi\<bullet>e\<^isub>2,pi\<bullet>e')" using f0 by (simp add: fresh_bij)
   1.301      have f2: "y\<sharp>(?pi'\<bullet>e\<^isub>1,?pi'\<bullet>e\<^isub>2,?pi'\<bullet>e')" using f0 
   1.302        by (auto simp add: pt_name2 fresh_left calc_atm perm_pi_simp fresh_prod)
   1.303 -    have p1: "e\<^isub>1 \<Down> Lam [x].e\<^isub>1'" by fact
   1.304 -    then have "(?pi'\<bullet>e\<^isub>1)\<Down>(?pi'\<bullet>Lam [x].e\<^isub>1')" by (simp only: big_eqvt)
   1.305 -    moreover
   1.306 -    have p2: "e\<^isub>2 \<Down> e\<^isub>2'" by fact
   1.307 -    then have "(?pi'\<bullet>e\<^isub>2) \<Down> (?pi'\<bullet>e\<^isub>2')" by (simp only: big_eqvt)
   1.308 -    moreover
   1.309 -    have p3: "e\<^isub>1'[x::=e\<^isub>2'] \<Down> e'" by fact
   1.310 -    then have "(?pi'\<bullet>(e\<^isub>1'[x::=e\<^isub>2'])) \<Down> (?pi'\<bullet>e')" by (simp only: big_eqvt)
   1.311 -    then have "(?pi'\<bullet>e\<^isub>1')[y::=(?pi'\<bullet>e\<^isub>2')] \<Down> (?pi'\<bullet>e')" by (simp add: subst_eqvt calc_atm)
   1.312 -    moreover
   1.313      have ih1: "\<And>c. P c (?pi'\<bullet>e\<^isub>1) (?pi'\<bullet>(Lam [x].e\<^isub>1'))" by fact
   1.314      then have "\<And>c. P c (?pi'\<bullet>e\<^isub>1) (Lam [y].(?pi'\<bullet>e\<^isub>1'))" by (simp add: calc_atm)
   1.315      moreover
   1.316 @@ -799,36 +736,25 @@
   1.317      show "P c (pi\<bullet>(Const n)) (pi\<bullet>(Const n))" using a3 by simp
   1.318    next
   1.319      case (b_Pr e\<^isub>1 e\<^isub>1' e\<^isub>2 e\<^isub>2' pi c)
   1.320 -    then show "P c (pi\<bullet>(Pr e\<^isub>1 e\<^isub>2)) (pi\<bullet>(Pr e\<^isub>1' e\<^isub>2'))" using a4 
   1.321 -      by (simp, blast intro: big_eqvt)
   1.322 +    then show "P c (pi\<bullet>(Pr e\<^isub>1 e\<^isub>2)) (pi\<bullet>(Pr e\<^isub>1' e\<^isub>2'))" using a4 by simp
   1.323    next
   1.324      case (b_Fst e e\<^isub>1 e\<^isub>2 pi c)
   1.325 -    have p1: "e \<Down> Pr e\<^isub>1 e\<^isub>2" by fact
   1.326 -    then have "(pi\<bullet>e)\<Down>(pi\<bullet>(Pr e\<^isub>1 e\<^isub>2))" by (simp only: big_eqvt) 
   1.327 -    moreover
   1.328 -    have ih1: "\<And>c. P c (pi\<bullet>e) (pi\<bullet>(Pr e\<^isub>1 e\<^isub>2))" by fact
   1.329 -    ultimately show "P c (pi\<bullet>(Fst e)) (pi\<bullet>e\<^isub>1)" using a5 by simp
   1.330 +    then show "P c (pi\<bullet>(Fst e)) (pi\<bullet>e\<^isub>1)" using a5 by (simp, blast)
   1.331    next
   1.332      case (b_Snd e e\<^isub>1 e\<^isub>2 pi c)
   1.333 -    have p1: "e \<Down> Pr e\<^isub>1 e\<^isub>2" by fact
   1.334 -    then have "(pi\<bullet>e)\<Down>(pi\<bullet>(Pr e\<^isub>1 e\<^isub>2))" by (simp only: big_eqvt) 
   1.335 -    moreover
   1.336 -    have ih1: "\<And>c. P c (pi\<bullet>e) (pi\<bullet>(Pr e\<^isub>1 e\<^isub>2))" by fact
   1.337 -    ultimately show "P c (pi\<bullet>(Snd e)) (pi\<bullet>e\<^isub>2)" using a6 by simp
   1.338 +    then show "P c (pi\<bullet>(Snd e)) (pi\<bullet>e\<^isub>2)" using a6 by (simp, blast)
   1.339    next
   1.340      case (b_InL e e' pi c)
   1.341 -    then show "P c (pi\<bullet>(InL e)) (pi\<bullet>(InL e'))" using a7
   1.342 -      by (simp, blast intro: big_eqvt)
   1.343 +    then show "P c (pi\<bullet>(InL e)) (pi\<bullet>(InL e'))" using a7 by (simp)
   1.344    next
   1.345      case (b_InR e e' pi c)
   1.346 -    then show "P c (pi\<bullet>(InR e)) (pi\<bullet>(InR e'))" using a8
   1.347 -      by (simp, blast intro: big_eqvt)
   1.348 +    then show "P c (pi\<bullet>(InR e)) (pi\<bullet>(InR e'))" using a8 by (simp)
   1.349    next
   1.350      case (b_CaseL x\<^isub>1 e e\<^isub>2 e'' x\<^isub>2 e\<^isub>1 e' pi c)
   1.351      obtain y\<^isub>1::"name" where fs1: "y\<^isub>1\<sharp>(pi\<bullet>x\<^isub>1,pi\<bullet>e,pi\<bullet>e\<^isub>1,pi\<bullet>e\<^isub>2,pi\<bullet>e'',pi\<bullet>x\<^isub>2,c)"
   1.352 -      by (rule exists_fresh[OF fs_name1])
   1.353 +      by (rule exists_fresh[OF fin_supp])
   1.354      obtain y\<^isub>2::"name" where fs2: "y\<^isub>2\<sharp>(pi\<bullet>x\<^isub>2,pi\<bullet>e,pi\<bullet>e\<^isub>1,pi\<bullet>e\<^isub>2,pi\<bullet>e'',pi\<bullet>x\<^isub>1,c,y\<^isub>1)"
   1.355 -      by (rule exists_fresh[OF fs_name1])
   1.356 +      by (rule exists_fresh[OF fin_supp])
   1.357      let ?sw1 = "[(pi\<bullet>x\<^isub>1,y\<^isub>1)]"
   1.358      let ?sw2 = "[(pi\<bullet>x\<^isub>2,y\<^isub>2)]"
   1.359      let ?pi' = "?sw2@?sw1@pi"
   1.360 @@ -840,14 +766,6 @@
   1.361      have f12: "(pi\<bullet>x\<^isub>2)\<sharp>(pi\<bullet>e,pi\<bullet>e\<^isub>1,pi\<bullet>e'',pi\<bullet>x\<^isub>1)" using f02 by (simp add: fresh_bij)
   1.362      have f22: "y\<^isub>2\<sharp>(?pi'\<bullet>e,?pi'\<bullet>e\<^isub>1,?pi'\<bullet>e'')" using f02 fs1 fs2 
   1.363        by (auto simp add: fresh_atm fresh_prod fresh_left calc_atm pt_name2 perm_pi_simp)
   1.364 -    have p1: "e \<Down> InL e'" by fact
   1.365 -    then have "(?pi'\<bullet>e) \<Down> (?pi'\<bullet>(InL e'))" by (simp only: big_eqvt)
   1.366 -    moreover
   1.367 -    have p2: "e\<^isub>1[x\<^isub>1::=e'] \<Down> e''" by fact
   1.368 -    then have "(?pi'\<bullet>(e\<^isub>1[x\<^isub>1::=e'])) \<Down> (?pi'\<bullet>e'')" by (simp only: big_eqvt)
   1.369 -    then have "(?pi'\<bullet>e\<^isub>1)[y\<^isub>1::=(?pi'\<bullet>e')] \<Down> (?pi'\<bullet>e'')" using fs1 fs2 
   1.370 -      by (auto simp add: calc_atm subst_eqvt fresh_prod fresh_atm del: append_Cons)
   1.371 -    moreover
   1.372      have ih1: "\<And>c. P c (?pi'\<bullet>e) (?pi'\<bullet>(InL e'))" by fact
   1.373      moreover
   1.374      have ih2: "\<And>c. P c (?pi'\<bullet>(e\<^isub>1[x\<^isub>1::=e'])) (?pi'\<bullet>e'')" by fact
   1.375 @@ -874,9 +792,9 @@
   1.376    next
   1.377      case (b_CaseR x\<^isub>1 e e\<^isub>2 e'' x\<^isub>2 e\<^isub>1 e' pi c)
   1.378      obtain y\<^isub>1::"name" where fs1: "y\<^isub>1\<sharp>(pi\<bullet>x\<^isub>1,pi\<bullet>e,pi\<bullet>e\<^isub>1,pi\<bullet>e\<^isub>2,pi\<bullet>e'',pi\<bullet>x\<^isub>2,c)"
   1.379 -      by (rule exists_fresh[OF fs_name1])
   1.380 +      by (rule exists_fresh[OF fin_supp])
   1.381      obtain y\<^isub>2::"name" where fs2: "y\<^isub>2\<sharp>(pi\<bullet>x\<^isub>2,pi\<bullet>e,pi\<bullet>e\<^isub>1,pi\<bullet>e\<^isub>2,pi\<bullet>e'',pi\<bullet>x\<^isub>1,c,y\<^isub>1)"
   1.382 -      by (rule exists_fresh[OF fs_name1])
   1.383 +      by (rule exists_fresh[OF fin_supp])
   1.384      let ?sw1 = "[(pi\<bullet>x\<^isub>1,y\<^isub>1)]"
   1.385      let ?sw2 = "[(pi\<bullet>x\<^isub>2,y\<^isub>2)]"
   1.386      let ?pi' = "?sw2@?sw1@pi"
   1.387 @@ -888,14 +806,6 @@
   1.388      have f12: "(pi\<bullet>x\<^isub>2)\<sharp>(pi\<bullet>e,pi\<bullet>e\<^isub>1,pi\<bullet>e'',pi\<bullet>x\<^isub>1)" using f02 by (simp add: fresh_bij)
   1.389      have f22: "y\<^isub>2\<sharp>(?pi'\<bullet>e,?pi'\<bullet>e\<^isub>1,?pi'\<bullet>e'')" using f02 fs1 fs2 
   1.390        by (auto simp add: fresh_atm fresh_prod fresh_left calc_atm pt_name2 perm_pi_simp)
   1.391 -    have p1: "e \<Down> InR e'" by fact
   1.392 -    then have "(?pi'\<bullet>e) \<Down> (?pi'\<bullet>(InR e'))" by (simp only: big_eqvt)
   1.393 -    moreover
   1.394 -    have p2: "e\<^isub>2[x\<^isub>2::=e'] \<Down> e''" by fact
   1.395 -    then have "(?pi'\<bullet>(e\<^isub>2[x\<^isub>2::=e'])) \<Down> (?pi'\<bullet>e'')" by (simp only: big_eqvt)
   1.396 -    then have "(?pi'\<bullet>e\<^isub>2)[y\<^isub>2::=(?pi'\<bullet>e')] \<Down> (?pi'\<bullet>e'')" using fs1 fs2 f11 f12
   1.397 -      by (auto simp add: calc_atm subst_eqvt fresh_prod fresh_atm del: append_Cons)
   1.398 -    moreover
   1.399      have ih1: "\<And>c. P c (?pi'\<bullet>e) (?pi'\<bullet>(InR e'))" by fact
   1.400      moreover
   1.401      have ih2: "\<And>c. P c (?pi'\<bullet>(e\<^isub>2[x\<^isub>2::=e'])) (?pi'\<bullet>e'')" by fact
   1.402 @@ -937,24 +847,62 @@
   1.403    done
   1.404  
   1.405  lemma  b_CaseL_elim[elim]: 
   1.406 -  assumes "Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 \<Down> e''" and "(\<And> t. \<not>  e \<Down> InR t)"
   1.407 +  assumes "Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 \<Down> e''" 
   1.408 +  and     "\<And> t. \<not>  e \<Down> InR t"
   1.409 +  and     "x\<^isub>1\<sharp>e''" "x\<^isub>1\<sharp>e" "x\<^isub>2\<sharp>e''" "x\<^isub>1\<sharp>e"
   1.410    obtains e' where "e \<Down> InL e'" and "e\<^isub>1[x\<^isub>1::=e'] \<Down> e''"
   1.411    using assms 
   1.412    apply -
   1.413 -  apply (rule b_Case_inv_auto, auto) 
   1.414 -  apply(drule_tac u="e'" in subst_fun_eq)
   1.415 -  apply(simp)
   1.416 -  done
   1.417 +  apply(rule b_Case_inv_auto)
   1.418 +  apply(auto)
   1.419 +  apply(simp add: alpha)
   1.420 +  apply(auto)
   1.421 +  apply(drule_tac x="[(x\<^isub>1,x\<^isub>1')]\<bullet>e'" in meta_spec)
   1.422 +  apply(drule meta_mp)
   1.423 +  apply(rule_tac pi="[(x\<^isub>1,x\<^isub>1')]" in big_eqvt')
   1.424 +  apply(perm_simp add: fresh_prod)
   1.425 +  apply(drule meta_mp)
   1.426 +  apply(rule_tac pi="[(x\<^isub>1,x\<^isub>1')]" in big_eqvt')
   1.427 +  apply(perm_simp add: eqvt calc_atm)
   1.428 +  apply(assumption)
   1.429 +  apply(drule_tac x="[(x\<^isub>1,x\<^isub>1')]\<bullet>e'" in meta_spec)
   1.430 +  apply(drule meta_mp)
   1.431 +  apply(rule_tac pi="[(x\<^isub>1,x\<^isub>1')]" in big_eqvt')
   1.432 +  apply(perm_simp add: fresh_prod)
   1.433 +  apply(drule meta_mp)
   1.434 +  apply(rule_tac pi="[(x\<^isub>1,x\<^isub>1')]" in big_eqvt')
   1.435 +  apply(perm_simp add: eqvt calc_atm)
   1.436 +  apply(assumption)
   1.437 +done
   1.438  
   1.439  lemma b_CaseR_elim[elim]: 
   1.440 -  assumes "Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 \<Down> e''" and "\<And> t. \<not> e \<Down> InL t"
   1.441 +  assumes "Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 \<Down> e''" 
   1.442 +  and     "\<And> t. \<not> e \<Down> InL t"
   1.443 +  and     "x\<^isub>1\<sharp>e''" "x\<^isub>1\<sharp>e" "x\<^isub>2\<sharp>e''" "x\<^isub>2\<sharp>e"
   1.444    obtains e' where "e \<Down> InR e'" and "e\<^isub>2[x\<^isub>2::=e'] \<Down> e''"
   1.445 -  using assms
   1.446 +  using assms 
   1.447    apply -
   1.448 -  apply (rule b_Case_inv_auto, auto)
   1.449 -  apply(drule_tac u="e'" in subst_fun_eq)+
   1.450 -  apply(simp)
   1.451 -  done
   1.452 +  apply(rule b_Case_inv_auto)
   1.453 +  apply(auto)
   1.454 +  apply(simp add: alpha)
   1.455 +  apply(auto)
   1.456 +  apply(drule_tac x="[(x\<^isub>2,x\<^isub>2')]\<bullet>e'" in meta_spec)
   1.457 +  apply(drule meta_mp)
   1.458 +  apply(rule_tac pi="[(x\<^isub>2,x\<^isub>2')]" in big_eqvt')
   1.459 +  apply(perm_simp add: fresh_prod)
   1.460 +  apply(drule meta_mp)
   1.461 +  apply(rule_tac pi="[(x\<^isub>2,x\<^isub>2')]" in big_eqvt')
   1.462 +  apply(perm_simp add: eqvt calc_atm)
   1.463 +  apply(assumption)
   1.464 +  apply(drule_tac x="[(x\<^isub>2,x\<^isub>2')]\<bullet>e'" in meta_spec)
   1.465 +  apply(drule meta_mp)
   1.466 +  apply(rule_tac pi="[(x\<^isub>2,x\<^isub>2')]" in big_eqvt')
   1.467 +  apply(perm_simp add: fresh_prod)
   1.468 +  apply(drule meta_mp)
   1.469 +  apply(rule_tac pi="[(x\<^isub>2,x\<^isub>2')]" in big_eqvt')
   1.470 +  apply(perm_simp add: eqvt calc_atm)
   1.471 +  apply(assumption)
   1.472 +done
   1.473  
   1.474  inductive2
   1.475    val :: "trm\<Rightarrow>bool" 
   1.476 @@ -965,7 +913,6 @@
   1.477  | v_InL[intro]:   "val e \<Longrightarrow> val (InL e)"
   1.478  | v_InR[intro]:   "val e \<Longrightarrow> val (InR e)"
   1.479  
   1.480 -
   1.481  declare trm.inject  [simp add]
   1.482  declare ty.inject  [simp add]
   1.483  declare data.inject [simp add]
   1.484 @@ -986,17 +933,18 @@
   1.485  declare data.inject [simp del]
   1.486  
   1.487  lemma subject_reduction:
   1.488 -  assumes "e \<Down> e'" and "\<Gamma> \<turnstile> e : T"
   1.489 +  assumes a: "e \<Down> e'" 
   1.490 +  and     b: "\<Gamma> \<turnstile> e : T"
   1.491    shows "\<Gamma> \<turnstile> e' : T"
   1.492 -  using assms
   1.493 +  using a b
   1.494  proof (nominal_induct avoiding: \<Gamma> arbitrary: T rule: big_induct_strong) 
   1.495    case (b_App x e\<^isub>1 e\<^isub>2 e\<^isub>2' e' e \<Gamma> T)
   1.496    have vc: "x\<sharp>\<Gamma>" by fact
   1.497    have "\<Gamma> \<turnstile> App e\<^isub>1 e\<^isub>2 : T" by fact
   1.498 - then obtain T' where 
   1.499 +  then obtain T' where 
   1.500      a1: "\<Gamma> \<turnstile> e\<^isub>1 : T'\<rightarrow>T" and  
   1.501      a2: "\<Gamma> \<turnstile> e\<^isub>2 : T'" by auto
   1.502 -  have ih1: "\<Gamma> \<turnstile> e\<^isub>1 : T'\<rightarrow>T \<Longrightarrow> \<Gamma> \<turnstile> Lam [x].e : T'\<rightarrow>T" by fact
   1.503 +  have ih1: "\<Gamma> \<turnstile> e\<^isub>1 : T' \<rightarrow> T \<Longrightarrow> \<Gamma> \<turnstile> Lam [x].e : T' \<rightarrow> T" by fact
   1.504    have ih2: "\<Gamma> \<turnstile> e\<^isub>2 : T' \<Longrightarrow> \<Gamma> \<turnstile> e\<^isub>2' : T'" by fact 
   1.505    have ih3: "\<Gamma> \<turnstile> e[x::=e\<^isub>2'] : T \<Longrightarrow> \<Gamma> \<turnstile> e' : T" by fact
   1.506    have "\<Gamma> \<turnstile> Lam [x].e : T'\<rightarrow>T" using ih1 a1 by simp 
   1.507 @@ -1023,76 +971,57 @@
   1.508   then show "\<Gamma> \<turnstile> e'' : T" by (blast intro: typing_substitution)
   1.509  qed (blast)+
   1.510  
   1.511 -lemma challenge_5: 
   1.512 -  assumes "x\<noteq>y"
   1.513 -  shows "App (App (Lam [x].(Lam [y].Var y)) (Const n\<^isub>1)) (Const n\<^isub>2) \<Down> (Const n\<^isub>2)"
   1.514 -  using assms
   1.515 -  by (auto intro!: big.intros simp add: forget abs_fresh fresh_atm fresh_nat)
   1.516 -
   1.517 -lemma challenge_6:
   1.518 - shows "Fst (App (Lam [x].Pr (Var x) (Var x)) (Const n)) \<Down> Const n"
   1.519 -  by (auto intro!: big.intros) (simp add: fresh_nat abs_fresh)
   1.520 -
   1.521 -lemma challenge_4_unicity:
   1.522 -  assumes "e \<Down> e\<^isub>1" and "e \<Down> e\<^isub>2"
   1.523 +lemma unicity_of_evaluation:
   1.524 +  assumes a: "e \<Down> e\<^isub>1" 
   1.525 +  and     b: "e \<Down> e\<^isub>2"
   1.526    shows "e\<^isub>1 = e\<^isub>2"
   1.527 -  using assms
   1.528 -proof (induct arbitrary: e\<^isub>2)
   1.529 +  using a b
   1.530 +proof (nominal_induct e e\<^isub>1 avoiding: e\<^isub>2 rule: big_induct_strong)
   1.531    case (b_Lam x e t\<^isub>2)
   1.532    have "Lam [x].e \<Down> t\<^isub>2" by fact
   1.533    thus "Lam [x].e = t\<^isub>2" by (cases, simp_all add: trm.inject)
   1.534  next
   1.535 -  case (b_Fst e e\<^isub>1 e\<^isub>2 t\<^isub>2)
   1.536 -  have "Fst e \<Down> t\<^isub>2" by fact
   1.537 -  then obtain e\<^isub>1' e\<^isub>2' where "e \<Down> Pr e\<^isub>1' e\<^isub>2'" and eq: "t\<^isub>2 = e\<^isub>1'" by auto
   1.538 -  then have "Pr e\<^isub>1 e\<^isub>2 = Pr e\<^isub>1' e\<^isub>2'" by auto 
   1.539 -  thus "e\<^isub>1 = t\<^isub>2" using eq by (simp add: trm.inject)
   1.540 -next
   1.541 -  case (b_Snd e e\<^isub>1 e\<^isub>2 t\<^isub>2)
   1.542 -  thus ?case by (force simp add: trm.inject)
   1.543 -next
   1.544 -  case (b_App x e\<^isub>1 e\<^isub>2 e' e\<^isub>1' e\<^isub>2' t\<^isub>2)
   1.545 -  have "e\<^isub>1 \<Down> Lam [x].e\<^isub>1'" by fact
   1.546 +  case (b_App x e\<^isub>1 e\<^isub>2 e\<^isub>2' e' e\<^isub>1' t\<^isub>2)
   1.547    have ih1: "\<And>t. e\<^isub>1 \<Down> t \<Longrightarrow> Lam [x].e\<^isub>1' = t" by fact
   1.548 -  have "e\<^isub>2 \<Down> e\<^isub>2'" by fact
   1.549    have ih2:"\<And>t. e\<^isub>2 \<Down> t \<Longrightarrow> e\<^isub>2' = t" by fact
   1.550 -  have "e\<^isub>1'[x::=e\<^isub>2'] \<Down> e'" by fact
   1.551    have ih3: "\<And>t. e\<^isub>1'[x::=e\<^isub>2'] \<Down> t \<Longrightarrow> e' = t" by fact
   1.552 -  have f:"x\<sharp>(e\<^isub>1,e\<^isub>2,e')" by fact
   1.553 +  have app: "App e\<^isub>1 e\<^isub>2 \<Down> t\<^isub>2" by fact
   1.554 +  have vc: "x\<sharp>e\<^isub>1" "x\<sharp>e\<^isub>2" by fact
   1.555    then have "x \<sharp> App e\<^isub>1 e\<^isub>2" by auto
   1.556 -  moreover
   1.557 -  have app:"App e\<^isub>1 e\<^isub>2 \<Down> t\<^isub>2" by fact
   1.558 -  ultimately have "x\<sharp>t\<^isub>2" using fresh_preserved by blast
   1.559 -  then have "x\<sharp>(e\<^isub>1,e\<^isub>2,t\<^isub>2)" using f by auto 
   1.560 -  then obtain f\<^isub>1'' f\<^isub>2'' where x1:"e\<^isub>1 \<Down> Lam [x]. f\<^isub>1''" and x2:"e\<^isub>2 \<Down> f\<^isub>2''" and x3:"f\<^isub>1''[x::=f\<^isub>2''] \<Down> t\<^isub>2"
   1.561 -    using app by auto
   1.562 -  then have "Lam [x]. f\<^isub>1'' = Lam [x]. e\<^isub>1'" using ih1 by simp
   1.563 -  then have "f\<^isub>1'' = e\<^isub>1'" by (auto simp add: trm.inject alpha) 
   1.564 -  moreover have "f\<^isub>2''=e\<^isub>2'" using x2 ih2 by simp
   1.565 +  then have vc': "x\<sharp>t\<^isub>2" using fresh_preserved app by blast
   1.566 +  from vc vc' obtain f\<^isub>1 f\<^isub>2 where x1: "e\<^isub>1 \<Down> Lam [x]. f\<^isub>1" and x2: "e\<^isub>2 \<Down> f\<^isub>2" and x3: "f\<^isub>1[x::=f\<^isub>2] \<Down> t\<^isub>2"
   1.567 +    using app by (auto simp add: fresh_prod)
   1.568 +  then have "Lam [x]. f\<^isub>1 = Lam [x]. e\<^isub>1'" using ih1 by simp
   1.569 +  then 
   1.570 +  have "f\<^isub>1 = e\<^isub>1'" by (auto simp add: trm.inject alpha) 
   1.571 +  moreover 
   1.572 +  have "f\<^isub>2 = e\<^isub>2'" using x2 ih2 by simp
   1.573    ultimately have "e\<^isub>1'[x::=e\<^isub>2'] \<Down> t\<^isub>2" using x3 by simp
   1.574    thus ?case using ih3 by simp
   1.575  next
   1.576 -  case (b_CaseL  x\<^isub>1 e e\<^isub>2 e'' x\<^isub>2 e\<^isub>1 e' t\<^isub>2) 
   1.577 -  have ih1:"\<And> t. e \<Down> t \<Longrightarrow> InL e' = t" by fact 
   1.578 +  case (b_CaseL  x\<^isub>1 e e\<^isub>2 e'' x\<^isub>2 e\<^isub>1 e' t\<^isub>2)
   1.579 +  have fs: "x\<^isub>1\<sharp>e" "x\<^isub>1\<sharp>t\<^isub>2" "x\<^isub>2\<sharp>e" "x\<^isub>2\<sharp>t\<^isub>2" by fact 
   1.580 +  have ih1:"\<And>t. e \<Down> t \<Longrightarrow> InL e' = t" by fact 
   1.581    have ih2:"\<And>t. e\<^isub>1[x\<^isub>1::=e'] \<Down> t \<Longrightarrow> e'' = t" by fact
   1.582 -  have ha:"\<And> t. (e \<Down> InR t) \<Longrightarrow> False" using ih1 by force
   1.583 +  have ha: "\<not>(\<exists>t. e \<Down> InR t)" using ih1 by force
   1.584    have "Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 \<Down> t\<^isub>2" by fact
   1.585 -  then obtain xe' where "e\<Down>InL xe'" and h:"e\<^isub>1[x\<^isub>1::=xe']\<Down>t\<^isub>2" using ha by auto
   1.586 -  then have "InL xe'=InL e'" using ih1 by simp
   1.587 -  then have "xe'=e'" by (simp add: trm.inject)
   1.588 +  then obtain f' where "e \<Down> InL f'" and h: "e\<^isub>1[x\<^isub>1::=f']\<Down>t\<^isub>2" using ha fs by auto
   1.589 +  then have "InL f' = InL e'" using ih1 by simp
   1.590 +  then have "f' = e'" by (simp add: trm.inject)
   1.591    then have "e\<^isub>1[x\<^isub>1::=e'] \<Down> t\<^isub>2" using h by simp
   1.592 -  then show "e''=t\<^isub>2" using ih2 by simp
   1.593 +  then show "e'' = t\<^isub>2" using ih2 by simp
   1.594  next 
   1.595    case (b_CaseR x\<^isub>1 e e\<^isub>2 e'' x\<^isub>2 e\<^isub>1 e' t\<^isub>2 )
   1.596 -  have ih1:"\<And> t. e \<Down> t \<Longrightarrow> InR e' = t" by fact
   1.597 -  have ih2:"\<And>t. e\<^isub>2[x\<^isub>2::=e'] \<Down> t \<Longrightarrow> e'' = t" by fact
   1.598 -  have a:"\<And> t. (e \<Down> InL t \<Longrightarrow> False)" using ih1 by force
   1.599 +  have fs: "x\<^isub>1\<sharp>e" "x\<^isub>1\<sharp>t\<^isub>2" "x\<^isub>2\<sharp>e" "x\<^isub>2\<sharp>t\<^isub>2" by fact 
   1.600 +  have ih1: "\<And>t. e \<Down> t \<Longrightarrow> InR e' = t" by fact
   1.601 +  have ih2: "\<And>t. e\<^isub>2[x\<^isub>2::=e'] \<Down> t \<Longrightarrow> e'' = t" by fact
   1.602 +  have ha: "\<not>(\<exists>t. e \<Down> InL t)" using ih1 by force
   1.603    have "Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2 \<Down> t\<^isub>2" by fact
   1.604 -  then obtain xe' where "e\<Down>InR xe'" and h:"e\<^isub>2[x\<^isub>2::=xe']\<Down>t\<^isub>2"  using a by auto
   1.605 -  then have "InR xe'=InR e'" using ih1 by simp
   1.606 +  then obtain f' where "e \<Down> InR f'" and h: "e\<^isub>2[x\<^isub>2::=f']\<Down>t\<^isub>2"  using ha fs by auto
   1.607 +  then have "InR f' = InR e'" using ih1 by simp
   1.608    then have "e\<^isub>2[x\<^isub>2::=e'] \<Down> t\<^isub>2" using h by (simp add: trm.inject)
   1.609 -  thus "e''=t\<^isub>2" using ih2 by simp
   1.610 -qed (fast)+
   1.611 +  thus "e'' = t\<^isub>2" using ih2 by simp
   1.612 +qed (force simp add: trm.inject)+
   1.613  
   1.614  lemma not_val_App[simp]:
   1.615    shows 
   1.616 @@ -1103,51 +1032,52 @@
   1.617    "\<not> val (Case e of inl x\<^isub>1 \<rightarrow> e\<^isub>1 | inr x\<^isub>2 \<rightarrow> e\<^isub>2)"
   1.618  by auto
   1.619  
   1.620 -lemma reduces_to_value:
   1.621 +lemma reduces_evaluates_to_values:
   1.622    assumes h:"t \<Down> t'"
   1.623    shows "val t'"
   1.624 -  using h by (induct, auto)
   1.625 +  using h by (induct) (auto)
   1.626  
   1.627 -lemma type_prod_down_pair:
   1.628 -  assumes "\<Gamma> \<turnstile> t : Data (DProd S\<^isub>1 S\<^isub>2)" and "t \<Down> t'"
   1.629 +lemma type_prod_evaluates_to_pairs:
   1.630 +  assumes a: "\<Gamma> \<turnstile> t : Data (DProd S\<^isub>1 S\<^isub>2)" 
   1.631 +  and     b: "t \<Down> t'"
   1.632    obtains t\<^isub>1 t\<^isub>2 where "t' = Pr t\<^isub>1 t\<^isub>2"
   1.633  proof -
   1.634     have "\<Gamma> \<turnstile> t' : Data (DProd S\<^isub>1 S\<^isub>2)" using assms subject_reduction by simp
   1.635     moreover
   1.636 -   have "val t'" using reduces_to_value assms by simp
   1.637 +   have "val t'" using reduces_evaluates_to_values assms by simp
   1.638     ultimately obtain t\<^isub>1 t\<^isub>2 where "t' = Pr t\<^isub>1 t\<^isub>2" by (cases, auto simp add:ty.inject data.inject)
   1.639     thus ?thesis using prems by auto
   1.640  qed
   1.641  
   1.642 -lemma type_sum_down_or:
   1.643 +lemma type_sum_evaluates_to_ins:
   1.644    assumes "\<Gamma> \<turnstile> t : Data (DSum \<sigma>\<^isub>1 \<sigma>\<^isub>2)" and "t \<Down> t'"
   1.645 -  shows "(\<exists> t''. t' = InL t'') \<or> (\<exists> t''. t' = InR t'')"
   1.646 +  shows "(\<exists>t''. t' = InL t'') \<or> (\<exists>t''. t' = InR t'')"
   1.647  proof -
   1.648    have "\<Gamma> \<turnstile> t' : Data (DSum \<sigma>\<^isub>1 \<sigma>\<^isub>2)" using assms subject_reduction by simp
   1.649    moreover
   1.650 -  have "val t'" using reduces_to_value assms by simp
   1.651 +  have "val t'" using reduces_evaluates_to_values assms by simp
   1.652    ultimately obtain t'' where "t' = InL t'' \<or>  t' = InR t''"
   1.653      by (cases, auto simp add:ty.inject data.inject)
   1.654    thus ?thesis by auto
   1.655  qed
   1.656  
   1.657 -lemma type_arrow_down_lam:
   1.658 +lemma type_arrow_evaluates_to_lams:
   1.659    assumes "\<Gamma> \<turnstile> t : \<sigma> \<rightarrow> \<tau>" and "t \<Down> t'"
   1.660    obtains  x t'' where "t' = Lam [x]. t''"
   1.661  proof -
   1.662    have "\<Gamma> \<turnstile> t' : \<sigma> \<rightarrow> \<tau>" using assms subject_reduction by simp
   1.663    moreover
   1.664 -  have "val t'" using reduces_to_value assms by simp
   1.665 +  have "val t'" using reduces_evaluates_to_values assms by simp
   1.666    ultimately obtain x t'' where "t' = Lam [x]. t''" by (cases, auto simp add:ty.inject data.inject)
   1.667    thus ?thesis using prems by auto
   1.668  qed
   1.669  
   1.670 -lemma type_nat_down_const:
   1.671 +lemma type_nat_evaluates_to_consts:
   1.672    assumes "\<Gamma> \<turnstile> t : Data DNat" and "t \<Down> t'"
   1.673    obtains n where "t' = Const n"
   1.674  proof -
   1.675    have "\<Gamma> \<turnstile> t' : Data DNat " using assms subject_reduction by simp
   1.676 -  moreover have "val t'" using reduces_to_value assms by simp
   1.677 +  moreover have "val t'" using reduces_evaluates_to_values assms by simp
   1.678    ultimately obtain n where "t' = Const n" by (cases, auto simp add:ty.inject data.inject)
   1.679    thus ?thesis using prems by auto
   1.680  qed
   1.681 @@ -1170,6 +1100,14 @@
   1.682  by (nominal_induct S arbitrary: e rule:data.induct)
   1.683     (auto)
   1.684  
   1.685 +lemma V'_eqvt:
   1.686 +  fixes pi::"name prm"
   1.687 +  assumes a: "v \<in> V' S"
   1.688 +  shows "(pi\<bullet>v) \<in> V' S"
   1.689 +using a
   1.690 +by (nominal_induct S arbitrary: v rule: data.induct)
   1.691 +   (auto simp add: trm.inject)
   1.692 +
   1.693  consts
   1.694    V :: "ty \<Rightarrow> trm set" 
   1.695  
   1.696 @@ -1179,6 +1117,27 @@
   1.697  apply(rule TrueI)+ 
   1.698  done
   1.699  
   1.700 +lemma V_eqvt:
   1.701 +  fixes pi::"name prm"
   1.702 +  assumes a: "x\<in>V T"
   1.703 +  shows "(pi\<bullet>x)\<in>V T"
   1.704 +using a
   1.705 +apply(nominal_induct T arbitrary: pi x rule: ty.induct)
   1.706 +apply(auto simp add: trm.inject perm_set_def)
   1.707 +apply(perm_simp add: V'_eqvt)
   1.708 +apply(rule_tac x="pi\<bullet>xa" in exI)
   1.709 +apply(rule_tac x="pi\<bullet>e" in exI)
   1.710 +apply(simp)
   1.711 +apply(auto)
   1.712 +apply(drule_tac x="(rev pi)\<bullet>v" in bspec)
   1.713 +apply(force)
   1.714 +apply(auto)
   1.715 +apply(rule_tac x="pi\<bullet>v'" in exI)
   1.716 +apply(auto)
   1.717 +apply(drule_tac pi="pi" in big_eqvt)
   1.718 +apply(perm_simp add: eqvt)
   1.719 +done
   1.720 +
   1.721  lemma V_arrow_elim_weak[elim] :
   1.722    assumes h:"u \<in> (V (T\<^isub>1 \<rightarrow> T\<^isub>2))"
   1.723    obtains a t where "u = Lam[a].t" and "\<forall> v \<in> (V T\<^isub>1). \<exists> v'. t[a::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2"
   1.724 @@ -1186,27 +1145,34 @@
   1.725  
   1.726  lemma V_arrow_elim_strong[elim]:
   1.727    fixes c::"'a::fs_name"
   1.728 -  assumes h: "u \<in> (V (T\<^isub>1 \<rightarrow> T\<^isub>2))"
   1.729 -  obtains a t where "a\<sharp>c" "u = Lam[a].t" "\<forall> v \<in> (V T\<^isub>1). \<exists> v'. t[a::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2"
   1.730 +  assumes h: "u \<in> V (T\<^isub>1 \<rightarrow> T\<^isub>2)"
   1.731 +  obtains a t where "a\<sharp>c" "u = Lam[a].t" "\<forall>v \<in> (V T\<^isub>1). \<exists> v'. t[a::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2"
   1.732  using h
   1.733  apply -
   1.734  apply(erule V_arrow_elim_weak)
   1.735 -apply(subgoal_tac "\<exists>a'::name. a'\<sharp>(a,t,c)")
   1.736 +apply(subgoal_tac "\<exists>a'::name. a'\<sharp>(a,t,c)") (*A*)
   1.737  apply(erule exE)
   1.738  apply(drule_tac x="a'" in meta_spec)
   1.739 +apply(drule_tac x="[(a,a')]\<bullet>t" in meta_spec)
   1.740 +apply(drule meta_mp)
   1.741  apply(simp)
   1.742 -apply(drule_tac x="[(a,a')]\<bullet>t" in meta_spec)
   1.743 -apply(simp add: trm.inject alpha fresh_prod fresh_atm)
   1.744 +apply(drule meta_mp)
   1.745 +apply(simp add: trm.inject alpha fresh_left fresh_prod calc_atm fresh_atm)
   1.746  apply(perm_simp)
   1.747 -apply(simp add: fresh_left calc_atm)
   1.748 +apply(force)
   1.749 +apply(drule meta_mp)
   1.750 +apply(rule ballI)
   1.751 +apply(drule_tac x="[(a,a')]\<bullet>v" in bspec)
   1.752 +apply(simp add: V_eqvt)
   1.753  apply(auto)
   1.754 -apply(simp add: subst_rename)
   1.755 -apply(subgoal_tac "[(a',a)]\<bullet>t = [(a,a')]\<bullet>t")
   1.756 -apply(simp)
   1.757 -apply(rule pt_name3)
   1.758 -apply(rule at_ds5[OF at_name_inst])
   1.759 +apply(rule_tac x="[(a,a')]\<bullet>v'" in exI)
   1.760 +apply(auto)
   1.761 +apply(drule_tac pi="[(a,a')]" in big_eqvt)
   1.762 +apply(perm_simp add: eqvt calc_atm)
   1.763 +apply(simp add: V_eqvt)
   1.764 +(*A*)
   1.765  apply(rule exists_fresh')
   1.766 -apply(simp add: fs_name1)
   1.767 +apply(simp add: fin_supp)
   1.768  done
   1.769  
   1.770  lemma V_are_values :
   1.771 @@ -1306,7 +1272,7 @@
   1.772    then obtain v\<^isub>1 v\<^isub>2 where "\<theta><t\<^isub>1> \<Down> v\<^isub>1 \<and> v\<^isub>1 \<in> V (Data T\<^isub>a)" "\<theta><t\<^isub>2> \<Down> v\<^isub>2 \<and> v\<^isub>2 \<in> V (Data T\<^isub>b)" 
   1.773      using prems by blast
   1.774    thus "\<exists>v. \<theta><Pr t\<^isub>1 t\<^isub>2> \<Down> v \<and> v \<in> V T" using eq by auto
   1.775 -next
   1.776 +next 
   1.777    case (Lam x e \<Gamma> \<theta> T)
   1.778    have ih:"\<And>\<theta> \<Gamma> T. \<lbrakk>\<theta> Vcloses \<Gamma>; \<Gamma> \<turnstile> e : T\<rbrakk> \<Longrightarrow> \<exists>v. \<theta><e> \<Down> v \<and> v \<in> V T" by fact
   1.779    have as\<^isub>1: "\<theta> Vcloses \<Gamma>" by fact
   1.780 @@ -1314,15 +1280,14 @@
   1.781    have fs: "x\<sharp>\<Gamma>" "x\<sharp>\<theta>" by fact
   1.782    from as\<^isub>2 fs obtain T\<^isub>1 T\<^isub>2 
   1.783      where "(i)": "(x,T\<^isub>1)#\<Gamma> \<turnstile> e:T\<^isub>2" and "(ii)": "T = T\<^isub>1 \<rightarrow> T\<^isub>2" by auto
   1.784 -  from "(i)" have "(iii)": "valid ((x,T\<^isub>1)#\<Gamma>)" by (simp add: typing_valid)
   1.785 +  from "(i)" have "(iii)": "valid ((x,T\<^isub>1)#\<Gamma>)" by (simp add: typing_implies_valid)
   1.786    have "\<forall>v \<in> (V T\<^isub>1). \<exists>v'. (\<theta><e>)[x::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2"
   1.787    proof
   1.788      fix v
   1.789      assume "v \<in> (V T\<^isub>1)"
   1.790      with "(iii)" as\<^isub>1 have "(x,v)#\<theta> Vcloses (x,T\<^isub>1)#\<Gamma>" using monotonicity by auto
   1.791      with ih "(i)" obtain v' where "((x,v)#\<theta>)<e> \<Down> v' \<and> v' \<in> V T\<^isub>2" by blast
   1.792 -    then have "\<theta><e>[x::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2" using fs 
   1.793 -      by (simp add: psubst_subst_psubst)
   1.794 +    then have "\<theta><e>[x::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2" using fs by (simp add: psubst_subst_psubst)
   1.795      then show "\<exists>v'. \<theta><e>[x::=v] \<Down> v' \<and> v' \<in> V T\<^isub>2" by auto
   1.796    qed
   1.797    then have "Lam[x].\<theta><e> \<in> V (T\<^isub>1 \<rightarrow> T\<^isub>2)" by auto
   1.798 @@ -1336,21 +1301,20 @@
   1.799    have th:"\<Gamma> \<turnstile> Case t' of inl n\<^isub>1 \<rightarrow> t\<^isub>1 | inr n\<^isub>2 \<rightarrow> t\<^isub>2 : T" by fact
   1.800    then obtain S\<^isub>1 S\<^isub>2 where 
   1.801      hm:"\<Gamma> \<turnstile> t' : Data (DSum S\<^isub>1 S\<^isub>2)" and
   1.802 -    hl:"(n\<^isub>1,Data S\<^isub>1)# \<Gamma> \<turnstile> t\<^isub>1 : T" and
   1.803 -    hr:"(n\<^isub>2,Data S\<^isub>2)# \<Gamma> \<turnstile> t\<^isub>2 : T" using f by auto
   1.804 +    hl:"(n\<^isub>1,Data S\<^isub>1)#\<Gamma> \<turnstile> t\<^isub>1 : T" and
   1.805 +    hr:"(n\<^isub>2,Data S\<^isub>2)#\<Gamma> \<turnstile> t\<^isub>2 : T" using f by auto
   1.806    then obtain v\<^isub>0 where ht':"\<theta><t'> \<Down> v\<^isub>0" and hS:"v\<^isub>0 \<in> V (Data (DSum S\<^isub>1 S\<^isub>2))" using prems h by blast
   1.807    (* We distinguish between the cases InL and InR *)
   1.808 -  { 
   1.809 -    fix v\<^isub>0'
   1.810 +  { fix v\<^isub>0'
   1.811      assume eqc:"v\<^isub>0 = InL v\<^isub>0'" and "v\<^isub>0' \<in> V' S\<^isub>1"
   1.812      then have inc: "v\<^isub>0' \<in> V (Data S\<^isub>1)" by auto
   1.813 -    have "valid \<Gamma>" using th typing_valid by auto
   1.814 +    have "valid \<Gamma>" using th typing_implies_valid by auto
   1.815      then moreover have "valid ((n\<^isub>1,Data S\<^isub>1)#\<Gamma>)" using f by auto
   1.816      then moreover have "(n\<^isub>1,v\<^isub>0')#\<theta> Vcloses (n\<^isub>1,Data S\<^isub>1)#\<Gamma>" 
   1.817        using inc h monotonicity by blast
   1.818 -    moreover have ih:"\<And>\<Gamma> \<theta> T. \<lbrakk>\<theta> Vcloses \<Gamma>; \<Gamma> \<turnstile> t\<^isub>1 : T\<rbrakk> \<Longrightarrow> 
   1.819 -      \<exists>v. \<theta><t\<^isub>1> \<Down> v \<and> v \<in> V T" by fact
   1.820 -    ultimately obtain v\<^isub>1 where ho:"((n\<^isub>1,v\<^isub>0')#\<theta>)<t\<^isub>1> \<Down> v\<^isub>1 \<and> v\<^isub>1 \<in> V T" using hl by blast
   1.821 +    moreover 
   1.822 +    have ih:"\<And>\<Gamma> \<theta> T. \<lbrakk>\<theta> Vcloses \<Gamma>; \<Gamma> \<turnstile> t\<^isub>1 : T\<rbrakk> \<Longrightarrow> \<exists>v. \<theta><t\<^isub>1> \<Down> v \<and> v \<in> V T" by fact
   1.823 +    ultimately obtain v\<^isub>1 where ho: "((n\<^isub>1,v\<^isub>0')#\<theta>)<t\<^isub>1> \<Down> v\<^isub>1 \<and> v\<^isub>1 \<in> V T" using hl by blast
   1.824      then have r:"\<theta><t\<^isub>1>[n\<^isub>1::=v\<^isub>0'] \<Down> v\<^isub>1 \<and> v\<^isub>1 \<in> V T" using psubst_subst_psubst f by simp
   1.825      then moreover have "n\<^isub>1\<sharp>(\<theta><t'>,\<theta><t\<^isub>2>,v\<^isub>1,n\<^isub>2)" 
   1.826        proof -
   1.827 @@ -1375,11 +1339,10 @@
   1.828      ultimately have "\<exists>v. \<theta><Case t' of inl n\<^isub>1 \<rightarrow> t\<^isub>1 | inr n\<^isub>2 \<rightarrow> t\<^isub>2> \<Down> v \<and> v \<in> V T" by auto
   1.829    }
   1.830    moreover 
   1.831 -  {
   1.832 -    fix v\<^isub>0'
   1.833 +  { fix v\<^isub>0'
   1.834      assume eqc:"v\<^isub>0 = InR v\<^isub>0'" and "v\<^isub>0' \<in> V' S\<^isub>2"
   1.835      then have inc:"v\<^isub>0' \<in> V (Data S\<^isub>2)" by auto
   1.836 -    have "valid \<Gamma>" using th typing_valid by auto
   1.837 +    have "valid \<Gamma>" using th typing_implies_valid by auto
   1.838      then moreover have "valid ((n\<^isub>2,Data S\<^isub>2)#\<Gamma>)" using f by auto
   1.839      then moreover have "(n\<^isub>2,v\<^isub>0')#\<theta> Vcloses (n\<^isub>2,Data S\<^isub>2)#\<Gamma>" 
   1.840        using inc h monotonicity by blast
   1.841 @@ -1407,7 +1370,7 @@
   1.842        qed
   1.843      ultimately have "Case \<theta><t'> of inl n\<^isub>1 \<rightarrow> \<theta><t\<^isub>1> | inr n\<^isub>2 \<rightarrow> \<theta><t\<^isub>2> \<Down> v\<^isub>2 \<and> v\<^isub>2 \<in> V T" using ht' eqc by auto
   1.844      then have "\<exists>v. \<theta><Case t' of inl n\<^isub>1 \<rightarrow> t\<^isub>1 | inr n\<^isub>2 \<rightarrow> t\<^isub>2> \<Down> v \<and> v \<in> V T" using f by auto
   1.845 -}
   1.846 +  }
   1.847    ultimately show "\<exists>v. \<theta><Case t' of inl n\<^isub>1 \<rightarrow> t\<^isub>1 | inr n\<^isub>2 \<rightarrow> t\<^isub>2> \<Down> v \<and> v \<in> V T" using hS V_sum by blast
   1.848  qed (force)+
   1.849