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