src/HOL/Nominal/Examples/Weakening.thy
author urbanc
Tue, 13 Dec 2005 18:11:21 +0100
changeset 18396 b3e7da94b51f
parent 18354 715d6df89fcc
child 18653 7a00c80400b1
permissions -rw-r--r--
added a fresh_left lemma that contains all instantiation for the various atom-types.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18269
3f36e2165e51 some small tuning
urbanc
parents: 18105
diff changeset
     1
(* $Id$ *)
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
     2
18269
3f36e2165e51 some small tuning
urbanc
parents: 18105
diff changeset
     3
theory weakening 
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
     4
imports "../nominal" 
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
     5
begin
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
     6
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
     7
(* WEAKENING EXAMPLE*)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
     8
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
     9
section {* Simply-Typed Lambda-Calculus *}
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    10
(*======================================*)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    11
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    12
atom_decl name 
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    13
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    14
nominal_datatype lam = Var "name"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    15
                     | App "lam" "lam"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    16
                     | Lam "\<guillemotleft>name\<guillemotright>lam" ("Lam [_]._" [100,100] 100)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    17
18352
urbanc
parents: 18346
diff changeset
    18
nominal_datatype ty =
urbanc
parents: 18346
diff changeset
    19
    TVar "nat"
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    20
  | TArr "ty" "ty" (infix "\<rightarrow>" 200)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    21
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    22
lemma perm_ty[simp]:
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    23
  fixes pi ::"name prm"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    24
  and   \<tau>  ::"ty"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    25
  shows "pi\<bullet>\<tau> = \<tau>"
18352
urbanc
parents: 18346
diff changeset
    26
by (induct \<tau> rule: ty.induct_weak, simp_all add: perm_nat_def)  
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    27
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    28
(* valid contexts *)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    29
consts
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    30
  ctxts :: "((name\<times>ty) list) set" 
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    31
  valid :: "(name\<times>ty) list \<Rightarrow> bool"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    32
translations
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    33
  "valid \<Gamma>" \<rightleftharpoons> "\<Gamma> \<in> ctxts"  
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    34
inductive ctxts
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    35
intros
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    36
v1[intro]: "valid []"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    37
v2[intro]: "\<lbrakk>valid \<Gamma>;a\<sharp>\<Gamma>\<rbrakk>\<Longrightarrow> valid ((a,\<sigma>)#\<Gamma>)"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    38
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    39
lemma eqvt_valid:
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    40
  fixes   pi:: "name prm"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    41
  assumes a: "valid \<Gamma>"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    42
  shows   "valid (pi\<bullet>\<Gamma>)"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    43
using a
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    44
apply(induct)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    45
apply(auto simp add: pt_fresh_bij[OF pt_name_inst, OF at_name_inst])
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    46
done
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    47
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    48
(* typing judgements *)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    49
consts
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    50
  typing :: "(((name\<times>ty) list)\<times>lam\<times>ty) set" 
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    51
syntax
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    52
  "_typing_judge" :: "(name\<times>ty) list\<Rightarrow>lam\<Rightarrow>ty\<Rightarrow>bool" (" _ \<turnstile> _ : _ " [80,80,80] 80) 
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    53
translations
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    54
  "\<Gamma> \<turnstile> t : \<tau>" \<rightleftharpoons> "(\<Gamma>,t,\<tau>) \<in> typing"  
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    55
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    56
inductive typing
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    57
intros
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    58
t1[intro]: "\<lbrakk>valid \<Gamma>; (a,\<tau>)\<in>set \<Gamma>\<rbrakk>\<Longrightarrow> \<Gamma> \<turnstile> Var a : \<tau>"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    59
t2[intro]: "\<lbrakk>\<Gamma> \<turnstile> t1 : \<tau>\<rightarrow>\<sigma>; \<Gamma> \<turnstile> t2 : \<tau>\<rbrakk>\<Longrightarrow> \<Gamma> \<turnstile> App t1 t2 : \<sigma>"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    60
t3[intro]: "\<lbrakk>a\<sharp>\<Gamma>;((a,\<tau>)#\<Gamma>) \<turnstile> t : \<sigma>\<rbrakk> \<Longrightarrow> \<Gamma> \<turnstile> Lam [a].t : \<tau>\<rightarrow>\<sigma>"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    61
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    62
lemma eqvt_typing: 
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    63
  fixes  \<Gamma> :: "(name\<times>ty) list"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    64
  and    t :: "lam"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    65
  and    \<tau> :: "ty"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    66
  and    pi:: "name prm"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    67
  assumes a: "\<Gamma> \<turnstile> t : \<tau>"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    68
  shows "(pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>t) : \<tau>"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    69
using a
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    70
proof (induct)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    71
  case (t1 \<Gamma> \<tau> a)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    72
  have "valid (pi\<bullet>\<Gamma>)" by (rule eqvt_valid)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    73
  moreover
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    74
  have "(pi\<bullet>(a,\<tau>))\<in>((pi::name prm)\<bullet>set \<Gamma>)" by (rule pt_set_bij2[OF pt_name_inst, OF at_name_inst])
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    75
  ultimately show "(pi\<bullet>\<Gamma>) \<turnstile> ((pi::name prm)\<bullet>Var a) : \<tau>"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    76
    using typing.intros by (force simp add: pt_list_set_pi[OF pt_name_inst, symmetric])
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    77
next 
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    78
  case (t3 \<Gamma> \<sigma> \<tau> a t)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    79
  moreover have "(pi\<bullet>a)\<sharp>(pi\<bullet>\<Gamma>)" by (rule pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    80
  ultimately show "(pi\<bullet>\<Gamma>) \<turnstile> (pi\<bullet>Lam [a].t) :\<tau>\<rightarrow>\<sigma>" by force 
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    81
qed (auto)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    82
18296
3dcc34f18bfa adapted to the new nominal_induction
urbanc
parents: 18269
diff changeset
    83
lemma typing_induct[consumes 1, case_names t1 t2 t3]:
3dcc34f18bfa adapted to the new nominal_induction
urbanc
parents: 18269
diff changeset
    84
  fixes  P :: "'a::fs_name\<Rightarrow>(name\<times>ty) list \<Rightarrow> lam \<Rightarrow> ty \<Rightarrow>bool"
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    85
  and    \<Gamma> :: "(name\<times>ty) list"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    86
  and    t :: "lam"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    87
  and    \<tau> :: "ty"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    88
  and    x :: "'a::fs_name"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
    89
  assumes a: "\<Gamma> \<turnstile> t : \<tau>"
18296
3dcc34f18bfa adapted to the new nominal_induction
urbanc
parents: 18269
diff changeset
    90
  and a1:    "\<And>\<Gamma> (a::name) \<tau> x. valid \<Gamma> \<Longrightarrow> (a,\<tau>) \<in> set \<Gamma> \<Longrightarrow> P x \<Gamma> (Var a) \<tau>"
3dcc34f18bfa adapted to the new nominal_induction
urbanc
parents: 18269
diff changeset
    91
  and a2:    "\<And>\<Gamma> \<tau> \<sigma> t1 t2 x. 
3dcc34f18bfa adapted to the new nominal_induction
urbanc
parents: 18269
diff changeset
    92
              \<Gamma> \<turnstile> t1 : \<tau>\<rightarrow>\<sigma> \<Longrightarrow> (\<And>z. P z \<Gamma> t1 (\<tau>\<rightarrow>\<sigma>)) \<Longrightarrow> \<Gamma> \<turnstile> t2 : \<tau> \<Longrightarrow> (\<And>z. P z \<Gamma> t2 \<tau>)
3dcc34f18bfa adapted to the new nominal_induction
urbanc
parents: 18269
diff changeset
    93
              \<Longrightarrow> P x \<Gamma> (App t1 t2) \<sigma>"
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
    94
  and a3:    "\<And>a \<Gamma> \<tau> \<sigma> t x. a\<sharp>x \<Longrightarrow> a\<sharp>\<Gamma> \<Longrightarrow> ((a,\<tau>) # \<Gamma>) \<turnstile> t : \<sigma> \<Longrightarrow> (\<And>z. P z ((a,\<tau>)#\<Gamma>) t \<sigma>)
18296
3dcc34f18bfa adapted to the new nominal_induction
urbanc
parents: 18269
diff changeset
    95
              \<Longrightarrow> P x \<Gamma> (Lam [a].t) (\<tau>\<rightarrow>\<sigma>)"
3dcc34f18bfa adapted to the new nominal_induction
urbanc
parents: 18269
diff changeset
    96
  shows "P x \<Gamma> t \<tau>"
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
    97
proof -
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
    98
  from a have "\<And>(pi::name prm) x. P x (pi\<bullet>\<Gamma>) (pi\<bullet>t) \<tau>"
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
    99
  proof (induct)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   100
    case (t1 \<Gamma> \<tau> a)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   101
    have j1: "valid \<Gamma>" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   102
    have j2: "(a,\<tau>)\<in>set \<Gamma>" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   103
    from j1 have j3: "valid (pi\<bullet>\<Gamma>)" by (rule eqvt_valid)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   104
    from j2 have "pi\<bullet>(a,\<tau>)\<in>pi\<bullet>(set \<Gamma>)" by (simp only: pt_set_bij[OF pt_name_inst, OF at_name_inst])  
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   105
    hence j4: "(pi\<bullet>a,\<tau>)\<in>set (pi\<bullet>\<Gamma>)" by (simp add: pt_list_set_pi[OF pt_name_inst])
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   106
    show "P x (pi\<bullet>\<Gamma>) (pi\<bullet>(Var a)) \<tau>" using a1 j3 j4 by simp
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   107
  next
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   108
    case (t2 \<Gamma> \<sigma> \<tau> t1 t2)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   109
    thus ?case using a2 by (simp, blast intro: eqvt_typing)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   110
  next
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   111
    case (t3 \<Gamma> \<sigma> \<tau> a t)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   112
    have k1: "a\<sharp>\<Gamma>" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   113
    have k2: "((a,\<tau>)#\<Gamma>)\<turnstile>t:\<sigma>" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   114
    have k3: "\<And>(pi::name prm) (x::'a::fs_name). P x (pi \<bullet>((a,\<tau>)#\<Gamma>)) (pi\<bullet>t) \<sigma>" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   115
    have f: "\<exists>c::name. c\<sharp>(pi\<bullet>a,pi\<bullet>t,pi\<bullet>\<Gamma>,x)"
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   116
      by (rule at_exists_fresh[OF at_name_inst], simp add: fs_name1)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   117
    then obtain c::"name" 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   118
      where f1: "c\<noteq>(pi\<bullet>a)" and f2: "c\<sharp>x" and f3: "c\<sharp>(pi\<bullet>t)" and f4: "c\<sharp>(pi\<bullet>\<Gamma>)"
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   119
      by (force simp add: fresh_prod at_fresh[OF at_name_inst])
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   120
    from k1 have k1a: "(pi\<bullet>a)\<sharp>(pi\<bullet>\<Gamma>)" 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   121
      by (simp add: pt_fresh_left[OF pt_name_inst, OF at_name_inst] 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   122
                    pt_rev_pi[OF pt_name_inst, OF at_name_inst])
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   123
    have l1: "(([(c,pi\<bullet>a)]@pi)\<bullet>\<Gamma>) = (pi\<bullet>\<Gamma>)" using f4 k1a 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   124
      by (simp only: pt2[OF pt_name_inst], rule pt_fresh_fresh[OF pt_name_inst, OF at_name_inst])
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   125
    have "\<And>x. P x (([(c,pi\<bullet>a)]@pi)\<bullet>((a,\<tau>)#\<Gamma>)) (([(c,pi\<bullet>a)]@pi)\<bullet>t) \<sigma>" using k3 by force
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   126
    hence l2: "\<And>x. P x ((c, \<tau>)#(pi\<bullet>\<Gamma>)) (([(c,pi\<bullet>a)]@pi)\<bullet>t) \<sigma>" using f1 l1
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   127
      by (force simp add: pt2[OF pt_name_inst]  at_calc[OF at_name_inst])
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   128
    have "(([(c,pi\<bullet>a)]@pi)\<bullet>((a,\<tau>)#\<Gamma>)) \<turnstile> (([(c,pi\<bullet>a)]@pi)\<bullet>t) : \<sigma>" using k2 by (rule eqvt_typing)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   129
    hence l3: "((c, \<tau>)#(pi\<bullet>\<Gamma>)) \<turnstile> (([(c,pi\<bullet>a)]@pi)\<bullet>t) : \<sigma>" using l1 f1 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   130
      by (force simp add: pt2[OF pt_name_inst]  at_calc[OF at_name_inst])
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   131
    have l4: "P x (pi\<bullet>\<Gamma>) (Lam [c].(([(c,pi\<bullet>a)]@pi)\<bullet>t)) (\<tau> \<rightarrow> \<sigma>)" using f2 f4 l2 l3 a3 by auto
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   132
    have alpha: "(Lam [c].([(c,pi\<bullet>a)]\<bullet>(pi\<bullet>t))) = (Lam [(pi\<bullet>a)].(pi\<bullet>t))" using f1 f3
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   133
      by (simp add: lam.inject alpha)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   134
    show "P x (pi\<bullet>\<Gamma>) (pi\<bullet>(Lam [a].t)) (\<tau> \<rightarrow> \<sigma>)" using l4 alpha 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   135
      by (simp only: pt2[OF pt_name_inst], simp)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   136
  qed
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   137
  hence "P x (([]::name prm)\<bullet>\<Gamma>) (([]::name prm)\<bullet>t) \<tau>" by blast
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   138
  thus "P x \<Gamma> t \<tau>" by simp
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   139
qed
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   140
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   141
(* Now it comes: The Weakening Lemma *)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   142
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   143
constdefs
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   144
  "sub" :: "(name\<times>ty) list \<Rightarrow> (name\<times>ty) list \<Rightarrow> bool" (" _ \<lless> _ " [80,80] 80)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   145
  "\<Gamma>1 \<lless> \<Gamma>2 \<equiv> \<forall>a \<sigma>. (a,\<sigma>)\<in>set \<Gamma>1 \<longrightarrow>  (a,\<sigma>)\<in>set \<Gamma>2"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   146
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   147
lemma weakening_version1: 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   148
  assumes a: "\<Gamma>1 \<turnstile> t : \<sigma>" 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   149
  and     b: "valid \<Gamma>2" 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   150
  and     c: "\<Gamma>1 \<lless> \<Gamma>2"
18296
3dcc34f18bfa adapted to the new nominal_induction
urbanc
parents: 18269
diff changeset
   151
  shows "\<Gamma>2 \<turnstile> t:\<sigma>"
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   152
using a b c
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   153
apply(nominal_induct \<Gamma>1 t \<sigma> avoiding: \<Gamma>2 rule: typing_induct)
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   154
apply(auto simp add: sub_def)
18354
urbanc
parents: 18352
diff changeset
   155
(* FIXME: this was completely automatic before the *)
urbanc
parents: 18352
diff changeset
   156
(* change to meta-connectives :o(                  *)
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   157
apply(atomize)
18296
3dcc34f18bfa adapted to the new nominal_induction
urbanc
parents: 18269
diff changeset
   158
apply(auto)
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   159
done
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   160
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   161
lemma weakening_version2: 
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   162
  fixes \<Gamma>1::"(name\<times>ty) list"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   163
  and   t ::"lam"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   164
  and   \<tau> ::"ty"
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   165
  assumes a: "\<Gamma>1 \<turnstile> t:\<sigma>"
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   166
  and     b: "valid \<Gamma>2" 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   167
  and     c: "\<Gamma>1 \<lless> \<Gamma>2"
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   168
  shows "\<Gamma>2 \<turnstile> t:\<sigma>"
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   169
using a b c
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   170
proof (nominal_induct \<Gamma>1 t \<sigma> avoiding: \<Gamma>2 rule: typing_induct, auto)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   171
  case (t1 \<Gamma>1 a \<tau>)  (* variable case *)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   172
  have "\<Gamma>1 \<lless> \<Gamma>2" 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   173
  and  "valid \<Gamma>2" 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   174
  and  "(a,\<tau>)\<in> set \<Gamma>1" by fact+
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   175
  thus "\<Gamma>2 \<turnstile> Var a : \<tau>" by (force simp add: sub_def)
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   176
next
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   177
  case (t3 a \<Gamma>1 \<tau> \<sigma> t) (* lambda case *)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   178
  have a1: "\<Gamma>1 \<lless> \<Gamma>2" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   179
  have a2: "valid \<Gamma>2" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   180
  have a3: "a\<sharp>\<Gamma>2" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   181
  have ih: "\<And>\<Gamma>3. valid \<Gamma>3 \<Longrightarrow> ((a,\<tau>)#\<Gamma>1) \<lless> \<Gamma>3 \<Longrightarrow>  \<Gamma>3 \<turnstile> t:\<sigma>" by fact
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   182
  have "((a,\<tau>)#\<Gamma>1) \<lless> ((a,\<tau>)#\<Gamma>2)" using a1 by (simp add: sub_def)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   183
  moreover
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   184
  have "valid ((a,\<tau>)#\<Gamma>2)" using a2 a3 v2 by force
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   185
  ultimately have "((a,\<tau>)#\<Gamma>2) \<turnstile> t:\<sigma>" using ih by force
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   186
  with a3 show "\<Gamma>2 \<turnstile> (Lam [a].t) : \<tau> \<rightarrow> \<sigma>" by force
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   187
qed
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   188
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   189
lemma weakening_version3: 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   190
  assumes a: "\<Gamma>1 \<turnstile> t:\<sigma>"
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   191
  and     b: "valid \<Gamma>2" 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   192
  and     c: "\<Gamma>1 \<lless> \<Gamma>2"
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   193
  shows "\<Gamma>2 \<turnstile> t:\<sigma>"
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   194
using a b c
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   195
proof (nominal_induct \<Gamma>1 t \<sigma> avoiding: \<Gamma>2 rule: typing_induct)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   196
  case (t3 a \<Gamma>1 \<tau> \<sigma> t) (* lambda case *)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   197
  have fc: "a\<sharp>\<Gamma>2" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   198
  have ih: "\<And>\<Gamma>3. valid \<Gamma>3 \<Longrightarrow> ((a,\<tau>)#\<Gamma>1) \<lless> \<Gamma>3  \<Longrightarrow>  \<Gamma>3 \<turnstile> t:\<sigma>" by fact 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   199
  have a1: "\<Gamma>1 \<lless> \<Gamma>2" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   200
  have a2: "valid \<Gamma>2" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   201
  have "((a,\<tau>)#\<Gamma>1) \<lless> ((a,\<tau>)#\<Gamma>2)" using a1 sub_def by simp 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   202
  moreover
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   203
  have "valid ((a,\<tau>)#\<Gamma>2)" using a2 fc by force
18346
urbanc
parents: 18311
diff changeset
   204
  ultimately have "((a,\<tau>)#\<Gamma>2) \<turnstile> t:\<sigma>" using ih by simp 
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   205
  with fc show "\<Gamma>2 \<turnstile> (Lam [a].t) : \<tau> \<rightarrow> \<sigma>" by force
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   206
qed (auto simp add: sub_def) (* app and var case *)
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   207
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   208
text{* The original induction principle for typing 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   209
       is not strong enough - so the simple proof fails *}
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   210
lemma weakening_too_weak: 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   211
  assumes a: "\<Gamma>1 \<turnstile> t:\<sigma>"
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   212
  and     b: "valid \<Gamma>2" 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   213
  and     c: "\<Gamma>1 \<lless> \<Gamma>2"
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   214
  shows "\<Gamma>2 \<turnstile> t:\<sigma>"
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   215
using a b c
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   216
proof (induct fixing: \<Gamma>2)
18296
3dcc34f18bfa adapted to the new nominal_induction
urbanc
parents: 18269
diff changeset
   217
  case (t1 \<Gamma>1 \<tau> a) (* variable case *)
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   218
  have "\<Gamma>1 \<lless> \<Gamma>2" 
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   219
  and  "valid \<Gamma>2"
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   220
  and  "(a,\<tau>) \<in> (set \<Gamma>1)" by fact+ 
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   221
  thus "\<Gamma>2 \<turnstile> Var a : \<tau>" by (force simp add: sub_def)
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   222
next
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   223
  case (t3 \<Gamma>1 \<sigma> \<tau> a t) (* lambda case *)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   224
  (* all assumption in this case*)
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   225
  have a0: "a\<sharp>\<Gamma>1" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   226
  have a1: "((a,\<tau>)#\<Gamma>1) \<turnstile> t : \<sigma>" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   227
  have a2: "\<Gamma>1 \<lless> \<Gamma>2" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   228
  have a3: "valid \<Gamma>2" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   229
  have ih: "\<And>\<Gamma>3. valid \<Gamma>3 \<Longrightarrow> ((a,\<tau>)#\<Gamma>1) \<lless> \<Gamma>3  \<Longrightarrow>  \<Gamma>3 \<turnstile> t:\<sigma>" by fact
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   230
  have "((a,\<tau>)#\<Gamma>1) \<lless> ((a,\<tau>)#\<Gamma>2)" using a2 by (simp add: sub_def)
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   231
  moreover
18311
b83b00cbaecf changed "fresh:" to "avoiding:" and cleaned up the weakening example
urbanc
parents: 18296
diff changeset
   232
  have "valid ((a,\<tau>)#\<Gamma>2)" using v2 (* fails *) 
18105
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   233
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   234
4c9c081a416b Initial commit of the theory "Weakening".
urbanc
parents:
diff changeset
   235