src/ZF/Finite.thy
 changeset 13194 812b00ed1c03 parent 12214 f368821d9c68 child 13203 fac77a839aa2
```     1.1 --- a/src/ZF/Finite.thy	Fri May 31 12:27:24 2002 +0200
1.2 +++ b/src/ZF/Finite.thy	Fri May 31 15:06:06 2002 +0200
1.3 @@ -3,36 +3,227 @@
1.4      Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
1.5      Copyright   1994  University of Cambridge
1.6
1.7 -Finite powerset operator
1.8 +Finite powerset operator; finite function space
1.9 +
1.10 +prove X:Fin(A) ==> |X| < nat
1.11 +
1.12 +prove:  b: Fin(A) ==> inj(b,b) <= surj(b,b)
1.13  *)
1.14
1.15 -Finite = Inductive + Epsilon + Nat +
1.16 +theory Finite = Inductive + Epsilon + Nat:
1.17
1.18  (*The natural numbers as a datatype*)
1.19 -rep_datatype
1.20 -  elim		natE
1.21 -  induct	nat_induct
1.22 -  case_eqns	nat_case_0, nat_case_succ
1.23 -  recursor_eqns recursor_0, recursor_succ
1.24 +rep_datatype
1.25 +  elimination    natE
1.26 +  induction	 nat_induct
1.27 +  case_eqns	 nat_case_0 nat_case_succ
1.28 +  recursor_eqns  recursor_0 recursor_succ
1.29
1.30
1.31  consts
1.32 -  Fin       :: i=>i
1.33 -  FiniteFun :: [i,i]=>i         ("(_ -||>/ _)" [61, 60] 60)
1.34 +  Fin       :: "i=>i"
1.35 +  FiniteFun :: "[i,i]=>i"         ("(_ -||>/ _)" [61, 60] 60)
1.36
1.37  inductive
1.38    domains   "Fin(A)" <= "Pow(A)"
1.39 -  intrs
1.40 -    emptyI  "0 : Fin(A)"
1.41 -    consI   "[| a: A;  b: Fin(A) |] ==> cons(a,b) : Fin(A)"
1.42 -  type_intrs empty_subsetI, cons_subsetI, PowI
1.43 -  type_elims "[make_elim PowD]"
1.44 +  intros
1.45 +    emptyI:  "0 : Fin(A)"
1.46 +    consI:   "[| a: A;  b: Fin(A) |] ==> cons(a,b) : Fin(A)"
1.47 +  type_intros  empty_subsetI cons_subsetI PowI
1.48 +  type_elims   PowD [THEN revcut_rl]
1.49
1.50  inductive
1.51    domains   "FiniteFun(A,B)" <= "Fin(A*B)"
1.52 -  intrs
1.53 -    emptyI  "0 : A -||> B"
1.54 -    consI   "[| a: A;  b: B;  h: A -||> B;  a ~: domain(h)
1.55 -             |] ==> cons(<a,b>,h) : A -||> B"
1.56 -  type_intrs "Fin.intrs"
1.57 +  intros
1.58 +    emptyI:  "0 : A -||> B"
1.59 +    consI:   "[| a: A;  b: B;  h: A -||> B;  a ~: domain(h) |]
1.60 +              ==> cons(<a,b>,h) : A -||> B"
1.61 +  type_intros Fin.intros
1.62 +
1.63 +
1.64 +subsection {* Finite powerset operator *}
1.65 +
1.66 +lemma Fin_mono: "A<=B ==> Fin(A) <= Fin(B)"
1.67 +apply (unfold Fin.defs)
1.68 +apply (rule lfp_mono)
1.69 +apply (rule Fin.bnd_mono)+
1.70 +apply blast
1.71 +done
1.72 +
1.73 +(* A : Fin(B) ==> A <= B *)
1.74 +lemmas FinD = Fin.dom_subset [THEN subsetD, THEN PowD, standard]
1.75 +
1.76 +(** Induction on finite sets **)
1.77 +
1.78 +(*Discharging x~:y entails extra work*)
1.79 +lemma Fin_induct:
1.80 +    "[| b: Fin(A);
1.81 +        P(0);
1.82 +        !!x y. [| x: A;  y: Fin(A);  x~:y;  P(y) |] ==> P(cons(x,y))
1.83 +     |] ==> P(b)"
1.84 +apply (erule Fin.induct, simp)
1.85 +apply (case_tac "a:b")
1.86 + apply (erule cons_absorb [THEN ssubst], assumption) (*backtracking!*)
1.87 +apply simp
1.88 +done
1.89 +
1.90 +(** Simplification for Fin **)
1.91 +declare Fin.intros [simp]
1.92 +
1.93 +(*The union of two finite sets is finite.*)
1.94 +lemma Fin_UnI: "[| b: Fin(A);  c: Fin(A) |] ==> b Un c : Fin(A)"
1.95 +apply (erule Fin_induct)
1.97 +done
1.98 +
1.99 +declare Fin_UnI [simp]
1.100 +
1.101 +
1.102 +(*The union of a set of finite sets is finite.*)
1.103 +lemma Fin_UnionI: "C : Fin(Fin(A)) ==> Union(C) : Fin(A)"
1.104 +by (erule Fin_induct, simp_all)
1.105 +
1.106 +(*Every subset of a finite set is finite.*)
1.107 +lemma Fin_subset_lemma [rule_format]: "b: Fin(A) ==> \<forall>z. z<=b --> z: Fin(A)"
1.108 +apply (erule Fin_induct)
1.110 +apply (simp add: subset_cons_iff distrib_simps, safe)
1.111 +apply (erule_tac b = "z" in cons_Diff [THEN subst], simp)
1.112 +done
1.113 +
1.114 +lemma Fin_subset: "[| c<=b;  b: Fin(A) |] ==> c: Fin(A)"
1.115 +by (blast intro: Fin_subset_lemma)
1.116 +
1.117 +lemma Fin_IntI1 [intro,simp]: "b: Fin(A) ==> b Int c : Fin(A)"
1.118 +by (blast intro: Fin_subset)
1.119 +
1.120 +lemma Fin_IntI2 [intro,simp]: "c: Fin(A) ==> b Int c : Fin(A)"
1.121 +by (blast intro: Fin_subset)
1.122 +
1.123 +lemma Fin_0_induct_lemma [rule_format]:
1.124 +    "[| c: Fin(A);  b: Fin(A); P(b);
1.125 +        !!x y. [| x: A;  y: Fin(A);  x:y;  P(y) |] ==> P(y-{x})
1.126 +     |] ==> c<=b --> P(b-c)"
1.127 +apply (erule Fin_induct, simp)
1.128 +apply (subst Diff_cons)
1.129 +apply (simp add: cons_subset_iff Diff_subset [THEN Fin_subset])
1.130 +done
1.131 +
1.132 +lemma Fin_0_induct:
1.133 +    "[| b: Fin(A);
1.134 +        P(b);
1.135 +        !!x y. [| x: A;  y: Fin(A);  x:y;  P(y) |] ==> P(y-{x})
1.136 +     |] ==> P(0)"
1.137 +apply (rule Diff_cancel [THEN subst])
1.138 +apply (blast intro: Fin_0_induct_lemma)
1.139 +done
1.140 +
1.141 +(*Functions from a finite ordinal*)
1.142 +lemma nat_fun_subset_Fin: "n: nat ==> n->A <= Fin(nat*A)"
1.143 +apply (induct_tac "n")
1.145 +apply (simp add: succ_def mem_not_refl [THEN cons_fun_eq])
1.146 +apply (fast intro!: Fin.consI)
1.147 +done
1.148 +
1.149 +
1.150 +(*** Finite function space ***)
1.151 +
1.152 +lemma FiniteFun_mono:
1.153 +    "[| A<=C;  B<=D |] ==> A -||> B  <=  C -||> D"
1.154 +apply (unfold FiniteFun.defs)
1.155 +apply (rule lfp_mono)
1.156 +apply (rule FiniteFun.bnd_mono)+
1.157 +apply (intro Fin_mono Sigma_mono basic_monos, assumption+)
1.158 +done
1.159 +
1.160 +lemma FiniteFun_mono1: "A<=B ==> A -||> A  <=  B -||> B"
1.161 +by (blast dest: FiniteFun_mono)
1.162 +
1.163 +lemma FiniteFun_is_fun: "h: A -||>B ==> h: domain(h) -> B"
1.164 +apply (erule FiniteFun.induct, simp)
1.166 +done
1.167 +
1.168 +lemma FiniteFun_domain_Fin: "h: A -||>B ==> domain(h) : Fin(A)"
1.169 +apply (erule FiniteFun.induct, simp)
1.170 +apply simp
1.171 +done
1.172 +
1.173 +lemmas FiniteFun_apply_type = FiniteFun_is_fun [THEN apply_type, standard]
1.174 +
1.175 +(*Every subset of a finite function is a finite function.*)
1.176 +lemma FiniteFun_subset_lemma [rule_format]:
1.177 +     "b: A-||>B ==> ALL z. z<=b --> z: A-||>B"
1.178 +apply (erule FiniteFun.induct)
1.179 +apply (simp add: subset_empty_iff FiniteFun.intros)
1.180 +apply (simp add: subset_cons_iff distrib_simps, safe)
1.181 +apply (erule_tac b = "z" in cons_Diff [THEN subst])
1.182 +apply (drule spec [THEN mp], assumption)
1.183 +apply (fast intro!: FiniteFun.intros)
1.184 +done
1.185 +
1.186 +lemma FiniteFun_subset: "[| c<=b;  b: A-||>B |] ==> c: A-||>B"
1.187 +by (blast intro: FiniteFun_subset_lemma)
1.188 +
1.189 +(** Some further results by Sidi O. Ehmety **)
1.190 +
1.191 +lemma fun_FiniteFunI [rule_format]: "A:Fin(X) ==> ALL f. f:A->B --> f:A-||>B"
1.192 +apply (erule Fin.induct)
1.193 + apply (simp add: FiniteFun.intros)
1.194 +apply clarify
1.195 +apply (case_tac "a:b")
1.196 + apply (rotate_tac -1)
1.197 + apply (simp add: cons_absorb)
1.198 +apply (subgoal_tac "restrict (f,b) : b -||> B")
1.199 + prefer 2 apply (blast intro: restrict_type2)
1.200 +apply (subst fun_cons_restrict_eq, assumption)
1.201 +apply (simp add: restrict_def lam_def)
1.202 +apply (blast intro: apply_funtype FiniteFun.intros
1.203 +                    FiniteFun_mono [THEN [2] rev_subsetD])
1.204 +done
1.205 +
1.206 +lemma lam_FiniteFun: "A: Fin(X) ==> (lam x:A. b(x)) : A -||> {b(x). x:A}"
1.207 +by (blast intro: fun_FiniteFunI lam_funtype)
1.208 +
1.209 +lemma FiniteFun_Collect_iff:
1.210 +     "f : FiniteFun(A, {y:B. P(y)})
1.211 +      <-> f : FiniteFun(A,B) & (ALL x:domain(f). P(f`x))"
1.212 +apply auto
1.213 +apply (blast intro: FiniteFun_mono [THEN [2] rev_subsetD])
1.214 +apply (blast dest: Pair_mem_PiD FiniteFun_is_fun)
1.215 +apply (rule_tac A1="domain(f)" in
1.216 +       subset_refl [THEN [2] FiniteFun_mono, THEN subsetD])
1.217 + apply (fast dest: FiniteFun_domain_Fin Fin.dom_subset [THEN subsetD])
1.218 +apply (rule fun_FiniteFunI)
1.219 +apply (erule FiniteFun_domain_Fin)
1.220 +apply (rule_tac B = "range (f) " in fun_weaken_type)
1.221 + apply (blast dest: FiniteFun_is_fun range_of_fun range_type apply_equality)+
1.222 +done
1.223 +
1.224 +ML
1.225 +{*
1.226 +val Fin_intros = thms "Fin.intros";
1.227 +
1.228 +val Fin_mono = thm "Fin_mono";
1.229 +val FinD = thm "FinD";
1.230 +val Fin_induct = thm "Fin_induct";
1.231 +val Fin_UnI = thm "Fin_UnI";
1.232 +val Fin_UnionI = thm "Fin_UnionI";
1.233 +val Fin_subset = thm "Fin_subset";
1.234 +val Fin_IntI1 = thm "Fin_IntI1";
1.235 +val Fin_IntI2 = thm "Fin_IntI2";
1.236 +val Fin_0_induct = thm "Fin_0_induct";
1.237 +val nat_fun_subset_Fin = thm "nat_fun_subset_Fin";
1.238 +val FiniteFun_mono = thm "FiniteFun_mono";
1.239 +val FiniteFun_mono1 = thm "FiniteFun_mono1";
1.240 +val FiniteFun_is_fun = thm "FiniteFun_is_fun";
1.241 +val FiniteFun_domain_Fin = thm "FiniteFun_domain_Fin";
1.242 +val FiniteFun_apply_type = thm "FiniteFun_apply_type";
1.243 +val FiniteFun_subset = thm "FiniteFun_subset";
1.244 +val fun_FiniteFunI = thm "fun_FiniteFunI";
1.245 +val lam_FiniteFun = thm "lam_FiniteFun";
1.246 +val FiniteFun_Collect_iff = thm "FiniteFun_Collect_iff";
1.247 +*}
1.248 +
1.249  end
```