src/HOL/Nominal/Examples/Compile.thy
changeset 22418 49e2d9744ae1
parent 22271 51a80e238b29
child 22541 c33b542394f3
equal deleted inserted replaced
22417:014e7696ac6b 22418:49e2d9744ae1
     1 (* $Id$ *)
     1 (* $Id$ *)
     2 
     2 
     3 (* A challenge suggested by Adam Chlipala *)
     3 (* A challenge suggested by Adam Chlipala *)
     4 
     4 
     5 theory Compile
     5 theory Compile
     6 imports "Nominal"
     6 imports "../Nominal"
     7 begin
     7 begin
     8 
     8 
     9 atom_decl name 
     9 atom_decl name 
    10 
    10 
    11 nominal_datatype data = DNat
    11 nominal_datatype data = DNat
    81 | t7[intro]: "\<lbrakk>\<Gamma> I\<turnstile> e1 : DataI(NatI); \<Gamma> I\<turnstile> e2 : DataI(NatI)\<rbrakk> \<Longrightarrow> \<Gamma> I\<turnstile> e1\<mapsto>e2 : DataI(OneI)"
    81 | t7[intro]: "\<lbrakk>\<Gamma> I\<turnstile> e1 : DataI(NatI); \<Gamma> I\<turnstile> e2 : DataI(NatI)\<rbrakk> \<Longrightarrow> \<Gamma> I\<turnstile> e1\<mapsto>e2 : DataI(OneI)"
    82 | t8[intro]: "\<lbrakk>\<Gamma> I\<turnstile> e1 : DataI(NatI); \<Gamma> I\<turnstile> e2 : \<tau>\<rbrakk> \<Longrightarrow> \<Gamma> I\<turnstile> e1;;e2 : \<tau>"
    82 | t8[intro]: "\<lbrakk>\<Gamma> I\<turnstile> e1 : DataI(NatI); \<Gamma> I\<turnstile> e2 : \<tau>\<rbrakk> \<Longrightarrow> \<Gamma> I\<turnstile> e1;;e2 : \<tau>"
    83 | t9[intro]: "\<lbrakk>\<Gamma> I\<turnstile> e: DataI(NatI); \<Gamma> I\<turnstile> e1 : \<tau>; \<Gamma> I\<turnstile> e2 : \<tau>\<rbrakk> \<Longrightarrow> \<Gamma> I\<turnstile> Iif e e1 e2 : \<tau>"
    83 | t9[intro]: "\<lbrakk>\<Gamma> I\<turnstile> e: DataI(NatI); \<Gamma> I\<turnstile> e1 : \<tau>; \<Gamma> I\<turnstile> e2 : \<tau>\<rbrakk> \<Longrightarrow> \<Gamma> I\<turnstile> Iif e e1 e2 : \<tau>"
    84 
    84 
    85 text {* capture-avoiding substitution *}
    85 text {* capture-avoiding substitution *}
    86 
       
    87 lemma perm_if:
       
    88   fixes pi::"'a prm"
       
    89   shows "pi\<bullet>(if b then c1 else c2) = (if (pi\<bullet>b) then (pi\<bullet>c1) else (pi\<bullet>c2))"
       
    90 apply(simp add: perm_fun_def)
       
    91 done
       
    92 
       
    93 lemma eq_eqvt:
       
    94   fixes pi::"name prm"
       
    95   and   x::"'a::pt_name"
       
    96   shows "pi\<bullet>(x=y) = ((pi\<bullet>x)=(pi\<bullet>y))"
       
    97   apply(simp add: perm_bool perm_bij)
       
    98   done
       
    99 
    86 
   100 consts
    87 consts
   101   subst :: "'a \<Rightarrow> name \<Rightarrow> 'a \<Rightarrow> 'a"  ("_[_::=_]" [100,100,100] 100)
    88   subst :: "'a \<Rightarrow> name \<Rightarrow> 'a \<Rightarrow> 'a"  ("_[_::=_]" [100,100,100] 100)
   102 
    89 
   103 nominal_primrec
    90 nominal_primrec
   111   "(InL e)[y::=t'] = InL (e[y::=t'])"
    98   "(InL e)[y::=t'] = InL (e[y::=t'])"
   112   "(InR e)[y::=t'] = InR (e[y::=t'])"
    99   "(InR e)[y::=t'] = InR (e[y::=t'])"
   113   "\<lbrakk>z\<noteq>x; x\<sharp>y; x\<sharp>e; x\<sharp>e2; z\<sharp>y; z\<sharp>e; z\<sharp>e1; x\<sharp>t'; z\<sharp>t'\<rbrakk> \<Longrightarrow>
   100   "\<lbrakk>z\<noteq>x; x\<sharp>y; x\<sharp>e; x\<sharp>e2; z\<sharp>y; z\<sharp>e; z\<sharp>e1; x\<sharp>t'; z\<sharp>t'\<rbrakk> \<Longrightarrow>
   114      (Case e of inl x \<rightarrow> e1 | inr z \<rightarrow> e2)[y::=t'] =
   101      (Case e of inl x \<rightarrow> e1 | inr z \<rightarrow> e2)[y::=t'] =
   115        (Case (e[y::=t']) of inl x \<rightarrow> (e1[y::=t']) | inr z \<rightarrow> (e2[y::=t']))"
   102        (Case (e[y::=t']) of inl x \<rightarrow> (e1[y::=t']) | inr z \<rightarrow> (e2[y::=t']))"
   116   apply (finite_guess add: fs_name1 perm_if eq_eqvt)
   103   apply(finite_guess)+
   117   apply (finite_guess add: fs_name1)
   104   apply(rule TrueI)+
   118   apply (finite_guess add: fs_name1)
   105   apply(simp add: abs_fresh)+
   119   apply (finite_guess add: fs_name1)
   106   apply(fresh_guess)+
   120   apply (finite_guess add: fs_name1)
       
   121   apply (finite_guess add: fs_name1)
       
   122   apply (finite_guess add: fs_name1)
       
   123   apply (finite_guess add: fs_name1)
       
   124   apply (finite_guess add: fs_name1)
       
   125   apply (finite_guess only: fs_name1)
       
   126   apply perm_simp
       
   127   apply (simp add: supp_unit)
       
   128   apply (rule TrueI)+
       
   129   apply (simp add: abs_fresh)
       
   130   apply (simp_all add: abs_fresh)
       
   131   apply (fresh_guess add: fs_name1 perm_if eq_eqvt)
       
   132   apply (fresh_guess add: fs_name1)
       
   133   apply (fresh_guess add: fs_name1)
       
   134   apply (fresh_guess add: fs_name1)
       
   135   apply (fresh_guess add: fs_name1)
       
   136   apply (fresh_guess add: fs_name1)
       
   137   apply (fresh_guess add: fs_name1)
       
   138   apply (fresh_guess add: fs_name1)
       
   139   apply (fresh_guess add: fs_name1)
       
   140   apply (fresh_guess only: fs_name1)
       
   141   apply perm_simp
       
   142   apply (fresh_guess add: fs_name1 perm_if eq_eqvt)
       
   143   apply (fresh_guess add: fs_name1 perm_if eq_eqvt)
       
   144   apply (fresh_guess add: fs_name1)
       
   145   apply (fresh_guess add: fs_name1)
       
   146   apply (fresh_guess add: fs_name1)
       
   147   apply (fresh_guess add: fs_name1)
       
   148   apply (fresh_guess add: fs_name1)
       
   149   apply (fresh_guess add: fs_name1)
       
   150   apply (fresh_guess add: fs_name1)
       
   151   apply (fresh_guess add: fs_name1)
       
   152   apply (fresh_guess add: fs_name1)
       
   153   apply (fresh_guess add: fs_name1)
       
   154   apply (fresh_guess add: fs_name1)
       
   155   apply (fresh_guess add: fs_name1)
       
   156   apply (fresh_guess add: fs_name1)
       
   157   apply (fresh_guess add: fs_name1)
       
   158   apply (fresh_guess add: fs_name1)
       
   159   apply (fresh_guess add: fs_name1)
       
   160   apply (fresh_guess only: fs_name1)
       
   161   apply perm_simp
       
   162   apply (fresh_guess only: fs_name1)
       
   163   apply perm_simp
       
   164   done
   107   done
   165 
   108 
   166 nominal_primrec (Isubst)
   109 nominal_primrec (Isubst)
   167   "(IVar x)[y::=t'] = (if x=y then t' else (IVar x))"
   110   "(IVar x)[y::=t'] = (if x=y then t' else (IVar x))"
   168   "(IApp t1 t2)[y::=t'] = IApp (t1[y::=t']) (t2[y::=t'])"
   111   "(IApp t1 t2)[y::=t'] = IApp (t1[y::=t']) (t2[y::=t'])"
   172   "(ISucc e)[y::=t'] = ISucc (e[y::=t'])"
   115   "(ISucc e)[y::=t'] = ISucc (e[y::=t'])"
   173   "(IAss e1 e2)[y::=t'] = IAss (e1[y::=t']) (e2[y::=t'])"
   116   "(IAss e1 e2)[y::=t'] = IAss (e1[y::=t']) (e2[y::=t'])"
   174   "(IRef e)[y::=t'] = IRef (e[y::=t'])"
   117   "(IRef e)[y::=t'] = IRef (e[y::=t'])"
   175   "(ISeq e1 e2)[y::=t'] = ISeq (e1[y::=t']) (e2[y::=t'])"
   118   "(ISeq e1 e2)[y::=t'] = ISeq (e1[y::=t']) (e2[y::=t'])"
   176   "(Iif e e1 e2)[y::=t'] = Iif (e[y::=t']) (e1[y::=t']) (e2[y::=t'])"
   119   "(Iif e e1 e2)[y::=t'] = Iif (e[y::=t']) (e1[y::=t']) (e2[y::=t'])"
   177   apply (finite_guess add: fs_name1 perm_if eq_eqvt)
   120   apply(finite_guess)+
   178   apply (finite_guess add: fs_name1)
   121   apply(rule TrueI)+
   179   apply (finite_guess add: fs_name1)
   122   apply(simp add: abs_fresh)+
   180   apply (finite_guess add: fs_name1)
   123   apply(fresh_guess)+
   181   apply (finite_guess add: fs_name1)
   124   done
   182   apply (finite_guess add: fs_name1)
   125 
   183   apply (finite_guess add: fs_name1)
   126 lemma Isubst_eqvt[eqvt]:
   184   apply (finite_guess add: fs_name1)
       
   185   apply (finite_guess add: fs_name1)
       
   186   apply (finite_guess only: fs_name1)
       
   187   apply perm_simp
       
   188   apply (simp add: supp_unit)
       
   189   apply (rule TrueI)+
       
   190   apply (simp add: abs_fresh)
       
   191   apply (fresh_guess add: fs_name1 perm_if eq_eqvt)
       
   192   apply (fresh_guess add: fs_name1)
       
   193   apply (fresh_guess add: fs_name1)
       
   194   apply (fresh_guess add: fs_name1)
       
   195   apply (fresh_guess add: fs_name1)
       
   196   apply (fresh_guess add: fs_name1)
       
   197   apply (fresh_guess add: fs_name1)
       
   198   apply (fresh_guess add: fs_name1)
       
   199   apply (fresh_guess add: fs_name1)
       
   200   apply (fresh_guess only: fs_name1)
       
   201   apply perm_simp
       
   202   done
       
   203 
       
   204 lemma Isubst_eqvt:
       
   205   fixes pi::"name prm"
   127   fixes pi::"name prm"
   206   and   t1::"trmI"
   128   and   t1::"trmI"
   207   and   t2::"trmI"
   129   and   t2::"trmI"
   208   and   x::"name"
   130   and   x::"name"
   209   shows "pi\<bullet>(t1[x::=t2]) = ((pi\<bullet>t1)[(pi\<bullet>x)::=(pi\<bullet>t2)])"
   131   shows "pi\<bullet>(t1[x::=t2]) = ((pi\<bullet>t1)[(pi\<bullet>x)::=(pi\<bullet>t2)])"
   210   apply (nominal_induct t1 avoiding: x t2 rule: trmI.induct)
   132   apply (nominal_induct t1 avoiding: x t2 rule: trmI.induct)
   211   apply (simp_all add: Isubst.simps perm_if eq_eqvt fresh_bij)
   133   apply (simp_all add: Isubst.simps eqvt fresh_bij)
   212   done
   134   done
   213 
   135 
   214 lemma Isubst_supp:
   136 lemma Isubst_supp:
   215   fixes t1::"trmI"
   137   fixes t1::"trmI"
   216   and   t2::"trmI"
   138   and   t2::"trmI"
   292    trans (Case e of inl x1 \<rightarrow> e1 | inr x2 \<rightarrow> e2) =
   214    trans (Case e of inl x1 \<rightarrow> e1 | inr x2 \<rightarrow> e2) =
   293        (let v = (trans e) in
   215        (let v = (trans e) in
   294         let v1 = (trans e1) in
   216         let v1 = (trans e1) in
   295         let v2 = (trans e2) in 
   217         let v2 = (trans e2) in 
   296         Iif (IRef (ISucc v)) (v2[x2::=IRef (ISucc (ISucc v))]) (v1[x1::=IRef (ISucc (ISucc v))]))"
   218         Iif (IRef (ISucc v)) (v2[x2::=IRef (ISucc (ISucc v))]) (v1[x1::=IRef (ISucc (ISucc v))]))"
   297   apply (finite_guess add: fs_name1)
   219   apply(finite_guess add: Let_def)+
   298   apply (finite_guess add: fs_name1)
   220   apply(rule TrueI)+
   299   apply (finite_guess add: fs_name1)
   221   apply(simp add: abs_fresh Isubst_fresh)+
   300   apply (finite_guess add: fs_name1)
   222   apply(fresh_guess add: Let_def)+
   301   apply (finite_guess add: fs_name1 Let_def perm_nat_def)
       
   302   apply (finite_guess add: fs_name1)
       
   303   apply (finite_guess add: fs_name1)
       
   304   apply (finite_guess add: fs_name1 Let_def perm_nat_def)
       
   305   apply (finite_guess add: fs_name1 Let_def perm_nat_def)
       
   306   apply (finite_guess add: fs_name1 Let_def Isubst_eqvt)
       
   307   apply (simp add: supp_unit)
       
   308   apply (rule TrueI)+
       
   309   apply (simp add: abs_fresh)
       
   310   apply (simp_all add: abs_fresh Isubst_fresh)
       
   311   apply (fresh_guess add: fs_name1 perm_if eq_eqvt)
       
   312   apply (fresh_guess add: fs_name1)
       
   313   apply (fresh_guess add: fs_name1)
       
   314   apply (fresh_guess add: fs_name1)
       
   315   apply (fresh_guess add: fs_name1 Let_def perm_nat_def)
       
   316   apply (fresh_guess add: fs_name1)
       
   317   apply (fresh_guess add: fs_name1)
       
   318   apply (fresh_guess add: fs_name1 Let_def perm_nat_def)
       
   319   apply (fresh_guess add: fs_name1 Let_def perm_nat_def)
       
   320   apply (fresh_guess add: fs_name1 Let_def Isubst_eqvt)
       
   321   apply (fresh_guess add: fs_name1 perm_if eq_eqvt)
       
   322   apply (fresh_guess add: fs_name1 perm_if eq_eqvt)
       
   323   apply (fresh_guess add: fs_name1)
       
   324   apply (fresh_guess add: fs_name1)
       
   325   apply (fresh_guess add: fs_name1)
       
   326   apply (fresh_guess add: fs_name1)
       
   327   apply (fresh_guess add: fs_name1)
       
   328   apply (fresh_guess add: fs_name1)
       
   329   apply (fresh_guess add: fs_name1 Let_def perm_nat_def)
       
   330   apply (fresh_guess add: fs_name1 Let_def perm_nat_def)
       
   331   apply (fresh_guess add: fs_name1)
       
   332   apply (fresh_guess add: fs_name1)
       
   333   apply (fresh_guess add: fs_name1)
       
   334   apply (fresh_guess add: fs_name1)
       
   335   apply (fresh_guess add: fs_name1 Let_def perm_nat_def)
       
   336   apply (fresh_guess add: fs_name1 Let_def perm_nat_def)
       
   337   apply (fresh_guess add: fs_name1 Let_def perm_nat_def)
       
   338   apply (fresh_guess add: fs_name1 Let_def perm_nat_def)
       
   339   apply (fresh_guess add: fs_name1 Let_def Isubst_eqvt)
       
   340   apply (fresh_guess add: fs_name1 Let_def Isubst_eqvt)
       
   341   done
   223   done
   342 
   224 
   343 consts trans_type :: "ty \<Rightarrow> tyI"
   225 consts trans_type :: "ty \<Rightarrow> tyI"
   344 
   226 
   345 nominal_primrec
   227 nominal_primrec