src/ZF/Finite.ML
author lcp
Tue Aug 16 19:03:45 1994 +0200 (1994-08-16)
changeset 534 cd8bec47e175
parent 516 1957113f0d7d
child 760 f0200e91b272
permissions -rw-r--r--
ZF/Finite: added the finite function space, A-||>B
ZF/InfDatatype: added rules for the above
lcp@516
     1
(*  Title: 	ZF/Finite.ML
lcp@516
     2
    ID:         $Id$
lcp@516
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
lcp@516
     4
    Copyright   1994  University of Cambridge
lcp@516
     5
lcp@534
     6
Finite powerset operator; finite function space
lcp@516
     7
lcp@516
     8
prove X:Fin(A) ==> |X| < nat
lcp@516
     9
lcp@516
    10
prove:  b: Fin(A) ==> inj(b,b)<=surj(b,b)
lcp@516
    11
*)
lcp@516
    12
lcp@516
    13
open Finite;
lcp@516
    14
lcp@534
    15
(*** Finite powerset operator ***)
lcp@534
    16
lcp@516
    17
goalw Finite.thy Fin.defs "!!A B. A<=B ==> Fin(A) <= Fin(B)";
lcp@516
    18
by (rtac lfp_mono 1);
lcp@516
    19
by (REPEAT (rtac Fin.bnd_mono 1));
lcp@516
    20
by (REPEAT (ares_tac (Pow_mono::basic_monos) 1));
lcp@516
    21
val Fin_mono = result();
lcp@516
    22
lcp@516
    23
(* A : Fin(B) ==> A <= B *)
lcp@516
    24
val FinD = Fin.dom_subset RS subsetD RS PowD;
lcp@516
    25
lcp@516
    26
(** Induction on finite sets **)
lcp@516
    27
lcp@516
    28
(*Discharging x~:y entails extra work*)
lcp@516
    29
val major::prems = goal Finite.thy 
lcp@516
    30
    "[| b: Fin(A);  \
lcp@516
    31
\       P(0);        \
lcp@516
    32
\       !!x y. [| x: A;  y: Fin(A);  x~:y;  P(y) |] ==> P(cons(x,y)) \
lcp@516
    33
\    |] ==> P(b)";
lcp@516
    34
by (rtac (major RS Fin.induct) 1);
lcp@516
    35
by (excluded_middle_tac "a:b" 2);
lcp@516
    36
by (etac (cons_absorb RS ssubst) 3 THEN assume_tac 3);	    (*backtracking!*)
lcp@516
    37
by (REPEAT (ares_tac prems 1));
lcp@516
    38
val Fin_induct = result();
lcp@516
    39
lcp@516
    40
(** Simplification for Fin **)
lcp@516
    41
val Fin_ss = arith_ss addsimps Fin.intrs;
lcp@516
    42
lcp@516
    43
(*The union of two finite sets is finite.*)
lcp@516
    44
val major::prems = goal Finite.thy
lcp@516
    45
    "[| b: Fin(A);  c: Fin(A) |] ==> b Un c : Fin(A)";
lcp@516
    46
by (rtac (major RS Fin_induct) 1);
lcp@516
    47
by (ALLGOALS (asm_simp_tac (Fin_ss addsimps (prems@[Un_0, Un_cons]))));
lcp@516
    48
val Fin_UnI = result();
lcp@516
    49
lcp@516
    50
(*The union of a set of finite sets is finite.*)
lcp@516
    51
val [major] = goal Finite.thy "C : Fin(Fin(A)) ==> Union(C) : Fin(A)";
lcp@516
    52
by (rtac (major RS Fin_induct) 1);
lcp@516
    53
by (ALLGOALS (asm_simp_tac (Fin_ss addsimps [Union_0, Union_cons, Fin_UnI])));
lcp@516
    54
val Fin_UnionI = result();
lcp@516
    55
lcp@516
    56
(*Every subset of a finite set is finite.*)
lcp@516
    57
goal Finite.thy "!!b A. b: Fin(A) ==> ALL z. z<=b --> z: Fin(A)";
lcp@516
    58
by (etac Fin_induct 1);
lcp@516
    59
by (simp_tac (Fin_ss addsimps [subset_empty_iff]) 1);
lcp@534
    60
by (asm_simp_tac (ZF_ss addsimps subset_cons_iff::distrib_rews) 1);
lcp@534
    61
by (safe_tac ZF_cs);
lcp@534
    62
by (eres_inst_tac [("b","z")] (cons_Diff RS subst) 1);
lcp@534
    63
by (asm_simp_tac Fin_ss 1);
lcp@516
    64
val Fin_subset_lemma = result();
lcp@516
    65
lcp@516
    66
goal Finite.thy "!!c b A. [| c<=b;  b: Fin(A) |] ==> c: Fin(A)";
lcp@516
    67
by (REPEAT (ares_tac [Fin_subset_lemma RS spec RS mp] 1));
lcp@516
    68
val Fin_subset = result();
lcp@516
    69
lcp@516
    70
val major::prems = goal Finite.thy 
lcp@516
    71
    "[| c: Fin(A);  b: Fin(A);  				\
lcp@516
    72
\       P(b);       						\
lcp@516
    73
\       !!x y. [| x: A;  y: Fin(A);  x:y;  P(y) |] ==> P(y-{x}) \
lcp@516
    74
\    |] ==> c<=b --> P(b-c)";
lcp@516
    75
by (rtac (major RS Fin_induct) 1);
lcp@516
    76
by (rtac (Diff_cons RS ssubst) 2);
lcp@516
    77
by (ALLGOALS (asm_simp_tac (Fin_ss addsimps (prems@[Diff_0, cons_subset_iff, 
lcp@516
    78
				Diff_subset RS Fin_subset]))));
lcp@516
    79
val Fin_0_induct_lemma = result();
lcp@516
    80
lcp@516
    81
val prems = goal Finite.thy 
lcp@516
    82
    "[| b: Fin(A);  						\
lcp@516
    83
\       P(b);        						\
lcp@516
    84
\       !!x y. [| x: A;  y: Fin(A);  x:y;  P(y) |] ==> P(y-{x}) \
lcp@516
    85
\    |] ==> P(0)";
lcp@516
    86
by (rtac (Diff_cancel RS subst) 1);
lcp@516
    87
by (rtac (Fin_0_induct_lemma RS mp) 1);
lcp@516
    88
by (REPEAT (ares_tac (subset_refl::prems) 1));
lcp@516
    89
val Fin_0_induct = result();
lcp@516
    90
lcp@516
    91
(*Functions from a finite ordinal*)
lcp@516
    92
val prems = goal Finite.thy "n: nat ==> n->A <= Fin(nat*A)";
lcp@516
    93
by (nat_ind_tac "n" prems 1);
lcp@516
    94
by (simp_tac (ZF_ss addsimps [Pi_empty1, Fin.emptyI, subset_iff, cons_iff]) 1);
lcp@516
    95
by (asm_simp_tac (ZF_ss addsimps [succ_def, mem_not_refl RS cons_fun_eq]) 1);
lcp@516
    96
by (fast_tac (ZF_cs addSIs [Fin.consI]) 1);
lcp@516
    97
val nat_fun_subset_Fin = result();
lcp@534
    98
lcp@534
    99
lcp@534
   100
(*** Finite function space ***)
lcp@534
   101
lcp@534
   102
goalw Finite.thy FiniteFun.defs
lcp@534
   103
    "!!A B C D. [| A<=C;  B<=D |] ==> A -||> B  <=  C -||> D";
lcp@534
   104
by (rtac lfp_mono 1);
lcp@534
   105
by (REPEAT (rtac FiniteFun.bnd_mono 1));
lcp@534
   106
by (REPEAT (ares_tac (Fin_mono::Sigma_mono::basic_monos) 1));
lcp@534
   107
val FiniteFun_mono = result();
lcp@534
   108
lcp@534
   109
goal Finite.thy "!!A B. A<=B ==> A -||> A  <=  B -||> B";
lcp@534
   110
by (REPEAT (ares_tac [FiniteFun_mono] 1));
lcp@534
   111
val FiniteFun_mono1 = result();
lcp@534
   112
lcp@534
   113
goal Finite.thy "!!h. h: A -||>B ==> h: domain(h) -> B";
lcp@534
   114
by (etac FiniteFun.induct 1);
lcp@534
   115
by (simp_tac (ZF_ss addsimps [empty_fun, domain_0]) 1);
lcp@534
   116
by (asm_simp_tac (ZF_ss addsimps [fun_extend3, domain_cons]) 1);
lcp@534
   117
val FiniteFun_is_fun = result();
lcp@534
   118
lcp@534
   119
goal Finite.thy "!!h. h: A -||>B ==> domain(h) : Fin(A)";
lcp@534
   120
by (etac FiniteFun.induct 1);
lcp@534
   121
by (simp_tac (Fin_ss addsimps [domain_0]) 1);
lcp@534
   122
by (asm_simp_tac (Fin_ss addsimps [domain_cons]) 1);
lcp@534
   123
val FiniteFun_domain_Fin = result();
lcp@534
   124
lcp@534
   125
val FiniteFun_apply_type = FiniteFun_is_fun RS apply_type |> standard;
lcp@534
   126
lcp@534
   127
(*Every subset of a finite function is a finite function.*)
lcp@534
   128
goal Finite.thy "!!b A. b: A-||>B ==> ALL z. z<=b --> z: A-||>B";
lcp@534
   129
by (etac FiniteFun.induct 1);
lcp@534
   130
by (simp_tac (ZF_ss addsimps subset_empty_iff::FiniteFun.intrs) 1);
lcp@534
   131
by (asm_simp_tac (ZF_ss addsimps subset_cons_iff::distrib_rews) 1);
lcp@534
   132
by (safe_tac ZF_cs);
lcp@534
   133
by (eres_inst_tac [("b","z")] (cons_Diff RS subst) 1);
lcp@534
   134
by (dtac (spec RS mp) 1 THEN assume_tac 1);
lcp@534
   135
by (fast_tac (ZF_cs addSIs FiniteFun.intrs) 1);
lcp@534
   136
val FiniteFun_subset_lemma = result();
lcp@534
   137
lcp@534
   138
goal Finite.thy "!!c b A. [| c<=b;  b: A-||>B |] ==> c: A-||>B";
lcp@534
   139
by (REPEAT (ares_tac [FiniteFun_subset_lemma RS spec RS mp] 1));
lcp@534
   140
val FiniteFun_subset = result();
lcp@534
   141