src/HOL/Nominal/Examples/Crary.thy
changeset 29097 68245155eb58
parent 28042 1471f2974eb1
child 32638 d9bd7e01a681
equal deleted inserted replaced
29088:95a239a5e055 29097:68245155eb58
     1 (* "$Id$" *)
       
     2 (*                                                    *)
     1 (*                                                    *)
     3 (* Formalisation of the chapter on Logical Relations  *)
     2 (* Formalisation of the chapter on Logical Relations  *)
     4 (* and a Case Study in Equivalence Checking           *)
     3 (* and a Case Study in Equivalence Checking           *)
     5 (* by Karl Crary from the book on Advanced Topics in  *)
     4 (* by Karl Crary from the book on Advanced Topics in  *)
     6 (* Types and Programming Languages, MIT Press 2005    *)
     5 (* Types and Programming Languages, MIT Press 2005    *)
    45 lemma ty_cases:
    44 lemma ty_cases:
    46   fixes T::ty
    45   fixes T::ty
    47   shows "(\<exists> T\<^isub>1 T\<^isub>2. T=T\<^isub>1\<rightarrow>T\<^isub>2) \<or> T=TUnit \<or> T=TBase"
    46   shows "(\<exists> T\<^isub>1 T\<^isub>2. T=T\<^isub>1\<rightarrow>T\<^isub>2) \<or> T=TUnit \<or> T=TBase"
    48 by (induct T rule:ty.induct) (auto)
    47 by (induct T rule:ty.induct) (auto)
    49 
    48 
    50 instance ty :: size ..
    49 instantiation ty :: size
    51 
    50 begin
    52 nominal_primrec
    51 
       
    52 nominal_primrec size_ty
       
    53 where
    53   "size (TBase) = 1"
    54   "size (TBase) = 1"
    54   "size (TUnit) = 1"
    55 | "size (TUnit) = 1"
    55   "size (T\<^isub>1\<rightarrow>T\<^isub>2) = size T\<^isub>1 + size T\<^isub>2"
    56 | "size (T\<^isub>1\<rightarrow>T\<^isub>2) = size T\<^isub>1 + size T\<^isub>2"
    56 by (rule TrueI)+
    57 by (rule TrueI)+
       
    58 
       
    59 instance ..
       
    60 
       
    61 end
    57 
    62 
    58 lemma ty_size_greater_zero[simp]:
    63 lemma ty_size_greater_zero[simp]:
    59   fixes T::"ty"
    64   fixes T::"ty"
    60   shows "size T > 0"
    65   shows "size T > 0"
    61 by (nominal_induct rule: ty.strong_induct) (simp_all)
    66 by (nominal_induct rule: ty.strong_induct) (simp_all)
    85   assumes a: "z\<sharp>\<theta>"
    90   assumes a: "z\<sharp>\<theta>"
    86   shows "lookup \<theta> z = Var z"
    91   shows "lookup \<theta> z = Var z"
    87 using a
    92 using a
    88 by (induct rule: lookup.induct)
    93 by (induct rule: lookup.induct)
    89    (auto simp add: fresh_list_cons fresh_prod fresh_atm)
    94    (auto simp add: fresh_list_cons fresh_prod fresh_atm)
    90 
       
    91 consts
       
    92   psubst :: "Subst \<Rightarrow> trm \<Rightarrow> trm"  ("_<_>" [100,100] 130)
       
    93  
    95  
    94 nominal_primrec
    96 nominal_primrec
       
    97   psubst :: "Subst \<Rightarrow> trm \<Rightarrow> trm"  ("_<_>" [100,100] 130)
       
    98 where
    95   "\<theta><(Var x)> = (lookup \<theta> x)"
    99   "\<theta><(Var x)> = (lookup \<theta> x)"
    96   "\<theta><(App t\<^isub>1 t\<^isub>2)> = App \<theta><t\<^isub>1> \<theta><t\<^isub>2>"
   100 | "\<theta><(App t\<^isub>1 t\<^isub>2)> = App \<theta><t\<^isub>1> \<theta><t\<^isub>2>"
    97   "x\<sharp>\<theta> \<Longrightarrow> \<theta><(Lam [x].t)> = Lam [x].(\<theta><t>)"
   101 | "x\<sharp>\<theta> \<Longrightarrow> \<theta><(Lam [x].t)> = Lam [x].(\<theta><t>)"
    98   "\<theta><(Const n)> = Const n"
   102 | "\<theta><(Const n)> = Const n"
    99   "\<theta><(Unit)> = Unit"
   103 | "\<theta><(Unit)> = Unit"
   100 apply(finite_guess)+
   104 apply(finite_guess)+
   101 apply(rule TrueI)+
   105 apply(rule TrueI)+
   102 apply(simp add: abs_fresh)+
   106 apply(simp add: abs_fresh)+
   103 apply(fresh_guess)+
   107 apply(fresh_guess)+
   104 done
   108 done