| 
4776
 | 
     1  | 
(*  Title:      HOL/LessThan/LessThan
  | 
| 
 | 
     2  | 
    ID:         $Id$
  | 
| 
 | 
     3  | 
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
  | 
| 
 | 
     4  | 
    Copyright   1998  University of Cambridge
  | 
| 
 | 
     5  | 
  | 
| 
 | 
     6  | 
lessThan, greaterThan, atLeast, atMost
  | 
| 
 | 
     7  | 
*)
  | 
| 
 | 
     8  | 
  | 
| 
 | 
     9  | 
  | 
| 
5983
 | 
    10  | 
(*Make Auto_tac and Force_tac try lin_arith_tac!*)
  | 
| 
 | 
    11  | 
claset_ref() := claset() addaltern ("lin_arith_tac",Fast_Nat_Arith.lin_arith_tac);
 | 
| 
5320
 | 
    12  | 
  | 
| 
 | 
    13  | 
  | 
| 
4776
 | 
    14  | 
(*** lessThan ***)
  | 
| 
 | 
    15  | 
  | 
| 
5069
 | 
    16  | 
Goalw [lessThan_def] "(i: lessThan k) = (i<k)";
  | 
| 
4776
 | 
    17  | 
by (Blast_tac 1);
  | 
| 
 | 
    18  | 
qed "lessThan_iff";
  | 
| 
 | 
    19  | 
AddIffs [lessThan_iff];
  | 
| 
 | 
    20  | 
  | 
| 
5069
 | 
    21  | 
Goalw [lessThan_def] "lessThan 0 = {}";
 | 
| 
4776
 | 
    22  | 
by (Simp_tac 1);
  | 
| 
 | 
    23  | 
qed "lessThan_0";
  | 
| 
 | 
    24  | 
Addsimps [lessThan_0];
  | 
| 
 | 
    25  | 
  | 
| 
5069
 | 
    26  | 
Goalw [lessThan_def] "lessThan (Suc k) = insert k (lessThan k)";
  | 
| 
4776
 | 
    27  | 
by (simp_tac (simpset() addsimps [less_Suc_eq]) 1);
  | 
| 
 | 
    28  | 
by (Blast_tac 1);
  | 
| 
 | 
    29  | 
qed "lessThan_Suc";
  | 
| 
 | 
    30  | 
  | 
| 
5648
 | 
    31  | 
Goalw [lessThan_def, atMost_def] "lessThan (Suc k) = atMost k";
  | 
| 
 | 
    32  | 
by (simp_tac (simpset() addsimps [less_Suc_eq_le]) 1);
  | 
| 
 | 
    33  | 
qed "lessThan_Suc_atMost";
  | 
| 
 | 
    34  | 
  | 
| 
5069
 | 
    35  | 
Goal "(UN m. lessThan m) = UNIV";
  | 
| 
4776
 | 
    36  | 
by (Blast_tac 1);
  | 
| 
 | 
    37  | 
qed "UN_lessThan_UNIV";
  | 
| 
 | 
    38  | 
  | 
| 
5069
 | 
    39  | 
Goalw [lessThan_def, atLeast_def, le_def]
  | 
| 
5490
 | 
    40  | 
    "-lessThan k = atLeast k";
  | 
| 
4776
 | 
    41  | 
by (Blast_tac 1);
  | 
| 
 | 
    42  | 
qed "Compl_lessThan";
  | 
| 
 | 
    43  | 
  | 
| 
 | 
    44  | 
  | 
| 
 | 
    45  | 
(*** greaterThan ***)
  | 
| 
 | 
    46  | 
  | 
| 
5069
 | 
    47  | 
Goalw [greaterThan_def] "(i: greaterThan k) = (k<i)";
  | 
| 
4776
 | 
    48  | 
by (Blast_tac 1);
  | 
| 
 | 
    49  | 
qed "greaterThan_iff";
  | 
| 
 | 
    50  | 
AddIffs [greaterThan_iff];
  | 
| 
 | 
    51  | 
  | 
| 
5069
 | 
    52  | 
Goalw [greaterThan_def] "greaterThan 0 = range Suc";
  | 
| 
4776
 | 
    53  | 
by (blast_tac (claset() addIs [Suc_pred RS sym]) 1);
  | 
| 
 | 
    54  | 
qed "greaterThan_0";
  | 
| 
 | 
    55  | 
Addsimps [greaterThan_0];
  | 
| 
 | 
    56  | 
  | 
| 
5069
 | 
    57  | 
Goalw [greaterThan_def] "greaterThan (Suc k) = greaterThan k - {Suc k}";
 | 
| 
5625
 | 
    58  | 
by (auto_tac (claset() addEs [linorder_neqE], simpset()));
  | 
| 
4776
 | 
    59  | 
qed "greaterThan_Suc";
  | 
| 
 | 
    60  | 
  | 
| 
5069
 | 
    61  | 
Goal "(INT m. greaterThan m) = {}";
 | 
| 
4776
 | 
    62  | 
by (Blast_tac 1);
  | 
| 
 | 
    63  | 
qed "INT_greaterThan_UNIV";
  | 
| 
 | 
    64  | 
  | 
| 
5069
 | 
    65  | 
Goalw [greaterThan_def, atMost_def, le_def]
  | 
| 
5490
 | 
    66  | 
    "-greaterThan k = atMost k";
  | 
| 
4776
 | 
    67  | 
by (Blast_tac 1);
  | 
| 
 | 
    68  | 
qed "Compl_greaterThan";
  | 
| 
 | 
    69  | 
  | 
| 
5069
 | 
    70  | 
Goalw [greaterThan_def, atMost_def, le_def]
  | 
| 
5490
 | 
    71  | 
    "-atMost k = greaterThan k";
  | 
| 
4776
 | 
    72  | 
by (Blast_tac 1);
  | 
| 
 | 
    73  | 
qed "Compl_atMost";
  | 
| 
 | 
    74  | 
  | 
| 
5069
 | 
    75  | 
Goal "less_than ^^ {k} = greaterThan k";
 | 
| 
4776
 | 
    76  | 
by (Blast_tac 1);
  | 
| 
 | 
    77  | 
qed "Image_less_than";
  | 
| 
 | 
    78  | 
  | 
| 
 | 
    79  | 
Addsimps [Compl_greaterThan, Compl_atMost, Image_less_than];
  | 
| 
 | 
    80  | 
  | 
| 
 | 
    81  | 
(*** atLeast ***)
  | 
| 
 | 
    82  | 
  | 
| 
5069
 | 
    83  | 
Goalw [atLeast_def] "(i: atLeast k) = (k<=i)";
  | 
| 
4776
 | 
    84  | 
by (Blast_tac 1);
  | 
| 
 | 
    85  | 
qed "atLeast_iff";
  | 
| 
 | 
    86  | 
AddIffs [atLeast_iff];
  | 
| 
 | 
    87  | 
  | 
| 
5069
 | 
    88  | 
Goalw [atLeast_def, UNIV_def] "atLeast 0 = UNIV";
  | 
| 
4776
 | 
    89  | 
by (Simp_tac 1);
  | 
| 
 | 
    90  | 
qed "atLeast_0";
  | 
| 
 | 
    91  | 
Addsimps [atLeast_0];
  | 
| 
 | 
    92  | 
  | 
| 
5069
 | 
    93  | 
Goalw [atLeast_def] "atLeast (Suc k) = atLeast k - {k}";
 | 
| 
4776
 | 
    94  | 
by (simp_tac (simpset() addsimps [Suc_le_eq]) 1);
  | 
| 
5596
 | 
    95  | 
by (simp_tac (simpset() addsimps [order_le_less]) 1);
  | 
| 
4776
 | 
    96  | 
by (Blast_tac 1);
  | 
| 
 | 
    97  | 
qed "atLeast_Suc";
  | 
| 
 | 
    98  | 
  | 
| 
5069
 | 
    99  | 
Goal "(UN m. atLeast m) = UNIV";
  | 
| 
4776
 | 
   100  | 
by (Blast_tac 1);
  | 
| 
 | 
   101  | 
qed "UN_atLeast_UNIV";
  | 
| 
 | 
   102  | 
  | 
| 
5069
 | 
   103  | 
Goalw [lessThan_def, atLeast_def, le_def]
  | 
| 
5490
 | 
   104  | 
    "-atLeast k = lessThan k";
  | 
| 
4776
 | 
   105  | 
by (Blast_tac 1);
  | 
| 
 | 
   106  | 
qed "Compl_atLeast";
  | 
| 
 | 
   107  | 
  | 
| 
5069
 | 
   108  | 
Goal "less_than^-1 ^^ {k} = lessThan k";
 | 
| 
4776
 | 
   109  | 
by (Blast_tac 1);
  | 
| 
 | 
   110  | 
qed "Image_inverse_less_than";
  | 
| 
 | 
   111  | 
  | 
| 
 | 
   112  | 
Addsimps [Compl_lessThan, Compl_atLeast, Image_inverse_less_than];
  | 
| 
 | 
   113  | 
  | 
| 
 | 
   114  | 
(*** atMost ***)
  | 
| 
 | 
   115  | 
  | 
| 
5069
 | 
   116  | 
Goalw [atMost_def] "(i: atMost k) = (i<=k)";
  | 
| 
4776
 | 
   117  | 
by (Blast_tac 1);
  | 
| 
 | 
   118  | 
qed "atMost_iff";
  | 
| 
 | 
   119  | 
AddIffs [atMost_iff];
  | 
| 
 | 
   120  | 
  | 
| 
5069
 | 
   121  | 
Goalw [atMost_def] "atMost 0 = {0}";
 | 
| 
4776
 | 
   122  | 
by (Simp_tac 1);
  | 
| 
 | 
   123  | 
qed "atMost_0";
  | 
| 
 | 
   124  | 
Addsimps [atMost_0];
  | 
| 
 | 
   125  | 
  | 
| 
5069
 | 
   126  | 
Goalw [atMost_def] "atMost (Suc k) = insert (Suc k) (atMost k)";
  | 
| 
5596
 | 
   127  | 
by (simp_tac (simpset() addsimps [less_Suc_eq, order_le_less]) 1);
  | 
| 
4776
 | 
   128  | 
by (Blast_tac 1);
  | 
| 
 | 
   129  | 
qed "atMost_Suc";
  | 
| 
 | 
   130  | 
  | 
| 
5069
 | 
   131  | 
Goal "(UN m. atMost m) = UNIV";
  | 
| 
4776
 | 
   132  | 
by (Blast_tac 1);
  | 
| 
 | 
   133  | 
qed "UN_atMost_UNIV";
  | 
| 
 | 
   134  | 
  | 
| 
5069
 | 
   135  | 
Goalw [atMost_def, le_def]
  | 
| 
5490
 | 
   136  | 
    "-atMost k = greaterThan k";
  | 
| 
4776
 | 
   137  | 
by (Blast_tac 1);
  | 
| 
 | 
   138  | 
qed "Compl_atMost";
  | 
| 
 | 
   139  | 
Addsimps [Compl_atMost];
  | 
| 
 | 
   140  | 
  | 
| 
 | 
   141  | 
  | 
| 
 | 
   142  | 
(*** Combined properties ***)
  | 
| 
 | 
   143  | 
  | 
| 
5069
 | 
   144  | 
Goal "atMost n Int atLeast n = {n}";
 | 
| 
4776
 | 
   145  | 
by (blast_tac (claset() addIs [le_anti_sym]) 1);
  | 
| 
 | 
   146  | 
qed "atMost_Int_atLeast";
  | 
| 
 | 
   147  | 
  | 
| 
 | 
   148  | 
  | 
| 
5232
 | 
   149  | 
  | 
| 
 | 
   150  | 
  | 
| 
 | 
   151  | 
(*** Finally, a few set-theoretic laws...
  | 
| 
 | 
   152  | 
     CAN BOOLEAN SIMPLIFICATION BE AUTOMATED? ***)
  | 
| 
 | 
   153  | 
  | 
| 
 | 
   154  | 
context Set.thy;
  | 
| 
 | 
   155  | 
  | 
| 
5490
 | 
   156  | 
(** Rewrite rules to eliminate A.  Conditions can be satisfied by letting B
  | 
| 
5232
 | 
   157  | 
    be any set including A Int C and contained in A Un C, such as B=A or B=C.
  | 
| 
 | 
   158  | 
**)
  | 
| 
 | 
   159  | 
  | 
| 
 | 
   160  | 
Goal "[| A Int C <= B; B <= A Un C |] \
  | 
| 
5490
 | 
   161  | 
\     ==> (A Int B) Un (-A Int C) = B Un C";
  | 
| 
5232
 | 
   162  | 
by (Blast_tac 1);
  | 
| 
5490
 | 
   163  | 
qed "set_cancel1";
  | 
| 
5232
 | 
   164  | 
  | 
| 
 | 
   165  | 
Goal "[| A Int C <= B; B <= A Un C |] \
  | 
| 
5490
 | 
   166  | 
\     ==> (A Un B) Int (-A Un C) = B Int C";
  | 
| 
5232
 | 
   167  | 
by (Blast_tac 1);
  | 
| 
5490
 | 
   168  | 
qed "set_cancel2";
  | 
| 
5232
 | 
   169  | 
  | 
| 
 | 
   170  | 
(*The base B=A*)
  | 
| 
5490
 | 
   171  | 
Goal "A Un (-A Int C) = A Un C";
  | 
| 
5232
 | 
   172  | 
by (Blast_tac 1);
  | 
| 
5490
 | 
   173  | 
qed "set_cancel3";
  | 
| 
5232
 | 
   174  | 
  | 
| 
5490
 | 
   175  | 
Goal "A Int (-A Un C) = A Int C";
  | 
| 
5232
 | 
   176  | 
by (Blast_tac 1);
  | 
| 
5490
 | 
   177  | 
qed "set_cancel4";
  | 
| 
5232
 | 
   178  | 
  | 
| 
 | 
   179  | 
(*The base B=C*)
  | 
| 
5490
 | 
   180  | 
Goal "(A Int C) Un (-A Int C) = C";
  | 
| 
5232
 | 
   181  | 
by (Blast_tac 1);
  | 
| 
5490
 | 
   182  | 
qed "set_cancel5";
  | 
| 
5232
 | 
   183  | 
  | 
| 
5490
 | 
   184  | 
Goal "(A Un C) Int (-A Un C) = C";
  | 
| 
5232
 | 
   185  | 
by (Blast_tac 1);
  | 
| 
5490
 | 
   186  | 
qed "set_cancel6";
  | 
| 
 | 
   187  | 
  | 
| 
 | 
   188  | 
Addsimps [set_cancel1, set_cancel2, set_cancel3,
  | 
| 
 | 
   189  | 
	  set_cancel4, set_cancel5, set_cancel6];
  | 
| 
5232
 | 
   190  | 
  | 
| 
 | 
   191  | 
  | 
| 
 | 
   192  | 
(** More ad-hoc rules **)
  | 
| 
 | 
   193  | 
  | 
| 
 | 
   194  | 
Goal "A Un B - (A - B) = B";
  | 
| 
 | 
   195  | 
by (Blast_tac 1);
  | 
| 
 | 
   196  | 
qed "Un_Diff_Diff";
  | 
| 
5490
 | 
   197  | 
Addsimps [Un_Diff_Diff];
  | 
| 
5232
 | 
   198  | 
  | 
| 
 | 
   199  | 
Goal "A Int (B - C) Un C = A Int B Un C";
  | 
| 
 | 
   200  | 
by (Blast_tac 1);
  | 
| 
 | 
   201  | 
qed "Int_Diff_Un";
  | 
| 
 | 
   202  | 
  | 
| 
 | 
   203  | 
Goal "Union(B) Int A = (UN C:B. C Int A)";
  | 
| 
 | 
   204  | 
by (Blast_tac 1);
  | 
| 
 | 
   205  | 
qed "Int_Union2";
  | 
| 
 | 
   206  | 
  | 
| 
 | 
   207  | 
Goal "Union(B) Int A = Union((%C. C Int A)``B)";
  | 
| 
 | 
   208  | 
by (Blast_tac 1);
  | 
| 
 | 
   209  | 
qed "Int_Union_Union";
  | 
| 
 | 
   210  | 
  |