src/ZF/Finite.ML
author wenzelm
Fri, 07 Mar 1997 11:48:46 +0100
changeset 2754 59bd96046ad6
parent 2469 b50b8c0eec01
child 4091 771b1f6422a8
permissions -rw-r--r--
moved settings comment to build;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 803
diff changeset
     1
(*  Title:      ZF/Finite.ML
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
     2
    ID:         $Id$
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 803
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
     4
    Copyright   1994  University of Cambridge
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
     5
534
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
     6
Finite powerset operator; finite function space
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
     7
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
     8
prove X:Fin(A) ==> |X| < nat
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
     9
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    10
prove:  b: Fin(A) ==> inj(b,b)<=surj(b,b)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    11
*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    12
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    13
open Finite;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    14
534
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
    15
(*** Finite powerset operator ***)
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
    16
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    17
goalw Finite.thy Fin.defs "!!A B. A<=B ==> Fin(A) <= Fin(B)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    18
by (rtac lfp_mono 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    19
by (REPEAT (rtac Fin.bnd_mono 1));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    20
by (REPEAT (ares_tac (Pow_mono::basic_monos) 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
    21
qed "Fin_mono";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    22
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    23
(* A : Fin(B) ==> A <= B *)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    24
val FinD = Fin.dom_subset RS subsetD RS PowD;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    25
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    26
(** Induction on finite sets **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    27
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    28
(*Discharging x~:y entails extra work*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    29
val major::prems = goal Finite.thy 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    30
    "[| b: Fin(A);  \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    31
\       P(0);        \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    32
\       !!x y. [| x: A;  y: Fin(A);  x~:y;  P(y) |] ==> P(cons(x,y)) \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    33
\    |] ==> P(b)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    34
by (rtac (major RS Fin.induct) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    35
by (excluded_middle_tac "a:b" 2);
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 803
diff changeset
    36
by (etac (cons_absorb RS ssubst) 3 THEN assume_tac 3);      (*backtracking!*)
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    37
by (REPEAT (ares_tac prems 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
    38
qed "Fin_induct";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    39
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    40
(** Simplification for Fin **)
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    41
Addsimps Fin.intrs;
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    42
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    43
(*The union of two finite sets is finite.*)
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    44
goal Finite.thy
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    45
    "!!b c. [| b: Fin(A);  c: Fin(A) |] ==> b Un c : Fin(A)";
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    46
by (etac Fin_induct 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    47
by (ALLGOALS (asm_simp_tac (!simpset addsimps [Un_cons])));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
    48
qed "Fin_UnI";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    49
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    50
Addsimps [Fin_UnI];
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    51
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    52
(*The union of a set of finite sets is finite.*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    53
val [major] = goal Finite.thy "C : Fin(Fin(A)) ==> Union(C) : Fin(A)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    54
by (rtac (major RS Fin_induct) 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    55
by (ALLGOALS Asm_simp_tac);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
    56
qed "Fin_UnionI";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    57
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    58
(*Every subset of a finite set is finite.*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    59
goal Finite.thy "!!b A. b: Fin(A) ==> ALL z. z<=b --> z: Fin(A)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    60
by (etac Fin_induct 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    61
by (simp_tac (!simpset addsimps [subset_empty_iff]) 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    62
by (asm_simp_tac (!simpset addsimps subset_cons_iff::distrib_simps) 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    63
by (safe_tac (!claset));
534
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
    64
by (eres_inst_tac [("b","z")] (cons_Diff RS subst) 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    65
by (Asm_simp_tac 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
    66
qed "Fin_subset_lemma";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    67
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    68
goal Finite.thy "!!c b A. [| c<=b;  b: Fin(A) |] ==> c: Fin(A)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    69
by (REPEAT (ares_tac [Fin_subset_lemma RS spec RS mp] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
    70
qed "Fin_subset";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    71
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    72
val major::prems = goal Finite.thy 
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 803
diff changeset
    73
    "[| c: Fin(A);  b: Fin(A);                                  \
6bcb44e4d6e5 expanded tabs
clasohm
parents: 803
diff changeset
    74
\       P(b);                                                   \
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    75
\       !!x y. [| x: A;  y: Fin(A);  x:y;  P(y) |] ==> P(y-{x}) \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    76
\    |] ==> c<=b --> P(b-c)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    77
by (rtac (major RS Fin_induct) 1);
2033
639de962ded4 Ran expandshort; used stac instead of ssubst
paulson
parents: 1956
diff changeset
    78
by (stac Diff_cons 2);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    79
by (ALLGOALS (asm_simp_tac (!simpset addsimps (prems@[cons_subset_iff, 
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 803
diff changeset
    80
                                Diff_subset RS Fin_subset]))));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
    81
qed "Fin_0_induct_lemma";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    82
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    83
val prems = goal Finite.thy 
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 803
diff changeset
    84
    "[| b: Fin(A);                                              \
6bcb44e4d6e5 expanded tabs
clasohm
parents: 803
diff changeset
    85
\       P(b);                                                   \
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    86
\       !!x y. [| x: A;  y: Fin(A);  x:y;  P(y) |] ==> P(y-{x}) \
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    87
\    |] ==> P(0)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    88
by (rtac (Diff_cancel RS subst) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    89
by (rtac (Fin_0_induct_lemma RS mp) 1);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    90
by (REPEAT (ares_tac (subset_refl::prems) 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
    91
qed "Fin_0_induct";
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    92
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    93
(*Functions from a finite ordinal*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    94
val prems = goal Finite.thy "n: nat ==> n->A <= Fin(nat*A)";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents:
diff changeset
    95
by (nat_ind_tac "n" prems 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    96
by (simp_tac (!simpset addsimps [Pi_empty1, subset_iff, cons_iff]) 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    97
by (asm_simp_tac (!simpset addsimps [succ_def, mem_not_refl RS cons_fun_eq]) 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
    98
by (fast_tac (!claset addSIs [Fin.consI]) 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
    99
qed "nat_fun_subset_Fin";
534
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   100
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   101
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   102
(*** Finite function space ***)
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   103
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   104
goalw Finite.thy FiniteFun.defs
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   105
    "!!A B C D. [| A<=C;  B<=D |] ==> A -||> B  <=  C -||> D";
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   106
by (rtac lfp_mono 1);
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   107
by (REPEAT (rtac FiniteFun.bnd_mono 1));
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   108
by (REPEAT (ares_tac (Fin_mono::Sigma_mono::basic_monos) 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
   109
qed "FiniteFun_mono";
534
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   110
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   111
goal Finite.thy "!!A B. A<=B ==> A -||> A  <=  B -||> B";
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   112
by (REPEAT (ares_tac [FiniteFun_mono] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
   113
qed "FiniteFun_mono1";
534
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   114
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   115
goal Finite.thy "!!h. h: A -||>B ==> h: domain(h) -> B";
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   116
by (etac FiniteFun.induct 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   117
by (simp_tac (!simpset addsimps [empty_fun, domain_0]) 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   118
by (asm_simp_tac (!simpset addsimps [fun_extend3, domain_cons]) 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
   119
qed "FiniteFun_is_fun";
534
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   120
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   121
goal Finite.thy "!!h. h: A -||>B ==> domain(h) : Fin(A)";
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   122
by (etac FiniteFun.induct 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   123
by (simp_tac (!simpset addsimps [domain_0]) 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   124
by (asm_simp_tac (!simpset addsimps [domain_cons]) 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
   125
qed "FiniteFun_domain_Fin";
534
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   126
803
4c8333ab3eae changed useless "qed" calls for lemmas back to uses of "result",
lcp
parents: 760
diff changeset
   127
bind_thm ("FiniteFun_apply_type", FiniteFun_is_fun RS apply_type);
534
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   128
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   129
(*Every subset of a finite function is a finite function.*)
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   130
goal Finite.thy "!!b A. b: A-||>B ==> ALL z. z<=b --> z: A-||>B";
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   131
by (etac FiniteFun.induct 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   132
by (simp_tac (!simpset addsimps subset_empty_iff::FiniteFun.intrs) 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   133
by (asm_simp_tac (!simpset addsimps subset_cons_iff::distrib_simps) 1);
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   134
by (safe_tac (!claset));
534
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   135
by (eres_inst_tac [("b","z")] (cons_Diff RS subst) 1);
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   136
by (dtac (spec RS mp) 1 THEN assume_tac 1);
2469
b50b8c0eec01 Implicit simpsets and clasets for FOL and ZF
paulson
parents: 2033
diff changeset
   137
by (fast_tac (!claset addSIs FiniteFun.intrs) 1);
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
   138
qed "FiniteFun_subset_lemma";
534
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   139
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   140
goal Finite.thy "!!c b A. [| c<=b;  b: A-||>B |] ==> c: A-||>B";
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   141
by (REPEAT (ares_tac [FiniteFun_subset_lemma RS spec RS mp] 1));
760
f0200e91b272 added qed and qed_goal[w]
clasohm
parents: 534
diff changeset
   142
qed "FiniteFun_subset";
534
cd8bec47e175 ZF/Finite: added the finite function space, A-||>B
lcp
parents: 516
diff changeset
   143