| author | nipkow | 
| Tue, 11 Oct 2022 10:45:42 +0200 | |
| changeset 76259 | d1c26efb7a47 | 
| parent 71989 | bad75618fb82 | 
| child 80141 | 022a9c26b14f | 
| 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 | ||
| 63167 | 6 | section \<open>Standardization\<close> | 
| 27623 | 7 | |
| 8 | theory Standardization | |
| 66453 
cc19f7ca2ed6
session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
 wenzelm parents: 
63882diff
changeset | 9 | imports "HOL-Nominal.Nominal" | 
| 27623 | 10 | begin | 
| 11 | ||
| 63167 | 12 | text \<open> | 
| 27623 | 13 | The proof of the standardization theorem, as well as most of the theorems about | 
| 63167 | 14 | lambda calculus in the following sections, are taken from \<open>HOL/Lambda\<close>. | 
| 15 | \<close> | |
| 27623 | 16 | |
| 63167 | 17 | subsection \<open>Lambda terms\<close> | 
| 27623 | 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))" | 
| 53015 
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
 wenzelm parents: 
47397diff
changeset | 48 | | subst_App: "(t\<^sub>1 \<degree> t\<^sub>2)[y::=s] = t\<^sub>1[y::=s] \<degree> t\<^sub>2[y::=s]" | 
| 29097 
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 | ||
| 63167 | 121 | subsection \<open>Application of a term to a list of terms\<close> | 
| 27623 | 122 | |
| 123 | abbreviation | |
| 124 | list_application :: "lam \<Rightarrow> lam list \<Rightarrow> lam" (infixl "\<degree>\<degree>" 150) where | |
| 67399 | 125 | "t \<degree>\<degree> ts \<equiv> foldl (\<degree>) t ts" | 
| 27623 | 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) | |
| 39459 | 172 | apply (metis foldl_Nil) | 
| 173 | apply (metis foldl_Cons foldl_Nil foldl_append) | |
| 174 | apply (metis foldl_Nil) | |
| 27623 | 175 | done | 
| 176 | ||
| 177 | lemma size_apps [simp]: | |
| 67399 | 178 | "size (r \<degree>\<degree> rs) = size r + foldl (+) 0 (map size rs) + length rs" | 
| 27623 | 179 | by (induct rs rule: rev_induct) auto | 
| 180 | ||
| 181 | lemma lem0: "(0::nat) < k \<Longrightarrow> m \<le> n \<Longrightarrow> m < n + k" | |
| 182 | by simp | |
| 183 | ||
| 184 | lemma subst_map [simp]: | |
| 185 | "(t \<degree>\<degree> ts)[x::=u] = t[x::=u] \<degree>\<degree> map (\<lambda>t. t[x::=u]) ts" | |
| 186 | by (induct ts arbitrary: t) simp_all | |
| 187 | ||
| 188 | lemma app_last: "(t \<degree>\<degree> ts) \<degree> u = t \<degree>\<degree> (ts @ [u])" | |
| 189 | by simp | |
| 190 | ||
| 191 | lemma perm_apps [eqvt]: | |
| 192 | "(pi::name prm) \<bullet> (t \<degree>\<degree> ts) = ((pi \<bullet> t) \<degree>\<degree> (pi \<bullet> ts))" | |
| 193 | by (induct ts rule: rev_induct) (auto simp add: append_eqvt) | |
| 194 | ||
| 195 | lemma fresh_apps [simp]: "(x::name) \<sharp> (t \<degree>\<degree> ts) = (x \<sharp> t \<and> x \<sharp> ts)" | |
| 196 | by (induct ts rule: rev_induct) | |
| 197 | (auto simp add: fresh_list_append fresh_list_nil fresh_list_cons) | |
| 198 | ||
| 63167 | 199 | text \<open>A customized induction schema for \<open>\<degree>\<degree>\<close>.\<close> | 
| 27623 | 200 | |
| 201 | lemma lem: | |
| 202 | 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)" | |
| 203 | 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)" | |
| 204 | shows "size t = n \<Longrightarrow> P z t" | |
| 205 | apply (induct n arbitrary: t z rule: nat_less_induct) | |
| 206 | apply (cut_tac t = t in ex_head_tail) | |
| 207 | apply clarify | |
| 208 | apply (erule disjE) | |
| 209 | apply clarify | |
| 210 | apply (rule assms) | |
| 211 | apply clarify | |
| 212 | apply (erule allE, erule impE) | |
| 213 | prefer 2 | |
| 214 | apply (erule allE, erule impE, rule refl, erule spec) | |
| 46129 | 215 | apply simp | 
| 63882 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63167diff
changeset | 216 | apply (simp only: foldl_conv_fold add.commute fold_plus_sum_list_rev) | 
| 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63167diff
changeset | 217 | apply (fastforce simp add: sum_list_map_remove1) | 
| 27623 | 218 | apply clarify | 
| 219 | apply (subgoal_tac "\<exists>y::name. y \<sharp> (x, u, z)") | |
| 39459 | 220 | prefer 2 | 
| 221 | apply (blast intro: exists_fresh' fin_supp) | |
| 27623 | 222 | apply (erule exE) | 
| 223 | apply (subgoal_tac "(Lam [x].u) = (Lam [y].([(y, x)] \<bullet> u))") | |
| 224 | prefer 2 | |
| 225 | apply (auto simp add: lam.inject alpha' fresh_prod fresh_atm)[] | |
| 226 | apply (simp (no_asm_simp)) | |
| 227 | apply (rule assms) | |
| 228 | apply (simp add: fresh_prod) | |
| 229 | apply (erule allE, erule impE) | |
| 230 | prefer 2 | |
| 231 | apply (erule allE, erule impE, rule refl, erule spec) | |
| 232 | apply simp | |
| 233 | apply clarify | |
| 234 | apply (erule allE, erule impE) | |
| 235 | prefer 2 | |
| 47397 
d654c73e4b12
no preference wrt. fold(l/r); prefer fold rather than foldr for iterating over lists in generated code
 haftmann parents: 
46317diff
changeset | 236 | apply blast | 
| 
d654c73e4b12
no preference wrt. fold(l/r); prefer fold rather than foldr for iterating over lists in generated code
 haftmann parents: 
46317diff
changeset | 237 | apply simp | 
| 63882 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63167diff
changeset | 238 | apply (simp only: foldl_conv_fold add.commute fold_plus_sum_list_rev) | 
| 
018998c00003
renamed listsum -> sum_list, listprod ~> prod_list
 nipkow parents: 
63167diff
changeset | 239 | apply (fastforce simp add: sum_list_map_remove1) | 
| 27623 | 240 | done | 
| 241 | ||
| 242 | theorem Apps_lam_induct: | |
| 243 | 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)" | |
| 244 | 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)" | |
| 245 | shows "P z t" | |
| 246 | apply (rule_tac t = t and z = z in lem) | |
| 247 | prefer 3 | |
| 248 | apply (rule refl) | |
| 249 | using assms apply blast+ | |
| 250 | done | |
| 251 | ||
| 252 | ||
| 63167 | 253 | subsection \<open>Congruence rules\<close> | 
| 27623 | 254 | |
| 255 | lemma apps_preserves_beta [simp]: | |
| 256 | "r \<rightarrow>\<^sub>\<beta> s \<Longrightarrow> r \<degree>\<degree> ss \<rightarrow>\<^sub>\<beta> s \<degree>\<degree> ss" | |
| 257 | by (induct ss rule: rev_induct) auto | |
| 258 | ||
| 259 | lemma rtrancl_beta_Abs [intro!]: | |
| 260 | "s \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<Longrightarrow> (Lam [x].s) \<rightarrow>\<^sub>\<beta>\<^sup>* (Lam [x].s')" | |
| 261 | by (induct set: rtranclp) (blast intro: rtranclp.rtrancl_into_rtrancl)+ | |
| 262 | ||
| 263 | lemma rtrancl_beta_AppL: | |
| 264 | "s \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<Longrightarrow> s \<degree> t \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<degree> t" | |
| 265 | by (induct set: rtranclp) (blast intro: rtranclp.rtrancl_into_rtrancl)+ | |
| 266 | ||
| 267 | lemma rtrancl_beta_AppR: | |
| 268 | "t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<Longrightarrow> s \<degree> t \<rightarrow>\<^sub>\<beta>\<^sup>* s \<degree> t'" | |
| 269 | by (induct set: rtranclp) (blast intro: rtranclp.rtrancl_into_rtrancl)+ | |
| 270 | ||
| 271 | lemma rtrancl_beta_App [intro]: | |
| 272 | "s \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<Longrightarrow> t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<Longrightarrow> s \<degree> t \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<degree> t'" | |
| 273 | by (blast intro!: rtrancl_beta_AppL rtrancl_beta_AppR intro: rtranclp_trans) | |
| 274 | ||
| 275 | ||
| 63167 | 276 | subsection \<open>Lifting an order to lists of elements\<close> | 
| 27623 | 277 | |
| 278 | definition | |
| 279 |   step1 :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" where
 | |
| 280 | "step1 r = | |
| 281 | (\<lambda>ys xs. \<exists>us z z' vs. xs = us @ z # vs \<and> r z' z \<and> ys = | |
| 282 | us @ z' # vs)" | |
| 283 | ||
| 284 | lemma not_Nil_step1 [iff]: "\<not> step1 r [] xs" | |
| 285 | apply (unfold step1_def) | |
| 286 | apply blast | |
| 287 | done | |
| 288 | ||
| 289 | lemma not_step1_Nil [iff]: "\<not> step1 r xs []" | |
| 290 | apply (unfold step1_def) | |
| 291 | apply blast | |
| 292 | done | |
| 293 | ||
| 294 | lemma Cons_step1_Cons [iff]: | |
| 295 | "(step1 r (y # ys) (x # xs)) = | |
| 296 | (r y x \<and> xs = ys \<or> x = y \<and> step1 r ys xs)" | |
| 297 | apply (unfold step1_def) | |
| 298 | apply (rule iffI) | |
| 299 | apply (erule exE) | |
| 300 | apply (rename_tac ts) | |
| 301 | apply (case_tac ts) | |
| 44890 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
39779diff
changeset | 302 | apply fastforce | 
| 27623 | 303 | apply force | 
| 304 | apply (erule disjE) | |
| 305 | apply blast | |
| 306 | apply (blast intro: Cons_eq_appendI) | |
| 307 | done | |
| 308 | ||
| 309 | lemma append_step1I: | |
| 310 | "step1 r ys xs \<and> vs = us \<or> ys = xs \<and> step1 r vs us | |
| 311 | \<Longrightarrow> step1 r (ys @ vs) (xs @ us)" | |
| 312 | apply (unfold step1_def) | |
| 313 | apply auto | |
| 314 | apply blast | |
| 315 | apply (blast intro: append_eq_appendI) | |
| 316 | done | |
| 317 | ||
| 318 | lemma Cons_step1E [elim!]: | |
| 319 | assumes "step1 r ys (x # xs)" | |
| 320 | and "\<And>y. ys = y # xs \<Longrightarrow> r y x \<Longrightarrow> R" | |
| 321 | and "\<And>zs. ys = x # zs \<Longrightarrow> step1 r zs xs \<Longrightarrow> R" | |
| 322 | shows R | |
| 323 | using assms | |
| 324 | apply (cases ys) | |
| 325 | apply (simp add: step1_def) | |
| 326 | apply blast | |
| 327 | done | |
| 328 | ||
| 329 | lemma Snoc_step1_SnocD: | |
| 330 | "step1 r (ys @ [y]) (xs @ [x]) | |
| 331 | \<Longrightarrow> (step1 r ys xs \<and> y = x \<or> ys = xs \<and> r y x)" | |
| 332 | apply (unfold step1_def) | |
| 333 | apply (clarify del: disjCI) | |
| 334 | apply (rename_tac vs) | |
| 335 | apply (rule_tac xs = vs in rev_exhaust) | |
| 336 | apply force | |
| 337 | apply simp | |
| 338 | apply blast | |
| 339 | done | |
| 340 | ||
| 341 | ||
| 63167 | 342 | subsection \<open>Lifting beta-reduction to lists\<close> | 
| 27623 | 343 | |
| 344 | abbreviation | |
| 345 | list_beta :: "lam list \<Rightarrow> lam list \<Rightarrow> bool" (infixl "[\<rightarrow>\<^sub>\<beta>]\<^sub>1" 50) where | |
| 346 | "rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss \<equiv> step1 beta rs ss" | |
| 347 | ||
| 348 | lemma head_Var_reduction: | |
| 349 | "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" | |
| 350 | apply (induct u \<equiv> "Var n \<degree>\<degree> rs" v arbitrary: rs set: beta) | |
| 351 | apply simp | |
| 352 | apply (rule_tac xs = rs in rev_exhaust) | |
| 353 | apply simp | |
| 354 | apply (atomize, force intro: append_step1I iff: lam.inject) | |
| 355 | apply (rule_tac xs = rs in rev_exhaust) | |
| 356 | apply simp | |
| 357 | apply (auto 0 3 intro: disjI2 [THEN append_step1I] simp add: lam.inject) | |
| 358 | done | |
| 359 | ||
| 360 | lemma apps_betasE [case_names appL appR beta, consumes 1]: | |
| 361 | assumes major: "r \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> s" | |
| 362 | and cases: "\<And>r'. r \<rightarrow>\<^sub>\<beta> r' \<Longrightarrow> s = r' \<degree>\<degree> rs \<Longrightarrow> R" | |
| 363 | "\<And>rs'. rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 rs' \<Longrightarrow> s = r \<degree>\<degree> rs' \<Longrightarrow> R" | |
| 364 | "\<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" | |
| 365 | shows R | |
| 366 | proof - | |
| 367 | from major have | |
| 368 | "(\<exists>r'. r \<rightarrow>\<^sub>\<beta> r' \<and> s = r' \<degree>\<degree> rs) \<or> | |
| 369 | (\<exists>rs'. rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 rs' \<and> s = r \<degree>\<degree> rs') \<or> | |
| 370 | (\<exists>t u us. x \<sharp> r \<longrightarrow> r = (Lam [x].t) \<and> rs = u # us \<and> s = t[x::=u] \<degree>\<degree> us)" | |
| 71989 
bad75618fb82
extraction of equations x = t from premises beneath meta-all
 haftmann parents: 
69597diff
changeset | 371 | supply [[simproc del: defined_all]] | 
| 27623 | 372 | apply (nominal_induct u \<equiv> "r \<degree>\<degree> rs" s avoiding: x r rs rule: beta.strong_induct) | 
| 373 | apply (simp add: App_eq_foldl_conv) | |
| 62390 | 374 | apply (split if_split_asm) | 
| 27623 | 375 | apply simp | 
| 376 | apply blast | |
| 377 | apply simp | |
| 378 | apply (rule impI)+ | |
| 379 | apply (rule disjI2) | |
| 380 | apply (rule disjI2) | |
| 381 | apply (subgoal_tac "r = [(xa, x)] \<bullet> (Lam [x].s)") | |
| 382 | prefer 2 | |
| 383 | apply (simp add: perm_fresh_fresh) | |
| 384 | apply (drule conjunct1) | |
| 385 | apply (subgoal_tac "r = (Lam [xa]. [(xa, x)] \<bullet> s)") | |
| 386 | prefer 2 | |
| 387 | apply (simp add: calc_atm) | |
| 59807 | 388 | apply (thin_tac "r = _") | 
| 27623 | 389 | apply simp | 
| 390 | apply (rule exI) | |
| 391 | apply (rule conjI) | |
| 392 | apply (rule refl) | |
| 393 | apply (simp add: abs_fresh fresh_atm fresh_left calc_atm subst_rename) | |
| 394 | apply (drule App_eq_foldl_conv [THEN iffD1]) | |
| 62390 | 395 | apply (split if_split_asm) | 
| 27623 | 396 | apply simp | 
| 397 | apply blast | |
| 398 | apply (force intro!: disjI1 [THEN append_step1I] simp add: fresh_list_append) | |
| 399 | apply (drule App_eq_foldl_conv [THEN iffD1]) | |
| 62390 | 400 | apply (split if_split_asm) | 
| 27623 | 401 | apply simp | 
| 402 | apply blast | |
| 403 | apply (clarify, auto 0 3 intro!: exI intro: append_step1I) | |
| 404 | done | |
| 405 | with cases show ?thesis by blast | |
| 406 | qed | |
| 407 | ||
| 408 | lemma apps_preserves_betas [simp]: | |
| 409 | "rs [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss \<Longrightarrow> r \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> r \<degree>\<degree> ss" | |
| 410 | apply (induct rs arbitrary: ss rule: rev_induct) | |
| 411 | apply simp | |
| 412 | apply simp | |
| 413 | apply (rule_tac xs = ss in rev_exhaust) | |
| 414 | apply simp | |
| 415 | apply simp | |
| 416 | apply (drule Snoc_step1_SnocD) | |
| 417 | apply blast | |
| 418 | done | |
| 419 | ||
| 420 | ||
| 63167 | 421 | subsection \<open>Standard reduction relation\<close> | 
| 27623 | 422 | |
| 63167 | 423 | text \<open> | 
| 27623 | 424 | Based on lecture notes by Ralph Matthes, | 
| 425 | original proof idea due to Ralph Loader. | |
| 63167 | 426 | \<close> | 
| 27623 | 427 | |
| 428 | declare listrel_mono [mono_set] | |
| 429 | ||
| 430 | lemma listrelp_eqvt [eqvt]: | |
| 46317 | 431 | fixes f :: "'a::pt_name \<Rightarrow> 'b::pt_name \<Rightarrow> bool" | 
| 27623 | 432 | assumes xy: "listrelp f (x::'a::pt_name list) y" | 
| 433 | shows "listrelp ((pi::name prm) \<bullet> f) (pi \<bullet> x) (pi \<bullet> y)" using xy | |
| 45966 | 434 | by induct (simp_all add: listrelp.intros perm_app [symmetric]) | 
| 27623 | 435 | |
| 436 | inductive | |
| 437 | sred :: "lam \<Rightarrow> lam \<Rightarrow> bool" (infixl "\<rightarrow>\<^sub>s" 50) | |
| 438 | and sredlist :: "lam list \<Rightarrow> lam list \<Rightarrow> bool" (infixl "[\<rightarrow>\<^sub>s]" 50) | |
| 439 | where | |
| 67399 | 440 | "s [\<rightarrow>\<^sub>s] t \<equiv> listrelp (\<rightarrow>\<^sub>s) s t" | 
| 27623 | 441 | | Var: "rs [\<rightarrow>\<^sub>s] rs' \<Longrightarrow> Var x \<degree>\<degree> rs \<rightarrow>\<^sub>s Var x \<degree>\<degree> rs'" | 
| 442 | | 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'" | |
| 443 | | 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" | |
| 444 | ||
| 445 | equivariance sred | |
| 446 | nominal_inductive sred | |
| 447 | by (simp add: abs_fresh)+ | |
| 448 | ||
| 449 | lemma better_sred_Abs: | |
| 450 | assumes H1: "r \<rightarrow>\<^sub>s r'" | |
| 451 | and H2: "ss [\<rightarrow>\<^sub>s] ss'" | |
| 452 | shows "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> ss'" | |
| 453 | proof - | |
| 454 | obtain y::name where y: "y \<sharp> (x, r, r', ss, ss')" | |
| 455 | by (rule exists_fresh) (rule fin_supp) | |
| 456 | then have "y \<sharp> (ss, ss')" by simp | |
| 457 | moreover from H1 have "[(y, x)] \<bullet> (r \<rightarrow>\<^sub>s r')" by (rule perm_boolI) | |
| 458 | then have "([(y, x)] \<bullet> r) \<rightarrow>\<^sub>s ([(y, x)] \<bullet> r')" by (simp add: eqvts) | |
| 459 | 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 | |
| 460 | by (rule sred.Abs) | |
| 461 | moreover from y have "(Lam [x].r) = (Lam [y]. [(y, x)] \<bullet> r)" | |
| 462 | by (auto simp add: lam.inject alpha' fresh_prod fresh_atm) | |
| 463 | moreover from y have "(Lam [x].r') = (Lam [y]. [(y, x)] \<bullet> r')" | |
| 464 | by (auto simp add: lam.inject alpha' fresh_prod fresh_atm) | |
| 465 | ultimately show ?thesis by simp | |
| 466 | qed | |
| 467 | ||
| 468 | lemma better_sred_Beta: | |
| 469 | assumes H: "r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>s t" | |
| 470 | shows "(Lam [x].r) \<degree> s \<degree>\<degree> ss \<rightarrow>\<^sub>s t" | |
| 471 | proof - | |
| 472 | obtain y::name where y: "y \<sharp> (x, r, s, ss, t)" | |
| 473 | by (rule exists_fresh) (rule fin_supp) | |
| 474 | then have "y \<sharp> (s, ss, t)" by simp | |
| 475 | moreover from y H have "([(y, x)] \<bullet> r)[y::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>s t" | |
| 476 | by (simp add: subst_rename) | |
| 477 | ultimately have "(Lam [y].[(y, x)] \<bullet> r) \<degree> s \<degree>\<degree> ss \<rightarrow>\<^sub>s t" | |
| 478 | by (rule sred.Beta) | |
| 479 | moreover from y have "(Lam [x].r) = (Lam [y]. [(y, x)] \<bullet> r)" | |
| 480 | by (auto simp add: lam.inject alpha' fresh_prod fresh_atm) | |
| 481 | ultimately show ?thesis by simp | |
| 482 | qed | |
| 483 | ||
| 484 | lemmas better_sred_intros = sred.Var better_sred_Abs better_sred_Beta | |
| 485 | ||
| 486 | lemma refl_listrelp: "\<forall>x\<in>set xs. R x x \<Longrightarrow> listrelp R xs xs" | |
| 487 | by (induct xs) (auto intro: listrelp.intros) | |
| 488 | ||
| 489 | lemma refl_sred: "t \<rightarrow>\<^sub>s t" | |
| 490 | by (nominal_induct t rule: Apps_lam_induct) (auto intro: refl_listrelp better_sred_intros) | |
| 491 | ||
| 492 | lemma listrelp_conj1: "listrelp (\<lambda>x y. R x y \<and> S x y) x y \<Longrightarrow> listrelp R x y" | |
| 493 | by (erule listrelp.induct) (auto intro: listrelp.intros) | |
| 494 | ||
| 495 | lemma listrelp_conj2: "listrelp (\<lambda>x y. R x y \<and> S x y) x y \<Longrightarrow> listrelp S x y" | |
| 496 | by (erule listrelp.induct) (auto intro: listrelp.intros) | |
| 497 | ||
| 498 | lemma listrelp_app: | |
| 499 | assumes xsys: "listrelp R xs ys" | |
| 500 | shows "listrelp R xs' ys' \<Longrightarrow> listrelp R (xs @ xs') (ys @ ys')" using xsys | |
| 501 | by (induct arbitrary: xs' ys') (auto intro: listrelp.intros) | |
| 502 | ||
| 503 | lemma lemma1: | |
| 504 | assumes r: "r \<rightarrow>\<^sub>s r'" and s: "s \<rightarrow>\<^sub>s s'" | |
| 505 | shows "r \<degree> s \<rightarrow>\<^sub>s r' \<degree> s'" using r | |
| 506 | proof induct | |
| 507 | case (Var rs rs' x) | |
| 508 | then have "rs [\<rightarrow>\<^sub>s] rs'" by (rule listrelp_conj1) | |
| 509 | moreover have "[s] [\<rightarrow>\<^sub>s] [s']" by (iprover intro: s listrelp.intros) | |
| 510 | ultimately have "rs @ [s] [\<rightarrow>\<^sub>s] rs' @ [s']" by (rule listrelp_app) | |
| 511 | hence "Var x \<degree>\<degree> (rs @ [s]) \<rightarrow>\<^sub>s Var x \<degree>\<degree> (rs' @ [s'])" by (rule sred.Var) | |
| 512 | thus ?case by (simp only: app_last) | |
| 513 | next | |
| 514 | case (Abs x ss ss' r r') | |
| 515 | from Abs(4) have "ss [\<rightarrow>\<^sub>s] ss'" by (rule listrelp_conj1) | |
| 516 | moreover have "[s] [\<rightarrow>\<^sub>s] [s']" by (iprover intro: s listrelp.intros) | |
| 517 | ultimately have "ss @ [s] [\<rightarrow>\<^sub>s] ss' @ [s']" by (rule listrelp_app) | |
| 63167 | 518 | with \<open>r \<rightarrow>\<^sub>s r'\<close> have "(Lam [x].r) \<degree>\<degree> (ss @ [s]) \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> (ss' @ [s'])" | 
| 27623 | 519 | by (rule better_sred_Abs) | 
| 520 | thus ?case by (simp only: app_last) | |
| 521 | next | |
| 522 | case (Beta x u ss t r) | |
| 523 | hence "r[x::=u] \<degree>\<degree> (ss @ [s]) \<rightarrow>\<^sub>s t \<degree> s'" by (simp only: app_last) | |
| 524 | hence "(Lam [x].r) \<degree> u \<degree>\<degree> (ss @ [s]) \<rightarrow>\<^sub>s t \<degree> s'" by (rule better_sred_Beta) | |
| 525 | thus ?case by (simp only: app_last) | |
| 526 | qed | |
| 527 | ||
| 528 | lemma lemma1': | |
| 529 | assumes ts: "ts [\<rightarrow>\<^sub>s] ts'" | |
| 530 | shows "r \<rightarrow>\<^sub>s r' \<Longrightarrow> r \<degree>\<degree> ts \<rightarrow>\<^sub>s r' \<degree>\<degree> ts'" using ts | |
| 531 | by (induct arbitrary: r r') (auto intro: lemma1) | |
| 532 | ||
| 533 | lemma listrelp_betas: | |
| 67399 | 534 | assumes ts: "listrelp (\<rightarrow>\<^sub>\<beta>\<^sup>*) ts ts'" | 
| 27623 | 535 | 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 | 
| 536 | by induct auto | |
| 537 | ||
| 538 | lemma lemma2: | |
| 539 | assumes t: "t \<rightarrow>\<^sub>s u" | |
| 540 | shows "t \<rightarrow>\<^sub>\<beta>\<^sup>* u" using t | |
| 541 | by induct (auto dest: listrelp_conj2 | |
| 542 | intro: listrelp_betas apps_preserves_beta converse_rtranclp_into_rtranclp) | |
| 543 | ||
| 544 | lemma lemma3: | |
| 545 | assumes r: "r \<rightarrow>\<^sub>s r'" | |
| 546 | shows "s \<rightarrow>\<^sub>s s' \<Longrightarrow> r[x::=s] \<rightarrow>\<^sub>s r'[x::=s']" using r | |
| 547 | proof (nominal_induct avoiding: x s s' rule: sred.strong_induct) | |
| 548 | case (Var rs rs' y) | |
| 549 | hence "map (\<lambda>t. t[x::=s]) rs [\<rightarrow>\<^sub>s] map (\<lambda>t. t[x::=s']) rs'" | |
| 550 | by induct (auto intro: listrelp.intros Var) | |
| 551 | moreover have "Var y[x::=s] \<rightarrow>\<^sub>s Var y[x::=s']" | |
| 552 | by (cases "y = x") (auto simp add: Var intro: refl_sred) | |
| 553 | ultimately show ?case by simp (rule lemma1') | |
| 554 | next | |
| 555 | case (Abs y ss ss' r r') | |
| 556 | then have "r[x::=s] \<rightarrow>\<^sub>s r'[x::=s']" by fast | |
| 63167 | 557 | moreover from Abs(8) \<open>s \<rightarrow>\<^sub>s s'\<close> have "map (\<lambda>t. t[x::=s]) ss [\<rightarrow>\<^sub>s] map (\<lambda>t. t[x::=s']) ss'" | 
| 27623 | 558 | by induct (auto intro: listrelp.intros Abs) | 
| 63167 | 559 | ultimately show ?case using Abs(6) \<open>y \<sharp> x\<close> \<open>y \<sharp> s\<close> \<open>y \<sharp> s'\<close> | 
| 27623 | 560 | by simp (rule better_sred_Abs) | 
| 561 | next | |
| 562 | case (Beta y u ss t r) | |
| 563 | thus ?case by (auto simp add: subst_subst fresh_atm intro: better_sred_Beta) | |
| 564 | qed | |
| 565 | ||
| 566 | lemma lemma4_aux: | |
| 567 | 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'" | |
| 568 | shows "rs' [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss \<Longrightarrow> rs [\<rightarrow>\<^sub>s] ss" using rs | |
| 569 | proof (induct arbitrary: ss) | |
| 570 | case Nil | |
| 571 | thus ?case by cases (auto intro: listrelp.Nil) | |
| 572 | next | |
| 573 | case (Cons x y xs ys) | |
| 574 | note Cons' = Cons | |
| 575 | show ?case | |
| 576 | proof (cases ss) | |
| 577 | case Nil with Cons show ?thesis by simp | |
| 578 | next | |
| 579 | case (Cons y' ys') | |
| 580 | hence ss: "ss = y' # ys'" by simp | |
| 581 | 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 | |
| 582 | hence "x # xs [\<rightarrow>\<^sub>s] y' # ys'" | |
| 583 | proof | |
| 584 | assume H: "y \<rightarrow>\<^sub>\<beta> y' \<and> ys' = ys" | |
| 585 | with Cons' have "x \<rightarrow>\<^sub>s y'" by blast | |
| 586 | moreover from Cons' have "xs [\<rightarrow>\<^sub>s] ys" by (iprover dest: listrelp_conj1) | |
| 587 | ultimately have "x # xs [\<rightarrow>\<^sub>s] y' # ys" by (rule listrelp.Cons) | |
| 588 | with H show ?thesis by simp | |
| 589 | next | |
| 590 | assume H: "y' = y \<and> ys [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ys'" | |
| 591 | with Cons' have "x \<rightarrow>\<^sub>s y'" by blast | |
| 592 | moreover from H have "xs [\<rightarrow>\<^sub>s] ys'" by (blast intro: Cons') | |
| 593 | ultimately show ?thesis by (rule listrelp.Cons) | |
| 594 | qed | |
| 595 | with ss show ?thesis by simp | |
| 596 | qed | |
| 597 | qed | |
| 598 | ||
| 599 | lemma lemma4: | |
| 600 | assumes r: "r \<rightarrow>\<^sub>s r'" | |
| 601 | shows "r' \<rightarrow>\<^sub>\<beta> r'' \<Longrightarrow> r \<rightarrow>\<^sub>s r''" using r | |
| 602 | proof (nominal_induct avoiding: r'' rule: sred.strong_induct) | |
| 603 | case (Var rs rs' x) | |
| 604 | then obtain ss where rs: "rs' [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ss" and r'': "r'' = Var x \<degree>\<degree> ss" | |
| 605 | by (blast dest: head_Var_reduction) | |
| 606 | from Var(1) [simplified] rs have "rs [\<rightarrow>\<^sub>s] ss" by (rule lemma4_aux) | |
| 607 | hence "Var x \<degree>\<degree> rs \<rightarrow>\<^sub>s Var x \<degree>\<degree> ss" by (rule sred.Var) | |
| 608 | with r'' show ?case by simp | |
| 609 | next | |
| 610 | case (Abs x ss ss' r r') | |
| 63167 | 611 | from \<open>(Lam [x].r') \<degree>\<degree> ss' \<rightarrow>\<^sub>\<beta> r''\<close> show ?case | 
| 27623 | 612 | proof (cases rule: apps_betasE [where x=x]) | 
| 613 | case (appL s) | |
| 63167 | 614 | then obtain r''' where s: "s = (Lam [x].r''')" and r''': "r' \<rightarrow>\<^sub>\<beta> r'''" using \<open>x \<sharp> r''\<close> | 
| 27623 | 615 | by (cases rule: beta.strong_cases) (auto simp add: abs_fresh lam.inject alpha) | 
| 616 | from r''' have "r \<rightarrow>\<^sub>s r'''" by (blast intro: Abs) | |
| 617 | moreover from Abs have "ss [\<rightarrow>\<^sub>s] ss'" by (iprover dest: listrelp_conj1) | |
| 618 | ultimately have "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s (Lam [x].r''') \<degree>\<degree> ss'" by (rule better_sred_Abs) | |
| 619 | with appL s show "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s r''" by simp | |
| 620 | next | |
| 621 | case (appR rs') | |
| 63167 | 622 | from Abs(6) [simplified] \<open>ss' [\<rightarrow>\<^sub>\<beta>]\<^sub>1 rs'\<close> | 
| 27623 | 623 | have "ss [\<rightarrow>\<^sub>s] rs'" by (rule lemma4_aux) | 
| 63167 | 624 | with \<open>r \<rightarrow>\<^sub>s r'\<close> have "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> rs'" by (rule better_sred_Abs) | 
| 27623 | 625 | with appR show "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s r''" by simp | 
| 626 | next | |
| 627 | case (beta t u' us') | |
| 628 | then have Lam_eq: "(Lam [x].r') = (Lam [x].t)" and ss': "ss' = u' # us'" | |
| 629 | and r'': "r'' = t[x::=u'] \<degree>\<degree> us'" | |
| 630 | by (simp_all add: abs_fresh) | |
| 631 | from Abs(6) ss' obtain u us where | |
| 632 | ss: "ss = u # us" and u: "u \<rightarrow>\<^sub>s u'" and us: "us [\<rightarrow>\<^sub>s] us'" | |
| 633 | by cases (auto dest!: listrelp_conj1) | |
| 63167 | 634 | have "r[x::=u] \<rightarrow>\<^sub>s r'[x::=u']" using \<open>r \<rightarrow>\<^sub>s r'\<close> and u by (rule lemma3) | 
| 27623 | 635 | with us have "r[x::=u] \<degree>\<degree> us \<rightarrow>\<^sub>s r'[x::=u'] \<degree>\<degree> us'" by (rule lemma1') | 
| 636 | hence "(Lam [x].r) \<degree> u \<degree>\<degree> us \<rightarrow>\<^sub>s r'[x::=u'] \<degree>\<degree> us'" by (rule better_sred_Beta) | |
| 637 | with ss r'' Lam_eq show "(Lam [x].r) \<degree>\<degree> ss \<rightarrow>\<^sub>s r''" by (simp add: lam.inject alpha) | |
| 638 | qed | |
| 639 | next | |
| 640 | case (Beta x s ss t r) | |
| 641 | show ?case | |
| 642 | by (rule better_sred_Beta) (rule Beta)+ | |
| 643 | qed | |
| 644 | ||
| 645 | lemma rtrancl_beta_sred: | |
| 646 | assumes r: "r \<rightarrow>\<^sub>\<beta>\<^sup>* r'" | |
| 647 | shows "r \<rightarrow>\<^sub>s r'" using r | |
| 648 | by induct (iprover intro: refl_sred lemma4)+ | |
| 649 | ||
| 650 | ||
| 63167 | 651 | subsection \<open>Terms in normal form\<close> | 
| 27623 | 652 | |
| 653 | lemma listsp_eqvt [eqvt]: | |
| 654 | assumes xs: "listsp p (xs::'a::pt_name list)" | |
| 655 | shows "listsp ((pi::name prm) \<bullet> p) (pi \<bullet> xs)" using xs | |
| 656 | apply induct | |
| 657 | apply simp | |
| 658 | apply simp | |
| 659 | apply (rule listsp.intros) | |
| 660 | apply (drule_tac pi=pi in perm_boolI) | |
| 661 | apply perm_simp | |
| 662 | apply assumption | |
| 663 | done | |
| 664 | ||
| 665 | inductive NF :: "lam \<Rightarrow> bool" | |
| 666 | where | |
| 667 | App: "listsp NF ts \<Longrightarrow> NF (Var x \<degree>\<degree> ts)" | |
| 668 | | Abs: "NF t \<Longrightarrow> NF (Lam [x].t)" | |
| 669 | ||
| 670 | equivariance NF | |
| 671 | nominal_inductive NF | |
| 672 | by (simp add: abs_fresh) | |
| 673 | ||
| 674 | lemma Abs_NF: | |
| 675 | assumes NF: "NF ((Lam [x].t) \<degree>\<degree> ts)" | |
| 676 | shows "ts = []" using NF | |
| 677 | proof cases | |
| 678 | case (App us i) | |
| 679 | thus ?thesis by (simp add: Var_apps_neq_Abs_apps [THEN not_sym]) | |
| 680 | next | |
| 681 | case (Abs u) | |
| 682 | thus ?thesis by simp | |
| 683 | qed | |
| 684 | ||
| 63167 | 685 | text \<open> | 
| 69597 | 686 | \<^term>\<open>NF\<close> characterizes exactly the terms that are in normal form. | 
| 63167 | 687 | \<close> | 
| 27623 | 688 | |
| 689 | lemma NF_eq: "NF t = (\<forall>t'. \<not> t \<rightarrow>\<^sub>\<beta> t')" | |
| 690 | proof | |
| 691 | assume H: "NF t" | |
| 692 | show "\<forall>t'. \<not> t \<rightarrow>\<^sub>\<beta> t'" | |
| 693 | proof | |
| 694 | fix t' | |
| 695 | from H show "\<not> t \<rightarrow>\<^sub>\<beta> t'" | |
| 696 | proof (nominal_induct avoiding: t' rule: NF.strong_induct) | |
| 697 | case (App ts t) | |
| 698 | show ?case | |
| 699 | proof | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 700 | 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 | 701 | 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 | 702 | by (iprover dest: head_Var_reduction) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 703 | with App show False | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 704 | by (induct rs arbitrary: ts) (auto del: in_listspD) | 
| 27623 | 705 | qed | 
| 706 | next | |
| 707 | case (Abs t x) | |
| 708 | show ?case | |
| 709 | proof | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 710 | assume "(Lam [x].t) \<rightarrow>\<^sub>\<beta> t'" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 711 | then show False using Abs | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
29097diff
changeset | 712 | by (cases rule: beta.strong_cases) (auto simp add: abs_fresh lam.inject alpha) | 
| 27623 | 713 | qed | 
| 714 | qed | |
| 715 | qed | |
| 716 | next | |
| 717 | assume H: "\<forall>t'. \<not> t \<rightarrow>\<^sub>\<beta> t'" | |
| 718 | then show "NF t" | |
| 719 | proof (nominal_induct t rule: Apps_lam_induct) | |
| 720 | case (1 n ts) | |
| 721 | then have "\<forall>ts'. \<not> ts [\<rightarrow>\<^sub>\<beta>]\<^sub>1 ts'" | |
| 722 | by (iprover intro: apps_preserves_betas) | |
| 723 | with 1(1) have "listsp NF ts" | |
| 724 | by (induct ts) (auto simp add: in_listsp_conv_set) | |
| 725 | then show ?case by (rule NF.App) | |
| 726 | next | |
| 727 | case (2 x u ts) | |
| 728 | show ?case | |
| 729 | proof (cases ts) | |
| 39459 | 730 | case Nil thus ?thesis by (metis 2 NF.Abs abs foldl_Nil) | 
| 27623 | 731 | next | 
| 732 | case (Cons r rs) | |
| 733 | have "(Lam [x].u) \<degree> r \<rightarrow>\<^sub>\<beta> u[x::=r]" .. | |
| 734 | 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 | 735 | by (rule apps_preserves_beta) | 
| 27623 | 736 | 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 | 737 | by simp | 
| 27623 | 738 | with 2 show ?thesis by iprover | 
| 739 | qed | |
| 740 | qed | |
| 741 | qed | |
| 742 | ||
| 743 | ||
| 63167 | 744 | subsection \<open>Leftmost reduction and weakly normalizing terms\<close> | 
| 27623 | 745 | |
| 746 | inductive | |
| 747 | lred :: "lam \<Rightarrow> lam \<Rightarrow> bool" (infixl "\<rightarrow>\<^sub>l" 50) | |
| 748 | and lredlist :: "lam list \<Rightarrow> lam list \<Rightarrow> bool" (infixl "[\<rightarrow>\<^sub>l]" 50) | |
| 749 | where | |
| 67399 | 750 | "s [\<rightarrow>\<^sub>l] t \<equiv> listrelp (\<rightarrow>\<^sub>l) s t" | 
| 27623 | 751 | | Var: "rs [\<rightarrow>\<^sub>l] rs' \<Longrightarrow> Var x \<degree>\<degree> rs \<rightarrow>\<^sub>l Var x \<degree>\<degree> rs'" | 
| 752 | | Abs: "r \<rightarrow>\<^sub>l r' \<Longrightarrow> (Lam [x].r) \<rightarrow>\<^sub>l (Lam [x].r')" | |
| 753 | | Beta: "r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>l t \<Longrightarrow> (Lam [x].r) \<degree> s \<degree>\<degree> ss \<rightarrow>\<^sub>l t" | |
| 754 | ||
| 755 | lemma lred_imp_sred: | |
| 756 | assumes lred: "s \<rightarrow>\<^sub>l t" | |
| 757 | shows "s \<rightarrow>\<^sub>s t" using lred | |
| 758 | proof induct | |
| 759 | case (Var rs rs' x) | |
| 760 | then have "rs [\<rightarrow>\<^sub>s] rs'" | |
| 761 | by induct (iprover intro: listrelp.intros)+ | |
| 762 | then show ?case by (rule sred.Var) | |
| 763 | next | |
| 764 | case (Abs r r' x) | |
| 63167 | 765 | from \<open>r \<rightarrow>\<^sub>s r'\<close> | 
| 27623 | 766 | have "(Lam [x].r) \<degree>\<degree> [] \<rightarrow>\<^sub>s (Lam [x].r') \<degree>\<degree> []" using listrelp.Nil | 
| 767 | by (rule better_sred_Abs) | |
| 768 | then show ?case by simp | |
| 769 | next | |
| 770 | case (Beta r x s ss t) | |
| 63167 | 771 | from \<open>r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>s t\<close> | 
| 27623 | 772 | show ?case by (rule better_sred_Beta) | 
| 773 | qed | |
| 774 | ||
| 775 | inductive WN :: "lam \<Rightarrow> bool" | |
| 776 | where | |
| 777 | Var: "listsp WN rs \<Longrightarrow> WN (Var n \<degree>\<degree> rs)" | |
| 778 | | Lambda: "WN r \<Longrightarrow> WN (Lam [x].r)" | |
| 779 | | Beta: "WN ((r[x::=s]) \<degree>\<degree> ss) \<Longrightarrow> WN (((Lam [x].r) \<degree> s) \<degree>\<degree> ss)" | |
| 780 | ||
| 781 | lemma listrelp_imp_listsp1: | |
| 782 | assumes H: "listrelp (\<lambda>x y. P x) xs ys" | |
| 783 | shows "listsp P xs" using H | |
| 784 | by induct auto | |
| 785 | ||
| 786 | lemma listrelp_imp_listsp2: | |
| 787 | assumes H: "listrelp (\<lambda>x y. P y) xs ys" | |
| 788 | shows "listsp P ys" using H | |
| 789 | by induct auto | |
| 790 | ||
| 791 | lemma lemma5: | |
| 792 | assumes lred: "r \<rightarrow>\<^sub>l r'" | |
| 793 | shows "WN r" and "NF r'" using lred | |
| 794 | by induct | |
| 795 | (iprover dest: listrelp_conj1 listrelp_conj2 | |
| 796 | listrelp_imp_listsp1 listrelp_imp_listsp2 intro: WN.intros | |
| 797 | NF.intros)+ | |
| 798 | ||
| 799 | lemma lemma6: | |
| 800 | assumes wn: "WN r" | |
| 801 | shows "\<exists>r'. r \<rightarrow>\<^sub>l r'" using wn | |
| 802 | proof induct | |
| 803 | case (Var rs n) | |
| 804 | then have "\<exists>rs'. rs [\<rightarrow>\<^sub>l] rs'" | |
| 805 | by induct (iprover intro: listrelp.intros)+ | |
| 806 | then show ?case by (iprover intro: lred.Var) | |
| 807 | qed (iprover intro: lred.intros)+ | |
| 808 | ||
| 809 | lemma lemma7: | |
| 810 | assumes r: "r \<rightarrow>\<^sub>s r'" | |
| 811 | shows "NF r' \<Longrightarrow> r \<rightarrow>\<^sub>l r'" using r | |
| 812 | proof induct | |
| 813 | case (Var rs rs' x) | |
| 63167 | 814 | from \<open>NF (Var x \<degree>\<degree> rs')\<close> have "listsp NF rs'" | 
| 27623 | 815 | by cases simp_all | 
| 816 | with Var(1) have "rs [\<rightarrow>\<^sub>l] rs'" | |
| 817 | proof induct | |
| 818 | case Nil | |
| 819 | show ?case by (rule listrelp.Nil) | |
| 820 | next | |
| 39459 | 821 | case (Cons x y xs ys) | 
| 27623 | 822 | hence "x \<rightarrow>\<^sub>l y" and "xs [\<rightarrow>\<^sub>l] ys" by (auto del: in_listspD) | 
| 823 | thus ?case by (rule listrelp.Cons) | |
| 824 | qed | |
| 825 | thus ?case by (rule lred.Var) | |
| 826 | next | |
| 827 | case (Abs x ss ss' r r') | |
| 63167 | 828 | from \<open>NF ((Lam [x].r') \<degree>\<degree> ss')\<close> | 
| 27623 | 829 | have ss': "ss' = []" by (rule Abs_NF) | 
| 830 | from Abs(4) have ss: "ss = []" using ss' | |
| 831 | by cases simp_all | |
| 832 | from ss' Abs have "NF (Lam [x].r')" by simp | |
| 833 | hence "NF r'" by (cases rule: NF.strong_cases) (auto simp add: abs_fresh lam.inject alpha) | |
| 834 | with Abs have "r \<rightarrow>\<^sub>l r'" by simp | |
| 835 | hence "(Lam [x].r) \<rightarrow>\<^sub>l (Lam [x].r')" by (rule lred.Abs) | |
| 836 | with ss ss' show ?case by simp | |
| 837 | next | |
| 838 | case (Beta x s ss t r) | |
| 839 | hence "r[x::=s] \<degree>\<degree> ss \<rightarrow>\<^sub>l t" by simp | |
| 840 | thus ?case by (rule lred.Beta) | |
| 841 | qed | |
| 842 | ||
| 843 | lemma WN_eq: "WN t = (\<exists>t'. t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<and> NF t')" | |
| 844 | proof | |
| 845 | assume "WN t" | |
| 846 | then have "\<exists>t'. t \<rightarrow>\<^sub>l t'" by (rule lemma6) | |
| 847 | then obtain t' where t': "t \<rightarrow>\<^sub>l t'" .. | |
| 848 | then have NF: "NF t'" by (rule lemma5) | |
| 849 | from t' have "t \<rightarrow>\<^sub>s t'" by (rule lred_imp_sred) | |
| 850 | then have "t \<rightarrow>\<^sub>\<beta>\<^sup>* t'" by (rule lemma2) | |
| 851 | with NF show "\<exists>t'. t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<and> NF t'" by iprover | |
| 852 | next | |
| 853 | assume "\<exists>t'. t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<and> NF t'" | |
| 854 | then obtain t' where t': "t \<rightarrow>\<^sub>\<beta>\<^sup>* t'" and NF: "NF t'" | |
| 855 | by iprover | |
| 856 | from t' have "t \<rightarrow>\<^sub>s t'" by (rule rtrancl_beta_sred) | |
| 857 | then have "t \<rightarrow>\<^sub>l t'" using NF by (rule lemma7) | |
| 858 | then show "WN t" by (rule lemma5) | |
| 859 | qed | |
| 860 | ||
| 861 | end | |
| 47397 
d654c73e4b12
no preference wrt. fold(l/r); prefer fold rather than foldr for iterating over lists in generated code
 haftmann parents: 
46317diff
changeset | 862 |