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