author | webertj |
Sun, 30 Jul 2006 02:06:01 +0200 | |
changeset 20255 | 5a8410198a33 |
parent 18372 | 2bffdf62fe7f |
child 24893 | b8ef7afe3a6b |
permissions | -rw-r--r-- |
12229 | 1 |
(* Title: ZF/Induct/Ntree.thy |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1994 University of Cambridge |
|
5 |
*) |
|
6 |
||
7 |
header {* Datatype definition n-ary branching trees *} |
|
8 |
||
16417 | 9 |
theory Ntree imports Main begin |
12229 | 10 |
|
11 |
text {* |
|
12 |
Demonstrates a simple use of function space in a datatype |
|
13 |
definition. Based upon theory @{text Term}. |
|
14 |
*} |
|
15 |
||
16 |
consts |
|
17 |
ntree :: "i => i" |
|
18 |
maptree :: "i => i" |
|
19 |
maptree2 :: "[i, i] => i" |
|
20 |
||
21 |
datatype "ntree(A)" = Branch ("a \<in> A", "h \<in> (\<Union>n \<in> nat. n -> ntree(A))") |
|
22 |
monos UN_mono [OF subset_refl Pi_mono] -- {* MUST have this form *} |
|
23 |
type_intros nat_fun_univ [THEN subsetD] |
|
24 |
type_elims UN_E |
|
25 |
||
26 |
datatype "maptree(A)" = Sons ("a \<in> A", "h \<in> maptree(A) -||> maptree(A)") |
|
27 |
monos FiniteFun_mono1 -- {* Use monotonicity in BOTH args *} |
|
28 |
type_intros FiniteFun_univ1 [THEN subsetD] |
|
29 |
||
30 |
datatype "maptree2(A, B)" = Sons2 ("a \<in> A", "h \<in> B -||> maptree2(A, B)") |
|
31 |
monos FiniteFun_mono [OF subset_refl] |
|
32 |
type_intros FiniteFun_in_univ' |
|
33 |
||
34 |
constdefs |
|
35 |
ntree_rec :: "[[i, i, i] => i, i] => i" |
|
36 |
"ntree_rec(b) == |
|
12610 | 37 |
Vrecursor(\<lambda>pr. ntree_case(\<lambda>x h. b(x, h, \<lambda>i \<in> domain(h). pr`(h`i))))" |
12229 | 38 |
|
39 |
constdefs |
|
40 |
ntree_copy :: "i => i" |
|
12610 | 41 |
"ntree_copy(z) == ntree_rec(\<lambda>x h r. Branch(x,r), z)" |
12229 | 42 |
|
43 |
||
44 |
text {* |
|
45 |
\medskip @{text ntree} |
|
46 |
*} |
|
47 |
||
48 |
lemma ntree_unfold: "ntree(A) = A \<times> (\<Union>n \<in> nat. n -> ntree(A))" |
|
12788 | 49 |
by (blast intro: ntree.intros [unfolded ntree.con_defs] |
12229 | 50 |
elim: ntree.cases [unfolded ntree.con_defs]) |
51 |
||
18372 | 52 |
lemma ntree_induct [consumes 1, case_names Branch, induct set: ntree]: |
53 |
assumes t: "t \<in> ntree(A)" |
|
54 |
and step: "!!x n h. [| x \<in> A; n \<in> nat; h \<in> n -> ntree(A); \<forall>i \<in> n. P(h`i) |
|
55 |
|] ==> P(Branch(x,h))" |
|
56 |
shows "P(t)" |
|
12229 | 57 |
-- {* A nicer induction rule than the standard one. *} |
18372 | 58 |
using t |
59 |
apply induct |
|
60 |
apply (erule UN_E) |
|
61 |
apply (assumption | rule step)+ |
|
62 |
apply (fast elim: fun_weaken_type) |
|
63 |
apply (fast dest: apply_type) |
|
64 |
done |
|
12229 | 65 |
|
18372 | 66 |
lemma ntree_induct_eqn [consumes 1]: |
67 |
assumes t: "t \<in> ntree(A)" |
|
68 |
and f: "f \<in> ntree(A)->B" |
|
69 |
and g: "g \<in> ntree(A)->B" |
|
70 |
and step: "!!x n h. [| x \<in> A; n \<in> nat; h \<in> n -> ntree(A); f O h = g O h |] ==> |
|
71 |
f ` Branch(x,h) = g ` Branch(x,h)" |
|
72 |
shows "f`t=g`t" |
|
12229 | 73 |
-- {* Induction on @{term "ntree(A)"} to prove an equation *} |
18372 | 74 |
using t |
75 |
apply induct |
|
76 |
apply (assumption | rule step)+ |
|
77 |
apply (insert f g) |
|
78 |
apply (rule fun_extension) |
|
79 |
apply (assumption | rule comp_fun)+ |
|
80 |
apply (simp add: comp_fun_apply) |
|
12229 | 81 |
done |
82 |
||
83 |
text {* |
|
84 |
\medskip Lemmas to justify using @{text Ntree} in other recursive |
|
85 |
type definitions. |
|
86 |
*} |
|
87 |
||
88 |
lemma ntree_mono: "A \<subseteq> B ==> ntree(A) \<subseteq> ntree(B)" |
|
89 |
apply (unfold ntree.defs) |
|
90 |
apply (rule lfp_mono) |
|
91 |
apply (rule ntree.bnd_mono)+ |
|
92 |
apply (assumption | rule univ_mono basic_monos)+ |
|
93 |
done |
|
94 |
||
95 |
lemma ntree_univ: "ntree(univ(A)) \<subseteq> univ(A)" |
|
96 |
-- {* Easily provable by induction also *} |
|
97 |
apply (unfold ntree.defs ntree.con_defs) |
|
98 |
apply (rule lfp_lowerbound) |
|
99 |
apply (rule_tac [2] A_subset_univ [THEN univ_mono]) |
|
100 |
apply (blast intro: Pair_in_univ nat_fun_univ [THEN subsetD]) |
|
101 |
done |
|
102 |
||
103 |
lemma ntree_subset_univ: "A \<subseteq> univ(B) ==> ntree(A) \<subseteq> univ(B)" |
|
104 |
by (rule subset_trans [OF ntree_mono ntree_univ]) |
|
105 |
||
106 |
||
107 |
text {* |
|
108 |
\medskip @{text ntree} recursion. |
|
109 |
*} |
|
110 |
||
13175
81082cfa5618
new definition of "apply" and new simprule "beta_if"
paulson
parents:
12788
diff
changeset
|
111 |
lemma ntree_rec_Branch: |
81082cfa5618
new definition of "apply" and new simprule "beta_if"
paulson
parents:
12788
diff
changeset
|
112 |
"function(h) ==> |
81082cfa5618
new definition of "apply" and new simprule "beta_if"
paulson
parents:
12788
diff
changeset
|
113 |
ntree_rec(b, Branch(x,h)) = b(x, h, \<lambda>i \<in> domain(h). ntree_rec(b, h`i))" |
12229 | 114 |
apply (rule ntree_rec_def [THEN def_Vrecursor, THEN trans]) |
115 |
apply (simp add: ntree.con_defs rank_pair2 [THEN [2] lt_trans] rank_apply) |
|
116 |
done |
|
117 |
||
118 |
lemma ntree_copy_Branch [simp]: |
|
13175
81082cfa5618
new definition of "apply" and new simprule "beta_if"
paulson
parents:
12788
diff
changeset
|
119 |
"function(h) ==> |
81082cfa5618
new definition of "apply" and new simprule "beta_if"
paulson
parents:
12788
diff
changeset
|
120 |
ntree_copy (Branch(x, h)) = Branch(x, \<lambda>i \<in> domain(h). ntree_copy (h`i))" |
81082cfa5618
new definition of "apply" and new simprule "beta_if"
paulson
parents:
12788
diff
changeset
|
121 |
by (simp add: ntree_copy_def ntree_rec_Branch) |
12229 | 122 |
|
123 |
lemma ntree_copy_is_ident: "z \<in> ntree(A) ==> ntree_copy(z) = z" |
|
18372 | 124 |
by (induct z set: ntree) |
125 |
(auto simp add: domain_of_fun Pi_Collect_iff fun_is_function) |
|
12229 | 126 |
|
127 |
||
128 |
text {* |
|
129 |
\medskip @{text maptree} |
|
130 |
*} |
|
131 |
||
132 |
lemma maptree_unfold: "maptree(A) = A \<times> (maptree(A) -||> maptree(A))" |
|
133 |
by (fast intro!: maptree.intros [unfolded maptree.con_defs] |
|
134 |
elim: maptree.cases [unfolded maptree.con_defs]) |
|
135 |
||
18372 | 136 |
lemma maptree_induct [consumes 1, induct set: maptree]: |
137 |
assumes t: "t \<in> maptree(A)" |
|
138 |
and step: "!!x n h. [| x \<in> A; h \<in> maptree(A) -||> maptree(A); |
|
12229 | 139 |
\<forall>y \<in> field(h). P(y) |
18372 | 140 |
|] ==> P(Sons(x,h))" |
141 |
shows "P(t)" |
|
12229 | 142 |
-- {* A nicer induction rule than the standard one. *} |
18372 | 143 |
using t |
144 |
apply induct |
|
145 |
apply (assumption | rule step)+ |
|
146 |
apply (erule Collect_subset [THEN FiniteFun_mono1, THEN subsetD]) |
|
147 |
apply (drule FiniteFun.dom_subset [THEN subsetD]) |
|
148 |
apply (drule Fin.dom_subset [THEN subsetD]) |
|
149 |
apply fast |
|
150 |
done |
|
12229 | 151 |
|
152 |
||
153 |
text {* |
|
154 |
\medskip @{text maptree2} |
|
155 |
*} |
|
156 |
||
157 |
lemma maptree2_unfold: "maptree2(A, B) = A \<times> (B -||> maptree2(A, B))" |
|
158 |
by (fast intro!: maptree2.intros [unfolded maptree2.con_defs] |
|
159 |
elim: maptree2.cases [unfolded maptree2.con_defs]) |
|
160 |
||
18372 | 161 |
lemma maptree2_induct [consumes 1, induct set: maptree2]: |
162 |
assumes t: "t \<in> maptree2(A, B)" |
|
163 |
and step: "!!x n h. [| x \<in> A; h \<in> B -||> maptree2(A,B); \<forall>y \<in> range(h). P(y) |
|
164 |
|] ==> P(Sons2(x,h))" |
|
165 |
shows "P(t)" |
|
166 |
using t |
|
167 |
apply induct |
|
168 |
apply (assumption | rule step)+ |
|
169 |
apply (erule FiniteFun_mono [OF subset_refl Collect_subset, THEN subsetD]) |
|
170 |
apply (drule FiniteFun.dom_subset [THEN subsetD]) |
|
171 |
apply (drule Fin.dom_subset [THEN subsetD]) |
|
172 |
apply fast |
|
173 |
done |
|
12229 | 174 |
|
175 |
end |