src/HOL/Nominal/Examples/Crary.thy
author boehmes
Wed, 02 Sep 2009 21:31:58 +0200
changeset 32498 1132c7c13f36
parent 29097 68245155eb58
child 32638 d9bd7e01a681
permissions -rw-r--r--
Mirabelle: actions are responsible for handling exceptions, Mirabelle core logs only structural information, measuring running times for sledgehammer and subsequent metis invocation, Mirabelle produces reports for every theory (only for sledgehammer at the moment)
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
(*                                                    *)
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
     2
(* Formalisation of the chapter on Logical Relations  *)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
     3
(* and a Case Study in Equivalence Checking           *)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
     4
(* by Karl Crary from the book on Advanced Topics in  *)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
     5
(* Types and Programming Languages, MIT Press 2005    *)
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
     6
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
     7
(* The formalisation was done by Julien Narboux and   *)
22594
33a690455f88 add a few details in the Fst and Snd cases of unicity proof
narboux
parents: 22542
diff changeset
     8
(* Christian Urban.                                   *)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
     9
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    10
theory Crary
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
    11
  imports "../Nominal"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    12
begin
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    13
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    14
atom_decl name 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    15
22829
f1db55c7534d tuned some proofs and changed variable names in some definitions of Nominal.thy
urbanc
parents: 22730
diff changeset
    16
nominal_datatype ty = 
f1db55c7534d tuned some proofs and changed variable names in some definitions of Nominal.thy
urbanc
parents: 22730
diff changeset
    17
    TBase 
f1db55c7534d tuned some proofs and changed variable names in some definitions of Nominal.thy
urbanc
parents: 22730
diff changeset
    18
  | TUnit 
f1db55c7534d tuned some proofs and changed variable names in some definitions of Nominal.thy
urbanc
parents: 22730
diff changeset
    19
  | Arrow "ty" "ty" ("_\<rightarrow>_" [100,100] 100)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    20
22829
f1db55c7534d tuned some proofs and changed variable names in some definitions of Nominal.thy
urbanc
parents: 22730
diff changeset
    21
nominal_datatype trm = 
f1db55c7534d tuned some proofs and changed variable names in some definitions of Nominal.thy
urbanc
parents: 22730
diff changeset
    22
    Unit
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
    23
  | Var "name" ("Var _" [100] 100)
22829
f1db55c7534d tuned some proofs and changed variable names in some definitions of Nominal.thy
urbanc
parents: 22730
diff changeset
    24
  | Lam "\<guillemotleft>name\<guillemotright>trm" ("Lam [_]._" [100,100] 100)
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
    25
  | App "trm" "trm" ("App _ _" [110,110] 100)
22829
f1db55c7534d tuned some proofs and changed variable names in some definitions of Nominal.thy
urbanc
parents: 22730
diff changeset
    26
  | Const "nat"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    27
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    28
types Ctxt  = "(name\<times>ty) list"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    29
types Subst = "(name\<times>trm) list" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    30
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    31
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    32
lemma perm_ty[simp]: 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    33
  fixes T::"ty"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    34
  and   pi::"name prm"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    35
  shows "pi\<bullet>T = T"
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
    36
  by (induct T rule: ty.induct) (simp_all)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    37
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    38
lemma fresh_ty[simp]:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    39
  fixes x::"name" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    40
  and   T::"ty"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    41
  shows "x\<sharp>T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    42
  by (simp add: fresh_def supp_def)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    43
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    44
lemma ty_cases:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    45
  fixes T::ty
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
    46
  shows "(\<exists> T\<^isub>1 T\<^isub>2. T=T\<^isub>1\<rightarrow>T\<^isub>2) \<or> T=TUnit \<or> T=TBase"
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
    47
by (induct T rule:ty.induct) (auto)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    48
29097
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
    49
instantiation ty :: size
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
    50
begin
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    51
29097
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
    52
nominal_primrec size_ty
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
    53
where
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    54
  "size (TBase) = 1"
29097
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
    55
| "size (TUnit) = 1"
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
    56
| "size (T\<^isub>1\<rightarrow>T\<^isub>2) = size T\<^isub>1 + size T\<^isub>2"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    57
by (rule TrueI)+
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    58
29097
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
    59
instance ..
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
    60
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
    61
end
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
    62
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    63
lemma ty_size_greater_zero[simp]:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    64
  fixes T::"ty"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    65
  shows "size T > 0"
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
    66
by (nominal_induct rule: ty.strong_induct) (simp_all)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
    67
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    68
section {* Substitutions *}
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    69
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    70
fun
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    71
  lookup :: "Subst \<Rightarrow> name \<Rightarrow> trm"   
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    72
where
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    73
  "lookup [] x        = Var x"
22501
cb41c397a699 fixed function syntax
krauss
parents: 22494
diff changeset
    74
| "lookup ((y,T)#\<theta>) x = (if x=y then T else lookup \<theta> x)"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    75
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    76
lemma lookup_eqvt[eqvt]:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    77
  fixes pi::"name prm"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    78
  shows "pi\<bullet>(lookup \<theta> x) = lookup (pi\<bullet>\<theta>) (pi\<bullet>x)"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    79
by (induct \<theta>) (auto simp add: perm_bij)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    80
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    81
lemma lookup_fresh:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    82
  fixes z::"name"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    83
  assumes a: "z\<sharp>\<theta>" "z\<sharp>x"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    84
  shows "z\<sharp> lookup \<theta> x"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    85
using a
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    86
by (induct rule: lookup.induct) 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    87
   (auto simp add: fresh_list_cons)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    88
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    89
lemma lookup_fresh':
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    90
  assumes a: "z\<sharp>\<theta>"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    91
  shows "lookup \<theta> z = Var z"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    92
using a
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    93
by (induct rule: lookup.induct)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    94
   (auto simp add: fresh_list_cons fresh_prod fresh_atm)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    95
 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    96
nominal_primrec
29097
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
    97
  psubst :: "Subst \<Rightarrow> trm \<Rightarrow> trm"  ("_<_>" [100,100] 130)
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
    98
where
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
    99
  "\<theta><(Var x)> = (lookup \<theta> x)"
29097
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
   100
| "\<theta><(App t\<^isub>1 t\<^isub>2)> = App \<theta><t\<^isub>1> \<theta><t\<^isub>2>"
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
   101
| "x\<sharp>\<theta> \<Longrightarrow> \<theta><(Lam [x].t)> = Lam [x].(\<theta><t>)"
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
   102
| "\<theta><(Const n)> = Const n"
68245155eb58 Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents: 28042
diff changeset
   103
| "\<theta><(Unit)> = Unit"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   104
apply(finite_guess)+
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   105
apply(rule TrueI)+
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   106
apply(simp add: abs_fresh)+
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   107
apply(fresh_guess)+
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   108
done
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   109
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   110
abbreviation 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   111
 subst :: "trm \<Rightarrow> name \<Rightarrow> trm \<Rightarrow> trm" ("_[_::=_]" [100,100,100] 100)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   112
where
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   113
  "t[x::=t']  \<equiv> ([(x,t')])<t>" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   114
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   115
lemma subst[simp]:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   116
  shows "(Var x)[y::=t'] = (if x=y then t' else (Var x))"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   117
  and   "(App t\<^isub>1 t\<^isub>2)[y::=t'] = App (t\<^isub>1[y::=t']) (t\<^isub>2[y::=t'])"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   118
  and   "x\<sharp>(y,t') \<Longrightarrow> (Lam [x].t)[y::=t'] = Lam [x].(t[y::=t'])"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   119
  and   "Const n[y::=t'] = Const n"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   120
  and   "Unit [y::=t'] = Unit"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   121
  by (simp_all add: fresh_list_cons fresh_list_nil)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   122
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   123
lemma subst_eqvt[eqvt]:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   124
  fixes pi::"name prm" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   125
  shows "pi\<bullet>(t[x::=t']) = (pi\<bullet>t)[(pi\<bullet>x)::=(pi\<bullet>t')]"
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   126
  by (nominal_induct t avoiding: x t' rule: trm.strong_induct)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   127
     (perm_simp add: fresh_bij)+
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   128
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   129
lemma subst_rename: 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   130
  fixes c::"name"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   131
  assumes a: "c\<sharp>t\<^isub>1"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   132
  shows "t\<^isub>1[a::=t\<^isub>2] = ([(c,a)]\<bullet>t\<^isub>1)[c::=t\<^isub>2]"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   133
using a
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   134
apply(nominal_induct t\<^isub>1 avoiding: a c t\<^isub>2 rule: trm.strong_induct)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   135
apply(simp add: trm.inject calc_atm fresh_atm abs_fresh perm_nat_def)+
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   136
done
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   137
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   138
lemma fresh_psubst: 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   139
  fixes z::"name"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   140
  assumes a: "z\<sharp>t" "z\<sharp>\<theta>"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   141
  shows "z\<sharp>(\<theta><t>)"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   142
using a
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   143
by (nominal_induct t avoiding: z \<theta> t rule: trm.strong_induct)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   144
   (auto simp add: abs_fresh lookup_fresh)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   145
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   146
lemma fresh_subst'':
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   147
  fixes z::"name"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   148
  assumes "z\<sharp>t\<^isub>2"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   149
  shows "z\<sharp>t\<^isub>1[z::=t\<^isub>2]"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   150
using assms 
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   151
by (nominal_induct t\<^isub>1 avoiding: t\<^isub>2 z rule: trm.strong_induct)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   152
   (auto simp add: abs_fresh fresh_nat fresh_atm)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   153
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   154
lemma fresh_subst':
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   155
  fixes z::"name"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   156
  assumes "z\<sharp>[y].t\<^isub>1" "z\<sharp>t\<^isub>2"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   157
  shows "z\<sharp>t\<^isub>1[y::=t\<^isub>2]"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   158
using assms 
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   159
by (nominal_induct t\<^isub>1 avoiding: y t\<^isub>2 z rule: trm.strong_induct)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   160
   (auto simp add: abs_fresh fresh_nat fresh_atm)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   161
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   162
lemma fresh_subst:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   163
  fixes z::"name"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   164
  assumes a: "z\<sharp>t\<^isub>1" "z\<sharp>t\<^isub>2"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   165
  shows "z\<sharp>t\<^isub>1[y::=t\<^isub>2]"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   166
using a 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   167
by (auto simp add: fresh_subst' abs_fresh) 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   168
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   169
lemma fresh_psubst_simp:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   170
  assumes "x\<sharp>t"
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   171
  shows "((x,u)#\<theta>)<t> = \<theta><t>" 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   172
using assms
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   173
proof (nominal_induct t avoiding: x u \<theta> rule: trm.strong_induct)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   174
  case (Lam y t x u)
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   175
  have fs: "y\<sharp>\<theta>" "y\<sharp>x" "y\<sharp>u" by fact+
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   176
  moreover have "x\<sharp> Lam [y].t" by fact 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   177
  ultimately have "x\<sharp>t" by (simp add: abs_fresh fresh_atm)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   178
  moreover have ih:"\<And>n T. n\<sharp>t \<Longrightarrow> ((n,T)#\<theta>)<t> = \<theta><t>" by fact
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   179
  ultimately have "((x,u)#\<theta>)<t> = \<theta><t>" by auto
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   180
  moreover have "((x,u)#\<theta>)<Lam [y].t> = Lam [y].(((x,u)#\<theta>)<t>)" using fs 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   181
    by (simp add: fresh_list_cons fresh_prod)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   182
  moreover have " \<theta><Lam [y].t> = Lam [y]. (\<theta><t>)" using fs by simp
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   183
  ultimately show "((x,u)#\<theta>)<Lam [y].t> = \<theta><Lam [y].t>" by auto
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   184
qed (auto simp add: fresh_atm abs_fresh)
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   185
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   186
lemma forget: 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   187
  fixes x::"name"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   188
  assumes a: "x\<sharp>t" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   189
  shows "t[x::=t'] = t"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   190
  using a
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   191
by (nominal_induct t avoiding: x t' rule: trm.strong_induct)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   192
   (auto simp add: fresh_atm abs_fresh)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   193
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   194
lemma subst_fun_eq:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   195
  fixes u::trm
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   196
  assumes h:"[x].t\<^isub>1 = [y].t\<^isub>2"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   197
  shows "t\<^isub>1[x::=u] = t\<^isub>2[y::=u]"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   198
proof -
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   199
  { 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   200
    assume "x=y" and "t\<^isub>1=t\<^isub>2"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   201
    then have ?thesis using h by simp
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   202
  }
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   203
  moreover 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   204
  {
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   205
    assume h1:"x \<noteq> y" and h2:"t\<^isub>1=[(x,y)] \<bullet> t\<^isub>2" and h3:"x \<sharp> t\<^isub>2"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   206
    then have "([(x,y)] \<bullet> t\<^isub>2)[x::=u] = t\<^isub>2[y::=u]" by (simp add: subst_rename)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   207
    then have ?thesis using h2 by simp 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   208
  }
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   209
  ultimately show ?thesis using alpha h by blast
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   210
qed
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   211
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   212
lemma psubst_empty[simp]:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   213
  shows "[]<t> = t"
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   214
by (nominal_induct t rule: trm.strong_induct) 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   215
   (auto simp add: fresh_list_nil)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   216
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   217
lemma psubst_subst_psubst:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   218
  assumes h:"c\<sharp>\<theta>"
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   219
  shows "\<theta><t>[c::=s] = ((c,s)#\<theta>)<t>"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   220
  using h
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   221
by (nominal_induct t avoiding: \<theta> c s rule: trm.strong_induct)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   222
   (auto simp add: fresh_list_cons fresh_atm forget lookup_fresh lookup_fresh' fresh_psubst)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   223
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   224
lemma subst_fresh_simp:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   225
  assumes a: "x\<sharp>\<theta>"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   226
  shows "\<theta><Var x> = Var x"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   227
using a
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   228
by (induct \<theta> arbitrary: x, auto simp add:fresh_list_cons fresh_prod fresh_atm)
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   229
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   230
lemma psubst_subst_propagate: 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   231
  assumes "x\<sharp>\<theta>" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   232
  shows "\<theta><t[x::=u]> = \<theta><t>[x::=\<theta><u>]"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   233
using assms
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   234
proof (nominal_induct t avoiding: x u \<theta> rule: trm.strong_induct)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   235
  case (Var n x u \<theta>)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   236
  { assume "x=n"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   237
    moreover have "x\<sharp>\<theta>" by fact 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   238
    ultimately have "\<theta><Var n[x::=u]> = \<theta><Var n>[x::=\<theta><u>]" using subst_fresh_simp by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   239
  }
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   240
  moreover 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   241
  { assume h:"x\<noteq>n"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   242
    then have "x\<sharp>Var n" by (auto simp add: fresh_atm) 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   243
    moreover have "x\<sharp>\<theta>" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   244
    ultimately have "x\<sharp>\<theta><Var n>" using fresh_psubst by blast
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   245
    then have " \<theta><Var n>[x::=\<theta><u>] =  \<theta><Var n>" using forget by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   246
    then have "\<theta><Var n[x::=u]> = \<theta><Var n>[x::=\<theta><u>]" using h by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   247
  }
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   248
  ultimately show ?case by auto  
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   249
next
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   250
  case (Lam n t x u \<theta>)
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   251
  have fs:"n\<sharp>x" "n\<sharp>u" "n\<sharp>\<theta>" "x\<sharp>\<theta>" by fact+
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   252
  have ih:"\<And> y s \<theta>. y\<sharp>\<theta> \<Longrightarrow> ((\<theta><(t[y::=s])>) = ((\<theta><t>)[y::=(\<theta><s>)]))" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   253
  have "\<theta> <(Lam [n].t)[x::=u]> = \<theta><Lam [n]. (t [x::=u])>" using fs by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   254
  then have "\<theta> <(Lam [n].t)[x::=u]> = Lam [n]. \<theta><t [x::=u]>" using fs by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   255
  moreover have "\<theta><t[x::=u]> = \<theta><t>[x::=\<theta><u>]" using ih fs by blast
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   256
  ultimately have "\<theta> <(Lam [n].t)[x::=u]> = Lam [n].(\<theta><t>[x::=\<theta><u>])" by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   257
  moreover have "Lam [n].(\<theta><t>[x::=\<theta><u>]) = (Lam [n].\<theta><t>)[x::=\<theta><u>]" using fs fresh_psubst by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   258
  ultimately have "\<theta><(Lam [n].t)[x::=u]> = (Lam [n].\<theta><t>)[x::=\<theta><u>]" using fs by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   259
  then show "\<theta><(Lam [n].t)[x::=u]> = \<theta><Lam [n].t>[x::=\<theta><u>]" using fs by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   260
qed (auto)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   261
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   262
section {* Typing *}
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   263
23760
aca2c7f80e2f Renamed inductive2 to inductive.
berghofe
parents: 23450
diff changeset
   264
inductive
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   265
  valid :: "Ctxt \<Rightarrow> bool"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   266
where
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   267
  v_nil[intro]:  "valid []"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   268
| v_cons[intro]: "\<lbrakk>valid \<Gamma>;a\<sharp>\<Gamma>\<rbrakk> \<Longrightarrow> valid ((a,T)#\<Gamma>)"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   269
22538
3ccb92dfb5e9 tuned proofs (taking full advantage of nominal_inductive)
urbanc
parents: 22531
diff changeset
   270
equivariance valid 
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   271
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   272
inductive_cases
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   273
  valid_cons_elim_auto[elim]:"valid ((x,T)#\<Gamma>)"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   274
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   275
abbreviation
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   276
  "sub_context" :: "Ctxt \<Rightarrow> Ctxt \<Rightarrow> bool" (" _ \<subseteq> _ " [55,55] 55)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   277
where
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   278
  "\<Gamma>\<^isub>1 \<subseteq> \<Gamma>\<^isub>2 \<equiv> \<forall>a T. (a,T)\<in>set \<Gamma>\<^isub>1 \<longrightarrow> (a,T)\<in>set \<Gamma>\<^isub>2"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   279
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   280
lemma valid_monotonicity[elim]:
24231
85fb973a8207 added type constraints to resolve syntax ambiguities;
wenzelm
parents: 24088
diff changeset
   281
 fixes \<Gamma> \<Gamma>' :: Ctxt
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   282
 assumes a: "\<Gamma> \<subseteq> \<Gamma>'" 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   283
 and     b: "x\<sharp>\<Gamma>'"
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   284
 shows "(x,T\<^isub>1)#\<Gamma> \<subseteq> (x,T\<^isub>1)#\<Gamma>'"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   285
using a b by auto
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   286
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   287
lemma fresh_context: 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   288
  fixes  \<Gamma> :: "Ctxt"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   289
  and    a :: "name"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   290
  assumes "a\<sharp>\<Gamma>"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   291
  shows "\<not>(\<exists>\<tau>::ty. (a,\<tau>)\<in>set \<Gamma>)"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   292
using assms 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   293
by (induct \<Gamma>)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   294
   (auto simp add: fresh_prod fresh_list_cons fresh_atm)
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   295
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   296
lemma type_unicity_in_context:
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   297
  assumes a: "valid \<Gamma>" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   298
  and     b: "(x,T\<^isub>1) \<in> set \<Gamma>" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   299
  and     c: "(x,T\<^isub>2) \<in> set \<Gamma>"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   300
  shows "T\<^isub>1=T\<^isub>2"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   301
using a b c
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   302
by (induct \<Gamma>)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   303
   (auto dest!: fresh_context)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   304
23760
aca2c7f80e2f Renamed inductive2 to inductive.
berghofe
parents: 23450
diff changeset
   305
inductive
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   306
  typing :: "Ctxt\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" (" _ \<turnstile> _ : _ " [60,60,60] 60) 
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   307
where
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   308
  T_Var[intro]:   "\<lbrakk>valid \<Gamma>; (x,T)\<in>set \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Var x : T"
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   309
| T_App[intro]:   "\<lbrakk>\<Gamma> \<turnstile> e\<^isub>1 : T\<^isub>1\<rightarrow>T\<^isub>2; \<Gamma> \<turnstile> e\<^isub>2 : T\<^isub>1\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> App e\<^isub>1 e\<^isub>2 : T\<^isub>2"
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   310
| T_Lam[intro]:   "\<lbrakk>x\<sharp>\<Gamma>; (x,T\<^isub>1)#\<Gamma> \<turnstile> t : T\<^isub>2\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Lam [x].t : T\<^isub>1\<rightarrow>T\<^isub>2"
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   311
| T_Const[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> Const n : TBase"
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   312
| T_Unit[intro]:  "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> Unit : TUnit"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   313
22730
8bcc8809ed3b nominal_inductive no longer proves equivariance.
berghofe
parents: 22650
diff changeset
   314
equivariance typing
8bcc8809ed3b nominal_inductive no longer proves equivariance.
berghofe
parents: 22650
diff changeset
   315
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   316
nominal_inductive typing
22531
1cbfb4066e47 Adapted to changes in nominal_inductive.
berghofe
parents: 22501
diff changeset
   317
  by (simp_all add: abs_fresh)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   318
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   319
lemma typing_implies_valid:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   320
  assumes a: "\<Gamma> \<turnstile> t : T"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   321
  shows "valid \<Gamma>"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   322
  using a by (induct) (auto)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   323
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   324
declare trm.inject [simp add]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   325
declare ty.inject  [simp add]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   326
24088
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   327
inductive_cases typing_inv_auto[elim]:
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   328
  "\<Gamma> \<turnstile> Lam [x].t : T"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   329
  "\<Gamma> \<turnstile> Var x : T"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   330
  "\<Gamma> \<turnstile> App x y : T"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   331
  "\<Gamma> \<turnstile> Const n : T"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   332
  "\<Gamma> \<turnstile> Unit : TUnit"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   333
  "\<Gamma> \<turnstile> s : TUnit"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   334
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   335
declare trm.inject [simp del]
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   336
declare ty.inject [simp del]
24088
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   337
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   338
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   339
section {* Definitional Equivalence *}
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   340
23760
aca2c7f80e2f Renamed inductive2 to inductive.
berghofe
parents: 23450
diff changeset
   341
inductive
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   342
  def_equiv :: "Ctxt\<Rightarrow>trm\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" ("_ \<turnstile> _ \<equiv> _ : _" [60,60] 60) 
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   343
where
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   344
  Q_Refl[intro]:  "\<Gamma> \<turnstile> t : T \<Longrightarrow> \<Gamma> \<turnstile> t \<equiv> t : T"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   345
| Q_Symm[intro]:  "\<Gamma> \<turnstile> t \<equiv> s : T \<Longrightarrow> \<Gamma> \<turnstile> s \<equiv> t : T"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   346
| Q_Trans[intro]: "\<lbrakk>\<Gamma> \<turnstile> s \<equiv> t : T; \<Gamma> \<turnstile> t \<equiv> u : T\<rbrakk> \<Longrightarrow>  \<Gamma> \<turnstile> s \<equiv> u : T"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   347
| Q_Abs[intro]:   "\<lbrakk>x\<sharp>\<Gamma>; (x,T\<^isub>1)#\<Gamma> \<turnstile> s\<^isub>2 \<equiv> t\<^isub>2 : T\<^isub>2\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Lam [x]. s\<^isub>2 \<equiv>  Lam [x]. t\<^isub>2 : T\<^isub>1 \<rightarrow> T\<^isub>2"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   348
| Q_App[intro]:   "\<lbrakk>\<Gamma> \<turnstile> s\<^isub>1 \<equiv> t\<^isub>1 : T\<^isub>1 \<rightarrow> T\<^isub>2 ; \<Gamma> \<turnstile> s\<^isub>2 \<equiv> t\<^isub>2 : T\<^isub>1\<rbrakk> \<Longrightarrow>  \<Gamma> \<turnstile> App s\<^isub>1 s\<^isub>2 \<equiv> App t\<^isub>1 t\<^isub>2 : T\<^isub>2"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   349
| Q_Beta[intro]:  "\<lbrakk>x\<sharp>(\<Gamma>,s\<^isub>2,t\<^isub>2); (x,T\<^isub>1)#\<Gamma> \<turnstile> s\<^isub>1 \<equiv> t\<^isub>1 : T\<^isub>2 ; \<Gamma> \<turnstile> s\<^isub>2 \<equiv> t\<^isub>2 : T\<^isub>1\<rbrakk> 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   350
                   \<Longrightarrow>  \<Gamma> \<turnstile> App (Lam [x]. s\<^isub>1) s\<^isub>2 \<equiv> t\<^isub>1[x::=t\<^isub>2] : T\<^isub>2"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   351
| Q_Ext[intro]:   "\<lbrakk>x\<sharp>(\<Gamma>,s,t); (x,T\<^isub>1)#\<Gamma> \<turnstile> App s (Var x) \<equiv> App t (Var x) : T\<^isub>2\<rbrakk> 
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   352
                   \<Longrightarrow> \<Gamma> \<turnstile> s \<equiv> t : T\<^isub>1 \<rightarrow> T\<^isub>2"
23370
513a8ee192f1 added the Q_Unit rule (was missing) and adjusted the proof accordingly
urbanc
parents: 22829
diff changeset
   353
| Q_Unit[intro]:  "\<lbrakk>\<Gamma> \<turnstile> s : TUnit; \<Gamma> \<turnstile> t: TUnit\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s \<equiv> t : TUnit"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   354
22730
8bcc8809ed3b nominal_inductive no longer proves equivariance.
berghofe
parents: 22650
diff changeset
   355
equivariance def_equiv
8bcc8809ed3b nominal_inductive no longer proves equivariance.
berghofe
parents: 22650
diff changeset
   356
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   357
nominal_inductive def_equiv
22531
1cbfb4066e47 Adapted to changes in nominal_inductive.
berghofe
parents: 22501
diff changeset
   358
  by (simp_all add: abs_fresh fresh_subst'')
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   359
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   360
lemma def_equiv_implies_valid:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   361
  assumes a: "\<Gamma> \<turnstile> t \<equiv> s : T"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   362
  shows "valid \<Gamma>"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   363
using a by (induct) (auto elim: typing_implies_valid)
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   364
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   365
section {* Weak Head Reduction *}
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   366
23760
aca2c7f80e2f Renamed inductive2 to inductive.
berghofe
parents: 23450
diff changeset
   367
inductive
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   368
  whr_def :: "trm\<Rightarrow>trm\<Rightarrow>bool" ("_ \<leadsto> _" [80,80] 80) 
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   369
where
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   370
  QAR_Beta[intro]: "App (Lam [x]. t\<^isub>1) t\<^isub>2 \<leadsto> t\<^isub>1[x::=t\<^isub>2]"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   371
| QAR_App[intro]:  "t\<^isub>1 \<leadsto> t\<^isub>1' \<Longrightarrow> App t\<^isub>1 t\<^isub>2 \<leadsto> App t\<^isub>1' t\<^isub>2"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   372
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   373
declare trm.inject  [simp add]
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   374
declare ty.inject  [simp add]
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   375
24088
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   376
inductive_cases whr_inv_auto[elim]: 
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   377
  "t \<leadsto> t'"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   378
  "Lam [x].t \<leadsto> t'"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   379
  "App (Lam [x].t12) t2 \<leadsto> t"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   380
  "Var x \<leadsto> t"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   381
  "Const n \<leadsto> t"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   382
  "App p q \<leadsto> t"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   383
  "t \<leadsto> Const n"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   384
  "t \<leadsto> Var x"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   385
  "t \<leadsto> App p q"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   386
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   387
declare trm.inject  [simp del]
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   388
declare ty.inject  [simp del]
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   389
22531
1cbfb4066e47 Adapted to changes in nominal_inductive.
berghofe
parents: 22501
diff changeset
   390
equivariance whr_def
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   391
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   392
section {* Weak Head Normalisation *}
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   393
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   394
abbreviation 
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   395
 nf :: "trm \<Rightarrow> bool" ("_ \<leadsto>|" [100] 100)
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   396
where
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   397
  "t\<leadsto>|  \<equiv> \<not>(\<exists> u. t \<leadsto> u)" 
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   398
23760
aca2c7f80e2f Renamed inductive2 to inductive.
berghofe
parents: 23450
diff changeset
   399
inductive
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   400
  whn_def :: "trm\<Rightarrow>trm\<Rightarrow>bool" ("_ \<Down> _" [80,80] 80) 
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   401
where
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   402
  QAN_Reduce[intro]: "\<lbrakk>s \<leadsto> t; t \<Down> u\<rbrakk> \<Longrightarrow> s \<Down> u"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   403
| QAN_Normal[intro]: "t\<leadsto>|  \<Longrightarrow> t \<Down> t"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   404
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   405
declare trm.inject[simp]
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   406
23760
aca2c7f80e2f Renamed inductive2 to inductive.
berghofe
parents: 23450
diff changeset
   407
inductive_cases whn_inv_auto[elim]: "t \<Down> t'"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   408
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   409
declare trm.inject[simp del]
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   410
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   411
lemma whn_eqvt[eqvt]:
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   412
  fixes pi::"name prm"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   413
  assumes a: "t \<Down> t'"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   414
  shows "(pi\<bullet>t) \<Down> (pi\<bullet>t')"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   415
using a
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   416
apply(induct)
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   417
apply(rule QAN_Reduce)
22542
8279a25ad0ae - Renamed <predicate>_eqvt to <predicate>.eqvt
berghofe
parents: 22538
diff changeset
   418
apply(rule whr_def.eqvt)
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   419
apply(assumption)+
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   420
apply(rule QAN_Normal)
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   421
apply(auto)
22542
8279a25ad0ae - Renamed <predicate>_eqvt to <predicate>.eqvt
berghofe
parents: 22538
diff changeset
   422
apply(drule_tac pi="rev pi" in whr_def.eqvt)
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   423
apply(perm_simp)
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   424
done
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   425
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   426
lemma red_unicity : 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   427
  assumes a: "x \<leadsto> a" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   428
  and     b: "x \<leadsto> b"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   429
  shows "a=b"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   430
  using a b
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   431
apply (induct arbitrary: b)
24088
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   432
apply (erule whr_inv_auto(3))
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   433
apply (clarify)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   434
apply (rule subst_fun_eq)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   435
apply (simp)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   436
apply (force)
24088
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   437
apply (erule whr_inv_auto(6))
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   438
apply (blast)+
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   439
done
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   440
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   441
lemma nf_unicity :
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   442
  assumes "x \<Down> a" and "x \<Down> b"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   443
  shows "a=b"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   444
  using assms 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   445
proof (induct arbitrary: b)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   446
  case (QAN_Reduce x t a b)
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   447
  have h:"x \<leadsto> t" "t \<Down> a" by fact+
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   448
  have ih:"\<And>b. t \<Down> b \<Longrightarrow> a = b" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   449
  have "x \<Down> b" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   450
  then obtain t' where "x \<leadsto> t'" and hl:"t' \<Down> b" using h by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   451
  then have "t=t'" using h red_unicity by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   452
  then show "a=b" using ih hl by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   453
qed (auto)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   454
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   455
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   456
section {* Algorithmic Term Equivalence and Algorithmic Path Equivalence *}
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   457
23760
aca2c7f80e2f Renamed inductive2 to inductive.
berghofe
parents: 23450
diff changeset
   458
inductive
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   459
  alg_equiv :: "Ctxt\<Rightarrow>trm\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" ("_ \<turnstile> _ \<Leftrightarrow> _ : _" [60,60,60,60] 60) 
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   460
and
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   461
  alg_path_equiv :: "Ctxt\<Rightarrow>trm\<Rightarrow>trm\<Rightarrow>ty\<Rightarrow>bool" ("_ \<turnstile> _ \<leftrightarrow> _ : _" [60,60,60,60] 60) 
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   462
where
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   463
  QAT_Base[intro]:  "\<lbrakk>s \<Down> p; t \<Down> q; \<Gamma> \<turnstile> p \<leftrightarrow> q : TBase\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> t : TBase"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   464
| QAT_Arrow[intro]: "\<lbrakk>x\<sharp>(\<Gamma>,s,t); (x,T\<^isub>1)#\<Gamma> \<turnstile> App s (Var x) \<Leftrightarrow> App t (Var x) : T\<^isub>2\<rbrakk> 
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   465
                     \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> t : T\<^isub>1 \<rightarrow> T\<^isub>2"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   466
| QAT_One[intro]:   "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> t : TUnit"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   467
| QAP_Var[intro]:   "\<lbrakk>valid \<Gamma>;(x,T) \<in> set \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Var x \<leftrightarrow> Var x : T"
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   468
| QAP_App[intro]:   "\<lbrakk>\<Gamma> \<turnstile> p \<leftrightarrow> q : T\<^isub>1 \<rightarrow> T\<^isub>2; \<Gamma> \<turnstile> s \<Leftrightarrow> t : T\<^isub>1\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> App p s \<leftrightarrow> App q t : T\<^isub>2"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   469
| QAP_Const[intro]: "valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> Const n \<leftrightarrow> Const n : TBase"
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   470
22730
8bcc8809ed3b nominal_inductive no longer proves equivariance.
berghofe
parents: 22650
diff changeset
   471
equivariance alg_equiv
8bcc8809ed3b nominal_inductive no longer proves equivariance.
berghofe
parents: 22650
diff changeset
   472
22531
1cbfb4066e47 Adapted to changes in nominal_inductive.
berghofe
parents: 22501
diff changeset
   473
nominal_inductive alg_equiv
1cbfb4066e47 Adapted to changes in nominal_inductive.
berghofe
parents: 22501
diff changeset
   474
  avoids QAT_Arrow: x
1cbfb4066e47 Adapted to changes in nominal_inductive.
berghofe
parents: 22501
diff changeset
   475
  by simp_all
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   476
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   477
declare trm.inject [simp add]
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   478
declare ty.inject  [simp add]
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   479
24088
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   480
inductive_cases alg_equiv_inv_auto[elim]: 
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   481
  "\<Gamma> \<turnstile> s\<Leftrightarrow>t : TBase"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   482
  "\<Gamma> \<turnstile> s\<Leftrightarrow>t : T\<^isub>1 \<rightarrow> T\<^isub>2"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   483
  "\<Gamma> \<turnstile> s\<leftrightarrow>t : TBase"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   484
  "\<Gamma> \<turnstile> s\<leftrightarrow>t : TUnit"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   485
  "\<Gamma> \<turnstile> s\<leftrightarrow>t : T\<^isub>1 \<rightarrow> T\<^isub>2"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   486
24088
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   487
  "\<Gamma> \<turnstile> Var x \<leftrightarrow> t : T"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   488
  "\<Gamma> \<turnstile> Var x \<leftrightarrow> t : T'"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   489
  "\<Gamma> \<turnstile> s \<leftrightarrow> Var x : T"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   490
  "\<Gamma> \<turnstile> s \<leftrightarrow> Var x : T'"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   491
  "\<Gamma> \<turnstile> Const n \<leftrightarrow> t : T"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   492
  "\<Gamma> \<turnstile> s \<leftrightarrow> Const n : T"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   493
  "\<Gamma> \<turnstile> App p s \<leftrightarrow> t : T"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   494
  "\<Gamma> \<turnstile> s \<leftrightarrow> App q t : T"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   495
  "\<Gamma> \<turnstile> Lam[x].s \<leftrightarrow> t : T"
c2d8270e53a5 undo a change in last commit : give a single name to the inversion lemmas for the same inductive type
narboux
parents: 24070
diff changeset
   496
  "\<Gamma> \<turnstile> t \<leftrightarrow> Lam[x].s : T"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   497
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   498
declare trm.inject [simp del]
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   499
declare ty.inject [simp del]
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   500
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   501
lemma Q_Arrow_strong_inversion:
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   502
  assumes fs: "x\<sharp>\<Gamma>" "x\<sharp>t" "x\<sharp>u" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   503
  and h: "\<Gamma> \<turnstile> t \<Leftrightarrow> u : T\<^isub>1\<rightarrow>T\<^isub>2"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   504
  shows "(x,T\<^isub>1)#\<Gamma> \<turnstile> App t (Var x) \<Leftrightarrow> App u (Var x) : T\<^isub>2"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   505
proof -
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   506
  obtain y where fs2: "y\<sharp>(\<Gamma>,t,u)" and "(y,T\<^isub>1)#\<Gamma> \<turnstile> App t (Var y) \<Leftrightarrow> App u (Var y) : T\<^isub>2" 
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   507
    using h by auto
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   508
  then have "([(x,y)]\<bullet>((y,T\<^isub>1)#\<Gamma>)) \<turnstile> [(x,y)]\<bullet> App t (Var y) \<Leftrightarrow> [(x,y)]\<bullet> App u (Var y) : T\<^isub>2" 
22542
8279a25ad0ae - Renamed <predicate>_eqvt to <predicate>.eqvt
berghofe
parents: 22538
diff changeset
   509
    using  alg_equiv.eqvt[simplified] by blast
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   510
  then show ?thesis using fs fs2 by (perm_simp)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   511
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   512
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   513
(*
22594
33a690455f88 add a few details in the Fst and Snd cases of unicity proof
narboux
parents: 22542
diff changeset
   514
Warning this lemma is false:
33a690455f88 add a few details in the Fst and Snd cases of unicity proof
narboux
parents: 22542
diff changeset
   515
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   516
lemma algorithmic_type_unicity:
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   517
  shows "\<lbrakk> \<Gamma> \<turnstile> s \<Leftrightarrow> t : T ; \<Gamma> \<turnstile> s \<Leftrightarrow> u : T' \<rbrakk> \<Longrightarrow> T = T'"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   518
  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
   519
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   520
Here is the counter example : 
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   521
\<Gamma> \<turnstile> Const n \<Leftrightarrow> Const n : Tbase and \<Gamma> \<turnstile> Const n \<Leftrightarrow> Const n : TUnit
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   522
*)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   523
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   524
lemma algorithmic_path_type_unicity:
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   525
  shows "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<turnstile> s \<leftrightarrow> u : T' \<Longrightarrow> T = T'"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   526
proof (induct arbitrary:  u T' 
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   527
       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
   528
  case (QAP_Var \<Gamma> x T u T')
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   529
  have "\<Gamma> \<turnstile> Var x \<leftrightarrow> u : T'" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   530
  then have "u=Var x" and "(x,T') \<in> set \<Gamma>" by auto
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   531
  moreover have "valid \<Gamma>" "(x,T) \<in> set \<Gamma>" by fact+
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   532
  ultimately show "T=T'" using type_unicity_in_context by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   533
next
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   534
  case (QAP_App \<Gamma> p q T\<^isub>1 T\<^isub>2 s t u T\<^isub>2')
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   535
  have ih:"\<And>u T. \<Gamma> \<turnstile> p \<leftrightarrow> u : T \<Longrightarrow> T\<^isub>1\<rightarrow>T\<^isub>2 = T" by fact
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   536
  have "\<Gamma> \<turnstile> App p s \<leftrightarrow> u : T\<^isub>2'" by fact
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   537
  then obtain r t T\<^isub>1' where "u = App r t"  "\<Gamma> \<turnstile> p \<leftrightarrow> r : T\<^isub>1' \<rightarrow> T\<^isub>2'" by auto
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   538
  with ih have "T\<^isub>1\<rightarrow>T\<^isub>2 = T\<^isub>1' \<rightarrow> T\<^isub>2'" by auto
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   539
  then show "T\<^isub>2=T\<^isub>2'" using ty.inject by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   540
qed (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   541
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   542
lemma alg_path_equiv_implies_valid:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   543
  shows  "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T \<Longrightarrow> valid \<Gamma>" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   544
  and    "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> valid \<Gamma>"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   545
by (induct rule : alg_equiv_alg_path_equiv.inducts, auto)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   546
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   547
lemma algorithmic_symmetry:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   548
  shows "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<turnstile> t \<Leftrightarrow> s : T" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   549
  and   "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<turnstile> t \<leftrightarrow> s : T"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   550
by (induct rule: alg_equiv_alg_path_equiv.inducts) 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   551
   (auto simp add: fresh_prod)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   552
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   553
lemma algorithmic_transitivity:
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   554
  shows "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<turnstile> t \<Leftrightarrow> u : T \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> u : T"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   555
  and   "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<turnstile> t \<leftrightarrow> u : T \<Longrightarrow> \<Gamma> \<turnstile> s \<leftrightarrow> u : T"
22531
1cbfb4066e47 Adapted to changes in nominal_inductive.
berghofe
parents: 22501
diff changeset
   556
proof (nominal_induct \<Gamma> s t T and \<Gamma> s t T avoiding: u rule: alg_equiv_alg_path_equiv.strong_inducts)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   557
  case (QAT_Base s p t q \<Gamma> u)
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   558
  have "\<Gamma> \<turnstile> t \<Leftrightarrow> u : TBase" by fact
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   559
  then obtain r' q' where b1: "t \<Down> q'" and b2: "u \<Down> r'" and b3: "\<Gamma> \<turnstile> q' \<leftrightarrow> r' : TBase" by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   560
  have ih: "\<Gamma> \<turnstile> q \<leftrightarrow> r' : TBase \<Longrightarrow> \<Gamma> \<turnstile> p \<leftrightarrow> r' : TBase" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   561
  have "t \<Down> q" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   562
  with b1 have eq: "q=q'" by (simp add: nf_unicity)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   563
  with ih b3 have "\<Gamma> \<turnstile> p \<leftrightarrow> r' : TBase" by simp
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   564
  moreover
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   565
  have "s \<Down> p" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   566
  ultimately show "\<Gamma> \<turnstile> s \<Leftrightarrow> u : TBase" using b2 by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   567
next
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   568
  case (QAT_Arrow  x \<Gamma> s t T\<^isub>1 T\<^isub>2 u)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   569
  have ih:"(x,T\<^isub>1)#\<Gamma> \<turnstile> App t (Var x) \<Leftrightarrow> App u (Var x) : T\<^isub>2 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   570
                                   \<Longrightarrow> (x,T\<^isub>1)#\<Gamma> \<turnstile> App s (Var x) \<Leftrightarrow> App u (Var x) : T\<^isub>2" by fact
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   571
  have fs: "x\<sharp>\<Gamma>" "x\<sharp>s" "x\<sharp>t" "x\<sharp>u" by fact+
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   572
  have "\<Gamma> \<turnstile> t \<Leftrightarrow> u : T\<^isub>1\<rightarrow>T\<^isub>2" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   573
  then have "(x,T\<^isub>1)#\<Gamma> \<turnstile> App t (Var x) \<Leftrightarrow> App u (Var x) : T\<^isub>2" using fs 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   574
    by (simp add: Q_Arrow_strong_inversion)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   575
  with ih have "(x,T\<^isub>1)#\<Gamma> \<turnstile> App s (Var x) \<Leftrightarrow> App u (Var x) : T\<^isub>2" by simp
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   576
  then show "\<Gamma> \<turnstile> s \<Leftrightarrow> u : T\<^isub>1\<rightarrow>T\<^isub>2" using fs by (auto simp add: fresh_prod)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   577
next
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   578
  case (QAP_App \<Gamma> p q T\<^isub>1 T\<^isub>2 s t u)
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   579
  have "\<Gamma> \<turnstile> App q t \<leftrightarrow> u : T\<^isub>2" by fact
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   580
  then obtain r T\<^isub>1' v where ha: "\<Gamma> \<turnstile> q \<leftrightarrow> r : T\<^isub>1'\<rightarrow>T\<^isub>2" and hb: "\<Gamma> \<turnstile> t \<Leftrightarrow> v : T\<^isub>1'" and eq: "u = App r v" 
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   581
    by auto
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   582
  have ih1: "\<Gamma> \<turnstile> q \<leftrightarrow> r : T\<^isub>1\<rightarrow>T\<^isub>2 \<Longrightarrow> \<Gamma> \<turnstile> p \<leftrightarrow> r : T\<^isub>1\<rightarrow>T\<^isub>2" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   583
  have ih2:"\<Gamma> \<turnstile> t \<Leftrightarrow> v : T\<^isub>1 \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> v : T\<^isub>1" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   584
  have "\<Gamma> \<turnstile> p \<leftrightarrow> q : T\<^isub>1\<rightarrow>T\<^isub>2" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   585
  then have "\<Gamma> \<turnstile> q \<leftrightarrow> p : T\<^isub>1\<rightarrow>T\<^isub>2" by (simp add: algorithmic_symmetry)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   586
  with ha have "T\<^isub>1'\<rightarrow>T\<^isub>2 = T\<^isub>1\<rightarrow>T\<^isub>2" using algorithmic_path_type_unicity by simp
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   587
  then have "T\<^isub>1' = T\<^isub>1" by (simp add: ty.inject) 
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   588
  then have "\<Gamma> \<turnstile> s \<Leftrightarrow> v : T\<^isub>1" "\<Gamma> \<turnstile> p \<leftrightarrow> r : T\<^isub>1\<rightarrow>T\<^isub>2" using ih1 ih2 ha hb by auto
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   589
  then show "\<Gamma> \<turnstile> App p s \<leftrightarrow> u : T\<^isub>2" using eq by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   590
qed (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   591
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   592
lemma algorithmic_weak_head_closure:
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   593
  shows "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T \<Longrightarrow> s' \<leadsto> s \<Longrightarrow> t' \<leadsto> t \<Longrightarrow> \<Gamma> \<turnstile> s' \<Leftrightarrow> t' : T"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   594
apply (nominal_induct \<Gamma> s t T avoiding: s' t'  
22531
1cbfb4066e47 Adapted to changes in nominal_inductive.
berghofe
parents: 22501
diff changeset
   595
    rule: alg_equiv_alg_path_equiv.strong_inducts(1) [of _ _ _ _ "%a b c d e. True"])
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   596
apply(auto intro!: QAT_Arrow)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   597
done
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   598
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   599
lemma algorithmic_monotonicity:
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   600
  shows "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<subseteq> \<Gamma>' \<Longrightarrow> valid \<Gamma>' \<Longrightarrow> \<Gamma>' \<turnstile> s \<Leftrightarrow> t : T"
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   601
  and   "\<Gamma> \<turnstile> s \<leftrightarrow> t : T \<Longrightarrow> \<Gamma> \<subseteq> \<Gamma>' \<Longrightarrow> valid \<Gamma>' \<Longrightarrow> \<Gamma>' \<turnstile> s \<leftrightarrow> t : T"
22531
1cbfb4066e47 Adapted to changes in nominal_inductive.
berghofe
parents: 22501
diff changeset
   602
proof (nominal_induct \<Gamma> s t T and \<Gamma> s t T avoiding: \<Gamma>' rule: alg_equiv_alg_path_equiv.strong_inducts)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   603
 case (QAT_Arrow x \<Gamma> s t T\<^isub>1 T\<^isub>2 \<Gamma>')
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   604
  have fs:"x\<sharp>\<Gamma>" "x\<sharp>s" "x\<sharp>t" "x\<sharp>\<Gamma>'" by fact+
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   605
  have h2:"\<Gamma> \<subseteq> \<Gamma>'" by fact
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   606
  have ih:"\<And>\<Gamma>'. \<lbrakk>(x,T\<^isub>1)#\<Gamma> \<subseteq> \<Gamma>'; valid \<Gamma>'\<rbrakk>  \<Longrightarrow> \<Gamma>' \<turnstile> App s (Var x) \<Leftrightarrow> App t (Var x) : T\<^isub>2" by fact
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   607
  have "valid \<Gamma>'" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   608
  then have "valid ((x,T\<^isub>1)#\<Gamma>')" using fs by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   609
  moreover
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   610
  have sub: "(x,T\<^isub>1)#\<Gamma> \<subseteq> (x,T\<^isub>1)#\<Gamma>'" using h2 by auto
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   611
  ultimately have "(x,T\<^isub>1)#\<Gamma>' \<turnstile> App s (Var x) \<Leftrightarrow> App t (Var x) : T\<^isub>2" using ih by simp
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   612
  then show "\<Gamma>' \<turnstile> s \<Leftrightarrow> t : T\<^isub>1\<rightarrow>T\<^isub>2" using fs by (auto simp add: fresh_prod)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   613
qed (auto)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   614
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   615
lemma path_equiv_implies_nf:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   616
  assumes "\<Gamma> \<turnstile> s \<leftrightarrow> t : T"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   617
  shows "s \<leadsto>|" and "t \<leadsto>|"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   618
using assms
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   619
by (induct rule: alg_equiv_alg_path_equiv.inducts(2)) (simp, auto)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   620
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   621
section {* Logical Equivalence *}
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   622
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   623
function log_equiv :: "(Ctxt \<Rightarrow> trm \<Rightarrow> trm \<Rightarrow> ty \<Rightarrow> bool)" ("_ \<turnstile> _ is _ : _" [60,60,60,60] 60) 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   624
where    
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   625
   "\<Gamma> \<turnstile> s is t : TUnit = True"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   626
 | "\<Gamma> \<turnstile> s is t : TBase = \<Gamma> \<turnstile> s \<Leftrightarrow> t : TBase"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   627
 | "\<Gamma> \<turnstile> s is t : (T\<^isub>1 \<rightarrow> T\<^isub>2) =  
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   628
    (\<forall>\<Gamma>' s' t'. \<Gamma>\<subseteq>\<Gamma>' \<longrightarrow> valid \<Gamma>' \<longrightarrow> \<Gamma>' \<turnstile> s' is t' : T\<^isub>1 \<longrightarrow>  (\<Gamma>' \<turnstile> (App s s') is (App t t') : T\<^isub>2))"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   629
apply (auto simp add: ty.inject)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   630
apply (subgoal_tac "(\<exists>T\<^isub>1 T\<^isub>2. b=T\<^isub>1 \<rightarrow> T\<^isub>2) \<or> b=TUnit \<or> b=TBase" )
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   631
apply (force)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   632
apply (rule ty_cases)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   633
done
28042
1471f2974eb1 more function -> fun
krauss
parents: 26966
diff changeset
   634
termination by lexicographic_order
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   635
24231
85fb973a8207 added type constraints to resolve syntax ambiguities;
wenzelm
parents: 24088
diff changeset
   636
lemma logical_monotonicity:
85fb973a8207 added type constraints to resolve syntax ambiguities;
wenzelm
parents: 24088
diff changeset
   637
 fixes \<Gamma> \<Gamma>' :: Ctxt
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   638
 assumes a1: "\<Gamma> \<turnstile> s is t : T" 
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   639
 and     a2: "\<Gamma> \<subseteq> \<Gamma>'" 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   640
 and     a3: "valid \<Gamma>'"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   641
 shows "\<Gamma>' \<turnstile> s is t : T"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   642
using a1 a2 a3
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   643
proof (induct arbitrary: \<Gamma>' rule: log_equiv.induct)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   644
  case (2 \<Gamma> s t \<Gamma>')
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   645
  then show "\<Gamma>' \<turnstile> s is t : TBase" using algorithmic_monotonicity by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   646
next
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   647
  case (3 \<Gamma> s t T\<^isub>1 T\<^isub>2 \<Gamma>')
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   648
  have "\<Gamma> \<turnstile> s is t : T\<^isub>1\<rightarrow>T\<^isub>2" 
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   649
  and  "\<Gamma> \<subseteq> \<Gamma>'" 
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   650
  and  "valid \<Gamma>'" by fact+
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   651
  then show "\<Gamma>' \<turnstile> s is t : T\<^isub>1\<rightarrow>T\<^isub>2" by simp
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   652
qed (auto)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   653
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   654
lemma main_lemma:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   655
  shows "\<Gamma> \<turnstile> s is t : T \<Longrightarrow> valid \<Gamma> \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> t : T" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   656
    and "\<Gamma> \<turnstile> p \<leftrightarrow> q : T \<Longrightarrow> \<Gamma> \<turnstile> p is q : T"
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   657
proof (nominal_induct T arbitrary: \<Gamma> s t p q rule: ty.strong_induct)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   658
  case (Arrow T\<^isub>1 T\<^isub>2)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   659
  { 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   660
    case (1 \<Gamma> s t)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   661
    have ih1:"\<And>\<Gamma> s t. \<lbrakk>\<Gamma> \<turnstile> s is t : T\<^isub>2; valid \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> t : T\<^isub>2" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   662
    have ih2:"\<And>\<Gamma> s t. \<Gamma> \<turnstile> s \<leftrightarrow> t : T\<^isub>1 \<Longrightarrow> \<Gamma> \<turnstile> s is t : T\<^isub>1" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   663
    have h:"\<Gamma> \<turnstile> s is t : T\<^isub>1\<rightarrow>T\<^isub>2" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   664
    obtain x::name where fs:"x\<sharp>(\<Gamma>,s,t)" by (erule exists_fresh[OF fs_name1])
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   665
    have "valid \<Gamma>" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   666
    then have v: "valid ((x,T\<^isub>1)#\<Gamma>)" using fs by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   667
    then have "(x,T\<^isub>1)#\<Gamma> \<turnstile> Var x \<leftrightarrow> Var x : T\<^isub>1" by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   668
    then have "(x,T\<^isub>1)#\<Gamma> \<turnstile> Var x is Var x : T\<^isub>1" using ih2 by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   669
    then have "(x,T\<^isub>1)#\<Gamma> \<turnstile> App s (Var x) is App t (Var x) : T\<^isub>2" using h v by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   670
    then have "(x,T\<^isub>1)#\<Gamma> \<turnstile> App s (Var x) \<Leftrightarrow> App t (Var x) : T\<^isub>2" using ih1 v by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   671
    then show "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T\<^isub>1\<rightarrow>T\<^isub>2" using fs by (auto simp add: fresh_prod)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   672
  next
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   673
    case (2 \<Gamma> p q)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   674
    have h: "\<Gamma> \<turnstile> p \<leftrightarrow> q : T\<^isub>1\<rightarrow>T\<^isub>2" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   675
    have ih1:"\<And>\<Gamma> s t. \<Gamma> \<turnstile> s \<leftrightarrow> t : T\<^isub>2 \<Longrightarrow> \<Gamma> \<turnstile> s is t : T\<^isub>2" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   676
    have ih2:"\<And>\<Gamma> s t. \<lbrakk>\<Gamma> \<turnstile> s is t : T\<^isub>1; valid \<Gamma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s \<Leftrightarrow> t : T\<^isub>1" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   677
    {
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   678
      fix \<Gamma>' s t
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   679
      assume "\<Gamma> \<subseteq> \<Gamma>'" and hl:"\<Gamma>' \<turnstile> s is t : T\<^isub>1" and hk: "valid \<Gamma>'"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   680
      then have "\<Gamma>' \<turnstile> p \<leftrightarrow> q : T\<^isub>1 \<rightarrow> T\<^isub>2" using h algorithmic_monotonicity by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   681
      moreover have "\<Gamma>' \<turnstile> s \<Leftrightarrow> t : T\<^isub>1" using ih2 hl hk by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   682
      ultimately have "\<Gamma>' \<turnstile> App p s \<leftrightarrow> App q t : T\<^isub>2" by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   683
      then have "\<Gamma>' \<turnstile> App p s is App q t : T\<^isub>2" using ih1 by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   684
    }
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   685
    then show "\<Gamma> \<turnstile> p is q : T\<^isub>1\<rightarrow>T\<^isub>2"  by simp
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   686
  }
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   687
next
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   688
  case TBase
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   689
  { case 2
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   690
    have h:"\<Gamma> \<turnstile> s \<leftrightarrow> t : TBase" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   691
    then have "s \<leadsto>|" and "t \<leadsto>|" using path_equiv_implies_nf by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   692
    then have "s \<Down> s" and "t \<Down> t" by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   693
    then have "\<Gamma> \<turnstile> s \<Leftrightarrow> t : TBase" using h by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   694
    then show "\<Gamma> \<turnstile> s is t : TBase" by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   695
  }
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   696
qed (auto elim: alg_path_equiv_implies_valid) 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   697
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   698
corollary corollary_main:
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   699
  assumes a: "\<Gamma> \<turnstile> s \<leftrightarrow> t : T"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   700
  shows "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   701
using a main_lemma alg_path_equiv_implies_valid by blast
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   702
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   703
lemma logical_symmetry:
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   704
  assumes a: "\<Gamma> \<turnstile> s is t : T"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   705
  shows "\<Gamma> \<turnstile> t is s : T"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   706
using a 
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   707
by (nominal_induct arbitrary: \<Gamma> s t rule: ty.strong_induct) 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   708
   (auto simp add: algorithmic_symmetry)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   709
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   710
lemma logical_transitivity:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   711
  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
   712
  shows "\<Gamma> \<turnstile> s is u : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   713
using assms
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   714
proof (nominal_induct arbitrary: \<Gamma> s t u  rule:ty.strong_induct)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   715
  case TBase
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   716
  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
   717
next 
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   718
  case (Arrow T\<^isub>1 T\<^isub>2 \<Gamma> s t u)
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   719
  have h1:"\<Gamma> \<turnstile> s is t : T\<^isub>1 \<rightarrow> T\<^isub>2" by fact
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   720
  have h2:"\<Gamma> \<turnstile> t is u : T\<^isub>1 \<rightarrow> T\<^isub>2" by fact
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   721
  have ih1:"\<And>\<Gamma> s t u. \<lbrakk>\<Gamma> \<turnstile> s is t : T\<^isub>1; \<Gamma> \<turnstile> t is u : T\<^isub>1\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s is u : T\<^isub>1" by fact
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   722
  have ih2:"\<And>\<Gamma> s t u. \<lbrakk>\<Gamma> \<turnstile> s is t : T\<^isub>2; \<Gamma> \<turnstile> t is u : T\<^isub>2\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s is u : T\<^isub>2" by fact
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   723
  {
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   724
    fix \<Gamma>' s' u'
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   725
    assume hsub:"\<Gamma> \<subseteq> \<Gamma>'" and hl:"\<Gamma>' \<turnstile> s' is u' : T\<^isub>1" and hk: "valid \<Gamma>'"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   726
    then have "\<Gamma>' \<turnstile> u' is s' : T\<^isub>1" using logical_symmetry by blast
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   727
    then have "\<Gamma>' \<turnstile> u' is u' : T\<^isub>1" using ih1 hl by blast
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   728
    then have "\<Gamma>' \<turnstile> App t u' is App u u' : T\<^isub>2" using h2 hsub hk by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   729
    moreover have "\<Gamma>' \<turnstile>  App s s' is App t u' : T\<^isub>2" using h1 hsub hl hk by auto
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   730
    ultimately have "\<Gamma>' \<turnstile>  App s s' is App u u' : T\<^isub>2" using ih2 by blast
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   731
  }
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   732
  then show "\<Gamma> \<turnstile> s is u : T\<^isub>1 \<rightarrow> T\<^isub>2" by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   733
qed (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   734
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   735
lemma logical_weak_head_closure:
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   736
  assumes a: "\<Gamma> \<turnstile> s is t : T" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   737
  and     b: "s' \<leadsto> s" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   738
  and     c: "t' \<leadsto> t"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   739
  shows "\<Gamma> \<turnstile> s' is t' : T"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   740
using a b c algorithmic_weak_head_closure 
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   741
by (nominal_induct arbitrary: \<Gamma> s t s' t' rule: ty.strong_induct) 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   742
   (auto, blast)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   743
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   744
lemma logical_weak_head_closure':
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   745
  assumes "\<Gamma> \<turnstile> s is t : T" and "s' \<leadsto> s" 
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   746
  shows "\<Gamma> \<turnstile> s' is t : T"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   747
using assms
26966
071f40487734 made the naming of the induction principles consistent: weak_induct is
urbanc
parents: 26677
diff changeset
   748
proof (nominal_induct arbitrary: \<Gamma> s t s' rule: ty.strong_induct)
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   749
  case (TBase  \<Gamma> s t s')
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   750
  then show ?case by force
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   751
next
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   752
  case (TUnit \<Gamma> s t s')
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   753
  then show ?case by auto
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   754
next 
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   755
  case (Arrow T\<^isub>1 T\<^isub>2 \<Gamma> s t s')
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   756
  have h1:"s' \<leadsto> s" by fact
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   757
  have ih:"\<And>\<Gamma> s t s'. \<lbrakk>\<Gamma> \<turnstile> s is t : T\<^isub>2; s' \<leadsto> s\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s' is t : T\<^isub>2" by fact
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   758
  have h2:"\<Gamma> \<turnstile> s is t : T\<^isub>1\<rightarrow>T\<^isub>2" by fact
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   759
  then 
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   760
  have hb:"\<forall>\<Gamma>' s' t'. \<Gamma>\<subseteq>\<Gamma>' \<longrightarrow> valid \<Gamma>' \<longrightarrow> \<Gamma>' \<turnstile> s' is t' : T\<^isub>1 \<longrightarrow> (\<Gamma>' \<turnstile> (App s s') is (App t t') : T\<^isub>2)" 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   761
    by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   762
  {
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   763
    fix \<Gamma>' s\<^isub>2 t\<^isub>2
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   764
    assume "\<Gamma> \<subseteq> \<Gamma>'" and "\<Gamma>' \<turnstile> s\<^isub>2 is t\<^isub>2 : T\<^isub>1" and "valid \<Gamma>'"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   765
    then have "\<Gamma>' \<turnstile> (App s s\<^isub>2) is (App t t\<^isub>2) : T\<^isub>2" using hb by auto
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   766
    moreover have "(App s' s\<^isub>2)  \<leadsto> (App s s\<^isub>2)" using h1 by auto  
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   767
    ultimately have "\<Gamma>' \<turnstile> App s' s\<^isub>2 is App t t\<^isub>2 : T\<^isub>2" using ih by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   768
  }
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   769
  then show "\<Gamma> \<turnstile> s' is t : T\<^isub>1\<rightarrow>T\<^isub>2" by auto
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   770
qed 
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   771
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   772
abbreviation 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   773
 log_equiv_for_psubsts :: "Ctxt \<Rightarrow> Subst \<Rightarrow> Subst \<Rightarrow> Ctxt \<Rightarrow> bool"  ("_ \<turnstile> _ is _ over _" [60,60] 60) 
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   774
where
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   775
  "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma> \<equiv> \<forall>x T. (x,T) \<in> set \<Gamma> \<longrightarrow> \<Gamma>' \<turnstile> \<theta><Var x> is  \<theta>'<Var x> : T"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   776
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   777
lemma logical_pseudo_reflexivity:
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   778
  assumes "\<Gamma>' \<turnstile> t is s over \<Gamma>"
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   779
  shows "\<Gamma>' \<turnstile> s is s over \<Gamma>" 
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   780
proof -
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   781
  have "\<Gamma>' \<turnstile> t is s over \<Gamma>" by fact
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   782
  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
   783
  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
   784
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   785
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   786
lemma logical_subst_monotonicity :
24231
85fb973a8207 added type constraints to resolve syntax ambiguities;
wenzelm
parents: 24088
diff changeset
   787
  fixes \<Gamma> \<Gamma>' \<Gamma>'' :: Ctxt
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   788
  assumes a: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" 
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   789
  and     b: "\<Gamma>' \<subseteq> \<Gamma>''"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   790
  and     c: "valid \<Gamma>''"
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   791
  shows "\<Gamma>'' \<turnstile> \<theta> is \<theta>' over \<Gamma>"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   792
using a b c logical_monotonicity by blast
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   793
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   794
lemma equiv_subst_ext :
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   795
  assumes h1: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   796
  and     h2: "\<Gamma>' \<turnstile> s is t : T" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   797
  and     fs: "x\<sharp>\<Gamma>"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   798
  shows "\<Gamma>' \<turnstile> (x,s)#\<theta> is (x,t)#\<theta>' over (x,T)#\<Gamma>"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   799
using assms
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   800
proof -
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   801
  {
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   802
    fix y U
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   803
    assume "(y,U) \<in> set ((x,T)#\<Gamma>)"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   804
    moreover
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   805
    { 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   806
      assume "(y,U) \<in> set [(x,T)]"
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   807
      with h2 have "\<Gamma>' \<turnstile> ((x,s)#\<theta>)<Var y> is ((x,t)#\<theta>')<Var y> : U" by auto 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   808
    }
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   809
    moreover
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   810
    {
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   811
      assume hl:"(y,U) \<in> set \<Gamma>"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   812
      then have "\<not> y\<sharp>\<Gamma>" by (induct \<Gamma>) (auto simp add: fresh_list_cons fresh_atm fresh_prod)
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   813
      then have hf:"x\<sharp> Var y" using fs by (auto simp add: fresh_atm)
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   814
      then have "((x,s)#\<theta>)<Var y> = \<theta><Var y>" "((x,t)#\<theta>')<Var y> = \<theta>'<Var y>" 
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   815
	using fresh_psubst_simp by blast+ 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   816
      moreover have  "\<Gamma>' \<turnstile> \<theta><Var y> is \<theta>'<Var y> : U" using h1 hl by auto
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   817
      ultimately have "\<Gamma>' \<turnstile> ((x,s)#\<theta>)<Var y> is ((x,t)#\<theta>')<Var y> : U" by auto
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   818
    }
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   819
    ultimately have "\<Gamma>' \<turnstile> ((x,s)#\<theta>)<Var y> is ((x,t)#\<theta>')<Var y> : U" by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   820
  }
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   821
  then show "\<Gamma>' \<turnstile> (x,s)#\<theta> is (x,t)#\<theta>' over (x,T)#\<Gamma>" by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   822
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   823
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   824
theorem fundamental_theorem_1:
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   825
  assumes a1: "\<Gamma> \<turnstile> t : T" 
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   826
  and     a2: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>"
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   827
  and     a3: "valid \<Gamma>'" 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   828
  shows "\<Gamma>' \<turnstile> \<theta><t> is \<theta>'<t> : T"   
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   829
using a1 a2 a3
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   830
proof (nominal_induct \<Gamma> t T avoiding: \<theta> \<theta>' arbitrary: \<Gamma>' rule: typing.strong_induct)
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   831
  case (T_Lam x \<Gamma> T\<^isub>1 t\<^isub>2 T\<^isub>2 \<theta> \<theta>' \<Gamma>')
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   832
  have vc: "x\<sharp>\<theta>" "x\<sharp>\<theta>'" "x\<sharp>\<Gamma>" by fact+
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   833
  have asm1: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" by fact
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   834
  have ih:"\<And>\<theta> \<theta>' \<Gamma>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over (x,T\<^isub>1)#\<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><t\<^isub>2> is \<theta>'<t\<^isub>2> : T\<^isub>2" by fact
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   835
  show "\<Gamma>' \<turnstile> \<theta><Lam [x].t\<^isub>2> is \<theta>'<Lam [x].t\<^isub>2> : T\<^isub>1\<rightarrow>T\<^isub>2" using vc
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   836
  proof (simp, intro strip)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   837
    fix \<Gamma>'' s' t'
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   838
    assume sub: "\<Gamma>' \<subseteq> \<Gamma>''" 
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   839
    and    asm2: "\<Gamma>''\<turnstile> s' is t' : T\<^isub>1" 
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   840
    and    val: "valid \<Gamma>''"
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   841
    from asm1 val sub have "\<Gamma>'' \<turnstile> \<theta> is \<theta>' over \<Gamma>" using logical_subst_monotonicity by blast
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   842
    with asm2 vc have "\<Gamma>'' \<turnstile> (x,s')#\<theta> is (x,t')#\<theta>' over (x,T\<^isub>1)#\<Gamma>" using equiv_subst_ext by blast
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   843
    with ih val have "\<Gamma>'' \<turnstile> ((x,s')#\<theta>)<t\<^isub>2> is ((x,t')#\<theta>')<t\<^isub>2> : T\<^isub>2" by auto
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   844
    with vc have "\<Gamma>''\<turnstile>\<theta><t\<^isub>2>[x::=s'] is \<theta>'<t\<^isub>2>[x::=t'] : T\<^isub>2" by (simp add: psubst_subst_psubst)
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   845
    moreover 
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   846
    have "App (Lam [x].\<theta><t\<^isub>2>) s' \<leadsto> \<theta><t\<^isub>2>[x::=s']" by auto
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   847
    moreover 
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   848
    have "App (Lam [x].\<theta>'<t\<^isub>2>) t' \<leadsto> \<theta>'<t\<^isub>2>[x::=t']" by auto
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   849
    ultimately show "\<Gamma>''\<turnstile> App (Lam [x].\<theta><t\<^isub>2>) s' is App (Lam [x].\<theta>'<t\<^isub>2>) t' : T\<^isub>2" 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   850
      using logical_weak_head_closure by auto
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   851
  qed
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   852
qed (auto)
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   853
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   854
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   855
theorem fundamental_theorem_2:
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   856
  assumes h1: "\<Gamma> \<turnstile> s \<equiv> t : T" 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   857
  and     h2: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   858
  and     h3: "valid \<Gamma>'"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   859
  shows "\<Gamma>' \<turnstile> \<theta><s> is \<theta>'<t> : T"
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   860
using h1 h2 h3
22531
1cbfb4066e47 Adapted to changes in nominal_inductive.
berghofe
parents: 22501
diff changeset
   861
proof (nominal_induct \<Gamma> s t T avoiding: \<Gamma>' \<theta> \<theta>' rule: def_equiv.strong_induct)
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   862
  case (Q_Refl \<Gamma> t T \<Gamma>' \<theta> \<theta>')
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   863
  have "\<Gamma> \<turnstile> t : T" 
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   864
  and  "valid \<Gamma>'" by fact+
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   865
  moreover 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   866
  have "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   867
  ultimately show "\<Gamma>' \<turnstile> \<theta><t> is \<theta>'<t> : T" using fundamental_theorem_1 by blast
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   868
next
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   869
  case (Q_Symm \<Gamma> t s T \<Gamma>' \<theta> \<theta>')
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   870
  have "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" 
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   871
  and "valid \<Gamma>'" by fact+
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   872
  moreover 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   873
  have ih: "\<And> \<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><t> is \<theta>'<s> : T" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   874
  ultimately show "\<Gamma>' \<turnstile> \<theta><s> is \<theta>'<t> : T" using logical_symmetry by blast
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   875
next
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   876
  case (Q_Trans \<Gamma> s t T u \<Gamma>' \<theta> \<theta>')
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   877
  have ih1: "\<And> \<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><s> is \<theta>'<t> : T" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   878
  have ih2: "\<And> \<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><t> is \<theta>'<u> : T" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   879
  have h: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" 
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   880
  and  v: "valid \<Gamma>'" by fact+
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   881
  then have "\<Gamma>' \<turnstile> \<theta>' is \<theta>' over \<Gamma>" using logical_pseudo_reflexivity by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   882
  then have "\<Gamma>' \<turnstile> \<theta>'<t> is \<theta>'<u> : T" using ih2 v by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   883
  moreover have "\<Gamma>' \<turnstile> \<theta><s> is \<theta>'<t> : T" using ih1 h v by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   884
  ultimately show "\<Gamma>' \<turnstile> \<theta><s> is \<theta>'<u> : T" using logical_transitivity by blast
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   885
next
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   886
  case (Q_Abs x \<Gamma> T\<^isub>1 s\<^isub>2 t\<^isub>2 T\<^isub>2 \<Gamma>' \<theta> \<theta>')
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   887
  have fs:"x\<sharp>\<Gamma>" by fact
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   888
  have fs2: "x\<sharp>\<theta>" "x\<sharp>\<theta>'" by fact+
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   889
  have h2: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" 
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   890
  and  h3: "valid \<Gamma>'" by fact+
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   891
  have ih:"\<And>\<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over (x,T\<^isub>1)#\<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><s\<^isub>2> is \<theta>'<t\<^isub>2> : T\<^isub>2" by fact
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   892
  {
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   893
    fix \<Gamma>'' s' t'
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   894
    assume "\<Gamma>' \<subseteq> \<Gamma>''" and hl:"\<Gamma>''\<turnstile> s' is t' : T\<^isub>1" and hk: "valid \<Gamma>''"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   895
    then have "\<Gamma>'' \<turnstile> \<theta> is \<theta>' over \<Gamma>" using h2 logical_subst_monotonicity by blast
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   896
    then have "\<Gamma>'' \<turnstile> (x,s')#\<theta> is (x,t')#\<theta>' over (x,T\<^isub>1)#\<Gamma>" using equiv_subst_ext hl fs by blast
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   897
    then have "\<Gamma>'' \<turnstile> ((x,s')#\<theta>)<s\<^isub>2> is ((x,t')#\<theta>')<t\<^isub>2> : T\<^isub>2" using ih hk by blast
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   898
    then have "\<Gamma>''\<turnstile> \<theta><s\<^isub>2>[x::=s'] is \<theta>'<t\<^isub>2>[x::=t'] : T\<^isub>2" using fs2 psubst_subst_psubst by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   899
    moreover have "App (Lam [x]. \<theta><s\<^isub>2>) s' \<leadsto>  \<theta><s\<^isub>2>[x::=s']" 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   900
              and "App (Lam [x].\<theta>'<t\<^isub>2>) t' \<leadsto> \<theta>'<t\<^isub>2>[x::=t']" by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   901
    ultimately have "\<Gamma>'' \<turnstile> App (Lam [x]. \<theta><s\<^isub>2>) s' is App (Lam [x].\<theta>'<t\<^isub>2>) t' : T\<^isub>2" 
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   902
      using logical_weak_head_closure by auto
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   903
  }
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   904
  moreover have "valid \<Gamma>'" by fact
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   905
  ultimately have "\<Gamma>' \<turnstile> Lam [x].\<theta><s\<^isub>2> is Lam [x].\<theta>'<t\<^isub>2> : T\<^isub>1\<rightarrow>T\<^isub>2" by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   906
  then show "\<Gamma>' \<turnstile> \<theta><Lam [x].s\<^isub>2> is \<theta>'<Lam [x].t\<^isub>2> : T\<^isub>1\<rightarrow>T\<^isub>2" using fs2 by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   907
next
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   908
  case (Q_App \<Gamma> s\<^isub>1 t\<^isub>1 T\<^isub>1 T\<^isub>2 s\<^isub>2 t\<^isub>2 \<Gamma>' \<theta> \<theta>')
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   909
  then show "\<Gamma>' \<turnstile> \<theta><App s\<^isub>1 s\<^isub>2> is \<theta>'<App t\<^isub>1 t\<^isub>2> : T\<^isub>2" by auto 
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   910
next
22531
1cbfb4066e47 Adapted to changes in nominal_inductive.
berghofe
parents: 22501
diff changeset
   911
  case (Q_Beta x \<Gamma> s\<^isub>2 t\<^isub>2 T\<^isub>1 s12 t12 T\<^isub>2 \<Gamma>' \<theta> \<theta>')
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   912
  have h: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" 
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   913
  and  h': "valid \<Gamma>'" by fact+
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   914
  have fs: "x\<sharp>\<Gamma>" by fact
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   915
  have fs2: " x\<sharp>\<theta>" "x\<sharp>\<theta>'" by fact+
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   916
  have ih1: "\<And>\<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><s\<^isub>2> is \<theta>'<t\<^isub>2> : T\<^isub>1" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   917
  have ih2: "\<And>\<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over (x,T\<^isub>1)#\<Gamma>; valid \<Gamma>'\<rbrakk> \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><s12> is \<theta>'<t12> : T\<^isub>2" by fact
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   918
  have "\<Gamma>' \<turnstile> \<theta><s\<^isub>2> is \<theta>'<t\<^isub>2> : T\<^isub>1" using ih1 h' h by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   919
  then have "\<Gamma>' \<turnstile> (x,\<theta><s\<^isub>2>)#\<theta> is (x,\<theta>'<t\<^isub>2>)#\<theta>' over (x,T\<^isub>1)#\<Gamma>" using equiv_subst_ext h fs by blast
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   920
  then have "\<Gamma>' \<turnstile> ((x,\<theta><s\<^isub>2>)#\<theta>)<s12> is ((x,\<theta>'<t\<^isub>2>)#\<theta>')<t12> : T\<^isub>2" using ih2 h' by auto
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   921
  then have "\<Gamma>' \<turnstile> \<theta><s12>[x::=\<theta><s\<^isub>2>] is \<theta>'<t12>[x::=\<theta>'<t\<^isub>2>] : T\<^isub>2" using fs2 psubst_subst_psubst by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   922
  then have "\<Gamma>' \<turnstile> \<theta><s12>[x::=\<theta><s\<^isub>2>] is \<theta>'<t12[x::=t\<^isub>2]> : T\<^isub>2" using fs2 psubst_subst_propagate by auto
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   923
  moreover have "App (Lam [x].\<theta><s12>) (\<theta><s\<^isub>2>) \<leadsto> \<theta><s12>[x::=\<theta><s\<^isub>2>]" by auto 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   924
  ultimately have "\<Gamma>' \<turnstile> App (Lam [x].\<theta><s12>) (\<theta><s\<^isub>2>) is \<theta>'<t12[x::=t\<^isub>2]> : T\<^isub>2" 
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   925
    using logical_weak_head_closure' by auto
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   926
  then show "\<Gamma>' \<turnstile> \<theta><App (Lam [x].s12) s\<^isub>2> is \<theta>'<t12[x::=t\<^isub>2]> : T\<^isub>2" using fs2 by simp
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   927
next
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   928
  case (Q_Ext x \<Gamma> s t T\<^isub>1 T\<^isub>2 \<Gamma>' \<theta> \<theta>')
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   929
  have h2: "\<Gamma>' \<turnstile> \<theta> is \<theta>' over \<Gamma>" 
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   930
  and  h2': "valid \<Gamma>'" by fact+
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   931
  have fs:"x\<sharp>\<Gamma>" "x\<sharp>s" "x\<sharp>t" by fact+
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   932
  have ih:"\<And>\<Gamma>' \<theta> \<theta>'. \<lbrakk>\<Gamma>' \<turnstile> \<theta> is \<theta>' over (x,T\<^isub>1)#\<Gamma>; valid \<Gamma>'\<rbrakk> 
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   933
                          \<Longrightarrow> \<Gamma>' \<turnstile> \<theta><App s (Var x)> is \<theta>'<App t (Var x)> : T\<^isub>2" by fact
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   934
   {
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   935
    fix \<Gamma>'' s' t'
22650
0c5b22076fb3 tuned the proof of lemma pt_list_set_fresh (as suggested by Randy Pollack) and tuned the syntax for sub_contexts
urbanc
parents: 22609
diff changeset
   936
    assume hsub: "\<Gamma>' \<subseteq> \<Gamma>''" and hl: "\<Gamma>''\<turnstile> s' is t' : T\<^isub>1" and hk: "valid \<Gamma>''"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   937
    then have "\<Gamma>'' \<turnstile> \<theta> is \<theta>' over \<Gamma>" using h2 logical_subst_monotonicity by blast
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   938
    then have "\<Gamma>'' \<turnstile> (x,s')#\<theta> is (x,t')#\<theta>' over (x,T\<^isub>1)#\<Gamma>" using equiv_subst_ext hl fs by blast
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   939
    then have "\<Gamma>'' \<turnstile> ((x,s')#\<theta>)<App s (Var x)>  is ((x,t')#\<theta>')<App t (Var x)> : T\<^isub>2" using ih hk by blast
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   940
    then 
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   941
    have "\<Gamma>'' \<turnstile> App (((x,s')#\<theta>)<s>) (((x,s')#\<theta>)<(Var x)>) is App (((x,t')#\<theta>')<t>) (((x,t')#\<theta>')<(Var x)>) : T\<^isub>2"
22082
b1be13d32efd tuned a bit the proofs
urbanc
parents: 22073
diff changeset
   942
      by auto
24070
ff4c715a11cd updated some of the definitions and proofs
urbanc
parents: 23760
diff changeset
   943
    then have "\<Gamma>'' \<turnstile> App ((x,s')#\<theta>)<s> s'  is App ((x,t')#\<theta>')<t> t' : T\<^isub>2" by auto
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   944
    then have "\<Gamma>'' \<turnstile> App (\<theta><s>) s' is App (\<theta>'<t>) t' : T\<^isub>2" using fs fresh_psubst_simp by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   945
  }
25107
dbf09ca6a80e tuned proofs: avoid implicit prems;
wenzelm
parents: 24231
diff changeset
   946
  moreover have "valid \<Gamma>'" by fact
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   947
  ultimately show "\<Gamma>' \<turnstile> \<theta><s> is \<theta>'<t> : T\<^isub>1\<rightarrow>T\<^isub>2" by auto
23370
513a8ee192f1 added the Q_Unit rule (was missing) and adjusted the proof accordingly
urbanc
parents: 22829
diff changeset
   948
next
513a8ee192f1 added the Q_Unit rule (was missing) and adjusted the proof accordingly
urbanc
parents: 22829
diff changeset
   949
  case (Q_Unit \<Gamma> s t \<Gamma>' \<theta> \<theta>')  
513a8ee192f1 added the Q_Unit rule (was missing) and adjusted the proof accordingly
urbanc
parents: 22829
diff changeset
   950
  then show "\<Gamma>' \<turnstile> \<theta><s> is \<theta>'<t> : TUnit" by auto
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   951
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   952
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   953
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   954
theorem completeness:
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   955
  assumes asm: "\<Gamma> \<turnstile> s \<equiv> t : T"
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   956
  shows   "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T"
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   957
proof -
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   958
  have val: "valid \<Gamma>" using def_equiv_implies_valid asm by simp
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   959
  moreover
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   960
  {
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   961
    fix x T
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   962
    assume "(x,T) \<in> set \<Gamma>" "valid \<Gamma>"
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   963
    then have "\<Gamma> \<turnstile> Var x is Var x : T" using main_lemma(2) by blast
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   964
  }
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   965
  ultimately have "\<Gamma> \<turnstile> [] is [] over \<Gamma>" by auto 
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   966
  then have "\<Gamma> \<turnstile> []<s> is []<t> : T" using fundamental_theorem_2 val asm by blast
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   967
  then have "\<Gamma> \<turnstile> s is t : T" by simp
22494
b61306c7987a tuned some proofs
urbanc
parents: 22492
diff changeset
   968
  then show  "\<Gamma> \<turnstile> s \<Leftrightarrow> t : T" using main_lemma(1) val by simp
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   969
qed
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   970
22418
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   971
text {* We leave soundness as an exercise - like in the book :-) \\ 
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   972
 @{prop[mode=IfThen] "\<lbrakk>\<Gamma> \<turnstile> s \<Leftrightarrow> t : T; \<Gamma> \<turnstile> t : T; \<Gamma> \<turnstile> s : T\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s \<equiv> t : T"} \\
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   973
 @{prop "\<lbrakk>\<Gamma> \<turnstile> s \<leftrightarrow> t : T; \<Gamma> \<turnstile> t : T; \<Gamma> \<turnstile> s : T\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> s \<equiv> t : T"} 
49e2d9744ae1 major update of the nominal package; there is now an infrastructure
urbanc
parents: 22231
diff changeset
   974
*}
22073
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   975
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   976
end
c170dcbe6c9d formalisation of Crary's chapter on logical relations
urbanc
parents:
diff changeset
   977