src/HOL/Integ/Int.ML
author paulson
Wed, 02 Jan 2002 16:06:31 +0100
changeset 12613 279facb4253a
parent 11868 56db9f3a6b3e
permissions -rw-r--r--
Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson@5562
     1
(*  Title:      HOL/Integ/Int.ML
paulson@5562
     2
    ID:         $Id$
paulson@5562
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@5562
     4
    Copyright   1998  University of Cambridge
paulson@5562
     5
paulson@5562
     6
Type "int" is a linear order
paulson@6866
     7
paulson@6866
     8
And many further lemmas
paulson@5562
     9
*)
paulson@5562
    10
wenzelm@7707
    11
paulson@11868
    12
Goal "int 0 = (0::int)";
paulson@11868
    13
by (simp_tac (simpset() addsimps [Zero_int_def]) 1);
paulson@11868
    14
qed "int_0";
paulson@11868
    15
paulson@11868
    16
Goal "int 1 = 1";
paulson@11868
    17
by (simp_tac (simpset() addsimps [One_int_def]) 1); 
paulson@11868
    18
qed "int_1";
paulson@11868
    19
paulson@11868
    20
Goal "int (Suc 0) = 1";
paulson@11868
    21
by (simp_tac (simpset() addsimps [One_int_def, One_nat_def]) 1); 
paulson@11868
    22
qed "int_Suc0_eq_1";
paulson@11868
    23
paulson@11868
    24
Goalw [zdiff_def,zless_def] "neg x = (x < 0)";
paulson@11868
    25
by Auto_tac; 
paulson@11868
    26
qed "neg_eq_less_0"; 
paulson@11868
    27
paulson@11868
    28
Goalw [zle_def] "(~neg x) = (0 <= x)";
paulson@11868
    29
by (simp_tac (simpset() addsimps [neg_eq_less_0]) 1); 
paulson@11868
    30
qed "not_neg_eq_ge_0"; 
paulson@11868
    31
paulson@11868
    32
(** Needed to simplify inequalities when Numeral1 can get simplified to 1 **)
paulson@11868
    33
paulson@11868
    34
Goal "~ neg 0";
paulson@11868
    35
by (simp_tac (simpset() addsimps [One_int_def, neg_eq_less_0]) 1);  
paulson@11868
    36
qed "not_neg_0"; 
paulson@11868
    37
paulson@11868
    38
Goal "~ neg 1";
paulson@11868
    39
by (simp_tac (simpset() addsimps [One_int_def, neg_eq_less_0]) 1);  
paulson@11868
    40
qed "not_neg_1"; 
paulson@11868
    41
paulson@11868
    42
Goal "iszero 0";
paulson@11868
    43
by (simp_tac (simpset() addsimps [iszero_def]) 1);
paulson@11868
    44
qed "iszero_0"; 
paulson@11868
    45
paulson@11868
    46
Goal "~ iszero 1";
paulson@11868
    47
by (simp_tac (simpset() addsimps [Zero_int_def, One_int_def, One_nat_def, 
paulson@11868
    48
                                  iszero_def]) 1);
paulson@11868
    49
qed "not_iszero_1"; 
paulson@11868
    50
paulson@11868
    51
Goal "0 < (1::int)";
paulson@11868
    52
by (simp_tac (simpset() addsimps [Zero_int_def, One_int_def, One_nat_def]) 1); 
paulson@11868
    53
qed "int_0_less_1";
paulson@11868
    54
paulson@11868
    55
Goal "0 \\<noteq> (1::int)";
paulson@11868
    56
by (simp_tac (simpset() addsimps [Zero_int_def, One_int_def, One_nat_def]) 1); 
paulson@11868
    57
qed "int_0_neq_1";
paulson@11868
    58
paulson@11868
    59
Addsimps [int_0, int_1, int_0_neq_1];
paulson@11868
    60
paulson@11868
    61
wenzelm@7707
    62
(*** Abel_Cancel simproc on the integers ***)
wenzelm@7707
    63
wenzelm@7707
    64
(* Lemmas needed for the simprocs *)
wenzelm@7707
    65
wenzelm@7707
    66
(*Deletion of other terms in the formula, seeking the -x at the front of z*)
wenzelm@7707
    67
Goal "((x::int) + (y + z) = y + u) = ((x + z) = u)";
wenzelm@7707
    68
by (stac zadd_left_commute 1);
wenzelm@7707
    69
by (rtac zadd_left_cancel 1);
wenzelm@7707
    70
qed "zadd_cancel_21";
wenzelm@7707
    71
wenzelm@7707
    72
(*A further rule to deal with the case that
wenzelm@7707
    73
  everything gets cancelled on the right.*)
wenzelm@7707
    74
Goal "((x::int) + (y + z) = y) = (x = -z)";
wenzelm@7707
    75
by (stac zadd_left_commute 1);
paulson@11868
    76
by (res_inst_tac [("t", "y")] (zadd_0_right RS subst) 1
wenzelm@7707
    77
    THEN stac zadd_left_cancel 1);
wenzelm@7707
    78
by (simp_tac (simpset() addsimps [eq_zdiff_eq RS sym]) 1);
wenzelm@7707
    79
qed "zadd_cancel_end";
wenzelm@7707
    80
wenzelm@7707
    81
wenzelm@7707
    82
structure Int_Cancel_Data =
wenzelm@7707
    83
struct
wenzelm@7707
    84
  val ss		= HOL_ss
wenzelm@7707
    85
  val eq_reflection	= eq_reflection
wenzelm@7707
    86
wenzelm@9436
    87
  val sg_ref 		= Sign.self_ref (Theory.sign_of (the_context ()))
wenzelm@7707
    88
  val T		= HOLogic.intT
paulson@11868
    89
  val zero		= Const ("0", HOLogic.intT)
wenzelm@7707
    90
  val restrict_to_left  = restrict_to_left
wenzelm@7707
    91
  val add_cancel_21	= zadd_cancel_21
wenzelm@7707
    92
  val add_cancel_end	= zadd_cancel_end
wenzelm@7707
    93
  val add_left_cancel	= zadd_left_cancel
wenzelm@7707
    94
  val add_assoc		= zadd_assoc
wenzelm@7707
    95
  val add_commute	= zadd_commute
wenzelm@7707
    96
  val add_left_commute	= zadd_left_commute
paulson@11868
    97
  val add_0		= zadd_0
paulson@11868
    98
  val add_0_right	= zadd_0_right
wenzelm@7707
    99
wenzelm@7707
   100
  val eq_diff_eq	= eq_zdiff_eq
wenzelm@7707
   101
  val eqI_rules		= [zless_eqI, zeq_eqI, zle_eqI]
wenzelm@7707
   102
  fun dest_eqI th = 
wenzelm@11701
   103
      #1 (HOLogic.dest_bin "op =" HOLogic.boolT
wenzelm@7707
   104
	      (HOLogic.dest_Trueprop (concl_of th)))
wenzelm@7707
   105
wenzelm@7707
   106
  val diff_def		= zdiff_def
wenzelm@7707
   107
  val minus_add_distrib	= zminus_zadd_distrib
wenzelm@7707
   108
  val minus_minus	= zminus_zminus
paulson@11868
   109
  val minus_0		= zminus_0
paulson@11868
   110
  val add_inverses	= [zadd_zminus_inverse, zadd_zminus_inverse2]
wenzelm@7707
   111
  val cancel_simps	= [zadd_zminus_cancel, zminus_zadd_cancel]
wenzelm@7707
   112
end;
wenzelm@7707
   113
wenzelm@7707
   114
structure Int_Cancel = Abel_Cancel (Int_Cancel_Data);
wenzelm@7707
   115
wenzelm@7707
   116
Addsimprocs [Int_Cancel.sum_conv, Int_Cancel.rel_conv];
wenzelm@7707
   117
wenzelm@7707
   118
wenzelm@7707
   119
wenzelm@7707
   120
(*** misc ***)
wenzelm@7707
   121
paulson@8785
   122
Goal "- (z - y) = y - (z::int)";
paulson@8785
   123
by (Simp_tac 1);
paulson@8785
   124
qed "zminus_zdiff_eq";
paulson@8785
   125
Addsimps [zminus_zdiff_eq];
paulson@8785
   126
paulson@5562
   127
Goal "(w<z) = neg(w-z)";
paulson@5562
   128
by (simp_tac (simpset() addsimps [zless_def]) 1);
paulson@5562
   129
qed "zless_eq_neg";
paulson@5562
   130
paulson@5562
   131
Goal "(w=z) = iszero(w-z)";
paulson@5562
   132
by (simp_tac (simpset() addsimps [iszero_def, zdiff_eq_eq]) 1);
paulson@5562
   133
qed "eq_eq_iszero";
paulson@5562
   134
paulson@5562
   135
Goal "(w<=z) = (~ neg(z-w))";
paulson@5562
   136
by (simp_tac (simpset() addsimps [zle_def, zless_def]) 1);
paulson@5562
   137
qed "zle_eq_not_neg";
paulson@5562
   138
paulson@11868
   139
(** Inequality reasoning **)
paulson@5562
   140
paulson@11868
   141
Goal "(w < z + (1::int)) = (w<z | w=z)";
paulson@11868
   142
by (auto_tac (claset(),
paulson@11868
   143
	      simpset() addsimps [zless_iff_Suc_zadd, int_Suc,
paulson@11868
   144
                                  gr0_conv_Suc, zero_reorient]));
paulson@11868
   145
by (res_inst_tac [("x","Suc n")] exI 1); 
paulson@11868
   146
by (simp_tac (simpset() addsimps [int_Suc]) 1); 
paulson@11868
   147
qed "zless_add1_eq";
paulson@5593
   148
paulson@11868
   149
Goal "(w + (1::int) <= z) = (w<z)";
paulson@11868
   150
by (asm_full_simp_tac (simpset() addsimps [zle_def, zless_add1_eq]) 1); 
paulson@11868
   151
by (auto_tac (claset() addIs [zle_anti_sym],
paulson@11868
   152
	      simpset() addsimps [order_less_imp_le, symmetric zle_def]));
paulson@11868
   153
qed "add1_zle_eq";
paulson@5593
   154
paulson@11868
   155
Goal "((1::int) + w <= z) = (w<z)";
paulson@11868
   156
by (stac zadd_commute 1);
paulson@11868
   157
by (rtac add1_zle_eq 1);
paulson@11868
   158
qed "add1_left_zle_eq";
paulson@5593
   159
paulson@5593
   160
paulson@5562
   161
(*** Monotonicity results ***)
paulson@5562
   162
paulson@5562
   163
Goal "(v+z < w+z) = (v < (w::int))";
paulson@5582
   164
by (Simp_tac 1);
paulson@5562
   165
qed "zadd_right_cancel_zless";
paulson@5562
   166
paulson@5562
   167
Goal "(z+v < z+w) = (v < (w::int))";
paulson@5582
   168
by (Simp_tac 1);
paulson@5562
   169
qed "zadd_left_cancel_zless";
paulson@5562
   170
paulson@5562
   171
Addsimps [zadd_right_cancel_zless, zadd_left_cancel_zless];
paulson@5562
   172
paulson@5562
   173
Goal "(v+z <= w+z) = (v <= (w::int))";
paulson@5582
   174
by (Simp_tac 1);
paulson@5562
   175
qed "zadd_right_cancel_zle";
paulson@5562
   176
paulson@5562
   177
Goal "(z+v <= z+w) = (v <= (w::int))";
paulson@5582
   178
by (Simp_tac 1);
paulson@5562
   179
qed "zadd_left_cancel_zle";
paulson@5562
   180
paulson@5562
   181
Addsimps [zadd_right_cancel_zle, zadd_left_cancel_zle];
paulson@5562
   182
paulson@5562
   183
(*"v<=w ==> v+z <= w+z"*)
paulson@5562
   184
bind_thm ("zadd_zless_mono1", zadd_right_cancel_zless RS iffD2);
paulson@5562
   185
paulson@6998
   186
(*"v<=w ==> z+v <= z+w"*)
paulson@6998
   187
bind_thm ("zadd_zless_mono2", zadd_left_cancel_zless RS iffD2);
paulson@6998
   188
paulson@5562
   189
(*"v<=w ==> v+z <= w+z"*)
paulson@5562
   190
bind_thm ("zadd_zle_mono1", zadd_right_cancel_zle RS iffD2);
paulson@5562
   191
paulson@6998
   192
(*"v<=w ==> z+v <= z+w"*)
paulson@6998
   193
bind_thm ("zadd_zle_mono2", zadd_left_cancel_zle RS iffD2);
paulson@6998
   194
paulson@7081
   195
Goal "[| w'<=w; z'<=z |] ==> w' + z' <= w + (z::int)";
paulson@5562
   196
by (etac (zadd_zle_mono1 RS zle_trans) 1);
paulson@5562
   197
by (Simp_tac 1);
paulson@5562
   198
qed "zadd_zle_mono";
paulson@5562
   199
paulson@7081
   200
Goal "[| w'<w; z'<=z |] ==> w' + z' < w + (z::int)";
paulson@10646
   201
by (etac (zadd_zless_mono1 RS order_less_le_trans) 1);
paulson@5562
   202
by (Simp_tac 1);
paulson@5562
   203
qed "zadd_zless_mono";
paulson@5562
   204
paulson@5562
   205
paulson@5562
   206
(*** Comparison laws ***)
paulson@5562
   207
paulson@5562
   208
Goal "(- x < - y) = (y < (x::int))";
paulson@5582
   209
by (simp_tac (simpset() addsimps [zless_def, zdiff_def] @ zadd_ac) 1);
paulson@5562
   210
qed "zminus_zless_zminus"; 
paulson@5562
   211
Addsimps [zminus_zless_zminus];
paulson@5562
   212
paulson@5562
   213
Goal "(- x <= - y) = (y <= (x::int))";
paulson@5582
   214
by (simp_tac (simpset() addsimps [zle_def]) 1);
paulson@5562
   215
qed "zminus_zle_zminus"; 
paulson@5562
   216
Addsimps [zminus_zle_zminus];
paulson@5562
   217
paulson@5562
   218
(** The next several equations can make the simplifier loop! **)
paulson@5562
   219
paulson@5562
   220
Goal "(x < - y) = (y < - (x::int))";
paulson@5582
   221
by (simp_tac (simpset() addsimps [zless_def, zdiff_def] @ zadd_ac) 1);
paulson@5562
   222
qed "zless_zminus"; 
paulson@5562
   223
paulson@5562
   224
Goal "(- x < y) = (- y < (x::int))";
paulson@5582
   225
by (simp_tac (simpset() addsimps [zless_def, zdiff_def] @ zadd_ac) 1);
paulson@5562
   226
qed "zminus_zless"; 
paulson@5562
   227
paulson@5562
   228
Goal "(x <= - y) = (y <= - (x::int))";
paulson@5582
   229
by (simp_tac (simpset() addsimps [zle_def, zminus_zless]) 1);
paulson@5562
   230
qed "zle_zminus"; 
paulson@5562
   231
paulson@5562
   232
Goal "(- x <= y) = (- y <= (x::int))";
paulson@5582
   233
by (simp_tac (simpset() addsimps [zle_def, zless_zminus]) 1);
paulson@5562
   234
qed "zminus_zle"; 
paulson@5562
   235
paulson@6917
   236
Goal "(x = - y) = (y = - (x::int))";
paulson@6917
   237
by Auto_tac;
paulson@6917
   238
qed "equation_zminus";
paulson@6917
   239
paulson@6917
   240
Goal "(- x = y) = (- (y::int) = x)";
paulson@6917
   241
by Auto_tac;
paulson@6917
   242
qed "zminus_equation";
paulson@6917
   243
paulson@11868
   244
paulson@11868
   245
(** Instances of the equations above, for zero **)
paulson@11868
   246
paulson@11868
   247
(*instantiate a variable to zero and simplify*)
paulson@11868
   248
fun zero_instance v th = simplify (simpset()) (inst v "0" th);
paulson@11868
   249
paulson@11868
   250
Addsimps [zero_instance "x" zless_zminus,
paulson@11868
   251
          zero_instance "y" zminus_zless,
paulson@11868
   252
          zero_instance "x" zle_zminus,
paulson@11868
   253
          zero_instance "y" zminus_zle,
paulson@11868
   254
          zero_instance "x" equation_zminus,
paulson@11868
   255
          zero_instance "y" zminus_equation];
paulson@11868
   256
paulson@11868
   257
paulson@11868
   258
Goal "- (int (Suc n)) < 0";
paulson@5582
   259
by (simp_tac (simpset() addsimps [zless_def]) 1);
paulson@5562
   260
qed "negative_zless_0"; 
paulson@5562
   261
paulson@5582
   262
Goal "- (int (Suc n)) < int m";
paulson@10646
   263
by (rtac (negative_zless_0 RS order_less_le_trans) 1);
paulson@5562
   264
by (Simp_tac 1); 
paulson@5562
   265
qed "negative_zless"; 
paulson@5562
   266
AddIffs [negative_zless]; 
paulson@5562
   267
paulson@11868
   268
Goal "- int n <= 0";
paulson@5582
   269
by (simp_tac (simpset() addsimps [zminus_zle]) 1);
paulson@5562
   270
qed "negative_zle_0"; 
paulson@5562
   271
paulson@5582
   272
Goal "- int n <= int m";
paulson@5582
   273
by (simp_tac (simpset() addsimps [zless_def, zle_def, zdiff_def, zadd_int]) 1);
paulson@5562
   274
qed "negative_zle"; 
paulson@5562
   275
AddIffs [negative_zle]; 
paulson@5562
   276
paulson@11868
   277
Goal "~(0 <= - (int (Suc n)))";
paulson@5562
   278
by (stac zle_zminus 1);
paulson@5562
   279
by (Simp_tac 1);
paulson@5562
   280
qed "not_zle_0_negative"; 
paulson@5562
   281
Addsimps [not_zle_0_negative]; 
paulson@5562
   282
paulson@5582
   283
Goal "(int n <= - int m) = (n = 0 & m = 0)"; 
paulson@5562
   284
by Safe_tac; 
paulson@5562
   285
by (Simp_tac 3); 
paulson@5562
   286
by (dtac (zle_zminus RS iffD1) 2); 
paulson@5562
   287
by (ALLGOALS (dtac (negative_zle_0 RSN(2,zle_trans)))); 
paulson@5562
   288
by (ALLGOALS Asm_full_simp_tac); 
paulson@5562
   289
qed "int_zle_neg"; 
paulson@5562
   290
paulson@5582
   291
Goal "~(int n < - int m)";
paulson@5562
   292
by (simp_tac (simpset() addsimps [symmetric zle_def]) 1); 
paulson@5562
   293
qed "not_int_zless_negative"; 
paulson@5562
   294
paulson@5582
   295
Goal "(- int n = int m) = (n = 0 & m = 0)"; 
paulson@5562
   296
by (rtac iffI 1);
paulson@5562
   297
by (rtac (int_zle_neg RS iffD1) 1); 
paulson@5562
   298
by (dtac sym 1); 
paulson@5562
   299
by (ALLGOALS Asm_simp_tac); 
paulson@5562
   300
qed "negative_eq_positive"; 
paulson@5562
   301
paulson@5562
   302
Addsimps [negative_eq_positive, not_int_zless_negative]; 
paulson@5562
   303
paulson@5562
   304
paulson@5582
   305
Goal "(w <= z) = (EX n. z = w + int n)";
paulson@11868
   306
by (auto_tac (claset() addIs [inst "x" "0::nat" exI]
paulson@11868
   307
		       addSIs [not_sym RS not0_implies_Suc],
wenzelm@10472
   308
	      simpset() addsimps [zless_iff_Suc_zadd, int_le_less]));
paulson@5562
   309
qed "zle_iff_zadd";
paulson@5562
   310
paulson@9945
   311
Goal "abs (int m) = int m";
paulson@9945
   312
by (simp_tac (simpset() addsimps [zabs_def]) 1); 
paulson@9945
   313
qed "abs_int_eq";
paulson@9945
   314
Addsimps [abs_int_eq];
paulson@9945
   315
paulson@5562
   316
paulson@5562
   317
(**** nat: magnitide of an integer, as a natural number ****)
paulson@5562
   318
paulson@5582
   319
Goalw [nat_def] "nat(int n) = n";
paulson@5562
   320
by Auto_tac;
paulson@7009
   321
qed "nat_int";
paulson@11868
   322
Addsimps [nat_int];
paulson@5562
   323
paulson@11868
   324
Goalw [nat_def] "nat(- (int n)) = 0";
paulson@5562
   325
by (auto_tac (claset(),
paulson@11868
   326
     simpset() addsimps [neg_eq_less_0, zero_reorient, zminus_zless])); 
paulson@7009
   327
qed "nat_zminus_int";
paulson@11868
   328
Addsimps [nat_zminus_int];
paulson@5562
   329
paulson@11868
   330
Goalw [Zero_int_def] "nat 0 = 0";
paulson@11868
   331
by (rtac nat_int 1);
paulson@11868
   332
qed "nat_zero";
paulson@11868
   333
Addsimps [nat_zero];
paulson@5562
   334
paulson@5582
   335
Goal "~ neg z ==> int (nat z) = z"; 
paulson@11868
   336
by (dtac (not_neg_eq_ge_0 RS iffD1) 1); 
paulson@5562
   337
by (dtac zle_imp_zless_or_eq 1); 
paulson@5562
   338
by (auto_tac (claset(), simpset() addsimps [zless_iff_Suc_zadd])); 
paulson@5562
   339
qed "not_neg_nat"; 
paulson@5562
   340
paulson@7081
   341
Goal "neg x ==> EX n. x = - (int (Suc n))"; 
paulson@5562
   342
by (auto_tac (claset(), 
paulson@11868
   343
	      simpset() addsimps [neg_eq_less_0, zless_iff_Suc_zadd,
paulson@5562
   344
				  zdiff_eq_eq RS sym, zdiff_def])); 
paulson@5562
   345
qed "negD"; 
paulson@5562
   346
paulson@5562
   347
Goalw [nat_def] "neg z ==> nat z = 0"; 
paulson@5562
   348
by Auto_tac; 
paulson@5562
   349
qed "neg_nat"; 
paulson@5562
   350
paulson@7518
   351
Goal "(m < nat z) = (int m < z)";
paulson@7518
   352
by (case_tac "neg z" 1);
paulson@7518
   353
by (etac (not_neg_nat RS subst) 2);
paulson@7518
   354
by (auto_tac (claset(), simpset() addsimps [neg_nat])); 
paulson@7518
   355
by (auto_tac (claset() addDs [order_less_trans], 
paulson@11868
   356
	      simpset() addsimps [neg_eq_less_0])); 
paulson@7518
   357
qed "zless_nat_eq_int_zless";
paulson@7518
   358
paulson@12613
   359
Goal "0 <= z ==> int (nat z) = z"; 
paulson@12613
   360
by (asm_full_simp_tac
paulson@12613
   361
    (simpset() addsimps [neg_eq_less_0, zle_def, not_neg_nat]) 1); 
paulson@12613
   362
qed "nat_0_le"; 
paulson@12613
   363
paulson@11868
   364
Goal "z <= 0 ==> nat z = 0"; 
paulson@7518
   365
by (auto_tac (claset(), 
paulson@11868
   366
	      simpset() addsimps [order_le_less, neg_eq_less_0, 
paulson@7518
   367
				  zle_def, neg_nat])); 
paulson@12613
   368
qed "nat_le_0"; 
paulson@12613
   369
Addsimps [nat_0_le, nat_le_0];
paulson@7518
   370
paulson@11868
   371
(*An alternative condition is  0 <= w  *)
paulson@11868
   372
Goal "0 < z ==> (nat w < nat z) = (w < z)";
paulson@6866
   373
by (stac (zless_int RS sym) 1);
paulson@11868
   374
by (asm_simp_tac (simpset() addsimps [not_neg_nat, not_neg_eq_ge_0, 
paulson@6866
   375
				      order_le_less]) 1);
paulson@6866
   376
by (case_tac "neg w" 1);
paulson@6866
   377
by (asm_simp_tac (simpset() addsimps [not_neg_nat]) 2);
paulson@11868
   378
by (asm_full_simp_tac (simpset() addsimps [neg_eq_less_0, neg_nat]) 1);
paulson@6866
   379
by (blast_tac (claset() addIs [order_less_trans]) 1);
paulson@6917
   380
val lemma = result();
paulson@6917
   381
paulson@11868
   382
Goal "(nat w < nat z) = (0 < z & w < z)";
paulson@11868
   383
by (case_tac "0 < z" 1);
paulson@12613
   384
by (auto_tac (claset(), simpset() addsimps [lemma, linorder_not_less])); 
paulson@6917
   385
qed "zless_nat_conj";
paulson@6917
   386
paulson@6866
   387
paulson@6866
   388
(* a case theorem distinguishing non-negative and negative int *)  
paulson@5562
   389
paulson@6942
   390
val prems = Goal
paulson@6942
   391
     "[|!! n. z = int n ==> P;  !! n. z =  - (int (Suc n)) ==> P |] ==> P"; 
paulson@5562
   392
by (case_tac "neg z" 1); 
paulson@6942
   393
by (fast_tac (claset() addSDs [negD] addSEs prems) 1); 
paulson@6942
   394
by (dtac (not_neg_nat RS sym) 1);
paulson@6942
   395
by (eresolve_tac prems 1);
paulson@5562
   396
qed "int_cases"; 
paulson@5562
   397
paulson@5562
   398
fun int_case_tac x = res_inst_tac [("z",x)] int_cases; 
paulson@5562
   399
paulson@6866
   400
paulson@6866
   401
(*** Monotonicity of Multiplication ***)
paulson@6866
   402
paulson@6866
   403
Goal "i <= (j::int) ==> i * int k <= j * int k";
paulson@6866
   404
by (induct_tac "k" 1);
paulson@11868
   405
by (stac int_Suc 2);
paulson@6866
   406
by (ALLGOALS 
paulson@11868
   407
    (asm_simp_tac (simpset() addsimps [zadd_zmult_distrib2, zadd_zle_mono, 
paulson@11868
   408
                                       int_Suc0_eq_1])));
paulson@6866
   409
val lemma = result();
paulson@6866
   410
paulson@11868
   411
Goal "[| i <= j;  (0::int) <= k |] ==> i*k <= j*k";
paulson@6866
   412
by (res_inst_tac [("t", "k")] (not_neg_nat RS subst) 1);
paulson@6866
   413
by (etac lemma 2);
paulson@11868
   414
by (full_simp_tac (simpset() addsimps [not_neg_eq_ge_0]) 1);
paulson@6866
   415
qed "zmult_zle_mono1";
paulson@6866
   416
paulson@11868
   417
Goal "[| i <= j;  k <= (0::int) |] ==> j*k <= i*k";
paulson@6866
   418
by (rtac (zminus_zle_zminus RS iffD1) 1);
paulson@6866
   419
by (asm_simp_tac (simpset() addsimps [zmult_zminus_right RS sym,
paulson@6866
   420
				      zmult_zle_mono1, zle_zminus]) 1);
paulson@6866
   421
qed "zmult_zle_mono1_neg";
paulson@6866
   422
paulson@11868
   423
Goal "[| i <= j;  (0::int) <= k |] ==> k*i <= k*j";
paulson@6942
   424
by (dtac zmult_zle_mono1 1);
paulson@6942
   425
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [zmult_commute])));
paulson@6942
   426
qed "zmult_zle_mono2";
paulson@6942
   427
paulson@11868
   428
Goal "[| i <= j;  k <= (0::int) |] ==> k*j <= k*i";
paulson@6942
   429
by (dtac zmult_zle_mono1_neg 1);
paulson@6942
   430
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [zmult_commute])));
paulson@6942
   431
qed "zmult_zle_mono2_neg";
paulson@6942
   432
paulson@6990
   433
(* <= monotonicity, BOTH arguments*)
paulson@11868
   434
Goal "[| i <= j;  k <= l;  (0::int) <= j;  (0::int) <= k |] ==> i*k <= j*l";
paulson@6866
   435
by (etac (zmult_zle_mono1 RS order_trans) 1);
paulson@6866
   436
by (assume_tac 1);
paulson@6990
   437
by (etac zmult_zle_mono2 1);
paulson@6990
   438
by (assume_tac 1);
paulson@6866
   439
qed "zmult_zle_mono";
paulson@6866
   440
paulson@6866
   441
paulson@6866
   442
(** strict, in 1st argument; proof is by induction on k>0 **)
paulson@6866
   443
paulson@6866
   444
Goal "i<j ==> 0<k --> int k * i < int k * j";
paulson@6866
   445
by (induct_tac "k" 1);
paulson@11868
   446
by (stac int_Suc 2);
paulson@6866
   447
by (case_tac "n=0" 2);
paulson@6866
   448
by (ALLGOALS (asm_full_simp_tac
paulson@6866
   449
	      (simpset() addsimps [zadd_zmult_distrib, zadd_zless_mono, 
paulson@11868
   450
				   int_Suc0_eq_1, order_le_less])));
paulson@11868
   451
val lemma = result();
paulson@6866
   452
paulson@11868
   453
Goal "[| i<j;  (0::int) < k |] ==> k*i < k*j";
paulson@6866
   454
by (res_inst_tac [("t", "k")] (not_neg_nat RS subst) 1);
paulson@11868
   455
by (etac (lemma RS mp) 2);
paulson@11868
   456
by (asm_simp_tac (simpset() addsimps [not_neg_eq_ge_0, 
paulson@6866
   457
				      order_le_less]) 1);
paulson@6917
   458
by (forward_tac [conjI RS (zless_nat_conj RS iffD2)] 1);
paulson@6866
   459
by Auto_tac;
paulson@6866
   460
qed "zmult_zless_mono2";
paulson@6866
   461
paulson@11868
   462
Goal "[| i<j;  (0::int) < k |] ==> i*k < j*k";
paulson@6866
   463
by (dtac zmult_zless_mono2 1);
paulson@6866
   464
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [zmult_commute])));
paulson@6866
   465
qed "zmult_zless_mono1";
paulson@6866
   466
paulson@6990
   467
(* < monotonicity, BOTH arguments*)
paulson@11868
   468
Goal "[| i < j;  k < l;  (0::int) < j;  (0::int) < k |] ==> i*k < j*l";
paulson@6990
   469
by (etac (zmult_zless_mono1 RS order_less_trans) 1);
paulson@6990
   470
by (assume_tac 1);
paulson@6990
   471
by (etac zmult_zless_mono2 1);
paulson@6990
   472
by (assume_tac 1);
paulson@6990
   473
qed "zmult_zless_mono";
paulson@6990
   474
paulson@11868
   475
Goal "[| i<j;  k < (0::int) |] ==> j*k < i*k";
paulson@6866
   476
by (rtac (zminus_zless_zminus RS iffD1) 1);
paulson@6866
   477
by (asm_simp_tac (simpset() addsimps [zmult_zminus_right RS sym,
paulson@6866
   478
				      zmult_zless_mono1, zless_zminus]) 1);
paulson@6866
   479
qed "zmult_zless_mono1_neg";
paulson@6866
   480
paulson@11868
   481
Goal "[| i<j;  k < (0::int) |] ==> k*j < k*i";
paulson@6866
   482
by (rtac (zminus_zless_zminus RS iffD1) 1);
paulson@6866
   483
by (asm_simp_tac (simpset() addsimps [zmult_zminus RS sym,
paulson@6866
   484
				      zmult_zless_mono2, zless_zminus]) 1);
paulson@6866
   485
qed "zmult_zless_mono2_neg";
paulson@6866
   486
paulson@6866
   487
paulson@11868
   488
Goal "(m*n = (0::int)) = (m = 0 | n = 0)";
paulson@11868
   489
by (case_tac "m < (0::int)" 1);
paulson@6866
   490
by (auto_tac (claset(), 
paulson@6866
   491
	      simpset() addsimps [linorder_not_less, order_le_less, 
paulson@6866
   492
				  linorder_neq_iff])); 
paulson@6866
   493
by (REPEAT 
paulson@6866
   494
    (force_tac (claset() addDs [zmult_zless_mono1_neg, zmult_zless_mono1], 
paulson@6866
   495
		simpset()) 1));
paulson@11868
   496
qed "zmult_eq_0_iff";
paulson@11868
   497
AddIffs [zmult_eq_0_iff];
paulson@6866
   498
paulson@6866
   499
paulson@9633
   500
(** Cancellation laws for k*m < k*n and m*k < n*k, also for <= and =,
paulson@9633
   501
    but not (yet?) for k*m < n*k. **)
paulson@9633
   502
paulson@11868
   503
Goal "(m*k < n*k) = (((0::int) < k & m<n) | (k < 0 & n<m))";
paulson@11868
   504
by (case_tac "k = (0::int)" 1);
paulson@9633
   505
by (auto_tac (claset(), simpset() addsimps [linorder_neq_iff, 
paulson@9633
   506
                              zmult_zless_mono1, zmult_zless_mono1_neg]));  
paulson@9633
   507
by (auto_tac (claset(), 
paulson@9633
   508
              simpset() addsimps [linorder_not_less,
paulson@9633
   509
				  inst "y1" "m*k" (linorder_not_le RS sym),
paulson@9633
   510
                                  inst "y1" "m" (linorder_not_le RS sym)]));
paulson@9633
   511
by (ALLGOALS (etac notE));
paulson@10646
   512
by (auto_tac (claset(), simpset() addsimps [order_less_imp_le, zmult_zle_mono1,
paulson@9633
   513
                                            zmult_zle_mono1_neg]));  
paulson@6866
   514
qed "zmult_zless_cancel2";
paulson@6866
   515
paulson@9633
   516
paulson@11868
   517
Goal "(k*m < k*n) = (((0::int) < k & m<n) | (k < 0 & n<m))";
paulson@9633
   518
by (simp_tac (simpset() addsimps [inst "z" "k" zmult_commute, 
paulson@9633
   519
                                  zmult_zless_cancel2]) 1);
paulson@6866
   520
qed "zmult_zless_cancel1";
paulson@6866
   521
paulson@11868
   522
Goal "(m*k <= n*k) = (((0::int) < k --> m<=n) & (k < 0 --> n<=m))";
paulson@9633
   523
by (simp_tac (simpset() addsimps [linorder_not_less RS sym, 
paulson@9633
   524
                                  zmult_zless_cancel2]) 1);
paulson@6866
   525
qed "zmult_zle_cancel2";
paulson@6866
   526
paulson@11868
   527
Goal "(k*m <= k*n) = (((0::int) < k --> m<=n) & (k < 0 --> n<=m))";
paulson@9633
   528
by (simp_tac (simpset() addsimps [linorder_not_less RS sym, 
paulson@9633
   529
                                  zmult_zless_cancel1]) 1);
paulson@6866
   530
qed "zmult_zle_cancel1";
paulson@6866
   531
paulson@11868
   532
Goal "(m*k = n*k) = (k = (0::int) | m=n)";
paulson@6866
   533
by (cut_facts_tac [linorder_less_linear] 1);
paulson@6866
   534
by Safe_tac;
paulson@9633
   535
by Auto_tac;  
paulson@6866
   536
by (REPEAT 
paulson@6866
   537
    (force_tac (claset() addD2 ("mono_neg", zmult_zless_mono1_neg)
paulson@6866
   538
                         addD2 ("mono_pos", zmult_zless_mono1), 
paulson@6866
   539
		simpset() addsimps [linorder_neq_iff]) 1));
paulson@9633
   540
paulson@6866
   541
qed "zmult_cancel2";
paulson@6866
   542
paulson@11868
   543
Goal "(k*m = k*n) = (k = (0::int) | m=n)";
paulson@9633
   544
by (simp_tac (simpset() addsimps [inst "z" "k" zmult_commute, 
paulson@9633
   545
                                  zmult_cancel2]) 1);
paulson@6866
   546
qed "zmult_cancel1";
paulson@6866
   547
Addsimps [zmult_cancel1, zmult_cancel2];
paulson@11868
   548
paulson@11868
   549
paulson@11868
   550
(*Analogous to zadd_int*)
paulson@11868
   551
Goal "n<=m --> int m - int n = int (m-n)";
paulson@11868
   552
by (induct_thm_tac diff_induct "m n" 1);
paulson@11868
   553
by (auto_tac (claset(), simpset() addsimps [int_Suc, symmetric zdiff_def])); 
paulson@11868
   554
qed_spec_mp "zdiff_int";