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