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