equal
deleted
inserted
replaced
5 begin |
5 begin |
6 |
6 |
7 subsection {* Terms and substitution *} |
7 subsection {* Terms and substitution *} |
8 |
8 |
9 datatype ('a, 'b) "term" = |
9 datatype ('a, 'b) "term" = |
10 Var 'a |
10 Var 'a |
11 | App 'b "('a, 'b) term list" |
11 | App 'b "('a, 'b) term list" |
12 |
12 |
13 primrec |
13 primrec subst_term :: "('a \<Rightarrow> ('a, 'b) term) \<Rightarrow> ('a, 'b) term \<Rightarrow> ('a, 'b) term" |
14 subst_term :: "('a => ('a, 'b) term) => ('a, 'b) term => ('a, 'b) term" and |
14 and subst_term_list :: "('a \<Rightarrow> ('a, 'b) term) \<Rightarrow> ('a, 'b) term list \<Rightarrow> ('a, 'b) term list" |
15 subst_term_list :: "('a => ('a, 'b) term) => ('a, 'b) term list => ('a, 'b) term list" |
|
16 where |
15 where |
17 "subst_term f (Var a) = f a" |
16 "subst_term f (Var a) = f a" |
18 | "subst_term f (App b ts) = App b (subst_term_list f ts)" |
17 | "subst_term f (App b ts) = App b (subst_term_list f ts)" |
19 | "subst_term_list f [] = []" |
18 | "subst_term_list f [] = []" |
20 | "subst_term_list f (t # ts) = subst_term f t # subst_term_list f ts" |
19 | "subst_term_list f (t # ts) = subst_term f t # subst_term_list f ts" |
22 lemmas subst_simps = subst_term_subst_term_list.simps |
21 lemmas subst_simps = subst_term_subst_term_list.simps |
23 |
22 |
24 text {* \medskip A simple lemma about composition of substitutions. *} |
23 text {* \medskip A simple lemma about composition of substitutions. *} |
25 |
24 |
26 lemma |
25 lemma |
27 "subst_term (subst_term f1 o f2) t = |
26 "subst_term (subst_term f1 \<circ> f2) t = |
28 subst_term f1 (subst_term f2 t)" |
27 subst_term f1 (subst_term f2 t)" |
29 and |
28 and |
30 "subst_term_list (subst_term f1 o f2) ts = |
29 "subst_term_list (subst_term f1 \<circ> f2) ts = |
31 subst_term_list f1 (subst_term_list f2 ts)" |
30 subst_term_list f1 (subst_term_list f2 ts)" |
32 by (induct t and ts) simp_all |
31 by (induct t and ts) simp_all |
33 |
32 |
34 lemma "subst_term (subst_term f1 o f2) t = |
33 lemma "subst_term (subst_term f1 \<circ> f2) t = |
35 subst_term f1 (subst_term f2 t)" |
34 subst_term f1 (subst_term f2 t)" |
36 proof - |
35 proof - |
37 let "?P t" = ?thesis |
36 let "?P t" = ?thesis |
38 let ?Q = "\<lambda>ts. subst_term_list (subst_term f1 o f2) ts = |
37 let ?Q = "\<lambda>ts. subst_term_list (subst_term f1 \<circ> f2) ts = |
39 subst_term_list f1 (subst_term_list f2 ts)" |
38 subst_term_list f1 (subst_term_list f2 ts)" |
40 show ?thesis |
39 show ?thesis |
41 proof (induct t) |
40 proof (induct t) |
42 fix a show "?P (Var a)" by simp |
41 fix a show "?P (Var a)" by simp |
43 next |
42 next |
55 |
54 |
56 |
55 |
57 subsection {* Alternative induction *} |
56 subsection {* Alternative induction *} |
58 |
57 |
59 theorem term_induct' [case_names Var App]: |
58 theorem term_induct' [case_names Var App]: |
60 assumes var: "!!a. P (Var a)" |
59 assumes var: "\<And>a. P (Var a)" |
61 and app: "!!b ts. (\<forall>t \<in> set ts. P t) ==> P (App b ts)" |
60 and app: "\<And>b ts. (\<forall>t \<in> set ts. P t) \<Longrightarrow> P (App b ts)" |
62 shows "P t" |
61 shows "P t" |
63 proof (induct t) |
62 proof (induct t) |
64 fix a show "P (Var a)" by (rule var) |
63 fix a show "P (Var a)" by (rule var) |
65 next |
64 next |
66 fix b t ts assume "\<forall>t \<in> set ts. P t" |
65 fix b t ts assume "\<forall>t \<in> set ts. P t" |
70 next |
69 next |
71 fix t ts assume "P t" "\<forall>t' \<in> set ts. P t'" |
70 fix t ts assume "P t" "\<forall>t' \<in> set ts. P t'" |
72 then show "\<forall>t' \<in> set (t # ts). P t'" by simp |
71 then show "\<forall>t' \<in> set (t # ts). P t'" by simp |
73 qed |
72 qed |
74 |
73 |
75 lemma |
74 lemma "subst_term (subst_term f1 \<circ> f2) t = subst_term f1 (subst_term f2 t)" |
76 "subst_term (subst_term f1 o f2) t = subst_term f1 (subst_term f2 t)" |
|
77 proof (induct t rule: term_induct') |
75 proof (induct t rule: term_induct') |
78 case (Var a) |
76 case (Var a) |
79 show ?case by (simp add: o_def) |
77 show ?case by (simp add: o_def) |
80 next |
78 next |
81 case (App b ts) |
79 case (App b ts) |