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