src/HOL/Ord.ML
author wenzelm
Fri Jun 04 19:58:06 1999 +0200 (1999-06-04)
changeset 6780 769cea1985e4
parent 6433 228237ec56e5
child 6814 d96d4977f94e
permissions -rw-r--r--
added order_le_less_trans, order_less_le_trans;
clasohm@1465
     1
(*  Title:      HOL/Ord.ML
clasohm@923
     2
    ID:         $Id$
clasohm@1465
     3
    Author:     Tobias Nipkow, Cambridge University Computer Laboratory
clasohm@923
     4
    Copyright   1993  University of Cambridge
clasohm@923
     5
clasohm@923
     6
The type class for ordered types
clasohm@923
     7
*)
clasohm@923
     8
paulson@5449
     9
(*Tell Blast_tac about overloading of < and <= to reduce the risk of
paulson@5449
    10
  its applying a rule for the wrong type*)
paulson@5449
    11
Blast.overloaded ("op <", domain_type); 
paulson@5449
    12
Blast.overloaded ("op <=", domain_type);
paulson@5449
    13
nipkow@2608
    14
(** mono **)
clasohm@923
    15
paulson@5316
    16
val [prem] = Goalw [mono_def]
clasohm@923
    17
    "[| !!A B. A <= B ==> f(A) <= f(B) |] ==> mono(f)";
clasohm@923
    18
by (REPEAT (ares_tac [allI, impI, prem] 1));
clasohm@923
    19
qed "monoI";
clasohm@923
    20
paulson@5316
    21
Goalw [mono_def] "[| mono(f);  A <= B |] ==> f(A) <= f(B)";
paulson@5316
    22
by (Fast_tac 1);
clasohm@923
    23
qed "monoD";
clasohm@923
    24
nipkow@2608
    25
nipkow@2608
    26
section "Orders";
nipkow@2608
    27
paulson@5538
    28
(** Reflexivity **)
paulson@5538
    29
nipkow@6115
    30
AddIffs [order_refl];
nipkow@2608
    31
paulson@4600
    32
(*This form is useful with the classical reasoner*)
wenzelm@5069
    33
Goal "!!x::'a::order. x = y ==> x <= y";
paulson@4600
    34
by (etac ssubst 1);
paulson@4600
    35
by (rtac order_refl 1);
paulson@4600
    36
qed "order_eq_refl";
paulson@4600
    37
wenzelm@5069
    38
Goal "~ x < (x::'a::order)";
wenzelm@4089
    39
by (simp_tac (simpset() addsimps [order_less_le]) 1);
nipkow@2608
    40
qed "order_less_irrefl";
paulson@5449
    41
Addsimps [order_less_irrefl];
nipkow@2608
    42
wenzelm@5069
    43
Goal "(x::'a::order) <= y = (x < y | x = y)";
wenzelm@4089
    44
by (simp_tac (simpset() addsimps [order_less_le]) 1);
paulson@5449
    45
   (*NOT suitable for AddIffs, since it can cause PROOF FAILED*)
paulson@5449
    46
by (blast_tac (claset() addSIs [order_refl]) 1);
nipkow@2608
    47
qed "order_le_less";
nipkow@2608
    48
paulson@5538
    49
(** Asymmetry **)
paulson@5538
    50
paulson@5538
    51
Goal "(x::'a::order) < y ==> ~ (y<x)";
paulson@5538
    52
by (asm_full_simp_tac (simpset() addsimps [order_less_le, order_antisym]) 1);
paulson@5538
    53
qed "order_less_not_sym";
paulson@5538
    54
paulson@5538
    55
(* [| n<m;  ~P ==> m<n |] ==> P *)
paulson@5538
    56
bind_thm ("order_less_asym", order_less_not_sym RS swap);
paulson@5538
    57
nipkow@6073
    58
(* Transitivity *)
nipkow@6073
    59
nipkow@6073
    60
Goal "!!x::'a::order. [| x < y; y < z |] ==> x < z";
nipkow@6073
    61
by (asm_full_simp_tac (simpset() addsimps [order_less_le]) 1);
nipkow@6073
    62
by (blast_tac (claset() addIs [order_trans,order_antisym]) 1);
nipkow@6073
    63
qed "order_less_trans";
nipkow@6073
    64
wenzelm@6780
    65
Goal "!!x::'a::order. [| x <= y; y < z |] ==> x < z";
wenzelm@6780
    66
by (asm_full_simp_tac (simpset() addsimps [order_less_le]) 1);
wenzelm@6780
    67
by (blast_tac (claset() addIs [order_trans,order_antisym]) 1);
wenzelm@6780
    68
qed "order_le_less_trans";
wenzelm@6780
    69
wenzelm@6780
    70
Goal "!!x::'a::order. [| x < y; y <= z |] ==> x < z";
wenzelm@6780
    71
by (asm_full_simp_tac (simpset() addsimps [order_less_le]) 1);
wenzelm@6780
    72
by (blast_tac (claset() addIs [order_trans,order_antisym]) 1);
wenzelm@6780
    73
qed "order_less_le_trans";
wenzelm@6780
    74
paulson@5538
    75
paulson@5538
    76
(** Useful for simplification, but too risky to include by default. **)
paulson@5538
    77
paulson@5538
    78
Goal "(x::'a::order) < y ==>  (~ y < x) = True";
paulson@5538
    79
by (blast_tac (claset() addEs [order_less_asym]) 1);
paulson@5538
    80
qed "order_less_imp_not_less";
paulson@5538
    81
paulson@5538
    82
Goal "(x::'a::order) < y ==>  (y < x --> P) = True";
paulson@5538
    83
by (blast_tac (claset() addEs [order_less_asym]) 1);
paulson@5538
    84
qed "order_less_imp_triv";
paulson@5538
    85
paulson@5538
    86
Goal "(x::'a::order) < y ==>  (x = y) = False";
paulson@5538
    87
by Auto_tac;
paulson@5538
    88
qed "order_less_imp_not_eq";
paulson@5538
    89
paulson@5538
    90
Goal "(x::'a::order) < y ==>  (y = x) = False";
paulson@5538
    91
by Auto_tac;
paulson@5538
    92
qed "order_less_imp_not_eq2";
paulson@5538
    93
paulson@5538
    94
nipkow@2608
    95
(** min **)
nipkow@2608
    96
paulson@5143
    97
val prems = Goalw [min_def] "(!!x. least <= x) ==> min least x = least";
paulson@5143
    98
by (simp_tac (simpset() addsimps prems) 1);
nipkow@2608
    99
qed "min_leastL";
nipkow@2608
   100
paulson@5316
   101
val prems = Goalw [min_def]
nipkow@2608
   102
 "(!!x::'a::order. least <= x) ==> min x least = least";
paulson@2935
   103
by (cut_facts_tac prems 1);
paulson@2935
   104
by (Asm_simp_tac 1);
wenzelm@4089
   105
by (blast_tac (claset() addIs [order_antisym]) 1);
nipkow@2608
   106
qed "min_leastR";
nipkow@4640
   107
nipkow@4640
   108
nipkow@4640
   109
section "Linear/Total Orders";
nipkow@4640
   110
wenzelm@5069
   111
Goal "!!x::'a::linorder. x<y | x=y | y<x";
nipkow@4640
   112
by (simp_tac (simpset() addsimps [order_less_le]) 1);
wenzelm@5132
   113
by (cut_facts_tac [linorder_linear] 1);
nipkow@4640
   114
by (Blast_tac 1);
nipkow@4640
   115
qed "linorder_less_linear";
nipkow@4640
   116
nipkow@6128
   117
Goal "!!x::'a::linorder. (~ x < y) = (y <= x)";
nipkow@6128
   118
by (simp_tac (simpset() addsimps [order_less_le]) 1);
nipkow@6128
   119
by (cut_facts_tac [linorder_linear] 1);
nipkow@6128
   120
by (blast_tac (claset() addIs [order_antisym]) 1);
nipkow@6128
   121
qed "linorder_not_less";
nipkow@6128
   122
nipkow@6128
   123
Goal "!!x::'a::linorder. (~ x <= y) = (y < x)";
nipkow@6128
   124
by (simp_tac (simpset() addsimps [order_less_le]) 1);
nipkow@6128
   125
by (cut_facts_tac [linorder_linear] 1);
nipkow@6128
   126
by (blast_tac (claset() addIs [order_antisym]) 1);
nipkow@6128
   127
qed "linorder_not_le";
nipkow@6128
   128
nipkow@6128
   129
Goal "!!x::'a::linorder. (x ~= y) = (x<y | y<x)";
nipkow@6128
   130
by (cut_inst_tac [("x","x"),("y","y")] linorder_less_linear 1);
nipkow@6128
   131
by Auto_tac;
nipkow@6128
   132
qed "linorder_neq_iff";
nipkow@6128
   133
nipkow@6128
   134
(* eliminates ~= in premises *)
nipkow@6128
   135
bind_thm("linorder_neqE", linorder_neq_iff RS iffD1 RS disjE);
nipkow@6128
   136
nipkow@6128
   137
(** min & max **)
nipkow@6128
   138
nipkow@6433
   139
Goalw [min_def] "min (x::'a::order) x = x";
nipkow@6433
   140
by(Simp_tac 1);
nipkow@6433
   141
qed "min_same";
nipkow@6433
   142
Addsimps [min_same];
nipkow@6433
   143
nipkow@6433
   144
Goalw [max_def] "max (x::'a::order) x = x";
nipkow@6433
   145
by(Simp_tac 1);
nipkow@6433
   146
qed "max_same";
nipkow@6433
   147
Addsimps [max_same];
nipkow@6433
   148
wenzelm@5069
   149
Goalw [max_def] "!!z::'a::linorder. (z <= max x y) = (z <= x | z <= y)";
nipkow@4686
   150
by (Simp_tac 1);
wenzelm@5132
   151
by (cut_facts_tac [linorder_linear] 1);
nipkow@4640
   152
by (blast_tac (claset() addIs [order_trans]) 1);
nipkow@4640
   153
qed "le_max_iff_disj";
nipkow@4640
   154
nipkow@6073
   155
Goalw [max_def] "!!z::'a::linorder. (z < max x y) = (z < x | z < y)";
nipkow@6073
   156
by (simp_tac (simpset() addsimps [order_le_less]) 1);
nipkow@6073
   157
by (cut_facts_tac [linorder_less_linear] 1);
nipkow@6073
   158
by (blast_tac (claset() addIs [order_less_trans]) 1);
nipkow@6073
   159
qed "less_max_iff_disj";
nipkow@6073
   160
wenzelm@5069
   161
Goalw [max_def] "!!z::'a::linorder. (max x y <= z) = (x <= z & y <= z)";
nipkow@4686
   162
by (Simp_tac 1);
wenzelm@5132
   163
by (cut_facts_tac [linorder_linear] 1);
nipkow@4640
   164
by (blast_tac (claset() addIs [order_trans]) 1);
nipkow@4640
   165
qed "max_le_iff_conj";
nipkow@5673
   166
Addsimps [max_le_iff_conj];
nipkow@4640
   167
nipkow@6433
   168
Goalw [max_def] "!!z::'a::linorder. (max x y < z) = (x < z & y < z)";
nipkow@6433
   169
by (simp_tac (simpset() addsimps [order_le_less]) 1);
nipkow@6433
   170
by (cut_facts_tac [linorder_less_linear] 1);
nipkow@6433
   171
by (blast_tac (claset() addIs [order_less_trans]) 1);
nipkow@6433
   172
qed "max_less_iff_conj";
nipkow@6433
   173
Addsimps [max_less_iff_conj];
nipkow@6433
   174
wenzelm@5069
   175
Goalw [min_def] "!!z::'a::linorder. (z <= min x y) = (z <= x & z <= y)";
nipkow@4686
   176
by (Simp_tac 1);
wenzelm@5132
   177
by (cut_facts_tac [linorder_linear] 1);
nipkow@4640
   178
by (blast_tac (claset() addIs [order_trans]) 1);
nipkow@4640
   179
qed "le_min_iff_conj";
nipkow@5673
   180
Addsimps [le_min_iff_conj];
nipkow@5673
   181
(* AddIffs screws up a blast_tac in MiniML *)
nipkow@4640
   182
nipkow@6433
   183
Goalw [min_def] "!!z::'a::linorder. (z < min x y) = (z < x & z < y)";
nipkow@6433
   184
by (simp_tac (simpset() addsimps [order_le_less]) 1);
nipkow@6433
   185
by (cut_facts_tac [linorder_less_linear] 1);
nipkow@6433
   186
by (blast_tac (claset() addIs [order_less_trans]) 1);
nipkow@6433
   187
qed "min_less_iff_conj";
nipkow@6433
   188
Addsimps [min_less_iff_conj];
nipkow@6433
   189
wenzelm@5069
   190
Goalw [min_def] "!!z::'a::linorder. (min x y <= z) = (x <= z | y <= z)";
nipkow@4686
   191
by (Simp_tac 1);
wenzelm@5132
   192
by (cut_facts_tac [linorder_linear] 1);
nipkow@4640
   193
by (blast_tac (claset() addIs [order_trans]) 1);
nipkow@4640
   194
qed "min_le_iff_disj";
nipkow@6157
   195
nipkow@6157
   196
Goalw [min_def]
nipkow@6157
   197
 "P(min (i::'a::linorder) j) = ((i <= j --> P(i)) & (~ i <= j --> P(j)))";
paulson@6301
   198
by (Simp_tac 1);
nipkow@6157
   199
qed "split_min";
nipkow@6157
   200
nipkow@6157
   201
Goalw [max_def]
nipkow@6157
   202
 "P(max (i::'a::linorder) j) = ((i <= j --> P(j)) & (~ i <= j --> P(i)))";
paulson@6301
   203
by (Simp_tac 1);
nipkow@6157
   204
qed "split_max";