| author | haftmann | 
| Wed, 21 Oct 2009 08:16:25 +0200 | |
| changeset 33039 | 5018f6a76b3f | 
| parent 32960 | 69916a850301 | 
| child 39459 | 7753083c00e6 | 
| permissions | -rw-r--r-- | 
| 27623 | 1 | (* Title: HOL/Nominal/Examples/Standardization.thy | 
| 2 | Author: Stefan Berghofer and Tobias Nipkow | |
| 3 | Copyright 2005, 2008 TU Muenchen | |
| 4 | *) | |
| 5 | ||
| 6 | header {* Standardization *}
 | |
| 7 | ||
| 8 | theory Standardization | |
| 9 | imports Nominal | |
| 10 | begin | |
| 11 | ||
| 12 | text {*
 | |
| 13 | The proof of the standardization theorem, as well as most of the theorems about | |
| 14 | lambda calculus in the following sections, are taken from @{text "HOL/Lambda"}.
 | |
| 15 | *} | |
| 16 | ||
| 17 | subsection {* Lambda terms *}
 | |
| 18 | ||
| 19 | atom_decl name | |
| 20 | ||
| 21 | nominal_datatype lam = | |
| 22 | Var "name" | |
| 23 | | App "lam" "lam" (infixl "\<degree>" 200) | |
| 24 | | Lam "\<guillemotleft>name\<guillemotright>lam" ("Lam [_]._" [0, 10] 10)
 | |
| 25 | ||
| 29097 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 berghofe parents: 
27623diff
changeset | 26 | instantiation lam :: size | 
| 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 berghofe parents: 
27623diff
changeset | 27 | begin | 
| 27623 | 28 | |
| 29097 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 berghofe parents: 
27623diff
changeset | 29 | nominal_primrec size_lam | 
| 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 berghofe parents: 
27623diff
changeset | 30 | where | 
| 27623 | 31 | "size (Var n) = 0" | 
| 29097 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 berghofe parents: 
27623diff
changeset | 32 | | "size (t \<degree> u) = size t + size u + 1" | 
| 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 berghofe parents: 
27623diff
changeset | 33 | | "size (Lam [x].t) = size t + 1" | 
| 27623 | 34 | apply finite_guess+ | 
| 35 | apply (rule TrueI)+ | |
| 36 | apply (simp add: fresh_nat) | |
| 37 | apply fresh_guess+ | |
| 38 | done | |
| 39 | ||
| 29097 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 berghofe parents: 
27623diff
changeset | 40 | instance .. | 
| 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 berghofe parents: 
27623diff
changeset | 41 | |
| 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 berghofe parents: 
27623diff
changeset | 42 | end | 
| 27623 | 43 | |
| 44 | nominal_primrec | |
| 29097 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 berghofe parents: 
27623diff
changeset | 45 |   subst :: "lam \<Rightarrow> name \<Rightarrow> lam \<Rightarrow> lam"  ("_[_::=_]" [300, 0, 0] 300)
 | 
| 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 berghofe parents: 
27623diff
changeset | 46 | where | 
| 27623 | 47 | subst_Var: "(Var x)[y::=s] = (if x=y then s else (Var x))" | 
| 29097 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 berghofe parents: 
27623diff
changeset | 48 | | subst_App: "(t\<^isub>1 \<degree> t\<^isub>2)[y::=s] = t\<^isub>1[y::=s] \<degree> t\<^isub>2[y::=s]" | 
| 
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
 berghofe parents: 
27623diff
changeset | 49 | | subst_Lam: "x \<sharp> (y, s) \<Longrightarrow> (Lam [x].t)[y::=s] = (Lam [x].(t[y::=s]))" | 
| 27623 | 50 | apply(finite_guess)+ | 
| 51 | apply(rule TrueI)+ | |
| 52 | apply(simp add: abs_fresh) | |
| 53 | apply(fresh_guess)+ | |
| 54 | done | |
| 55 | ||
| 56 | lemma subst_eqvt [eqvt]: | |
| 57 | "(pi::name prm) \<bullet> (t[x::=u]) = (pi \<bullet> t)[(pi \<bullet> x)::=(pi \<bullet> u)]" | |
| 58 | by (nominal_induct t avoiding: x u rule: lam.strong_induct) | |
| 59 | (perm_simp add: fresh_bij)+ | |
| 60 | ||
| 61 | lemma subst_rename: | |
| 62 | "y \<sharp> t \<Longrightarrow> ([(y, x)] \<bullet> t)[y::=u] = t[x::=u]" | |
| 63 | by (nominal_induct t avoiding: x y u rule: lam.strong_induct) | |
| 64 | (simp_all add: fresh_atm calc_atm abs_fresh) | |
| 65 | ||
| 66 | lemma fresh_subst: | |
| 67 | "(x::name) \<sharp> t \<Longrightarrow> x \<sharp> u \<Longrightarrow> x \<sharp> t[y::=u]" | |
| 68 | by (nominal_induct t avoiding: x y u rule: lam.strong_induct) | |
| 69 | (auto simp add: abs_fresh fresh_atm) | |
| 70 | ||
| 71 | lemma fresh_subst': | |
| 72 | "(x::name) \<sharp> u \<Longrightarrow> x \<sharp> t[x::=u]" | |
| 73 | by (nominal_induct t avoiding: x u rule: lam.strong_induct) | |
| 74 | (auto simp add: abs_fresh fresh_atm) | |
| 75 | ||
| 76 | lemma subst_forget: "(x::name) \<sharp> t \<Longrightarrow> t[x::=u] = t" | |
| 77 | by (nominal_induct t avoiding: x u rule: lam.strong_induct) | |
| 78 | (auto simp add: abs_fresh fresh_atm) | |
| 79 | ||
| 80 | lemma subst_subst: | |
| 81 | "x \<noteq> y \<Longrightarrow> x \<sharp> v \<Longrightarrow> t[y::=v][x::=u[y::=v]] = t[x::=u][y::=v]" | |
| 82 | by (nominal_induct t avoiding: x y u v rule: lam.strong_induct) | |
| 83 | (auto simp add: fresh_subst subst_forget) | |
| 84 | ||
| 85 | declare subst_Var [simp del] | |
| 86 | ||
| 87 | lemma subst_eq [simp]: "(Var x)[x::=u] = u" | |
| 88 | by (simp add: subst_Var) | |
| 89 | ||
| 90 | lemma subst_neq [simp]: "x \<noteq> y \<Longrightarrow> (Var x)[y::=u] = Var x" | |
| 91 | by (simp add: subst_Var) | |
| 92 | ||
| 93 | inductive beta :: "lam \<Rightarrow> lam \<Rightarrow> bool" (infixl "\<rightarrow>\<^sub>\<beta>" 50) | |
| 94 | where | |
| 95 | beta: "x \<sharp> t \<Longrightarrow> (Lam [x].s) \<degree> t \<rightarrow>\<^sub>\<beta> s[x::=t]" | |
| 96 | | appL [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t \<Longrightarrow> s \<degree> u \<rightarrow>\<^sub>\<beta> t \<degree> u" | |
| 97 | | appR [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t \<Longrightarrow> u \<degree> s \<rightarrow>\<^sub>\<beta> u \<degree> t" | |
| 98 | | abs [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t \<Longrightarrow> (Lam [x].s) \<rightarrow>\<^sub>\<beta> (Lam [x].t)" | |
| 99 | ||
| 100 | equivariance beta | |
| 101 | nominal_inductive beta | |
| 102 | by (simp_all add: abs_fresh fresh_subst') | |
| 103 | ||
| 104 | lemma better_beta [simp, intro!]: "(Lam [x].s) \<degree> t \<rightarrow>\<^sub>\<beta> s[x::=t]" | |
| 105 | proof - | |
| 106 | obtain y::name where y: "y \<sharp> (x, s, t)" | |
| 107 | by (rule exists_fresh) (rule fin_supp) | |
| 108 | then have "y \<sharp> t" by simp | |
| 109 | then have "(Lam [y]. [(y, x)] \<bullet> s) \<degree> t \<rightarrow>\<^sub>\<beta> ([(y, x)] \<bullet> s)[y::=t]" | |
| 110 | by (rule beta) | |
| 111 | moreover from y have "(Lam [x].s) = (Lam [y]. [(y, x)] \<bullet> s)" | |
| 112 | by (auto simp add: lam.inject alpha' fresh_prod fresh_atm) | |
| 113 | ultimately show ?thesis using y by (simp add: subst_rename) | |
| 114 | qed | |
| 115 | ||
| 116 | abbreviation | |
| 117 | beta_reds :: "lam \<Rightarrow> lam \<Rightarrow> bool" (infixl "\<rightarrow>\<^sub>\<beta>\<^sup>*" 50) where | |
| 118 | "s \<rightarrow>\<^sub>\<beta>\<^sup>* t \<equiv> beta\<^sup>*\<^sup>* s t" | |
| 119 | ||
| 120 | ||
| 121 | subsection {* Application of a term to a list of terms *}
 | |
| 122 | ||
| 123 | abbreviation | |
| 124 | list_application :: "lam \<Rightarrow> lam list \<Rightarrow> lam" (infixl "\<degree>\<degree>" 150) where | |
| 125 | "t \<degree>\<degree> ts \<equiv> foldl (op \<degree>) t ts" | |
| 126 | ||
| 127 | lemma apps_eq_tail_conv [iff]: "(r \<degree>\<degree> ts = s \<degree>\<degree> ts) = (r = s)" | |
| 128 | by (induct ts rule: rev_induct) (auto simp add: lam.inject) | |
| 129 | ||
| 130 | lemma Var_eq_apps_conv [iff]: "(Var m = s \<degree>\<degree> ss) = (Var m = s \<and> ss = [])" | |
| 131 | by (induct ss arbitrary: s) auto | |
| 132 | ||
| 133 | lemma Var_apps_eq_Var_apps_conv [iff]: | |
| 134 | "(Var m \<degree>\<degree> rs = Var n \<degree>\<degree> ss) = (m = n \<and> rs = ss)" | |
| 135 | apply (induct rs arbitrary: ss rule: rev_induct) | |
| 136 | apply (simp add: lam.inject) | |
| 137 | apply blast | |
| 138 | apply (induct_tac ss rule: rev_induct) | |
| 139 | apply (auto simp add: lam.inject) | |
| 140 | done | |
| 141 | ||
| 142 | lemma App_eq_foldl_conv: | |
| 143 | "(r \<degree> s = t \<degree>\<degree> ts) = | |
| 144 | (if ts = [] then r \<degree> s = t | |
| 145 | else (\<exists>ss. ts = ss @ [s] \<and> r = t \<degree>\<degree> ss))" | |
| 146 | apply (rule_tac xs = ts in rev_exhaust) | |
| 147 | apply (auto simp add: lam.inject) | |
| 148 | done | |
| 149 | ||
| 150 | lemma Abs_eq_apps_conv [iff]: | |
| 151 | "((Lam [x].r) = s \<degree>\<degree> ss) = ((Lam [x].r) = s \<and> ss = [])" | |
| 152 | by (induct ss rule: rev_induct) auto | |
| 153 | ||
| 154 | lemma apps_eq_Abs_conv [iff]: "(s \<degree>\<degree> ss = (Lam [x].r)) = (s = (Lam [x].r) \<and> ss = [])" | |
| 155 | by (induct ss rule: rev_induct) auto | |
| 156 | ||
| 157 | lemma Abs_App_neq_Var_apps [iff]: | |
| 158 | "(Lam [x].s) \<degree> t \<noteq> Var n \<degree>\<degree> ss" | |
| 159 | by (induct ss arbitrary: s t rule: rev_induct) (auto simp add: lam.inject) | |
| 160 | ||
| 161 | lemma Var_apps_neq_Abs_apps [iff]: | |
| 162 | "Var n \<degree>\<degree> ts \<noteq> (Lam [x].r) \<degree>\<degree> ss" | |
| 163 | apply (induct ss arbitrary: ts rule: rev_induct) | |
| 164 | apply simp | |
| 165 | apply (induct_tac ts rule: rev_induct) | |
| 166 | apply (auto simp add: lam.inject) | |
| 167 | done | |
| 168 | ||
| 169 | lemma ex_head_tail: | |
| 170 | "\<exists>ts h. t = h \<degree>\<degree> ts \<and> ((\<exists>n. h = Var n) \<or> (\<exists>x u. h = (Lam [x].u)))" | |
| 171 | apply (induct t rule: lam.induct) | |
| 172 | apply (rule_tac x = "[]" in exI) | |
| 173 | apply (simp add: lam.inject) | |
| 174 | apply clarify | |
| 175 | apply (rename_tac ts1 ts2 h1 h2) | |
| 176 | apply (rule_tac x = "ts1 @ [h2 \<degree>\<degree> ts2]" in exI) | |
| 177 | apply (simp add: lam.inject) | |
| 178 | apply simp | |
| 179 | apply blast | |
| 180 | done | |
| 181 | ||
| 182 | lemma size_apps [simp]: | |
| 183 | "size (r \<degree>\<degree> rs) = size r + foldl (op +) 0 (map size rs) + length rs" | |
| 184 | by (induct rs rule: rev_induct) auto | |
| 185 | ||
| 186 | lemma lem0: "(0::nat) < k \<Longrightarrow> m \<le> n \<Longrightarrow> m < n + k" | |
| 187 | by simp | |
| 188 | ||
| 189 | lemma subst_map [simp]: | |
| 190 | "(t \<degree>\<degree> ts)[x::=u] = t[x::=u] \<degree>\<degree> map (\<lambda>t. t[x::=u]) ts" | |
| 191 | by (induct ts arbitrary: t) simp_all | |
| 192 | ||
| 193 | lemma app_last: "(t \<degree>\<degree> ts) \<degree> u = t \<degree>\<degree> (ts @ [u])" | |
| 194 | by simp | |
| 195 | ||
| 196 | lemma perm_apps [eqvt]: | |
| 197 | "(pi::name prm) \<bullet> (t \<degree>\<degree> ts) = ((pi \<bullet> t) \<degree>\<degree> (pi \<bullet> ts))" | |
| 198 | by (induct ts rule: rev_induct) (auto simp add: append_eqvt) | |
| 199 | ||
| 200 | lemma fresh_apps [simp]: "(x::name) \<sharp> (t \<degree>\<degree> ts) = (x \<sharp> t \<and> x \<sharp> ts)" | |
| 201 | by (induct ts rule: rev_induct) | |
| 202 | (auto simp add: fresh_list_append fresh_list_nil fresh_list_cons) | |
| 203 | ||
| 204 | text {* A customized induction schema for @{text "\<degree>\<degree>"}. *}
 | |
| 205 | ||
| 206 | lemma lem: | |
| 207 | assumes "\<And>n ts (z::'a::fs_name). (\<And>z. \<forall>t \<in> set ts. P z t) \<Longrightarrow> P z (Var n \<degree>\<degree> ts)" | |
| 208 | and "\<And>x u ts z. x \<sharp> z \<Longrightarrow> (\<And>z. P z u) \<Longrightarrow> (\<And>z. \<forall>t \<in> set ts. P z t) \<Longrightarrow> P z ((Lam [x].u) \<degree>\<degree> ts)" | |
| 209 | shows "size t = n \<Longrightarrow> P z t" | |
| 210 | apply (induct n arbitrary: t z rule: nat_less_induct) | |
| 211 | apply (cut_tac t = t in ex_head_tail) | |
| 212 | apply clarify | |
| 213 | apply (erule disjE) | |
| 214 | apply clarify | |
| 215 | apply (rule assms) | |
| 216 | apply clarify | |
| 217 | apply (erule allE, erule impE) | |
| 218 | prefer 2 | |
| 219 | apply (erule allE, erule impE, rule refl, erule spec) | |
| 220 | apply simp | |
| 221 | apply (rule lem0) | |
| 222 | apply force | |
| 223 | apply (rule elem_le_sum) | |
| 224 | apply force | |
| 225 | apply clarify | |
| 226 | apply (subgoal_tac "\<exists>y::name. y \<sharp> (x, u, z)") | |
| 227 | prefer 2 | |
| 228 | apply (rule exists_fresh') | |
| 229 | apply (rule fin_supp) | |
| 230 | apply (erule exE) | |
| 231 | apply (subgoal_tac "(Lam [x].u) = (Lam [y].([(y, x)] \<bullet> u))") | |
| 232 | prefer 2 | |
| 233 | apply (auto simp add: lam.inject alpha' fresh_prod fresh_atm)[] | |
| 234 | apply (simp (no_asm_simp)) | |
| 235 | apply (rule assms) | |
| 236 | apply (simp add: fresh_prod) | |
| 237 | apply (erule allE, erule impE) | |
| 238 | prefer 2 | |
| 239 | apply (erule allE, erule impE, rule refl, erule spec) | |
| 240 | apply simp | |
| 241 | apply clarify | |
| 242 | apply (erule allE, erule impE) | |
| 243 | prefer 2 | |
| 244 | apply (erule allE, erule impE, rule refl, erule spec) | |
| 245 | apply simp | |
| 246 | apply (rule le_imp_less_Suc) | |
| 247 | apply (rule trans_le_add1) | |
| 248 | apply (rule trans_le_add2) | |
| 249 | apply (rule elem_le_sum) | |
| 250 | apply force | |
| 251 | done | |
| 252 | ||
| 253 | theorem Apps_lam_induct: | |
| 254 | assumes "\<And>n ts (z::'a::fs_name). (\<And>z. \<forall>t \<in> set ts. P z t) \<Longrightarrow> P z (Var n \<degree>\<degree> ts)" | |
| 255 | and "\<And>x u ts z. x \<sharp> z \<Longrightarrow> (\<And>z. P z u) \<Longrightarrow> (\<And>z. \<forall>t \<in> set ts. P z t) \<Longrightarrow> P z ((Lam [x].u) \<degree>\<degree> ts)" | |
| 256 | shows "P z t" | |
| 257 | apply (rule_tac t = t and z = z in lem) | |
| 258 | prefer 3 | |
| 259 | apply (rule refl) | |
| 260 | using assms apply blast+ | |
| 261 | done | |
| 262 | ||
| 263 | ||
| 264 | subsection {* Congruence rules *}
 | |
| 265 | ||
| 266 | lemma apps_preserves_beta [simp]: | |
| 267 | "r \<rightarrow>\<^sub>\<beta> s \<Longrightarrow> r \<degree>\<degree> ss \<rightarrow>\<^sub>\<beta> s \<degree>\<degree> ss" | |
| 268 | by (induct ss rule: rev_induct) auto | |
| 269 | ||
| 270 | lemma rtrancl_beta_Abs [intro!]: | |
| 271 | "s \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<Longrightarrow> (Lam [x].s) \<rightarrow>\<^sub>\<beta>\<^sup>* (Lam [x].s')" | |
| 272 | by (induct set: rtranclp) (blast intro: rtranclp.rtrancl_into_rtrancl)+ | |
| 273 | ||
| 274 | lemma rtrancl_beta_AppL: | |
| 275 | "s \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<Longrightarrow> s \<degree> t \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<degree> t" | |
| 276 | by (induct set: rtranclp) (blast intro: rtranclp.rtrancl_into_rtrancl)+ | |
| 277 | ||
| 278 | lemma rtrancl_beta_AppR: | |
| 279 | "t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<Longrightarrow> s \<degree> t \<rightarrow>\<^sub>\<beta>\<^sup>* s \<degree> t'" | |
| 280 | by (induct set: rtranclp) (blast intro: rtranclp.rtrancl_into_rtrancl)+ | |
| 281 | ||
| 282 | lemma rtrancl_beta_App [intro]: | |
| 283 | "s \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<Longrightarrow> t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<Longrightarrow> s \<degree> t \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<degree> t'" | |
| 284 | by (blast intro!: rtrancl_beta_AppL rtrancl_beta_AppR intro: rtranclp_trans) | |
| 285 | ||
| 286 | ||
| 287 | subsection {* Lifting an order to lists of elements *}
 | |
| 288 | ||
| 289 | definition | |
| 290 |   step1 :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" where
 | |
| 291 | "step1 r = | |
| 292 | (\<lambda>ys xs. \<exists>us z z' vs. xs = us @ z # vs \<and> r z' z \<and> ys = | |
| 293 | us @ z' # vs)" | |
| 294 | ||
| 295 | lemma not_Nil_step1 [iff]: "\<not> step1 r [] xs" | |
| 296 | apply (unfold step1_def) | |
| 297 | apply blast | |
| 298 | done | |
| 299 | ||
| 300 | lemma not_step1_Nil [iff]: "\<not> step1 r xs []" | |
| 301 | apply (unfold step1_def) | |
| 302 | apply blast | |
| 303 | done | |
| 304 | ||
| 305 | lemma Cons_step1_Cons [iff]: | |
| 306 | "(step1 r (y # ys) (x # xs)) = | |
| 307 | (r y x \<and> xs = ys \<or> x = y \<and> step1 r ys xs)" | |
| 308 | apply (unfold step1_def) | |
| 309 | apply (rule iffI) | |
| 310 | apply (erule exE) | |
| 311 | apply (rename_tac ts) | |
| 312 | apply (case_tac ts) | |
| 313 | apply fastsimp | |
| 314 | apply force | |
| 315 | apply (erule disjE) | |
| 316 | apply blast | |
| 317 | apply (blast intro: Cons_eq_appendI) | |
| 318 | done | |
| 319 | ||
| 320 | lemma append_step1I: | |
| 321 | "step1 r ys xs \<and> vs = us \<or> ys = xs \<and> step1 r vs us | |
| 322 | \<Longrightarrow> step1 r (ys @ vs) (xs @ us)" | |
| 323 | apply (unfold step1_def) | |
| 324 | apply auto | |
| 325 | apply blast | |
| 326 | apply (blast intro: append_eq_appendI) | |
| 327 | done | |
| 328 | ||
| 329 | lemma Cons_step1E [elim!]: | |
| 330 | assumes "step1 r ys (x # xs)" | |
| 331 | and "\<And>y. ys = y # xs \<Longrightarrow> r y x \<Longrightarrow> R" | |
| 332 | and "\<And>zs. ys = x # zs \<Longrightarrow> step1 r zs xs \<Longrightarrow> R" | |
| 333 | shows R | |
| 334 | using assms | |
| 335 | apply (cases ys) | |
| 336 | apply (simp add: step1_def) | |
| 337 | apply blast | |
| 338 | done | |
| 339 | ||
| 340 | lemma Snoc_step1_SnocD: | |
| 341 | "step1 r (ys @ [y]) (xs @ [x]) | |
| 342 | \<Longrightarrow> (step1 r ys xs \<and> y = x \<or> ys = xs \<and> r y x)" | |
| 343 | apply (unfold step1_def) | |
| 344 | apply (clarify del: disjCI) | |
| 345 | apply (rename_tac vs) | |
| 346 | apply (rule_tac xs = vs in rev_exhaust) | |
| 347 | apply force | |
| 348 | apply simp | |
| 349 | apply blast | |
| 350 | done | |
| 351 | ||
| 352 | ||
| 353 | subsection {* Lifting beta-reduction to lists *}
 | |
| 354 | ||
| 355 | abbreviation | |
| 356 | list_beta :: "lam list \<Rightarrow> lam list \<Rightarrow> bool" (infixl "[\<rightarrow>\<^sub>\<beta>]\<^sub>1" 50) where | |
| 357 | "rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss \<equiv> step1 beta rs ss" | |
| 358 | ||
| 359 | lemma head_Var_reduction: | |
| 360 | "Var n \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> v \<Longrightarrow> \<exists>ss. rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss \<and> v = Var n \<degree>\<degree> ss" | |
| 361 | apply (induct u \<equiv> "Var n \<degree>\<degree> rs" v arbitrary: rs set: beta) | |
| 362 | apply simp | |
| 363 | apply (rule_tac xs = rs in rev_exhaust) | |
| 364 | apply simp | |
| 365 | apply (atomize, force intro: append_step1I iff: lam.inject) | |
| 366 | apply (rule_tac xs = rs in rev_exhaust) | |
| 367 | apply simp | |
| 368 | apply (auto 0 3 intro: disjI2 [THEN append_step1I] simp add: lam.inject) | |
| 369 | done | |
| 370 | ||
| 371 | lemma apps_betasE [case_names appL appR beta, consumes 1]: | |
| 372 | assumes major: "r \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> s" | |
| 373 | and cases: "\<And>r'. r \<rightarrow>\<^sub>\<beta> r' \<Longrightarrow> s = r' \<degree>\<degree> rs \<Longrightarrow> R" | |
| 374 | "\<And>rs'. rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 rs' \<Longrightarrow> s = r \<degree>\<degree> rs' \<Longrightarrow> R" | |
| 375 | "\<And>t u us. (x \<sharp> r \<Longrightarrow> r = (Lam [x].t) \<and> rs = u # us \<and> s = t[x::=u] \<degree>\<degree> us) \<Longrightarrow> R" | |
| 376 | shows R | |
| 377 | proof - | |
| 378 | from major have | |
| 379 | "(\<exists>r'. r \<rightarrow>\<^sub>\<beta> r' \<and> s = r' \<degree>\<degree> rs) \<or> | |
| 380 | (\<exists>rs'. rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 rs' \<and> s = r \<degree>\<degree> rs') \<or> | |
| 381 | (\<exists>t u us. x \<sharp> r \<longrightarrow> r = (Lam [x].t) \<and> rs = u # us \<and> s = t[x::=u] \<degree>\<degree> us)" | |
| 382 | apply (nominal_induct u \<equiv> "r \<degree>\<degree> rs" s avoiding: x r rs rule: beta.strong_induct) | |
| 383 | apply (simp add: App_eq_foldl_conv) | |
| 384 | apply (split split_if_asm) | |
| 385 | apply simp | |
| 386 | apply blast | |
| 387 | apply simp | |
| 388 | apply (rule impI)+ | |
| 389 | apply (rule disjI2) | |
| 390 | apply (rule disjI2) | |
| 391 | apply (subgoal_tac "r = [(xa, x)] \<bullet> (Lam [x].s)") | |
| 392 | prefer 2 | |
| 393 | apply (simp add: perm_fresh_fresh) | |
| 394 | apply (drule conjunct1) | |
| 395 | apply (subgoal_tac "r = (Lam [xa]. [(xa, x)] \<bullet> s)") | |
| 396 | prefer 2 | |
| 397 | apply (simp add: calc_atm) | |
| 398 | apply (thin_tac "r = ?t") | |
| 399 | apply simp | |
| 400 | apply (rule exI) | |
| 401 | apply (rule conjI) | |
| 402 | apply (rule refl) | |
| 403 | apply (simp add: abs_fresh fresh_atm fresh_left calc_atm subst_rename) | |
| 404 | apply (drule App_eq_foldl_conv [THEN iffD1]) | |
| 405 | apply (split split_if_asm) | |
| 406 | apply simp | |
| 407 | apply blast | |
| 408 | apply (force intro!: disjI1 [THEN append_step1I] simp add: fresh_list_append) | |
| 409 | apply (drule App_eq_foldl_conv [THEN iffD1]) | |
| 410 | apply (split split_if_asm) | |
| 411 | apply simp | |
| 412 | apply blast | |
| 413 | apply (clarify, auto 0 3 intro!: exI intro: append_step1I) | |
| 414 | done | |
| 415 | with cases show ?thesis by blast | |
| 416 | qed | |
| 417 | ||
| 418 | lemma apps_preserves_betas [simp]: | |
| 419 | "rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss \<Longrightarrow> r \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> r \<degree>\<degree> ss" | |
| 420 | apply (induct rs arbitrary: ss rule: rev_induct) | |
| 421 | apply simp | |
| 422 | apply simp | |
| 423 | apply (rule_tac xs = ss in rev_exhaust) | |
| 424 | apply simp | |
| 425 | apply simp | |
| 426 | apply (drule Snoc_step1_SnocD) | |
| 427 | apply blast | |
| 428 | done | |
| 429 | ||
| 430 | ||
| 431 | subsection {* Standard reduction relation *}
 | |
| 432 | ||
| 433 | text {*
 | |
| 434 | Based on lecture notes by Ralph Matthes, | |
| 435 | original proof idea due to Ralph Loader. | |
| 436 | *} | |
| 437 | ||
| 438 | declare listrel_mono [mono_set] | |
| 439 | ||
| 440 | lemma listrelp_eqvt [eqvt]: | |
| 441 | assumes xy: "listrelp f (x::'a::pt_name list) y" | |
| 442 | shows "listrelp ((pi::name prm) \<bullet> f) (pi \<bullet> x) (pi \<bullet> y)" using xy | |
| 443 | apply induct | |
| 444 | apply simp | |
| 445 | apply (rule listrelp.intros) | |
| 446 | apply simp | |
| 447 | apply (rule listrelp.intros) | |
| 448 | apply (drule_tac pi=pi in perm_boolI) | |
| 449 | apply perm_simp | |
| 450 | apply assumption | |
| 451 | done | |
| 452 | ||
| 453 | inductive | |
| 454 | sred :: "lam \<Rightarrow> lam \<Rightarrow> bool" (infixl "\<rightarrow>\<^sub>s" 50) | |
| 455 | and sredlist :: "lam list \<Rightarrow> lam list \<Rightarrow> bool" (infixl "[\<rightarrow>\<^sub>s]" 50) | |
| 456 | where | |
| 457 | "s [\<rightarrow>\<^sub>s] t \<equiv> listrelp op \<rightarrow>\<^sub>s s t" | |
| 458 | | Var: "rs [\<rightarrow>\<^sub>s] rs' \<Longrightarrow> Var x \<degree>\<degree> rs \<rightarrow>\<^sub>s Var x \<degree>\<degree> rs'" | |
| 459 | | Abs: "x \<sharp> (ss, ss') \<Longrightarrow> r \<rightarrow>\<^sub>s r' \<Longrightarrow> ss [\<rightarrow>\<^sub>s] ss' \<Longrightarrow> (Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> ss'" | |
| 460 | | Beta: "x \<sharp> (s, ss, t) \<Longrightarrow> r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>s t \<Longrightarrow> (Lam [x].r) \<degree> s \<degree>\<degree> ss \<rightarrow>\<^sub>s t" | |
| 461 | ||
| 462 | equivariance sred | |
| 463 | nominal_inductive sred | |
| 464 | by (simp add: abs_fresh)+ | |
| 465 | ||
| 466 | lemma better_sred_Abs: | |
| 467 | assumes H1: "r \<rightarrow>\<^sub>s r'" | |
| 468 | and H2: "ss [\<rightarrow>\<^sub>s] ss'" | |
| 469 | shows "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> ss'" | |
| 470 | proof - | |
| 471 | obtain y::name where y: "y \<sharp> (x, r, r', ss, ss')" | |
| 472 | by (rule exists_fresh) (rule fin_supp) | |
| 473 | then have "y \<sharp> (ss, ss')" by simp | |
| 474 | moreover from H1 have "[(y, x)] \<bullet> (r \<rightarrow>\<^sub>s r')" by (rule perm_boolI) | |
| 475 | then have "([(y, x)] \<bullet> r) \<rightarrow>\<^sub>s ([(y, x)] \<bullet> r')" by (simp add: eqvts) | |
| 476 | ultimately have "(Lam [y]. [(y, x)] \<bullet> r) \<degree>\<degree> ss \<rightarrow>\<^sub>s (Lam [y]. [(y, x)] \<bullet> r') \<degree>\<degree> ss'" using H2 | |
| 477 | by (rule sred.Abs) | |
| 478 | moreover from y have "(Lam [x].r) = (Lam [y]. [(y, x)] \<bullet> r)" | |
| 479 | by (auto simp add: lam.inject alpha' fresh_prod fresh_atm) | |
| 480 | moreover from y have "(Lam [x].r') = (Lam [y]. [(y, x)] \<bullet> r')" | |
| 481 | by (auto simp add: lam.inject alpha' fresh_prod fresh_atm) | |
| 482 | ultimately show ?thesis by simp | |
| 483 | qed | |
| 484 | ||
| 485 | lemma better_sred_Beta: | |
| 486 | assumes H: "r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>s t" | |
| 487 | shows "(Lam [x].r) \<degree> s \<degree>\<degree> ss \<rightarrow>\<^sub>s t" | |
| 488 | proof - | |
| 489 | obtain y::name where y: "y \<sharp> (x, r, s, ss, t)" | |
| 490 | by (rule exists_fresh) (rule fin_supp) | |
| 491 | then have "y \<sharp> (s, ss, t)" by simp | |
| 492 | moreover from y H have "([(y, x)] \<bullet> r)[y::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>s t" | |
| 493 | by (simp add: subst_rename) | |
| 494 | ultimately have "(Lam [y].[(y, x)] \<bullet> r) \<degree> s \<degree>\<degree> ss \<rightarrow>\<^sub>s t" | |
| 495 | by (rule sred.Beta) | |
| 496 | moreover from y have "(Lam [x].r) = (Lam [y]. [(y, x)] \<bullet> r)" | |
| 497 | by (auto simp add: lam.inject alpha' fresh_prod fresh_atm) | |
| 498 | ultimately show ?thesis by simp | |
| 499 | qed | |
| 500 | ||
| 501 | lemmas better_sred_intros = sred.Var better_sred_Abs better_sred_Beta | |
| 502 | ||
| 503 | lemma refl_listrelp: "\<forall>x\<in>set xs. R x x \<Longrightarrow> listrelp R xs xs" | |
| 504 | by (induct xs) (auto intro: listrelp.intros) | |
| 505 | ||
| 506 | lemma refl_sred: "t \<rightarrow>\<^sub>s t" | |
| 507 | by (nominal_induct t rule: Apps_lam_induct) (auto intro: refl_listrelp better_sred_intros) | |
| 508 | ||
| 509 | lemma listrelp_conj1: "listrelp (\<lambda>x y. R x y \<and> S x y) x y \<Longrightarrow> listrelp R x y" | |
| 510 | by (erule listrelp.induct) (auto intro: listrelp.intros) | |
| 511 | ||
| 512 | lemma listrelp_conj2: "listrelp (\<lambda>x y. R x y \<and> S x y) x y \<Longrightarrow> listrelp S x y" | |
| 513 | by (erule listrelp.induct) (auto intro: listrelp.intros) | |
| 514 | ||
| 515 | lemma listrelp_app: | |
| 516 | assumes xsys: "listrelp R xs ys" | |
| 517 | shows "listrelp R xs' ys' \<Longrightarrow> listrelp R (xs @ xs') (ys @ ys')" using xsys | |
| 518 | by (induct arbitrary: xs' ys') (auto intro: listrelp.intros) | |
| 519 | ||
| 520 | lemma lemma1: | |
| 521 | assumes r: "r \<rightarrow>\<^sub>s r'" and s: "s \<rightarrow>\<^sub>s s'" | |
| 522 | shows "r \<degree> s \<rightarrow>\<^sub>s r' \<degree> s'" using r | |
| 523 | proof induct | |
| 524 | case (Var rs rs' x) | |
| 525 | then have "rs [\<rightarrow>\<^sub>s] rs'" by (rule listrelp_conj1) | |
| 526 | moreover have "[s] [\<rightarrow>\<^sub>s] [s']" by (iprover intro: s listrelp.intros) | |
| 527 | ultimately have "rs @ [s] [\<rightarrow>\<^sub>s] rs' @ [s']" by (rule listrelp_app) | |
| 528 | hence "Var x \<degree>\<degree> (rs @ [s]) \<rightarrow>\<^sub>s Var x \<degree>\<degree> (rs' @ [s'])" by (rule sred.Var) | |
| 529 | thus ?case by (simp only: app_last) | |
| 530 | next | |
| 531 | case (Abs x ss ss' r r') | |
| 532 | from Abs(4) have "ss [\<rightarrow>\<^sub>s] ss'" by (rule listrelp_conj1) | |
| 533 | moreover have "[s] [\<rightarrow>\<^sub>s] [s']" by (iprover intro: s listrelp.intros) | |
| 534 | ultimately have "ss @ [s] [\<rightarrow>\<^sub>s] ss' @ [s']" by (rule listrelp_app) | |
| 535 | with `r \<rightarrow>\<^sub>s r'` have "(Lam [x].r) \<degree>\<degree> (ss @ [s]) \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> (ss' @ [s'])" | |
| 536 | by (rule better_sred_Abs) | |
| 537 | thus ?case by (simp only: app_last) | |
| 538 | next | |
| 539 | case (Beta x u ss t r) | |
| 540 | hence "r[x::=u] \<degree>\<degree> (ss @ [s]) \<rightarrow>\<^sub>s t \<degree> s'" by (simp only: app_last) | |
| 541 | hence "(Lam [x].r) \<degree> u \<degree>\<degree> (ss @ [s]) \<rightarrow>\<^sub>s t \<degree> s'" by (rule better_sred_Beta) | |
| 542 | thus ?case by (simp only: app_last) | |
| 543 | qed | |
| 544 | ||
| 545 | lemma lemma1': | |
| 546 | assumes ts: "ts [\<rightarrow>\<^sub>s] ts'" | |
| 547 | shows "r \<rightarrow>\<^sub>s r' \<Longrightarrow> r \<degree>\<degree> ts \<rightarrow>\<^sub>s r' \<degree>\<degree> ts'" using ts | |
| 548 | by (induct arbitrary: r r') (auto intro: lemma1) | |
| 549 | ||
| 550 | lemma listrelp_betas: | |
| 551 | assumes ts: "listrelp op \<rightarrow>\<^sub>\<beta>\<^sup>* ts ts'" | |
| 552 | shows "\<And>t t'. t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<Longrightarrow> t \<degree>\<degree> ts \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<degree>\<degree> ts'" using ts | |
| 553 | by induct auto | |
| 554 | ||
| 555 | lemma lemma2: | |
| 556 | assumes t: "t \<rightarrow>\<^sub>s u" | |
| 557 | shows "t \<rightarrow>\<^sub>\<beta>\<^sup>* u" using t | |
| 558 | by induct (auto dest: listrelp_conj2 | |
| 559 | intro: listrelp_betas apps_preserves_beta converse_rtranclp_into_rtranclp) | |
| 560 | ||
| 561 | lemma lemma3: | |
| 562 | assumes r: "r \<rightarrow>\<^sub>s r'" | |
| 563 | shows "s \<rightarrow>\<^sub>s s' \<Longrightarrow> r[x::=s] \<rightarrow>\<^sub>s r'[x::=s']" using r | |
| 564 | proof (nominal_induct avoiding: x s s' rule: sred.strong_induct) | |
| 565 | case (Var rs rs' y) | |
| 566 | hence "map (\<lambda>t. t[x::=s]) rs [\<rightarrow>\<^sub>s] map (\<lambda>t. t[x::=s']) rs'" | |
| 567 | by induct (auto intro: listrelp.intros Var) | |
| 568 | moreover have "Var y[x::=s] \<rightarrow>\<^sub>s Var y[x::=s']" | |
| 569 | by (cases "y = x") (auto simp add: Var intro: refl_sred) | |
| 570 | ultimately show ?case by simp (rule lemma1') | |
| 571 | next | |
| 572 | case (Abs y ss ss' r r') | |
| 573 | then have "r[x::=s] \<rightarrow>\<^sub>s r'[x::=s']" by fast | |
| 574 | moreover from Abs(8) `s \<rightarrow>\<^sub>s s'` have "map (\<lambda>t. t[x::=s]) ss [\<rightarrow>\<^sub>s] map (\<lambda>t. t[x::=s']) ss'" | |
| 575 | by induct (auto intro: listrelp.intros Abs) | |
| 576 | ultimately show ?case using Abs(6) `y \<sharp> x` `y \<sharp> s` `y \<sharp> s'` | |
| 577 | by simp (rule better_sred_Abs) | |
| 578 | next | |
| 579 | case (Beta y u ss t r) | |
| 580 | thus ?case by (auto simp add: subst_subst fresh_atm intro: better_sred_Beta) | |
| 581 | qed | |
| 582 | ||
| 583 | lemma lemma4_aux: | |
| 584 | assumes rs: "listrelp (\<lambda>t u. t \<rightarrow>\<^sub>s u \<and> (\<forall>r. u \<rightarrow>\<^sub>\<beta> r \<longrightarrow> t \<rightarrow>\<^sub>s r)) rs rs'" | |
| 585 | shows "rs' [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss \<Longrightarrow> rs [\<rightarrow>\<^sub>s] ss" using rs | |
| 586 | proof (induct arbitrary: ss) | |
| 587 | case Nil | |
| 588 | thus ?case by cases (auto intro: listrelp.Nil) | |
| 589 | next | |
| 590 | case (Cons x y xs ys) | |
| 591 | note Cons' = Cons | |
| 592 | show ?case | |
| 593 | proof (cases ss) | |
| 594 | case Nil with Cons show ?thesis by simp | |
| 595 | next | |
| 596 | case (Cons y' ys') | |
| 597 | hence ss: "ss = y' # ys'" by simp | |
| 598 | from Cons Cons' have "y \<rightarrow>\<^sub>\<beta> y' \<and> ys' = ys \<or> y' = y \<and> ys [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ys'" by simp | |
| 599 | hence "x # xs [\<rightarrow>\<^sub>s] y' # ys'" | |
| 600 | proof | |
| 601 | assume H: "y \<rightarrow>\<^sub>\<beta> y' \<and> ys' = ys" | |
| 602 | with Cons' have "x \<rightarrow>\<^sub>s y'" by blast | |
| 603 | moreover from Cons' have "xs [\<rightarrow>\<^sub>s] ys" by (iprover dest: listrelp_conj1) | |
| 604 | ultimately have "x # xs [\<rightarrow>\<^sub>s] y' # ys" by (rule listrelp.Cons) | |
| 605 | with H show ?thesis by simp | |
| 606 | next | |
| 607 | assume H: "y' = y \<and> ys [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ys'" | |
| 608 | with Cons' have "x \<rightarrow>\<^sub>s y'" by blast | |
| 609 | moreover from H have "xs [\<rightarrow>\<^sub>s] ys'" by (blast intro: Cons') | |
| 610 | ultimately show ?thesis by (rule listrelp.Cons) | |
| 611 | qed | |
| 612 | with ss show ?thesis by simp | |
| 613 | qed | |
| 614 | qed | |
| 615 | ||
| 616 | lemma lemma4: | |
| 617 | assumes r: "r \<rightarrow>\<^sub>s r'" | |
| 618 | shows "r' \<rightarrow>\<^sub>\<beta> r'' \<Longrightarrow> r \<rightarrow>\<^sub>s r''" using r | |
| 619 | proof (nominal_induct avoiding: r'' rule: sred.strong_induct) | |
| 620 | case (Var rs rs' x) | |
| 621 | then obtain ss where rs: "rs' [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss" and r'': "r'' = Var x \<degree>\<degree> ss" | |
| 622 | by (blast dest: head_Var_reduction) | |
| 623 | from Var(1) [simplified] rs have "rs [\<rightarrow>\<^sub>s] ss" by (rule lemma4_aux) | |
| 624 | hence "Var x \<degree>\<degree> rs \<rightarrow>\<^sub>s Var x \<degree>\<degree> ss" by (rule sred.Var) | |
| 625 | with r'' show ?case by simp | |
| 626 | next | |
| 627 | case (Abs x ss ss' r r') | |
| 628 | from `(Lam [x].r') \<degree>\<degree> ss' \<rightarrow>\<^sub>\<beta> r''` show ?case | |
| 629 | proof (cases rule: apps_betasE [where x=x]) | |
| 630 | case (appL s) | |
| 631 | then obtain r''' where s: "s = (Lam [x].r''')" and r''': "r' \<rightarrow>\<^sub>\<beta> r'''" using `x \<sharp> r''` | |
| 632 | by (cases rule: beta.strong_cases) (auto simp add: abs_fresh lam.inject alpha) | |
| 633 | from r''' have "r \<rightarrow>\<^sub>s r'''" by (blast intro: Abs) | |
| 634 | moreover from Abs have "ss [\<rightarrow>\<^sub>s] ss'" by (iprover dest: listrelp_conj1) | |
| 635 | ultimately have "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s (Lam [x].r''') \<degree>\<degree> ss'" by (rule better_sred_Abs) | |
| 636 | with appL s show "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s r''" by simp | |
| 637 | next | |
| 638 | case (appR rs') | |
| 639 | from Abs(6) [simplified] `ss' [\<rightarrow>\<^sub>\<beta>]\<^sub>1 rs'` | |
| 640 | have "ss [\<rightarrow>\<^sub>s] rs'" by (rule lemma4_aux) | |
| 641 | with `r \<rightarrow>\<^sub>s r'` have "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> rs'" by (rule better_sred_Abs) | |
| 642 | with appR show "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s r''" by simp | |
| 643 | next | |
| 644 | case (beta t u' us') | |
| 645 | then have Lam_eq: "(Lam [x].r') = (Lam [x].t)" and ss': "ss' = u' # us'" | |
| 646 | and r'': "r'' = t[x::=u'] \<degree>\<degree> us'" | |
| 647 | by (simp_all add: abs_fresh) | |
| 648 | from Abs(6) ss' obtain u us where | |
| 649 | ss: "ss = u # us" and u: "u \<rightarrow>\<^sub>s u'" and us: "us [\<rightarrow>\<^sub>s] us'" | |
| 650 | by cases (auto dest!: listrelp_conj1) | |
| 651 | have "r[x::=u] \<rightarrow>\<^sub>s r'[x::=u']" using `r \<rightarrow>\<^sub>s r'` and u by (rule lemma3) | |
| 652 | with us have "r[x::=u] \<degree>\<degree> us \<rightarrow>\<^sub>s r'[x::=u'] \<degree>\<degree> us'" by (rule lemma1') | |
| 653 | hence "(Lam [x].r) \<degree> u \<degree>\<degree> us \<rightarrow>\<^sub>s r'[x::=u'] \<degree>\<degree> us'" by (rule better_sred_Beta) | |
| 654 | with ss r'' Lam_eq show "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s r''" by (simp add: lam.inject alpha) | |
| 655 | qed | |
| 656 | next | |
| 657 | case (Beta x s ss t r) | |
| 658 | show ?case | |
| 659 | by (rule better_sred_Beta) (rule Beta)+ | |
| 660 | qed | |
| 661 | ||
| 662 | lemma rtrancl_beta_sred: | |
| 663 | assumes r: "r \<rightarrow>\<^sub>\<beta>\<^sup>* r'" | |
| 664 | shows "r \<rightarrow>\<^sub>s r'" using r | |
| 665 | by induct (iprover intro: refl_sred lemma4)+ | |
| 666 | ||
| 667 | ||
| 668 | subsection {* Terms in normal form *}
 | |
| 669 | ||
| 670 | lemma listsp_eqvt [eqvt]: | |
| 671 | assumes xs: "listsp p (xs::'a::pt_name list)" | |
| 672 | shows "listsp ((pi::name prm) \<bullet> p) (pi \<bullet> xs)" using xs | |
| 673 | apply induct | |
| 674 | apply simp | |
| 675 | apply (rule listsp.intros) | |
| 676 | apply simp | |
| 677 | apply (rule listsp.intros) | |
| 678 | apply (drule_tac pi=pi in perm_boolI) | |
| 679 | apply perm_simp | |
| 680 | apply assumption | |
| 681 | done | |
| 682 | ||
| 683 | inductive NF :: "lam \<Rightarrow> bool" | |
| 684 | where | |
| 685 | App: "listsp NF ts \<Longrightarrow> NF (Var x \<degree>\<degree> ts)" | |
| 686 | | Abs: "NF t \<Longrightarrow> NF (Lam [x].t)" | |
| 687 | ||
| 688 | equivariance NF | |
| 689 | nominal_inductive NF | |
| 690 | by (simp add: abs_fresh) | |
| 691 | ||
| 692 | lemma Abs_NF: | |
| 693 | assumes NF: "NF ((Lam [x].t) \<degree>\<degree> ts)" | |
| 694 | shows "ts = []" using NF | |
| 695 | proof cases | |
| 696 | case (App us i) | |
| 697 | thus ?thesis by (simp add: Var_apps_neq_Abs_apps [THEN not_sym]) | |
| 698 | next | |
| 699 | case (Abs u) | |
| 700 | thus ?thesis by simp | |
| 701 | qed | |
| 702 | ||
| 703 | text {*
 | |
| 704 | @{term NF} characterizes exactly the terms that are in normal form.
 | |
| 705 | *} | |
| 706 | ||
| 707 | lemma NF_eq: "NF t = (\<forall>t'. \<not> t \<rightarrow>\<^sub>\<beta> t')" | |
| 708 | proof | |
| 709 | assume H: "NF t" | |
| 710 | show "\<forall>t'. \<not> t \<rightarrow>\<^sub>\<beta> t'" | |
| 711 | proof | |
| 712 | fix t' | |
| 713 | from H show "\<not> t \<rightarrow>\<^sub>\<beta> t'" | |
| 714 | proof (nominal_induct avoiding: t' rule: NF.strong_induct) | |
| 715 | case (App ts t) | |
| 716 | show ?case | |
| 717 | proof | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 718 | assume "Var t \<degree>\<degree> ts \<rightarrow>\<^sub>\<beta> t'" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 719 | then obtain rs where "ts [\<rightarrow>\<^sub>\<beta>]\<^sub>1 rs" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 720 | by (iprover dest: head_Var_reduction) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 721 | with App show False | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 722 | by (induct rs arbitrary: ts) (auto del: in_listspD) | 
| 27623 | 723 | qed | 
| 724 | next | |
| 725 | case (Abs t x) | |
| 726 | show ?case | |
| 727 | proof | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 728 | assume "(Lam [x].t) \<rightarrow>\<^sub>\<beta> t'" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 729 | then show False using Abs | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 730 | by (cases rule: beta.strong_cases) (auto simp add: abs_fresh lam.inject alpha) | 
| 27623 | 731 | qed | 
| 732 | qed | |
| 733 | qed | |
| 734 | next | |
| 735 | assume H: "\<forall>t'. \<not> t \<rightarrow>\<^sub>\<beta> t'" | |
| 736 | then show "NF t" | |
| 737 | proof (nominal_induct t rule: Apps_lam_induct) | |
| 738 | case (1 n ts) | |
| 739 | then have "\<forall>ts'. \<not> ts [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ts'" | |
| 740 | by (iprover intro: apps_preserves_betas) | |
| 741 | with 1(1) have "listsp NF ts" | |
| 742 | by (induct ts) (auto simp add: in_listsp_conv_set) | |
| 743 | then show ?case by (rule NF.App) | |
| 744 | next | |
| 745 | case (2 x u ts) | |
| 746 | show ?case | |
| 747 | proof (cases ts) | |
| 748 | case Nil | |
| 749 | from 2 have "\<forall>u'. \<not> u \<rightarrow>\<^sub>\<beta> u'" | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 750 | by (auto intro: apps_preserves_beta) | 
| 27623 | 751 | then have "NF u" by (rule 2) | 
| 752 | then have "NF (Lam [x].u)" by (rule NF.Abs) | |
| 753 | with Nil show ?thesis by simp | |
| 754 | next | |
| 755 | case (Cons r rs) | |
| 756 | have "(Lam [x].u) \<degree> r \<rightarrow>\<^sub>\<beta> u[x::=r]" .. | |
| 757 | then have "(Lam [x].u) \<degree> r \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> u[x::=r] \<degree>\<degree> rs" | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 758 | by (rule apps_preserves_beta) | 
| 27623 | 759 | with Cons have "(Lam [x].u) \<degree>\<degree> ts \<rightarrow>\<^sub>\<beta> u[x::=r] \<degree>\<degree> rs" | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 760 | by simp | 
| 27623 | 761 | with 2 show ?thesis by iprover | 
| 762 | qed | |
| 763 | qed | |
| 764 | qed | |
| 765 | ||
| 766 | ||
| 767 | subsection {* Leftmost reduction and weakly normalizing terms *}
 | |
| 768 | ||
| 769 | inductive | |
| 770 | lred :: "lam \<Rightarrow> lam \<Rightarrow> bool" (infixl "\<rightarrow>\<^sub>l" 50) | |
| 771 | and lredlist :: "lam list \<Rightarrow> lam list \<Rightarrow> bool" (infixl "[\<rightarrow>\<^sub>l]" 50) | |
| 772 | where | |
| 773 | "s [\<rightarrow>\<^sub>l] t \<equiv> listrelp op \<rightarrow>\<^sub>l s t" | |
| 774 | | Var: "rs [\<rightarrow>\<^sub>l] rs' \<Longrightarrow> Var x \<degree>\<degree> rs \<rightarrow>\<^sub>l Var x \<degree>\<degree> rs'" | |
| 775 | | Abs: "r \<rightarrow>\<^sub>l r' \<Longrightarrow> (Lam [x].r) \<rightarrow>\<^sub>l (Lam [x].r')" | |
| 776 | | Beta: "r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>l t \<Longrightarrow> (Lam [x].r) \<degree> s \<degree>\<degree> ss \<rightarrow>\<^sub>l t" | |
| 777 | ||
| 778 | lemma lred_imp_sred: | |
| 779 | assumes lred: "s \<rightarrow>\<^sub>l t" | |
| 780 | shows "s \<rightarrow>\<^sub>s t" using lred | |
| 781 | proof induct | |
| 782 | case (Var rs rs' x) | |
| 783 | then have "rs [\<rightarrow>\<^sub>s] rs'" | |
| 784 | by induct (iprover intro: listrelp.intros)+ | |
| 785 | then show ?case by (rule sred.Var) | |
| 786 | next | |
| 787 | case (Abs r r' x) | |
| 788 | from `r \<rightarrow>\<^sub>s r'` | |
| 789 | have "(Lam [x].r) \<degree>\<degree> [] \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> []" using listrelp.Nil | |
| 790 | by (rule better_sred_Abs) | |
| 791 | then show ?case by simp | |
| 792 | next | |
| 793 | case (Beta r x s ss t) | |
| 794 | from `r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>s t` | |
| 795 | show ?case by (rule better_sred_Beta) | |
| 796 | qed | |
| 797 | ||
| 798 | inductive WN :: "lam \<Rightarrow> bool" | |
| 799 | where | |
| 800 | Var: "listsp WN rs \<Longrightarrow> WN (Var n \<degree>\<degree> rs)" | |
| 801 | | Lambda: "WN r \<Longrightarrow> WN (Lam [x].r)" | |
| 802 | | Beta: "WN ((r[x::=s]) \<degree>\<degree> ss) \<Longrightarrow> WN (((Lam [x].r) \<degree> s) \<degree>\<degree> ss)" | |
| 803 | ||
| 804 | lemma listrelp_imp_listsp1: | |
| 805 | assumes H: "listrelp (\<lambda>x y. P x) xs ys" | |
| 806 | shows "listsp P xs" using H | |
| 807 | by induct auto | |
| 808 | ||
| 809 | lemma listrelp_imp_listsp2: | |
| 810 | assumes H: "listrelp (\<lambda>x y. P y) xs ys" | |
| 811 | shows "listsp P ys" using H | |
| 812 | by induct auto | |
| 813 | ||
| 814 | lemma lemma5: | |
| 815 | assumes lred: "r \<rightarrow>\<^sub>l r'" | |
| 816 | shows "WN r" and "NF r'" using lred | |
| 817 | by induct | |
| 818 | (iprover dest: listrelp_conj1 listrelp_conj2 | |
| 819 | listrelp_imp_listsp1 listrelp_imp_listsp2 intro: WN.intros | |
| 820 | NF.intros)+ | |
| 821 | ||
| 822 | lemma lemma6: | |
| 823 | assumes wn: "WN r" | |
| 824 | shows "\<exists>r'. r \<rightarrow>\<^sub>l r'" using wn | |
| 825 | proof induct | |
| 826 | case (Var rs n) | |
| 827 | then have "\<exists>rs'. rs [\<rightarrow>\<^sub>l] rs'" | |
| 828 | by induct (iprover intro: listrelp.intros)+ | |
| 829 | then show ?case by (iprover intro: lred.Var) | |
| 830 | qed (iprover intro: lred.intros)+ | |
| 831 | ||
| 832 | lemma lemma7: | |
| 833 | assumes r: "r \<rightarrow>\<^sub>s r'" | |
| 834 | shows "NF r' \<Longrightarrow> r \<rightarrow>\<^sub>l r'" using r | |
| 835 | proof induct | |
| 836 | case (Var rs rs' x) | |
| 837 | from `NF (Var x \<degree>\<degree> rs')` have "listsp NF rs'" | |
| 838 | by cases simp_all | |
| 839 | with Var(1) have "rs [\<rightarrow>\<^sub>l] rs'" | |
| 840 | proof induct | |
| 841 | case Nil | |
| 842 | show ?case by (rule listrelp.Nil) | |
| 843 | next | |
| 844 | case (Cons x y xs ys) | |
| 845 | hence "x \<rightarrow>\<^sub>l y" and "xs [\<rightarrow>\<^sub>l] ys" by (auto del: in_listspD) | |
| 846 | thus ?case by (rule listrelp.Cons) | |
| 847 | qed | |
| 848 | thus ?case by (rule lred.Var) | |
| 849 | next | |
| 850 | case (Abs x ss ss' r r') | |
| 851 | from `NF ((Lam [x].r') \<degree>\<degree> ss')` | |
| 852 | have ss': "ss' = []" by (rule Abs_NF) | |
| 853 | from Abs(4) have ss: "ss = []" using ss' | |
| 854 | by cases simp_all | |
| 855 | from ss' Abs have "NF (Lam [x].r')" by simp | |
| 856 | hence "NF r'" by (cases rule: NF.strong_cases) (auto simp add: abs_fresh lam.inject alpha) | |
| 857 | with Abs have "r \<rightarrow>\<^sub>l r'" by simp | |
| 858 | hence "(Lam [x].r) \<rightarrow>\<^sub>l (Lam [x].r')" by (rule lred.Abs) | |
| 859 | with ss ss' show ?case by simp | |
| 860 | next | |
| 861 | case (Beta x s ss t r) | |
| 862 | hence "r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>l t" by simp | |
| 863 | thus ?case by (rule lred.Beta) | |
| 864 | qed | |
| 865 | ||
| 866 | lemma WN_eq: "WN t = (\<exists>t'. t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<and> NF t')" | |
| 867 | proof | |
| 868 | assume "WN t" | |
| 869 | then have "\<exists>t'. t \<rightarrow>\<^sub>l t'" by (rule lemma6) | |
| 870 | then obtain t' where t': "t \<rightarrow>\<^sub>l t'" .. | |
| 871 | then have NF: "NF t'" by (rule lemma5) | |
| 872 | from t' have "t \<rightarrow>\<^sub>s t'" by (rule lred_imp_sred) | |
| 873 | then have "t \<rightarrow>\<^sub>\<beta>\<^sup>* t'" by (rule lemma2) | |
| 874 | with NF show "\<exists>t'. t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<and> NF t'" by iprover | |
| 875 | next | |
| 876 | assume "\<exists>t'. t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<and> NF t'" | |
| 877 | then obtain t' where t': "t \<rightarrow>\<^sub>\<beta>\<^sup>* t'" and NF: "NF t'" | |
| 878 | by iprover | |
| 879 | from t' have "t \<rightarrow>\<^sub>s t'" by (rule rtrancl_beta_sred) | |
| 880 | then have "t \<rightarrow>\<^sub>l t'" using NF by (rule lemma7) | |
| 881 | then show "WN t" by (rule lemma5) | |
| 882 | qed | |
| 883 | ||
| 884 | end |