151 done |
151 done |
152 |
152 |
153 lemma Lam_beta: "A \<longrightarrow>b* B \<Longrightarrow> Lam [x]. A \<longrightarrow>b* Lam [x]. B" |
153 lemma Lam_beta: "A \<longrightarrow>b* B \<Longrightarrow> Lam [x]. A \<longrightarrow>b* Lam [x]. B" |
154 by (erule beta_star.induct) auto |
154 by (erule beta_star.induct) auto |
155 |
155 |
|
156 lemma Lam_rsp: "A \<approx> B \<Longrightarrow> Lam [x]. A \<approx> Lam [x]. B" |
|
157 unfolding equ_def |
|
158 apply auto |
|
159 apply (rule_tac x="Lam [x]. r" in exI) |
|
160 apply (auto simp add: Lam_beta) |
|
161 done |
|
162 |
156 lemma [quot_respect]: |
163 lemma [quot_respect]: |
157 shows "(op = ===> equ) Var Var" |
164 shows "(op = ===> equ) Var Var" |
158 and "(equ ===> equ ===> equ) App App" |
165 and "(equ ===> equ ===> equ) App App" |
159 and "(op = ===> equ ===> equ) BetaCR.Lam BetaCR.Lam" |
166 and "(op = ===> equ ===> equ) BetaCR.Lam BetaCR.Lam" |
160 unfolding fun_rel_def equ_def |
167 unfolding fun_rel_def equ_def |
219 done |
226 done |
220 |
227 |
221 lemma beta_subst: "A \<longrightarrow>b* B \<Longrightarrow> C \<longrightarrow>b* D \<Longrightarrow> A [x ::= C] \<longrightarrow>b* B [x ::= D]" |
228 lemma beta_subst: "A \<longrightarrow>b* B \<Longrightarrow> C \<longrightarrow>b* D \<Longrightarrow> A [x ::= C] \<longrightarrow>b* B [x ::= D]" |
222 using beta_subst1 beta_subst2 beta_star_trans by metis |
229 using beta_subst1 beta_subst2 beta_star_trans by metis |
223 |
230 |
|
231 lemma subst_rsp_pre: |
|
232 "x \<approx> y \<Longrightarrow> xb \<approx> ya \<Longrightarrow> x [xa ::= xb] \<approx> y [xa ::= ya]" |
|
233 unfolding equ_def |
|
234 apply auto |
|
235 apply (rule_tac x="r [xa ::= ra]" in exI) |
|
236 apply (simp add: beta_subst) |
|
237 done |
|
238 |
224 lemma [quot_respect]: |
239 lemma [quot_respect]: |
225 shows "(equ ===> op = ===> equ ===> equ) subst subst" |
240 shows "(equ ===> op = ===> equ ===> equ) subst subst" |
226 unfolding fun_rel_def equ_def |
241 unfolding fun_rel_def by (auto simp add: subst_rsp_pre) |
227 apply auto |
|
228 apply (rule_tac x="r [xa ::= ra]" in exI) |
|
229 apply (simp add: beta_subst) |
|
230 done |
|
231 |
242 |
232 lemma [quot_respect]: |
243 lemma [quot_respect]: |
233 shows "(op = ===> equ ===> equ) permute permute" |
244 shows "(op = ===> equ ===> equ) permute permute" |
234 unfolding fun_rel_def equ_def |
245 unfolding fun_rel_def equ_def |
235 apply (auto intro: eqvts) |
246 apply (auto intro: eqvts) |
305 end |
316 end |
306 |
317 |
307 quotient_definition subst_qlam ("_[_ ::q= _]") |
318 quotient_definition subst_qlam ("_[_ ::q= _]") |
308 where "subst_qlam::qlam \<Rightarrow> name \<Rightarrow> qlam \<Rightarrow> qlam" is subst |
319 where "subst_qlam::qlam \<Rightarrow> name \<Rightarrow> qlam \<Rightarrow> qlam" is subst |
309 |
320 |
310 lemmas qsubst = subst.simps(1-2)[quot_lifted] |
|
311 |
|
312 definition |
321 definition |
313 "Supp t = \<Inter>{supp s | s. s \<approx> t}" |
322 "Supp t = \<Inter>{supp s | s. s \<approx> t}" |
314 |
323 |
315 lemma [quot_respect]: |
324 lemma Supp_rsp: |
316 shows "(equ ===> op=) Supp Supp" |
325 "a \<approx> b \<Longrightarrow> Supp a = Supp b" |
317 unfolding fun_rel_def Supp_def |
326 unfolding Supp_def |
318 apply(intro allI impI) |
|
319 apply(rule_tac f="Inter" in arg_cong) |
327 apply(rule_tac f="Inter" in arg_cong) |
320 apply(auto) |
328 apply(auto) |
321 apply (metis equ_trans) |
329 apply (metis equ_trans) |
322 by (metis equivp_def qlam_equivp) |
330 by (metis equivp_def qlam_equivp) |
|
331 |
|
332 lemma [quot_respect]: |
|
333 shows "(equ ===> op=) Supp Supp" |
|
334 unfolding fun_rel_def by (auto simp add: Supp_rsp) |
323 |
335 |
324 quotient_definition "supp_qlam::qlam \<Rightarrow> atom set" |
336 quotient_definition "supp_qlam::qlam \<Rightarrow> atom set" |
325 is "Supp::lam \<Rightarrow> atom set" |
337 is "Supp::lam \<Rightarrow> atom set" |
326 |
338 |
327 lemma Supp_supp: |
339 lemma Supp_supp: |
329 unfolding Supp_def |
341 unfolding Supp_def |
330 apply(auto) |
342 apply(auto) |
331 apply(drule_tac x="supp t" in spec) |
343 apply(drule_tac x="supp t" in spec) |
332 apply(auto simp add: equ_refl) |
344 apply(auto simp add: equ_refl) |
333 done |
345 done |
|
346 |
|
347 lemma supp_subst: |
|
348 shows "supp (t[x ::= s]) \<subseteq> (supp t - {atom x}) \<union> supp s" |
|
349 by (induct t x s rule: subst.induct) (auto simp add: lam.supp supp_at_base) |
|
350 |
|
351 lemma supp_beta: "x \<longrightarrow>b r \<Longrightarrow> supp r \<subseteq> supp x" |
|
352 apply (induct rule: beta.induct) |
|
353 apply (simp_all add: lam.supp) |
|
354 apply blast+ |
|
355 using supp_subst by blast |
|
356 |
|
357 lemma supp_beta_star: "x \<longrightarrow>b* r \<Longrightarrow> supp r \<subseteq> supp x" |
|
358 apply (erule beta_star.induct) |
|
359 apply auto |
|
360 using supp_beta by blast |
|
361 |
|
362 lemma supp_equ: "x \<approx> y \<Longrightarrow> \<exists>z. z \<approx> x \<and> supp z \<subseteq> supp x \<inter> supp y" |
|
363 unfolding equ_def |
|
364 apply (simp (no_asm) only: equ_def[symmetric]) |
|
365 apply (elim exE) |
|
366 apply (rule_tac x=r in exI) |
|
367 apply rule |
|
368 apply (metis bs1 equ_def) |
|
369 using supp_beta_star by blast |
|
370 |
|
371 lemma supp_psubset: "Supp x \<subset> supp x \<Longrightarrow> \<exists>t. t \<approx> x \<and> supp t \<subset> supp x" |
|
372 proof - |
|
373 assume "Supp x \<subset> supp x" |
|
374 then obtain a where "a \<in> supp x" "a \<notin> Supp x" by blast |
|
375 then obtain y where nin: "y \<approx> x" "a \<notin> supp y" unfolding Supp_def by blast |
|
376 then obtain t where eq: "t \<approx> x" "supp t \<subseteq> supp x \<inter> supp y" |
|
377 using supp_equ equ_sym by blast |
|
378 then have "supp t \<subset> supp x" using nin |
|
379 by (metis `(a\<Colon>atom) \<in> supp (x\<Colon>lam)` le_infE psubset_eq set_rev_mp) |
|
380 then show "\<exists>t. t \<approx> x \<and> supp t \<subset> supp x" using eq by blast |
|
381 qed |
|
382 |
|
383 lemma Supp_exists: "\<exists>t. supp t = Supp t \<and> t \<approx> x" |
|
384 proof - |
|
385 have "\<And>fs x. supp x = fs \<Longrightarrow> \<exists>t. supp t = Supp t \<and> t \<approx> x" |
|
386 proof - |
|
387 fix fs |
|
388 show "\<And>x. supp x = fs \<Longrightarrow> \<exists>t\<Colon>lam. supp t = Supp t \<and> t \<approx> x" |
|
389 proof (cases "finite fs") |
|
390 case True |
|
391 assume fs: "finite fs" |
|
392 then show "\<And>x. supp x = fs \<Longrightarrow> \<exists>t\<Colon>lam. supp t = Supp t \<and> t \<approx> x" |
|
393 proof (induct fs rule: finite_psubset_induct, clarify) |
|
394 fix A :: "atom set" fix x :: lam |
|
395 assume IH: "\<And>B xa. \<lbrakk>B \<subset> supp x; supp xa = B\<rbrakk> \<Longrightarrow> \<exists>t\<Colon>lam. supp t = Supp t \<and> t \<approx> xa" |
|
396 show "\<exists>t\<Colon>lam. supp t = Supp t \<and> t \<approx> x" |
|
397 proof (cases "supp x = Supp x") |
|
398 assume "supp x = Supp x" |
|
399 then show "\<exists>t\<Colon>lam. supp t = Supp t \<and> t \<approx> x" |
|
400 by (rule_tac x="x" in exI) (simp add: equ_refl) |
|
401 next |
|
402 assume "supp x \<noteq> Supp x" |
|
403 then have "Supp x \<subset> supp x" using Supp_supp by blast |
|
404 then obtain y where a1: "supp y \<subset> supp x" "y \<approx> x" |
|
405 using supp_psubset by blast |
|
406 then obtain t where "supp t = Supp t \<and> t \<approx> y" |
|
407 using IH[of "supp y" y] by blast |
|
408 then show "\<exists>t\<Colon>lam. supp t = Supp t \<and> t \<approx> x" using a1 equ_trans |
|
409 by blast |
|
410 qed |
|
411 qed |
|
412 next |
|
413 case False |
|
414 fix x :: lam |
|
415 assume "supp x = fs" "infinite fs" |
|
416 then show "\<exists>t\<Colon>lam. supp t = Supp t \<and> t \<approx> x" |
|
417 by (auto simp add: finite_supp) |
|
418 qed simp |
|
419 qed |
|
420 then show "\<exists>t\<Colon>lam. supp t = Supp t \<and> t \<approx> x" by blast |
|
421 qed |
|
422 |
|
423 lemma subst3: "x \<noteq> y \<and> atom x \<notin> Supp s \<Longrightarrow> Lam [x]. t [y ::= s] \<approx> Lam [x]. (t [y ::= s])" |
|
424 proof - |
|
425 assume as: "x \<noteq> y \<and> atom x \<notin> Supp s" |
|
426 obtain s' where s: "supp s' = Supp s'" "s' \<approx> s" using Supp_exists[of s] by blast |
|
427 then have lhs: "Lam [x]. t [y ::= s] \<approx> Lam [x]. t [y ::= s']" using subst_rsp_pre equ_refl equ_sym by blast |
|
428 have supp: "Supp s' = Supp s" using Supp_rsp s(2) by blast |
|
429 have lhs_rhs: "Lam [x]. t [y ::= s'] = Lam [x]. (t [y ::= s'])" |
|
430 by (simp add: fresh_def supp_Pair s supp as supp_at_base) |
|
431 have "t [y ::= s'] \<approx> t [y ::= s]" |
|
432 using subst_rsp_pre[OF equ_refl s(2)] . |
|
433 with Lam_rsp have rhs: "Lam [x]. (t [y ::= s']) \<approx> Lam [x]. (t [y ::= s])" . |
|
434 show ?thesis |
|
435 using lhs[unfolded lhs_rhs] rhs equ_trans by blast |
|
436 qed |
|
437 |
|
438 thm subst3[quot_lifted] |
334 |
439 |
335 lemma Supp_Lam: |
440 lemma Supp_Lam: |
336 "atom a \<notin> Supp (Lam [a].t)" |
441 "atom a \<notin> Supp (Lam [a].t)" |
337 proof - |
442 proof - |
338 have "atom a \<notin> supp (Lam [a].t)" by (simp add: lam.supp) |
443 have "atom a \<notin> supp (Lam [a].t)" by (simp add: lam.supp) |