equal
deleted
inserted
replaced
63 apply (induct_tac t) |
63 apply (induct_tac t) |
64 apply simp_all |
64 apply simp_all |
65 done |
65 done |
66 |
66 |
67 |
67 |
68 subsection {* Number of nodes *} |
68 subsection {* Number of nodes, with an example of tail-recursion *} |
69 |
69 |
70 consts |
70 consts n_nodes :: "i => i" |
71 n_nodes :: "i => i" |
|
72 primrec |
71 primrec |
73 "n_nodes(Lf) = 0" |
72 "n_nodes(Lf) = 0" |
74 "n_nodes(Br(a, l, r)) = succ(n_nodes(l) #+ n_nodes(r))" |
73 "n_nodes(Br(a, l, r)) = succ(n_nodes(l) #+ n_nodes(r))" |
75 |
74 |
76 lemma n_nodes_type [simp]: "t \<in> bt(A) ==> n_nodes(t) \<in> nat" |
75 lemma n_nodes_type [simp]: "t \<in> bt(A) ==> n_nodes(t) \<in> nat" |
77 by (induct_tac t) auto |
76 by (induct_tac t) auto |
|
77 |
|
78 consts n_nodes_aux :: "i => i" |
|
79 primrec |
|
80 "n_nodes_aux(Lf) = (\<lambda>k \<in> nat. k)" |
|
81 "n_nodes_aux(Br(a, l, r)) = |
|
82 (\<lambda>k \<in> nat. n_nodes_aux(r) ` (n_nodes_aux(l) ` succ(k)))" |
|
83 |
|
84 lemma n_nodes_aux_eq [rule_format]: |
|
85 "t \<in> bt(A) ==> \<forall>k \<in> nat. n_nodes_aux(t)`k = n_nodes(t) #+ k" |
|
86 by (induct_tac t, simp_all) |
|
87 |
|
88 constdefs |
|
89 n_nodes_tail :: "i => i" |
|
90 "n_nodes_tail(t) == n_nodes_aux(t) ` 0" |
|
91 |
|
92 lemma "t \<in> bt(A) ==> n_nodes_tail(t) = n_nodes(t)" |
|
93 by (simp add: n_nodes_tail_def n_nodes_aux_eq) |
78 |
94 |
79 |
95 |
80 subsection {* Number of leaves *} |
96 subsection {* Number of leaves *} |
81 |
97 |
82 consts |
98 consts |