author  paulson 
Tue, 09 Jul 2002 23:05:26 +0200  
changeset 13328  703de709a64b 
parent 13269  3ba9be497c33 
child 13356  c9cfe1638bf2 
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 

44 
subsection {* Finite powerset operator *} 

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*) 

59 
lemma Fin_induct: 

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 
(*fixed up for induct method*) 
fac77a839aa2
Tidying up. Mainly moving proofs from Main.thy to other (Isar) theory files.
paulson
parents:
13194
diff
changeset

71 
lemmas Fin_induct = Fin_induct [case_names 0 cons, induct set: Fin] 
fac77a839aa2
Tidying up. Mainly moving proofs from Main.thy to other (Isar) theory files.
paulson
parents:
13194
diff
changeset

72 

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

73 

13194  74 
(** Simplification for Fin **) 
75 
declare Fin.intros [simp] 

76 

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

77 
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

78 
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

79 

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

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

84 
done 

85 

86 

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

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

89 
by (erule Fin_induct, simp_all) 

90 

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

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

93 
apply (erule Fin_induct) 

94 
apply (simp add: subset_empty_iff) 

95 
apply (simp add: subset_cons_iff distrib_simps, safe) 

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

97 
done 

98 

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

100 
by (blast intro: Fin_subset_lemma) 

101 

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

103 
by (blast intro: Fin_subset) 

104 

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

106 
by (blast intro: Fin_subset) 

107 

108 
lemma Fin_0_induct_lemma [rule_format]: 

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

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

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

112 
apply (erule Fin_induct, simp) 

113 
apply (subst Diff_cons) 

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

115 
done 

116 

117 
lemma Fin_0_induct: 

118 
"[ b: Fin(A); 

119 
P(b); 

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

121 
] ==> P(0)" 

122 
apply (rule Diff_cancel [THEN subst]) 

123 
apply (blast intro: Fin_0_induct_lemma) 

124 
done 

125 

126 
(*Functions from a finite ordinal*) 

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

128 
apply (induct_tac "n") 

129 
apply (simp add: subset_iff) 

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

131 
apply (fast intro!: Fin.consI) 

132 
done 

133 

134 

135 
(*** Finite function space ***) 

136 

137 
lemma FiniteFun_mono: 

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

139 
apply (unfold FiniteFun.defs) 

140 
apply (rule lfp_mono) 

141 
apply (rule FiniteFun.bnd_mono)+ 

142 
apply (intro Fin_mono Sigma_mono basic_monos, assumption+) 

143 
done 

144 

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

146 
by (blast dest: FiniteFun_mono) 

147 

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

149 
apply (erule FiniteFun.induct, simp) 

150 
apply (simp add: fun_extend3) 

151 
done 

152 

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

13269  154 
by (erule FiniteFun.induct, simp, simp) 
13194  155 

156 
lemmas FiniteFun_apply_type = FiniteFun_is_fun [THEN apply_type, standard] 

157 

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

159 
lemma FiniteFun_subset_lemma [rule_format]: 

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

161 
apply (erule FiniteFun.induct) 

162 
apply (simp add: subset_empty_iff FiniteFun.intros) 

163 
apply (simp add: subset_cons_iff distrib_simps, safe) 

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

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

166 
apply (fast intro!: FiniteFun.intros) 

167 
done 

168 

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

170 
by (blast intro: FiniteFun_subset_lemma) 

171 

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

173 

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

175 
apply (erule Fin.induct) 

13269  176 
apply (simp add: FiniteFun.intros, clarify) 
13194  177 
apply (case_tac "a:b") 
178 
apply (rotate_tac 1) 

179 
apply (simp add: cons_absorb) 

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

181 
prefer 2 apply (blast intro: restrict_type2) 

182 
apply (subst fun_cons_restrict_eq, assumption) 

183 
apply (simp add: restrict_def lam_def) 

184 
apply (blast intro: apply_funtype FiniteFun.intros 

185 
FiniteFun_mono [THEN [2] rev_subsetD]) 

186 
done 

187 

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

189 
by (blast intro: fun_FiniteFunI lam_funtype) 

190 

191 
lemma FiniteFun_Collect_iff: 

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

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

194 
apply auto 

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

196 
apply (blast dest: Pair_mem_PiD FiniteFun_is_fun) 

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

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

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

200 
apply (rule fun_FiniteFunI) 

201 
apply (erule FiniteFun_domain_Fin) 

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

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

204 
done 

205 

206 
ML 

207 
{* 

208 
val Fin_intros = thms "Fin.intros"; 

209 

210 
val Fin_mono = thm "Fin_mono"; 

211 
val FinD = thm "FinD"; 

212 
val Fin_induct = thm "Fin_induct"; 

213 
val Fin_UnI = thm "Fin_UnI"; 

214 
val Fin_UnionI = thm "Fin_UnionI"; 

215 
val Fin_subset = thm "Fin_subset"; 

216 
val Fin_IntI1 = thm "Fin_IntI1"; 

217 
val Fin_IntI2 = thm "Fin_IntI2"; 

218 
val Fin_0_induct = thm "Fin_0_induct"; 

219 
val nat_fun_subset_Fin = thm "nat_fun_subset_Fin"; 

220 
val FiniteFun_mono = thm "FiniteFun_mono"; 

221 
val FiniteFun_mono1 = thm "FiniteFun_mono1"; 

222 
val FiniteFun_is_fun = thm "FiniteFun_is_fun"; 

223 
val FiniteFun_domain_Fin = thm "FiniteFun_domain_Fin"; 

224 
val FiniteFun_apply_type = thm "FiniteFun_apply_type"; 

225 
val FiniteFun_subset = thm "FiniteFun_subset"; 

226 
val fun_FiniteFunI = thm "fun_FiniteFunI"; 

227 
val lam_FiniteFun = thm "lam_FiniteFun"; 

228 
val FiniteFun_Collect_iff = thm "FiniteFun_Collect_iff"; 

229 
*} 

230 

516  231 
end 