58882
|
1 |
section \<open>Nested datatypes\<close>
|
8676
|
2 |
|
31758
|
3 |
theory Nested_Datatype
|
|
4 |
imports Main
|
|
5 |
begin
|
8676
|
6 |
|
58614
|
7 |
subsection \<open>Terms and substitution\<close>
|
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 |
|
61541
|
23 |
text \<open>\<^medskip> A simple lemma about composition of substitutions.\<close>
|
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)
|
60416
|
40 |
show "?P (Var a)" for a by simp
|
|
41 |
show "?P (App b ts)" if "?Q ts" for b ts
|
60449
|
42 |
using that by (simp only: subst_simps)
|
10007
|
43 |
show "?Q []" by simp
|
60416
|
44 |
show "?Q (t # ts)" if "?P t" "?Q ts" for t ts
|
60449
|
45 |
using that by (simp only: subst_simps)
|
10007
|
46 |
qed
|
|
47 |
qed
|
8676
|
48 |
|
|
49 |
|
58614
|
50 |
subsection \<open>Alternative induction\<close>
|
8676
|
51 |
|
55656
|
52 |
lemma "subst_term (subst_term f1 \<circ> f2) t = subst_term f1 (subst_term f2 t)"
|
58260
|
53 |
proof (induct t rule: term.induct)
|
11809
|
54 |
case (Var a)
|
18153
|
55 |
show ?case by (simp add: o_def)
|
10007
|
56 |
next
|
11809
|
57 |
case (App b ts)
|
23373
|
58 |
then show ?case by (induct ts) simp_all
|
10007
|
59 |
qed
|
8676
|
60 |
|
10007
|
61 |
end
|