src/ZF/Integ/Int.ML
author paulson
Thu Aug 10 11:27:34 2000 +0200 (2000-08-10)
changeset 9570 e16e168984e1
parent 9548 15bee2731e43
child 9576 3df14e0a3a51
permissions -rw-r--r--
installation of cancellation simprocs for the integers
paulson@5561
     1
(*  Title:      ZF/Integ/Int.ML
paulson@5561
     2
    ID:         $Id$
paulson@5561
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@5561
     4
    Copyright   1993  University of Cambridge
paulson@5561
     5
paulson@5561
     6
The integers as equivalence classes over nat*nat.
paulson@5561
     7
paulson@5561
     8
Could also prove...
paulson@9548
     9
"znegative(z) ==> $# zmagnitude(z) = $- z"
paulson@5561
    10
"~ znegative(z) ==> $# zmagnitude(z) = z"
paulson@5561
    11
$+ and $* are monotonic wrt $<
paulson@5561
    12
*)
paulson@5561
    13
paulson@5561
    14
AddSEs [quotientE];
paulson@5561
    15
paulson@5561
    16
(*** Proving that intrel is an equivalence relation ***)
paulson@5561
    17
paulson@5561
    18
(** Natural deduction for intrel **)
paulson@5561
    19
paulson@5561
    20
Goalw [intrel_def]
paulson@5561
    21
    "<<x1,y1>,<x2,y2>>: intrel <-> \
paulson@5561
    22
\    x1: nat & y1: nat & x2: nat & y2: nat & x1#+y2 = x2#+y1";
paulson@5561
    23
by (Fast_tac 1);
paulson@5561
    24
qed "intrel_iff";
paulson@5561
    25
paulson@5561
    26
Goalw [intrel_def]
paulson@9496
    27
    "[| x1#+y2 = x2#+y1; x1: nat; y1: nat; x2: nat; y2: nat |]  \
paulson@9496
    28
\    ==> <<x1,y1>,<x2,y2>>: intrel";
paulson@5561
    29
by (fast_tac (claset() addIs prems) 1);
paulson@5561
    30
qed "intrelI";
paulson@5561
    31
paulson@5561
    32
(*intrelE is hard to derive because fast_tac tries hyp_subst_tac so soon*)
paulson@5561
    33
Goalw [intrel_def]
paulson@5561
    34
  "p: intrel --> (EX x1 y1 x2 y2. \
paulson@5561
    35
\                  p = <<x1,y1>,<x2,y2>> & x1#+y2 = x2#+y1 & \
paulson@5561
    36
\                  x1: nat & y1: nat & x2: nat & y2: nat)";
paulson@5561
    37
by (Fast_tac 1);
paulson@5561
    38
qed "intrelE_lemma";
paulson@5561
    39
paulson@5561
    40
val [major,minor] = goal thy
paulson@5561
    41
  "[| p: intrel;  \
paulson@5561
    42
\     !!x1 y1 x2 y2. [| p = <<x1,y1>,<x2,y2>>;  x1#+y2 = x2#+y1; \
paulson@5561
    43
\                       x1: nat; y1: nat; x2: nat; y2: nat |] ==> Q |] \
paulson@5561
    44
\  ==> Q";
paulson@5561
    45
by (cut_facts_tac [major RS (intrelE_lemma RS mp)] 1);
paulson@5561
    46
by (REPEAT (eresolve_tac [asm_rl,exE,conjE,minor] 1));
paulson@5561
    47
qed "intrelE";
paulson@5561
    48
paulson@5561
    49
AddSIs [intrelI];
paulson@5561
    50
AddSEs [intrelE];
paulson@5561
    51
paulson@9548
    52
Goal "[| x1 #+ y2 = x2 #+ y1; x2 #+ y3 = x3 #+ y2 |] ==> x1 #+ y3 = x3 #+ y1";
paulson@9548
    53
by (rtac sym 1);
paulson@9548
    54
by (REPEAT (etac add_left_cancel 1));
paulson@9548
    55
by (ALLGOALS Asm_simp_tac);
paulson@9491
    56
qed "int_trans_lemma";
paulson@9491
    57
paulson@5561
    58
Goalw [equiv_def, refl_def, sym_def, trans_def]
paulson@5561
    59
    "equiv(nat*nat, intrel)";
paulson@5561
    60
by (fast_tac (claset() addSEs [sym, int_trans_lemma]) 1);
paulson@5561
    61
qed "equiv_intrel";
paulson@5561
    62
paulson@5561
    63
paulson@9496
    64
Goalw [int_def] "[| m: nat; n: nat |] ==> intrel `` {<m,n>} : int";
paulson@9496
    65
by (blast_tac (claset() addIs [quotientI]) 1);
paulson@9496
    66
qed "image_intrel_int";
paulson@9496
    67
paulson@9496
    68
paulson@5561
    69
Addsimps [equiv_intrel RS eq_equiv_class_iff, intrel_iff,
paulson@5561
    70
	  add_0_right, add_succ_right];
paulson@5561
    71
Addcongs [conj_cong];
paulson@5561
    72
paulson@5561
    73
val eq_intrelD = equiv_intrel RSN (2,eq_equiv_class);
paulson@5561
    74
paulson@5561
    75
(** int_of: the injection from nat to int **)
paulson@5561
    76
paulson@9496
    77
Goalw [int_def,quotient_def,int_of_def]  "$#m : int";
paulson@6153
    78
by Auto_tac;
paulson@5561
    79
qed "int_of_type";
paulson@5561
    80
paulson@9496
    81
AddIffs [int_of_type];
paulson@9496
    82
AddTCs  [int_of_type];
paulson@9496
    83
paulson@5561
    84
paulson@9496
    85
Goalw [int_of_def] "($# m = $# n) <-> natify(m)=natify(n)"; 
paulson@9496
    86
by Auto_tac;  
paulson@9496
    87
qed "int_of_eq"; 
paulson@9496
    88
AddIffs [int_of_eq];
paulson@9496
    89
paulson@9496
    90
Goal "[| $#m = $#n;  m: nat;  n: nat |] ==> m=n";
paulson@9496
    91
by (dtac (int_of_eq RS iffD1) 1);
paulson@6153
    92
by Auto_tac;
paulson@5561
    93
qed "int_of_inject";
paulson@5561
    94
paulson@9496
    95
paulson@9496
    96
(** intify: coercion from anything to int **)
paulson@9496
    97
paulson@9496
    98
Goal "intify(x) : int";
paulson@9496
    99
by (simp_tac (simpset() addsimps [intify_def]) 1);
paulson@9496
   100
qed "intify_in_int";
paulson@9496
   101
AddIffs [intify_in_int];
paulson@9496
   102
AddTCs [intify_in_int];
paulson@9496
   103
paulson@9496
   104
Goal "n : int ==> intify(n) = n";
paulson@9496
   105
by (asm_simp_tac (simpset() addsimps [intify_def]) 1);
paulson@9496
   106
qed "intify_ident";
paulson@9496
   107
Addsimps [intify_ident];
paulson@9496
   108
paulson@9496
   109
paulson@9496
   110
(*** Collapsing rules: to remove intify from arithmetic expressions ***)
paulson@9496
   111
paulson@9496
   112
Goal "intify(intify(x)) = intify(x)";
paulson@9496
   113
by (Simp_tac 1);
paulson@9496
   114
qed "intify_idem";
paulson@9496
   115
Addsimps [intify_idem];
paulson@9496
   116
paulson@9496
   117
Goal "$# (natify(m)) = $# m";
paulson@9496
   118
by (simp_tac (simpset() addsimps [int_of_def]) 1);
paulson@9496
   119
qed "int_of_natify";
paulson@5561
   120
paulson@9548
   121
Goal "$- (intify(m)) = $- m";
paulson@9496
   122
by (simp_tac (simpset() addsimps [zminus_def]) 1);
paulson@9496
   123
qed "zminus_intify";
paulson@9496
   124
paulson@9496
   125
Addsimps [int_of_natify, zminus_intify];
paulson@9496
   126
paulson@9496
   127
(** Addition **)
paulson@9496
   128
paulson@9496
   129
Goal "intify(x) $+ y = x $+ y";
paulson@9496
   130
by (simp_tac (simpset() addsimps [zadd_def]) 1);
paulson@9496
   131
qed "zadd_intify1";
paulson@9496
   132
paulson@9496
   133
Goal "x $+ intify(y) = x $+ y";
paulson@9496
   134
by (simp_tac (simpset() addsimps [zadd_def]) 1);
paulson@9496
   135
qed "zadd_intify2";
paulson@9496
   136
Addsimps [zadd_intify1, zadd_intify2];
paulson@9496
   137
paulson@9548
   138
(** Subtraction **)
paulson@9548
   139
paulson@9548
   140
Goal "intify(x) $- y = x $- y";
paulson@9548
   141
by (simp_tac (simpset() addsimps [zdiff_def]) 1);
paulson@9548
   142
qed "zdiff_intify1";
paulson@9548
   143
paulson@9548
   144
Goal "x $- intify(y) = x $- y";
paulson@9548
   145
by (simp_tac (simpset() addsimps [zdiff_def]) 1);
paulson@9548
   146
qed "zdiff_intify2";
paulson@9548
   147
Addsimps [zdiff_intify1, zdiff_intify2];
paulson@9548
   148
paulson@9496
   149
(** Multiplication **)
paulson@9496
   150
paulson@9496
   151
Goal "intify(x) $* y = x $* y";
paulson@9496
   152
by (simp_tac (simpset() addsimps [zmult_def]) 1);
paulson@9496
   153
qed "zmult_intify1";
paulson@9496
   154
paulson@9496
   155
Goal "x $* intify(y) = x $* y";
paulson@9496
   156
by (simp_tac (simpset() addsimps [zmult_def]) 1);
paulson@9496
   157
qed "zmult_intify2";
paulson@9496
   158
Addsimps [zmult_intify1, zmult_intify2];
paulson@9496
   159
paulson@9548
   160
(** Orderings **)
paulson@9548
   161
paulson@9548
   162
Goal "intify(x) $< y <-> x $< y";
paulson@9548
   163
by (simp_tac (simpset() addsimps [zless_def]) 1);
paulson@9548
   164
qed "zless_intify1";
paulson@9548
   165
paulson@9548
   166
Goal "x $< intify(y) <-> x $< y";
paulson@9548
   167
by (simp_tac (simpset() addsimps [zless_def]) 1);
paulson@9548
   168
qed "zless_intify2";
paulson@9548
   169
Addsimps [zless_intify1, zless_intify2];
paulson@9548
   170
paulson@9570
   171
Goal "intify(x) $<= y <-> x $<= y";
paulson@9570
   172
by (simp_tac (simpset() addsimps [zle_def]) 1);
paulson@9570
   173
qed "zle_intify1";
paulson@9570
   174
paulson@9570
   175
Goal "x $<= intify(y) <-> x $<= y";
paulson@9570
   176
by (simp_tac (simpset() addsimps [zle_def]) 1);
paulson@9570
   177
qed "zle_intify2";
paulson@9570
   178
Addsimps [zle_intify1, zle_intify2];
paulson@9570
   179
paulson@5561
   180
paulson@5561
   181
(**** zminus: unary negation on int ****)
paulson@5561
   182
paulson@5561
   183
Goalw [congruent_def] "congruent(intrel, %<x,y>. intrel``{<y,x>})";
paulson@5561
   184
by Safe_tac;
paulson@5561
   185
by (asm_full_simp_tac (simpset() addsimps add_ac) 1);
paulson@5561
   186
qed "zminus_congruent";
paulson@5561
   187
paulson@9333
   188
val RSLIST = curry (op MRS);
paulson@9333
   189
paulson@5561
   190
(*Resolve th against the corresponding facts for zminus*)
paulson@5561
   191
val zminus_ize = RSLIST [equiv_intrel, zminus_congruent];
paulson@5561
   192
paulson@9496
   193
Goalw [int_def,raw_zminus_def] "z : int ==> raw_zminus(z) : int";
paulson@6153
   194
by (typecheck_tac (tcset() addTCs [zminus_ize UN_equiv_class_type]));
paulson@9496
   195
qed "raw_zminus_type";
paulson@9496
   196
paulson@9548
   197
Goalw [zminus_def] "$-z : int";
paulson@9496
   198
by (simp_tac (simpset() addsimps [zminus_def, raw_zminus_type]) 1);
paulson@5561
   199
qed "zminus_type";
paulson@9496
   200
AddIffs [zminus_type];
paulson@6153
   201
AddTCs [zminus_type];
paulson@5561
   202
paulson@9496
   203
paulson@9496
   204
Goalw [int_def,raw_zminus_def]
paulson@9496
   205
     "[| raw_zminus(z) = raw_zminus(w);  z: int;  w: int |] ==> z=w";
paulson@5561
   206
by (etac (zminus_ize UN_equiv_class_inject) 1);
paulson@5561
   207
by Safe_tac;
paulson@9496
   208
by (auto_tac (claset() addDs [eq_intrelD], simpset() addsimps add_ac));  
paulson@9496
   209
qed "raw_zminus_inject";
paulson@9496
   210
paulson@9548
   211
Goalw [zminus_def] "$-z = $-w ==> intify(z) = intify(w)";
paulson@9496
   212
by (blast_tac (claset() addSDs [raw_zminus_inject]) 1);
paulson@9496
   213
qed "zminus_inject_intify";
paulson@9496
   214
paulson@9496
   215
AddSDs [zminus_inject_intify];
paulson@9496
   216
paulson@9548
   217
Goal "[| $-z = $-w;  z: int;  w: int |] ==> z=w";
paulson@9496
   218
by Auto_tac;  
paulson@5561
   219
qed "zminus_inject";
paulson@5561
   220
paulson@9496
   221
Goalw [raw_zminus_def]
paulson@9496
   222
    "[| x: nat;  y: nat |] \
paulson@9496
   223
\    ==> raw_zminus(intrel``{<x,y>}) = intrel `` {<y,x>}";
paulson@9496
   224
by (asm_simp_tac (simpset() addsimps [zminus_ize UN_equiv_class, SigmaI]) 1);
paulson@9496
   225
qed "raw_zminus";
paulson@9496
   226
paulson@5561
   227
Goalw [zminus_def]
paulson@9496
   228
    "[| x: nat;  y: nat |] \
paulson@9548
   229
\    ==> $- (intrel``{<x,y>}) = intrel `` {<y,x>}";
paulson@9496
   230
by (asm_simp_tac (simpset() addsimps [raw_zminus, image_intrel_int]) 1);
paulson@5561
   231
qed "zminus";
paulson@5561
   232
paulson@9496
   233
Goalw [int_def] "z : int ==> raw_zminus (raw_zminus(z)) = z";
paulson@9496
   234
by (auto_tac (claset(), simpset() addsimps [raw_zminus]));  
paulson@9496
   235
qed "raw_zminus_zminus";
paulson@5561
   236
paulson@9548
   237
Goal "$- ($- z) = intify(z)";
paulson@9496
   238
by (simp_tac (simpset() addsimps [zminus_def, raw_zminus_type, 
paulson@9496
   239
	                          raw_zminus_zminus]) 1);
paulson@9496
   240
qed "zminus_zminus_intify"; 
paulson@9496
   241
paulson@9548
   242
Goalw [int_of_def] "$- ($#0) = $#0";
paulson@5561
   243
by (simp_tac (simpset() addsimps [zminus]) 1);
paulson@5561
   244
qed "zminus_0";
paulson@5561
   245
paulson@9496
   246
Addsimps [zminus_zminus_intify, zminus_0];
paulson@9496
   247
paulson@9548
   248
Goal "z : int ==> $- ($- z) = z";
paulson@9496
   249
by (Asm_simp_tac 1);
paulson@9496
   250
qed "zminus_zminus";
paulson@5561
   251
paulson@5561
   252
paulson@5561
   253
(**** znegative: the test for negative integers ****)
paulson@5561
   254
paulson@5561
   255
(*No natural number is negative!*)
paulson@5561
   256
Goalw [znegative_def, int_of_def]  "~ znegative($# n)";
paulson@5561
   257
by Safe_tac;
paulson@5561
   258
by (dres_inst_tac [("psi", "?lhs=?rhs")] asm_rl 1);
paulson@5561
   259
by (dres_inst_tac [("psi", "?lhs<?rhs")] asm_rl 1);
paulson@5561
   260
by (force_tac (claset(),
paulson@9548
   261
	       simpset() addsimps [add_le_self2 RS le_imp_not_lt,
paulson@9548
   262
				   natify_succ]) 1);
paulson@5561
   263
qed "not_znegative_int_of";
paulson@5561
   264
paulson@5561
   265
Addsimps [not_znegative_int_of];
paulson@5561
   266
AddSEs   [not_znegative_int_of RS notE];
paulson@5561
   267
paulson@9548
   268
Goalw [znegative_def, int_of_def] "znegative($- $# succ(n))";
paulson@9548
   269
by (asm_simp_tac (simpset() addsimps [zminus, natify_succ]) 1);
paulson@5561
   270
by (blast_tac (claset() addIs [nat_0_le]) 1);
paulson@5561
   271
qed "znegative_zminus_int_of";
paulson@5561
   272
paulson@5561
   273
Addsimps [znegative_zminus_int_of];
paulson@5561
   274
paulson@9548
   275
Goalw [znegative_def, int_of_def] "~ znegative($- $# n) ==> natify(n)=0";
paulson@5561
   276
by (asm_full_simp_tac (simpset() addsimps [zminus, image_singleton_iff]) 1);
paulson@9496
   277
by (dres_inst_tac [("x","0")] spec 1);
paulson@9496
   278
by (auto_tac(claset(), 
paulson@9496
   279
             simpset() addsimps [nat_into_Ord RS Ord_0_lt_iff RS iff_sym]));
paulson@5561
   280
qed "not_znegative_imp_zero";
paulson@5561
   281
paulson@5561
   282
(**** zmagnitude: magnitide of an integer, as a natural number ****)
paulson@5561
   283
paulson@9496
   284
Goalw [zmagnitude_def] "zmagnitude($# n) = natify(n)";
paulson@9496
   285
by (auto_tac (claset(), simpset() addsimps [int_of_eq]));  
paulson@5561
   286
qed "zmagnitude_int_of";
paulson@5561
   287
paulson@9496
   288
Goal "natify(x)=n ==> $#x = $# n";
paulson@9496
   289
by (dtac sym 1);
paulson@9496
   290
by (asm_simp_tac (simpset() addsimps [int_of_eq]) 1);
paulson@9496
   291
qed "natify_int_of_eq";
paulson@9496
   292
paulson@9548
   293
Goalw [zmagnitude_def] "zmagnitude($- $# n) = natify(n)";
paulson@9496
   294
by (rtac the_equality 1);
paulson@9496
   295
by (auto_tac((claset() addSDs [not_znegative_imp_zero, natify_int_of_eq], 
paulson@9496
   296
              simpset())
paulson@9496
   297
             delIffs [int_of_eq]));
paulson@9496
   298
by Auto_tac;  
paulson@5561
   299
qed "zmagnitude_zminus_int_of";
paulson@5561
   300
paulson@5561
   301
Addsimps [zmagnitude_int_of, zmagnitude_zminus_int_of];
paulson@5561
   302
paulson@5561
   303
Goalw [zmagnitude_def] "zmagnitude(z) : nat";
paulson@6153
   304
by (rtac theI2 1);
paulson@5561
   305
by Auto_tac;
paulson@5561
   306
qed "zmagnitude_type";
paulson@9570
   307
AddIffs [zmagnitude_type];
paulson@6153
   308
AddTCs [zmagnitude_type];
paulson@5561
   309
paulson@5561
   310
Goalw [int_def, znegative_def, int_of_def]
paulson@5561
   311
     "[| z: int; ~ znegative(z) |] ==> EX n:nat. z = $# n"; 
paulson@5561
   312
by (auto_tac(claset() , simpset() addsimps [image_singleton_iff]));
paulson@5561
   313
by (rename_tac "i j" 1);
paulson@5561
   314
by (dres_inst_tac [("x", "i")] spec 1);
paulson@5561
   315
by (dres_inst_tac [("x", "j")] spec 1);
paulson@6153
   316
by (rtac bexI 1);
paulson@6153
   317
by (rtac (add_diff_inverse2 RS sym) 1);
paulson@5561
   318
by Auto_tac;
paulson@8201
   319
by (asm_full_simp_tac (simpset() addsimps [not_lt_iff_le]) 1);
paulson@5561
   320
qed "not_zneg_int_of";
paulson@5561
   321
paulson@5561
   322
Goal "[| z: int; ~ znegative(z) |] ==> $# (zmagnitude(z)) = z"; 
paulson@6153
   323
by (dtac not_zneg_int_of 1);
paulson@5561
   324
by Auto_tac;
paulson@5561
   325
qed "not_zneg_mag"; 
paulson@5561
   326
paulson@5561
   327
Addsimps [not_zneg_mag];
paulson@5561
   328
paulson@5561
   329
Goalw [int_def, znegative_def, int_of_def]
paulson@9548
   330
     "[| z: int; znegative(z) |] ==> EX n:nat. z = $- ($# succ(n))"; 
paulson@9548
   331
by (auto_tac(claset() addSDs [less_imp_succ_add], 
paulson@5561
   332
	     simpset() addsimps [zminus, image_singleton_iff]));
paulson@5561
   333
qed "zneg_int_of";
paulson@5561
   334
paulson@9548
   335
Goal "[| z: int; znegative(z) |] ==> $# (zmagnitude(z)) = $- z"; 
paulson@6153
   336
by (dtac zneg_int_of 1);
paulson@5561
   337
by Auto_tac;
paulson@5561
   338
qed "zneg_mag"; 
paulson@5561
   339
paulson@5561
   340
Addsimps [zneg_mag];
paulson@5561
   341
paulson@9570
   342
Goal "z : int ==> EX n: nat. z = $# n | z = $- ($# succ(n))"; 
paulson@9570
   343
by (case_tac "znegative(z)" 1);
paulson@9570
   344
by (blast_tac (claset() addDs [not_zneg_mag, sym]) 2);
paulson@9570
   345
by (blast_tac (claset() addDs [zneg_int_of]) 1);
paulson@9570
   346
qed "int_cases"; 
paulson@9570
   347
paulson@5561
   348
paulson@5561
   349
(**** zadd: addition on int ****)
paulson@5561
   350
paulson@5561
   351
(** Congruence property for addition **)
paulson@5561
   352
paulson@5561
   353
Goalw [congruent2_def]
paulson@5561
   354
    "congruent2(intrel, %z1 z2.                      \
paulson@5561
   355
\         let <x1,y1>=z1; <x2,y2>=z2                 \
paulson@5561
   356
\                           in intrel``{<x1#+x2, y1#+y2>})";
paulson@5561
   357
(*Proof via congruent2_commuteI seems longer*)
paulson@5561
   358
by Safe_tac;
paulson@5561
   359
by (asm_simp_tac (simpset() addsimps [add_assoc, Let_def]) 1);
paulson@5561
   360
(*The rest should be trivial, but rearranging terms is hard;
paulson@5561
   361
  add_ac does not help rewriting with the assumptions.*)
paulson@5561
   362
by (res_inst_tac [("m1","x1a")] (add_left_commute RS ssubst) 1);
paulson@9491
   363
by (res_inst_tac [("m1","x2a")] (add_left_commute RS ssubst) 1);
paulson@5561
   364
by (asm_simp_tac (simpset() addsimps [add_assoc RS sym]) 1);
paulson@5561
   365
qed "zadd_congruent2";
paulson@5561
   366
paulson@5561
   367
(*Resolve th against the corresponding facts for zadd*)
paulson@5561
   368
val zadd_ize = RSLIST [equiv_intrel, zadd_congruent2];
paulson@5561
   369
paulson@9496
   370
Goalw [int_def,raw_zadd_def] "[| z: int;  w: int |] ==> raw_zadd(z,w) : int";
paulson@5561
   371
by (rtac (zadd_ize UN_equiv_class_type2) 1);
paulson@5561
   372
by (simp_tac (simpset() addsimps [Let_def]) 3);
paulson@9496
   373
by (REPEAT (assume_tac 1));
paulson@9496
   374
qed "raw_zadd_type";
paulson@5561
   375
paulson@9496
   376
Goal "z $+ w : int";
paulson@9496
   377
by (simp_tac (simpset() addsimps [zadd_def, raw_zadd_type]) 1);
paulson@9496
   378
qed "zadd_type";
paulson@9496
   379
AddIffs [zadd_type];  AddTCs [zadd_type];
paulson@9496
   380
paulson@9496
   381
Goalw [raw_zadd_def]
paulson@9496
   382
  "[| x1: nat; y1: nat;  x2: nat; y2: nat |]              \
paulson@9496
   383
\  ==> raw_zadd (intrel``{<x1,y1>}, intrel``{<x2,y2>}) =  \
paulson@9496
   384
\      intrel `` {<x1#+x2, y1#+y2>}";
paulson@5561
   385
by (asm_simp_tac (simpset() addsimps [zadd_ize UN_equiv_class2, SigmaI]) 1);
paulson@5561
   386
by (simp_tac (simpset() addsimps [Let_def]) 1);
paulson@9496
   387
qed "raw_zadd";
paulson@9496
   388
paulson@9496
   389
Goalw [zadd_def]
paulson@9496
   390
  "[| x1: nat; y1: nat;  x2: nat; y2: nat |]         \
paulson@9496
   391
\  ==> (intrel``{<x1,y1>}) $+ (intrel``{<x2,y2>}) =  \
paulson@9496
   392
\      intrel `` {<x1#+x2, y1#+y2>}";
paulson@9496
   393
by (asm_simp_tac (simpset() addsimps [raw_zadd, image_intrel_int]) 1);
paulson@5561
   394
qed "zadd";
paulson@5561
   395
paulson@9496
   396
Goalw [int_def,int_of_def] "z : int ==> raw_zadd ($#0,z) = z";
paulson@9496
   397
by (auto_tac (claset(), simpset() addsimps [raw_zadd]));  
paulson@9548
   398
qed "raw_zadd_int0";
paulson@9496
   399
paulson@9496
   400
Goal "$#0 $+ z = intify(z)";
paulson@9548
   401
by (asm_simp_tac (simpset() addsimps [zadd_def, raw_zadd_int0]) 1);
paulson@9548
   402
qed "zadd_int0_intify";
paulson@9548
   403
Addsimps [zadd_int0_intify];
paulson@9496
   404
paulson@9496
   405
Goal "z: int ==> $#0 $+ z = z";
paulson@9496
   406
by (Asm_simp_tac 1);
paulson@9548
   407
qed "zadd_int0";
paulson@5561
   408
paulson@9496
   409
Goalw [int_def]
paulson@9548
   410
     "[| z: int;  w: int |] ==> $- raw_zadd(z,w) = raw_zadd($- z, $- w)";
paulson@9496
   411
by (auto_tac (claset(), simpset() addsimps [zminus,raw_zadd]));  
paulson@9496
   412
qed "raw_zminus_zadd_distrib";
paulson@9496
   413
paulson@9548
   414
Goal "$- (z $+ w) = $- z $+ $- w";
paulson@9496
   415
by (simp_tac (simpset() addsimps [zadd_def, raw_zminus_zadd_distrib]) 1);
paulson@5561
   416
qed "zminus_zadd_distrib";
paulson@5561
   417
paulson@9548
   418
Addsimps [zminus_zadd_distrib];
paulson@9548
   419
paulson@9496
   420
Goalw [int_def] "[| z: int;  w: int |] ==> raw_zadd(z,w) = raw_zadd(w,z)";
paulson@9496
   421
by (auto_tac (claset(), simpset() addsimps raw_zadd::add_ac));  
paulson@9496
   422
qed "raw_zadd_commute";
paulson@9496
   423
paulson@9496
   424
Goal "z $+ w = w $+ z";
paulson@9496
   425
by (simp_tac (simpset() addsimps [zadd_def, raw_zadd_commute]) 1);
paulson@5561
   426
qed "zadd_commute";
paulson@5561
   427
paulson@5561
   428
Goalw [int_def]
paulson@5561
   429
    "[| z1: int;  z2: int;  z3: int |]   \
paulson@9496
   430
\    ==> raw_zadd (raw_zadd(z1,z2),z3) = raw_zadd(z1,raw_zadd(z2,z3))";
paulson@9496
   431
by (auto_tac (claset(), simpset() addsimps [raw_zadd, add_assoc]));  
paulson@9496
   432
qed "raw_zadd_assoc";
paulson@9496
   433
paulson@9496
   434
Goal "(z1 $+ z2) $+ z3 = z1 $+ (z2 $+ z3)";
paulson@9496
   435
by (simp_tac (simpset() addsimps [zadd_def, raw_zadd_type, raw_zadd_assoc]) 1);
paulson@5561
   436
qed "zadd_assoc";
paulson@5561
   437
paulson@5561
   438
(*For AC rewriting*)
paulson@9496
   439
Goal "z1$+(z2$+z3) = z2$+(z1$+z3)";
paulson@6153
   440
by (asm_simp_tac (simpset() addsimps [zadd_assoc RS sym]) 1);
paulson@6153
   441
by (asm_simp_tac (simpset() addsimps [zadd_commute]) 1);
paulson@5561
   442
qed "zadd_left_commute";
paulson@5561
   443
paulson@5561
   444
(*Integer addition is an AC operator*)
paulson@5561
   445
val zadd_ac = [zadd_assoc, zadd_commute, zadd_left_commute];
paulson@5561
   446
paulson@9496
   447
Goalw [int_of_def] "$# (m #+ n) = ($#m) $+ ($#n)";
paulson@5561
   448
by (asm_simp_tac (simpset() addsimps [zadd]) 1);
paulson@5561
   449
qed "int_of_add";
paulson@5561
   450
paulson@9570
   451
Goal "$# succ(m) = $# 1 $+ ($# m)";
paulson@9570
   452
by (simp_tac (simpset() addsimps [int_of_add RS sym, natify_succ]) 1);
paulson@9570
   453
qed "int_succ_int_1";
paulson@9570
   454
paulson@9570
   455
Goalw [int_of_def,zdiff_def]
paulson@9570
   456
     "[| m: nat;  n le m |] ==> $# (m #- n) = ($#m) $- ($#n)";
paulson@9570
   457
by (ftac lt_nat_in_nat 1);
paulson@9570
   458
by (asm_simp_tac (simpset() addsimps [zadd,zminus,add_diff_inverse2]) 2);
paulson@9570
   459
by Auto_tac;  
paulson@9570
   460
qed "int_of_diff";
paulson@9570
   461
paulson@9548
   462
Goalw [int_def,int_of_def] "z : int ==> raw_zadd (z, $- z) = $#0";
paulson@9496
   463
by (auto_tac (claset(), simpset() addsimps [zminus, raw_zadd, add_commute]));  
paulson@9496
   464
qed "raw_zadd_zminus_inverse";
paulson@9496
   465
paulson@9548
   466
Goal "z $+ ($- z) = $#0";
paulson@9496
   467
by (simp_tac (simpset() addsimps [zadd_def]) 1);
paulson@9496
   468
by (stac (zminus_intify RS sym) 1);
paulson@9496
   469
by (rtac (intify_in_int RS raw_zadd_zminus_inverse) 1); 
paulson@5561
   470
qed "zadd_zminus_inverse";
paulson@5561
   471
paulson@9548
   472
Goal "($- z) $+ z = $#0";
paulson@9496
   473
by (simp_tac (simpset() addsimps [zadd_commute, zadd_zminus_inverse]) 1);
paulson@5561
   474
qed "zadd_zminus_inverse2";
paulson@5561
   475
paulson@9496
   476
Goal "z $+ $#0 = intify(z)";
paulson@9548
   477
by (rtac ([zadd_commute, zadd_int0_intify] MRS trans) 1);
paulson@9548
   478
qed "zadd_int0_right_intify";
paulson@9548
   479
Addsimps [zadd_int0_right_intify];
paulson@9496
   480
paulson@5561
   481
Goal "z:int ==> z $+ $#0 = z";
paulson@9496
   482
by (Asm_simp_tac 1);
paulson@9548
   483
qed "zadd_int0_right";
paulson@5561
   484
paulson@9496
   485
Addsimps [zadd_zminus_inverse, zadd_zminus_inverse2];
paulson@5561
   486
paulson@5561
   487
paulson@5561
   488
paulson@5561
   489
(**** zmult: multiplication on int ****)
paulson@5561
   490
paulson@5561
   491
(** Congruence property for multiplication **)
paulson@5561
   492
paulson@5561
   493
Goal "congruent2(intrel, %p1 p2.                 \
paulson@5561
   494
\               split(%x1 y1. split(%x2 y2.     \
paulson@5561
   495
\                   intrel``{<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}, p2), p1))";
paulson@5561
   496
by (rtac (equiv_intrel RS congruent2_commuteI) 1);
paulson@9548
   497
by Auto_tac;
paulson@5561
   498
(*Proof that zmult is congruent in one argument*)
paulson@9548
   499
by (rename_tac "x y" 1);
paulson@9548
   500
by (forw_inst_tac [("t", "%u. x#*u")] (sym RS subst_context) 1);
paulson@9548
   501
by (dres_inst_tac [("t", "%u. y#*u")] subst_context 1);
paulson@9548
   502
by (REPEAT (etac add_left_cancel 1));
paulson@9548
   503
by (asm_simp_tac (simpset() addsimps [add_mult_distrib_left]) 1);
paulson@9548
   504
by Auto_tac;
paulson@5561
   505
qed "zmult_congruent2";
paulson@5561
   506
paulson@5561
   507
paulson@5561
   508
(*Resolve th against the corresponding facts for zmult*)
paulson@5561
   509
val zmult_ize = RSLIST [equiv_intrel, zmult_congruent2];
paulson@5561
   510
paulson@9496
   511
Goalw [int_def,raw_zmult_def] "[| z: int;  w: int |] ==> raw_zmult(z,w) : int";
paulson@5561
   512
by (REPEAT (ares_tac [zmult_ize UN_equiv_class_type2,
paulson@5561
   513
                      split_type, add_type, mult_type, 
paulson@5561
   514
                      quotientI, SigmaI] 1));
paulson@9496
   515
qed "raw_zmult_type";
paulson@9496
   516
paulson@9496
   517
Goal "z $* w : int";
paulson@9496
   518
by (simp_tac (simpset() addsimps [zmult_def, raw_zmult_type]) 1);
paulson@5561
   519
qed "zmult_type";
paulson@9496
   520
AddIffs [zmult_type];  AddTCs [zmult_type];
paulson@9496
   521
paulson@9496
   522
Goalw [raw_zmult_def]
paulson@9496
   523
     "[| x1: nat; y1: nat;  x2: nat; y2: nat |]    \
paulson@9496
   524
\     ==> raw_zmult(intrel``{<x1,y1>}, intrel``{<x2,y2>}) =     \
paulson@9496
   525
\         intrel `` {<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}";
paulson@9496
   526
by (asm_simp_tac (simpset() addsimps [zmult_ize UN_equiv_class2, SigmaI]) 1);
paulson@9496
   527
qed "raw_zmult";
paulson@5561
   528
paulson@5561
   529
Goalw [zmult_def]
paulson@9496
   530
     "[| x1: nat; y1: nat;  x2: nat; y2: nat |]    \
paulson@9496
   531
\     ==> (intrel``{<x1,y1>}) $* (intrel``{<x2,y2>}) =     \
paulson@9496
   532
\         intrel `` {<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}";
paulson@9496
   533
by (asm_simp_tac (simpset() addsimps [raw_zmult, image_intrel_int]) 1);
paulson@5561
   534
qed "zmult";
paulson@5561
   535
paulson@9496
   536
Goalw [int_def,int_of_def] "z : int ==> raw_zmult ($#0,z) = $#0";
paulson@9496
   537
by (auto_tac (claset(), simpset() addsimps [raw_zmult]));  
paulson@9548
   538
qed "raw_zmult_int0";
paulson@9496
   539
paulson@9496
   540
Goal "$#0 $* z = $#0";
paulson@9548
   541
by (simp_tac (simpset() addsimps [zmult_def, raw_zmult_int0]) 1);
paulson@9548
   542
qed "zmult_int0";
paulson@9548
   543
Addsimps [zmult_int0];
paulson@5561
   544
paulson@9496
   545
Goalw [int_def,int_of_def] "z : int ==> raw_zmult ($#1,z) = z";
paulson@9496
   546
by (auto_tac (claset(), simpset() addsimps [raw_zmult]));  
paulson@9548
   547
qed "raw_zmult_int1";
paulson@9496
   548
paulson@9496
   549
Goal "$#1 $* z = intify(z)";
paulson@9548
   550
by (simp_tac (simpset() addsimps [zmult_def, raw_zmult_int1]) 1);
paulson@9548
   551
qed "zmult_int1_intify";
paulson@9548
   552
Addsimps [zmult_int1_intify];
paulson@9496
   553
paulson@9496
   554
Goal "z : int ==> $#1 $* z = z";
paulson@9496
   555
by (Asm_simp_tac 1);
paulson@9548
   556
qed "zmult_int1";
paulson@5561
   557
paulson@9496
   558
Goalw [int_def] "[| z: int;  w: int |] ==> raw_zmult(z,w) = raw_zmult(w,z)";
paulson@9496
   559
by (auto_tac (claset(), simpset() addsimps [raw_zmult] @ add_ac @ mult_ac));  
paulson@9496
   560
qed "raw_zmult_commute";
paulson@5561
   561
paulson@9496
   562
Goal "z $* w = w $* z";
paulson@9496
   563
by (simp_tac (simpset() addsimps [zmult_def, raw_zmult_commute]) 1);
paulson@5561
   564
qed "zmult_commute";
paulson@5561
   565
paulson@5561
   566
Goalw [int_def]
paulson@9548
   567
     "[| z: int;  w: int |] ==> raw_zmult($- z, w) = $- raw_zmult(z, w)";
paulson@9496
   568
by (auto_tac (claset(), simpset() addsimps [zminus, raw_zmult] @ add_ac));  
paulson@9496
   569
qed "raw_zmult_zminus";
paulson@9496
   570
paulson@9548
   571
Goal "($- z) $* w = $- (z $* w)";
paulson@9496
   572
by (simp_tac (simpset() addsimps [zmult_def, raw_zmult_zminus]) 1);
paulson@9496
   573
by (stac (zminus_intify RS sym) 1 THEN rtac raw_zmult_zminus 1); 
paulson@9496
   574
by Auto_tac;  
paulson@9496
   575
qed "zmult_zminus";
paulson@9496
   576
Addsimps [zmult_zminus];
paulson@9496
   577
paulson@9570
   578
Goal "w $* ($- z) = $- (w $* z)";
paulson@9570
   579
by (simp_tac (simpset() addsimps [inst "z" "w" zmult_commute]) 1);
paulson@9570
   580
qed "zmult_zminus_right";
paulson@9570
   581
Addsimps [zmult_zminus_right];
paulson@9496
   582
paulson@9496
   583
Goalw [int_def]
paulson@9496
   584
    "[| z1: int;  z2: int;  z3: int |]   \
paulson@9496
   585
\    ==> raw_zmult (raw_zmult(z1,z2),z3) = raw_zmult(z1,raw_zmult(z2,z3))";
paulson@9496
   586
by (auto_tac (claset(), 
paulson@9496
   587
  simpset() addsimps [raw_zmult, add_mult_distrib_left] @ add_ac @ mult_ac));  
paulson@9496
   588
qed "raw_zmult_assoc";
paulson@9496
   589
paulson@9496
   590
Goal "(z1 $* z2) $* z3 = z1 $* (z2 $* z3)";
paulson@9496
   591
by (simp_tac (simpset() addsimps [zmult_def, raw_zmult_type, 
paulson@9496
   592
                                  raw_zmult_assoc]) 1);
paulson@5561
   593
qed "zmult_assoc";
paulson@5561
   594
paulson@5561
   595
(*For AC rewriting*)
paulson@9496
   596
Goal "z1$*(z2$*z3) = z2$*(z1$*z3)";
paulson@6153
   597
by (asm_simp_tac (simpset() addsimps [zmult_assoc RS sym]) 1);
paulson@6153
   598
by (asm_simp_tac (simpset() addsimps [zmult_commute]) 1);
paulson@5561
   599
qed "zmult_left_commute";
paulson@5561
   600
paulson@5561
   601
(*Integer multiplication is an AC operator*)
paulson@5561
   602
val zmult_ac = [zmult_assoc, zmult_commute, zmult_left_commute];
paulson@5561
   603
paulson@5561
   604
Goalw [int_def]
paulson@9496
   605
    "[| z1: int;  z2: int;  w: int |]  \
paulson@9496
   606
\    ==> raw_zmult(raw_zadd(z1,z2), w) = \
paulson@9496
   607
\        raw_zadd (raw_zmult(z1,w), raw_zmult(z2,w))";
paulson@9496
   608
by (auto_tac (claset(), 
paulson@9496
   609
              simpset() addsimps [raw_zadd, raw_zmult, add_mult_distrib_left] @ 
paulson@9496
   610
                                 add_ac @ mult_ac));  
paulson@9496
   611
qed "raw_zadd_zmult_distrib";
paulson@9496
   612
paulson@9496
   613
Goal "(z1 $+ z2) $* w = (z1 $* w) $+ (z2 $* w)";
paulson@9496
   614
by (simp_tac (simpset() addsimps [zmult_def, zadd_def, raw_zadd_type, 
paulson@9496
   615
     	                          raw_zmult_type, raw_zadd_zmult_distrib]) 1);
paulson@5561
   616
qed "zadd_zmult_distrib";
paulson@5561
   617
paulson@9496
   618
Goal "w $* (z1 $+ z2) = (w $* z1) $+ (w $* z2)";
paulson@9496
   619
by (simp_tac (simpset() addsimps [inst "z" "w" zmult_commute,
paulson@9496
   620
                                  zadd_zmult_distrib]) 1);
paulson@9496
   621
qed "zadd_zmult_distrib_left";
paulson@9496
   622
paulson@5561
   623
val int_typechecks =
paulson@5561
   624
    [int_of_type, zminus_type, zmagnitude_type, zadd_type, zmult_type];
paulson@5561
   625
paulson@5561
   626
paulson@9548
   627
(*** Subtraction laws ***)
paulson@9548
   628
paulson@9570
   629
Goal "z $- w : int";
paulson@9570
   630
by (simp_tac (simpset() addsimps [zdiff_def]) 1);
paulson@9570
   631
qed "zdiff_type";
paulson@9570
   632
AddIffs [zdiff_type];  AddTCs [zdiff_type];
paulson@9570
   633
paulson@9548
   634
Goal "$#0 $- x = $-x";
paulson@9548
   635
by (simp_tac (simpset() addsimps [zdiff_def]) 1);
paulson@9548
   636
qed "zdiff_int0";
paulson@9548
   637
paulson@9548
   638
Goal "x $- $#0 = intify(x)";
paulson@9548
   639
by (simp_tac (simpset() addsimps [zdiff_def]) 1);
paulson@9548
   640
qed "zdiff_int0_right";
paulson@9548
   641
paulson@9548
   642
Goal "x $- x = $#0";
paulson@9548
   643
by (simp_tac (simpset() addsimps [zdiff_def]) 1);
paulson@9548
   644
qed "zdiff_self";
paulson@9548
   645
paulson@9548
   646
Addsimps [zdiff_int0, zdiff_int0_right, zdiff_self];
paulson@9548
   647
paulson@9570
   648
Goal "$- (z $- y) = y $- z";
paulson@9570
   649
by (simp_tac (simpset() addsimps [zdiff_def, zadd_commute])1);
paulson@9570
   650
qed "zminus_zdiff_eq";
paulson@9570
   651
Addsimps [zminus_zdiff_eq];
paulson@9570
   652
paulson@9570
   653
Goal "$- (z $- y) = y $- z";
paulson@9570
   654
by (simp_tac (simpset() addsimps [zdiff_def, zadd_commute])1);
paulson@9570
   655
qed "zminus_zdiff_eq";
paulson@9570
   656
Addsimps [zminus_zdiff_eq];
paulson@9548
   657
paulson@9548
   658
Goalw [zdiff_def] "(z1 $- z2) $* w = (z1 $* w) $- (z2 $* w)";
paulson@9548
   659
by (stac zadd_zmult_distrib 1);
paulson@9548
   660
by (simp_tac (simpset() addsimps [zmult_zminus]) 1);
paulson@9548
   661
qed "zdiff_zmult_distrib";
paulson@9548
   662
paulson@9548
   663
val zmult_commute'= inst "z" "w" zmult_commute;
paulson@9548
   664
paulson@9548
   665
Goal "w $* (z1 $- z2) = (w $* z1) $- (w $* z2)";
paulson@9548
   666
by (simp_tac (simpset() addsimps [zmult_commute',zdiff_zmult_distrib]) 1);
paulson@9548
   667
qed "zdiff_zmult_distrib2";
paulson@9548
   668
paulson@9548
   669
Goal "x $+ (y $- z) = (x $+ y) $- z";
paulson@9548
   670
by (simp_tac (simpset() addsimps zdiff_def::zadd_ac) 1);
paulson@9548
   671
qed "zadd_zdiff_eq";
paulson@9548
   672
paulson@9548
   673
Goal "(x $- y) $+ z = (x $+ z) $- y";
paulson@9548
   674
by (simp_tac (simpset() addsimps zdiff_def::zadd_ac) 1);
paulson@9548
   675
qed "zdiff_zadd_eq";
paulson@9548
   676
paulson@9548
   677
paulson@9548
   678
(*** "Less Than" ***)
paulson@9548
   679
paulson@9548
   680
(*"Less than" is a linear ordering*)
paulson@9548
   681
Goalw [int_def, zless_def, znegative_def, zdiff_def] 
paulson@9548
   682
     "[| z: int; w: int |] ==> z$<w | z=w | w$<z"; 
paulson@9548
   683
by Auto_tac;  
paulson@9548
   684
by (asm_full_simp_tac
paulson@9548
   685
    (simpset() addsimps [zadd, zminus, image_iff, Bex_def]) 1);
paulson@9548
   686
by (res_inst_tac [("i", "xb#+ya"), ("j", "xc #+ y")] Ord_linear_lt 1);
paulson@9548
   687
by (ALLGOALS (force_tac (claset() addSDs [spec], 
paulson@9548
   688
                         simpset() addsimps add_ac)));
paulson@9548
   689
qed "zless_linear_lemma";
paulson@9548
   690
paulson@9548
   691
Goal "z$<w | intify(z)=intify(w) | w$<z"; 
paulson@9548
   692
by (cut_inst_tac [("z"," intify(z)"),("w"," intify(w)")] zless_linear_lemma 1);
paulson@9548
   693
by Auto_tac;  
paulson@9548
   694
qed "zless_linear";
paulson@9548
   695
paulson@9548
   696
Goal "~ (z$<z)";
paulson@9548
   697
by (auto_tac (claset(), 
paulson@9548
   698
              simpset() addsimps  [zless_def, znegative_def, int_of_def]));  
paulson@9548
   699
by (rotate_tac 2 1);
paulson@9548
   700
by Auto_tac;  
paulson@9548
   701
qed "zless_not_refl";
paulson@9548
   702
AddIffs [zless_not_refl];
paulson@9548
   703
paulson@9548
   704
(*This lemma allows direct proofs of other <-properties*)
paulson@9548
   705
Goalw [zless_def, znegative_def, zdiff_def, int_def] 
paulson@9548
   706
    "[| w $< z; w: int; z: int |] ==> (EX n. z = w $+ $#(succ(n)))";
paulson@9548
   707
by (auto_tac (claset() addSDs [less_imp_succ_add], 
paulson@9548
   708
              simpset() addsimps [zadd, zminus, int_of_def]));  
paulson@9548
   709
by (res_inst_tac [("x","k")] exI 1);
paulson@9548
   710
by (etac add_left_cancel 1);
paulson@9548
   711
by Auto_tac;  
paulson@9548
   712
qed "zless_imp_succ_zadd_lemma";
paulson@9548
   713
paulson@9548
   714
Goal "w $< z ==> (EX n. w $+ $#(succ(n)) = intify(z))";
paulson@9548
   715
by (subgoal_tac "intify(w) $< intify(z)" 1);
paulson@9548
   716
by (dres_inst_tac [("w","intify(w)")] zless_imp_succ_zadd_lemma 1);
paulson@9548
   717
by Auto_tac;  
paulson@9548
   718
qed "zless_imp_succ_zadd";
paulson@9548
   719
paulson@9548
   720
Goalw [zless_def, znegative_def, zdiff_def, int_def] 
paulson@9548
   721
    "w : int ==> w $< w $+ $# succ(n)";
paulson@9548
   722
by (auto_tac (claset(), 
paulson@9548
   723
              simpset() addsimps [zadd, zminus, int_of_def, image_iff]));  
paulson@9548
   724
by (res_inst_tac [("x","0")] exI 1);
paulson@9548
   725
by Auto_tac;  
paulson@9548
   726
qed "zless_succ_zadd_lemma";
paulson@9548
   727
paulson@9548
   728
Goal "w $< w $+ $# succ(n)";
paulson@9548
   729
by (cut_facts_tac [intify_in_int RS zless_succ_zadd_lemma] 1);
paulson@9548
   730
by Auto_tac;  
paulson@9548
   731
qed "zless_succ_zadd";
paulson@9548
   732
paulson@9548
   733
Goal "w $< z <-> (EX n. w $+ $#(succ(n)) = intify(z))";
paulson@9548
   734
by (rtac iffI 1);
paulson@9548
   735
by (etac zless_imp_succ_zadd 1);
paulson@9548
   736
by Auto_tac;  
paulson@9548
   737
by (cut_inst_tac [("w","w"),("n","n")] zless_succ_zadd 1);
paulson@9548
   738
by Auto_tac;  
paulson@9548
   739
qed "zless_iff_succ_zadd";
paulson@9548
   740
paulson@9548
   741
Goalw [zless_def, znegative_def, zdiff_def, int_def] 
paulson@9548
   742
    "[| x $< y; y $< z; x: int; y : int; z: int |] ==> x $< z"; 
paulson@9548
   743
by (auto_tac (claset(), 
paulson@9548
   744
              simpset() addsimps [zadd, zminus, int_of_def, image_iff]));
paulson@9548
   745
by (rename_tac "x1 x2 y1 y2" 1);
paulson@9548
   746
by (res_inst_tac [("x","x1#+x2")] exI 1);  
paulson@9548
   747
by (res_inst_tac [("x","y1#+y2")] exI 1);  
paulson@9548
   748
by (auto_tac (claset(), simpset() addsimps [add_lt_mono]));  
paulson@9548
   749
by (rtac sym 1);
paulson@9548
   750
by (REPEAT (etac add_left_cancel 1));
paulson@9548
   751
by Auto_tac;  
paulson@9548
   752
qed "zless_trans_lemma";
paulson@9548
   753
paulson@9548
   754
Goal "[| x $< y; y $< z |] ==> x $< z"; 
paulson@9548
   755
by (subgoal_tac "intify(x) $< intify(z)" 1);
paulson@9548
   756
by (res_inst_tac [("y", "intify(y)")] zless_trans_lemma 2);
paulson@9548
   757
by Auto_tac;  
paulson@9548
   758
qed "zless_trans";
paulson@9548
   759
paulson@9570
   760
(*** "Less Than or Equals", $<= ***)
paulson@9548
   761
paulson@9548
   762
Goalw [zle_def] "z $<= z";
paulson@9548
   763
by Auto_tac;  
paulson@9548
   764
qed "zle_refl";
paulson@9548
   765
paulson@9570
   766
Goalw [zle_def] "[| x $<= y; y $<= x |] ==> intify(x) = intify(y)";
paulson@9570
   767
by Auto_tac;  
paulson@9548
   768
by (blast_tac (claset() addDs [zless_trans]) 1);
paulson@9548
   769
qed "zle_anti_sym";
paulson@9548
   770
paulson@9570
   771
Goalw [zle_def] "[| x: int; y: int; z: int; x $<= y; y $<= z |] ==> x $<= z";
paulson@9570
   772
by Auto_tac;  
paulson@9548
   773
by (blast_tac (claset() addIs [zless_trans]) 1);
paulson@9570
   774
val lemma = result();
paulson@9570
   775
paulson@9570
   776
Goal "[| x $<= y; y $<= z |] ==> x $<= z";
paulson@9570
   777
by (subgoal_tac "intify(x) $<= intify(z)" 1);
paulson@9570
   778
by (res_inst_tac [("y", "intify(y)")] lemma 2);
paulson@9570
   779
by Auto_tac;  
paulson@9548
   780
qed "zle_trans";
paulson@9548
   781
paulson@9570
   782
Goal "[| i $<= j; j $< k |] ==> i $< k";
paulson@9570
   783
by (auto_tac (claset(), simpset() addsimps [zle_def]));  
paulson@9570
   784
by (blast_tac (claset() addIs [zless_trans]) 1);
paulson@9570
   785
by (asm_full_simp_tac (simpset() addsimps [zless_def, zdiff_def, zadd_def]) 1);
paulson@9570
   786
qed "zle_zless_trans";
paulson@9548
   787
paulson@9570
   788
Goal "[| i $< j; j $<= k |] ==> i $< k";
paulson@9570
   789
by (auto_tac (claset(), simpset() addsimps [zle_def]));  
paulson@9570
   790
by (blast_tac (claset() addIs [zless_trans]) 1);
paulson@9570
   791
by (asm_full_simp_tac
paulson@9570
   792
    (simpset() addsimps [zless_def, zdiff_def, zminus_def]) 1);
paulson@9570
   793
qed "zless_zle_trans";
paulson@9570
   794
paulson@9570
   795
Goal "~ (z $< w) <-> (w $<= z)";
paulson@9570
   796
by (cut_inst_tac [("z","z"),("w","w")] zless_linear 1);
paulson@9570
   797
by (auto_tac (claset() addDs [zless_trans], simpset() addsimps [zle_def]));  
paulson@9570
   798
by (auto_tac (claset(), 
paulson@9570
   799
            simpset() addsimps [zless_def, zdiff_def, zadd_def, zminus_def]));
paulson@9570
   800
by (fold_tac [zless_def, zdiff_def, zadd_def, zminus_def]);
paulson@9570
   801
by Auto_tac;  
paulson@9570
   802
qed "not_zless_iff_zle";
paulson@9570
   803
paulson@9570
   804
Goal "~ (z $<= w) <-> (w $< z)";
paulson@9570
   805
by (simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 1);
paulson@9570
   806
qed "not_zle_iff_zless";
paulson@9570
   807
paulson@9570
   808
paulson@9570
   809
paulson@9570
   810
(*** More subtraction laws (for zcompare_rls) ***)
paulson@9548
   811
paulson@9548
   812
Goal "(x $- y) $- z = x $- (y $+ z)";
paulson@9548
   813
by (simp_tac (simpset() addsimps zdiff_def::zadd_ac) 1);
paulson@9548
   814
qed "zdiff_zdiff_eq";
paulson@9548
   815
paulson@9548
   816
Goal "x $- (y $- z) = (x $+ z) $- y";
paulson@9548
   817
by (simp_tac (simpset() addsimps zdiff_def::zadd_ac) 1);
paulson@9548
   818
qed "zdiff_zdiff_eq2";
paulson@9548
   819
paulson@9548
   820
Goalw [zless_def, zdiff_def] "(x$-y $< z) <-> (x $< z $+ y)";
paulson@9548
   821
by (simp_tac (simpset() addsimps zadd_ac) 1);
paulson@9548
   822
qed "zdiff_zless_iff";
paulson@9548
   823
paulson@9548
   824
Goalw [zless_def, zdiff_def] "(x $< z$-y) <-> (x $+ y $< z)";
paulson@9548
   825
by (simp_tac (simpset() addsimps zadd_ac) 1);
paulson@9548
   826
qed "zless_zdiff_iff";
paulson@9548
   827
paulson@9548
   828
Goalw [zdiff_def] "[| x: int; z: int |] ==> (x$-y = z) <-> (x = z $+ y)";
paulson@9548
   829
by (auto_tac (claset(), simpset() addsimps [zadd_assoc]));
paulson@9548
   830
qed "zdiff_eq_iff";
paulson@9548
   831
paulson@9548
   832
Goalw [zdiff_def] "[| x: int; z: int |] ==> (x = z$-y) <-> (x $+ y = z)";
paulson@9548
   833
by (auto_tac (claset(), simpset() addsimps [zadd_assoc]));
paulson@9548
   834
qed "eq_zdiff_iff";
paulson@9548
   835
paulson@9548
   836
Goalw [zle_def] "[| x: int; z: int |] ==> (x$-y $<= z) <-> (x $<= z $+ y)";
paulson@9570
   837
by (auto_tac (claset(), simpset() addsimps [zdiff_eq_iff, zdiff_zless_iff]));  
paulson@9570
   838
val lemma = result();
paulson@9570
   839
paulson@9570
   840
Goal "(x$-y $<= z) <-> (x $<= z $+ y)";
paulson@9570
   841
by (cut_facts_tac [[intify_in_int, intify_in_int] MRS lemma] 1);
paulson@9570
   842
by (Asm_full_simp_tac 1);
paulson@9548
   843
qed "zdiff_zle_iff";
paulson@9548
   844
paulson@9570
   845
Goalw [zle_def] "[| x: int; z: int |] ==>(x $<= z$-y) <-> (x $+ y $<= z)";
paulson@9570
   846
by (auto_tac (claset(), simpset() addsimps [zdiff_eq_iff, zless_zdiff_iff]));  
paulson@9570
   847
by (auto_tac (claset(), simpset() addsimps [zdiff_def, zadd_assoc]));  
paulson@9570
   848
val lemma = result();
paulson@9570
   849
paulson@9570
   850
Goal "(x $<= z$-y) <-> (x $+ y $<= z)";
paulson@9570
   851
by (cut_facts_tac [[intify_in_int, intify_in_int] MRS lemma] 1);
paulson@9570
   852
by (Asm_full_simp_tac 1);
paulson@9548
   853
qed "zle_zdiff_iff";
paulson@9570
   854
paulson@9570
   855
(*This list of rewrites simplifies (in)equalities by bringing subtractions
paulson@9570
   856
  to the top and then moving negative terms to the other side.  
paulson@9570
   857
  Use with zadd_ac*)
paulson@9570
   858
bind_thms ("zcompare_rls",
paulson@9570
   859
    [symmetric zdiff_def,
paulson@9570
   860
     zadd_zdiff_eq, zdiff_zadd_eq, zdiff_zdiff_eq, zdiff_zdiff_eq2, 
paulson@9570
   861
     zdiff_zless_iff, zless_zdiff_iff, zdiff_zle_iff, zle_zdiff_iff, 
paulson@9570
   862
     zdiff_eq_iff, eq_zdiff_iff]);
paulson@9548
   863
paulson@9548
   864
paulson@9548
   865
(*** Monotonicity/cancellation results that could allow instantiation
paulson@9548
   866
     of the CancelNumerals simprocs ***)
paulson@9548
   867
paulson@9548
   868
Goal "[| w: int; w': int |] ==> (z $+ w' = z $+ w) <-> (w' = w)";
paulson@9548
   869
by Safe_tac;
paulson@9548
   870
by (dres_inst_tac [("t", "%x. x $+ ($-z)")] subst_context 1);
paulson@9548
   871
by (asm_full_simp_tac (simpset() addsimps zadd_ac) 1);
paulson@9548
   872
qed "zadd_left_cancel";
paulson@9548
   873
paulson@9548
   874
Goal "(z $+ w' = z $+ w) <-> intify(w') = intify(w)";
paulson@9548
   875
by (rtac iff_trans 1);
paulson@9548
   876
by (rtac zadd_left_cancel 2);
paulson@9548
   877
by Auto_tac;  
paulson@9548
   878
qed "zadd_left_cancel_intify";
paulson@9548
   879
paulson@9548
   880
Addsimps [zadd_left_cancel_intify];
paulson@9548
   881
paulson@9548
   882
Goal "[| w: int; w': int |] ==> (w' $+ z = w $+ z) <-> (w' = w)";
paulson@9548
   883
by Safe_tac;
paulson@9548
   884
by (dres_inst_tac [("t", "%x. x $+ ($-z)")] subst_context 1);
paulson@9548
   885
by (asm_full_simp_tac (simpset() addsimps zadd_ac) 1);
paulson@9548
   886
qed "zadd_right_cancel";
paulson@9548
   887
paulson@9548
   888
Goal "(w' $+ z = w $+ z) <-> intify(w') = intify(w)";
paulson@9548
   889
by (rtac iff_trans 1);
paulson@9548
   890
by (rtac zadd_right_cancel 2);
paulson@9548
   891
by Auto_tac;  
paulson@9548
   892
qed "zadd_right_cancel_intify";
paulson@9548
   893
paulson@9548
   894
Addsimps [zadd_right_cancel_intify];
paulson@9548
   895
paulson@9548
   896
paulson@9548
   897
Goal "(w' $+ z $< w $+ z) <-> (w' $< w)";
paulson@9548
   898
by (simp_tac (simpset() addsimps [zdiff_zless_iff RS iff_sym]) 1);
paulson@9548
   899
by (simp_tac (simpset() addsimps [zdiff_def, zadd_assoc]) 1);
paulson@9548
   900
qed "zadd_right_cancel_zless";
paulson@9548
   901
paulson@9548
   902
Goal "(z $+ w' $< z $+ w) <-> (w' $< w)";
paulson@9548
   903
by (simp_tac (simpset() addsimps [inst "z" "z" zadd_commute,
paulson@9548
   904
                                  zadd_right_cancel_zless]) 1);
paulson@9548
   905
qed "zadd_left_cancel_zless";
paulson@9548
   906
paulson@9548
   907
Addsimps [zadd_right_cancel_zless, zadd_left_cancel_zless];
paulson@9548
   908
paulson@9548
   909
paulson@9570
   910
Goal "(w' $+ z $<= w $+ z) <-> w' $<= w";
paulson@9548
   911
by (simp_tac (simpset() addsimps [zle_def]) 1);
paulson@9548
   912
qed "zadd_right_cancel_zle";
paulson@9548
   913
paulson@9570
   914
Goal "(z $+ w' $<= z $+ w) <->  w' $<= w";
paulson@9548
   915
by (simp_tac (simpset() addsimps [inst "z" "z" zadd_commute,
paulson@9548
   916
                                  zadd_right_cancel_zle]) 1);
paulson@9548
   917
qed "zadd_left_cancel_zle";
paulson@9548
   918
paulson@9548
   919
Addsimps [zadd_right_cancel_zle, zadd_left_cancel_zle];
paulson@9548
   920
paulson@9570
   921
paulson@9570
   922
(*** More inequality lemmas ***)
paulson@9570
   923
paulson@9570
   924
Goal "[| x: int;  y: int |] ==> (x = $- y) <-> (y = $- x)";
paulson@9570
   925
by Auto_tac;
paulson@9570
   926
qed "equation_zminus";
paulson@9570
   927
paulson@9570
   928
Goal "[| x: int;  y: int |] ==> ($- x = y) <-> ($- y = x)";
paulson@9570
   929
by Auto_tac;
paulson@9570
   930
qed "zminus_equation";