equal
deleted
inserted
replaced
1 (* Title: HOL/Proofs/Lambda/Lambda.thy |
1 (* Title: HOL/Proofs/Lambda/Lambda.thy |
2 Author: Tobias Nipkow |
2 Author: Tobias Nipkow |
3 Copyright 1995 TU Muenchen |
3 Copyright 1995 TU Muenchen |
4 *) |
4 *) |
5 |
5 |
6 section {* Basic definitions of Lambda-calculus *} |
6 section \<open>Basic definitions of Lambda-calculus\<close> |
7 |
7 |
8 theory Lambda |
8 theory Lambda |
9 imports Main |
9 imports Main |
10 begin |
10 begin |
11 |
11 |
12 declare [[syntax_ambiguity_warning = false]] |
12 declare [[syntax_ambiguity_warning = false]] |
13 |
13 |
14 |
14 |
15 subsection {* Lambda-terms in de Bruijn notation and substitution *} |
15 subsection \<open>Lambda-terms in de Bruijn notation and substitution\<close> |
16 |
16 |
17 datatype dB = |
17 datatype dB = |
18 Var nat |
18 Var nat |
19 | App dB dB (infixl "\<degree>" 200) |
19 | App dB dB (infixl "\<degree>" 200) |
20 | Abs dB |
20 | Abs dB |
34 | subst_App: "(t \<degree> u)[s/k] = t[s/k] \<degree> u[s/k]" |
34 | subst_App: "(t \<degree> u)[s/k] = t[s/k] \<degree> u[s/k]" |
35 | subst_Abs: "(Abs t)[s/k] = Abs (t[lift s 0 / k+1])" |
35 | subst_Abs: "(Abs t)[s/k] = Abs (t[lift s 0 / k+1])" |
36 |
36 |
37 declare subst_Var [simp del] |
37 declare subst_Var [simp del] |
38 |
38 |
39 text {* Optimized versions of @{term subst} and @{term lift}. *} |
39 text \<open>Optimized versions of @{term subst} and @{term lift}.\<close> |
40 |
40 |
41 primrec |
41 primrec |
42 liftn :: "[nat, dB, nat] => dB" |
42 liftn :: "[nat, dB, nat] => dB" |
43 where |
43 where |
44 "liftn n (Var i) k = (if i < k then Var i else Var (i + n))" |
44 "liftn n (Var i) k = (if i < k then Var i else Var (i + n))" |
52 (if k < i then Var (i - 1) else if i = k then liftn k s 0 else Var i)" |
52 (if k < i then Var (i - 1) else if i = k then liftn k s 0 else Var i)" |
53 | "substn (t \<degree> u) s k = substn t s k \<degree> substn u s k" |
53 | "substn (t \<degree> u) s k = substn t s k \<degree> substn u s k" |
54 | "substn (Abs t) s k = Abs (substn t s (k + 1))" |
54 | "substn (Abs t) s k = Abs (substn t s (k + 1))" |
55 |
55 |
56 |
56 |
57 subsection {* Beta-reduction *} |
57 subsection \<open>Beta-reduction\<close> |
58 |
58 |
59 inductive beta :: "[dB, dB] => bool" (infixl "\<rightarrow>\<^sub>\<beta>" 50) |
59 inductive beta :: "[dB, dB] => bool" (infixl "\<rightarrow>\<^sub>\<beta>" 50) |
60 where |
60 where |
61 beta [simp, intro!]: "Abs s \<degree> t \<rightarrow>\<^sub>\<beta> s[t/0]" |
61 beta [simp, intro!]: "Abs s \<degree> t \<rightarrow>\<^sub>\<beta> s[t/0]" |
62 | appL [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t ==> s \<degree> u \<rightarrow>\<^sub>\<beta> t \<degree> u" |
62 | appL [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t ==> s \<degree> u \<rightarrow>\<^sub>\<beta> t \<degree> u" |
74 "Var i \<rightarrow>\<^sub>\<beta> t" |
74 "Var i \<rightarrow>\<^sub>\<beta> t" |
75 "Abs r \<rightarrow>\<^sub>\<beta> s" |
75 "Abs r \<rightarrow>\<^sub>\<beta> s" |
76 "s \<degree> t \<rightarrow>\<^sub>\<beta> u" |
76 "s \<degree> t \<rightarrow>\<^sub>\<beta> u" |
77 |
77 |
78 declare if_not_P [simp] not_less_eq [simp] |
78 declare if_not_P [simp] not_less_eq [simp] |
79 -- {* don't add @{text "r_into_rtrancl[intro!]"} *} |
79 \<comment> \<open>don't add \<open>r_into_rtrancl[intro!]\<close>\<close> |
80 |
80 |
81 |
81 |
82 subsection {* Congruence rules *} |
82 subsection \<open>Congruence rules\<close> |
83 |
83 |
84 lemma rtrancl_beta_Abs [intro!]: |
84 lemma rtrancl_beta_Abs [intro!]: |
85 "s \<rightarrow>\<^sub>\<beta>\<^sup>* s' ==> Abs s \<rightarrow>\<^sub>\<beta>\<^sup>* Abs s'" |
85 "s \<rightarrow>\<^sub>\<beta>\<^sup>* s' ==> Abs s \<rightarrow>\<^sub>\<beta>\<^sup>* Abs s'" |
86 by (induct set: rtranclp) (blast intro: rtranclp.rtrancl_into_rtrancl)+ |
86 by (induct set: rtranclp) (blast intro: rtranclp.rtrancl_into_rtrancl)+ |
87 |
87 |
96 lemma rtrancl_beta_App [intro]: |
96 lemma rtrancl_beta_App [intro]: |
97 "[| s \<rightarrow>\<^sub>\<beta>\<^sup>* s'; t \<rightarrow>\<^sub>\<beta>\<^sup>* t' |] ==> s \<degree> t \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<degree> t'" |
97 "[| s \<rightarrow>\<^sub>\<beta>\<^sup>* s'; t \<rightarrow>\<^sub>\<beta>\<^sup>* t' |] ==> s \<degree> t \<rightarrow>\<^sub>\<beta>\<^sup>* s' \<degree> t'" |
98 by (blast intro!: rtrancl_beta_AppL rtrancl_beta_AppR intro: rtranclp_trans) |
98 by (blast intro!: rtrancl_beta_AppL rtrancl_beta_AppR intro: rtranclp_trans) |
99 |
99 |
100 |
100 |
101 subsection {* Substitution-lemmas *} |
101 subsection \<open>Substitution-lemmas\<close> |
102 |
102 |
103 lemma subst_eq [simp]: "(Var k)[u/k] = u" |
103 lemma subst_eq [simp]: "(Var k)[u/k] = u" |
104 by (simp add: subst_Var) |
104 by (simp add: subst_Var) |
105 |
105 |
106 lemma subst_gt [simp]: "i < j ==> (Var j)[u/i] = Var (j - 1)" |
106 lemma subst_gt [simp]: "i < j ==> (Var j)[u/i] = Var (j - 1)" |
131 by (induct t arbitrary: i j u v) |
131 by (induct t arbitrary: i j u v) |
132 (simp_all add: diff_Suc subst_Var lift_lift [symmetric] lift_subst_lt |
132 (simp_all add: diff_Suc subst_Var lift_lift [symmetric] lift_subst_lt |
133 split: nat.split) |
133 split: nat.split) |
134 |
134 |
135 |
135 |
136 subsection {* Equivalence proof for optimized substitution *} |
136 subsection \<open>Equivalence proof for optimized substitution\<close> |
137 |
137 |
138 lemma liftn_0 [simp]: "liftn 0 t k = t" |
138 lemma liftn_0 [simp]: "liftn 0 t k = t" |
139 by (induct t arbitrary: k) (simp_all add: subst_Var) |
139 by (induct t arbitrary: k) (simp_all add: subst_Var) |
140 |
140 |
141 lemma liftn_lift [simp]: "liftn (Suc n) t k = lift (liftn n t k) k" |
141 lemma liftn_lift [simp]: "liftn (Suc n) t k = lift (liftn n t k) k" |
146 |
146 |
147 theorem substn_subst_0: "substn t s 0 = t[s/0]" |
147 theorem substn_subst_0: "substn t s 0 = t[s/0]" |
148 by simp |
148 by simp |
149 |
149 |
150 |
150 |
151 subsection {* Preservation theorems *} |
151 subsection \<open>Preservation theorems\<close> |
152 |
152 |
153 text {* Not used in Church-Rosser proof, but in Strong |
153 text \<open>Not used in Church-Rosser proof, but in Strong |
154 Normalization. \medskip *} |
154 Normalization. \medskip\<close> |
155 |
155 |
156 theorem subst_preserves_beta [simp]: |
156 theorem subst_preserves_beta [simp]: |
157 "r \<rightarrow>\<^sub>\<beta> s ==> r[t/i] \<rightarrow>\<^sub>\<beta> s[t/i]" |
157 "r \<rightarrow>\<^sub>\<beta> s ==> r[t/i] \<rightarrow>\<^sub>\<beta> s[t/i]" |
158 by (induct arbitrary: t i set: beta) (simp_all add: subst_subst [symmetric]) |
158 by (induct arbitrary: t i set: beta) (simp_all add: subst_subst [symmetric]) |
159 |
159 |