src/HOL/Nominal/Examples/VC_Condition.thy
author wenzelm
Thu, 20 Dec 2007 13:58:45 +0100
changeset 25727 e43d91f31118
parent 25722 0a104ddb72d9
child 25751 a4e69ce247e0
permissions -rw-r--r--
adapted theory name;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25722
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
     1
(* $Id$ *)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
     2
25727
e43d91f31118 adapted theory name;
wenzelm
parents: 25722
diff changeset
     3
theory VC_Condition
25722
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
     4
imports "../Nominal" 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
     5
begin
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
     6
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
     7
text {* 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
     8
  We give here two examples that show if we use the variable  
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
     9
  convention carelessly in rule inductions, we might end 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    10
  up with faulty lemmas. The point is that the examples
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    11
  are not variable-convention compatible and therefore in the 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    12
  nominal package one is protected from such bogus reasoning.
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    13
*}
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    14
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    15
text {* 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    16
  We define alpha-equated lambda-terms as usual. *}
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    17
atom_decl name 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    18
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    19
nominal_datatype lam = 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    20
    Var "name"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    21
  | App "lam" "lam"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    22
  | Lam "\<guillemotleft>name\<guillemotright>lam" ("Lam [_]._" [100,100] 100)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    23
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    24
text {*
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    25
  The inductive relation 'unbind' unbinds the top-most  
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    26
  binders of a lambda-term; this relation is obviously  
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    27
  not a function, since it does not respect alpha-      
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    28
  equivalence. However as a relation 'unbind' is ok and     
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    29
  a similar relation has been used in our formalisation 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    30
  of the algorithm W. *}
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    31
inductive
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    32
  unbind :: "lam \<Rightarrow> name list \<Rightarrow> lam \<Rightarrow> bool" ("_ \<mapsto> _,_" [60,60,60] 60)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    33
where
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    34
  u_var: "(Var a) \<mapsto> [],(Var a)"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    35
| u_app: "(App t1 t2) \<mapsto> [],(App t1 t2)"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    36
| u_lam: "t\<mapsto>xs,t' \<Longrightarrow> (Lam [x].t) \<mapsto> (x#xs),t'"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    37
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    38
text {*
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    39
  We can show that Lam [x].Lam [x].Var x unbinds to [x,x],Var x 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    40
  and also to [z,y],Var y (though the proof for the second is a 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    41
  bit clumsy). *} 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    42
lemma unbind_lambda_lambda1: 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    43
  shows "Lam [x].Lam [x].(Var x)\<mapsto>[x,x],(Var x)"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    44
by (auto intro: unbind.intros)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    45
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    46
lemma unbind_lambda_lambda2: 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    47
  shows "Lam [x].Lam [x].(Var x)\<mapsto>[y,z],(Var z)"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    48
proof -
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    49
  have "Lam [x].Lam [x].(Var x) = Lam [y].Lam [z].(Var z)" 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    50
    by (auto simp add: lam.inject alpha calc_atm abs_fresh fresh_atm)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    51
  moreover
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    52
  have "Lam [y].Lam [z].(Var z) \<mapsto> [y,z],(Var z)"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    53
    by (auto intro: unbind.intros)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    54
  ultimately 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    55
  show "Lam [x].Lam [x].(Var x)\<mapsto>[y,z],(Var z)" by simp
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    56
qed
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    57
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    58
text {* Unbind is equivariant ...*}
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    59
equivariance unbind
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    60
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    61
text {*
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    62
  ... but it is not variable-convention compatible (see Urban, 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    63
  Berghofer, Norrish [2007] for more details). This condition 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    64
  requires for rule u_lam to have the binder x being not a free variable 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    65
  in the rule's conclusion. Because this condition is not satisfied, 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    66
  Isabelle will not derive a strong induction principle for 'unbind' 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    67
  - that means Isabelle does not allow us to use the variable 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    68
  convention in induction proofs over 'unbind'. We can, however,  
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    69
  force Isabelle to derive the strengthening induction principle
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    70
  and see what happens. *}
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    71
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    72
nominal_inductive unbind
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    73
  sorry
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    74
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    75
text {*
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    76
  To obtain a faulty lemma, we introduce the function 'bind'
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    77
  which takes a list of names and abstracts away these names in 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    78
  a given lambda-term. *}
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    79
fun 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    80
  bind :: "name list \<Rightarrow> lam \<Rightarrow> lam"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    81
where
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    82
  "bind [] t = t"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    83
| "bind (x#xs) t = Lam [x].(bind xs t)"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    84
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    85
text {*
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    86
  Although not necessary for our main argument below, we can 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    87
  easily prove that bind undoes the unbinding. *}
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    88
lemma bind_unbind:
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    89
  assumes a: "t \<mapsto> xs,t'"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    90
  shows "t = bind xs t'"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    91
using a by (induct) (auto)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    92
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    93
text {*
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    94
  The next lemma shows by induction on xs that if x is a free 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    95
  variable in t and x does not occur in xs, then x is a free 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    96
  variable in bind xs t. In the nominal tradition we formulate    
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    97
  'is a free variable in' as 'is not fresh for'. *}
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    98
lemma free_variable:
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
    99
  fixes x::"name"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   100
  assumes a: "\<not>(x\<sharp>t)" and b: "x\<sharp>xs"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   101
  shows "\<not>(x\<sharp>bind xs t)"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   102
using a b
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   103
by (induct xs)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   104
   (auto simp add: fresh_list_cons abs_fresh fresh_atm)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   105
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   106
text {*
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   107
  Now comes the faulty lemma. It is derived using the     
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   108
  variable convention (i.e. our strong induction principle). 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   109
  This faulty lemma states that if t unbinds to x::xs and t', 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   110
  and x is a free variable in t', then it is also a free 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   111
  variable in bind xs t'. We show this lemma by assuming that 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   112
  the binder x is fresh w.r.t. to the xs unbound previously. *}   
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   113
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   114
lemma faulty1:
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   115
  assumes a: "t\<mapsto>(x#xs),t'"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   116
  shows "\<not>(x\<sharp>t') \<Longrightarrow> \<not>(x\<sharp>bind xs t')"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   117
using a
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   118
by (nominal_induct t xs'\<equiv>"x#xs" t' avoiding: xs rule: unbind.strong_induct)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   119
   (simp_all add: free_variable)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   120
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   121
text {*
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   122
  Obviously the faulty lemma does not hold, for example, in 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   123
  case Lam [x].Lam [x].(Var x) \<mapsto> [x,x],(Var x). Therefore,
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   124
  we can prove False. *}
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   125
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   126
lemma false1:
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   127
  shows "False"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   128
proof -
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   129
  have "Lam [x].Lam [x].(Var x)\<mapsto>[x,x],(Var x)" 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   130
  and  "\<not>(x\<sharp>Var x)" by (simp_all add: unbind_lambda_lambda1 fresh_atm)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   131
  then have "\<not>(x\<sharp>(bind [x] (Var x)))" by (rule faulty1)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   132
  moreover 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   133
  have "x\<sharp>(bind [x] (Var x))" by (simp add: abs_fresh)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   134
  ultimately
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   135
  show "False" by simp
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   136
qed
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   137
   
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   138
text {* 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   139
  The next example is slightly simpler, but looks more
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   140
  contrived than 'unbind'. This example, caled 'strip' just 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   141
  strips off the top-most binders from lambdas. *}
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   142
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   143
inductive
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   144
  strip :: "lam \<Rightarrow> lam \<Rightarrow> bool" ("_ \<rightarrow> _" [60,60] 60)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   145
where
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   146
  s_var: "(Var a) \<rightarrow> (Var a)"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   147
| s_app: "(App t1 t2) \<rightarrow> (App t1 t2)"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   148
| s_lam: "t \<rightarrow> t' \<Longrightarrow> (Lam [x].t) \<rightarrow> t'"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   149
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   150
text {* 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   151
  The relation is equivariant but we have to use again 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   152
  sorry to derive a strong induction principle. *}
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   153
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   154
equivariance strip
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   155
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   156
nominal_inductive strip
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   157
  sorry
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   158
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   159
text {*
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   160
  The faulty lemma shows that a variable that is fresh
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   161
  for a term is also fresh for the term after striping. *}
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   162
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   163
lemma faulty2:
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   164
  fixes x::"name"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   165
  assumes a: "t \<rightarrow> t'"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   166
  shows "x\<sharp>t \<Longrightarrow> x\<sharp>t'"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   167
using a
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   168
by (nominal_induct t t'\<equiv>t' avoiding: t' rule: strip.strong_induct)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   169
   (auto simp add: abs_fresh)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   170
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   171
text {*
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   172
  Obviously Lam [x].Var x is a counter example to this lemma. *}
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   173
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   174
lemma false2:
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   175
  shows "False"
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   176
proof -
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   177
  have "Lam [x].(Var x) \<rightarrow> (Var x)" by (auto intro: strip.intros)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   178
  moreover
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   179
  have "x\<sharp>Lam [x].(Var x)" by (simp add: abs_fresh)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   180
  ultimately have "x\<sharp>(Var x)" by (simp only: faulty2)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   181
  then show "False" by (simp add: fresh_atm)
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   182
qed 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   183
 
0a104ddb72d9 polishing of some proofs
urbanc
parents:
diff changeset
   184
end