src/ZF/Finite.thy
author paulson
Sun Jul 14 15:14:43 2002 +0200 (2002-07-14)
changeset 13356 c9cfe1638bf2
parent 13328 703de709a64b
child 13524 604d0f3622d6
permissions -rw-r--r--
improved presentation markup
     1 (*  Title:      ZF/Finite.thy
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1994  University of Cambridge
     5 
     6 prove X:Fin(A) ==> |X| < nat
     7 
     8 prove:  b: Fin(A) ==> inj(b,b) <= surj(b,b)
     9 *)
    10 
    11 header{*Finite Powerset Operator and Finite Function Space*}
    12 
    13 theory Finite = Inductive + Epsilon + Nat:
    14 
    15 (*The natural numbers as a datatype*)
    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
    21 
    22 
    23 consts
    24   Fin       :: "i=>i"
    25   FiniteFun :: "[i,i]=>i"         ("(_ -||>/ _)" [61, 60] 60)
    26 
    27 inductive
    28   domains   "Fin(A)" <= "Pow(A)"
    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]
    34 
    35 inductive
    36   domains   "FiniteFun(A,B)" <= "Fin(A*B)"
    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 
    70 (*fixed up for induct method*)
    71 lemmas Fin_induct = Fin_induct [case_names 0 cons, induct set: Fin]
    72 
    73 
    74 (** Simplification for Fin **)
    75 declare Fin.intros [simp]
    76 
    77 lemma Fin_0: "Fin(0) = {0}"
    78 by (blast intro: Fin.emptyI dest: FinD)
    79 
    80 (*The union of two finite sets is finite.*)
    81 lemma Fin_UnI [simp]: "[| b: Fin(A);  c: Fin(A) |] ==> b Un c : Fin(A)"
    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(b-c)"
   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 subsection{*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)"
   154 by (erule FiniteFun.induct, simp, simp)
   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)
   176  apply (simp add: FiniteFun.intros, clarify)
   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 
   231 end