src/HOL/Finite.ML
author nipkow
Mon, 04 Mar 1996 14:37:33 +0100
changeset 1531 e5eb247ad13c
parent 1465 5d7a7e439cec
child 1548 afe750876848
permissions -rw-r--r--
Added a constant UNIV == {x.True} Added many new rewrite rules for sets. Moved LEAST into Nat. Added cardinality to Finite.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
     1
(*  Title:      HOL/Finite.thy
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
     3
    Author:     Lawrence C Paulson & Tobias Nipkow
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
     4
    Copyright   1995  University of Cambridge & TU Muenchen
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
     6
Finite sets and their cardinality
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
open Finite;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    11
(*** Fin ***)
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    12
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
goalw Finite.thy Fin.defs "!!A B. A<=B ==> Fin(A) <= Fin(B)";
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    14
by (rtac lfp_mono 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
by (REPEAT (ares_tac basic_monos 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    16
qed "Fin_mono";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    17
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
goalw Finite.thy Fin.defs "Fin(A) <= Pow(A)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
by (fast_tac (set_cs addSIs [lfp_lowerbound]) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    20
qed "Fin_subset_Pow";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    21
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    22
(* A : Fin(B) ==> A <= B *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    23
val FinD = Fin_subset_Pow RS subsetD RS PowD;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    24
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    25
(*Discharging ~ x:y entails extra work*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    26
val major::prems = goal Finite.thy 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    27
    "[| F:Fin(A);  P({}); \
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    28
\       !!F x. [| x:A;  F:Fin(A);  x~:F;  P(F) |] ==> P(insert x F) \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
\    |] ==> P(F)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    30
by (rtac (major RS Fin.induct) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    31
by (excluded_middle_tac "a:b" 2);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
by (etac (insert_absorb RS ssubst) 3 THEN assume_tac 3);   (*backtracking!*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
by (REPEAT (ares_tac prems 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
qed "Fin_induct";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    35
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 923
diff changeset
    36
Addsimps Fin.intrs;
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    38
(*The union of two finite sets is finite*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    39
val major::prems = goal Finite.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
    "[| F: Fin(A);  G: Fin(A) |] ==> F Un G : Fin(A)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
by (rtac (major RS Fin_induct) 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 923
diff changeset
    42
by (ALLGOALS (asm_simp_tac (!simpset addsimps (prems @ [Un_insert_left]))));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    43
qed "Fin_UnI";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
(*Every subset of a finite set is finite*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    46
val [subs,fin] = goal Finite.thy "[| A<=B;  B: Fin(M) |] ==> A: Fin(M)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
by (EVERY1 [subgoal_tac "ALL C. C<=B --> C: Fin(M)",
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    48
            rtac mp, etac spec,
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    49
            rtac subs]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
by (rtac (fin RS Fin_induct) 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 923
diff changeset
    51
by (simp_tac (!simpset addsimps [subset_Un_eq]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    52
by (safe_tac (set_cs addSDs [subset_insert_iff RS iffD1]));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
by (eres_inst_tac [("t","C")] (insert_Diff RS subst) 2);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 923
diff changeset
    54
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
qed "Fin_subset";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    57
goal Finite.thy "(F Un G : Fin(A)) = (F: Fin(A) & G: Fin(A))";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    58
by(fast_tac (set_cs addIs [Fin_UnI] addDs
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    59
                [Un_upper1 RS Fin_subset, Un_upper2 RS Fin_subset]) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    60
qed "subset_Fin";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    61
Addsimps[subset_Fin];
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    62
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    63
goal Finite.thy "(insert a A : Fin M) = (a:M & A : Fin M)";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    64
by(stac insert_is_Un 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    65
by(Simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    66
by(fast_tac (set_cs addSIs Fin.intrs addDs [FinD]) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    67
qed "insert_Fin";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    68
Addsimps[insert_Fin];
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    69
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
(*The image of a finite set is finite*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
val major::_ = goal Finite.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    72
    "F: Fin(A) ==> h``F : Fin(h``A)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    73
by (rtac (major RS Fin_induct) 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 923
diff changeset
    74
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 923
diff changeset
    75
by (asm_simp_tac
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 923
diff changeset
    76
    (!simpset addsimps [image_eqI RS Fin.insertI, image_insert]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
qed "Fin_imageI";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    79
val major::prems = goal Finite.thy 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    80
    "[| c: Fin(A);  b: Fin(A);                                  \
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    81
\       P(b);                                                   \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    82
\       !!(x::'a) y. [| x:A; y: Fin(A);  x:y;  P(y) |] ==> P(y-{x}) \
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    83
\    |] ==> c<=b --> P(b-c)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    84
by (rtac (major RS Fin_induct) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    85
by (rtac (Diff_insert RS ssubst) 2);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    86
by (ALLGOALS (asm_simp_tac
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 923
diff changeset
    87
                (!simpset addsimps (prems@[Diff_subset RS Fin_subset]))));
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    88
val lemma = result();
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    90
val prems = goal Finite.thy 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    91
    "[| b: Fin(A);                                              \
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    92
\       P(b);                                                   \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    93
\       !!x y. [| x:A; y: Fin(A);  x:y;  P(y) |] ==> P(y-{x}) \
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    94
\    |] ==> P({})";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    95
by (rtac (Diff_cancel RS subst) 1);
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    96
by (rtac (lemma RS mp) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    97
by (REPEAT (ares_tac (subset_refl::prems) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    98
qed "Fin_empty_induct";
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    99
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   100
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   101
(*** finite ***)
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   102
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   103
val major::prems = goalw Finite.thy [finite_def]
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   104
    "[| finite F;  P({}); \
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   105
\       !!F x. [| finite F;  x~:F;  P(F) |] ==> P(insert x F) \
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   106
\    |] ==> P(F)";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   107
by (rtac (major RS Fin_induct) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   108
by (REPEAT (ares_tac prems 1));
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   109
qed "finite_induct";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   110
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   111
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   112
goalw Finite.thy [finite_def] "finite {}";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   113
by(Simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   114
qed "finite_emptyI";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   115
Addsimps [finite_emptyI];
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   116
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   117
goalw Finite.thy [finite_def] "!!A. finite A ==> finite(insert a A)";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   118
by(Asm_simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   119
qed "finite_insertI";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   120
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   121
(*The union of two finite sets is finite*)
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   122
goalw Finite.thy [finite_def]
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   123
    "!!F. [| finite F;  finite G |] ==> finite(F Un G)";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   124
by(Asm_simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   125
qed "finite_UnI";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   126
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   127
goalw Finite.thy [finite_def] "!!A. [| A<=B;  finite B |] ==> finite A";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   128
be Fin_subset 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   129
ba 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   130
qed "finite_subset";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   131
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   132
goalw Finite.thy [finite_def] "finite(F Un G) = (finite F & finite G)";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   133
by(Simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   134
qed "subset_finite";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   135
Addsimps[subset_finite];
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   136
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   137
goalw Finite.thy [finite_def] "finite(insert a A) = finite(A)";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   138
by(Simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   139
qed "insert_finite";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   140
Addsimps[insert_finite];
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   141
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   142
goal Finite.thy "!!A. finite(A) ==> finite(A-B)";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   143
be finite_induct 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   144
by(Simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   145
by(asm_simp_tac (!simpset addsimps [insert_Diff_if]
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   146
                          setloop split_tac[expand_if]) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   147
qed "finite_Diff";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   148
Addsimps [finite_Diff];
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   149
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   150
(*The image of a finite set is finite*)
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   151
goal Finite.thy "!!F. finite F ==> finite(h``F)";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   152
be finite_induct 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   153
by(ALLGOALS Asm_simp_tac);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   154
qed "finite_imageI";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   155
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   156
val major::prems = goalw Finite.thy [finite_def]
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   157
    "[| finite A;                                       \
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   158
\       P(A);                                           \
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   159
\       !!a A. [| finite A;  a:A;  P(A) |] ==> P(A-{a}) \
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   160
\    |] ==> P({})";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   161
by (rtac (major RS Fin_empty_induct) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   162
by (REPEAT (ares_tac (subset_refl::prems) 1));
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   163
qed "finite_empty_induct";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   164
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   165
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   166
(*** Cardinality ***)
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   167
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   168
goal Set.thy "{f i |i. P i | i=n} = insert (f n) {f i|i. P i}";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   169
by(fast_tac eq_cs 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   170
val Collect_conv_insert = result();
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   171
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   172
goalw Finite.thy [card_def] "card {} = 0";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   173
br Least_equality 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   174
by(ALLGOALS Asm_full_simp_tac);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   175
qed "card_empty";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   176
Addsimps [card_empty];
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   177
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   178
(*Addsimps [Collect_conv_insert];*)
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   179
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   180
val [major] = goal Finite.thy
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   181
  "finite A ==> ? (n::nat) f. A = {f i |i. i<n}";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   182
br (major RS finite_induct) 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   183
 by(res_inst_tac [("x","0")] exI 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   184
 by(Simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   185
be exE 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   186
be exE 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   187
by(hyp_subst_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   188
by(res_inst_tac [("x","Suc n")] exI 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   189
by(res_inst_tac [("x","%i. if i<n then f i else x")] exI 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   190
by(asm_simp_tac (!simpset addsimps [Collect_conv_insert]
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   191
                          addcongs [Collect_cong1]) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   192
qed "finite_has_card";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   193
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   194
goal Finite.thy
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   195
  "!!A.[| x ~: A; insert x A = {f i|i.i<n} |] ==> \
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   196
\  ? m::nat. m<n & (? g. A = {g i|i.i<m})";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   197
by(res_inst_tac [("n","n")] natE 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   198
 by(hyp_subst_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   199
 by(Asm_full_simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   200
by(rename_tac "m" 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   201
by(hyp_subst_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   202
by(case_tac "? a. a:A" 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   203
 by(res_inst_tac [("x","0")] exI 2);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   204
 by(Simp_tac 2);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   205
 by(fast_tac eq_cs 2);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   206
be exE 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   207
by(Simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   208
br exI 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   209
br conjI 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   210
 br disjI2 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   211
 br refl 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   212
be equalityE 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   213
by(asm_full_simp_tac
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   214
     (!simpset addsimps [subset_insert,Collect_conv_insert]) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   215
by(SELECT_GOAL(safe_tac eq_cs)1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   216
  by(Asm_full_simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   217
  by(res_inst_tac [("x","%i. if f i = f m then a else f i")] exI 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   218
  by(SELECT_GOAL(safe_tac eq_cs)1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   219
   by(subgoal_tac "x ~= f m" 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   220
    by(fast_tac set_cs 2);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   221
   by(subgoal_tac "? k. f k = x & k<m" 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   222
    by(best_tac set_cs 2);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   223
   by(SELECT_GOAL(safe_tac HOL_cs)1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   224
   by(res_inst_tac [("x","k")] exI 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   225
   by(Asm_simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   226
  by(simp_tac (!simpset setloop (split_tac [expand_if])) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   227
  by(best_tac set_cs 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   228
 bd sym 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   229
 by(rotate_tac ~1 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   230
 by(Asm_full_simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   231
 by(res_inst_tac [("x","%i. if f i = f m then a else f i")] exI 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   232
 by(SELECT_GOAL(safe_tac eq_cs)1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   233
  by(subgoal_tac "x ~= f m" 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   234
   by(fast_tac set_cs 2);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   235
  by(subgoal_tac "? k. f k = x & k<m" 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   236
   by(best_tac set_cs 2);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   237
  by(SELECT_GOAL(safe_tac HOL_cs)1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   238
  by(res_inst_tac [("x","k")] exI 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   239
  by(Asm_simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   240
 by(simp_tac (!simpset setloop (split_tac [expand_if])) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   241
 by(best_tac set_cs 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   242
by(res_inst_tac [("x","%j. if f j = f i then f m else f j")] exI 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   243
by(SELECT_GOAL(safe_tac eq_cs)1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   244
 by(subgoal_tac "x ~= f i" 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   245
  by(fast_tac set_cs 2);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   246
 by(case_tac "x = f m" 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   247
  by(res_inst_tac [("x","i")] exI 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   248
  by(Asm_simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   249
 by(subgoal_tac "? k. f k = x & k<m" 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   250
  by(best_tac set_cs 2);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   251
 by(SELECT_GOAL(safe_tac HOL_cs)1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   252
 by(res_inst_tac [("x","k")] exI 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   253
 by(Asm_simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   254
by(simp_tac (!simpset setloop (split_tac [expand_if])) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   255
by(best_tac set_cs 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   256
val lemma = result();
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   257
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   258
goal Finite.thy "!!A. [| finite A; x ~: A |] ==> \
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   259
\ (LEAST n. ? f. insert x A = {f i|i.i<n}) = Suc(LEAST n. ? f. A={f i|i.i<n})";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   260
br Least_equality 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   261
 bd finite_has_card 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   262
 be exE 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   263
 by(dres_inst_tac [("P","%n.? f. A={f i|i.i<n}")] LeastI 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   264
 be exE 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   265
 by(res_inst_tac
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   266
   [("x","%i. if i<(LEAST n. ? f. A={f i |i. i < n}) then f i else x")] exI 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   267
 by(simp_tac
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   268
    (!simpset addsimps [Collect_conv_insert] addcongs [Collect_cong1]) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   269
 be subst 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   270
 br refl 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   271
br notI 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   272
be exE 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   273
bd lemma 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   274
 ba 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   275
be exE 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   276
be conjE 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   277
by(dres_inst_tac [("P","%x. ? g. A = {g i |i. i < x}")] Least_le 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   278
by(dtac le_less_trans 1 THEN atac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   279
by(Asm_full_simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   280
be disjE 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   281
by(etac less_asym 1 THEN atac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   282
by(hyp_subst_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   283
by(Asm_full_simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   284
val lemma = result();
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   285
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   286
goalw Finite.thy [card_def]
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   287
  "!!A. [| finite A; x ~: A |] ==> card(insert x A) = Suc(card A)";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   288
be lemma 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   289
ba 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   290
qed "card_insert_disjoint";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   291
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   292
val [major] = goal Finite.thy
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   293
  "finite A ==> card(insert x A) = Suc(card(A-{x}))";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   294
by(case_tac "x:A" 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   295
by(asm_simp_tac (!simpset addsimps [insert_absorb]) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   296
bd mk_disjoint_insert 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   297
be exE 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   298
by(Asm_simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   299
br card_insert_disjoint 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   300
br (major RSN (2,finite_subset)) 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   301
by(fast_tac set_cs 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   302
by(fast_tac HOL_cs 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   303
by(asm_simp_tac (!simpset addsimps [major RS card_insert_disjoint]) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   304
qed "card_insert";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   305
Addsimps [card_insert];
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   306
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   307
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   308
goal Finite.thy  "!!A. finite A ==> !B. B <= A --> card(B) <= card(A)";
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   309
be finite_induct 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   310
by(Simp_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   311
by(strip_tac 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   312
by(case_tac "x:B" 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   313
 bd mk_disjoint_insert 1;
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   314
 by(SELECT_GOAL(safe_tac HOL_cs)1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   315
 by(rotate_tac ~1 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   316
 by(asm_full_simp_tac (!simpset addsimps [subset_insert_iff,finite_subset]) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   317
by(rotate_tac ~1 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   318
by(asm_full_simp_tac (!simpset addsimps [subset_insert_iff,finite_subset]) 1);
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   319
qed_spec_mp "card_mono";