src/ZF/Finite.thy
author paulson
Fri May 31 15:06:06 2002 +0200 (2002-05-31)
changeset 13194 812b00ed1c03
parent 12214 f368821d9c68
child 13203 fac77a839aa2
permissions -rw-r--r--
conversion of Finite to Isar format
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
Finite powerset operator; finite function space
paulson@13194
     7
paulson@13194
     8
prove X:Fin(A) ==> |X| < nat
paulson@13194
     9
paulson@13194
    10
prove:  b: Fin(A) ==> inj(b,b) <= surj(b,b)
lcp@516
    11
*)
lcp@516
    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@13194
    70
(** Simplification for Fin **)
paulson@13194
    71
declare Fin.intros [simp]
paulson@13194
    72
paulson@13194
    73
(*The union of two finite sets is finite.*)
paulson@13194
    74
lemma Fin_UnI: "[| b: Fin(A);  c: Fin(A) |] ==> b Un c : Fin(A)"
paulson@13194
    75
apply (erule Fin_induct)
paulson@13194
    76
apply (simp_all add: Un_cons)
paulson@13194
    77
done
paulson@13194
    78
paulson@13194
    79
declare Fin_UnI [simp]
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@13194
    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@13194
   130
(*** 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@13194
   149
apply (erule FiniteFun.induct, simp)
paulson@13194
   150
apply simp
paulson@13194
   151
done
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@13194
   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@13194
   173
 apply (simp add: FiniteFun.intros)
paulson@13194
   174
apply clarify
paulson@13194
   175
apply (case_tac "a:b")
paulson@13194
   176
 apply (rotate_tac -1)
paulson@13194
   177
 apply (simp add: cons_absorb)
paulson@13194
   178
apply (subgoal_tac "restrict (f,b) : b -||> B")
paulson@13194
   179
 prefer 2 apply (blast intro: restrict_type2)
paulson@13194
   180
apply (subst fun_cons_restrict_eq, assumption)
paulson@13194
   181
apply (simp add: restrict_def lam_def)
paulson@13194
   182
apply (blast intro: apply_funtype FiniteFun.intros 
paulson@13194
   183
                    FiniteFun_mono [THEN [2] rev_subsetD])
paulson@13194
   184
done
paulson@13194
   185
paulson@13194
   186
lemma lam_FiniteFun: "A: Fin(X) ==> (lam x:A. b(x)) : A -||> {b(x). x:A}"
paulson@13194
   187
by (blast intro: fun_FiniteFunI lam_funtype)
paulson@13194
   188
paulson@13194
   189
lemma FiniteFun_Collect_iff:
paulson@13194
   190
     "f : FiniteFun(A, {y:B. P(y)})
paulson@13194
   191
      <-> f : FiniteFun(A,B) & (ALL x:domain(f). P(f`x))"
paulson@13194
   192
apply auto
paulson@13194
   193
apply (blast intro: FiniteFun_mono [THEN [2] rev_subsetD])
paulson@13194
   194
apply (blast dest: Pair_mem_PiD FiniteFun_is_fun)
paulson@13194
   195
apply (rule_tac A1="domain(f)" in 
paulson@13194
   196
       subset_refl [THEN [2] FiniteFun_mono, THEN subsetD])
paulson@13194
   197
 apply (fast dest: FiniteFun_domain_Fin Fin.dom_subset [THEN subsetD])
paulson@13194
   198
apply (rule fun_FiniteFunI)
paulson@13194
   199
apply (erule FiniteFun_domain_Fin)
paulson@13194
   200
apply (rule_tac B = "range (f) " in fun_weaken_type)
paulson@13194
   201
 apply (blast dest: FiniteFun_is_fun range_of_fun range_type apply_equality)+
paulson@13194
   202
done
paulson@13194
   203
paulson@13194
   204
ML
paulson@13194
   205
{*
paulson@13194
   206
val Fin_intros = thms "Fin.intros";
paulson@13194
   207
paulson@13194
   208
val Fin_mono = thm "Fin_mono";
paulson@13194
   209
val FinD = thm "FinD";
paulson@13194
   210
val Fin_induct = thm "Fin_induct";
paulson@13194
   211
val Fin_UnI = thm "Fin_UnI";
paulson@13194
   212
val Fin_UnionI = thm "Fin_UnionI";
paulson@13194
   213
val Fin_subset = thm "Fin_subset";
paulson@13194
   214
val Fin_IntI1 = thm "Fin_IntI1";
paulson@13194
   215
val Fin_IntI2 = thm "Fin_IntI2";
paulson@13194
   216
val Fin_0_induct = thm "Fin_0_induct";
paulson@13194
   217
val nat_fun_subset_Fin = thm "nat_fun_subset_Fin";
paulson@13194
   218
val FiniteFun_mono = thm "FiniteFun_mono";
paulson@13194
   219
val FiniteFun_mono1 = thm "FiniteFun_mono1";
paulson@13194
   220
val FiniteFun_is_fun = thm "FiniteFun_is_fun";
paulson@13194
   221
val FiniteFun_domain_Fin = thm "FiniteFun_domain_Fin";
paulson@13194
   222
val FiniteFun_apply_type = thm "FiniteFun_apply_type";
paulson@13194
   223
val FiniteFun_subset = thm "FiniteFun_subset";
paulson@13194
   224
val fun_FiniteFunI = thm "fun_FiniteFunI";
paulson@13194
   225
val lam_FiniteFun = thm "lam_FiniteFun";
paulson@13194
   226
val FiniteFun_Collect_iff = thm "FiniteFun_Collect_iff";
paulson@13194
   227
*}
paulson@13194
   228
lcp@516
   229
end