src/ZF/Finite.thy
author paulson
Thu Jan 23 10:30:14 2003 +0100 (2003-01-23)
changeset 13784 b9f6154427a4
parent 13615 449a70d88b38
child 14883 ca000a495448
permissions -rw-r--r--
tidying (by script)
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@13356
    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*)
wenzelm@13524
    59
lemma Fin_induct [case_names 0 cons, induct set: Fin]:
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
paulson@13194
    71
(** Simplification for Fin **)
paulson@13194
    72
declare Fin.intros [simp]
paulson@13194
    73
paulson@13203
    74
lemma Fin_0: "Fin(0) = {0}"
paulson@13203
    75
by (blast intro: Fin.emptyI dest: FinD)
paulson@13203
    76
paulson@13194
    77
(*The union of two finite sets is finite.*)
paulson@13203
    78
lemma Fin_UnI [simp]: "[| b: Fin(A);  c: Fin(A) |] ==> b Un c : Fin(A)"
paulson@13194
    79
apply (erule Fin_induct)
paulson@13194
    80
apply (simp_all add: Un_cons)
paulson@13194
    81
done
paulson@13194
    82
paulson@13194
    83
paulson@13194
    84
(*The union of a set of finite sets is finite.*)
paulson@13194
    85
lemma Fin_UnionI: "C : Fin(Fin(A)) ==> Union(C) : Fin(A)"
paulson@13194
    86
by (erule Fin_induct, simp_all)
paulson@13194
    87
paulson@13194
    88
(*Every subset of a finite set is finite.*)
paulson@13194
    89
lemma Fin_subset_lemma [rule_format]: "b: Fin(A) ==> \<forall>z. z<=b --> z: Fin(A)"
paulson@13194
    90
apply (erule Fin_induct)
paulson@13194
    91
apply (simp add: subset_empty_iff)
paulson@13194
    92
apply (simp add: subset_cons_iff distrib_simps, safe)
paulson@13784
    93
apply (erule_tac b = z in cons_Diff [THEN subst], simp)
paulson@13194
    94
done
paulson@13194
    95
paulson@13194
    96
lemma Fin_subset: "[| c<=b;  b: Fin(A) |] ==> c: Fin(A)"
paulson@13194
    97
by (blast intro: Fin_subset_lemma)
paulson@13194
    98
paulson@13194
    99
lemma Fin_IntI1 [intro,simp]: "b: Fin(A) ==> b Int c : Fin(A)"
paulson@13194
   100
by (blast intro: Fin_subset)
paulson@13194
   101
paulson@13194
   102
lemma Fin_IntI2 [intro,simp]: "c: Fin(A) ==> b Int c : Fin(A)"
paulson@13194
   103
by (blast intro: Fin_subset)
paulson@13194
   104
paulson@13194
   105
lemma Fin_0_induct_lemma [rule_format]:
paulson@13194
   106
    "[| c: Fin(A);  b: Fin(A); P(b);
paulson@13194
   107
        !!x y. [| x: A;  y: Fin(A);  x:y;  P(y) |] ==> P(y-{x})
paulson@13194
   108
     |] ==> c<=b --> P(b-c)"
paulson@13194
   109
apply (erule Fin_induct, simp)
paulson@13194
   110
apply (subst Diff_cons)
paulson@13194
   111
apply (simp add: cons_subset_iff Diff_subset [THEN Fin_subset])
paulson@13194
   112
done
paulson@13194
   113
paulson@13194
   114
lemma Fin_0_induct:
paulson@13194
   115
    "[| b: Fin(A);
paulson@13194
   116
        P(b);
paulson@13194
   117
        !!x y. [| x: A;  y: Fin(A);  x:y;  P(y) |] ==> P(y-{x})
paulson@13194
   118
     |] ==> P(0)"
paulson@13194
   119
apply (rule Diff_cancel [THEN subst])
paulson@13194
   120
apply (blast intro: Fin_0_induct_lemma) 
paulson@13194
   121
done
paulson@13194
   122
paulson@13194
   123
(*Functions from a finite ordinal*)
paulson@13194
   124
lemma nat_fun_subset_Fin: "n: nat ==> n->A <= Fin(nat*A)"
paulson@13194
   125
apply (induct_tac "n")
paulson@13194
   126
apply (simp add: subset_iff)
paulson@13194
   127
apply (simp add: succ_def mem_not_refl [THEN cons_fun_eq])
paulson@13194
   128
apply (fast intro!: Fin.consI)
paulson@13194
   129
done
paulson@13194
   130
paulson@13194
   131
paulson@13356
   132
subsection{*Finite Function Space*}
paulson@13194
   133
paulson@13194
   134
lemma FiniteFun_mono:
paulson@13194
   135
    "[| A<=C;  B<=D |] ==> A -||> B  <=  C -||> D"
paulson@13194
   136
apply (unfold FiniteFun.defs)
paulson@13194
   137
apply (rule lfp_mono)
paulson@13194
   138
apply (rule FiniteFun.bnd_mono)+
paulson@13194
   139
apply (intro Fin_mono Sigma_mono basic_monos, assumption+)
paulson@13194
   140
done
paulson@13194
   141
paulson@13194
   142
lemma FiniteFun_mono1: "A<=B ==> A -||> A  <=  B -||> B"
paulson@13194
   143
by (blast dest: FiniteFun_mono)
paulson@13194
   144
paulson@13194
   145
lemma FiniteFun_is_fun: "h: A -||>B ==> h: domain(h) -> B"
paulson@13194
   146
apply (erule FiniteFun.induct, simp)
paulson@13194
   147
apply (simp add: fun_extend3)
paulson@13194
   148
done
paulson@13194
   149
paulson@13194
   150
lemma FiniteFun_domain_Fin: "h: A -||>B ==> domain(h) : Fin(A)"
paulson@13269
   151
by (erule FiniteFun.induct, simp, simp)
paulson@13194
   152
paulson@13194
   153
lemmas FiniteFun_apply_type = FiniteFun_is_fun [THEN apply_type, standard]
paulson@13194
   154
paulson@13194
   155
(*Every subset of a finite function is a finite function.*)
paulson@13194
   156
lemma FiniteFun_subset_lemma [rule_format]:
paulson@13194
   157
     "b: A-||>B ==> ALL z. z<=b --> z: A-||>B"
paulson@13194
   158
apply (erule FiniteFun.induct)
paulson@13194
   159
apply (simp add: subset_empty_iff FiniteFun.intros)
paulson@13194
   160
apply (simp add: subset_cons_iff distrib_simps, safe)
paulson@13784
   161
apply (erule_tac b = z in cons_Diff [THEN subst])
paulson@13194
   162
apply (drule spec [THEN mp], assumption)
paulson@13194
   163
apply (fast intro!: FiniteFun.intros)
paulson@13194
   164
done
paulson@13194
   165
paulson@13194
   166
lemma FiniteFun_subset: "[| c<=b;  b: A-||>B |] ==> c: A-||>B"
paulson@13194
   167
by (blast intro: FiniteFun_subset_lemma)
paulson@13194
   168
paulson@13194
   169
(** Some further results by Sidi O. Ehmety **)
paulson@13194
   170
paulson@13194
   171
lemma fun_FiniteFunI [rule_format]: "A:Fin(X) ==> ALL f. f:A->B --> f:A-||>B"
paulson@13194
   172
apply (erule Fin.induct)
paulson@13269
   173
 apply (simp add: FiniteFun.intros, clarify)
paulson@13194
   174
apply (case_tac "a:b")
paulson@13194
   175
 apply (simp add: cons_absorb)
paulson@13194
   176
apply (subgoal_tac "restrict (f,b) : b -||> B")
paulson@13194
   177
 prefer 2 apply (blast intro: restrict_type2)
paulson@13194
   178
apply (subst fun_cons_restrict_eq, assumption)
paulson@13194
   179
apply (simp add: restrict_def lam_def)
paulson@13194
   180
apply (blast intro: apply_funtype FiniteFun.intros 
paulson@13194
   181
                    FiniteFun_mono [THEN [2] rev_subsetD])
paulson@13194
   182
done
paulson@13194
   183
paulson@13194
   184
lemma lam_FiniteFun: "A: Fin(X) ==> (lam x:A. b(x)) : A -||> {b(x). x:A}"
paulson@13194
   185
by (blast intro: fun_FiniteFunI lam_funtype)
paulson@13194
   186
paulson@13194
   187
lemma FiniteFun_Collect_iff:
paulson@13194
   188
     "f : FiniteFun(A, {y:B. P(y)})
paulson@13194
   189
      <-> f : FiniteFun(A,B) & (ALL x:domain(f). P(f`x))"
paulson@13194
   190
apply auto
paulson@13194
   191
apply (blast intro: FiniteFun_mono [THEN [2] rev_subsetD])
paulson@13194
   192
apply (blast dest: Pair_mem_PiD FiniteFun_is_fun)
paulson@13194
   193
apply (rule_tac A1="domain(f)" in 
paulson@13194
   194
       subset_refl [THEN [2] FiniteFun_mono, THEN subsetD])
paulson@13194
   195
 apply (fast dest: FiniteFun_domain_Fin Fin.dom_subset [THEN subsetD])
paulson@13194
   196
apply (rule fun_FiniteFunI)
paulson@13194
   197
apply (erule FiniteFun_domain_Fin)
paulson@13194
   198
apply (rule_tac B = "range (f) " in fun_weaken_type)
paulson@13194
   199
 apply (blast dest: FiniteFun_is_fun range_of_fun range_type apply_equality)+
paulson@13194
   200
done
paulson@13194
   201
paulson@13194
   202
ML
paulson@13194
   203
{*
paulson@13194
   204
val Fin_intros = thms "Fin.intros";
paulson@13194
   205
paulson@13194
   206
val Fin_mono = thm "Fin_mono";
paulson@13194
   207
val FinD = thm "FinD";
paulson@13194
   208
val Fin_induct = thm "Fin_induct";
paulson@13194
   209
val Fin_UnI = thm "Fin_UnI";
paulson@13194
   210
val Fin_UnionI = thm "Fin_UnionI";
paulson@13194
   211
val Fin_subset = thm "Fin_subset";
paulson@13194
   212
val Fin_IntI1 = thm "Fin_IntI1";
paulson@13194
   213
val Fin_IntI2 = thm "Fin_IntI2";
paulson@13194
   214
val Fin_0_induct = thm "Fin_0_induct";
paulson@13194
   215
val nat_fun_subset_Fin = thm "nat_fun_subset_Fin";
paulson@13194
   216
val FiniteFun_mono = thm "FiniteFun_mono";
paulson@13194
   217
val FiniteFun_mono1 = thm "FiniteFun_mono1";
paulson@13194
   218
val FiniteFun_is_fun = thm "FiniteFun_is_fun";
paulson@13194
   219
val FiniteFun_domain_Fin = thm "FiniteFun_domain_Fin";
paulson@13194
   220
val FiniteFun_apply_type = thm "FiniteFun_apply_type";
paulson@13194
   221
val FiniteFun_subset = thm "FiniteFun_subset";
paulson@13194
   222
val fun_FiniteFunI = thm "fun_FiniteFunI";
paulson@13194
   223
val lam_FiniteFun = thm "lam_FiniteFun";
paulson@13194
   224
val FiniteFun_Collect_iff = thm "FiniteFun_Collect_iff";
paulson@13194
   225
*}
paulson@13194
   226
lcp@516
   227
end