10007
|
1 |
header {* Nested datatypes *}
|
8676
|
2 |
|
31758
|
3 |
theory Nested_Datatype
|
|
4 |
imports Main
|
|
5 |
begin
|
8676
|
6 |
|
10007
|
7 |
subsection {* Terms and substitution *}
|
8676
|
8 |
|
58310
|
9 |
datatype ('a, 'b) "term" =
|
55656
|
10 |
Var 'a
|
|
11 |
| App 'b "('a, 'b) term list"
|
8676
|
12 |
|
55656
|
13 |
primrec subst_term :: "('a \<Rightarrow> ('a, 'b) term) \<Rightarrow> ('a, 'b) term \<Rightarrow> ('a, 'b) term"
|
|
14 |
and subst_term_list :: "('a \<Rightarrow> ('a, 'b) term) \<Rightarrow> ('a, 'b) term list \<Rightarrow> ('a, 'b) term list"
|
37671
|
15 |
where
|
37597
|
16 |
"subst_term f (Var a) = f a"
|
|
17 |
| "subst_term f (App b ts) = App b (subst_term_list f ts)"
|
|
18 |
| "subst_term_list f [] = []"
|
|
19 |
| "subst_term_list f (t # ts) = subst_term f t # subst_term_list f ts"
|
8676
|
20 |
|
58260
|
21 |
lemmas subst_simps = subst_term.simps subst_term_list.simps
|
8676
|
22 |
|
37671
|
23 |
text {* \medskip A simple lemma about composition of substitutions. *}
|
8676
|
24 |
|
37671
|
25 |
lemma
|
55656
|
26 |
"subst_term (subst_term f1 \<circ> f2) t =
|
37671
|
27 |
subst_term f1 (subst_term f2 t)"
|
|
28 |
and
|
55656
|
29 |
"subst_term_list (subst_term f1 \<circ> f2) ts =
|
37671
|
30 |
subst_term_list f1 (subst_term_list f2 ts)"
|
58260
|
31 |
by (induct t and ts rule: subst_term.induct subst_term_list.induct) simp_all
|
8676
|
32 |
|
58260
|
33 |
lemma "subst_term (subst_term f1 \<circ> f2) t = subst_term f1 (subst_term f2 t)"
|
10007
|
34 |
proof -
|
|
35 |
let "?P t" = ?thesis
|
55656
|
36 |
let ?Q = "\<lambda>ts. subst_term_list (subst_term f1 \<circ> f2) ts =
|
10007
|
37 |
subst_term_list f1 (subst_term_list f2 ts)"
|
|
38 |
show ?thesis
|
58260
|
39 |
proof (induct t rule: subst_term.induct)
|
10007
|
40 |
fix a show "?P (Var a)" by simp
|
|
41 |
next
|
|
42 |
fix b ts assume "?Q ts"
|
23373
|
43 |
then show "?P (App b ts)"
|
37597
|
44 |
by (simp only: subst_simps)
|
10007
|
45 |
next
|
|
46 |
show "?Q []" by simp
|
|
47 |
next
|
|
48 |
fix t ts
|
23373
|
49 |
assume "?P t" "?Q ts" then show "?Q (t # ts)"
|
37597
|
50 |
by (simp only: subst_simps)
|
10007
|
51 |
qed
|
|
52 |
qed
|
8676
|
53 |
|
|
54 |
|
10007
|
55 |
subsection {* Alternative induction *}
|
8676
|
56 |
|
55656
|
57 |
lemma "subst_term (subst_term f1 \<circ> f2) t = subst_term f1 (subst_term f2 t)"
|
58260
|
58 |
proof (induct t rule: term.induct)
|
11809
|
59 |
case (Var a)
|
18153
|
60 |
show ?case by (simp add: o_def)
|
10007
|
61 |
next
|
11809
|
62 |
case (App b ts)
|
23373
|
63 |
then show ?case by (induct ts) simp_all
|
10007
|
64 |
qed
|
8676
|
65 |
|
10007
|
66 |
end
|