src/HOL/Integ/Integ.ML
author wenzelm
Mon Nov 10 15:25:12 1997 +0100 (1997-11-10)
changeset 4195 7f7bf0bd0f63
parent 4162 4c2da701b801
child 4369 11b217d9d880
permissions -rw-r--r--
ASCII-fied;
clasohm@1465
     1
(*  Title:      Integ.ML
clasohm@925
     2
    ID:         $Id$
paulson@2215
     3
    Authors:    Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@925
     4
    Copyright   1993  University of Cambridge
clasohm@925
     5
clasohm@925
     6
The integers as equivalence classes over nat*nat.
clasohm@925
     7
clasohm@925
     8
Could also prove...
clasohm@925
     9
"znegative(z) ==> $# zmagnitude(z) = $~ z"
clasohm@925
    10
"~ znegative(z) ==> $# zmagnitude(z) = z"
clasohm@925
    11
< is a linear ordering
clasohm@925
    12
+ and * are monotonic wrt <
clasohm@925
    13
*)
clasohm@925
    14
clasohm@925
    15
open Integ;
clasohm@925
    16
berghofe@1894
    17
Delrules [equalityI];
berghofe@1894
    18
clasohm@925
    19
clasohm@925
    20
(*** Proving that intrel is an equivalence relation ***)
clasohm@925
    21
clasohm@925
    22
val eqa::eqb::prems = goal Arith.thy 
clasohm@925
    23
    "[| (x1::nat) + y2 = x2 + y1; x2 + y3 = x3 + y2 |] ==> \
clasohm@925
    24
\       x1 + y3 = x3 + y1";
clasohm@925
    25
by (res_inst_tac [("k2","x2")] (add_left_cancel RS iffD1) 1);
clasohm@925
    26
by (rtac (add_left_commute RS trans) 1);
paulson@2036
    27
by (stac eqb 1);
clasohm@925
    28
by (rtac (add_left_commute RS trans) 1);
paulson@2036
    29
by (stac eqa 1);
clasohm@925
    30
by (rtac (add_left_commute) 1);
clasohm@925
    31
qed "integ_trans_lemma";
clasohm@925
    32
clasohm@925
    33
(** Natural deduction for intrel **)
clasohm@925
    34
clasohm@925
    35
val prems = goalw Integ.thy [intrel_def]
clasohm@925
    36
    "[| x1+y2 = x2+y1|] ==> \
clasohm@972
    37
\    ((x1,y1),(x2,y2)): intrel";
wenzelm@4089
    38
by (fast_tac (claset() addIs prems) 1);
clasohm@925
    39
qed "intrelI";
clasohm@925
    40
clasohm@925
    41
(*intrelE is hard to derive because fast_tac tries hyp_subst_tac so soon*)
clasohm@925
    42
goalw Integ.thy [intrel_def]
clasohm@925
    43
  "p: intrel --> (EX x1 y1 x2 y2. \
clasohm@972
    44
\                  p = ((x1,y1),(x2,y2)) & x1+y2 = x2+y1)";
berghofe@1894
    45
by (Fast_tac 1);
clasohm@925
    46
qed "intrelE_lemma";
clasohm@925
    47
clasohm@925
    48
val [major,minor] = goal Integ.thy
clasohm@925
    49
  "[| p: intrel;  \
clasohm@972
    50
\     !!x1 y1 x2 y2. [| p = ((x1,y1),(x2,y2));  x1+y2 = x2+y1|] ==> Q |] \
clasohm@925
    51
\  ==> Q";
clasohm@925
    52
by (cut_facts_tac [major RS (intrelE_lemma RS mp)] 1);
clasohm@925
    53
by (REPEAT (eresolve_tac [asm_rl,exE,conjE,minor] 1));
clasohm@925
    54
qed "intrelE";
clasohm@925
    55
berghofe@1894
    56
AddSIs [intrelI];
berghofe@1894
    57
AddSEs [intrelE];
clasohm@925
    58
clasohm@972
    59
goal Integ.thy "((x1,y1),(x2,y2)): intrel = (x1+y2 = x2+y1)";
berghofe@1894
    60
by (Fast_tac 1);
clasohm@925
    61
qed "intrel_iff";
clasohm@925
    62
clasohm@972
    63
goal Integ.thy "(x,x): intrel";
paulson@2036
    64
by (stac surjective_pairing 1 THEN rtac (refl RS intrelI) 1);
clasohm@925
    65
qed "intrel_refl";
clasohm@925
    66
clasohm@925
    67
goalw Integ.thy [equiv_def, refl_def, sym_def, trans_def]
clasohm@925
    68
    "equiv {x::(nat*nat).True} intrel";
wenzelm@4089
    69
by (fast_tac (claset() addSIs [intrel_refl] 
clasohm@925
    70
                        addSEs [sym, integ_trans_lemma]) 1);
clasohm@925
    71
qed "equiv_intrel";
clasohm@925
    72
clasohm@925
    73
val equiv_intrel_iff =
clasohm@925
    74
    [TrueI, TrueI] MRS 
clasohm@925
    75
    ([CollectI, CollectI] MRS 
clasohm@925
    76
    (equiv_intrel RS eq_equiv_class_iff));
clasohm@925
    77
clasohm@972
    78
goalw Integ.thy  [Integ_def,intrel_def,quotient_def] "intrel^^{(x,y)}:Integ";
berghofe@1894
    79
by (Fast_tac 1);
clasohm@925
    80
qed "intrel_in_integ";
clasohm@925
    81
clasohm@925
    82
goal Integ.thy "inj_onto Abs_Integ Integ";
clasohm@925
    83
by (rtac inj_onto_inverseI 1);
clasohm@925
    84
by (etac Abs_Integ_inverse 1);
clasohm@925
    85
qed "inj_onto_Abs_Integ";
clasohm@925
    86
clasohm@1266
    87
Addsimps [equiv_intrel_iff, inj_onto_Abs_Integ RS inj_onto_iff,
clasohm@1465
    88
          intrel_iff, intrel_in_integ, Abs_Integ_inverse];
clasohm@925
    89
clasohm@925
    90
goal Integ.thy "inj(Rep_Integ)";
clasohm@925
    91
by (rtac inj_inverseI 1);
clasohm@925
    92
by (rtac Rep_Integ_inverse 1);
clasohm@925
    93
qed "inj_Rep_Integ";
clasohm@925
    94
clasohm@925
    95
clasohm@925
    96
clasohm@925
    97
clasohm@925
    98
(** znat: the injection from nat to Integ **)
clasohm@925
    99
clasohm@925
   100
goal Integ.thy "inj(znat)";
clasohm@925
   101
by (rtac injI 1);
clasohm@925
   102
by (rewtac znat_def);
clasohm@925
   103
by (dtac (inj_onto_Abs_Integ RS inj_ontoD) 1);
clasohm@925
   104
by (REPEAT (rtac intrel_in_integ 1));
clasohm@925
   105
by (dtac eq_equiv_class 1);
clasohm@925
   106
by (rtac equiv_intrel 1);
berghofe@1894
   107
by (Fast_tac 1);
paulson@4162
   108
by Safe_tac;
clasohm@1266
   109
by (Asm_full_simp_tac 1);
clasohm@925
   110
qed "inj_znat";
clasohm@925
   111
clasohm@925
   112
clasohm@925
   113
(**** zminus: unary negation on Integ ****)
clasohm@925
   114
clasohm@925
   115
goalw Integ.thy [congruent_def]
clasohm@972
   116
  "congruent intrel (%p. split (%x y. intrel^^{(y,x)}) p)";
paulson@4162
   117
by Safe_tac;
wenzelm@4089
   118
by (asm_simp_tac (simpset() addsimps add_ac) 1);
clasohm@925
   119
qed "zminus_congruent";
clasohm@925
   120
clasohm@925
   121
clasohm@925
   122
(*Resolve th against the corresponding facts for zminus*)
clasohm@925
   123
val zminus_ize = RSLIST [equiv_intrel, zminus_congruent];
clasohm@925
   124
clasohm@925
   125
goalw Integ.thy [zminus_def]
clasohm@972
   126
      "$~ Abs_Integ(intrel^^{(x,y)}) = Abs_Integ(intrel ^^ {(y,x)})";
clasohm@925
   127
by (res_inst_tac [("f","Abs_Integ")] arg_cong 1);
wenzelm@4089
   128
by (simp_tac (simpset() addsimps 
clasohm@925
   129
   [intrel_in_integ RS Abs_Integ_inverse,zminus_ize UN_equiv_class]) 1);
clasohm@925
   130
qed "zminus";
clasohm@925
   131
clasohm@925
   132
(*by lcp*)
clasohm@925
   133
val [prem] = goal Integ.thy
clasohm@972
   134
    "(!!x y. z = Abs_Integ(intrel^^{(x,y)}) ==> P) ==> P";
clasohm@925
   135
by (res_inst_tac [("x1","z")] 
clasohm@925
   136
    (rewrite_rule [Integ_def] Rep_Integ RS quotientE) 1);
clasohm@925
   137
by (dres_inst_tac [("f","Abs_Integ")] arg_cong 1);
clasohm@925
   138
by (res_inst_tac [("p","x")] PairE 1);
clasohm@925
   139
by (rtac prem 1);
wenzelm@4089
   140
by (asm_full_simp_tac (simpset() addsimps [Rep_Integ_inverse]) 1);
clasohm@925
   141
qed "eq_Abs_Integ";
clasohm@925
   142
clasohm@925
   143
goal Integ.thy "$~ ($~ z) = z";
clasohm@925
   144
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
wenzelm@4089
   145
by (asm_simp_tac (simpset() addsimps [zminus]) 1);
clasohm@925
   146
qed "zminus_zminus";
clasohm@925
   147
clasohm@925
   148
goal Integ.thy "inj(zminus)";
clasohm@925
   149
by (rtac injI 1);
clasohm@925
   150
by (dres_inst_tac [("f","zminus")] arg_cong 1);
wenzelm@4089
   151
by (asm_full_simp_tac (simpset() addsimps [zminus_zminus]) 1);
clasohm@925
   152
qed "inj_zminus";
clasohm@925
   153
clasohm@925
   154
goalw Integ.thy [znat_def] "$~ ($#0) = $#0";
wenzelm@4089
   155
by (simp_tac (simpset() addsimps [zminus]) 1);
clasohm@925
   156
qed "zminus_0";
clasohm@925
   157
clasohm@925
   158
clasohm@925
   159
(**** znegative: the test for negative integers ****)
clasohm@925
   160
clasohm@925
   161
goal Arith.thy "!!m x n::nat. n+m=x ==> m<=x";
clasohm@925
   162
by (dtac (disjI2 RS less_or_eq_imp_le) 1);
wenzelm@4089
   163
by (asm_full_simp_tac (simpset() addsimps add_ac) 1);
clasohm@925
   164
by (dtac add_leD1 1);
clasohm@925
   165
by (assume_tac 1);
clasohm@925
   166
qed "not_znegative_znat_lemma";
clasohm@925
   167
clasohm@925
   168
clasohm@925
   169
goalw Integ.thy [znegative_def, znat_def]
clasohm@925
   170
    "~ znegative($# n)";
clasohm@1266
   171
by (Simp_tac 1);
paulson@4162
   172
by Safe_tac;
clasohm@925
   173
by (rtac ccontr 1);
clasohm@925
   174
by (etac notE 1);
clasohm@1266
   175
by (Asm_full_simp_tac 1);
clasohm@925
   176
by (dtac not_znegative_znat_lemma 1);
wenzelm@4089
   177
by (fast_tac (claset() addDs [leD]) 1);
clasohm@925
   178
qed "not_znegative_znat";
clasohm@925
   179
clasohm@925
   180
goalw Integ.thy [znegative_def, znat_def] "znegative($~ $# Suc(n))";
wenzelm@4089
   181
by (simp_tac (simpset() addsimps [zminus]) 1);
clasohm@925
   182
by (REPEAT (ares_tac [exI, conjI] 1));
clasohm@925
   183
by (rtac (intrelI RS ImageI) 2);
clasohm@925
   184
by (rtac singletonI 3);
clasohm@1266
   185
by (Simp_tac 2);
clasohm@925
   186
by (rtac less_add_Suc1 1);
clasohm@925
   187
qed "znegative_zminus_znat";
clasohm@925
   188
clasohm@925
   189
clasohm@925
   190
(**** zmagnitude: magnitide of an integer, as a natural number ****)
clasohm@925
   191
clasohm@925
   192
goal Arith.thy "!!n::nat. n - Suc(n+m)=0";
clasohm@925
   193
by (nat_ind_tac "n" 1);
clasohm@1266
   194
by (ALLGOALS Asm_simp_tac);
clasohm@925
   195
qed "diff_Suc_add_0";
clasohm@925
   196
clasohm@925
   197
goal Arith.thy "Suc((n::nat)+m)-n=Suc(m)";
clasohm@925
   198
by (nat_ind_tac "n" 1);
clasohm@1266
   199
by (ALLGOALS Asm_simp_tac);
clasohm@925
   200
qed "diff_Suc_add_inverse";
clasohm@925
   201
clasohm@925
   202
goalw Integ.thy [congruent_def]
clasohm@972
   203
    "congruent intrel (split (%x y. intrel^^{((y-x) + (x-(y::nat)),0)}))";
paulson@4162
   204
by Safe_tac;
clasohm@1266
   205
by (Asm_simp_tac 1);
clasohm@925
   206
by (etac rev_mp 1);
clasohm@925
   207
by (res_inst_tac [("m","x1"),("n","y1")] diff_induct 1);
wenzelm@4089
   208
by (asm_simp_tac (simpset() addsimps [inj_Suc RS inj_eq]) 3);
wenzelm@4089
   209
by (asm_simp_tac (simpset() addsimps [diff_add_inverse,diff_add_0]) 2);
clasohm@1266
   210
by (Asm_simp_tac 1);
clasohm@925
   211
by (rtac impI 1);
clasohm@925
   212
by (etac subst 1);
clasohm@925
   213
by (res_inst_tac [("m1","x")] (add_commute RS ssubst) 1);
wenzelm@4089
   214
by (asm_simp_tac (simpset() addsimps [diff_add_inverse,diff_add_0]) 1);
clasohm@925
   215
by (rtac impI 1);
wenzelm@4089
   216
by (asm_simp_tac (simpset() addsimps
clasohm@1465
   217
                  [diff_add_inverse, diff_add_0, diff_Suc_add_0,
clasohm@1465
   218
                   diff_Suc_add_inverse]) 1);
clasohm@925
   219
qed "zmagnitude_congruent";
clasohm@925
   220
clasohm@925
   221
(*Resolve th against the corresponding facts for zmagnitude*)
clasohm@925
   222
val zmagnitude_ize = RSLIST [equiv_intrel, zmagnitude_congruent];
clasohm@925
   223
clasohm@925
   224
clasohm@925
   225
goalw Integ.thy [zmagnitude_def]
clasohm@972
   226
    "zmagnitude (Abs_Integ(intrel^^{(x,y)})) = \
clasohm@972
   227
\    Abs_Integ(intrel^^{((y - x) + (x - y),0)})";
clasohm@925
   228
by (res_inst_tac [("f","Abs_Integ")] arg_cong 1);
wenzelm@4089
   229
by (asm_simp_tac (simpset() addsimps [zmagnitude_ize UN_equiv_class]) 1);
clasohm@925
   230
qed "zmagnitude";
clasohm@925
   231
clasohm@925
   232
goalw Integ.thy [znat_def] "zmagnitude($# n) = $#n";
wenzelm@4089
   233
by (asm_simp_tac (simpset() addsimps [zmagnitude]) 1);
clasohm@925
   234
qed "zmagnitude_znat";
clasohm@925
   235
clasohm@925
   236
goalw Integ.thy [znat_def] "zmagnitude($~ $# n) = $#n";
wenzelm@4089
   237
by (asm_simp_tac (simpset() addsimps [zmagnitude, zminus]) 1);
clasohm@925
   238
qed "zmagnitude_zminus_znat";
clasohm@925
   239
clasohm@925
   240
clasohm@925
   241
(**** zadd: addition on Integ ****)
clasohm@925
   242
clasohm@925
   243
(** Congruence property for addition **)
clasohm@925
   244
clasohm@925
   245
goalw Integ.thy [congruent2_def]
clasohm@925
   246
    "congruent2 intrel (%p1 p2.                  \
clasohm@972
   247
\         split (%x1 y1. split (%x2 y2. intrel^^{(x1+x2, y1+y2)}) p2) p1)";
clasohm@925
   248
(*Proof via congruent2_commuteI seems longer*)
paulson@4162
   249
by Safe_tac;
wenzelm@4089
   250
by (asm_simp_tac (simpset() addsimps [add_assoc]) 1);
clasohm@925
   251
(*The rest should be trivial, but rearranging terms is hard*)
clasohm@925
   252
by (res_inst_tac [("x1","x1a")] (add_left_commute RS ssubst) 1);
wenzelm@4089
   253
by (asm_simp_tac (simpset() addsimps [add_assoc RS sym]) 1);
wenzelm@4089
   254
by (asm_simp_tac (simpset() addsimps add_ac) 1);
clasohm@925
   255
qed "zadd_congruent2";
clasohm@925
   256
clasohm@925
   257
(*Resolve th against the corresponding facts for zadd*)
clasohm@925
   258
val zadd_ize = RSLIST [equiv_intrel, zadd_congruent2];
clasohm@925
   259
clasohm@925
   260
goalw Integ.thy [zadd_def]
clasohm@972
   261
  "Abs_Integ(intrel^^{(x1,y1)}) + Abs_Integ(intrel^^{(x2,y2)}) = \
clasohm@972
   262
\  Abs_Integ(intrel^^{(x1+x2, y1+y2)})";
clasohm@925
   263
by (asm_simp_tac
wenzelm@4089
   264
    (simpset() addsimps [zadd_ize UN_equiv_class2]) 1);
clasohm@925
   265
qed "zadd";
clasohm@925
   266
clasohm@925
   267
goalw Integ.thy [znat_def] "$#0 + z = z";
clasohm@925
   268
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
wenzelm@4089
   269
by (asm_simp_tac (simpset() addsimps [zadd]) 1);
clasohm@925
   270
qed "zadd_0";
clasohm@925
   271
clasohm@925
   272
goal Integ.thy "$~ (z + w) = $~ z + $~ w";
clasohm@925
   273
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
clasohm@925
   274
by (res_inst_tac [("z","w")] eq_Abs_Integ 1);
wenzelm@4089
   275
by (asm_simp_tac (simpset() addsimps [zminus,zadd]) 1);
clasohm@925
   276
qed "zminus_zadd_distrib";
clasohm@925
   277
clasohm@925
   278
goal Integ.thy "(z::int) + w = w + z";
clasohm@925
   279
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
clasohm@925
   280
by (res_inst_tac [("z","w")] eq_Abs_Integ 1);
wenzelm@4089
   281
by (asm_simp_tac (simpset() addsimps (add_ac @ [zadd])) 1);
clasohm@925
   282
qed "zadd_commute";
clasohm@925
   283
clasohm@925
   284
goal Integ.thy "((z1::int) + z2) + z3 = z1 + (z2 + z3)";
clasohm@925
   285
by (res_inst_tac [("z","z1")] eq_Abs_Integ 1);
clasohm@925
   286
by (res_inst_tac [("z","z2")] eq_Abs_Integ 1);
clasohm@925
   287
by (res_inst_tac [("z","z3")] eq_Abs_Integ 1);
wenzelm@4089
   288
by (asm_simp_tac (simpset() addsimps [zadd, add_assoc]) 1);
clasohm@925
   289
qed "zadd_assoc";
clasohm@925
   290
clasohm@925
   291
(*For AC rewriting*)
clasohm@925
   292
goal Integ.thy "(x::int)+(y+z)=y+(x+z)";
clasohm@925
   293
by (rtac (zadd_commute RS trans) 1);
clasohm@925
   294
by (rtac (zadd_assoc RS trans) 1);
clasohm@925
   295
by (rtac (zadd_commute RS arg_cong) 1);
clasohm@925
   296
qed "zadd_left_commute";
clasohm@925
   297
clasohm@925
   298
(*Integer addition is an AC operator*)
clasohm@925
   299
val zadd_ac = [zadd_assoc,zadd_commute,zadd_left_commute];
clasohm@925
   300
clasohm@925
   301
goalw Integ.thy [znat_def] "$# (m + n) = ($#m) + ($#n)";
wenzelm@4089
   302
by (asm_simp_tac (simpset() addsimps [zadd]) 1);
clasohm@925
   303
qed "znat_add";
clasohm@925
   304
clasohm@925
   305
goalw Integ.thy [znat_def] "z + ($~ z) = $#0";
clasohm@925
   306
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
wenzelm@4089
   307
by (asm_simp_tac (simpset() addsimps [zminus, zadd, add_commute]) 1);
clasohm@925
   308
qed "zadd_zminus_inverse";
clasohm@925
   309
clasohm@925
   310
goal Integ.thy "($~ z) + z = $#0";
clasohm@925
   311
by (rtac (zadd_commute RS trans) 1);
clasohm@925
   312
by (rtac zadd_zminus_inverse 1);
clasohm@925
   313
qed "zadd_zminus_inverse2";
clasohm@925
   314
clasohm@925
   315
goal Integ.thy "z + $#0 = z";
clasohm@925
   316
by (rtac (zadd_commute RS trans) 1);
clasohm@925
   317
by (rtac zadd_0 1);
clasohm@925
   318
qed "zadd_0_right";
clasohm@925
   319
clasohm@925
   320
paulson@2224
   321
(** Lemmas **)
paulson@2224
   322
paulson@2224
   323
qed_goal "zadd_assoc_cong" Integ.thy
paulson@2224
   324
    "!!z. (z::int) + v = z' + v' ==> z + (v + w) = z' + (v' + w)"
wenzelm@4089
   325
 (fn _ => [(asm_simp_tac (simpset() addsimps [zadd_assoc RS sym]) 1)]);
paulson@2224
   326
paulson@2224
   327
qed_goal "zadd_assoc_swap" Integ.thy "(z::int) + (v + w) = v + (z + w)"
paulson@2224
   328
 (fn _ => [(REPEAT (ares_tac [zadd_commute RS zadd_assoc_cong] 1))]);
paulson@2224
   329
paulson@2224
   330
clasohm@925
   331
(*Need properties of subtraction?  Or use $- just as an abbreviation!*)
clasohm@925
   332
clasohm@925
   333
(**** zmult: multiplication on Integ ****)
clasohm@925
   334
clasohm@925
   335
(** Congruence property for multiplication **)
clasohm@925
   336
clasohm@925
   337
goal Integ.thy "((k::nat) + l) + (m + n) = (k + m) + (n + l)";
wenzelm@4089
   338
by (simp_tac (simpset() addsimps add_ac) 1);
clasohm@925
   339
qed "zmult_congruent_lemma";
clasohm@925
   340
clasohm@925
   341
goal Integ.thy 
clasohm@1465
   342
    "congruent2 intrel (%p1 p2.                 \
clasohm@1465
   343
\               split (%x1 y1. split (%x2 y2.   \
clasohm@972
   344
\                   intrel^^{(x1*x2 + y1*y2, x1*y2 + y1*x2)}) p2) p1)";
clasohm@925
   345
by (rtac (equiv_intrel RS congruent2_commuteI) 1);
paulson@4162
   346
by Safe_tac;
clasohm@925
   347
by (rewtac split_def);
wenzelm@4089
   348
by (simp_tac (simpset() addsimps add_ac@mult_ac) 1);
wenzelm@4089
   349
by (asm_simp_tac (simpset() delsimps [equiv_intrel_iff]
clasohm@1266
   350
                           addsimps add_ac@mult_ac) 1);
clasohm@925
   351
by (rtac (intrelI RS(equiv_intrel RS equiv_class_eq)) 1);
clasohm@925
   352
by (rtac (zmult_congruent_lemma RS trans) 1);
clasohm@925
   353
by (rtac (zmult_congruent_lemma RS trans RS sym) 1);
clasohm@925
   354
by (rtac (zmult_congruent_lemma RS trans RS sym) 1);
clasohm@925
   355
by (rtac (zmult_congruent_lemma RS trans RS sym) 1);
wenzelm@4089
   356
by (asm_simp_tac (simpset() addsimps [add_mult_distrib RS sym]) 1);
wenzelm@4089
   357
by (asm_simp_tac (simpset() addsimps add_ac@mult_ac) 1);
clasohm@925
   358
qed "zmult_congruent2";
clasohm@925
   359
clasohm@925
   360
(*Resolve th against the corresponding facts for zmult*)
clasohm@925
   361
val zmult_ize = RSLIST [equiv_intrel, zmult_congruent2];
clasohm@925
   362
clasohm@925
   363
goalw Integ.thy [zmult_def]
clasohm@1465
   364
   "Abs_Integ((intrel^^{(x1,y1)})) * Abs_Integ((intrel^^{(x2,y2)})) =   \
clasohm@972
   365
\   Abs_Integ(intrel ^^ {(x1*x2 + y1*y2, x1*y2 + y1*x2)})";
wenzelm@4089
   366
by (simp_tac (simpset() addsimps [zmult_ize UN_equiv_class2]) 1);
clasohm@925
   367
qed "zmult";
clasohm@925
   368
clasohm@925
   369
goalw Integ.thy [znat_def] "$#0 * z = $#0";
clasohm@925
   370
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
wenzelm@4089
   371
by (asm_simp_tac (simpset() addsimps [zmult]) 1);
clasohm@925
   372
qed "zmult_0";
clasohm@925
   373
clasohm@925
   374
goalw Integ.thy [znat_def] "$#Suc(0) * z = z";
clasohm@925
   375
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
wenzelm@4089
   376
by (asm_simp_tac (simpset() addsimps [zmult]) 1);
clasohm@925
   377
qed "zmult_1";
clasohm@925
   378
clasohm@925
   379
goal Integ.thy "($~ z) * w = $~ (z * w)";
clasohm@925
   380
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
clasohm@925
   381
by (res_inst_tac [("z","w")] eq_Abs_Integ 1);
wenzelm@4089
   382
by (asm_simp_tac (simpset() addsimps ([zminus, zmult] @ add_ac)) 1);
clasohm@925
   383
qed "zmult_zminus";
clasohm@925
   384
clasohm@925
   385
clasohm@925
   386
goal Integ.thy "($~ z) * ($~ w) = (z * w)";
clasohm@925
   387
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
clasohm@925
   388
by (res_inst_tac [("z","w")] eq_Abs_Integ 1);
wenzelm@4089
   389
by (asm_simp_tac (simpset() addsimps ([zminus, zmult] @ add_ac)) 1);
clasohm@925
   390
qed "zmult_zminus_zminus";
clasohm@925
   391
clasohm@925
   392
goal Integ.thy "(z::int) * w = w * z";
clasohm@925
   393
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
clasohm@925
   394
by (res_inst_tac [("z","w")] eq_Abs_Integ 1);
wenzelm@4089
   395
by (asm_simp_tac (simpset() addsimps ([zmult] @ add_ac @ mult_ac)) 1);
clasohm@925
   396
qed "zmult_commute";
clasohm@925
   397
clasohm@925
   398
goal Integ.thy "z * $# 0 = $#0";
clasohm@925
   399
by (rtac ([zmult_commute, zmult_0] MRS trans) 1);
clasohm@925
   400
qed "zmult_0_right";
clasohm@925
   401
clasohm@925
   402
goal Integ.thy "z * $#Suc(0) = z";
clasohm@925
   403
by (rtac ([zmult_commute, zmult_1] MRS trans) 1);
clasohm@925
   404
qed "zmult_1_right";
clasohm@925
   405
clasohm@925
   406
goal Integ.thy "((z1::int) * z2) * z3 = z1 * (z2 * z3)";
clasohm@925
   407
by (res_inst_tac [("z","z1")] eq_Abs_Integ 1);
clasohm@925
   408
by (res_inst_tac [("z","z2")] eq_Abs_Integ 1);
clasohm@925
   409
by (res_inst_tac [("z","z3")] eq_Abs_Integ 1);
wenzelm@4089
   410
by (asm_simp_tac (simpset() addsimps ([add_mult_distrib2,zmult] @ 
paulson@2036
   411
                                     add_ac @ mult_ac)) 1);
clasohm@925
   412
qed "zmult_assoc";
clasohm@925
   413
clasohm@925
   414
(*For AC rewriting*)
clasohm@925
   415
qed_goal "zmult_left_commute" Integ.thy
clasohm@925
   416
    "(z1::int)*(z2*z3) = z2*(z1*z3)"
clasohm@925
   417
 (fn _ => [rtac (zmult_commute RS trans) 1, rtac (zmult_assoc RS trans) 1,
clasohm@925
   418
           rtac (zmult_commute RS arg_cong) 1]);
clasohm@925
   419
clasohm@925
   420
(*Integer multiplication is an AC operator*)
clasohm@925
   421
val zmult_ac = [zmult_assoc, zmult_commute, zmult_left_commute];
clasohm@925
   422
clasohm@925
   423
goal Integ.thy "((z1::int) + z2) * w = (z1 * w) + (z2 * w)";
clasohm@925
   424
by (res_inst_tac [("z","z1")] eq_Abs_Integ 1);
clasohm@925
   425
by (res_inst_tac [("z","z2")] eq_Abs_Integ 1);
clasohm@925
   426
by (res_inst_tac [("z","w")] eq_Abs_Integ 1);
clasohm@925
   427
by (asm_simp_tac 
wenzelm@4089
   428
    (simpset() addsimps ([add_mult_distrib2, zadd, zmult] @ 
paulson@2036
   429
                        add_ac @ mult_ac)) 1);
clasohm@925
   430
qed "zadd_zmult_distrib";
clasohm@925
   431
clasohm@925
   432
val zmult_commute'= read_instantiate [("z","w")] zmult_commute;
clasohm@925
   433
clasohm@925
   434
goal Integ.thy "w * ($~ z) = $~ (w * z)";
wenzelm@4089
   435
by (simp_tac (simpset() addsimps [zmult_commute', zmult_zminus]) 1);
clasohm@925
   436
qed "zmult_zminus_right";
clasohm@925
   437
clasohm@925
   438
goal Integ.thy "(w::int) * (z1 + z2) = (w * z1) + (w * z2)";
wenzelm@4089
   439
by (simp_tac (simpset() addsimps [zmult_commute',zadd_zmult_distrib]) 1);
clasohm@925
   440
qed "zadd_zmult_distrib2";
clasohm@925
   441
clasohm@925
   442
val zadd_simps = 
clasohm@925
   443
    [zadd_0, zadd_0_right, zadd_zminus_inverse, zadd_zminus_inverse2];
clasohm@925
   444
clasohm@925
   445
val zminus_simps = [zminus_zminus, zminus_0, zminus_zadd_distrib];
clasohm@925
   446
clasohm@925
   447
val zmult_simps = [zmult_0, zmult_1, zmult_0_right, zmult_1_right, 
clasohm@1465
   448
                   zmult_zminus, zmult_zminus_right];
clasohm@925
   449
clasohm@1266
   450
Addsimps (zadd_simps @ zminus_simps @ zmult_simps @ 
clasohm@1266
   451
          [zmagnitude_znat, zmagnitude_zminus_znat]);
clasohm@925
   452
clasohm@925
   453
clasohm@925
   454
(**** Additional Theorems (by Mattolini; proofs mainly by lcp) ****)
clasohm@925
   455
clasohm@925
   456
(* Some Theorems about zsuc and zpred *)
clasohm@925
   457
goalw Integ.thy [zsuc_def] "$#(Suc(n)) = zsuc($# n)";
wenzelm@4089
   458
by (simp_tac (simpset() addsimps [znat_add RS sym]) 1);
clasohm@925
   459
qed "znat_Suc";
clasohm@925
   460
clasohm@925
   461
goalw Integ.thy [zpred_def,zsuc_def,zdiff_def] "$~ zsuc(z) = zpred($~ z)";
clasohm@1266
   462
by (Simp_tac 1);
clasohm@925
   463
qed "zminus_zsuc";
clasohm@925
   464
clasohm@925
   465
goalw Integ.thy [zpred_def,zsuc_def,zdiff_def] "$~ zpred(z) = zsuc($~ z)";
clasohm@1266
   466
by (Simp_tac 1);
clasohm@925
   467
qed "zminus_zpred";
clasohm@925
   468
clasohm@925
   469
goalw Integ.thy [zsuc_def,zpred_def,zdiff_def]
clasohm@925
   470
   "zpred(zsuc(z)) = z";
wenzelm@4089
   471
by (simp_tac (simpset() addsimps [zadd_assoc]) 1);
clasohm@925
   472
qed "zpred_zsuc";
clasohm@925
   473
clasohm@925
   474
goalw Integ.thy [zsuc_def,zpred_def,zdiff_def]
clasohm@925
   475
   "zsuc(zpred(z)) = z";
wenzelm@4089
   476
by (simp_tac (simpset() addsimps [zadd_assoc]) 1);
clasohm@925
   477
qed "zsuc_zpred";
clasohm@925
   478
clasohm@925
   479
goal Integ.thy "(zpred(z)=w) = (z=zsuc(w))";
paulson@4162
   480
by Safe_tac;
clasohm@925
   481
by (rtac (zsuc_zpred RS sym) 1);
clasohm@925
   482
by (rtac zpred_zsuc 1);
clasohm@925
   483
qed "zpred_to_zsuc";
clasohm@925
   484
clasohm@925
   485
goal Integ.thy "(zsuc(z)=w)=(z=zpred(w))";
paulson@4162
   486
by Safe_tac;
clasohm@925
   487
by (rtac (zpred_zsuc RS sym) 1);
clasohm@925
   488
by (rtac zsuc_zpred 1);
clasohm@925
   489
qed "zsuc_to_zpred";
clasohm@925
   490
clasohm@925
   491
goal Integ.thy "($~ z = w) = (z = $~ w)";
paulson@4162
   492
by Safe_tac;
clasohm@925
   493
by (rtac (zminus_zminus RS sym) 1);
clasohm@925
   494
by (rtac zminus_zminus 1);
clasohm@925
   495
qed "zminus_exchange";
clasohm@925
   496
clasohm@925
   497
goal Integ.thy"(zsuc(z)=zsuc(w)) = (z=w)";
paulson@4162
   498
by Safe_tac;
clasohm@925
   499
by (dres_inst_tac [("f","zpred")] arg_cong 1);
wenzelm@4089
   500
by (asm_full_simp_tac (simpset() addsimps [zpred_zsuc]) 1);
clasohm@925
   501
qed "bijective_zsuc";
clasohm@925
   502
clasohm@925
   503
goal Integ.thy"(zpred(z)=zpred(w)) = (z=w)";
paulson@4162
   504
by Safe_tac;
clasohm@925
   505
by (dres_inst_tac [("f","zsuc")] arg_cong 1);
wenzelm@4089
   506
by (asm_full_simp_tac (simpset() addsimps [zsuc_zpred]) 1);
clasohm@925
   507
qed "bijective_zpred";
clasohm@925
   508
clasohm@925
   509
(* Additional Theorems about zadd *)
clasohm@925
   510
clasohm@925
   511
goalw Integ.thy [zsuc_def] "zsuc(z) + w = zsuc(z+w)";
wenzelm@4089
   512
by (simp_tac (simpset() addsimps zadd_ac) 1);
clasohm@925
   513
qed "zadd_zsuc";
clasohm@925
   514
clasohm@925
   515
goalw Integ.thy [zsuc_def] "w + zsuc(z) = zsuc(w+z)";
wenzelm@4089
   516
by (simp_tac (simpset() addsimps zadd_ac) 1);
clasohm@925
   517
qed "zadd_zsuc_right";
clasohm@925
   518
clasohm@925
   519
goalw Integ.thy [zpred_def,zdiff_def] "zpred(z) + w = zpred(z+w)";
wenzelm@4089
   520
by (simp_tac (simpset() addsimps zadd_ac) 1);
clasohm@925
   521
qed "zadd_zpred";
clasohm@925
   522
clasohm@925
   523
goalw Integ.thy [zpred_def,zdiff_def] "w + zpred(z) = zpred(w+z)";
wenzelm@4089
   524
by (simp_tac (simpset() addsimps zadd_ac) 1);
clasohm@925
   525
qed "zadd_zpred_right";
clasohm@925
   526
clasohm@925
   527
clasohm@925
   528
(* Additional Theorems about zmult *)
clasohm@925
   529
clasohm@925
   530
goalw Integ.thy [zsuc_def] "zsuc(w) * z = z + w * z";
wenzelm@4089
   531
by (simp_tac (simpset() addsimps [zadd_zmult_distrib, zadd_commute]) 1);
clasohm@925
   532
qed "zmult_zsuc";
clasohm@925
   533
clasohm@925
   534
goalw Integ.thy [zsuc_def] "z * zsuc(w) = z + w * z";
clasohm@925
   535
by (simp_tac 
wenzelm@4089
   536
    (simpset() addsimps [zadd_zmult_distrib2, zadd_commute, zmult_commute]) 1);
clasohm@925
   537
qed "zmult_zsuc_right";
clasohm@925
   538
clasohm@925
   539
goalw Integ.thy [zpred_def, zdiff_def] "zpred(w) * z = w * z - z";
wenzelm@4089
   540
by (simp_tac (simpset() addsimps [zadd_zmult_distrib]) 1);
clasohm@925
   541
qed "zmult_zpred";
clasohm@925
   542
clasohm@925
   543
goalw Integ.thy [zpred_def, zdiff_def] "z * zpred(w) = w * z - z";
wenzelm@4089
   544
by (simp_tac (simpset() addsimps [zadd_zmult_distrib2, zmult_commute]) 1);
clasohm@925
   545
qed "zmult_zpred_right";
clasohm@925
   546
clasohm@925
   547
(* Further Theorems about zsuc and zpred *)
clasohm@925
   548
goal Integ.thy "$#Suc(m) ~= $#0";
wenzelm@4089
   549
by (simp_tac (simpset() addsimps [inj_znat RS inj_eq]) 1);
clasohm@925
   550
qed "znat_Suc_not_znat_Zero";
clasohm@925
   551
clasohm@925
   552
bind_thm ("znat_Zero_not_znat_Suc", (znat_Suc_not_znat_Zero RS not_sym));
clasohm@925
   553
clasohm@925
   554
clasohm@925
   555
goalw Integ.thy [zsuc_def,znat_def] "w ~= zsuc(w)";
clasohm@925
   556
by (res_inst_tac [("z","w")] eq_Abs_Integ 1);
wenzelm@4089
   557
by (asm_full_simp_tac (simpset() addsimps [zadd]) 1);
clasohm@925
   558
qed "n_not_zsuc_n";
clasohm@925
   559
clasohm@925
   560
val zsuc_n_not_n = n_not_zsuc_n RS not_sym;
clasohm@925
   561
clasohm@925
   562
goal Integ.thy "w ~= zpred(w)";
paulson@4162
   563
by Safe_tac;
clasohm@925
   564
by (dres_inst_tac [("x","w"),("f","zsuc")] arg_cong 1);
wenzelm@4089
   565
by (asm_full_simp_tac (simpset() addsimps [zsuc_zpred,zsuc_n_not_n]) 1);
clasohm@925
   566
qed "n_not_zpred_n";
clasohm@925
   567
clasohm@925
   568
val zpred_n_not_n = n_not_zpred_n RS not_sym;
clasohm@925
   569
clasohm@925
   570
clasohm@925
   571
(* Theorems about less and less_equal *)
clasohm@925
   572
clasohm@925
   573
goalw Integ.thy [zless_def, znegative_def, zdiff_def, znat_def] 
clasohm@925
   574
    "!!w. w<z ==> ? n. z = w + $#(Suc(n))";
clasohm@925
   575
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
clasohm@925
   576
by (res_inst_tac [("z","w")] eq_Abs_Integ 1);
paulson@4162
   577
by Safe_tac;
wenzelm@4089
   578
by (asm_full_simp_tac (simpset() addsimps [zadd, zminus]) 1);
wenzelm@4089
   579
by (safe_tac (claset() addSDs [less_eq_Suc_add]));
nipkow@2596
   580
by (rename_tac "k" 1);
clasohm@925
   581
by (res_inst_tac [("x","k")] exI 1);
clasohm@925
   582
(*To cancel x2, rename it to be first!*)
pusch@2683
   583
by (rename_tac "a b c" 1);
pusch@2683
   584
by (Asm_full_simp_tac 1);
wenzelm@4089
   585
by (asm_full_simp_tac (simpset() delsimps [add_Suc_right]
pusch@2683
   586
                                addsimps ([add_Suc_right RS sym] @ add_ac)) 1);
clasohm@925
   587
qed "zless_eq_zadd_Suc";
clasohm@925
   588
clasohm@925
   589
goalw Integ.thy [zless_def, znegative_def, zdiff_def, znat_def] 
clasohm@925
   590
    "z < z + $#(Suc(n))";
clasohm@925
   591
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
paulson@4162
   592
by Safe_tac;
wenzelm@4089
   593
by (simp_tac (simpset() addsimps [zadd, zminus]) 1);
clasohm@925
   594
by (REPEAT_SOME (ares_tac [refl, exI, singletonI, ImageI, conjI, intrelI]));
clasohm@925
   595
by (rtac le_less_trans 1);
clasohm@925
   596
by (rtac lessI 2);
wenzelm@4089
   597
by (asm_simp_tac (simpset() addsimps ([le_add1,add_left_cancel_le]@add_ac)) 1);
clasohm@925
   598
qed "zless_zadd_Suc";
clasohm@925
   599
clasohm@925
   600
goal Integ.thy "!!z1 z2 z3. [| z1<z2; z2<z3 |] ==> z1 < (z3::int)";
wenzelm@4089
   601
by (safe_tac (claset() addSDs [zless_eq_zadd_Suc]));
clasohm@925
   602
by (simp_tac 
wenzelm@4089
   603
    (simpset() addsimps [zadd_assoc, zless_zadd_Suc, znat_add RS sym]) 1);
clasohm@925
   604
qed "zless_trans";
clasohm@925
   605
clasohm@925
   606
goalw Integ.thy [zsuc_def] "z<zsuc(z)";
clasohm@925
   607
by (rtac zless_zadd_Suc 1);
clasohm@925
   608
qed "zlessI";
clasohm@925
   609
clasohm@925
   610
val zless_zsucI = zlessI RSN (2,zless_trans);
clasohm@925
   611
clasohm@925
   612
goal Integ.thy "!!z w::int. z<w ==> ~w<z";
wenzelm@4089
   613
by (safe_tac (claset() addSDs [zless_eq_zadd_Suc]));
clasohm@925
   614
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
paulson@4162
   615
by Safe_tac;
wenzelm@4089
   616
by (asm_full_simp_tac (simpset() addsimps ([znat_def, zadd])) 1);
clasohm@925
   617
by (asm_full_simp_tac
wenzelm@4089
   618
 (simpset() delsimps [add_Suc_right] addsimps [add_left_cancel, add_assoc, add_Suc_right RS sym]) 1);
clasohm@925
   619
by (resolve_tac [less_not_refl2 RS notE] 1);
clasohm@925
   620
by (etac sym 2);
clasohm@925
   621
by (REPEAT (resolve_tac [lessI, trans_less_add2, less_SucI] 1));
clasohm@925
   622
qed "zless_not_sym";
clasohm@925
   623
clasohm@925
   624
(* [| n<m; m<n |] ==> R *)
clasohm@925
   625
bind_thm ("zless_asym", (zless_not_sym RS notE));
clasohm@925
   626
clasohm@925
   627
goal Integ.thy "!!z::int. ~ z<z";
clasohm@925
   628
by (resolve_tac [zless_asym RS notI] 1);
clasohm@925
   629
by (REPEAT (assume_tac 1));
clasohm@925
   630
qed "zless_not_refl";
clasohm@925
   631
clasohm@925
   632
(* z<z ==> R *)
paulson@1619
   633
bind_thm ("zless_irrefl", (zless_not_refl RS notE));
clasohm@925
   634
clasohm@925
   635
goal Integ.thy "!!w. z<w ==> w ~= (z::int)";
wenzelm@4089
   636
by (fast_tac (claset() addEs [zless_irrefl]) 1);
clasohm@925
   637
qed "zless_not_refl2";
clasohm@925
   638
clasohm@925
   639
clasohm@925
   640
(*"Less than" is a linear ordering*)
clasohm@925
   641
goalw Integ.thy [zless_def, znegative_def, zdiff_def] 
clasohm@925
   642
    "z<w | z=w | w<(z::int)";
clasohm@925
   643
by (res_inst_tac [("z","z")] eq_Abs_Integ 1);
clasohm@925
   644
by (res_inst_tac [("z","w")] eq_Abs_Integ 1);
paulson@4162
   645
by Safe_tac;
clasohm@925
   646
by (asm_full_simp_tac
wenzelm@4089
   647
    (simpset() addsimps [zadd, zminus, Image_iff, Bex_def]) 1);
clasohm@925
   648
by (res_inst_tac [("m1", "x+ya"), ("n1", "xa+y")] (less_linear RS disjE) 1);
wenzelm@4089
   649
by (REPEAT (fast_tac (claset() addss (simpset() addsimps add_ac)) 1));
clasohm@925
   650
qed "zless_linear";
clasohm@925
   651
clasohm@925
   652
clasohm@925
   653
(*** Properties of <= ***)
clasohm@925
   654
clasohm@925
   655
goalw Integ.thy  [zless_def, znegative_def, zdiff_def, znat_def]
clasohm@925
   656
    "($#m < $#n) = (m<n)";
clasohm@925
   657
by (simp_tac
wenzelm@4089
   658
    (simpset() addsimps [zadd, zminus, Image_iff, Bex_def]) 1);
wenzelm@4089
   659
by (fast_tac (claset() addIs [add_commute] addSEs [less_add_eq_less]) 1);
clasohm@925
   660
qed "zless_eq_less";
clasohm@925
   661
clasohm@925
   662
goalw Integ.thy [zle_def, le_def] "($#m <= $#n) = (m<=n)";
wenzelm@4089
   663
by (simp_tac (simpset() addsimps [zless_eq_less]) 1);
clasohm@925
   664
qed "zle_eq_le";
clasohm@925
   665
clasohm@925
   666
goalw Integ.thy [zle_def] "!!w. ~(w<z) ==> z<=(w::int)";
clasohm@925
   667
by (assume_tac 1);
clasohm@925
   668
qed "zleI";
clasohm@925
   669
clasohm@925
   670
goalw Integ.thy [zle_def] "!!w. z<=w ==> ~(w<(z::int))";
clasohm@925
   671
by (assume_tac 1);
clasohm@925
   672
qed "zleD";
clasohm@925
   673
clasohm@925
   674
val zleE = make_elim zleD;
clasohm@925
   675
clasohm@925
   676
goalw Integ.thy [zle_def] "!!z. ~ z <= w ==> w<(z::int)";
berghofe@1894
   677
by (Fast_tac 1);
clasohm@925
   678
qed "not_zleE";
clasohm@925
   679
clasohm@925
   680
goalw Integ.thy [zle_def] "!!z. z < w ==> z <= (w::int)";
wenzelm@4089
   681
by (fast_tac (claset() addEs [zless_asym]) 1);
clasohm@925
   682
qed "zless_imp_zle";
clasohm@925
   683
clasohm@925
   684
goalw Integ.thy [zle_def] "!!z. z <= w ==> z < w | z=(w::int)";
clasohm@925
   685
by (cut_facts_tac [zless_linear] 1);
wenzelm@4089
   686
by (fast_tac (claset() addEs [zless_irrefl,zless_asym]) 1);
clasohm@925
   687
qed "zle_imp_zless_or_eq";
clasohm@925
   688
clasohm@925
   689
goalw Integ.thy [zle_def] "!!z. z<w | z=w ==> z <=(w::int)";
clasohm@925
   690
by (cut_facts_tac [zless_linear] 1);
wenzelm@4089
   691
by (fast_tac (claset() addEs [zless_irrefl,zless_asym]) 1);
clasohm@925
   692
qed "zless_or_eq_imp_zle";
clasohm@925
   693
clasohm@925
   694
goal Integ.thy "(x <= (y::int)) = (x < y | x=y)";
clasohm@925
   695
by (REPEAT(ares_tac [iffI, zless_or_eq_imp_zle, zle_imp_zless_or_eq] 1));
clasohm@925
   696
qed "zle_eq_zless_or_eq";
clasohm@925
   697
clasohm@925
   698
goal Integ.thy "w <= (w::int)";
wenzelm@4089
   699
by (simp_tac (simpset() addsimps [zle_eq_zless_or_eq]) 1);
clasohm@925
   700
qed "zle_refl";
clasohm@925
   701
clasohm@925
   702
val prems = goal Integ.thy "!!i. [| i <= j; j < k |] ==> i < (k::int)";
clasohm@925
   703
by (dtac zle_imp_zless_or_eq 1);
wenzelm@4089
   704
by (fast_tac (claset() addIs [zless_trans]) 1);
clasohm@925
   705
qed "zle_zless_trans";
clasohm@925
   706
clasohm@925
   707
goal Integ.thy "!!i. [| i <= j; j <= k |] ==> i <= (k::int)";
clasohm@925
   708
by (EVERY1 [dtac zle_imp_zless_or_eq, dtac zle_imp_zless_or_eq,
wenzelm@4089
   709
            rtac zless_or_eq_imp_zle, fast_tac (claset() addIs [zless_trans])]);
clasohm@925
   710
qed "zle_trans";
clasohm@925
   711
clasohm@925
   712
goal Integ.thy "!!z. [| z <= w; w <= z |] ==> z = (w::int)";
clasohm@925
   713
by (EVERY1 [dtac zle_imp_zless_or_eq, dtac zle_imp_zless_or_eq,
wenzelm@4089
   714
            fast_tac (claset() addEs [zless_irrefl,zless_asym])]);
clasohm@925
   715
qed "zle_anti_sym";
clasohm@925
   716
clasohm@925
   717
clasohm@925
   718
goal Integ.thy "!!w w' z::int. z + w' = z + w ==> w' = w";
clasohm@925
   719
by (dres_inst_tac [("f", "%x. x + $~z")] arg_cong 1);
wenzelm@4089
   720
by (asm_full_simp_tac (simpset() addsimps zadd_ac) 1);
clasohm@925
   721
qed "zadd_left_cancel";
clasohm@925
   722
clasohm@925
   723
clasohm@925
   724
(*** Monotonicity results ***)
clasohm@925
   725
clasohm@925
   726
goal Integ.thy "!!v w z::int. v < w ==> v + z < w + z";
wenzelm@4089
   727
by (safe_tac (claset() addSDs [zless_eq_zadd_Suc]));
wenzelm@4089
   728
by (simp_tac (simpset() addsimps zadd_ac) 1);
wenzelm@4089
   729
by (simp_tac (simpset() addsimps [zadd_assoc RS sym, zless_zadd_Suc]) 1);
clasohm@925
   730
qed "zadd_zless_mono1";
clasohm@925
   731
clasohm@925
   732
goal Integ.thy "!!v w z::int. (v+z < w+z) = (v < w)";
wenzelm@4089
   733
by (safe_tac (claset() addSEs [zadd_zless_mono1]));
clasohm@925
   734
by (dres_inst_tac [("z", "$~z")] zadd_zless_mono1 1);
wenzelm@4089
   735
by (asm_full_simp_tac (simpset() addsimps [zadd_assoc]) 1);
clasohm@925
   736
qed "zadd_left_cancel_zless";
clasohm@925
   737
clasohm@925
   738
goal Integ.thy "!!v w z::int. (v+z <= w+z) = (v <= w)";
clasohm@925
   739
by (asm_full_simp_tac
wenzelm@4089
   740
    (simpset() addsimps [zle_def, zadd_left_cancel_zless]) 1);
clasohm@925
   741
qed "zadd_left_cancel_zle";
clasohm@925
   742
clasohm@925
   743
(*"v<=w ==> v+z <= w+z"*)
clasohm@925
   744
bind_thm ("zadd_zle_mono1", zadd_left_cancel_zle RS iffD2);
clasohm@925
   745
clasohm@925
   746
clasohm@925
   747
goal Integ.thy "!!z' z::int. [| w'<=w; z'<=z |] ==> w' + z' <= w + z";
clasohm@925
   748
by (etac (zadd_zle_mono1 RS zle_trans) 1);
wenzelm@4089
   749
by (simp_tac (simpset() addsimps [zadd_commute]) 1);
clasohm@925
   750
(*w moves to the end because it is free while z', z are bound*)
clasohm@925
   751
by (etac zadd_zle_mono1 1);
clasohm@925
   752
qed "zadd_zle_mono";
clasohm@925
   753
clasohm@925
   754
goal Integ.thy "!!w z::int. z<=$#0 ==> w+z <= w";
clasohm@925
   755
by (dres_inst_tac [("z", "w")] zadd_zle_mono1 1);
wenzelm@4089
   756
by (asm_full_simp_tac (simpset() addsimps [zadd_commute]) 1);
clasohm@925
   757
qed "zadd_zle_self";
paulson@2224
   758
paulson@2224
   759
wenzelm@4195
   760
(**** Comparisons: lemmas and proofs by Norbert Voelker ****)
paulson@2224
   761
paulson@2224
   762
(** One auxiliary theorem...**)
paulson@2224
   763
paulson@2224
   764
goal HOL.thy "(x = False) = (~ x)";
paulson@2224
   765
  by (fast_tac HOL_cs 1);
paulson@2224
   766
qed "eq_False_conv";
paulson@2224
   767
paulson@2224
   768
(** Additional theorems for Integ.thy **) 
paulson@2224
   769
paulson@2224
   770
Addsimps [zless_eq_less, zle_eq_le,
paulson@2224
   771
	  znegative_zminus_znat, not_znegative_znat]; 
paulson@2224
   772
paulson@2224
   773
goal Integ.thy "!! x. (x::int) = y ==> x <= y"; 
paulson@2224
   774
  by (etac subst 1); by (rtac zle_refl 1); 
paulson@3725
   775
qed "zequalD1"; 
paulson@2224
   776
paulson@2224
   777
goal Integ.thy "($~ x < $~ y) = (y < x)";
paulson@2224
   778
  by (rewrite_goals_tac [zless_def,zdiff_def]); 
wenzelm@4089
   779
  by (simp_tac (simpset() addsimps zadd_ac ) 1); 
paulson@3725
   780
qed "zminus_zless_zminus"; 
paulson@2224
   781
paulson@2224
   782
goal Integ.thy "($~ x <= $~ y) = (y <= x)";
paulson@2224
   783
  by (simp_tac (HOL_ss addsimps[zle_def, zminus_zless_zminus]) 1); 
paulson@3725
   784
qed "zminus_zle_zminus"; 
paulson@2224
   785
paulson@2224
   786
goal Integ.thy "(x < $~ y) = (y < $~ x)";
paulson@2224
   787
  by (rewrite_goals_tac [zless_def,zdiff_def]); 
wenzelm@4089
   788
  by (simp_tac (simpset() addsimps zadd_ac ) 1); 
paulson@3725
   789
qed "zless_zminus"; 
paulson@2224
   790
paulson@2224
   791
goal Integ.thy "($~ x < y) = ($~ y < x)";
paulson@2224
   792
  by (rewrite_goals_tac [zless_def,zdiff_def]); 
wenzelm@4089
   793
  by (simp_tac (simpset() addsimps zadd_ac ) 1); 
paulson@3725
   794
qed "zminus_zless"; 
paulson@2224
   795
paulson@2224
   796
goal Integ.thy "(x <= $~ y) = (y <=  $~ x)";
paulson@2224
   797
  by (simp_tac (HOL_ss addsimps[zle_def, zminus_zless]) 1); 
paulson@3725
   798
qed "zle_zminus"; 
paulson@2224
   799
paulson@2224
   800
goal Integ.thy "($~ x <= y) = ($~ y <=  x)";
paulson@2224
   801
  by (simp_tac (HOL_ss addsimps[zle_def, zless_zminus]) 1); 
paulson@3725
   802
qed "zminus_zle"; 
paulson@2224
   803
paulson@2224
   804
goal Integ.thy " $#0 < $# Suc n"; 
paulson@2224
   805
  by (rtac (zero_less_Suc RS (zless_eq_less RS iffD2)) 1); 
paulson@3725
   806
qed "zero_zless_Suc_pos"; 
paulson@2224
   807
paulson@2224
   808
goal Integ.thy "($# n= $# m) = (n = m)"; 
paulson@2224
   809
  by (fast_tac (HOL_cs addSEs[inj_znat RS injD]) 1); 
paulson@3725
   810
qed "znat_znat_eq"; 
paulson@2224
   811
AddIffs[znat_znat_eq]; 
paulson@2224
   812
paulson@2224
   813
goal Integ.thy "$~ $# Suc n < $#0";
paulson@2224
   814
  by (stac (zminus_0 RS sym) 1); 
paulson@2224
   815
  by (rtac (zminus_zless_zminus RS iffD2) 1); 
paulson@2224
   816
  by (rtac (zero_less_Suc RS (zless_eq_less RS iffD2)) 1); 
paulson@3725
   817
qed "negative_zless_0"; 
paulson@2224
   818
Addsimps [zero_zless_Suc_pos, negative_zless_0]; 
paulson@2224
   819
paulson@2224
   820
goal Integ.thy "$~ $#  n <= $#0";
paulson@2224
   821
  by (rtac zless_or_eq_imp_zle 1); 
paulson@2224
   822
  by (nat_ind_tac "n" 1); 
paulson@2224
   823
  by (ALLGOALS Asm_simp_tac); 
paulson@3725
   824
qed "negative_zle_0"; 
paulson@2224
   825
Addsimps[negative_zle_0]; 
paulson@2224
   826
paulson@2224
   827
goal Integ.thy "~($#0 <= $~ $# Suc n)";
paulson@2224
   828
  by (stac zle_zminus 1);
paulson@2224
   829
  by (Simp_tac 1);
paulson@3725
   830
qed "not_zle_0_negative"; 
paulson@2224
   831
Addsimps[not_zle_0_negative]; 
paulson@2224
   832
paulson@2224
   833
goal Integ.thy "($# n <= $~ $# m) = (n = 0 & m = 0)"; 
paulson@2224
   834
  by (safe_tac HOL_cs); 
paulson@2224
   835
  by (Simp_tac 3); 
paulson@2224
   836
  by (dtac (zle_zminus RS iffD1) 2); 
paulson@2224
   837
  by (ALLGOALS(dtac (negative_zle_0 RSN(2,zle_trans)))); 
paulson@2224
   838
  by (ALLGOALS Asm_full_simp_tac); 
paulson@3725
   839
qed "znat_zle_znegative"; 
paulson@2224
   840
paulson@2224
   841
goal Integ.thy "~($# n < $~ $# Suc m)";
paulson@2224
   842
  by (rtac notI 1); by (forward_tac [zless_imp_zle] 1); 
paulson@2224
   843
  by (dtac (znat_zle_znegative RS iffD1) 1); 
paulson@2224
   844
  by (safe_tac HOL_cs); 
paulson@2224
   845
  by (dtac (zless_zminus RS iffD1) 1); 
paulson@2224
   846
  by (Asm_full_simp_tac 1);
paulson@3725
   847
qed "not_znat_zless_negative"; 
paulson@2224
   848
paulson@2224
   849
goal Integ.thy "($~ $# n = $# m) = (n = 0 & m = 0)"; 
paulson@2224
   850
  by (rtac iffI 1);
paulson@2224
   851
  by (rtac  (znat_zle_znegative RS iffD1) 1); 
paulson@2224
   852
  by (dtac sym 1); 
paulson@2224
   853
  by (ALLGOALS Asm_simp_tac); 
paulson@3725
   854
qed "negative_eq_positive"; 
paulson@2224
   855
paulson@2224
   856
Addsimps [zminus_zless_zminus, zminus_zle_zminus, 
paulson@2224
   857
	  negative_eq_positive, not_znat_zless_negative]; 
paulson@2224
   858
paulson@2224
   859
goalw Integ.thy [zdiff_def,zless_def] "!! x. znegative x = (x < $# 0)";
paulson@2224
   860
  by (Auto_tac()); 
paulson@3725
   861
qed "znegative_less_0"; 
paulson@2224
   862
paulson@2224
   863
goalw Integ.thy [zdiff_def,zless_def] "!! x. (~znegative x) = ($# 0 <= x)";
paulson@2224
   864
  by (stac znegative_less_0 1); 
paulson@2224
   865
  by (safe_tac (HOL_cs addSDs[zleD,not_zleE,zleI]) ); 
paulson@3725
   866
qed "not_znegative_ge_0"; 
paulson@2224
   867
paulson@2224
   868
goal Integ.thy "!! x. znegative x ==> ? n. x = $~ $# Suc n"; 
paulson@2224
   869
  by (dtac (znegative_less_0 RS iffD1 RS zless_eq_zadd_Suc) 1); 
paulson@2224
   870
  by (etac exE 1); 
paulson@2224
   871
  by (rtac exI 1);
paulson@2224
   872
  by (dres_inst_tac [("f","(% z. z + $~ $# Suc n )")] arg_cong 1); 
wenzelm@4089
   873
  by (auto_tac(claset(), simpset() addsimps [zadd_assoc])); 
paulson@3725
   874
qed "znegativeD"; 
paulson@2224
   875
paulson@2224
   876
goal Integ.thy "!! x. ~znegative x ==> ? n. x = $# n"; 
paulson@2224
   877
  by (dtac (not_znegative_ge_0 RS iffD1) 1); 
paulson@2224
   878
  by (dtac zle_imp_zless_or_eq 1); 
paulson@2224
   879
  by (etac disjE 1); 
paulson@2224
   880
  by (dtac zless_eq_zadd_Suc 1); 
paulson@2224
   881
  by (Auto_tac()); 
paulson@3725
   882
qed "not_znegativeD"; 
paulson@2224
   883
paulson@2224
   884
(* a case theorem distinguishing positive and negative int *)  
paulson@2224
   885
paulson@2224
   886
val prems = goal Integ.thy 
paulson@2224
   887
    "[|!! n. P ($# n); !! n. P ($~ $# Suc n) |] ==> P z"; 
paulson@2224
   888
  by (cut_inst_tac [("P","znegative z")] excluded_middle 1); 
paulson@2224
   889
  by (fast_tac (HOL_cs addSDs[znegativeD,not_znegativeD] addSIs prems) 1); 
paulson@3725
   890
qed "int_cases"; 
paulson@2224
   891
paulson@2224
   892
fun int_case_tac x = res_inst_tac [("z",x)] int_cases; 
paulson@2224
   893