author  wenzelm 
Tue, 27 Aug 2002 11:03:05 +0200  
changeset 13524  604d0f3622d6 
parent 13356  c9cfe1638bf2 
child 13615  449a70d88b38 
permissions  rwrr 
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 X:Fin(A) ==> X < nat 
7 

8 
prove: b: Fin(A) ==> inj(b,b) <= surj(b,b) 

516  9 
*) 
10 

13328  11 
header{*Finite Powerset Operator and Finite Function Space*} 
12 

13194  13 
theory Finite = Inductive + Epsilon + Nat: 
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6053
diff
changeset

14 

1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6053
diff
changeset

15 
(*The natural numbers as a datatype*) 
13194  16 
rep_datatype 
17 
elimination natE 

18 
induction nat_induct 

19 
case_eqns nat_case_0 nat_case_succ 

20 
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

21 

1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
6053
diff
changeset

22 

534  23 
consts 
13194  24 
Fin :: "i=>i" 
25 
FiniteFun :: "[i,i]=>i" ("(_ >/ _)" [61, 60] 60) 

534  26 

516  27 
inductive 
28 
domains "Fin(A)" <= "Pow(A)" 

13194  29 
intros 
30 
emptyI: "0 : Fin(A)" 

31 
consI: "[ a: A; b: Fin(A) ] ==> cons(a,b) : Fin(A)" 

32 
type_intros empty_subsetI cons_subsetI PowI 

33 
type_elims PowD [THEN revcut_rl] 

534  34 

35 
inductive 

36 
domains "FiniteFun(A,B)" <= "Fin(A*B)" 

13194  37 
intros 
38 
emptyI: "0 : A > B" 

39 
consI: "[ a: A; b: B; h: A > B; a ~: domain(h) ] 

40 
==> cons(<a,b>,h) : A > B" 

41 
type_intros Fin.intros 

42 

43 

13356  44 
subsection {* Finite Powerset Operator *} 
13194  45 

46 
lemma Fin_mono: "A<=B ==> Fin(A) <= Fin(B)" 

47 
apply (unfold Fin.defs) 

48 
apply (rule lfp_mono) 

49 
apply (rule Fin.bnd_mono)+ 

50 
apply blast 

51 
done 

52 

53 
(* A : Fin(B) ==> A <= B *) 

54 
lemmas FinD = Fin.dom_subset [THEN subsetD, THEN PowD, standard] 

55 

56 
(** Induction on finite sets **) 

57 

58 
(*Discharging x~:y entails extra work*) 

13524  59 
lemma Fin_induct [case_names 0 cons, induct set: Fin]: 
13194  60 
"[ b: Fin(A); 
61 
P(0); 

62 
!!x y. [ x: A; y: Fin(A); x~:y; P(y) ] ==> P(cons(x,y)) 

63 
] ==> P(b)" 

64 
apply (erule Fin.induct, simp) 

65 
apply (case_tac "a:b") 

66 
apply (erule cons_absorb [THEN ssubst], assumption) (*backtracking!*) 

67 
apply simp 

68 
done 

69 

13203
fac77a839aa2
Tidying up. Mainly moving proofs from Main.thy to other (Isar) theory files.
paulson
parents:
13194
diff
changeset

70 

13194  71 
(** Simplification for Fin **) 
72 
declare Fin.intros [simp] 

73 

13203
fac77a839aa2
Tidying up. Mainly moving proofs from Main.thy to other (Isar) theory files.
paulson
parents:
13194
diff
changeset

74 
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

75 
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

76 

13194  77 
(*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

78 
lemma Fin_UnI [simp]: "[ b: Fin(A); c: Fin(A) ] ==> b Un c : Fin(A)" 
13194  79 
apply (erule Fin_induct) 
80 
apply (simp_all add: Un_cons) 

81 
done 

82 

83 

84 
(*The union of a set of finite sets is finite.*) 

85 
lemma Fin_UnionI: "C : Fin(Fin(A)) ==> Union(C) : Fin(A)" 

86 
by (erule Fin_induct, simp_all) 

87 

88 
(*Every subset of a finite set is finite.*) 

89 
lemma Fin_subset_lemma [rule_format]: "b: Fin(A) ==> \<forall>z. z<=b > z: Fin(A)" 

90 
apply (erule Fin_induct) 

91 
apply (simp add: subset_empty_iff) 

92 
apply (simp add: subset_cons_iff distrib_simps, safe) 

93 
apply (erule_tac b = "z" in cons_Diff [THEN subst], simp) 

94 
done 

95 

96 
lemma Fin_subset: "[ c<=b; b: Fin(A) ] ==> c: Fin(A)" 

97 
by (blast intro: Fin_subset_lemma) 

98 

99 
lemma Fin_IntI1 [intro,simp]: "b: Fin(A) ==> b Int c : Fin(A)" 

100 
by (blast intro: Fin_subset) 

101 

102 
lemma Fin_IntI2 [intro,simp]: "c: Fin(A) ==> b Int c : Fin(A)" 

103 
by (blast intro: Fin_subset) 

104 

105 
lemma Fin_0_induct_lemma [rule_format]: 

106 
"[ c: Fin(A); b: Fin(A); P(b); 

107 
!!x y. [ x: A; y: Fin(A); x:y; P(y) ] ==> P(y{x}) 

108 
] ==> c<=b > P(bc)" 

109 
apply (erule Fin_induct, simp) 

110 
apply (subst Diff_cons) 

111 
apply (simp add: cons_subset_iff Diff_subset [THEN Fin_subset]) 

112 
done 

113 

114 
lemma Fin_0_induct: 

115 
"[ b: Fin(A); 

116 
P(b); 

117 
!!x y. [ x: A; y: Fin(A); x:y; P(y) ] ==> P(y{x}) 

118 
] ==> P(0)" 

119 
apply (rule Diff_cancel [THEN subst]) 

120 
apply (blast intro: Fin_0_induct_lemma) 

121 
done 

122 

123 
(*Functions from a finite ordinal*) 

124 
lemma nat_fun_subset_Fin: "n: nat ==> n>A <= Fin(nat*A)" 

125 
apply (induct_tac "n") 

126 
apply (simp add: subset_iff) 

127 
apply (simp add: succ_def mem_not_refl [THEN cons_fun_eq]) 

128 
apply (fast intro!: Fin.consI) 

129 
done 

130 

131 

13356  132 
subsection{*Finite Function Space*} 
13194  133 

134 
lemma FiniteFun_mono: 

135 
"[ A<=C; B<=D ] ==> A > B <= C > D" 

136 
apply (unfold FiniteFun.defs) 

137 
apply (rule lfp_mono) 

138 
apply (rule FiniteFun.bnd_mono)+ 

139 
apply (intro Fin_mono Sigma_mono basic_monos, assumption+) 

140 
done 

141 

142 
lemma FiniteFun_mono1: "A<=B ==> A > A <= B > B" 

143 
by (blast dest: FiniteFun_mono) 

144 

145 
lemma FiniteFun_is_fun: "h: A >B ==> h: domain(h) > B" 

146 
apply (erule FiniteFun.induct, simp) 

147 
apply (simp add: fun_extend3) 

148 
done 

149 

150 
lemma FiniteFun_domain_Fin: "h: A >B ==> domain(h) : Fin(A)" 

13269  151 
by (erule FiniteFun.induct, simp, simp) 
13194  152 

153 
lemmas FiniteFun_apply_type = FiniteFun_is_fun [THEN apply_type, standard] 

154 

155 
(*Every subset of a finite function is a finite function.*) 

156 
lemma FiniteFun_subset_lemma [rule_format]: 

157 
"b: A>B ==> ALL z. z<=b > z: A>B" 

158 
apply (erule FiniteFun.induct) 

159 
apply (simp add: subset_empty_iff FiniteFun.intros) 

160 
apply (simp add: subset_cons_iff distrib_simps, safe) 

161 
apply (erule_tac b = "z" in cons_Diff [THEN subst]) 

162 
apply (drule spec [THEN mp], assumption) 

163 
apply (fast intro!: FiniteFun.intros) 

164 
done 

165 

166 
lemma FiniteFun_subset: "[ c<=b; b: A>B ] ==> c: A>B" 

167 
by (blast intro: FiniteFun_subset_lemma) 

168 

169 
(** Some further results by Sidi O. Ehmety **) 

170 

171 
lemma fun_FiniteFunI [rule_format]: "A:Fin(X) ==> ALL f. f:A>B > f:A>B" 

172 
apply (erule Fin.induct) 

13269  173 
apply (simp add: FiniteFun.intros, clarify) 
13194  174 
apply (case_tac "a:b") 
175 
apply (rotate_tac 1) 

176 
apply (simp add: cons_absorb) 

177 
apply (subgoal_tac "restrict (f,b) : b > B") 

178 
prefer 2 apply (blast intro: restrict_type2) 

179 
apply (subst fun_cons_restrict_eq, assumption) 

180 
apply (simp add: restrict_def lam_def) 

181 
apply (blast intro: apply_funtype FiniteFun.intros 

182 
FiniteFun_mono [THEN [2] rev_subsetD]) 

183 
done 

184 

185 
lemma lam_FiniteFun: "A: Fin(X) ==> (lam x:A. b(x)) : A > {b(x). x:A}" 

186 
by (blast intro: fun_FiniteFunI lam_funtype) 

187 

188 
lemma FiniteFun_Collect_iff: 

189 
"f : FiniteFun(A, {y:B. P(y)}) 

190 
<> f : FiniteFun(A,B) & (ALL x:domain(f). P(f`x))" 

191 
apply auto 

192 
apply (blast intro: FiniteFun_mono [THEN [2] rev_subsetD]) 

193 
apply (blast dest: Pair_mem_PiD FiniteFun_is_fun) 

194 
apply (rule_tac A1="domain(f)" in 

195 
subset_refl [THEN [2] FiniteFun_mono, THEN subsetD]) 

196 
apply (fast dest: FiniteFun_domain_Fin Fin.dom_subset [THEN subsetD]) 

197 
apply (rule fun_FiniteFunI) 

198 
apply (erule FiniteFun_domain_Fin) 

199 
apply (rule_tac B = "range (f) " in fun_weaken_type) 

200 
apply (blast dest: FiniteFun_is_fun range_of_fun range_type apply_equality)+ 

201 
done 

202 

203 
ML 

204 
{* 

205 
val Fin_intros = thms "Fin.intros"; 

206 

207 
val Fin_mono = thm "Fin_mono"; 

208 
val FinD = thm "FinD"; 

209 
val Fin_induct = thm "Fin_induct"; 

210 
val Fin_UnI = thm "Fin_UnI"; 

211 
val Fin_UnionI = thm "Fin_UnionI"; 

212 
val Fin_subset = thm "Fin_subset"; 

213 
val Fin_IntI1 = thm "Fin_IntI1"; 

214 
val Fin_IntI2 = thm "Fin_IntI2"; 

215 
val Fin_0_induct = thm "Fin_0_induct"; 

216 
val nat_fun_subset_Fin = thm "nat_fun_subset_Fin"; 

217 
val FiniteFun_mono = thm "FiniteFun_mono"; 

218 
val FiniteFun_mono1 = thm "FiniteFun_mono1"; 

219 
val FiniteFun_is_fun = thm "FiniteFun_is_fun"; 

220 
val FiniteFun_domain_Fin = thm "FiniteFun_domain_Fin"; 

221 
val FiniteFun_apply_type = thm "FiniteFun_apply_type"; 

222 
val FiniteFun_subset = thm "FiniteFun_subset"; 

223 
val fun_FiniteFunI = thm "fun_FiniteFunI"; 

224 
val lam_FiniteFun = thm "lam_FiniteFun"; 

225 
val FiniteFun_Collect_iff = thm "FiniteFun_Collect_iff"; 

226 
*} 

227 

516  228 
end 