author | paulson |
Fri, 29 Oct 2004 15:16:02 +0200 | |
changeset 15270 | 8b3f707a78a7 |
parent 14883 | ca000a495448 |
child 16417 | 9bc16273c2d4 |
permissions | -rw-r--r-- |
1478 | 1 |
(* Title: ZF/Finite.thy |
516 | 2 |
ID: $Id$ |
1478 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
516 | 4 |
Copyright 1994 University of Cambridge |
5 |
||
13194 | 6 |
prove: b: Fin(A) ==> inj(b,b) <= surj(b,b) |
516 | 7 |
*) |
8 |
||
13328 | 9 |
header{*Finite Powerset Operator and Finite Function Space*} |
10 |
||
13194 | 11 |
theory Finite = Inductive + Epsilon + Nat: |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6053
diff
changeset
|
12 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6053
diff
changeset
|
13 |
(*The natural numbers as a datatype*) |
13194 | 14 |
rep_datatype |
15 |
elimination natE |
|
16 |
induction nat_induct |
|
17 |
case_eqns nat_case_0 nat_case_succ |
|
18 |
recursor_eqns recursor_0 recursor_succ |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6053
diff
changeset
|
19 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6053
diff
changeset
|
20 |
|
534 | 21 |
consts |
13194 | 22 |
Fin :: "i=>i" |
23 |
FiniteFun :: "[i,i]=>i" ("(_ -||>/ _)" [61, 60] 60) |
|
534 | 24 |
|
516 | 25 |
inductive |
26 |
domains "Fin(A)" <= "Pow(A)" |
|
13194 | 27 |
intros |
28 |
emptyI: "0 : Fin(A)" |
|
29 |
consI: "[| a: A; b: Fin(A) |] ==> cons(a,b) : Fin(A)" |
|
30 |
type_intros empty_subsetI cons_subsetI PowI |
|
31 |
type_elims PowD [THEN revcut_rl] |
|
534 | 32 |
|
33 |
inductive |
|
34 |
domains "FiniteFun(A,B)" <= "Fin(A*B)" |
|
13194 | 35 |
intros |
36 |
emptyI: "0 : A -||> B" |
|
37 |
consI: "[| a: A; b: B; h: A -||> B; a ~: domain(h) |] |
|
38 |
==> cons(<a,b>,h) : A -||> B" |
|
39 |
type_intros Fin.intros |
|
40 |
||
41 |
||
13356 | 42 |
subsection {* Finite Powerset Operator *} |
13194 | 43 |
|
44 |
lemma Fin_mono: "A<=B ==> Fin(A) <= Fin(B)" |
|
45 |
apply (unfold Fin.defs) |
|
46 |
apply (rule lfp_mono) |
|
47 |
apply (rule Fin.bnd_mono)+ |
|
48 |
apply blast |
|
49 |
done |
|
50 |
||
51 |
(* A : Fin(B) ==> A <= B *) |
|
52 |
lemmas FinD = Fin.dom_subset [THEN subsetD, THEN PowD, standard] |
|
53 |
||
54 |
(** Induction on finite sets **) |
|
55 |
||
56 |
(*Discharging x~:y entails extra work*) |
|
13524 | 57 |
lemma Fin_induct [case_names 0 cons, induct set: Fin]: |
13194 | 58 |
"[| b: Fin(A); |
59 |
P(0); |
|
60 |
!!x y. [| x: A; y: Fin(A); x~:y; P(y) |] ==> P(cons(x,y)) |
|
61 |
|] ==> P(b)" |
|
62 |
apply (erule Fin.induct, simp) |
|
63 |
apply (case_tac "a:b") |
|
64 |
apply (erule cons_absorb [THEN ssubst], assumption) (*backtracking!*) |
|
65 |
apply simp |
|
66 |
done |
|
67 |
||
13203
fac77a839aa2
Tidying up. Mainly moving proofs from Main.thy to other (Isar) theory files.
paulson
parents:
13194
diff
changeset
|
68 |
|
13194 | 69 |
(** Simplification for Fin **) |
70 |
declare Fin.intros [simp] |
|
71 |
||
13203
fac77a839aa2
Tidying up. Mainly moving proofs from Main.thy to other (Isar) theory files.
paulson
parents:
13194
diff
changeset
|
72 |
lemma Fin_0: "Fin(0) = {0}" |
fac77a839aa2
Tidying up. Mainly moving proofs from Main.thy to other (Isar) theory files.
paulson
parents:
13194
diff
changeset
|
73 |
by (blast intro: Fin.emptyI dest: FinD) |
fac77a839aa2
Tidying up. Mainly moving proofs from Main.thy to other (Isar) theory files.
paulson
parents:
13194
diff
changeset
|
74 |
|
13194 | 75 |
(*The union of two finite sets is finite.*) |
13203
fac77a839aa2
Tidying up. Mainly moving proofs from Main.thy to other (Isar) theory files.
paulson
parents:
13194
diff
changeset
|
76 |
lemma Fin_UnI [simp]: "[| b: Fin(A); c: Fin(A) |] ==> b Un c : Fin(A)" |
13194 | 77 |
apply (erule Fin_induct) |
78 |
apply (simp_all add: Un_cons) |
|
79 |
done |
|
80 |
||
81 |
||
82 |
(*The union of a set of finite sets is finite.*) |
|
83 |
lemma Fin_UnionI: "C : Fin(Fin(A)) ==> Union(C) : Fin(A)" |
|
84 |
by (erule Fin_induct, simp_all) |
|
85 |
||
86 |
(*Every subset of a finite set is finite.*) |
|
87 |
lemma Fin_subset_lemma [rule_format]: "b: Fin(A) ==> \<forall>z. z<=b --> z: Fin(A)" |
|
88 |
apply (erule Fin_induct) |
|
89 |
apply (simp add: subset_empty_iff) |
|
90 |
apply (simp add: subset_cons_iff distrib_simps, safe) |
|
13784 | 91 |
apply (erule_tac b = z in cons_Diff [THEN subst], simp) |
13194 | 92 |
done |
93 |
||
94 |
lemma Fin_subset: "[| c<=b; b: Fin(A) |] ==> c: Fin(A)" |
|
95 |
by (blast intro: Fin_subset_lemma) |
|
96 |
||
97 |
lemma Fin_IntI1 [intro,simp]: "b: Fin(A) ==> b Int c : Fin(A)" |
|
98 |
by (blast intro: Fin_subset) |
|
99 |
||
100 |
lemma Fin_IntI2 [intro,simp]: "c: Fin(A) ==> b Int c : Fin(A)" |
|
101 |
by (blast intro: Fin_subset) |
|
102 |
||
103 |
lemma Fin_0_induct_lemma [rule_format]: |
|
104 |
"[| c: Fin(A); b: Fin(A); P(b); |
|
105 |
!!x y. [| x: A; y: Fin(A); x:y; P(y) |] ==> P(y-{x}) |
|
106 |
|] ==> c<=b --> P(b-c)" |
|
107 |
apply (erule Fin_induct, simp) |
|
108 |
apply (subst Diff_cons) |
|
109 |
apply (simp add: cons_subset_iff Diff_subset [THEN Fin_subset]) |
|
110 |
done |
|
111 |
||
112 |
lemma Fin_0_induct: |
|
113 |
"[| b: Fin(A); |
|
114 |
P(b); |
|
115 |
!!x y. [| x: A; y: Fin(A); x:y; P(y) |] ==> P(y-{x}) |
|
116 |
|] ==> P(0)" |
|
117 |
apply (rule Diff_cancel [THEN subst]) |
|
118 |
apply (blast intro: Fin_0_induct_lemma) |
|
119 |
done |
|
120 |
||
121 |
(*Functions from a finite ordinal*) |
|
122 |
lemma nat_fun_subset_Fin: "n: nat ==> n->A <= Fin(nat*A)" |
|
123 |
apply (induct_tac "n") |
|
124 |
apply (simp add: subset_iff) |
|
125 |
apply (simp add: succ_def mem_not_refl [THEN cons_fun_eq]) |
|
126 |
apply (fast intro!: Fin.consI) |
|
127 |
done |
|
128 |
||
129 |
||
13356 | 130 |
subsection{*Finite Function Space*} |
13194 | 131 |
|
132 |
lemma FiniteFun_mono: |
|
133 |
"[| A<=C; B<=D |] ==> A -||> B <= C -||> D" |
|
134 |
apply (unfold FiniteFun.defs) |
|
135 |
apply (rule lfp_mono) |
|
136 |
apply (rule FiniteFun.bnd_mono)+ |
|
137 |
apply (intro Fin_mono Sigma_mono basic_monos, assumption+) |
|
138 |
done |
|
139 |
||
140 |
lemma FiniteFun_mono1: "A<=B ==> A -||> A <= B -||> B" |
|
141 |
by (blast dest: FiniteFun_mono) |
|
142 |
||
143 |
lemma FiniteFun_is_fun: "h: A -||>B ==> h: domain(h) -> B" |
|
144 |
apply (erule FiniteFun.induct, simp) |
|
145 |
apply (simp add: fun_extend3) |
|
146 |
done |
|
147 |
||
148 |
lemma FiniteFun_domain_Fin: "h: A -||>B ==> domain(h) : Fin(A)" |
|
13269 | 149 |
by (erule FiniteFun.induct, simp, simp) |
13194 | 150 |
|
151 |
lemmas FiniteFun_apply_type = FiniteFun_is_fun [THEN apply_type, standard] |
|
152 |
||
153 |
(*Every subset of a finite function is a finite function.*) |
|
154 |
lemma FiniteFun_subset_lemma [rule_format]: |
|
155 |
"b: A-||>B ==> ALL z. z<=b --> z: A-||>B" |
|
156 |
apply (erule FiniteFun.induct) |
|
157 |
apply (simp add: subset_empty_iff FiniteFun.intros) |
|
158 |
apply (simp add: subset_cons_iff distrib_simps, safe) |
|
13784 | 159 |
apply (erule_tac b = z in cons_Diff [THEN subst]) |
13194 | 160 |
apply (drule spec [THEN mp], assumption) |
161 |
apply (fast intro!: FiniteFun.intros) |
|
162 |
done |
|
163 |
||
164 |
lemma FiniteFun_subset: "[| c<=b; b: A-||>B |] ==> c: A-||>B" |
|
165 |
by (blast intro: FiniteFun_subset_lemma) |
|
166 |
||
167 |
(** Some further results by Sidi O. Ehmety **) |
|
168 |
||
169 |
lemma fun_FiniteFunI [rule_format]: "A:Fin(X) ==> ALL f. f:A->B --> f:A-||>B" |
|
170 |
apply (erule Fin.induct) |
|
13269 | 171 |
apply (simp add: FiniteFun.intros, clarify) |
13194 | 172 |
apply (case_tac "a:b") |
173 |
apply (simp add: cons_absorb) |
|
174 |
apply (subgoal_tac "restrict (f,b) : b -||> B") |
|
175 |
prefer 2 apply (blast intro: restrict_type2) |
|
176 |
apply (subst fun_cons_restrict_eq, assumption) |
|
177 |
apply (simp add: restrict_def lam_def) |
|
178 |
apply (blast intro: apply_funtype FiniteFun.intros |
|
179 |
FiniteFun_mono [THEN [2] rev_subsetD]) |
|
180 |
done |
|
181 |
||
182 |
lemma lam_FiniteFun: "A: Fin(X) ==> (lam x:A. b(x)) : A -||> {b(x). x:A}" |
|
183 |
by (blast intro: fun_FiniteFunI lam_funtype) |
|
184 |
||
185 |
lemma FiniteFun_Collect_iff: |
|
186 |
"f : FiniteFun(A, {y:B. P(y)}) |
|
187 |
<-> f : FiniteFun(A,B) & (ALL x:domain(f). P(f`x))" |
|
188 |
apply auto |
|
189 |
apply (blast intro: FiniteFun_mono [THEN [2] rev_subsetD]) |
|
190 |
apply (blast dest: Pair_mem_PiD FiniteFun_is_fun) |
|
191 |
apply (rule_tac A1="domain(f)" in |
|
192 |
subset_refl [THEN [2] FiniteFun_mono, THEN subsetD]) |
|
193 |
apply (fast dest: FiniteFun_domain_Fin Fin.dom_subset [THEN subsetD]) |
|
194 |
apply (rule fun_FiniteFunI) |
|
195 |
apply (erule FiniteFun_domain_Fin) |
|
196 |
apply (rule_tac B = "range (f) " in fun_weaken_type) |
|
197 |
apply (blast dest: FiniteFun_is_fun range_of_fun range_type apply_equality)+ |
|
198 |
done |
|
199 |
||
14883 | 200 |
|
201 |
subsection{*The Contents of a Singleton Set*} |
|
202 |
||
203 |
constdefs |
|
204 |
contents :: "i=>i" |
|
205 |
"contents(X) == THE x. X = {x}" |
|
206 |
||
207 |
lemma contents_eq [simp]: "contents ({x}) = x" |
|
208 |
by (simp add: contents_def) |
|
209 |
||
210 |
||
13194 | 211 |
ML |
212 |
{* |
|
213 |
val Fin_intros = thms "Fin.intros"; |
|
214 |
||
215 |
val Fin_mono = thm "Fin_mono"; |
|
216 |
val FinD = thm "FinD"; |
|
217 |
val Fin_induct = thm "Fin_induct"; |
|
218 |
val Fin_UnI = thm "Fin_UnI"; |
|
219 |
val Fin_UnionI = thm "Fin_UnionI"; |
|
220 |
val Fin_subset = thm "Fin_subset"; |
|
221 |
val Fin_IntI1 = thm "Fin_IntI1"; |
|
222 |
val Fin_IntI2 = thm "Fin_IntI2"; |
|
223 |
val Fin_0_induct = thm "Fin_0_induct"; |
|
224 |
val nat_fun_subset_Fin = thm "nat_fun_subset_Fin"; |
|
225 |
val FiniteFun_mono = thm "FiniteFun_mono"; |
|
226 |
val FiniteFun_mono1 = thm "FiniteFun_mono1"; |
|
227 |
val FiniteFun_is_fun = thm "FiniteFun_is_fun"; |
|
228 |
val FiniteFun_domain_Fin = thm "FiniteFun_domain_Fin"; |
|
229 |
val FiniteFun_apply_type = thm "FiniteFun_apply_type"; |
|
230 |
val FiniteFun_subset = thm "FiniteFun_subset"; |
|
231 |
val fun_FiniteFunI = thm "fun_FiniteFunI"; |
|
232 |
val lam_FiniteFun = thm "lam_FiniteFun"; |
|
233 |
val FiniteFun_Collect_iff = thm "FiniteFun_Collect_iff"; |
|
234 |
*} |
|
235 |
||
516 | 236 |
end |