21107
|
1 |
(* $Id: *)
|
|
2 |
|
|
3 |
theory Lam_Funs
|
|
4 |
imports Nominal
|
|
5 |
begin
|
|
6 |
|
|
7 |
atom_decl name
|
|
8 |
|
|
9 |
nominal_datatype lam = Var "name"
|
|
10 |
| App "lam" "lam"
|
|
11 |
| Lam "\<guillemotleft>name\<guillemotright>lam" ("Lam [_]._" [100,100] 100)
|
|
12 |
|
|
13 |
|
|
14 |
constdefs
|
|
15 |
depth_Var :: "name \<Rightarrow> nat"
|
|
16 |
"depth_Var \<equiv> \<lambda>(a::name). 1"
|
|
17 |
|
|
18 |
depth_App :: "lam \<Rightarrow> lam \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
|
|
19 |
"depth_App \<equiv> \<lambda>_ _ n1 n2. (max n1 n2)+1"
|
|
20 |
|
|
21 |
depth_Lam :: "name \<Rightarrow> lam \<Rightarrow> nat \<Rightarrow> nat"
|
|
22 |
"depth_Lam \<equiv> \<lambda>_ _ n. n+1"
|
|
23 |
|
|
24 |
depth_lam :: "lam \<Rightarrow> nat"
|
|
25 |
"depth_lam t \<equiv> (lam_rec depth_Var depth_App depth_Lam) t"
|
|
26 |
|
|
27 |
lemma fin_supp_depth_lam:
|
|
28 |
shows "finite ((supp depth_Var)::name set)"
|
|
29 |
and "finite ((supp depth_Lam)::name set)"
|
|
30 |
and "finite ((supp depth_App)::name set)"
|
|
31 |
by (finite_guess add: depth_Var_def depth_Lam_def depth_App_def perm_nat_def)+
|
|
32 |
|
|
33 |
lemma fcb_depth_lam:
|
|
34 |
fixes a::"name"
|
|
35 |
shows "a\<sharp>(depth_Lam a t n)"
|
|
36 |
by (simp add: fresh_nat)
|
|
37 |
|
|
38 |
lemma depth_lam:
|
|
39 |
shows "depth_lam (Var a) = 1"
|
|
40 |
and "depth_lam (App t1 t2) = (max (depth_lam t1) (depth_lam t2))+1"
|
|
41 |
and "depth_lam (Lam [a].t) = (depth_lam t)+1"
|
|
42 |
apply -
|
|
43 |
apply(unfold depth_lam_def)
|
|
44 |
apply(rule trans)
|
|
45 |
apply(rule lam.recs[where P="\<lambda>_. True" and z="()", simplified])
|
|
46 |
apply(simp_all add: fin_supp_depth_lam supp_unit)
|
|
47 |
apply(simp add: fcb_depth_lam)
|
|
48 |
apply(simp add: depth_Var_def)
|
|
49 |
apply(rule trans)
|
|
50 |
apply(rule lam.recs[where P="\<lambda>_. True" and z="()", simplified])
|
|
51 |
apply(simp_all add: fin_supp_depth_lam supp_unit)
|
|
52 |
apply(simp add: fcb_depth_lam)
|
|
53 |
apply(simp add: depth_App_def)
|
|
54 |
apply(rule trans)
|
|
55 |
apply(rule lam.recs[where P="\<lambda>_. True" and z="()", simplified])
|
|
56 |
apply(simp_all add: fin_supp_depth_lam supp_unit)
|
|
57 |
apply(simp add: fcb_depth_lam)
|
|
58 |
apply(simp add: depth_Var_def, fresh_guess add: perm_nat_def)
|
|
59 |
apply(simp add: depth_App_def, fresh_guess add: perm_nat_def)
|
|
60 |
apply(simp add: depth_Lam_def, fresh_guess add: perm_nat_def)
|
|
61 |
apply(simp add: depth_Lam_def)
|
|
62 |
done
|
|
63 |
|
|
64 |
text {* capture-avoiding substitution *}
|
|
65 |
constdefs
|
|
66 |
subst_Var :: "name \<Rightarrow>lam \<Rightarrow> name \<Rightarrow> lam"
|
|
67 |
"subst_Var b t \<equiv> \<lambda>a. (if a=b then t else (Var a))"
|
|
68 |
|
|
69 |
subst_App :: "name \<Rightarrow> lam \<Rightarrow> lam \<Rightarrow> lam \<Rightarrow> lam \<Rightarrow> lam \<Rightarrow> lam"
|
|
70 |
"subst_App b t \<equiv> \<lambda>_ _ r1 r2. App r1 r2"
|
|
71 |
|
|
72 |
subst_Lam :: "name \<Rightarrow> lam \<Rightarrow> name \<Rightarrow> lam \<Rightarrow> lam \<Rightarrow> lam"
|
|
73 |
"subst_Lam b t \<equiv> \<lambda>a _ r. Lam [a].r"
|
|
74 |
|
|
75 |
abbreviation
|
|
76 |
subst_syn :: "lam \<Rightarrow> name \<Rightarrow> lam \<Rightarrow> lam" ("_[_::=_]" [100,100,100] 900)
|
|
77 |
"t'[b::=t] \<equiv> (lam_rec (subst_Var b t) (subst_App b t) (subst_Lam b t)) t'"
|
|
78 |
|
|
79 |
(* FIXME: this lemma needs to be in Nominal.thy *)
|
|
80 |
lemma eq_eqvt:
|
|
81 |
fixes pi::"name prm"
|
|
82 |
and x::"'a::pt_name"
|
|
83 |
shows "pi\<bullet>(x=y) = ((pi\<bullet>x)=(pi\<bullet>y))"
|
|
84 |
apply(simp add: perm_bool perm_bij)
|
|
85 |
done
|
|
86 |
|
|
87 |
lemma fin_supp_subst:
|
|
88 |
shows "finite ((supp (subst_Var b t))::name set)"
|
|
89 |
and "finite ((supp (subst_Lam b t))::name set)"
|
|
90 |
and "finite ((supp (subst_App b t))::name set)"
|
|
91 |
apply -
|
|
92 |
apply(finite_guess add: subst_Var_def perm_if eq_eqvt fs_name1)
|
|
93 |
apply(finite_guess add: subst_Lam_def fs_name1)
|
|
94 |
apply(finite_guess add: subst_App_def fs_name1)
|
|
95 |
done
|
|
96 |
|
|
97 |
lemma fcb_subst:
|
|
98 |
fixes a::"name"
|
|
99 |
shows "a\<sharp>(subst_Lam b t) a t' r"
|
|
100 |
by (simp add: subst_Lam_def abs_fresh)
|
|
101 |
|
|
102 |
lemma subst[simp]:
|
|
103 |
shows "(Var a)[b::=t] = (if a=b then t else (Var a))"
|
|
104 |
and "(App t1 t2)[b::=t] = App (t1[b::=t]) (t2[b::=t])"
|
|
105 |
and "a\<sharp>(b,t) \<Longrightarrow> (Lam [a].t1)[b::=t] = Lam [a].(t1[b::=t])"
|
|
106 |
and "\<lbrakk>a\<noteq>b; a\<sharp>t\<rbrakk> \<Longrightarrow> (Lam [a].t1)[b::=t] = Lam [a].(t1[b::=t])"
|
|
107 |
and "\<lbrakk>a\<sharp>b; a\<sharp>t\<rbrakk> \<Longrightarrow> (Lam [a].t1)[b::=t] = Lam [a].(t1[b::=t])"
|
|
108 |
apply -
|
|
109 |
apply(rule trans)
|
|
110 |
apply(rule lam.recs[where P="\<lambda>_. True" and z="()", simplified])
|
|
111 |
apply(simp add: fs_name1 fin_supp_subst)+
|
|
112 |
apply(simp add: fcb_subst)
|
|
113 |
apply(simp add: subst_Var_def)
|
|
114 |
apply(rule trans)
|
|
115 |
apply(rule lam.recs[where P="\<lambda>_. True" and z="()", simplified])
|
|
116 |
apply(simp add: fs_name1 fin_supp_subst)+
|
|
117 |
apply(simp add: fcb_subst)
|
|
118 |
apply(simp add: subst_App_def)
|
|
119 |
apply(rule trans)
|
|
120 |
apply(rule lam.recs[where P="\<lambda>_. True" and z="()", simplified])
|
|
121 |
apply(simp add: fs_name1 fin_supp_subst)+
|
|
122 |
apply(simp add: fcb_subst)
|
|
123 |
apply(fresh_guess add: subst_Var_def perm_if eq_eqvt fs_name1)
|
|
124 |
apply(fresh_guess add: subst_App_def fs_name1)
|
|
125 |
apply(fresh_guess add: subst_Lam_def fs_name1)
|
|
126 |
apply(simp add: subst_Lam_def)
|
|
127 |
apply(rule trans)
|
|
128 |
apply(rule lam.recs[where P="\<lambda>_. True" and z="()", simplified])
|
|
129 |
apply(simp add: fs_name1 fin_supp_subst)+
|
|
130 |
apply(simp add: fcb_subst)
|
|
131 |
apply(fresh_guess add: subst_Var_def perm_if eq_eqvt fs_name1 fresh_atm)
|
|
132 |
apply(fresh_guess add: subst_App_def fs_name1 fresh_atm)
|
|
133 |
apply(fresh_guess add: subst_Lam_def fs_name1 fresh_atm)
|
|
134 |
apply(simp add: subst_Lam_def)
|
|
135 |
apply(rule trans)
|
|
136 |
apply(rule lam.recs[where P="\<lambda>_. True" and z="()", simplified])
|
|
137 |
apply(simp add: fs_name1 fin_supp_subst)+
|
|
138 |
apply(simp add: fcb_subst)
|
|
139 |
apply(fresh_guess add: subst_Var_def perm_if eq_eqvt fs_name1)
|
|
140 |
apply(fresh_guess add: subst_App_def fs_name1)
|
|
141 |
apply(fresh_guess add: subst_Lam_def fs_name1)
|
|
142 |
apply(simp add: subst_Lam_def)
|
|
143 |
done
|
|
144 |
|
|
145 |
lemma subst_eqvt[simp]:
|
|
146 |
fixes pi:: "name prm"
|
|
147 |
and t1:: "lam"
|
|
148 |
and t2:: "lam"
|
|
149 |
and a :: "name"
|
|
150 |
shows "pi\<bullet>(t1[b::=t2]) = (pi\<bullet>t1)[(pi\<bullet>b)::=(pi\<bullet>t2)]"
|
|
151 |
apply(nominal_induct t1 avoiding: b t2 rule: lam.induct)
|
|
152 |
apply(auto simp add: perm_bij fresh_prod fresh_atm fresh_bij)
|
|
153 |
done
|
|
154 |
|
|
155 |
lemma subst_supp:
|
|
156 |
shows "supp(t1[a::=t2]) \<subseteq> (((supp(t1)-{a})\<union>supp(t2))::name set)"
|
|
157 |
apply(nominal_induct t1 avoiding: a t2 rule: lam.induct)
|
|
158 |
apply(auto simp add: lam.supp supp_atm fresh_prod abs_supp)
|
|
159 |
apply(blast)+
|
|
160 |
done
|
|
161 |
|
|
162 |
(* parallel substitution *)
|
|
163 |
|
|
164 |
(* simultaneous substitution *)
|
|
165 |
consts
|
|
166 |
"domain" :: "(name\<times>lam) list \<Rightarrow> (name list)"
|
|
167 |
primrec
|
|
168 |
"domain [] = []"
|
|
169 |
"domain (x#\<theta>) = (fst x)#(domain \<theta>)"
|
|
170 |
|
|
171 |
consts
|
|
172 |
"apply_sss" :: "(name\<times>lam) list \<Rightarrow> name \<Rightarrow> lam" (" _ < _ >" [80,80] 80)
|
|
173 |
primrec
|
|
174 |
"(x#\<theta>)<a> = (if (a = fst x) then (snd x) else \<theta><a>)"
|
|
175 |
|
|
176 |
lemma apply_sss_eqvt:
|
|
177 |
fixes pi::"name prm"
|
|
178 |
assumes a: "a\<in>set (domain \<theta>)"
|
|
179 |
shows "pi\<bullet>(\<theta><a>) = (pi\<bullet>\<theta>)<pi\<bullet>a>"
|
|
180 |
using a
|
|
181 |
by (induct \<theta>)
|
|
182 |
(auto simp add: perm_bij)
|
|
183 |
|
|
184 |
lemma domain_eqvt:
|
|
185 |
fixes pi::"name prm"
|
|
186 |
shows "((pi\<bullet>a)\<in>set (domain \<theta>)) = (a\<in>set (domain ((rev pi)\<bullet>\<theta>)))"
|
|
187 |
apply(induct \<theta>)
|
|
188 |
apply(auto)
|
|
189 |
apply(perm_simp)+
|
|
190 |
done
|
|
191 |
|
|
192 |
constdefs
|
|
193 |
psubst_Var :: "(name\<times>lam) list \<Rightarrow> name \<Rightarrow> lam"
|
|
194 |
"psubst_Var \<theta> \<equiv> \<lambda>a. (if a\<in>set (domain \<theta>) then \<theta><a> else (Var a))"
|
|
195 |
|
|
196 |
psubst_App :: "(name\<times>lam) list \<Rightarrow> lam \<Rightarrow> lam \<Rightarrow> lam \<Rightarrow> lam \<Rightarrow> lam"
|
|
197 |
"psubst_App \<theta> \<equiv> \<lambda>_ _ r1 r2. App r1 r2"
|
|
198 |
|
|
199 |
psubst_Lam :: "(name\<times>lam) list \<Rightarrow> name \<Rightarrow> lam \<Rightarrow> lam \<Rightarrow> lam"
|
|
200 |
"psubst_Lam \<theta> \<equiv> \<lambda>a _ r. Lam [a].r"
|
|
201 |
|
|
202 |
abbreviation
|
|
203 |
psubst_lam :: "lam \<Rightarrow> (name\<times>lam) list \<Rightarrow> lam" ("_[<_>]" [100,100] 900)
|
|
204 |
"t[<\<theta>>] \<equiv> (lam_rec (psubst_Var \<theta>) (psubst_App \<theta>) (psubst_Lam \<theta>)) t"
|
|
205 |
|
|
206 |
lemma fin_supp_psubst:
|
|
207 |
shows "finite ((supp (psubst_Var \<theta>))::name set)"
|
|
208 |
and "finite ((supp (psubst_Lam \<theta>))::name set)"
|
|
209 |
and "finite ((supp (psubst_App \<theta>))::name set)"
|
|
210 |
apply -
|
|
211 |
apply(finite_guess add: fs_name1 psubst_Var_def domain_eqvt apply_sss_eqvt)
|
|
212 |
apply(finite_guess add: fs_name1 psubst_Lam_def)
|
|
213 |
apply(finite_guess add: fs_name1 psubst_App_def)
|
|
214 |
done
|
|
215 |
|
|
216 |
lemma fcb_psubst_Lam:
|
|
217 |
shows "x\<sharp>(psubst_Lam \<theta>) x t r"
|
|
218 |
by (simp add: psubst_Lam_def abs_fresh)
|
|
219 |
|
|
220 |
lemma psubst[simp]:
|
|
221 |
shows "(Var a)[<\<theta>>] = (if a\<in>set (domain \<theta>) then \<theta><a> else (Var a))"
|
|
222 |
and "(App t1 t2)[<\<theta>>] = App (t1[<\<theta>>]) (t2[<\<theta>>])"
|
|
223 |
and "a\<sharp>\<theta> \<Longrightarrow> (Lam [a].t1)[<\<theta>>] = Lam [a].(t1[<\<theta>>])"
|
|
224 |
apply(rule trans)
|
|
225 |
apply(rule lam.recs[where P="\<lambda>_. True" and z="()", simplified])
|
|
226 |
apply(simp add: fin_supp_psubst fs_name1)+
|
|
227 |
apply(simp add: fcb_psubst_Lam)
|
|
228 |
apply(simp add: psubst_Var_def)
|
|
229 |
apply(rule trans)
|
|
230 |
apply(rule lam.recs[where P="\<lambda>_. True" and z="()", simplified])
|
|
231 |
apply(simp add: fin_supp_psubst fs_name1)+
|
|
232 |
apply(simp add: fcb_psubst_Lam)
|
|
233 |
apply(simp add: psubst_App_def)
|
|
234 |
apply(rule trans)
|
|
235 |
apply(rule lam.recs[where P="\<lambda>_. True" and z="()", simplified])
|
|
236 |
apply(simp add: fin_supp_psubst fs_name1)+
|
|
237 |
apply(simp add: fcb_psubst_Lam)
|
|
238 |
apply(fresh_guess add: psubst_Var_def domain_eqvt apply_sss_eqvt fs_name1)
|
|
239 |
apply(fresh_guess add: psubst_App_def fs_name1)
|
|
240 |
apply(fresh_guess add: psubst_Lam_def fs_name1)
|
|
241 |
apply(simp add: psubst_Lam_def)
|
|
242 |
done
|
|
243 |
|
|
244 |
end |