src/HOL/Nominal/Examples/Crary.thy
author urbanc
Wed, 17 Jan 2007 19:29:55 +0100
changeset 22082 b1be13d32efd
parent 22073 c170dcbe6c9d
child 22231 f76f187c91f9
permissions -rw-r--r--
tuned a bit the proofs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
     1
(* "$Id$" *)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
     2
(*                                                    *)
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
     3
(* Formalisation of the chapter on Logical Relations  *)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
     4
(* and a Case Study in Equivalence Checking           *)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
     5
(* by Karl Crary from the book on Advanced Topics in  *)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
     6
(* Types and Programming Languages, MIT Press 2005    *)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
     7
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
     8
(* The formalisation was done by Julien Narboux and   *)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
     9
(* Christian Urban                                    *)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    10
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    11
theory Crary
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    12
  imports "Nominal"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    13
begin
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    14
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    15
atom_decl name 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    16
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    17
nominal_datatype ty = TBase 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    18
                    | TUnit 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    19
                    | Arrow "ty" "ty" ("_\<rightarrow>_" [100,100] 100)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    20
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    21
nominal_datatype trm = Unit
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    22
                     | Var "name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    23
                     | Lam "\<guillemotleft>name\<guillemotright>trm" ("Lam [_]._" [100,100] 100)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    24
                     | App "trm" "trm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    25
                     | Const "nat"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    26
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
    27
(* The next 3 lemmas should be in the nominal library *)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    28
lemma eq_eqvt:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    29
  fixes pi::"name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    30
  and   x::"'a::pt_name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    31
  shows "pi\<bullet>(x=y) = (pi\<bullet>x=pi\<bullet>y)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    32
  apply(simp add: perm_bool perm_bij)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    33
  done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    34
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    35
lemma in_eqvt:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    36
  fixes pi::"name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    37
  and   x::"'a::pt_name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    38
  assumes "x\<in>X"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    39
  shows "pi\<bullet>x \<in> pi\<bullet>X"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    40
  using assms by (perm_simp add: pt_set_bij1a[OF pt_name_inst, OF at_name_inst])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    41
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    42
lemma set_eqvt:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    43
  fixes pi::"name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    44
  and   xs::"('a::pt_name) list"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    45
  shows "pi\<bullet>(set xs) = set (pi\<bullet>xs)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    46
  by (perm_simp add: pt_list_set_pi[OF pt_name_inst])
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
    47
(* end of library *)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    48
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    49
lemma perm_ty[simp]: 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    50
  fixes T::"ty"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    51
  and   pi::"name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    52
  shows "pi\<bullet>T = T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    53
  by (induct T rule: ty.induct_weak) (simp_all)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    54
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    55
lemma fresh_ty[simp]:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    56
  fixes x::"name" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    57
  and   T::"ty"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    58
  shows "x\<sharp>T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    59
  by (simp add: fresh_def supp_def)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    60
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    61
lemma ty_cases:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    62
  fixes T::ty
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    63
  shows "(\<exists> T1 T2. T=T1\<rightarrow>T2) \<or> T=TUnit \<or> T=TBase"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
    64
by (induct T rule:ty.induct_weak) (auto)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    65
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    66
text {* Size Functions *} 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    67
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    68
instance ty :: size ..
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    69
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    70
nominal_primrec
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    71
  "size (TBase) = 1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    72
  "size (TUnit) = 1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    73
  "size (T1\<rightarrow>T2) = size T1 + size T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    74
by (rule TrueI)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    75
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    76
instance trm :: size ..
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    77
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    78
nominal_primrec 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    79
  "size (Unit) = 1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    80
  "size (Var x) = 1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    81
  "size (Lam [x].t) = size t + 1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    82
  "size (App t1 t2) = size t1 + size t2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    83
  "size (Const n) = 1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    84
apply(finite_guess add: fs_name1 perm_nat_def)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    85
apply(perm_full_simp add: perm_nat_def)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    86
apply(simp add: fs_name1)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    87
apply(rule TrueI)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    88
apply(simp add: fresh_nat)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    89
apply(fresh_guess add: fs_name1 perm_nat_def)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    90
done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    91
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    92
lemma ty_size_greater_zero[simp]:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    93
  fixes T::"ty"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    94
  shows "size T > 0"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    95
by (nominal_induct rule:ty.induct) (simp_all)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    96
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    97
text {* valid contexts *}
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    98
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    99
inductive2
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   100
  valid :: "(name \<times> 'a::pt_name) list \<Rightarrow> bool"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   101
where
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   102
    v_nil[intro]:  "valid []"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   103
  | v_cons[intro]: "\<lbrakk>valid \<Gamma>;a\<sharp>\<Gamma>\<rbrakk> \<Longrightarrow> valid ((a,\<sigma>)#\<Gamma>)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   104
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   105
lemma valid_eqvt:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   106
  fixes   pi:: "name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   107
  assumes a: "valid \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   108
  shows "valid (pi\<bullet>\<Gamma>)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   109
  using a
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   110
  by (induct) (auto simp add: fresh_bij)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   111
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   112
inductive_cases2  
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   113
  valid_cons_elim_auto[elim]:"valid ((x,T)#\<Gamma>)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   114
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   115
text {* typing judgements for terms *}
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   116
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   117
inductive2
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   118
  typing :: "(name\<times>ty) list\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" (" _ \<turnstile> _ : _ " [60,60,60] 60) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   119
where
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   120
  t_Var[intro]:   "\<lbrakk>valid \<Gamma>; (x,T)\<in>set \<Gamma>\<rbrakk>\<Longrightarrow> \<Gamma> \<turnstile> Var x : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   121
| t_App[intro]:   "\<lbrakk>\<Gamma> \<turnstile> e1 : T1\<rightarrow>T2; \<Gamma> \<turnstile> e2 : T1\<rbrakk>\<Longrightarrow> \<Gamma> \<turnstile> App e1 e2 : T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   122
| t_Lam[intro]:   "\<lbrakk>x\<sharp>\<Gamma>; (x,T1)#\<Gamma> \<turnstile> t : T2\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Lam [x].t : T1\<rightarrow>T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   123
| t_Const[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> Const n : TBase"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   124
| t_Unit[intro]:  "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> Unit : TUnit"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   125
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   126
lemma typing_valid:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   127
  assumes "\<Gamma> \<turnstile> t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   128
  shows "valid \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   129
  using assms
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   130
  by (induct) (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   131
 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   132
lemma typing_eqvt :
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   133
  fixes pi::"name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   134
  assumes "\<Gamma> \<turnstile> t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   135
  shows "(pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>t) : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   136
  using assms
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   137
  apply(induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   138
  apply(auto simp add: fresh_bij set_eqvt valid_eqvt) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   139
  apply(rule t_Var)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   140
  apply(drule valid_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   141
  apply(assumption)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   142
  apply(drule in_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   143
  apply(simp add: set_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   144
  done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   145
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   146
text {* Inversion lemmas for the typing judgment *}
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   147
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   148
declare trm.inject [simp add]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   149
declare ty.inject  [simp add]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   150
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   151
inductive_cases2 t_Lam_elim_auto[elim]: "\<Gamma> \<turnstile> Lam [x].t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   152
inductive_cases2 t_Var_elim_auto[elim]: "\<Gamma> \<turnstile> Var x : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   153
inductive_cases2 t_App_elim_auto[elim]: "\<Gamma> \<turnstile> App x y : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   154
inductive_cases2  t_Const_elim_auto[elim]: "\<Gamma> \<turnstile> Const n : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   155
inductive_cases2  t_Unit_elim_auto[elim]: "\<Gamma> \<turnstile> Unit : TUnit"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   156
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   157
declare trm.inject [simp del]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   158
declare ty.inject [simp del]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   159
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   160
lemma typing_induct_strong
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   161
  [consumes 1, case_names t_Var t_App t_Lam t_Const t_Unit]:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   162
    fixes  P::"'a::fs_name \<Rightarrow> (name\<times>ty) list \<Rightarrow> trm \<Rightarrow> ty \<Rightarrow>bool"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   163
    and    x :: "'a::fs_name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   164
    assumes a: "\<Gamma> \<turnstile> e : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   165
    and a1: "\<And>\<Gamma> x T c. \<lbrakk>valid \<Gamma>; (x,T)\<in>set \<Gamma>\<rbrakk> \<Longrightarrow> P c \<Gamma> (Var x) T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   166
    and a2: "\<And>\<Gamma> e1 T1 T2 e2 c. 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   167
             \<lbrakk>\<Gamma> \<turnstile> e1 : T1\<rightarrow>T2 ; \<And>c. P c \<Gamma> e1 (T1\<rightarrow>T2); \<Gamma> \<turnstile> e2 : T1 ; \<And>c. P c \<Gamma> e2 T1\<rbrakk> 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   168
             \<Longrightarrow> P c \<Gamma> (App e1 e2) T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   169
    and a3: "\<And>x \<Gamma> T1 t T2 c.
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   170
             \<lbrakk>x\<sharp>(\<Gamma>,c); (x,T1)#\<Gamma> \<turnstile> t : T2 ; \<And>c. P c ((x,T1)#\<Gamma>) t T2\<rbrakk>
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   171
             \<Longrightarrow> P c \<Gamma> (Lam [x].t) (T1\<rightarrow>T2)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   172
    and a4: "\<And>\<Gamma> n c. valid \<Gamma> \<Longrightarrow> P c \<Gamma> (Const n) TBase"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   173
    and a5: "\<And>\<Gamma> c. valid \<Gamma> \<Longrightarrow> P c \<Gamma> Unit TUnit"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   174
    shows "P c \<Gamma> e T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   175
proof -
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   176
  from a have "\<And>(pi::name prm) c. P c (pi\<bullet>\<Gamma>) (pi\<bullet>e) T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   177
  proof (induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   178
    case (t_Var \<Gamma> x T pi c)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   179
    have "valid \<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   180
    then have "valid (pi\<bullet>\<Gamma>)" by (simp only: valid_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   181
    moreover
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   182
    have "(x,T)\<in>set \<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   183
    then have "pi\<bullet>(x,T)\<in>pi\<bullet>(set \<Gamma>)" by (simp only: pt_set_bij[OF pt_name_inst, OF at_name_inst])  
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   184
    then have "(pi\<bullet>x,T)\<in>set (pi\<bullet>\<Gamma>)" by (simp add: set_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   185
    ultimately show "P c (pi\<bullet>\<Gamma>) (pi\<bullet>(Var x)) T" using a1 by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   186
  next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   187
    case (t_App \<Gamma> e1 T1 T2 e2 pi c)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   188
    thus "P c (pi\<bullet>\<Gamma>) (pi\<bullet>(App e1 e2)) T2" using a2 by (simp, blast intro: typing_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   189
  next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   190
    case (t_Lam x \<Gamma> T1 t T2 pi c)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   191
    obtain y::"name" where fs: "y\<sharp>(pi\<bullet>x,pi\<bullet>\<Gamma>,pi\<bullet>t,c)" by (erule exists_fresh[OF fs_name1])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   192
    let ?sw = "[(pi\<bullet>x,y)]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   193
    let ?pi' = "?sw@pi"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   194
    have f0: "x\<sharp>\<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   195
    have f1: "(pi\<bullet>x)\<sharp>(pi\<bullet>\<Gamma>)" using f0 by (simp add: fresh_bij)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   196
    have f2: "y\<sharp>?pi'\<bullet>\<Gamma>" by (auto simp add: pt_name2 fresh_left calc_atm perm_pi_simp)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   197
    have pr1: "(x,T1)#\<Gamma> \<turnstile> t : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   198
    then have "(?pi'\<bullet>((x,T1)#\<Gamma>)) \<turnstile> (?pi'\<bullet>t) : T2" by (simp only: typing_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   199
    moreover
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   200
    have ih1: "\<And>c. P c (?pi'\<bullet>((x,T1)#\<Gamma>)) (?pi'\<bullet>t) T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   201
    ultimately have "P c (?pi'\<bullet>\<Gamma>) (Lam [y].(?pi'\<bullet>t)) (T1\<rightarrow>T2)" using fs f2 a3
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   202
      by (simp add: calc_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   203
    then have "P c (?sw\<bullet>pi\<bullet>\<Gamma>) (?sw\<bullet>(Lam [(pi\<bullet>x)].(pi\<bullet>t))) (T1\<rightarrow>T2)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   204
      by (simp del: append_Cons add: calc_atm pt_name2)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   205
    moreover have "(?sw\<bullet>pi\<bullet>\<Gamma>) = (pi\<bullet>\<Gamma>)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   206
      by (rule perm_fresh_fresh) (simp_all add: fs f1)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   207
    moreover have "(?sw\<bullet>(Lam [(pi\<bullet>x)].(pi\<bullet>t))) = Lam [(pi\<bullet>x)].(pi\<bullet>t)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   208
      by (rule perm_fresh_fresh) (simp_all add: fs f1 fresh_atm abs_fresh)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   209
    ultimately show "P c (pi\<bullet>\<Gamma>) (pi\<bullet>(Lam [x].t)) (T1\<rightarrow>T2)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   210
      by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   211
  next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   212
    case (t_Const \<Gamma> n pi c)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   213
    thus "P c (pi\<bullet>\<Gamma>) (pi\<bullet>(Const n)) (TBase)" using a4 by (simp, blast intro: valid_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   214
  next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   215
    case (t_Unit \<Gamma> pi c)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   216
    thus "P c (pi\<bullet>\<Gamma>) (pi\<bullet>Unit) (TUnit)" using a5 by (simp, blast intro: valid_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   217
  qed 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   218
  then have "P c (([]::name prm)\<bullet>\<Gamma>) (([]::name prm)\<bullet>e) T" by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   219
  then show "P c \<Gamma> e T" by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   220
qed 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   221
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   222
text {* capture-avoiding substitution *}
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   223
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   224
fun
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   225
  lookup :: "(name\<times>trm) list \<Rightarrow> name \<Rightarrow> trm"   
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   226
where
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   227
  "lookup [] X        = Var X"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   228
  "lookup ((Y,T)#\<theta>) X = (if X=Y then T else lookup \<theta> X)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   229
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   230
lemma lookup_eqvt:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   231
  fixes pi::"name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   232
  and   \<theta>::"(name\<times>trm) list"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   233
  and   X::"name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   234
  shows "pi\<bullet>(lookup \<theta> X) = lookup (pi\<bullet>\<theta>) (pi\<bullet>X)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   235
by (induct \<theta>)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   236
   (auto simp add: perm_bij)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   237
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   238
lemma lookup_fresh:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   239
  fixes z::"name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   240
  assumes "z\<sharp>\<theta>" "z\<sharp>x"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   241
  shows "z \<sharp>lookup \<theta> x"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   242
using assms 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   243
by (induct rule: lookup.induct) (auto simp add: fresh_list_cons)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   244
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   245
lemma lookup_fresh':
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   246
  assumes "z\<sharp>\<theta>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   247
  shows "lookup \<theta> z = Var z"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   248
using assms 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   249
by (induct rule: lookup.induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   250
   (auto simp add: fresh_list_cons fresh_prod fresh_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   251
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   252
consts
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   253
  psubst :: "(name\<times>trm) list \<Rightarrow> trm \<Rightarrow> trm"  ("_<_>" [60,100] 100)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   254
 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   255
nominal_primrec
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   256
  "\<theta><(Var x)> = (lookup \<theta> x)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   257
  "\<theta><(App t1 t2)> = App (\<theta><t1>) (\<theta><t2>)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   258
  "x\<sharp>\<theta> \<Longrightarrow> \<theta><(Lam [x].t)> = Lam [x].(\<theta><t>)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   259
  "\<theta><(Const n)> = Const n"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   260
  "\<theta><(Unit)> = Unit"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   261
apply(finite_guess add: fs_name1 lookup_eqvt)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   262
apply(perm_full_simp)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   263
apply(simp add: fs_name1)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   264
apply(rule TrueI)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   265
apply(simp add: abs_fresh)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   266
apply(fresh_guess add: fs_name1 lookup_eqvt)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   267
done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   268
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   269
abbreviation 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   270
 subst :: "trm \<Rightarrow> name \<Rightarrow> trm \<Rightarrow> trm" ("_[_::=_]" [100,100,100] 100)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   271
where
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   272
  "t[x::=t']  \<equiv> ([(x,t')])<t>" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   273
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   274
lemma subst[simp]:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   275
  shows "(Var x)[y::=t'] = (if x=y then t' else (Var x))"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   276
  and   "(App t1 t2)[y::=t'] = App (t1[y::=t']) (t2[y::=t'])"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   277
  and   "x\<sharp>(y,t') \<Longrightarrow> (Lam [x].t)[y::=t'] = Lam [x].(t[y::=t'])"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   278
  and   "Const n[y::=t'] = Const n"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   279
  and   "Unit [y::=t'] = Unit"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   280
  by (simp_all add: fresh_list_cons fresh_list_nil)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   281
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   282
lemma subst_eqvt:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   283
  fixes pi::"name prm" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   284
  and   t::"trm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   285
  shows "pi\<bullet>(t[x::=t']) = (pi\<bullet>t)[(pi\<bullet>x)::=(pi\<bullet>t')]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   286
  by (nominal_induct t avoiding: x t' rule: trm.induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   287
     (perm_simp add: fresh_bij)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   288
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   289
lemma subst_rename: 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   290
  fixes c::"name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   291
  and   t1::"trm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   292
  assumes a: "c\<sharp>t1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   293
  shows "t1[a::=t2] = ([(c,a)]\<bullet>t1)[c::=t2]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   294
  using a
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   295
  apply(nominal_induct t1 avoiding: a c t2 rule: trm.induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   296
  apply(simp add: trm.inject calc_atm fresh_atm abs_fresh perm_nat_def)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   297
  done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   298
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   299
lemma fresh_psubst: 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   300
  fixes z::"name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   301
  and   t::"trm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   302
  assumes "z\<sharp>t" "z\<sharp>\<theta>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   303
  shows "z\<sharp>(\<theta><t>)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   304
using assms
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   305
by (nominal_induct t avoiding: z \<theta> t rule: trm.induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   306
   (auto simp add: abs_fresh lookup_fresh)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   307
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   308
lemma fresh_subst'':
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   309
  fixes z::"name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   310
  and   t1::"trm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   311
  and   t2::"trm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   312
  assumes "z\<sharp>t2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   313
  shows "z\<sharp>t1[z::=t2]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   314
using assms 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   315
by (nominal_induct t1 avoiding: t2 z rule: trm.induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   316
   (auto simp add: abs_fresh fresh_nat fresh_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   317
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   318
lemma fresh_subst':
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   319
  fixes z::"name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   320
  and   t1::"trm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   321
  and   t2::"trm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   322
  assumes "z\<sharp>[y].t1" "z\<sharp>t2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   323
  shows "z\<sharp>t1[y::=t2]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   324
using assms 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   325
by (nominal_induct t1 avoiding: y t2 z rule: trm.induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   326
   (auto simp add: abs_fresh fresh_nat fresh_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   327
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   328
lemma fresh_subst:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   329
  fixes z::"name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   330
  and   t1::"trm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   331
  and   t2::"trm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   332
  assumes "z\<sharp>t1" "z\<sharp>t2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   333
  shows "z\<sharp>t1[y::=t2]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   334
using assms fresh_subst'
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   335
by (auto simp add: abs_fresh) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   336
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   337
lemma fresh_psubst_simpl:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   338
  assumes "x\<sharp>t"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   339
  shows "(x,u)#\<theta><t> = \<theta><t>" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   340
using assms
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   341
proof (nominal_induct t avoiding: x u \<theta> rule: trm.induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   342
  case (Lam y t x u)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   343
  have fs: "y\<sharp>\<theta>" "y\<sharp>x" "y\<sharp>u" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   344
  moreover have "x\<sharp> Lam [y].t" by fact 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   345
  ultimately have "x\<sharp>t" by (simp add: abs_fresh fresh_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   346
  moreover have ih:"\<And>n T. n\<sharp>t \<Longrightarrow> ((n,T)#\<theta>)<t> = \<theta><t>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   347
  ultimately have "(x,u)#\<theta><t> = \<theta><t>" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   348
  moreover have "(x,u)#\<theta><Lam [y].t> = Lam [y]. ((x,u)#\<theta><t>)" using fs 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   349
    by (simp add: fresh_list_cons fresh_prod)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   350
  moreover have " \<theta><Lam [y].t> = Lam [y]. (\<theta><t>)" using fs by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   351
  ultimately show "(x,u)#\<theta><Lam [y].t> = \<theta><Lam [y].t>" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   352
qed (auto simp add: fresh_atm abs_fresh)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   353
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   354
text {* Equivalence (defined) *}
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   355
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   356
inductive2
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   357
  equiv_def :: "(name\<times>ty) list\<Rightarrow>trm\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" ("_ \<turnstile> _ == _ : _" [60,60] 60) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   358
where
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   359
  Q_Refl[intro]:  "\<Gamma> \<turnstile> t : T \<Longrightarrow> \<Gamma> \<turnstile> t == t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   360
| Q_Symm[intro]:  "\<Gamma> \<turnstile> t == s : T \<Longrightarrow> \<Gamma> \<turnstile> s == t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   361
| Q_Trans[intro]: "\<lbrakk>\<Gamma> \<turnstile> s == t : T; \<Gamma> \<turnstile> t == u : T\<rbrakk> \<Longrightarrow>  \<Gamma> \<turnstile> s == u : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   362
| Q_Abs[intro]:   "\<lbrakk>x\<sharp>\<Gamma>; (x,T1)#\<Gamma> \<turnstile> s2 == t2 : T2\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Lam [x]. s2 ==  Lam [x]. t2 : T1 \<rightarrow> T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   363
| Q_App[intro]:   "\<lbrakk>\<Gamma> \<turnstile> s1 == t1 : T1 \<rightarrow> T2 ; \<Gamma> \<turnstile> s2 == t2 : T1\<rbrakk> \<Longrightarrow>  \<Gamma> \<turnstile> App s1 s2 == App t1 t2 : T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   364
| Q_Beta[intro]:  "\<lbrakk>x\<sharp>(\<Gamma>,s2,t2); (x,T1)#\<Gamma> \<turnstile> s12 == t12 : T2 ; \<Gamma> \<turnstile> s2 == t2 : T1\<rbrakk> 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   365
                   \<Longrightarrow>  \<Gamma> \<turnstile> App (Lam [x]. s12) s2 ==  t12[x::=t2] : T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   366
| Q_Ext[intro]:   "\<lbrakk>x\<sharp>(\<Gamma>,s,t); (x,T1)#\<Gamma> \<turnstile> App s (Var x) == App t (Var x) : T2\<rbrakk> 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   367
                   \<Longrightarrow> \<Gamma> \<turnstile> s == t : T1 \<rightarrow> T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   368
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   369
lemma equiv_def_valid:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   370
  assumes "\<Gamma> \<turnstile> t == s : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   371
  shows "valid \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   372
using assms by (induct,auto elim:typing_valid)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   373
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   374
lemma equiv_def_eqvt:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   375
  fixes pi::"name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   376
  assumes a: "\<Gamma> \<turnstile> s == t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   377
  shows "(pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>s) == (pi\<bullet>t) : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   378
using a
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   379
apply(induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   380
apply(auto intro: typing_eqvt valid_eqvt simp add: fresh_bij subst_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   381
apply(rule_tac x="pi\<bullet>x" in Q_Ext)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   382
apply(simp add: fresh_bij)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   383
done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   384
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   385
lemma equiv_def_strong_induct
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   386
  [consumes 1, case_names Q_Refl Q_Symm Q_Trans Q_Abs Q_App Q_Beta Q_Ext]:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   387
  fixes c::"'a::fs_name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   388
  assumes a0: "\<Gamma> \<turnstile> s == t : T" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   389
  and     a1: "\<And>\<Gamma> t T c.  \<Gamma> \<turnstile> t : T  \<Longrightarrow> P c \<Gamma> t t T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   390
  and     a2: "\<And>\<Gamma> t s T c. \<lbrakk>\<Gamma> \<turnstile> t == s : T; \<And>d. P d \<Gamma> t s T\<rbrakk> \<Longrightarrow>  P c \<Gamma> s t T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   391
  and     a3: "\<And>\<Gamma> s t T u c. 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   392
               \<lbrakk>\<Gamma> \<turnstile> s == t : T; \<And>d. P d \<Gamma> s t T; \<Gamma> \<turnstile> t == u : T; \<And>d. P d \<Gamma> t u T\<rbrakk> 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   393
               \<Longrightarrow> P c \<Gamma> s u T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   394
  and     a4: "\<And>x \<Gamma> T1 s2 t2 T2 c. \<lbrakk>x\<sharp>\<Gamma>; x\<sharp>c; (x,T1)#\<Gamma> \<turnstile> s2 == t2 : T2; \<And>d. P d ((x,T1)#\<Gamma>) s2 t2 T2\<rbrakk>
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   395
               \<Longrightarrow> P c \<Gamma> (Lam [x].s2) (Lam [x].t2) (T1\<rightarrow>T2)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   396
  and     a5: "\<And>\<Gamma> s1 t1 T1 T2 s2 t2 c.
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   397
               \<lbrakk>\<Gamma> \<turnstile> s1 == t1 : T1\<rightarrow>T2; \<And>d. P d \<Gamma> s1 t1 (T1\<rightarrow>T2); 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   398
                \<Gamma> \<turnstile> s2 == t2 : T1; \<And>d. P d \<Gamma> s2 t2 T1\<rbrakk> \<Longrightarrow> P c \<Gamma> (App s1 s2) (App t1 t2) T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   399
  and     a6: "\<And>x \<Gamma> T1 s12 t12 T2 s2 t2 c.
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   400
               \<lbrakk>x\<sharp>(\<Gamma>,s2,t2); x\<sharp>c; (x,T1)#\<Gamma> \<turnstile> s12 == t12 : T2; \<And>d. P d ((x,T1)#\<Gamma>) s12 t12 T2;
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   401
               \<Gamma> \<turnstile> s2 == t2 : T1; \<And>d. P d \<Gamma> s2 t2 T1\<rbrakk> 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   402
               \<Longrightarrow> P c \<Gamma> (App (Lam [x].s12) s2) (t12[x::=t2]) T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   403
  and     a7: "\<And>x \<Gamma> s t T1 T2 c.
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   404
               \<lbrakk>x\<sharp>(\<Gamma>,s,t); (x,T1)#\<Gamma> \<turnstile> App s (Var x) == App t (Var x) : T2;
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   405
               \<And>d. P d ((x,T1)#\<Gamma>) (App s (Var x)) (App t (Var x)) T2\<rbrakk>
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   406
               \<Longrightarrow> P c \<Gamma> s t (T1\<rightarrow>T2)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   407
 shows "P c \<Gamma>  s t T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   408
proof -
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   409
  from a0 have "\<And>(pi::name prm) c. P c (pi\<bullet>\<Gamma>) (pi\<bullet>s) (pi\<bullet>t) T" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   410
    proof(induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   411
      case (Q_Refl \<Gamma> t T pi c)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   412
      then show "P c (pi\<bullet>\<Gamma>) (pi\<bullet>t) (pi\<bullet>t) T" using a1 by (simp add: typing_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   413
    next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   414
      case (Q_Symm \<Gamma> t s T pi c)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   415
      then show "P c (pi\<bullet>\<Gamma>) (pi\<bullet>s) (pi\<bullet>t) T" using a2 by (simp only: equiv_def_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   416
    next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   417
      case (Q_Trans \<Gamma> s t T u pi c)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   418
      then show " P c (pi\<bullet>\<Gamma>) (pi\<bullet>s) (pi\<bullet>u) T" using a3 by (blast intro: equiv_def_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   419
    next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   420
      case (Q_App \<Gamma> s1 t1 T1 T2 s2 t2 pi c)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   421
      then show "P c (pi\<bullet>\<Gamma>) (pi\<bullet>App s1 s2) (pi\<bullet>App t1 t2) T2" using a5 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   422
	by (simp, blast intro: equiv_def_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   423
    next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   424
      case (Q_Ext x \<Gamma> s t T1 T2 pi c)
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   425
      then show "P c (pi\<bullet>\<Gamma>) (pi\<bullet>s) (pi\<bullet>t) (T1\<rightarrow>T2)"  
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   426
	apply(auto intro!: a7 simp add: fresh_bij)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   427
	apply(drule equiv_def_eqvt)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   428
	apply(simp)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   429
	done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   430
    next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   431
      case (Q_Abs x \<Gamma> T1 s2 t2 T2 pi c)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   432
      obtain y::"name" where fs: "y\<sharp>(pi\<bullet>x,pi\<bullet>s2,pi\<bullet>t2,pi\<bullet>\<Gamma>,c)" by (rule exists_fresh[OF fs_name1])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   433
      let ?sw="[(pi\<bullet>x,y)]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   434
      let ?pi'="?sw@pi"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   435
      have f1: "x\<sharp>\<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   436
      have f2: "(pi\<bullet>x)\<sharp>(pi\<bullet>\<Gamma>)" using f1 by (simp add: fresh_bij)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   437
      have f3: "y\<sharp>?pi'\<bullet>\<Gamma>" using f1 by (auto simp add: pt_name2 fresh_left calc_atm perm_pi_simp)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   438
      have pr1: "(x,T1)#\<Gamma> \<turnstile> s2 == t2 : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   439
      then have "?pi'\<bullet>((x,T1)#\<Gamma>) \<turnstile> (?pi'\<bullet>s2) == (?pi'\<bullet>t2) : T2" by (rule equiv_def_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   440
      then have "((y,T1)#(?pi'\<bullet>\<Gamma>)) \<turnstile> (?pi'\<bullet>s2) == (?pi'\<bullet>t2) : T2" by (simp add: calc_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   441
      moreover    
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   442
      have ih1: "\<And>c. P c (?pi'\<bullet>((x,T1)#\<Gamma>)) (?pi'\<bullet>s2) (?pi'\<bullet>t2) T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   443
      then have "\<And>c. P c ((y,T1)#(?pi'\<bullet>\<Gamma>)) (?pi'\<bullet>s2) (?pi'\<bullet>t2) T2" by (simp add: calc_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   444
      ultimately have "P c  (?pi'\<bullet>\<Gamma>) (?pi'\<bullet>Lam [x].s2) (?pi'\<bullet>Lam [x].t2) (T1\<rightarrow>T2)" using a4 f3 fs
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   445
	by (simp add: calc_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   446
      then have "P c (?sw\<bullet>pi\<bullet>\<Gamma>) (?sw\<bullet>Lam [(pi\<bullet>x)].(pi\<bullet>s2)) (?sw\<bullet>Lam [(pi\<bullet>x)].(pi\<bullet>t2)) (T1\<rightarrow>T2)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   447
	by (simp del: append_Cons add: calc_atm pt_name2)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   448
      moreover have "(?sw\<bullet>(pi\<bullet>\<Gamma>)) = (pi\<bullet>\<Gamma>)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   449
	by (rule perm_fresh_fresh) (simp_all add: fs f2)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   450
      moreover have "(?sw\<bullet>(Lam [(pi\<bullet>x)].(pi\<bullet>s2))) = Lam [(pi\<bullet>x)].(pi\<bullet>s2)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   451
	by (rule perm_fresh_fresh) (simp_all add: fs f2 abs_fresh)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   452
      moreover have "(?sw\<bullet>(Lam [(pi\<bullet>x)].(pi\<bullet>t2))) = Lam [(pi\<bullet>x)].(pi\<bullet>t2)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   453
	by (rule perm_fresh_fresh) (simp_all add: fs f2 abs_fresh)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   454
      ultimately have "P c (pi\<bullet>\<Gamma>) (Lam [(pi\<bullet>x)].(pi\<bullet>s2)) (Lam [(pi\<bullet>x)].(pi\<bullet>t2)) (T1\<rightarrow>T2)" by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   455
      then show  "P c (pi\<bullet>\<Gamma>) (pi\<bullet>Lam [x].s2) (pi\<bullet>Lam [x].t2) (T1\<rightarrow>T2)" by simp 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   456
    next 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   457
      case (Q_Beta x \<Gamma> s2 t2 T1 s12 t12 T2 pi c) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   458
      obtain y::"name" where fs: "y\<sharp>(pi\<bullet>x,pi\<bullet>s12,pi\<bullet>t12,pi\<bullet>s2,pi\<bullet>t2,pi\<bullet>\<Gamma>,c)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   459
	by (rule exists_fresh[OF fs_name1])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   460
      let ?sw="[(pi\<bullet>x,y)]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   461
      let ?pi'="?sw@pi"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   462
      have f1: "x\<sharp>(\<Gamma>,s2,t2)" by fact 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   463
      have f2: "(pi\<bullet>x)\<sharp>(pi\<bullet>(\<Gamma>,s2,t2))" using f1 by (simp add: fresh_bij)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   464
      have f3: "y\<sharp>(?pi'\<bullet>(\<Gamma>,s2,t2))" using f1 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   465
	by (auto simp add: pt_name2 fresh_left calc_atm perm_pi_simp fresh_prod)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   466
      have pr1: "(x,T1)#\<Gamma> \<turnstile> s12 == t12 : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   467
      then have "?pi'\<bullet>((x,T1)#\<Gamma>) \<turnstile> (?pi'\<bullet>s12) == (?pi'\<bullet>t12) : T2" by (rule equiv_def_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   468
      then have "((y,T1)#(?pi'\<bullet>\<Gamma>)) \<turnstile> (?pi'\<bullet>s12) == (?pi'\<bullet>t12) : T2" by (simp add: calc_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   469
      moreover    
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   470
      have ih1: "\<And>c. P c (?pi'\<bullet>((x,T1)#\<Gamma>)) (?pi'\<bullet>s12) (?pi'\<bullet>t12) T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   471
      then have "\<And>c. P c ((y,T1)#(?pi'\<bullet>\<Gamma>)) (?pi'\<bullet>s12) (?pi'\<bullet>t12) T2" by (simp add: calc_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   472
      moreover
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   473
      have pr2: "\<Gamma> \<turnstile> s2 == t2 : T1" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   474
      then have "(?pi'\<bullet>\<Gamma>) \<turnstile> (?pi'\<bullet>s2) == (?pi'\<bullet>t2) : T1" by (rule equiv_def_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   475
      moreover    
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   476
      have ih2: "\<And>c. P c (?pi'\<bullet>\<Gamma>) (?pi'\<bullet>s2) (?pi'\<bullet>t2) T1" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   477
      ultimately have "P c  (?pi'\<bullet>\<Gamma>) (?pi'\<bullet>(App (Lam [x].s12) s2)) (?pi'\<bullet>(t12[x::=t2])) T2" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   478
	using a6 f3 fs by (simp add: subst_eqvt calc_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   479
      then have "P c (?sw\<bullet>pi\<bullet>\<Gamma>) (?sw\<bullet>(App (Lam [(pi\<bullet>x)].(pi\<bullet>s12)) (pi\<bullet>s2))) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   480
	(?sw\<bullet>((pi\<bullet>t12)[(pi\<bullet>x)::=(pi\<bullet>t2)])) T2" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   481
	by (simp del: append_Cons add: calc_atm pt_name2 subst_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   482
      moreover have "(?sw\<bullet>(pi\<bullet>\<Gamma>)) = (pi\<bullet>\<Gamma>)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   483
	by (rule perm_fresh_fresh) (simp_all add: fs[simplified] f2[simplified])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   484
      moreover have "(?sw\<bullet>(App (Lam [(pi\<bullet>x)].(pi\<bullet>s12)) (pi\<bullet>s2))) = App (Lam [(pi\<bullet>x)].(pi\<bullet>s12)) (pi\<bullet>s2)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   485
	by (rule perm_fresh_fresh) (simp_all add: fs[simplified] f2[simplified] abs_fresh)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   486
      moreover have "(?sw\<bullet>((pi\<bullet>t12)[(pi\<bullet>x)::=(pi\<bullet>t2)])) = ((pi\<bullet>t12)[(pi\<bullet>x)::=(pi\<bullet>t2)])" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   487
	by (rule perm_fresh_fresh) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   488
	   (simp_all add: fs[simplified] f2[simplified] fresh_subst fresh_subst'')
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   489
      ultimately have "P c (pi\<bullet>\<Gamma>) (App (Lam [(pi\<bullet>x)].(pi\<bullet>s12)) (pi\<bullet>s2)) ((pi\<bullet>t12)[(pi\<bullet>x)::=(pi\<bullet>t2)]) T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   490
	by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   491
      then show "P c (pi\<bullet>\<Gamma>) (pi\<bullet>App (Lam [x].s12) s2) (pi\<bullet>t12[x::=t2]) T2" by (simp add: subst_eqvt)	
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   492
    qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   493
  then have "P c (([]::name prm)\<bullet>\<Gamma>) (([]::name prm)\<bullet>s) (([]::name prm)\<bullet>t) T" by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   494
  then show "P c \<Gamma> s t T" by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   495
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   496
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   497
text {* Weak head reduction *}
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   498
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   499
inductive2
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   500
  whr_def :: "trm\<Rightarrow>trm\<Rightarrow>bool" ("_ \<leadsto> _" [80,80] 80) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   501
where
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   502
  QAR_Beta[intro]: "App (Lam [x]. t12) t2 \<leadsto> t12[x::=t2]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   503
| QAR_App[intro]: "t1 \<leadsto> t1' \<Longrightarrow> App t1 t2 \<leadsto> App t1' t2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   504
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   505
declare trm.inject  [simp add]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   506
declare ty.inject  [simp add]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   507
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   508
inductive_cases2 whr_Gen[elim]: "t \<leadsto> t'"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   509
inductive_cases2 whr_Lam[elim]: "Lam [x].t \<leadsto> t'"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   510
inductive_cases2 whr_App_Lam[elim]: "App (Lam [x].t12) t2 \<leadsto> t"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   511
inductive_cases2 whr_Var[elim]: "Var x \<leadsto> t"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   512
inductive_cases2 whr_Const[elim]: "Const n \<leadsto> t"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   513
inductive_cases2 whr_App[elim]: "App p q \<leadsto> t"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   514
inductive_cases2 whr_Const_Right[elim]: "t \<leadsto> Const n"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   515
inductive_cases2 whr_Var_Right[elim]: "t \<leadsto> Var x"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   516
inductive_cases2 whr_App_Right[elim]: "t \<leadsto> App p q"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   517
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   518
declare trm.inject  [simp del]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   519
declare ty.inject  [simp del]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   520
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   521
text {* Weak head normalization *}
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   522
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   523
abbreviation 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   524
 nf :: "trm \<Rightarrow> bool" ("_ \<leadsto>|" [100] 100)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   525
where
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   526
  "t\<leadsto>|  \<equiv> \<not>(\<exists> u. t \<leadsto> u)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   527
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   528
inductive2
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   529
  whn_def :: "trm\<Rightarrow>trm\<Rightarrow>bool" ("_ \<Down> _" [80,80] 80) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   530
where
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   531
  QAN_Reduce[intro]: "\<lbrakk>s \<leadsto> t; t \<Down> u\<rbrakk> \<Longrightarrow> s \<Down> u"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   532
| QAN_Normal[intro]: "t\<leadsto>|  \<Longrightarrow> t \<Down> t"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   533
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   534
lemma whr_eqvt:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   535
  fixes pi::"name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   536
  assumes a: "t \<leadsto> t'"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   537
  shows "(pi\<bullet>t) \<leadsto> (pi\<bullet>t')"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   538
using a
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   539
by (induct) (auto simp add: subst_eqvt fresh_bij)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   540
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   541
lemma whn_eqvt:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   542
  fixes pi::"name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   543
  assumes a: "t \<Down> t'"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   544
  shows "(pi\<bullet>t) \<Down> (pi\<bullet>t')"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   545
using a
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   546
apply(induct)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   547
apply(rule QAN_Reduce)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   548
apply(rule whr_eqvt)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   549
apply(assumption)+
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   550
apply(rule QAN_Normal)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   551
apply(auto)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   552
apply(drule_tac pi="rev pi" in whr_eqvt)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   553
apply(perm_simp)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   554
done
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   555
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   556
text {* Algorithmic term equivalence and algorithmic path equivalence *}
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   557
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   558
inductive2
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   559
  alg_equiv :: "(name\<times>ty) list\<Rightarrow>trm\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" ("_ \<turnstile> _ <=> _ : _" [60,60] 60) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   560
and
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   561
  alg_path_equiv :: "(name\<times>ty) list\<Rightarrow>trm\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" ("_ \<turnstile> _ \<leftrightarrow> _ : _" [60,60] 60) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   562
where
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   563
  QAT_Base[intro]:  "\<lbrakk>s \<Down> p; t \<Down> q; \<Gamma> \<turnstile> p \<leftrightarrow> q : TBase \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s <=> t : TBase"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   564
| QAT_Arrow[intro]: "\<lbrakk>x\<sharp>\<Gamma>; x\<sharp>s; x\<sharp>t; (x,T1)#\<Gamma> \<turnstile> App s (Var x) <=> App t (Var x) : T2\<rbrakk> 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   565
                     \<Longrightarrow> \<Gamma> \<turnstile> s <=> t : T1 \<rightarrow> T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   566
| QAT_One[intro]:   "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> s <=> t : TUnit"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   567
| QAP_Var[intro]:   "\<lbrakk>valid \<Gamma>;(x,T) \<in> set \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Var x \<leftrightarrow> Var x : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   568
| QAP_App[intro]:   "\<lbrakk>\<Gamma> \<turnstile> p \<leftrightarrow> q : T1 \<rightarrow> T2; \<Gamma> \<turnstile> s <=> t : T1 \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> App p s \<leftrightarrow> App q t : T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   569
| QAP_Const[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> Const n \<leftrightarrow> Const n : TBase"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   570
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   571
lemma alg_equiv_alg_path_equiv_eqvt:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   572
  fixes pi::"name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   573
  shows "\<Gamma> \<turnstile> s <=> t : T \<Longrightarrow> (pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>s) <=> (pi\<bullet>t) : T" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   574
  and   "\<Gamma> \<turnstile> p \<leftrightarrow> q : T \<Longrightarrow> (pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>p) \<leftrightarrow> (pi\<bullet>q) : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   575
apply(induct rule: alg_equiv_alg_path_equiv.inducts)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   576
apply(auto intro: whn_eqvt simp add: fresh_bij valid_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   577
apply(rule_tac x="pi\<bullet>x" in  QAT_Arrow)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   578
apply(auto simp add: fresh_bij)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   579
apply(rule QAP_Var)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   580
apply(simp add: valid_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   581
apply(simp add: pt_list_set_pi[OF pt_name_inst, symmetric])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   582
apply(perm_simp add: pt_set_bij1a[OF pt_name_inst, OF at_name_inst])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   583
done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   584
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   585
lemma alg_equiv_alg_path_equiv_strong_induct
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   586
  [case_names QAT_Base QAT_Arrow QAT_One QAP_Var QAP_App QAP_Const]:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   587
  fixes c::"'a::fs_name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   588
  assumes a1: "\<And>s p t q \<Gamma> c. \<lbrakk>s \<Down> p; t \<Down> q; \<Gamma> \<turnstile> p \<leftrightarrow> q : TBase; \<And>d. P2 d \<Gamma> p q TBase\<rbrakk> 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   589
               \<Longrightarrow> P1 c \<Gamma> s t TBase"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   590
  and     a2: "\<And>x \<Gamma> s t T1 T2 c.
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   591
               \<lbrakk>x\<sharp>\<Gamma>; x\<sharp>s; x\<sharp>t; x\<sharp>c; (x,T1)#\<Gamma> \<turnstile> App s (Var x) <=> App t (Var x) : T2;
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   592
               \<And>d. P1 d ((x,T1)#\<Gamma>) (App s (Var x)) (App t (Var x)) T2\<rbrakk>
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   593
               \<Longrightarrow> P1 c \<Gamma> s t (T1\<rightarrow>T2)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   594
  and     a3: "\<And>\<Gamma> s t c. valid \<Gamma> \<Longrightarrow> P1 c \<Gamma> s t TUnit"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   595
  and     a4: "\<And>\<Gamma> x T c. \<lbrakk>valid \<Gamma>; (x,T) \<in> set \<Gamma>\<rbrakk> \<Longrightarrow> P2 c \<Gamma> (Var x) (Var x) T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   596
  and     a5: "\<And>\<Gamma> p q T1 T2 s t c.
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   597
               \<lbrakk>\<Gamma> \<turnstile> p \<leftrightarrow> q : T1\<rightarrow>T2; \<And>d. P2 d \<Gamma> p q (T1\<rightarrow>T2); \<Gamma> \<turnstile> s <=> t : T1; \<And>d. P1 d \<Gamma> s t T1\<rbrakk>
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   598
               \<Longrightarrow> P2 c \<Gamma> (App p s) (App q t) T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   599
  and     a6: "\<And>\<Gamma> n c. valid \<Gamma> \<Longrightarrow> P2 c \<Gamma> (Const n) (Const n) TBase"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   600
  shows "(\<Gamma> \<turnstile> s <=> t : T \<longrightarrow>P1 c \<Gamma> s t T) \<and> (\<Gamma>' \<turnstile> s' \<leftrightarrow> t' : T' \<longrightarrow> P2 c \<Gamma>' s' t' T')"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   601
proof -
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   602
  have "(\<Gamma> \<turnstile> s <=> t : T \<longrightarrow> (\<forall>c (pi::name prm). P1 c (pi\<bullet>\<Gamma>) (pi\<bullet>s) (pi\<bullet>t) T)) \<and> 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   603
        (\<Gamma>' \<turnstile> s' \<leftrightarrow> t' : T' \<longrightarrow> (\<forall>c (pi::name prm). P2 c (pi\<bullet>\<Gamma>') (pi\<bullet>s') (pi\<bullet>t') T'))"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   604
  proof(induct rule: alg_equiv_alg_path_equiv.induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   605
    case (QAT_Base s q t p \<Gamma>)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   606
    then show "\<forall>c (pi::name prm). P1 c (pi\<bullet>\<Gamma>) (pi\<bullet>s) (pi\<bullet>t) TBase"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   607
      apply(auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   608
      apply(rule_tac p="pi\<bullet>q" and q="pi\<bullet>p" in  a1)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   609
      apply(simp_all add: whn_eqvt alg_equiv_alg_path_equiv_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   610
      done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   611
  next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   612
    case (QAT_Arrow x \<Gamma> s t T1 T2)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   613
    show ?case
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   614
    proof (rule allI, rule allI)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   615
      fix c::"'a::fs_name" and pi::"name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   616
      obtain y::"name" where fs: "y\<sharp>(pi\<bullet>s,pi\<bullet>t,pi\<bullet>\<Gamma>,c)" by (rule exists_fresh[OF fs_name1])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   617
      let ?sw="[(pi\<bullet>x,y)]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   618
      let ?pi'="?sw@pi"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   619
      have f0: "x\<sharp>\<Gamma>" "x\<sharp>s" "x\<sharp>t" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   620
      then have f1: "x\<sharp>(\<Gamma>,s,t)" by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   621
      have f2: "(pi\<bullet>x)\<sharp>(pi\<bullet>(\<Gamma>,s,t))" using f1 by (simp add: fresh_bij)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   622
      have f3: "y\<sharp>?pi'\<bullet>(\<Gamma>,s,t)" using f1 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   623
	by (simp only: pt_name2 fresh_left, auto simp add: perm_pi_simp calc_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   624
      then have f3': "y\<sharp>?pi'\<bullet>\<Gamma>" "y\<sharp>?pi'\<bullet>s" "y\<sharp>?pi'\<bullet>t" by (auto simp add: fresh_prod)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   625
      have pr1: "(x,T1)#\<Gamma> \<turnstile> App s (Var x) <=> App t (Var x) : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   626
      then have "(?pi'\<bullet>((x,T1)#\<Gamma>)) \<turnstile> (?pi'\<bullet>(App s (Var x))) <=> (?pi'\<bullet>(App t (Var x))) : T2" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   627
	by (simp only: alg_equiv_alg_path_equiv_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   628
      then have "(y,T1)#(?pi'\<bullet>\<Gamma>) \<turnstile> (App (?pi'\<bullet>s) (Var y)) <=> (App (?pi'\<bullet>t) (Var y)) : T2" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   629
	by (simp add: calc_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   630
      moreover    
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   631
      have ih1: "\<forall>c (pi::name prm).  P1 c (pi\<bullet>((x,T1)#\<Gamma>)) (pi\<bullet>App s (Var x)) (pi\<bullet>App t (Var x)) T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   632
	by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   633
      then have "\<And>c.  P1 c (?pi'\<bullet>((x,T1)#\<Gamma>)) (?pi'\<bullet>App s (Var x)) (?pi'\<bullet>App t (Var x)) T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   634
	by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   635
      then have "\<And>c.  P1 c ((y,T1)#(?pi'\<bullet>\<Gamma>)) (App (?pi'\<bullet>s) (Var y)) (App (?pi'\<bullet>t) (Var y)) T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   636
	by (simp add: calc_atm)     
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   637
      ultimately have "P1 c (?pi'\<bullet>\<Gamma>) (?pi'\<bullet>s) (?pi'\<bullet>t) (T1\<rightarrow>T2)" using a2 f3' fs by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   638
      then have "P1 c (?sw\<bullet>pi\<bullet>\<Gamma>) (?sw\<bullet>pi\<bullet>s) (?sw\<bullet>pi\<bullet>t) (T1\<rightarrow>T2)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   639
	by (simp del: append_Cons add: calc_atm pt_name2)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   640
      moreover have "(?sw\<bullet>(pi\<bullet>\<Gamma>)) = (pi\<bullet>\<Gamma>)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   641
	by (rule perm_fresh_fresh) (simp_all add: fs[simplified] f2[simplified])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   642
      moreover have "(?sw\<bullet>(pi\<bullet>s)) = (pi\<bullet>s)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   643
	by (rule perm_fresh_fresh) (simp_all add: fs[simplified] f2[simplified])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   644
      moreover have "(?sw\<bullet>(pi\<bullet>t)) = (pi\<bullet>t)" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   645
	by (rule perm_fresh_fresh) (simp_all add: fs[simplified] f2[simplified])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   646
      ultimately show "P1 c (pi\<bullet>\<Gamma>) (pi\<bullet>s) (pi\<bullet>t) (T1\<rightarrow>T2)" by (simp)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   647
    qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   648
  next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   649
    case (QAT_One \<Gamma> s t)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   650
    then show "\<forall>c (pi::name prm). P1 c (pi\<bullet>\<Gamma>) (pi\<bullet>s) (pi\<bullet>t) TUnit"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   651
      by (auto intro!: a3 simp add: valid_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   652
  next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   653
    case (QAP_Var \<Gamma> x T)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   654
    then show "\<forall>c (pi::name prm). P2 c (pi \<bullet> \<Gamma>) (pi \<bullet> Var x) (pi \<bullet> Var x) T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   655
      apply(auto intro!: a4 simp add: valid_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   656
      apply(simp add: pt_list_set_pi[OF pt_name_inst, symmetric])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   657
      apply(perm_simp add: pt_set_bij1a[OF pt_name_inst, OF at_name_inst])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   658
      done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   659
  next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   660
    case (QAP_App \<Gamma> p q T1 T2 s t)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   661
    then show "\<forall>c (pi::name prm). P2 c (pi\<bullet>\<Gamma>) (pi\<bullet>App p s) (pi\<bullet>App q t) T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   662
      by (auto intro!: a5 simp add: alg_equiv_alg_path_equiv_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   663
  next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   664
    case (QAP_Const \<Gamma> n)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   665
    then show "\<forall>c (pi::name prm). P2 c (pi\<bullet>\<Gamma>) (pi\<bullet>Const n) (pi\<bullet>Const n) TBase"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   666
      by (auto intro!: a6 simp add: valid_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   667
  qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   668
  then have "(\<Gamma> \<turnstile> s <=> t : T \<longrightarrow> P1 c (([]::name prm)\<bullet>\<Gamma>) (([]::name prm)\<bullet>s) (([]::name prm)\<bullet>t) T) \<and> 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   669
             (\<Gamma>' \<turnstile> s' \<leftrightarrow> t' : T' \<longrightarrow> P2 c (([]::name prm)\<bullet>\<Gamma>') (([]::name prm)\<bullet>s') (([]::name prm)\<bullet>t') T')"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   670
    by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   671
  then show ?thesis by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   672
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   673
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   674
(* post-processing of the strong induction principle proved above; *) 
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   675
(* the code extracts the strong_inducts-version from strong_induct *)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   676
setup {*
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   677
  PureThy.add_thmss
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   678
    [(("alg_equiv_alg_path_equiv_strong_inducts",
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   679
      ProjectRule.projects (ProofContext.init (the_context())) [1,2]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   680
        (thm "alg_equiv_alg_path_equiv_strong_induct")), [])] #> snd
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   681
*}
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   682
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   683
declare trm.inject  [simp add]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   684
declare ty.inject  [simp add]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   685
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   686
inductive_cases2 whn_inv_auto[elim]: "t \<Down> t'"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   687
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   688
inductive_cases2 alg_equiv_Base_inv_auto[elim]: "\<Gamma> \<turnstile> s<=>t : TBase"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   689
inductive_cases2 alg_equiv_Arrow_inv_auto[elim]: "\<Gamma> \<turnstile> s<=>t : T1 \<rightarrow> T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   690
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   691
inductive_cases2 alg_path_equiv_Base_inv_auto[elim]: "\<Gamma> \<turnstile> s\<leftrightarrow>t : TBase"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   692
inductive_cases2 alg_path_equiv_Unit_inv_auto[elim]: "\<Gamma> \<turnstile> s\<leftrightarrow>t : TUnit"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   693
inductive_cases2 alg_path_equiv_Arrow_inv_auto[elim]: "\<Gamma> \<turnstile> s\<leftrightarrow>t : T1 \<rightarrow> T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   694
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   695
inductive_cases2 alg_path_equiv_Var_left_inv_auto[elim]: "\<Gamma> \<turnstile> Var x \<leftrightarrow> t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   696
inductive_cases2 alg_path_equiv_Var_left_inv_auto'[elim]: "\<Gamma> \<turnstile> Var x \<leftrightarrow> t : T'"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   697
inductive_cases2 alg_path_equiv_Var_right_inv_auto[elim]: "\<Gamma> \<turnstile> s \<leftrightarrow> Var x : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   698
inductive_cases2 alg_path_equiv_Var_right_inv_auto'[elim]: "\<Gamma> \<turnstile> s \<leftrightarrow> Var x : T'"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   699
inductive_cases2 alg_path_equiv_Const_left_inv_auto[elim]: "\<Gamma> \<turnstile> Const n \<leftrightarrow> t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   700
inductive_cases2 alg_path_equiv_Const_right_inv_auto[elim]: "\<Gamma> \<turnstile> s \<leftrightarrow> Const n : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   701
inductive_cases2 alg_path_equiv_App_left_inv_auto[elim]: "\<Gamma> \<turnstile> App p s \<leftrightarrow> t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   702
inductive_cases2 alg_path_equiv_App_right_inv_auto[elim]: "\<Gamma> \<turnstile> s \<leftrightarrow> App q t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   703
inductive_cases2 alg_path_equiv_Lam_left_inv_auto[elim]: "\<Gamma> \<turnstile> Lam[x].s \<leftrightarrow> t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   704
inductive_cases2 alg_path_equiv_Lam_right_inv_auto[elim]: "\<Gamma> \<turnstile> t \<leftrightarrow> Lam[x].s : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   705
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   706
declare trm.inject [simp del]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   707
declare ty.inject [simp del]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   708
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   709
text {* Subcontext. *}
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   710
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   711
abbreviation
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   712
  "sub" :: "(name\<times>ty) list \<Rightarrow> (name\<times>ty) list \<Rightarrow> bool" (" _ \<lless> _ " [55,55] 55)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   713
where
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   714
  "\<Gamma>1 \<lless> \<Gamma>2 \<equiv> (\<forall>a \<sigma>. (a,\<sigma>)\<in>set \<Gamma>1 \<longrightarrow>  (a,\<sigma>)\<in>set \<Gamma>2) \<and> valid \<Gamma>2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   715
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   716
lemma alg_equiv_valid:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   717
  shows  "\<Gamma> \<turnstile> s <=> t : T \<Longrightarrow> valid \<Gamma>" and  "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> valid \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   718
by (induct rule : alg_equiv_alg_path_equiv.inducts, auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   719
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   720
lemma algorithmic_monotonicity:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   721
  fixes \<Gamma>':: "(name\<times>ty) list"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   722
  shows "\<Gamma> \<turnstile> s <=> t : T \<Longrightarrow> \<Gamma>\<lless>\<Gamma>' \<Longrightarrow> \<Gamma>' \<turnstile> s <=> t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   723
  and "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> \<Gamma>\<lless>\<Gamma>' \<Longrightarrow> \<Gamma>' \<turnstile> s \<leftrightarrow> t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   724
proof (nominal_induct \<Gamma> s t T and \<Gamma> s t T avoiding: \<Gamma>' rule: alg_equiv_alg_path_equiv_strong_inducts)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   725
  case (QAT_Arrow x \<Gamma> s t T1 T2 \<Gamma>')
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   726
  have fs:"x\<sharp>\<Gamma>" "x\<sharp>s" "x\<sharp>t" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   727
  have h1:"(x,T1)#\<Gamma> \<turnstile> App s (Var x) <=> App t (Var x) : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   728
  have h2:"\<Gamma>\<lless>\<Gamma>'" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   729
  have ih:"\<And>\<Gamma>'. \<lbrakk>(x,T1)#\<Gamma> \<lless> \<Gamma>'\<rbrakk>  \<Longrightarrow> \<Gamma>' \<turnstile> App s (Var x) <=> App t (Var x) : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   730
  have "x\<sharp>\<Gamma>'" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   731
  then have sub:"(x,T1)#\<Gamma> \<lless> (x,T1)#\<Gamma>'" using h2 by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   732
  then have "(x,T1)#\<Gamma>' \<turnstile> App s (Var x) <=> App t (Var x) : T2" using ih by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   733
  then show "\<Gamma>' \<turnstile> s <=> t : T1\<rightarrow>T2" using sub fs by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   734
qed (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   735
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   736
text {* Logical equivalence. *}
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   737
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   738
function log_equiv :: "((name\<times>ty) list \<Rightarrow> trm \<Rightarrow> trm \<Rightarrow> ty \<Rightarrow> bool)"   
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   739
                      ("_ \<turnstile> _ is _ : _" [60,60,60,60] 60) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   740
where    
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   741
   "\<Gamma> \<turnstile> s is t : TUnit = valid \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   742
 | "\<Gamma> \<turnstile> s is t : TBase = \<Gamma> \<turnstile> s <=> t : TBase"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   743
 | "\<Gamma> \<turnstile> s is t : (T1 \<rightarrow> T2) =  
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   744
           (valid \<Gamma> \<and> (\<forall>\<Gamma>' s' t'. \<Gamma>\<lless>\<Gamma>' \<longrightarrow> \<Gamma>' \<turnstile> s' is t' : T1 \<longrightarrow>  (\<Gamma>' \<turnstile> (App s s') is (App t t') : T2)))"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   745
apply (auto simp add: ty.inject)
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   746
apply (subgoal_tac "(\<exists>T1 T2. b=T1 \<rightarrow> T2) \<or> b=TUnit \<or> b=TBase" )
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   747
apply (force)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   748
apply (rule ty_cases)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   749
done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   750
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   751
termination
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   752
apply(relation "measure (\<lambda>(_,_,_,T). size T)")
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   753
apply(auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   754
done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   755
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   756
lemma log_equiv_valid: 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   757
  assumes "\<Gamma> \<turnstile> s is t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   758
  shows "valid \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   759
using assms 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   760
by (induct rule: log_equiv.induct,auto elim: alg_equiv_valid)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   761
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   762
lemma logical_monotonicity :
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   763
 fixes T::ty
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   764
 assumes "\<Gamma> \<turnstile> s is t : T" "\<Gamma>\<lless>\<Gamma>'" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   765
 shows "\<Gamma>' \<turnstile> s is t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   766
using assms
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   767
proof (induct arbitrary: \<Gamma>' rule: log_equiv.induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   768
  case (2 \<Gamma> s t \<Gamma>')
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   769
  then show "\<Gamma>' \<turnstile> s is t : TBase" using algorithmic_monotonicity by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   770
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   771
  case (3 \<Gamma> s t T1 T2 \<Gamma>')
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   772
  have h1:"\<Gamma> \<turnstile> s is t : T1\<rightarrow>T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   773
  have h2:"\<Gamma>\<lless>\<Gamma>'" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   774
  {
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   775
    fix \<Gamma>'' s' t'
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   776
    assume "\<Gamma>'\<lless>\<Gamma>''" "\<Gamma>'' \<turnstile> s' is t' : T1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   777
    then have "\<Gamma>'' \<turnstile> (App s s') is (App t t') : T2" using h1 h2 by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   778
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   779
  then show "\<Gamma>' \<turnstile> s is t : T1\<rightarrow>T2" using h2 by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   780
qed (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   781
  
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   782
lemma forget: 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   783
  fixes x::"name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   784
  and   L::"trm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   785
  assumes a: "x\<sharp>L" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   786
  shows "L[x::=P] = L"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   787
  using a
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   788
by (nominal_induct L avoiding: x P rule: trm.induct)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   789
   (auto simp add: fresh_atm abs_fresh)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   790
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   791
lemma subst_fun_eq:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   792
  fixes u::trm
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   793
  assumes h:"[x].t1 = [y].t2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   794
  shows "t1[x::=u] = t2[y::=u]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   795
proof -
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   796
  { 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   797
    assume "x=y" and "t1=t2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   798
    then have ?thesis using h by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   799
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   800
  moreover 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   801
  {
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   802
    assume h1:"x \<noteq> y" and h2:"t1=[(x,y)] \<bullet> t2" and h3:"x \<sharp> t2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   803
    then have "([(x,y)] \<bullet> t2)[x::=u] = t2[y::=u]" by (simp add: subst_rename)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   804
    then have ?thesis using h2 by simp 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   805
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   806
  ultimately show ?thesis using alpha h by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   807
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   808
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   809
lemma psubst_empty[simp]:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   810
  shows "[]<t> = t"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   811
  by (nominal_induct t rule: trm.induct) (auto simp add: fresh_list_nil)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   812
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   813
lemma psubst_subst_psubst:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   814
  assumes h:"c \<sharp> \<theta>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   815
  shows "\<theta><t>[c::=s] = (c,s)#\<theta><t>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   816
  using h
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   817
by (nominal_induct t avoiding: \<theta> c s rule: trm.induct)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   818
   (auto simp add: fresh_list_cons fresh_atm forget lookup_fresh lookup_fresh' fresh_psubst)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   819
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   820
lemma subst_fresh_simpl:
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   821
  assumes a: "x\<sharp>\<theta>"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   822
  shows "\<theta><Var x> = Var x"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   823
using a
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   824
by (induct \<theta> arbitrary: x, auto simp add:fresh_list_cons fresh_prod fresh_atm)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   825
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   826
lemma psubst_subst_propagate: 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   827
  assumes "x\<sharp>\<theta>" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   828
  shows "\<theta><t[x::=u]> = \<theta><t>[x::=\<theta><u>]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   829
using assms
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   830
proof (nominal_induct t avoiding: x u \<theta> rule: trm.induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   831
  case (Var n x u \<theta>)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   832
  { assume "x=n"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   833
    moreover have "x\<sharp>\<theta>" by fact 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   834
    ultimately have "\<theta><Var n[x::=u]> = \<theta><Var n>[x::=\<theta><u>]" using subst_fresh_simpl by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   835
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   836
  moreover 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   837
  { assume h:"x\<noteq>n"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   838
    then have "x\<sharp>Var n" by (auto simp add: fresh_atm) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   839
    moreover have "x\<sharp>\<theta>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   840
    ultimately have "x\<sharp>\<theta><Var n>" using fresh_psubst by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   841
    then have " \<theta><Var n>[x::=\<theta><u>] =  \<theta><Var n>" using forget by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   842
    then have "\<theta><Var n[x::=u]> = \<theta><Var n>[x::=\<theta><u>]" using h by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   843
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   844
  ultimately show ?case by auto  
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   845
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   846
  case (Lam n t x u \<theta>)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   847
  have fs:"n\<sharp>x" "n\<sharp>u" "n\<sharp>\<theta>" "x\<sharp>\<theta>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   848
  have ih:"\<And> y s \<theta>. y\<sharp>\<theta> \<Longrightarrow> ((\<theta><(t[y::=s])>) = ((\<theta><t>)[y::=(\<theta><s>)]))" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   849
  have "\<theta> <(Lam [n].t)[x::=u]> = \<theta><Lam [n]. (t [x::=u])>" using fs by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   850
  then have "\<theta> <(Lam [n].t)[x::=u]> = Lam [n]. \<theta><t [x::=u]>" using fs by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   851
  moreover have "\<theta><t[x::=u]> = \<theta><t>[x::=\<theta><u>]" using ih fs by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   852
  ultimately have "\<theta> <(Lam [n].t)[x::=u]> = Lam [n].(\<theta><t>[x::=\<theta><u>])" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   853
  moreover have "Lam [n].(\<theta><t>[x::=\<theta><u>]) = (Lam [n].\<theta><t>)[x::=\<theta><u>]" using fs fresh_psubst by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   854
  ultimately have "\<theta><(Lam [n].t)[x::=u]> = (Lam [n].\<theta><t>)[x::=\<theta><u>]" using fs by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   855
  then show "\<theta><(Lam [n].t)[x::=u]> = \<theta><Lam [n].t>[x::=\<theta><u>]" using fs by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   856
qed (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   857
 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   858
lemma fresh_subst_fresh:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   859
    assumes "a\<sharp>e"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   860
    shows "a\<sharp>t[a::=e]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   861
using assms 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   862
by (nominal_induct t avoiding: a e rule: trm.induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   863
   (auto simp add: fresh_atm abs_fresh fresh_nat) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   864
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   865
lemma path_equiv_implies_nf:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   866
  assumes "\<Gamma> \<turnstile> s \<leftrightarrow> t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   867
  shows "s \<leadsto>|" and "t \<leadsto>|"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   868
using assms
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   869
by (induct rule: alg_equiv_alg_path_equiv.inducts(2)) (simp, auto)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   870
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   871
lemma path_equiv_implies_nf:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   872
  shows "\<Gamma> \<turnstile> s <=> t : T \<Longrightarrow> True"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   873
    and "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> s \<leadsto>|"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   874
        "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> t \<leadsto>|"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   875
by (induct rule: alg_equiv_alg_path_equiv.inducts) (auto)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   876
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   877
lemma main_lemma:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   878
  shows "\<Gamma> \<turnstile> s is t : T \<Longrightarrow> \<Gamma> \<turnstile> s <=> t : T" and "\<Gamma> \<turnstile> p \<leftrightarrow> q : T \<Longrightarrow> \<Gamma> \<turnstile> p is q : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   879
proof (nominal_induct T arbitrary: \<Gamma> s t p q rule:ty.induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   880
  case (Arrow T1 T2)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   881
  { 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   882
    case (1 \<Gamma> s t)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   883
    have ih1:"\<And>\<Gamma> s t. \<Gamma> \<turnstile> s is t : T2 \<Longrightarrow> \<Gamma> \<turnstile> s <=> t : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   884
    have ih2:"\<And>\<Gamma> s t. \<Gamma> \<turnstile> s \<leftrightarrow> t : T1 \<Longrightarrow> \<Gamma> \<turnstile> s is t : T1" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   885
    have h:"\<Gamma> \<turnstile> s is t : T1\<rightarrow>T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   886
    obtain x::name where fs:"x\<sharp>(\<Gamma>,s,t)" by (erule exists_fresh[OF fs_name1])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   887
    have "valid \<Gamma>" using h log_equiv_valid by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   888
    then have v:"valid ((x,T1)#\<Gamma>)" using fs by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   889
    then have "(x,T1)#\<Gamma> \<turnstile> Var x \<leftrightarrow> Var x : T1" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   890
    then have "(x,T1)#\<Gamma> \<turnstile> Var x is Var x : T1" using ih2 by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   891
    then have "(x,T1)#\<Gamma> \<turnstile> App s (Var x) is App t (Var x) : T2" using h v by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   892
    then have "(x,T1)#\<Gamma> \<turnstile> App s (Var x) <=> App t (Var x) : T2" using ih1 by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   893
    then show "\<Gamma> \<turnstile> s <=> t : T1\<rightarrow>T2" using fs by (auto simp add: fresh_prod)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   894
  next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   895
    case (2 \<Gamma> p q)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   896
    have h:"\<Gamma> \<turnstile> p \<leftrightarrow> q : T1\<rightarrow>T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   897
    have ih1:"\<And>\<Gamma> s t. \<Gamma> \<turnstile> s \<leftrightarrow> t : T2 \<Longrightarrow> \<Gamma> \<turnstile> s is t : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   898
    have ih2:"\<And>\<Gamma> s t. \<Gamma> \<turnstile> s is t : T1 \<Longrightarrow> \<Gamma> \<turnstile> s <=> t : T1" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   899
    {
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   900
      fix \<Gamma>' s t
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   901
      assume "\<Gamma>\<lless>\<Gamma>'" and hl:"\<Gamma>' \<turnstile> s is t : T1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   902
      then have "\<Gamma>' \<turnstile> p \<leftrightarrow> q : T1 \<rightarrow> T2" using h algorithmic_monotonicity by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   903
      moreover have "\<Gamma>' \<turnstile> s <=> t : T1" using ih2 hl by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   904
      ultimately have "\<Gamma>' \<turnstile> App p s \<leftrightarrow> App q t : T2" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   905
      then have "\<Gamma>' \<turnstile> App p s is App q t : T2" using ih1 by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   906
    }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   907
    moreover have "valid \<Gamma>" using h alg_equiv_valid by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   908
    ultimately show "\<Gamma> \<turnstile> p is q : T1\<rightarrow>T2"  by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   909
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   910
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   911
  case TBase
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   912
  { case 2
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   913
    have h:"\<Gamma> \<turnstile> s \<leftrightarrow> t : TBase" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   914
    then have "s \<leadsto>|" and "t \<leadsto>|" using path_equiv_implies_nf by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   915
    then have "s \<Down> s" and "t \<Down> t" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   916
    then have "\<Gamma> \<turnstile> s <=> t : TBase" using h by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   917
    then show "\<Gamma> \<turnstile> s is t : TBase" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   918
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   919
qed (auto elim:alg_equiv_valid)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   920
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   921
corollary corollary_main:
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   922
  assumes a: "\<Gamma> \<turnstile> s \<leftrightarrow> t : T"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   923
  shows "\<Gamma> \<turnstile> s <=> t : T"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   924
using a main_lemma by blast
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   925
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   926
lemma algorithmic_symmetry_aux:
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   927
  shows "\<Gamma> \<turnstile> s <=> t : T \<Longrightarrow> \<Gamma> \<turnstile> t <=> s : T" 
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   928
  and   "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<turnstile> t \<leftrightarrow> s : T"
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   929
by (induct rule: alg_equiv_alg_path_equiv.inducts) (auto)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   930
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   931
lemma algorithmic_symmetry:
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   932
  assumes a: "\<Gamma> \<turnstile> s <=> t : T"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   933
  shows "\<Gamma> \<turnstile> t <=> s : T"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   934
using a by (simp add: algorithmic_symmetry_aux)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   935
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   936
lemma algorithmic_path_symmetry:
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   937
  assumes a: "\<Gamma> \<turnstile> s \<leftrightarrow> t : T"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   938
  shows "\<Gamma> \<turnstile> t \<leftrightarrow> s : T"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   939
using a by (simp add: algorithmic_symmetry_aux)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   940
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   941
lemma red_unicity : 
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   942
  assumes a: "x \<leadsto> a" 
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   943
  and     b: "x \<leadsto> b"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   944
  shows "a=b"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   945
  using a b
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   946
apply (induct arbitrary: b)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   947
apply (erule whr_App_Lam)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   948
apply (clarify)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   949
apply (rule subst_fun_eq)
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   950
apply (simp)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   951
apply (force)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   952
apply (erule whr_App)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   953
apply (blast)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   954
done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   955
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   956
lemma nf_unicity :
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   957
  assumes "x \<Down> a" "x \<Down> b"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   958
  shows "a=b"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   959
  using assms 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   960
proof (induct arbitrary: b)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   961
  case (QAN_Reduce x t a b)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   962
  have h:"x \<leadsto> t" "t \<Down> a" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   963
  have ih:"\<And>b. t \<Down> b \<Longrightarrow> a = b" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   964
  have "x \<Down> b" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   965
  then obtain t' where "x \<leadsto> t'" and hl:"t' \<Down> b" using h by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   966
  then have "t=t'" using h red_unicity by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   967
  then show "a=b" using ih hl by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   968
qed (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   969
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   970
lemma Q_eqvt :
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   971
  fixes pi:: "name prm"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   972
  shows "\<Gamma> \<turnstile> s <=> t : T \<Longrightarrow> (pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>s) <=> (pi\<bullet>t) : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   973
  and "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> (pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>s) \<leftrightarrow> (pi\<bullet>t) : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   974
using assms
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   975
proof (induct rule:alg_equiv_alg_path_equiv.inducts)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   976
  case (QAP_Var \<Gamma> x T)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   977
  then have "pi\<bullet>(x,T) \<in> (pi\<bullet>(set \<Gamma>))" using in_eqvt by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   978
  then have "(pi\<bullet>x,T) \<in> (set (pi\<bullet>\<Gamma>))" using set_eqvt perm_ty by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   979
  moreover have "valid \<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   980
  ultimately show ?case using valid_eqvt by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   981
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   982
  case (QAT_Arrow x \<Gamma> s t T1 T2)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   983
  then have h:"((pi\<bullet>x)\<sharp>(pi\<bullet>\<Gamma>))" "((pi\<bullet>x)\<sharp>(pi\<bullet>s))" "((pi\<bullet>x)\<sharp>(pi\<bullet>t))"  using fresh_bij by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   984
  have "(pi\<bullet>((x,T1)#\<Gamma>)) \<turnstile> pi \<bullet> (App s (Var x)) <=> pi \<bullet> (App t (Var x)) : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   985
  then have "(pi\<bullet>((x,T1)#\<Gamma>)) \<turnstile> (App (pi\<bullet>s) (Var (pi\<bullet>x))) <=> (App (pi\<bullet>t) (Var (pi\<bullet>x))) : T2" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   986
  moreover have "pi\<bullet>((x,T1)#\<Gamma>) = (pi\<bullet>x,pi\<bullet>T1)#(pi\<bullet>\<Gamma>)" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   987
  ultimately have "((pi\<bullet>x,T1)#(pi\<bullet>\<Gamma>))  \<turnstile> (App (pi\<bullet>s) (Var (pi\<bullet>x))) <=> (App (pi\<bullet>t) (Var (pi\<bullet>x))) : T2" using perm_ty by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   988
  then show ?case using h by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   989
qed (auto elim:whn_eqvt valid_eqvt)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   990
 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   991
(* FIXME this lemma should not be here I am reinventing the wheel I guess *)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   992
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   993
lemma perm_basic[simp]:
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   994
 fixes x y::"name"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   995
shows "[(x,y)]\<bullet>y = x"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   996
using assms using calc_atm by perm_simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   997
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   998
lemma Q_Arrow_strong_inversion:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   999
  assumes fs:"x\<sharp>\<Gamma>" "x\<sharp>t" "x\<sharp>u" and h:"\<Gamma> \<turnstile> t <=> u : T1\<rightarrow>T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1000
  shows "(x,T1)#\<Gamma> \<turnstile> App t (Var x) <=> App u (Var x) : T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1001
proof -
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1002
  obtain y where  fs2:"y\<sharp>\<Gamma>" "y\<sharp>u" "y\<sharp>t" and "(y,T1)#\<Gamma> \<turnstile> App t (Var y) <=> App u (Var y) : T2" 
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1003
    using h by auto
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1004
  then have "([(x,y)]\<bullet>((y,T1)#\<Gamma>)) \<turnstile> [(x,y)]\<bullet> App t (Var y) <=> [(x,y)]\<bullet> App u (Var y) : T2" 
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1005
    using Q_eqvt by blast
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1006
  then show ?thesis using fs fs2 by (perm_simp)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1007
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1008
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1009
lemma fresh_context: 
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1010
  fixes  \<Gamma> :: "(name\<times>ty) list"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1011
  and    a :: "name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1012
  assumes "a\<sharp>\<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1013
  shows "\<not>(\<exists>\<tau>::ty. (a,\<tau>)\<in>set \<Gamma>)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1014
using assms by(induct \<Gamma>, auto simp add: fresh_prod fresh_list_cons fresh_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1015
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1016
lemma type_unicity_in_context:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1017
  fixes  \<Gamma> :: "(name\<times>ty)list"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1018
  and    pi:: "name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1019
  and    a :: "name"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1020
  and    \<tau> :: "ty"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1021
  assumes "valid \<Gamma>" and "(x,T1) \<in> set \<Gamma>" and "(x,T2) \<in> set \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1022
  shows "T1=T2"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1023
using assms by (induct \<Gamma>, auto dest!: fresh_context)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1024
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1025
(* 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1026
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1027
Warning: This lemma is false.
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1028
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1029
lemma algorithmic_type_unicity:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1030
  shows "\<lbrakk> \<Gamma> \<turnstile> s <=> t : T ; \<Gamma> \<turnstile> s <=> u : T' \<rbrakk> \<Longrightarrow> T = T'"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1031
  and "\<lbrakk> \<Gamma> \<turnstile> s \<leftrightarrow> t : T ; \<Gamma> \<turnstile> s \<leftrightarrow> u : T' \<rbrakk> \<Longrightarrow> T = T'"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1032
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1033
Here is the counter example : 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1034
\<Gamma> \<turnstile> Const n <=> Const n : Tbase and \<Gamma> \<turnstile> Const n <=> Const n : TUnit
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1035
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1036
*)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1037
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1038
lemma algorithmic_path_type_unicity:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1039
  shows "\<lbrakk> \<Gamma> \<turnstile> s \<leftrightarrow> t : T ; \<Gamma> \<turnstile> s \<leftrightarrow> u : T' \<rbrakk> \<Longrightarrow> T = T'"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1040
proof (induct arbitrary:  u T' 
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1041
       rule: alg_equiv_alg_path_equiv.inducts(2) [of _ _ _ _ _  "%a b c d . True"    ])
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1042
  case (QAP_Var \<Gamma> x T u T')
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1043
  have "\<Gamma> \<turnstile> Var x \<leftrightarrow> u : T'" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1044
  then have "u=Var x" and "(x,T') \<in> set \<Gamma>" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1045
  moreover have "valid \<Gamma>" "(x,T) \<in> set \<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1046
  ultimately show "T=T'" using type_unicity_in_context by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1047
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1048
  case (QAP_App \<Gamma> p q T1 T2 s t u T2')
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1049
  have ih:"\<And>u T. \<Gamma> \<turnstile> p \<leftrightarrow> u : T \<Longrightarrow> T1\<rightarrow>T2 = T" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1050
  have "\<Gamma> \<turnstile> App p s \<leftrightarrow> u : T2'" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1051
  then obtain r t T1' where "u = App r t"  "\<Gamma> \<turnstile> p \<leftrightarrow> r : T1' \<rightarrow> T2'" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1052
  then have "T1\<rightarrow>T2 = T1' \<rightarrow> T2'" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1053
  then show "T2=T2'" using ty.inject by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1054
qed (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1055
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1056
lemma algorithmic_transitivity:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1057
  shows "\<lbrakk> \<Gamma> \<turnstile> s <=> t : T ; \<Gamma> \<turnstile> t <=> u : T \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s <=> u : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1058
  and  "\<lbrakk> \<Gamma> \<turnstile> s \<leftrightarrow> t : T ; \<Gamma> \<turnstile> t \<leftrightarrow> u : T \<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s \<leftrightarrow> u : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1059
proof (nominal_induct \<Gamma> s t T and \<Gamma> s t T avoiding: u rule: alg_equiv_alg_path_equiv_strong_inducts)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1060
  case (QAT_Base s p t q \<Gamma> u)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1061
  have h:"s \<Down> p" "t \<Down> q" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1062
  have ih:"\<And>u. \<Gamma> \<turnstile> q \<leftrightarrow> u : TBase \<Longrightarrow> \<Gamma> \<turnstile> p \<leftrightarrow> u : TBase" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1063
  have "\<Gamma> \<turnstile> t <=> u : TBase" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1064
  then obtain r q' where hl:"t \<Down> q'" "u \<Down> r" "\<Gamma> \<turnstile> q' \<leftrightarrow> r : TBase" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1065
  moreover have eq:"q=q'" using nf_unicity hl h by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1066
  ultimately have "\<Gamma> \<turnstile> p \<leftrightarrow> r : TBase" using ih by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1067
  then show "\<Gamma> \<turnstile> s <=> u : TBase" using hl h by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1068
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1069
  case (QAT_Arrow  x \<Gamma> s t T1 T2 u)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1070
  have fs:"x\<sharp>\<Gamma>" "x\<sharp>s" "x\<sharp>t" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1071
  moreover have h:"\<Gamma> \<turnstile> t <=> u : T1\<rightarrow>T2" by fact
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1072
  moreover then obtain y where "y\<sharp>\<Gamma>" "y\<sharp>t" "y\<sharp>u" and "(y,T1)#\<Gamma> \<turnstile> App t (Var y) <=> App u (Var y) : T2" 
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1073
    by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1074
  moreover have fs2:"x\<sharp>u" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1075
  ultimately have "(x,T1)#\<Gamma> \<turnstile> App t (Var x) <=> App u (Var x) : T2" using Q_Arrow_strong_inversion by blast
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1076
  moreover have ih:"\<And> v. (x,T1)#\<Gamma> \<turnstile> App t (Var x) <=> v : T2 \<Longrightarrow> (x,T1)#\<Gamma> \<turnstile> App s (Var x) <=> v : T2" 
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1077
    by fact
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1078
  ultimately have "(x,T1)#\<Gamma> \<turnstile> App s (Var x) <=> App u (Var x) : T2" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1079
  then show "\<Gamma> \<turnstile> s <=> u : T1\<rightarrow>T2" using fs fs2 by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1080
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1081
  case (QAP_App \<Gamma> p q T1 T2 s t u)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1082
  have h1:"\<Gamma> \<turnstile> p \<leftrightarrow> q : T1\<rightarrow>T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1083
  have ih1:"\<And>u. \<Gamma> \<turnstile> q \<leftrightarrow> u : T1\<rightarrow>T2 \<Longrightarrow> \<Gamma> \<turnstile> p \<leftrightarrow> u : T1\<rightarrow>T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1084
  have "\<Gamma> \<turnstile> s <=> t : T1" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1085
  have ih2:"\<And>u. \<Gamma> \<turnstile> t <=> u : T1 \<Longrightarrow> \<Gamma> \<turnstile> s <=> u : T1" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1086
  have "\<Gamma> \<turnstile> App q t \<leftrightarrow> u : T2" by fact
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1087
  then obtain r T1' v where ha:"\<Gamma> \<turnstile> q \<leftrightarrow> r : T1'\<rightarrow>T2" and hb:"\<Gamma> \<turnstile> t <=> v : T1'" and eq:"u = App r v" 
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1088
    by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1089
  moreover have "\<Gamma> \<turnstile> q \<leftrightarrow> p : T1\<rightarrow>T2" using h1 algorithmic_path_symmetry by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1090
  ultimately have "T1'\<rightarrow>T2 = T1\<rightarrow>T2" using algorithmic_path_type_unicity by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1091
  then have "T1' = T1" using ty.inject by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1092
  then have "\<Gamma> \<turnstile> s <=> v : T1" "\<Gamma> \<turnstile> p \<leftrightarrow> r : T1\<rightarrow>T2" using ih1 ih2 ha hb by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1093
  then show "\<Gamma> \<turnstile> App p s \<leftrightarrow> u : T2" using eq by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1094
qed (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1095
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1096
lemma algorithmic_weak_head_closure:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1097
  shows "\<lbrakk>\<Gamma> \<turnstile> s <=> t : T ; s' \<leadsto> s; t' \<leadsto> t\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s' <=> t' : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1098
by (nominal_induct \<Gamma> s t T avoiding: s' t'  
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1099
    rule: alg_equiv_alg_path_equiv_strong_inducts(1) [of _ _ _ _ "%a b c d e. True"])
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1100
   (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1101
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1102
lemma logical_symmetry:
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1103
  assumes a: "\<Gamma> \<turnstile> s is t : T"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1104
  shows "\<Gamma> \<turnstile> t is s : T"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1105
using a 
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1106
by (nominal_induct arbitrary: \<Gamma> s t rule:ty.induct) (auto simp add: algorithmic_symmetry)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1107
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1108
lemma logical_transitivity:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1109
  assumes "\<Gamma> \<turnstile> s is t : T" "\<Gamma> \<turnstile> t is u : T" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1110
  shows "\<Gamma> \<turnstile> s is u : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1111
using assms
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1112
proof (nominal_induct arbitrary: \<Gamma> s t u  rule:ty.induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1113
  case TBase
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1114
  then show "\<Gamma> \<turnstile> s is u : TBase" by (auto elim:  algorithmic_transitivity)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1115
next 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1116
  case (Arrow T1 T2 \<Gamma> s t u)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1117
  have h1:"\<Gamma> \<turnstile> s is t : T1 \<rightarrow> T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1118
  have h2:"\<Gamma> \<turnstile> t is u : T1 \<rightarrow> T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1119
  have ih1:"\<And>\<Gamma> s t u. \<lbrakk>\<Gamma> \<turnstile> s is t : T1; \<Gamma> \<turnstile> t is u : T1\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s is u : T1" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1120
  have ih2:"\<And>\<Gamma> s t u. \<lbrakk>\<Gamma> \<turnstile> s is t : T2; \<Gamma> \<turnstile> t is u : T2\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s is u : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1121
  {
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1122
    fix \<Gamma>' s' u'
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1123
    assume hsub:"\<Gamma>\<lless>\<Gamma>'" and hl:"\<Gamma>' \<turnstile> s' is u' : T1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1124
    then have "\<Gamma>' \<turnstile> u' is s' : T1" using logical_symmetry by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1125
    then have "\<Gamma>' \<turnstile> u' is u' : T1" using ih1 hl by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1126
    then have "\<Gamma>' \<turnstile> App t u' is App u u' : T2" using h2 hsub by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1127
    moreover have "\<Gamma>' \<turnstile>  App s s' is App t u' : T2" using h1 hsub hl by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1128
    ultimately have "\<Gamma>' \<turnstile>  App s s' is App u u' : T2" using ih2 by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1129
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1130
  moreover have "valid \<Gamma>" using h1 alg_equiv_valid by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1131
  ultimately show "\<Gamma> \<turnstile> s is u : T1 \<rightarrow> T2" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1132
qed (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1133
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1134
lemma logical_weak_head_closure:
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1135
  assumes a: "\<Gamma> \<turnstile> s is t : T" "s' \<leadsto> s" "t' \<leadsto> t"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1136
  shows "\<Gamma> \<turnstile> s' is t' : T"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1137
using a
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1138
apply(nominal_induct arbitrary: \<Gamma> s t s' t' rule:ty.induct)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1139
apply(auto simp add: algorithmic_weak_head_closure)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1140
apply(blast)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1141
done
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1142
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1143
lemma logical_weak_head_closure':
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1144
  assumes "\<Gamma> \<turnstile> s is t : T" "s' \<leadsto> s" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1145
  shows "\<Gamma> \<turnstile> s' is t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1146
using assms
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1147
proof (nominal_induct arbitrary: \<Gamma> s t s' rule: ty.induct)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1148
  case (TBase  \<Gamma> s t s')
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1149
  then show ?case by force
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1150
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1151
  case (TUnit \<Gamma> s t s')
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1152
  then show ?case by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1153
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1154
  case (Arrow T1 T2 \<Gamma> s t s')
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1155
  have h1:"s' \<leadsto> s" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1156
  have ih:"\<And>\<Gamma> s t s'. \<lbrakk>\<Gamma> \<turnstile> s is t : T2; s' \<leadsto> s\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s' is t : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1157
  have h2:"\<Gamma> \<turnstile> s is t : T1\<rightarrow>T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1158
  then have hb:"\<forall>\<Gamma>' s' t'. \<Gamma>\<lless>\<Gamma>' \<longrightarrow> \<Gamma>' \<turnstile> s' is t' : T1 \<longrightarrow>  (\<Gamma>' \<turnstile> (App s s') is (App t t') : T2)" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1159
  {
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1160
    fix \<Gamma>' s2 t2
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1161
    assume "\<Gamma>\<lless>\<Gamma>'" and "\<Gamma>' \<turnstile> s2 is t2 : T1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1162
    then have "\<Gamma>' \<turnstile> (App s s2) is (App t t2) : T2" using hb by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1163
    moreover have "(App s' s2)  \<leadsto> (App s s2)" using h1 by auto  
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1164
    ultimately have "\<Gamma>' \<turnstile> App s' s2 is App t t2 : T2" using ih by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1165
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1166
  moreover have "valid \<Gamma>" using h2 log_equiv_valid by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1167
  ultimately show "\<Gamma> \<turnstile> s' is t : T1\<rightarrow>T2" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1168
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1169
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1170
abbreviation 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1171
 log_equiv_subst :: "(name\<times>ty) list \<Rightarrow> (name\<times>trm) list \<Rightarrow>  (name\<times>trm) list \<Rightarrow> (name\<times>ty) list \<Rightarrow> bool"  
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1172
                     ("_ \<turnstile> _ is _ over _" [60,60] 60) 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1173
where
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1174
  "\<Gamma>' \<turnstile> \<gamma> is \<delta> over \<Gamma> \<equiv> valid \<Gamma>' \<and> (\<forall>  x T. (x,T) \<in> set \<Gamma> \<longrightarrow> \<Gamma>' \<turnstile> \<gamma><Var x> is  \<delta><Var x> : T)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1175
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1176
lemma logical_pseudo_reflexivity:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1177
  assumes "\<Gamma>' \<turnstile> t is s over \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1178
  shows "\<Gamma>' \<turnstile> s is s over \<Gamma>" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1179
proof -
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1180
  have "\<Gamma>' \<turnstile> t is s over \<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1181
  moreover then have "\<Gamma>' \<turnstile> s is t over \<Gamma>" using logical_symmetry by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1182
  ultimately show "\<Gamma>' \<turnstile> s is s over \<Gamma>" using logical_transitivity by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1183
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1184
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1185
lemma logical_subst_monotonicity :
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1186
  fixes \<Gamma>::"(name\<times>ty) list"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1187
  and   \<Gamma>'::"(name\<times>ty) list"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1188
  and   \<Gamma>''::"(name\<times>ty) list"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1189
  assumes "\<Gamma>' \<turnstile> s is t over \<Gamma>" "\<Gamma>'\<lless>\<Gamma>''"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1190
  shows "\<Gamma>'' \<turnstile> s is t over \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1191
  using assms logical_monotonicity by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1192
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1193
lemma equiv_subst_ext :
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1194
  assumes h1:"\<Gamma>' \<turnstile> \<gamma> is \<delta> over \<Gamma>" and h2:"\<Gamma>' \<turnstile> s is t : T" and fs:"x\<sharp>\<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1195
  shows "\<Gamma>' \<turnstile> (x,s)#\<gamma> is (x,t)#\<delta> over (x,T)#\<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1196
using assms
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1197
proof -
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1198
{
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1199
  fix y U
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1200
  assume "(y,U) \<in> set ((x,T)#\<Gamma>)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1201
  moreover
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1202
  { 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1203
    assume "(y,U) \<in> set [(x,T)]"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1204
    then have "\<Gamma>' \<turnstile> (x,s)#\<gamma><Var y> is (x,t)#\<delta><Var y> : U" by auto 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1205
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1206
  moreover
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1207
  {
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1208
    assume hl:"(y,U) \<in> set \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1209
    then have "\<not> y\<sharp>\<Gamma>" by (induct \<Gamma>) (auto simp add: fresh_list_cons fresh_atm fresh_prod)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1210
    then have hf:"x\<sharp> Var y" using fs by (auto simp add: fresh_atm)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1211
    then have "(x,s)#\<gamma><Var y> = \<gamma><Var y>" "(x,t)#\<delta><Var y> = \<delta><Var y>" using fresh_psubst_simpl by blast+ 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1212
    moreover have  "\<Gamma>' \<turnstile> \<gamma><Var y> is \<delta><Var y> : U" using h1 hl by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1213
    ultimately have "\<Gamma>' \<turnstile> (x,s)#\<gamma><Var y> is (x,t)#\<delta><Var y> : U" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1214
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1215
  ultimately have "\<Gamma>' \<turnstile> (x,s)#\<gamma><Var y> is (x,t)#\<delta><Var y> : U" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1216
}
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1217
moreover have "valid \<Gamma>'" using h2 log_equiv_valid by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1218
ultimately show "\<Gamma>' \<turnstile> (x,s)#\<gamma> is (x,t)#\<delta> over (x,T)#\<Gamma>" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1219
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1220
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1221
theorem fundamental_theorem:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1222
  assumes "\<Gamma> \<turnstile> t : T" "\<Gamma>' \<turnstile> \<gamma> is \<theta> over \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1223
  shows "\<Gamma>' \<turnstile> \<gamma><t> is \<theta><t> : T"   
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1224
using assms
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1225
proof (nominal_induct avoiding:\<Gamma>' \<gamma> \<theta>  rule: typing_induct_strong)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1226
case (t_Lam x \<Gamma> T1 t2 T2 \<Gamma>' \<gamma> \<theta>)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1227
have fs:"x\<sharp>\<gamma>" "x\<sharp>\<theta>" "x\<sharp>\<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1228
have h:"\<Gamma>' \<turnstile> \<gamma> is \<theta> over \<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1229
have ih:"\<And> \<Gamma>' \<gamma> \<theta>. \<Gamma>' \<turnstile> \<gamma> is \<theta> over (x,T1)#\<Gamma> \<Longrightarrow> \<Gamma>' \<turnstile> \<gamma><t2> is \<theta><t2> : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1230
{
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1231
  fix \<Gamma>'' s' t'
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1232
  assume "\<Gamma>'\<lless>\<Gamma>''" and hl:"\<Gamma>''\<turnstile> s' is t' : T1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1233
  then have "\<Gamma>'' \<turnstile> \<gamma> is \<theta> over \<Gamma>" using logical_subst_monotonicity h by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1234
  then have "\<Gamma>'' \<turnstile> (x,s')#\<gamma> is (x,t')#\<theta> over (x,T1)#\<Gamma>" using equiv_subst_ext hl fs by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1235
  then have "\<Gamma>'' \<turnstile> (x,s')#\<gamma><t2> is (x,t')#\<theta><t2> : T2" using ih by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1236
  then have "\<Gamma>''\<turnstile>\<gamma><t2>[x::=s'] is \<theta><t2>[x::=t'] : T2" using psubst_subst_psubst fs by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1237
  moreover have "App (Lam [x].\<gamma><t2>) s' \<leadsto> \<gamma><t2>[x::=s']" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1238
  moreover have "App (Lam [x].\<theta><t2>) t' \<leadsto> \<theta><t2>[x::=t']" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1239
  ultimately have "\<Gamma>''\<turnstile> App (Lam [x].\<gamma><t2>) s' is App (Lam [x].\<theta><t2>) t' : T2" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1240
    using logical_weak_head_closure by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1241
}
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1242
moreover have "valid \<Gamma>'" using h by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1243
ultimately show "\<Gamma>' \<turnstile> \<gamma><Lam [x].t2> is \<theta><Lam [x].t2> : T1\<rightarrow>T2" using fs by auto 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1244
qed (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1245
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1246
theorem fundamental_theorem_2:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1247
  assumes h1: "\<Gamma> \<turnstile> s == t : T" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1248
  and     h2: "\<Gamma>' \<turnstile> \<gamma> is \<theta> over \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1249
  shows "\<Gamma>' \<turnstile> \<gamma><s> is \<theta><t> : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1250
using h1 h2
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1251
proof (nominal_induct \<Gamma> s t T avoiding: \<Gamma>' \<gamma> \<theta> rule: equiv_def_strong_induct)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1252
  case (Q_Refl \<Gamma> t T \<Gamma>' \<gamma> \<theta>)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1253
  have "\<Gamma> \<turnstile> t : T" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1254
  moreover have "\<Gamma>' \<turnstile> \<gamma> is \<theta> over \<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1255
  ultimately show "\<Gamma>' \<turnstile> \<gamma><t> is \<theta><t> : T" using fundamental_theorem by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1256
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1257
  case (Q_Symm \<Gamma> t s T \<Gamma>' \<gamma> \<theta>)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1258
  have "\<Gamma>' \<turnstile> \<gamma> is \<theta> over \<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1259
  moreover have ih:"\<And> \<Gamma>' \<gamma> \<theta>. \<Gamma>' \<turnstile> \<gamma> is \<theta> over \<Gamma> \<Longrightarrow> \<Gamma>' \<turnstile> \<gamma><t> is \<theta><s> : T" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1260
  ultimately show "\<Gamma>' \<turnstile> \<gamma><s> is \<theta><t> : T" using logical_symmetry by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1261
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1262
  case (Q_Trans \<Gamma> s t T u \<Gamma>' \<gamma> \<theta>)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1263
  have ih1:"\<And> \<Gamma>' \<gamma> \<theta>. \<Gamma>' \<turnstile> \<gamma> is \<theta> over \<Gamma> \<Longrightarrow> \<Gamma>' \<turnstile> \<gamma><s> is \<theta><t> : T" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1264
  have ih2:"\<And> \<Gamma>' \<gamma> \<theta>. \<Gamma>' \<turnstile> \<gamma> is \<theta> over \<Gamma> \<Longrightarrow> \<Gamma>' \<turnstile> \<gamma><t> is \<theta><u> : T" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1265
  have h:"\<Gamma>' \<turnstile> \<gamma> is \<theta> over \<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1266
  then have "\<Gamma>' \<turnstile> \<theta> is \<theta> over \<Gamma>" using logical_pseudo_reflexivity by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1267
  then have "\<Gamma>' \<turnstile> \<theta><t> is \<theta><u> : T" using ih2 by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1268
  moreover have "\<Gamma>' \<turnstile> \<gamma><s> is \<theta><t> : T" using ih1 h by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1269
  ultimately show "\<Gamma>' \<turnstile> \<gamma><s> is \<theta><u> : T" using logical_transitivity by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1270
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1271
  case (Q_Abs x \<Gamma> T1 s2 t2 T2 \<Gamma>' \<gamma> \<theta>)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1272
  have fs:"x\<sharp>\<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1273
  have fs2: "x\<sharp>\<gamma>" "x\<sharp>\<theta>" by fact 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1274
  have h1:"(x,T1)#\<Gamma> \<turnstile> s2 == t2 : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1275
  have h2:"\<Gamma>' \<turnstile> \<gamma> is \<theta> over \<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1276
  have ih:"\<And>\<Gamma>' \<gamma> \<theta>. \<Gamma>' \<turnstile> \<gamma> is \<theta> over (x,T1)#\<Gamma> \<Longrightarrow> \<Gamma>' \<turnstile> \<gamma><s2> is \<theta><t2> : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1277
  {
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1278
    fix \<Gamma>'' s' t'
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1279
    assume "\<Gamma>'\<lless>\<Gamma>''" and hl:"\<Gamma>''\<turnstile> s' is t' : T1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1280
    then have "\<Gamma>'' \<turnstile> \<gamma> is \<theta> over \<Gamma>" using h2 logical_subst_monotonicity by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1281
    then have "\<Gamma>'' \<turnstile> (x,s')#\<gamma> is (x,t')#\<theta> over (x,T1)#\<Gamma>" using equiv_subst_ext hl fs by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1282
    then have "\<Gamma>'' \<turnstile> (x,s')#\<gamma><s2> is (x,t')#\<theta><t2> : T2" using ih by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1283
    then have "\<Gamma>''\<turnstile> \<gamma><s2>[x::=s'] is \<theta><t2>[x::=t'] : T2" using fs2 psubst_subst_psubst by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1284
    moreover have "App (Lam [x]. \<gamma><s2>) s' \<leadsto>  \<gamma><s2>[x::=s']" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1285
              and "App (Lam [x].\<theta><t2>) t' \<leadsto> \<theta><t2>[x::=t']" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1286
    ultimately have "\<Gamma>'' \<turnstile> App (Lam [x]. \<gamma><s2>) s' is App (Lam [x].\<theta><t2>) t' : T2" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1287
      using logical_weak_head_closure by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1288
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1289
  moreover have "valid \<Gamma>'" using h2 by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1290
  ultimately have "\<Gamma>' \<turnstile> Lam [x].\<gamma><s2> is Lam [x].\<theta><t2> : T1\<rightarrow>T2" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1291
  then show "\<Gamma>' \<turnstile> \<gamma><Lam [x].s2> is \<theta><Lam [x].t2> : T1\<rightarrow>T2" using fs2 by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1292
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1293
  case (Q_App \<Gamma> s1 t1 T1 T2 s2 t2 \<Gamma>' \<gamma> \<theta>)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1294
  then show "\<Gamma>' \<turnstile> \<gamma><App s1 s2> is \<theta><App t1 t2> : T2" by auto 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1295
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1296
  case (Q_Beta x \<Gamma> T1 s12 t12 T2 s2 t2 \<Gamma>' \<gamma> \<theta>)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1297
  have h:"\<Gamma>' \<turnstile> \<gamma> is \<theta> over \<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1298
  have fs:"x\<sharp>\<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1299
  have fs2:"x\<sharp>\<gamma>" "x\<sharp>\<theta>" by fact 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1300
  have ih1:"\<And>\<Gamma>' \<gamma> \<theta>. \<Gamma>' \<turnstile> \<gamma> is \<theta> over \<Gamma> \<Longrightarrow> \<Gamma>' \<turnstile> \<gamma><s2> is \<theta><t2> : T1" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1301
  have ih2:"\<And>\<Gamma>' \<gamma> \<theta>. \<Gamma>' \<turnstile> \<gamma> is \<theta> over (x,T1)#\<Gamma> \<Longrightarrow> \<Gamma>' \<turnstile> \<gamma><s12> is \<theta><t12> : T2" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1302
  have "\<Gamma>' \<turnstile> \<gamma><s2> is \<theta><t2> : T1" using ih1 h by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1303
  then have "\<Gamma>' \<turnstile> (x,\<gamma><s2>)#\<gamma> is (x,\<theta><t2>)#\<theta> over (x,T1)#\<Gamma>" using equiv_subst_ext h fs by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1304
  then have "\<Gamma>' \<turnstile> (x,\<gamma><s2>)#\<gamma><s12> is (x,\<theta><t2>)#\<theta><t12> : T2" using ih2 by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1305
  then have "\<Gamma>' \<turnstile> \<gamma><s12>[x::=\<gamma><s2>] is \<theta><t12>[x::=\<theta><t2>] : T2" using fs2 psubst_subst_psubst by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1306
  then have "\<Gamma>' \<turnstile> \<gamma><s12>[x::=\<gamma><s2>] is \<theta><t12[x::=t2]> : T2" using fs2 psubst_subst_propagate by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1307
  moreover have "App (Lam [x].\<gamma><s12>) (\<gamma><s2>) \<leadsto> \<gamma><s12>[x::=\<gamma><s2>]" by auto 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1308
  ultimately have "\<Gamma>' \<turnstile> App (Lam [x].\<gamma><s12>) (\<gamma><s2>) is \<theta><t12[x::=t2]> : T2" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1309
    using logical_weak_head_closure' by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1310
  then show "\<Gamma>' \<turnstile> \<gamma><App (Lam [x].s12) s2> is \<theta><t12[x::=t2]> : T2" using fs2 by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1311
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1312
  case (Q_Ext x \<Gamma> s t T1 T2 \<Gamma>' \<gamma> \<theta>)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1313
  have h2:"\<Gamma>' \<turnstile> \<gamma> is \<theta> over \<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1314
  have fs:"x\<sharp>\<Gamma>" "x\<sharp>s" "x\<sharp>t" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1315
  have ih:"\<And>\<Gamma>' \<gamma> \<theta>. \<Gamma>' \<turnstile> \<gamma> is \<theta> over (x,T1)#\<Gamma> \<Longrightarrow> \<Gamma>' \<turnstile> \<gamma><App s (Var x)> is \<theta><App t (Var x)> : T2" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1316
    by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1317
   {
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1318
    fix \<Gamma>'' s' t'
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1319
    assume hsub:"\<Gamma>'\<lless>\<Gamma>''" and hl:"\<Gamma>''\<turnstile> s' is t' : T1"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1320
    then have "\<Gamma>'' \<turnstile> \<gamma> is \<theta> over \<Gamma>" using h2 logical_subst_monotonicity by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1321
    then have "\<Gamma>'' \<turnstile> (x,s')#\<gamma> is (x,t')#\<theta> over (x,T1)#\<Gamma>" using equiv_subst_ext hl fs by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1322
    then have "\<Gamma>'' \<turnstile> (x,s')#\<gamma><App s (Var x)>  is (x,t')#\<theta><App t (Var x)> : T2" using ih by blast
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1323
    then have "\<Gamma>'' \<turnstile> App (((x,s')#\<gamma>)<s>) (((x,s')#\<gamma>)<(Var x)>) is App ((x,t')#\<theta><t>) ((x,t')#\<theta><(Var x)>) : T2"
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1324
      by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1325
    then have "\<Gamma>'' \<turnstile> App ((x,s')#\<gamma><s>) s'  is App ((x,t')#\<theta><t>) t' : T2" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1326
    then have "\<Gamma>'' \<turnstile> App (\<gamma><s>) s' is App (\<theta><t>) t' : T2" using fs fresh_psubst_simpl by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1327
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1328
  moreover have "valid \<Gamma>'" using h2 by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1329
  ultimately show "\<Gamma>' \<turnstile> \<gamma><s> is \<theta><t> : T1\<rightarrow>T2" by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1330
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1331
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1332
theorem completeness:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1333
  assumes "\<Gamma> \<turnstile> s == t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1334
  shows "\<Gamma> \<turnstile> s <=> t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1335
using assms
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1336
proof -
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1337
  {
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1338
    fix x T
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1339
    assume "(x,T) \<in> set \<Gamma>" "valid \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1340
    then have "\<Gamma> \<turnstile> Var x is Var x : T" using main_lemma by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1341
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1342
  moreover have "valid \<Gamma>" using equiv_def_valid assms by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1343
  ultimately have "\<Gamma> \<turnstile> [] is [] over \<Gamma>" by auto 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1344
  then have "\<Gamma> \<turnstile> []<s> is []<t> : T" using fundamental_theorem_2 assms by blast
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1345
  then have "\<Gamma> \<turnstile> s is t : T" by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1346
  then show  "\<Gamma> \<turnstile> s <=> t : T" using main_lemma by simp
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1347
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1348
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1349
(* Soundness is left as an exercise - like in the book - for the avid formalist 
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1350
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1351
theorem soundness:
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1352
  shows "\<lbrakk>\<Gamma> \<turnstile> s <=> t : T; \<Gamma> \<turnstile> t : T; \<Gamma> \<turnstile> s : T\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s == t : T"
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1353
  and   "\<lbrakk>\<Gamma> \<turnstile> s \<leftrightarrow> t : T; \<Gamma> \<turnstile> t : T; \<Gamma> \<turnstile> s : T\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s == t : T"
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
  1354
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1355
*)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1356
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1357
end
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
  1358