src/ZF/Int_ZF.thy
author wenzelm
Sat Oct 10 22:19:06 2015 +0200 (2015-10-10)
changeset 61395 4f8c2c4a0a8c
parent 61378 3e04c9ca001a
child 61798 27f3c10b0b50
permissions -rw-r--r--
tuned syntax -- more symbols;
wenzelm@41777
     1
(*  Title:      ZF/Int_ZF.thy
krauss@26056
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
krauss@26056
     3
    Copyright   1993  University of Cambridge
krauss@26056
     4
*)
krauss@26056
     5
wenzelm@60770
     6
section\<open>The Integers as Equivalence Classes Over Pairs of Natural Numbers\<close>
krauss@26056
     7
krauss@26056
     8
theory Int_ZF imports EquivClass ArithSimp begin
krauss@26056
     9
krauss@26056
    10
definition
krauss@26056
    11
  intrel :: i  where
paulson@46953
    12
    "intrel == {p \<in> (nat*nat)*(nat*nat).
krauss@26056
    13
                \<exists>x1 y1 x2 y2. p=<<x1,y1>,<x2,y2>> & x1#+y2 = x2#+y1}"
krauss@26056
    14
krauss@26056
    15
definition
krauss@26056
    16
  int :: i  where
paulson@46953
    17
    "int == (nat*nat)//intrel"
krauss@26056
    18
krauss@26056
    19
definition
wenzelm@60770
    20
  int_of :: "i=>i" --\<open>coercion from nat to int\<close>    ("$# _" [80] 80)  where
krauss@26056
    21
    "$# m == intrel `` {<natify(m), 0>}"
krauss@26056
    22
krauss@26056
    23
definition
wenzelm@60770
    24
  intify :: "i=>i" --\<open>coercion from ANYTHING to int\<close>  where
paulson@46820
    25
    "intify(m) == if m \<in> int then m else $#0"
krauss@26056
    26
krauss@26056
    27
definition
krauss@26056
    28
  raw_zminus :: "i=>i"  where
krauss@26056
    29
    "raw_zminus(z) == \<Union><x,y>\<in>z. intrel``{<y,x>}"
krauss@26056
    30
krauss@26056
    31
definition
krauss@26056
    32
  zminus :: "i=>i"                                 ("$- _" [80] 80)  where
krauss@26056
    33
    "$- z == raw_zminus (intify(z))"
krauss@26056
    34
krauss@26056
    35
definition
krauss@26056
    36
  znegative   ::      "i=>o"  where
krauss@26056
    37
    "znegative(z) == \<exists>x y. x<y & y\<in>nat & <x,y>\<in>z"
krauss@26056
    38
krauss@26056
    39
definition
krauss@26056
    40
  iszero      ::      "i=>o"  where
krauss@26056
    41
    "iszero(z) == z = $# 0"
paulson@46953
    42
krauss@26056
    43
definition
krauss@26056
    44
  raw_nat_of  :: "i=>i"  where
krauss@26056
    45
  "raw_nat_of(z) == natify (\<Union><x,y>\<in>z. x#-y)"
krauss@26056
    46
krauss@26056
    47
definition
krauss@26056
    48
  nat_of  :: "i=>i"  where
krauss@26056
    49
  "nat_of(z) == raw_nat_of (intify(z))"
krauss@26056
    50
krauss@26056
    51
definition
krauss@26056
    52
  zmagnitude  ::      "i=>i"  where
wenzelm@60770
    53
  --\<open>could be replaced by an absolute value function from int to int?\<close>
krauss@26056
    54
    "zmagnitude(z) ==
krauss@26056
    55
     THE m. m\<in>nat & ((~ znegative(z) & z = $# m) |
wenzelm@32960
    56
                       (znegative(z) & $- z = $# m))"
krauss@26056
    57
krauss@26056
    58
definition
krauss@26056
    59
  raw_zmult   ::      "[i,i]=>i"  where
krauss@26056
    60
    (*Cannot use UN<x1,y2> here or in zadd because of the form of congruent2.
krauss@26056
    61
      Perhaps a "curried" or even polymorphic congruent predicate would be
krauss@26056
    62
      better.*)
paulson@46953
    63
     "raw_zmult(z1,z2) ==
paulson@46953
    64
       \<Union>p1\<in>z1. \<Union>p2\<in>z2.  split(%x1 y1. split(%x2 y2.
krauss@26056
    65
                   intrel``{<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}, p2), p1)"
krauss@26056
    66
krauss@26056
    67
definition
krauss@26056
    68
  zmult       ::      "[i,i]=>i"      (infixl "$*" 70)  where
krauss@26056
    69
     "z1 $* z2 == raw_zmult (intify(z1),intify(z2))"
krauss@26056
    70
krauss@26056
    71
definition
krauss@26056
    72
  raw_zadd    ::      "[i,i]=>i"  where
paulson@46953
    73
     "raw_zadd (z1, z2) ==
paulson@46953
    74
       \<Union>z1\<in>z1. \<Union>z2\<in>z2. let <x1,y1>=z1; <x2,y2>=z2
krauss@26056
    75
                           in intrel``{<x1#+x2, y1#+y2>}"
krauss@26056
    76
krauss@26056
    77
definition
krauss@26056
    78
  zadd        ::      "[i,i]=>i"      (infixl "$+" 65)  where
krauss@26056
    79
     "z1 $+ z2 == raw_zadd (intify(z1),intify(z2))"
krauss@26056
    80
krauss@26056
    81
definition
krauss@26056
    82
  zdiff        ::      "[i,i]=>i"      (infixl "$-" 65)  where
krauss@26056
    83
     "z1 $- z2 == z1 $+ zminus(z2)"
krauss@26056
    84
krauss@26056
    85
definition
krauss@26056
    86
  zless        ::      "[i,i]=>o"      (infixl "$<" 50)  where
krauss@26056
    87
     "z1 $< z2 == znegative(z1 $- z2)"
paulson@46953
    88
krauss@26056
    89
definition
wenzelm@61395
    90
  zle          ::      "[i,i]=>o"      (infixl "$\<le>" 50)  where
wenzelm@61395
    91
     "z1 $\<le> z2 == z1 $< z2 | intify(z1)=intify(z2)"
krauss@26056
    92
krauss@26056
    93
krauss@26056
    94
declare quotientE [elim!]
krauss@26056
    95
wenzelm@60770
    96
subsection\<open>Proving that @{term intrel} is an equivalence relation\<close>
krauss@26056
    97
krauss@26056
    98
(** Natural deduction for intrel **)
krauss@26056
    99
paulson@46953
   100
lemma intrel_iff [simp]:
paulson@46953
   101
    "<<x1,y1>,<x2,y2>>: intrel \<longleftrightarrow>
krauss@26056
   102
     x1\<in>nat & y1\<in>nat & x2\<in>nat & y2\<in>nat & x1#+y2 = x2#+y1"
krauss@26056
   103
by (simp add: intrel_def)
krauss@26056
   104
paulson@46953
   105
lemma intrelI [intro!]:
paulson@46953
   106
    "[| x1#+y2 = x2#+y1; x1\<in>nat; y1\<in>nat; x2\<in>nat; y2\<in>nat |]
krauss@26056
   107
     ==> <<x1,y1>,<x2,y2>>: intrel"
krauss@26056
   108
by (simp add: intrel_def)
krauss@26056
   109
krauss@26056
   110
lemma intrelE [elim!]:
paulson@46953
   111
  "[| p \<in> intrel;
paulson@46953
   112
      !!x1 y1 x2 y2. [| p = <<x1,y1>,<x2,y2>>;  x1#+y2 = x2#+y1;
paulson@46953
   113
                        x1\<in>nat; y1\<in>nat; x2\<in>nat; y2\<in>nat |] ==> Q |]
krauss@26056
   114
   ==> Q"
paulson@46953
   115
by (simp add: intrel_def, blast)
krauss@26056
   116
krauss@26056
   117
lemma int_trans_lemma:
krauss@26056
   118
     "[| x1 #+ y2 = x2 #+ y1; x2 #+ y3 = x3 #+ y2 |] ==> x1 #+ y3 = x3 #+ y1"
krauss@26056
   119
apply (rule sym)
krauss@26056
   120
apply (erule add_left_cancel)+
krauss@26056
   121
apply (simp_all (no_asm_simp))
krauss@26056
   122
done
krauss@26056
   123
krauss@26056
   124
lemma equiv_intrel: "equiv(nat*nat, intrel)"
krauss@26056
   125
apply (simp add: equiv_def refl_def sym_def trans_def)
krauss@26056
   126
apply (fast elim!: sym int_trans_lemma)
krauss@26056
   127
done
krauss@26056
   128
paulson@46820
   129
lemma image_intrel_int: "[| m\<in>nat; n\<in>nat |] ==> intrel `` {<m,n>} \<in> int"
krauss@26056
   130
by (simp add: int_def)
krauss@26056
   131
krauss@26056
   132
declare equiv_intrel [THEN eq_equiv_class_iff, simp]
krauss@26056
   133
declare conj_cong [cong]
krauss@26056
   134
krauss@26056
   135
lemmas eq_intrelD = eq_equiv_class [OF _ equiv_intrel]
krauss@26056
   136
krauss@26056
   137
(** int_of: the injection from nat to int **)
krauss@26056
   138
paulson@46820
   139
lemma int_of_type [simp,TC]: "$#m \<in> int"
krauss@26056
   140
by (simp add: int_def quotient_def int_of_def, auto)
krauss@26056
   141
paulson@46821
   142
lemma int_of_eq [iff]: "($# m = $# n) \<longleftrightarrow> natify(m)=natify(n)"
krauss@26056
   143
by (simp add: int_of_def)
krauss@26056
   144
krauss@26056
   145
lemma int_of_inject: "[| $#m = $#n;  m\<in>nat;  n\<in>nat |] ==> m=n"
krauss@26056
   146
by (drule int_of_eq [THEN iffD1], auto)
krauss@26056
   147
krauss@26056
   148
krauss@26056
   149
(** intify: coercion from anything to int **)
krauss@26056
   150
paulson@46820
   151
lemma intify_in_int [iff,TC]: "intify(x) \<in> int"
krauss@26056
   152
by (simp add: intify_def)
krauss@26056
   153
paulson@46820
   154
lemma intify_ident [simp]: "n \<in> int ==> intify(n) = n"
krauss@26056
   155
by (simp add: intify_def)
krauss@26056
   156
krauss@26056
   157
wenzelm@60770
   158
subsection\<open>Collapsing rules: to remove @{term intify}
wenzelm@60770
   159
            from arithmetic expressions\<close>
krauss@26056
   160
krauss@26056
   161
lemma intify_idem [simp]: "intify(intify(x)) = intify(x)"
krauss@26056
   162
by simp
krauss@26056
   163
krauss@26056
   164
lemma int_of_natify [simp]: "$# (natify(m)) = $# m"
krauss@26056
   165
by (simp add: int_of_def)
krauss@26056
   166
krauss@26056
   167
lemma zminus_intify [simp]: "$- (intify(m)) = $- m"
krauss@26056
   168
by (simp add: zminus_def)
krauss@26056
   169
krauss@26056
   170
(** Addition **)
krauss@26056
   171
krauss@26056
   172
lemma zadd_intify1 [simp]: "intify(x) $+ y = x $+ y"
krauss@26056
   173
by (simp add: zadd_def)
krauss@26056
   174
krauss@26056
   175
lemma zadd_intify2 [simp]: "x $+ intify(y) = x $+ y"
krauss@26056
   176
by (simp add: zadd_def)
krauss@26056
   177
krauss@26056
   178
(** Subtraction **)
krauss@26056
   179
krauss@26056
   180
lemma zdiff_intify1 [simp]:"intify(x) $- y = x $- y"
krauss@26056
   181
by (simp add: zdiff_def)
krauss@26056
   182
krauss@26056
   183
lemma zdiff_intify2 [simp]:"x $- intify(y) = x $- y"
krauss@26056
   184
by (simp add: zdiff_def)
krauss@26056
   185
krauss@26056
   186
(** Multiplication **)
krauss@26056
   187
krauss@26056
   188
lemma zmult_intify1 [simp]:"intify(x) $* y = x $* y"
krauss@26056
   189
by (simp add: zmult_def)
krauss@26056
   190
krauss@26056
   191
lemma zmult_intify2 [simp]:"x $* intify(y) = x $* y"
krauss@26056
   192
by (simp add: zmult_def)
krauss@26056
   193
krauss@26056
   194
(** Orderings **)
krauss@26056
   195
paulson@46821
   196
lemma zless_intify1 [simp]:"intify(x) $< y \<longleftrightarrow> x $< y"
krauss@26056
   197
by (simp add: zless_def)
krauss@26056
   198
paulson@46821
   199
lemma zless_intify2 [simp]:"x $< intify(y) \<longleftrightarrow> x $< y"
krauss@26056
   200
by (simp add: zless_def)
krauss@26056
   201
wenzelm@61395
   202
lemma zle_intify1 [simp]:"intify(x) $\<le> y \<longleftrightarrow> x $\<le> y"
krauss@26056
   203
by (simp add: zle_def)
krauss@26056
   204
wenzelm@61395
   205
lemma zle_intify2 [simp]:"x $\<le> intify(y) \<longleftrightarrow> x $\<le> y"
krauss@26056
   206
by (simp add: zle_def)
krauss@26056
   207
krauss@26056
   208
wenzelm@60770
   209
subsection\<open>@{term zminus}: unary negation on @{term int}\<close>
krauss@26056
   210
krauss@26056
   211
lemma zminus_congruent: "(%<x,y>. intrel``{<y,x>}) respects intrel"
krauss@26056
   212
by (auto simp add: congruent_def add_ac)
krauss@26056
   213
paulson@46820
   214
lemma raw_zminus_type: "z \<in> int ==> raw_zminus(z) \<in> int"
krauss@26056
   215
apply (simp add: int_def raw_zminus_def)
krauss@26056
   216
apply (typecheck add: UN_equiv_class_type [OF equiv_intrel zminus_congruent])
krauss@26056
   217
done
krauss@26056
   218
paulson@46820
   219
lemma zminus_type [TC,iff]: "$-z \<in> int"
krauss@26056
   220
by (simp add: zminus_def raw_zminus_type)
krauss@26056
   221
paulson@46953
   222
lemma raw_zminus_inject:
paulson@46953
   223
     "[| raw_zminus(z) = raw_zminus(w);  z \<in> int;  w \<in> int |] ==> z=w"
krauss@26056
   224
apply (simp add: int_def raw_zminus_def)
krauss@26056
   225
apply (erule UN_equiv_class_inject [OF equiv_intrel zminus_congruent], safe)
krauss@26056
   226
apply (auto dest: eq_intrelD simp add: add_ac)
krauss@26056
   227
done
krauss@26056
   228
krauss@26056
   229
lemma zminus_inject_intify [dest!]: "$-z = $-w ==> intify(z) = intify(w)"
krauss@26056
   230
apply (simp add: zminus_def)
krauss@26056
   231
apply (blast dest!: raw_zminus_inject)
krauss@26056
   232
done
krauss@26056
   233
paulson@46953
   234
lemma zminus_inject: "[| $-z = $-w;  z \<in> int;  w \<in> int |] ==> z=w"
krauss@26056
   235
by auto
krauss@26056
   236
paulson@46953
   237
lemma raw_zminus:
krauss@26056
   238
    "[| x\<in>nat;  y\<in>nat |] ==> raw_zminus(intrel``{<x,y>}) = intrel `` {<y,x>}"
krauss@26056
   239
apply (simp add: raw_zminus_def UN_equiv_class [OF equiv_intrel zminus_congruent])
krauss@26056
   240
done
krauss@26056
   241
paulson@46953
   242
lemma zminus:
paulson@46953
   243
    "[| x\<in>nat;  y\<in>nat |]
krauss@26056
   244
     ==> $- (intrel``{<x,y>}) = intrel `` {<y,x>}"
krauss@26056
   245
by (simp add: zminus_def raw_zminus image_intrel_int)
krauss@26056
   246
paulson@46820
   247
lemma raw_zminus_zminus: "z \<in> int ==> raw_zminus (raw_zminus(z)) = z"
krauss@26056
   248
by (auto simp add: int_def raw_zminus)
krauss@26056
   249
krauss@26056
   250
lemma zminus_zminus_intify [simp]: "$- ($- z) = intify(z)"
krauss@26056
   251
by (simp add: zminus_def raw_zminus_type raw_zminus_zminus)
krauss@26056
   252
krauss@26056
   253
lemma zminus_int0 [simp]: "$- ($#0) = $#0"
krauss@26056
   254
by (simp add: int_of_def zminus)
krauss@26056
   255
paulson@46820
   256
lemma zminus_zminus: "z \<in> int ==> $- ($- z) = z"
krauss@26056
   257
by simp
krauss@26056
   258
krauss@26056
   259
wenzelm@60770
   260
subsection\<open>@{term znegative}: the test for negative integers\<close>
krauss@26056
   261
paulson@46821
   262
lemma znegative: "[| x\<in>nat; y\<in>nat |] ==> znegative(intrel``{<x,y>}) \<longleftrightarrow> x<y"
paulson@46953
   263
apply (cases "x<y")
krauss@26056
   264
apply (auto simp add: znegative_def not_lt_iff_le)
paulson@46953
   265
apply (subgoal_tac "y #+ x2 < x #+ y2", force)
paulson@46953
   266
apply (rule add_le_lt_mono, auto)
krauss@26056
   267
done
krauss@26056
   268
krauss@26056
   269
(*No natural number is negative!*)
krauss@26056
   270
lemma not_znegative_int_of [iff]: "~ znegative($# n)"
paulson@46953
   271
by (simp add: znegative int_of_def)
krauss@26056
   272
krauss@26056
   273
lemma znegative_zminus_int_of [simp]: "znegative($- $# succ(n))"
krauss@26056
   274
by (simp add: znegative int_of_def zminus natify_succ)
krauss@26056
   275
krauss@26056
   276
lemma not_znegative_imp_zero: "~ znegative($- $# n) ==> natify(n)=0"
krauss@26056
   277
by (simp add: znegative int_of_def zminus Ord_0_lt_iff [THEN iff_sym])
krauss@26056
   278
krauss@26056
   279
wenzelm@60770
   280
subsection\<open>@{term nat_of}: Coercion of an Integer to a Natural Number\<close>
krauss@26056
   281
krauss@26056
   282
lemma nat_of_intify [simp]: "nat_of(intify(z)) = nat_of(z)"
krauss@26056
   283
by (simp add: nat_of_def)
krauss@26056
   284
krauss@26056
   285
lemma nat_of_congruent: "(\<lambda>x. (\<lambda>\<langle>x,y\<rangle>. x #- y)(x)) respects intrel"
krauss@26056
   286
by (auto simp add: congruent_def split add: nat_diff_split)
krauss@26056
   287
paulson@46953
   288
lemma raw_nat_of:
krauss@26056
   289
    "[| x\<in>nat;  y\<in>nat |] ==> raw_nat_of(intrel``{<x,y>}) = x#-y"
krauss@26056
   290
by (simp add: raw_nat_of_def UN_equiv_class [OF equiv_intrel nat_of_congruent])
krauss@26056
   291
krauss@26056
   292
lemma raw_nat_of_int_of: "raw_nat_of($# n) = natify(n)"
krauss@26056
   293
by (simp add: int_of_def raw_nat_of)
krauss@26056
   294
krauss@26056
   295
lemma nat_of_int_of [simp]: "nat_of($# n) = natify(n)"
krauss@26056
   296
by (simp add: raw_nat_of_int_of nat_of_def)
krauss@26056
   297
krauss@26056
   298
lemma raw_nat_of_type: "raw_nat_of(z) \<in> nat"
krauss@26056
   299
by (simp add: raw_nat_of_def)
krauss@26056
   300
krauss@26056
   301
lemma nat_of_type [iff,TC]: "nat_of(z) \<in> nat"
krauss@26056
   302
by (simp add: nat_of_def raw_nat_of_type)
krauss@26056
   303
wenzelm@60770
   304
subsection\<open>zmagnitude: magnitide of an integer, as a natural number\<close>
krauss@26056
   305
krauss@26056
   306
lemma zmagnitude_int_of [simp]: "zmagnitude($# n) = natify(n)"
krauss@26056
   307
by (auto simp add: zmagnitude_def int_of_eq)
krauss@26056
   308
krauss@26056
   309
lemma natify_int_of_eq: "natify(x)=n ==> $#x = $# n"
krauss@26056
   310
apply (drule sym)
krauss@26056
   311
apply (simp (no_asm_simp) add: int_of_eq)
krauss@26056
   312
done
krauss@26056
   313
krauss@26056
   314
lemma zmagnitude_zminus_int_of [simp]: "zmagnitude($- $# n) = natify(n)"
krauss@26056
   315
apply (simp add: zmagnitude_def)
krauss@26056
   316
apply (rule the_equality)
krauss@26056
   317
apply (auto dest!: not_znegative_imp_zero natify_int_of_eq
krauss@26056
   318
            iff del: int_of_eq, auto)
krauss@26056
   319
done
krauss@26056
   320
krauss@26056
   321
lemma zmagnitude_type [iff,TC]: "zmagnitude(z)\<in>nat"
krauss@26056
   322
apply (simp add: zmagnitude_def)
krauss@26056
   323
apply (rule theI2, auto)
krauss@26056
   324
done
krauss@26056
   325
paulson@46953
   326
lemma not_zneg_int_of:
paulson@46953
   327
     "[| z \<in> int; ~ znegative(z) |] ==> \<exists>n\<in>nat. z = $# n"
krauss@26056
   328
apply (auto simp add: int_def znegative int_of_def not_lt_iff_le)
paulson@46953
   329
apply (rename_tac x y)
paulson@46953
   330
apply (rule_tac x="x#-y" in bexI)
paulson@46953
   331
apply (auto simp add: add_diff_inverse2)
krauss@26056
   332
done
krauss@26056
   333
krauss@26056
   334
lemma not_zneg_mag [simp]:
paulson@46953
   335
     "[| z \<in> int; ~ znegative(z) |] ==> $# (zmagnitude(z)) = z"
krauss@26056
   336
by (drule not_zneg_int_of, auto)
krauss@26056
   337
paulson@46953
   338
lemma zneg_int_of:
paulson@46953
   339
     "[| znegative(z); z \<in> int |] ==> \<exists>n\<in>nat. z = $- ($# succ(n))"
krauss@26056
   340
by (auto simp add: int_def znegative zminus int_of_def dest!: less_imp_succ_add)
krauss@26056
   341
krauss@26056
   342
lemma zneg_mag [simp]:
paulson@46953
   343
     "[| znegative(z); z \<in> int |] ==> $# (zmagnitude(z)) = $- z"
krauss@26056
   344
by (drule zneg_int_of, auto)
krauss@26056
   345
paulson@46820
   346
lemma int_cases: "z \<in> int ==> \<exists>n\<in>nat. z = $# n | z = $- ($# succ(n))"
krauss@26056
   347
apply (case_tac "znegative (z) ")
krauss@26056
   348
prefer 2 apply (blast dest: not_zneg_mag sym)
krauss@26056
   349
apply (blast dest: zneg_int_of)
krauss@26056
   350
done
krauss@26056
   351
krauss@26056
   352
lemma not_zneg_raw_nat_of:
paulson@46953
   353
     "[| ~ znegative(z); z \<in> int |] ==> $# (raw_nat_of(z)) = z"
krauss@26056
   354
apply (drule not_zneg_int_of)
krauss@26056
   355
apply (auto simp add: raw_nat_of_type raw_nat_of_int_of)
krauss@26056
   356
done
krauss@26056
   357
krauss@26056
   358
lemma not_zneg_nat_of_intify:
krauss@26056
   359
     "~ znegative(intify(z)) ==> $# (nat_of(z)) = intify(z)"
krauss@26056
   360
by (simp (no_asm_simp) add: nat_of_def not_zneg_raw_nat_of)
krauss@26056
   361
paulson@46953
   362
lemma not_zneg_nat_of: "[| ~ znegative(z); z \<in> int |] ==> $# (nat_of(z)) = z"
krauss@26056
   363
apply (simp (no_asm_simp) add: not_zneg_nat_of_intify)
krauss@26056
   364
done
krauss@26056
   365
krauss@26056
   366
lemma zneg_nat_of [simp]: "znegative(intify(z)) ==> nat_of(z) = 0"
krauss@26056
   367
apply (subgoal_tac "intify(z) \<in> int")
paulson@46953
   368
apply (simp add: int_def)
paulson@46953
   369
apply (auto simp add: znegative nat_of_def raw_nat_of
paulson@46953
   370
            split add: nat_diff_split)
krauss@26056
   371
done
krauss@26056
   372
krauss@26056
   373
wenzelm@60770
   374
subsection\<open>@{term zadd}: addition on int\<close>
krauss@26056
   375
wenzelm@60770
   376
text\<open>Congruence Property for Addition\<close>
paulson@46953
   377
lemma zadd_congruent2:
paulson@46953
   378
    "(%z1 z2. let <x1,y1>=z1; <x2,y2>=z2
krauss@26056
   379
                            in intrel``{<x1#+x2, y1#+y2>})
krauss@26056
   380
     respects2 intrel"
krauss@26056
   381
apply (simp add: congruent2_def)
krauss@26056
   382
(*Proof via congruent2_commuteI seems longer*)
krauss@26056
   383
apply safe
krauss@26056
   384
apply (simp (no_asm_simp) add: add_assoc Let_def)
krauss@26056
   385
(*The rest should be trivial, but rearranging terms is hard
krauss@26056
   386
  add_ac does not help rewriting with the assumptions.*)
krauss@26056
   387
apply (rule_tac m1 = x1a in add_left_commute [THEN ssubst])
krauss@26056
   388
apply (rule_tac m1 = x2a in add_left_commute [THEN ssubst])
krauss@26056
   389
apply (simp (no_asm_simp) add: add_assoc [symmetric])
krauss@26056
   390
done
krauss@26056
   391
paulson@46953
   392
lemma raw_zadd_type: "[| z \<in> int;  w \<in> int |] ==> raw_zadd(z,w) \<in> int"
krauss@26056
   393
apply (simp add: int_def raw_zadd_def)
krauss@26056
   394
apply (rule UN_equiv_class_type2 [OF equiv_intrel zadd_congruent2], assumption+)
krauss@26056
   395
apply (simp add: Let_def)
krauss@26056
   396
done
krauss@26056
   397
paulson@46820
   398
lemma zadd_type [iff,TC]: "z $+ w \<in> int"
krauss@26056
   399
by (simp add: zadd_def raw_zadd_type)
krauss@26056
   400
paulson@46953
   401
lemma raw_zadd:
paulson@46953
   402
  "[| x1\<in>nat; y1\<in>nat;  x2\<in>nat; y2\<in>nat |]
paulson@46953
   403
   ==> raw_zadd (intrel``{<x1,y1>}, intrel``{<x2,y2>}) =
krauss@26056
   404
       intrel `` {<x1#+x2, y1#+y2>}"
paulson@46953
   405
apply (simp add: raw_zadd_def
krauss@26056
   406
             UN_equiv_class2 [OF equiv_intrel equiv_intrel zadd_congruent2])
krauss@26056
   407
apply (simp add: Let_def)
krauss@26056
   408
done
krauss@26056
   409
paulson@46953
   410
lemma zadd:
paulson@46953
   411
  "[| x1\<in>nat; y1\<in>nat;  x2\<in>nat; y2\<in>nat |]
paulson@46953
   412
   ==> (intrel``{<x1,y1>}) $+ (intrel``{<x2,y2>}) =
krauss@26056
   413
       intrel `` {<x1#+x2, y1#+y2>}"
krauss@26056
   414
by (simp add: zadd_def raw_zadd image_intrel_int)
krauss@26056
   415
paulson@46820
   416
lemma raw_zadd_int0: "z \<in> int ==> raw_zadd ($#0,z) = z"
krauss@26056
   417
by (auto simp add: int_def int_of_def raw_zadd)
krauss@26056
   418
krauss@26056
   419
lemma zadd_int0_intify [simp]: "$#0 $+ z = intify(z)"
krauss@26056
   420
by (simp add: zadd_def raw_zadd_int0)
krauss@26056
   421
paulson@46953
   422
lemma zadd_int0: "z \<in> int ==> $#0 $+ z = z"
krauss@26056
   423
by simp
krauss@26056
   424
paulson@46953
   425
lemma raw_zminus_zadd_distrib:
paulson@46953
   426
     "[| z \<in> int;  w \<in> int |] ==> $- raw_zadd(z,w) = raw_zadd($- z, $- w)"
krauss@26056
   427
by (auto simp add: zminus raw_zadd int_def)
krauss@26056
   428
krauss@26056
   429
lemma zminus_zadd_distrib [simp]: "$- (z $+ w) = $- z $+ $- w"
krauss@26056
   430
by (simp add: zadd_def raw_zminus_zadd_distrib)
krauss@26056
   431
krauss@26056
   432
lemma raw_zadd_commute:
paulson@46953
   433
     "[| z \<in> int;  w \<in> int |] ==> raw_zadd(z,w) = raw_zadd(w,z)"
krauss@26056
   434
by (auto simp add: raw_zadd add_ac int_def)
krauss@26056
   435
krauss@26056
   436
lemma zadd_commute: "z $+ w = w $+ z"
krauss@26056
   437
by (simp add: zadd_def raw_zadd_commute)
krauss@26056
   438
paulson@46953
   439
lemma raw_zadd_assoc:
paulson@46953
   440
    "[| z1: int;  z2: int;  z3: int |]
krauss@26056
   441
     ==> raw_zadd (raw_zadd(z1,z2),z3) = raw_zadd(z1,raw_zadd(z2,z3))"
krauss@26056
   442
by (auto simp add: int_def raw_zadd add_assoc)
krauss@26056
   443
krauss@26056
   444
lemma zadd_assoc: "(z1 $+ z2) $+ z3 = z1 $+ (z2 $+ z3)"
krauss@26056
   445
by (simp add: zadd_def raw_zadd_type raw_zadd_assoc)
krauss@26056
   446
krauss@26056
   447
(*For AC rewriting*)
krauss@26056
   448
lemma zadd_left_commute: "z1$+(z2$+z3) = z2$+(z1$+z3)"
krauss@26056
   449
apply (simp add: zadd_assoc [symmetric])
krauss@26056
   450
apply (simp add: zadd_commute)
krauss@26056
   451
done
krauss@26056
   452
krauss@26056
   453
(*Integer addition is an AC operator*)
krauss@26056
   454
lemmas zadd_ac = zadd_assoc zadd_commute zadd_left_commute
krauss@26056
   455
krauss@26056
   456
lemma int_of_add: "$# (m #+ n) = ($#m) $+ ($#n)"
krauss@26056
   457
by (simp add: int_of_def zadd)
krauss@26056
   458
krauss@26056
   459
lemma int_succ_int_1: "$# succ(m) = $# 1 $+ ($# m)"
krauss@26056
   460
by (simp add: int_of_add [symmetric] natify_succ)
krauss@26056
   461
paulson@46953
   462
lemma int_of_diff:
paulson@46820
   463
     "[| m\<in>nat;  n \<le> m |] ==> $# (m #- n) = ($#m) $- ($#n)"
krauss@26056
   464
apply (simp add: int_of_def zdiff_def)
krauss@26056
   465
apply (frule lt_nat_in_nat)
krauss@26056
   466
apply (simp_all add: zadd zminus add_diff_inverse2)
krauss@26056
   467
done
krauss@26056
   468
paulson@46820
   469
lemma raw_zadd_zminus_inverse: "z \<in> int ==> raw_zadd (z, $- z) = $#0"
krauss@26056
   470
by (auto simp add: int_def int_of_def zminus raw_zadd add_commute)
krauss@26056
   471
krauss@26056
   472
lemma zadd_zminus_inverse [simp]: "z $+ ($- z) = $#0"
krauss@26056
   473
apply (simp add: zadd_def)
krauss@26056
   474
apply (subst zminus_intify [symmetric])
krauss@26056
   475
apply (rule intify_in_int [THEN raw_zadd_zminus_inverse])
krauss@26056
   476
done
krauss@26056
   477
krauss@26056
   478
lemma zadd_zminus_inverse2 [simp]: "($- z) $+ z = $#0"
krauss@26056
   479
by (simp add: zadd_commute zadd_zminus_inverse)
krauss@26056
   480
krauss@26056
   481
lemma zadd_int0_right_intify [simp]: "z $+ $#0 = intify(z)"
krauss@26056
   482
by (rule trans [OF zadd_commute zadd_int0_intify])
krauss@26056
   483
paulson@46953
   484
lemma zadd_int0_right: "z \<in> int ==> z $+ $#0 = z"
krauss@26056
   485
by simp
krauss@26056
   486
krauss@26056
   487
wenzelm@60770
   488
subsection\<open>@{term zmult}: Integer Multiplication\<close>
krauss@26056
   489
wenzelm@60770
   490
text\<open>Congruence property for multiplication\<close>
krauss@26056
   491
lemma zmult_congruent2:
paulson@46953
   492
    "(%p1 p2. split(%x1 y1. split(%x2 y2.
krauss@26056
   493
                    intrel``{<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}, p2), p1))
krauss@26056
   494
     respects2 intrel"
krauss@26056
   495
apply (rule equiv_intrel [THEN congruent2_commuteI], auto)
krauss@26056
   496
(*Proof that zmult is congruent in one argument*)
krauss@26056
   497
apply (rename_tac x y)
krauss@26056
   498
apply (frule_tac t = "%u. x#*u" in sym [THEN subst_context])
krauss@26056
   499
apply (drule_tac t = "%u. y#*u" in subst_context)
krauss@26056
   500
apply (erule add_left_cancel)+
krauss@26056
   501
apply (simp_all add: add_mult_distrib_left)
krauss@26056
   502
done
krauss@26056
   503
krauss@26056
   504
paulson@46953
   505
lemma raw_zmult_type: "[| z \<in> int;  w \<in> int |] ==> raw_zmult(z,w) \<in> int"
krauss@26056
   506
apply (simp add: int_def raw_zmult_def)
krauss@26056
   507
apply (rule UN_equiv_class_type2 [OF equiv_intrel zmult_congruent2], assumption+)
krauss@26056
   508
apply (simp add: Let_def)
krauss@26056
   509
done
krauss@26056
   510
paulson@46820
   511
lemma zmult_type [iff,TC]: "z $* w \<in> int"
krauss@26056
   512
by (simp add: zmult_def raw_zmult_type)
krauss@26056
   513
paulson@46953
   514
lemma raw_zmult:
paulson@46953
   515
     "[| x1\<in>nat; y1\<in>nat;  x2\<in>nat; y2\<in>nat |]
paulson@46953
   516
      ==> raw_zmult(intrel``{<x1,y1>}, intrel``{<x2,y2>}) =
krauss@26056
   517
          intrel `` {<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}"
paulson@46953
   518
by (simp add: raw_zmult_def
krauss@26056
   519
           UN_equiv_class2 [OF equiv_intrel equiv_intrel zmult_congruent2])
krauss@26056
   520
paulson@46953
   521
lemma zmult:
paulson@46953
   522
     "[| x1\<in>nat; y1\<in>nat;  x2\<in>nat; y2\<in>nat |]
paulson@46953
   523
      ==> (intrel``{<x1,y1>}) $* (intrel``{<x2,y2>}) =
krauss@26056
   524
          intrel `` {<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}"
krauss@26056
   525
by (simp add: zmult_def raw_zmult image_intrel_int)
krauss@26056
   526
paulson@46820
   527
lemma raw_zmult_int0: "z \<in> int ==> raw_zmult ($#0,z) = $#0"
krauss@26056
   528
by (auto simp add: int_def int_of_def raw_zmult)
krauss@26056
   529
krauss@26056
   530
lemma zmult_int0 [simp]: "$#0 $* z = $#0"
krauss@26056
   531
by (simp add: zmult_def raw_zmult_int0)
krauss@26056
   532
paulson@46820
   533
lemma raw_zmult_int1: "z \<in> int ==> raw_zmult ($#1,z) = z"
krauss@26056
   534
by (auto simp add: int_def int_of_def raw_zmult)
krauss@26056
   535
krauss@26056
   536
lemma zmult_int1_intify [simp]: "$#1 $* z = intify(z)"
krauss@26056
   537
by (simp add: zmult_def raw_zmult_int1)
krauss@26056
   538
paulson@46820
   539
lemma zmult_int1: "z \<in> int ==> $#1 $* z = z"
krauss@26056
   540
by simp
krauss@26056
   541
krauss@26056
   542
lemma raw_zmult_commute:
paulson@46953
   543
     "[| z \<in> int;  w \<in> int |] ==> raw_zmult(z,w) = raw_zmult(w,z)"
krauss@26056
   544
by (auto simp add: int_def raw_zmult add_ac mult_ac)
krauss@26056
   545
krauss@26056
   546
lemma zmult_commute: "z $* w = w $* z"
krauss@26056
   547
by (simp add: zmult_def raw_zmult_commute)
krauss@26056
   548
paulson@46953
   549
lemma raw_zmult_zminus:
paulson@46953
   550
     "[| z \<in> int;  w \<in> int |] ==> raw_zmult($- z, w) = $- raw_zmult(z, w)"
krauss@26056
   551
by (auto simp add: int_def zminus raw_zmult add_ac)
krauss@26056
   552
krauss@26056
   553
lemma zmult_zminus [simp]: "($- z) $* w = $- (z $* w)"
krauss@26056
   554
apply (simp add: zmult_def raw_zmult_zminus)
krauss@26056
   555
apply (subst zminus_intify [symmetric], rule raw_zmult_zminus, auto)
krauss@26056
   556
done
krauss@26056
   557
krauss@26056
   558
lemma zmult_zminus_right [simp]: "w $* ($- z) = $- (w $* z)"
krauss@26056
   559
by (simp add: zmult_commute [of w])
krauss@26056
   560
paulson@46953
   561
lemma raw_zmult_assoc:
paulson@46953
   562
    "[| z1: int;  z2: int;  z3: int |]
krauss@26056
   563
     ==> raw_zmult (raw_zmult(z1,z2),z3) = raw_zmult(z1,raw_zmult(z2,z3))"
krauss@26056
   564
by (auto simp add: int_def raw_zmult add_mult_distrib_left add_ac mult_ac)
krauss@26056
   565
krauss@26056
   566
lemma zmult_assoc: "(z1 $* z2) $* z3 = z1 $* (z2 $* z3)"
krauss@26056
   567
by (simp add: zmult_def raw_zmult_type raw_zmult_assoc)
krauss@26056
   568
krauss@26056
   569
(*For AC rewriting*)
krauss@26056
   570
lemma zmult_left_commute: "z1$*(z2$*z3) = z2$*(z1$*z3)"
krauss@26056
   571
apply (simp add: zmult_assoc [symmetric])
krauss@26056
   572
apply (simp add: zmult_commute)
krauss@26056
   573
done
krauss@26056
   574
krauss@26056
   575
(*Integer multiplication is an AC operator*)
krauss@26056
   576
lemmas zmult_ac = zmult_assoc zmult_commute zmult_left_commute
krauss@26056
   577
paulson@46953
   578
lemma raw_zadd_zmult_distrib:
paulson@46953
   579
    "[| z1: int;  z2: int;  w \<in> int |]
paulson@46953
   580
     ==> raw_zmult(raw_zadd(z1,z2), w) =
krauss@26056
   581
         raw_zadd (raw_zmult(z1,w), raw_zmult(z2,w))"
krauss@26056
   582
by (auto simp add: int_def raw_zadd raw_zmult add_mult_distrib_left add_ac mult_ac)
krauss@26056
   583
krauss@26056
   584
lemma zadd_zmult_distrib: "(z1 $+ z2) $* w = (z1 $* w) $+ (z2 $* w)"
paulson@46953
   585
by (simp add: zmult_def zadd_def raw_zadd_type raw_zmult_type
krauss@26056
   586
              raw_zadd_zmult_distrib)
krauss@26056
   587
krauss@26056
   588
lemma zadd_zmult_distrib2: "w $* (z1 $+ z2) = (w $* z1) $+ (w $* z2)"
krauss@26056
   589
by (simp add: zmult_commute [of w] zadd_zmult_distrib)
krauss@26056
   590
paulson@46953
   591
lemmas int_typechecks =
krauss@26056
   592
  int_of_type zminus_type zmagnitude_type zadd_type zmult_type
krauss@26056
   593
krauss@26056
   594
krauss@26056
   595
(*** Subtraction laws ***)
krauss@26056
   596
paulson@46820
   597
lemma zdiff_type [iff,TC]: "z $- w \<in> int"
krauss@26056
   598
by (simp add: zdiff_def)
krauss@26056
   599
krauss@26056
   600
lemma zminus_zdiff_eq [simp]: "$- (z $- y) = y $- z"
krauss@26056
   601
by (simp add: zdiff_def zadd_commute)
krauss@26056
   602
krauss@26056
   603
lemma zdiff_zmult_distrib: "(z1 $- z2) $* w = (z1 $* w) $- (z2 $* w)"
krauss@26056
   604
apply (simp add: zdiff_def)
krauss@26056
   605
apply (subst zadd_zmult_distrib)
krauss@26056
   606
apply (simp add: zmult_zminus)
krauss@26056
   607
done
krauss@26056
   608
krauss@26056
   609
lemma zdiff_zmult_distrib2: "w $* (z1 $- z2) = (w $* z1) $- (w $* z2)"
krauss@26056
   610
by (simp add: zmult_commute [of w] zdiff_zmult_distrib)
krauss@26056
   611
krauss@26056
   612
lemma zadd_zdiff_eq: "x $+ (y $- z) = (x $+ y) $- z"
krauss@26056
   613
by (simp add: zdiff_def zadd_ac)
krauss@26056
   614
krauss@26056
   615
lemma zdiff_zadd_eq: "(x $- y) $+ z = (x $+ z) $- y"
krauss@26056
   616
by (simp add: zdiff_def zadd_ac)
krauss@26056
   617
krauss@26056
   618
wenzelm@60770
   619
subsection\<open>The "Less Than" Relation\<close>
krauss@26056
   620
krauss@26056
   621
(*"Less than" is a linear ordering*)
paulson@46953
   622
lemma zless_linear_lemma:
paulson@46953
   623
     "[| z \<in> int; w \<in> int |] ==> z$<w | z=w | w$<z"
krauss@26056
   624
apply (simp add: int_def zless_def znegative_def zdiff_def, auto)
krauss@26056
   625
apply (simp add: zadd zminus image_iff Bex_def)
krauss@26056
   626
apply (rule_tac i = "xb#+ya" and j = "xc #+ y" in Ord_linear_lt)
krauss@26056
   627
apply (force dest!: spec simp add: add_ac)+
krauss@26056
   628
done
krauss@26056
   629
krauss@26056
   630
lemma zless_linear: "z$<w | intify(z)=intify(w) | w$<z"
krauss@26056
   631
apply (cut_tac z = " intify (z) " and w = " intify (w) " in zless_linear_lemma)
krauss@26056
   632
apply auto
krauss@26056
   633
done
krauss@26056
   634
krauss@26056
   635
lemma zless_not_refl [iff]: "~ (z$<z)"
krauss@26056
   636
by (auto simp add: zless_def znegative_def int_of_def zdiff_def)
krauss@26056
   637
paulson@46953
   638
lemma neq_iff_zless: "[| x \<in> int; y \<in> int |] ==> (x \<noteq> y) \<longleftrightarrow> (x $< y | y $< x)"
krauss@26056
   639
by (cut_tac z = x and w = y in zless_linear, auto)
krauss@26056
   640
paulson@46820
   641
lemma zless_imp_intify_neq: "w $< z ==> intify(w) \<noteq> intify(z)"
krauss@26056
   642
apply auto
krauss@26056
   643
apply (subgoal_tac "~ (intify (w) $< intify (z))")
krauss@26056
   644
apply (erule_tac [2] ssubst)
krauss@26056
   645
apply (simp (no_asm_use))
krauss@26056
   646
apply auto
krauss@26056
   647
done
krauss@26056
   648
krauss@26056
   649
(*This lemma allows direct proofs of other <-properties*)
paulson@46953
   650
lemma zless_imp_succ_zadd_lemma:
paulson@46953
   651
    "[| w $< z; w \<in> int; z \<in> int |] ==> (\<exists>n\<in>nat. z = w $+ $#(succ(n)))"
krauss@26056
   652
apply (simp add: zless_def znegative_def zdiff_def int_def)
krauss@26056
   653
apply (auto dest!: less_imp_succ_add simp add: zadd zminus int_of_def)
krauss@26056
   654
apply (rule_tac x = k in bexI)
wenzelm@59788
   655
apply (erule_tac i="succ (v)" for v in add_left_cancel, auto)
krauss@26056
   656
done
krauss@26056
   657
krauss@26056
   658
lemma zless_imp_succ_zadd:
krauss@26056
   659
     "w $< z ==> (\<exists>n\<in>nat. w $+ $#(succ(n)) = intify(z))"
krauss@26056
   660
apply (subgoal_tac "intify (w) $< intify (z) ")
krauss@26056
   661
apply (drule_tac w = "intify (w) " in zless_imp_succ_zadd_lemma)
krauss@26056
   662
apply auto
krauss@26056
   663
done
krauss@26056
   664
paulson@46953
   665
lemma zless_succ_zadd_lemma:
paulson@46820
   666
    "w \<in> int ==> w $< w $+ $# succ(n)"
krauss@26056
   667
apply (simp add: zless_def znegative_def zdiff_def int_def)
krauss@26056
   668
apply (auto simp add: zadd zminus int_of_def image_iff)
krauss@26056
   669
apply (rule_tac x = 0 in exI, auto)
krauss@26056
   670
done
krauss@26056
   671
krauss@26056
   672
lemma zless_succ_zadd: "w $< w $+ $# succ(n)"
krauss@26056
   673
by (cut_tac intify_in_int [THEN zless_succ_zadd_lemma], auto)
krauss@26056
   674
krauss@26056
   675
lemma zless_iff_succ_zadd:
paulson@46821
   676
     "w $< z \<longleftrightarrow> (\<exists>n\<in>nat. w $+ $#(succ(n)) = intify(z))"
krauss@26056
   677
apply (rule iffI)
krauss@26056
   678
apply (erule zless_imp_succ_zadd, auto)
krauss@26056
   679
apply (rename_tac "n")
krauss@26056
   680
apply (cut_tac w = w and n = n in zless_succ_zadd, auto)
krauss@26056
   681
done
krauss@26056
   682
paulson@46821
   683
lemma zless_int_of [simp]: "[| m\<in>nat; n\<in>nat |] ==> ($#m $< $#n) \<longleftrightarrow> (m<n)"
krauss@26056
   684
apply (simp add: less_iff_succ_add zless_iff_succ_zadd int_of_add [symmetric])
krauss@26056
   685
apply (blast intro: sym)
krauss@26056
   686
done
krauss@26056
   687
paulson@46953
   688
lemma zless_trans_lemma:
paulson@46953
   689
    "[| x $< y; y $< z; x \<in> int; y \<in> int; z \<in> int |] ==> x $< z"
krauss@26056
   690
apply (simp add: zless_def znegative_def zdiff_def int_def)
krauss@26056
   691
apply (auto simp add: zadd zminus image_iff)
krauss@26056
   692
apply (rename_tac x1 x2 y1 y2)
krauss@26056
   693
apply (rule_tac x = "x1#+x2" in exI)
krauss@26056
   694
apply (rule_tac x = "y1#+y2" in exI)
krauss@26056
   695
apply (auto simp add: add_lt_mono)
krauss@26056
   696
apply (rule sym)
thomas@57492
   697
apply hypsubst_thin
krauss@26056
   698
apply (erule add_left_cancel)+
krauss@26056
   699
apply auto
krauss@26056
   700
done
krauss@26056
   701
paulson@46841
   702
lemma zless_trans [trans]: "[| x $< y; y $< z |] ==> x $< z"
krauss@26056
   703
apply (subgoal_tac "intify (x) $< intify (z) ")
krauss@26056
   704
apply (rule_tac [2] y = "intify (y) " in zless_trans_lemma)
krauss@26056
   705
apply auto
krauss@26056
   706
done
krauss@26056
   707
krauss@26056
   708
lemma zless_not_sym: "z $< w ==> ~ (w $< z)"
krauss@26056
   709
by (blast dest: zless_trans)
krauss@26056
   710
krauss@26056
   711
(* [| z $< w; ~ P ==> w $< z |] ==> P *)
wenzelm@45602
   712
lemmas zless_asym = zless_not_sym [THEN swap]
krauss@26056
   713
wenzelm@61395
   714
lemma zless_imp_zle: "z $< w ==> z $\<le> w"
krauss@26056
   715
by (simp add: zle_def)
krauss@26056
   716
wenzelm@61395
   717
lemma zle_linear: "z $\<le> w | w $\<le> z"
krauss@26056
   718
apply (simp add: zle_def)
krauss@26056
   719
apply (cut_tac zless_linear, blast)
krauss@26056
   720
done
krauss@26056
   721
krauss@26056
   722
wenzelm@60770
   723
subsection\<open>Less Than or Equals\<close>
krauss@26056
   724
wenzelm@61395
   725
lemma zle_refl: "z $\<le> z"
krauss@26056
   726
by (simp add: zle_def)
krauss@26056
   727
wenzelm@61395
   728
lemma zle_eq_refl: "x=y ==> x $\<le> y"
krauss@26056
   729
by (simp add: zle_refl)
krauss@26056
   730
wenzelm@61395
   731
lemma zle_anti_sym_intify: "[| x $\<le> y; y $\<le> x |] ==> intify(x) = intify(y)"
krauss@26056
   732
apply (simp add: zle_def, auto)
krauss@26056
   733
apply (blast dest: zless_trans)
krauss@26056
   734
done
krauss@26056
   735
wenzelm@61395
   736
lemma zle_anti_sym: "[| x $\<le> y; y $\<le> x; x \<in> int; y \<in> int |] ==> x=y"
krauss@26056
   737
by (drule zle_anti_sym_intify, auto)
krauss@26056
   738
krauss@26056
   739
lemma zle_trans_lemma:
wenzelm@61395
   740
     "[| x \<in> int; y \<in> int; z \<in> int; x $\<le> y; y $\<le> z |] ==> x $\<le> z"
krauss@26056
   741
apply (simp add: zle_def, auto)
krauss@26056
   742
apply (blast intro: zless_trans)
krauss@26056
   743
done
krauss@26056
   744
wenzelm@61395
   745
lemma zle_trans [trans]: "[| x $\<le> y; y $\<le> z |] ==> x $\<le> z"
wenzelm@61395
   746
apply (subgoal_tac "intify (x) $\<le> intify (z) ")
krauss@26056
   747
apply (rule_tac [2] y = "intify (y) " in zle_trans_lemma)
krauss@26056
   748
apply auto
krauss@26056
   749
done
krauss@26056
   750
wenzelm@61395
   751
lemma zle_zless_trans [trans]: "[| i $\<le> j; j $< k |] ==> i $< k"
krauss@26056
   752
apply (auto simp add: zle_def)
krauss@26056
   753
apply (blast intro: zless_trans)
krauss@26056
   754
apply (simp add: zless_def zdiff_def zadd_def)
krauss@26056
   755
done
krauss@26056
   756
wenzelm@61395
   757
lemma zless_zle_trans [trans]: "[| i $< j; j $\<le> k |] ==> i $< k"
krauss@26056
   758
apply (auto simp add: zle_def)
krauss@26056
   759
apply (blast intro: zless_trans)
krauss@26056
   760
apply (simp add: zless_def zdiff_def zminus_def)
krauss@26056
   761
done
krauss@26056
   762
wenzelm@61395
   763
lemma not_zless_iff_zle: "~ (z $< w) \<longleftrightarrow> (w $\<le> z)"
krauss@26056
   764
apply (cut_tac z = z and w = w in zless_linear)
krauss@26056
   765
apply (auto dest: zless_trans simp add: zle_def)
krauss@26056
   766
apply (auto dest!: zless_imp_intify_neq)
krauss@26056
   767
done
krauss@26056
   768
wenzelm@61395
   769
lemma not_zle_iff_zless: "~ (z $\<le> w) \<longleftrightarrow> (w $< z)"
krauss@26056
   770
by (simp add: not_zless_iff_zle [THEN iff_sym])
krauss@26056
   771
krauss@26056
   772
wenzelm@60770
   773
subsection\<open>More subtraction laws (for @{text zcompare_rls})\<close>
krauss@26056
   774
krauss@26056
   775
lemma zdiff_zdiff_eq: "(x $- y) $- z = x $- (y $+ z)"
krauss@26056
   776
by (simp add: zdiff_def zadd_ac)
krauss@26056
   777
krauss@26056
   778
lemma zdiff_zdiff_eq2: "x $- (y $- z) = (x $+ z) $- y"
krauss@26056
   779
by (simp add: zdiff_def zadd_ac)
krauss@26056
   780
paulson@46821
   781
lemma zdiff_zless_iff: "(x$-y $< z) \<longleftrightarrow> (x $< z $+ y)"
krauss@26056
   782
by (simp add: zless_def zdiff_def zadd_ac)
krauss@26056
   783
paulson@46821
   784
lemma zless_zdiff_iff: "(x $< z$-y) \<longleftrightarrow> (x $+ y $< z)"
krauss@26056
   785
by (simp add: zless_def zdiff_def zadd_ac)
krauss@26056
   786
paulson@46953
   787
lemma zdiff_eq_iff: "[| x \<in> int; z \<in> int |] ==> (x$-y = z) \<longleftrightarrow> (x = z $+ y)"
krauss@26056
   788
by (auto simp add: zdiff_def zadd_assoc)
krauss@26056
   789
paulson@46953
   790
lemma eq_zdiff_iff: "[| x \<in> int; z \<in> int |] ==> (x = z$-y) \<longleftrightarrow> (x $+ y = z)"
krauss@26056
   791
by (auto simp add: zdiff_def zadd_assoc)
krauss@26056
   792
krauss@26056
   793
lemma zdiff_zle_iff_lemma:
wenzelm@61395
   794
     "[| x \<in> int; z \<in> int |] ==> (x$-y $\<le> z) \<longleftrightarrow> (x $\<le> z $+ y)"
krauss@26056
   795
by (auto simp add: zle_def zdiff_eq_iff zdiff_zless_iff)
krauss@26056
   796
wenzelm@61395
   797
lemma zdiff_zle_iff: "(x$-y $\<le> z) \<longleftrightarrow> (x $\<le> z $+ y)"
krauss@26056
   798
by (cut_tac zdiff_zle_iff_lemma [OF intify_in_int intify_in_int], simp)
krauss@26056
   799
krauss@26056
   800
lemma zle_zdiff_iff_lemma:
wenzelm@61395
   801
     "[| x \<in> int; z \<in> int |] ==>(x $\<le> z$-y) \<longleftrightarrow> (x $+ y $\<le> z)"
krauss@26056
   802
apply (auto simp add: zle_def zdiff_eq_iff zless_zdiff_iff)
krauss@26056
   803
apply (auto simp add: zdiff_def zadd_assoc)
krauss@26056
   804
done
krauss@26056
   805
wenzelm@61395
   806
lemma zle_zdiff_iff: "(x $\<le> z$-y) \<longleftrightarrow> (x $+ y $\<le> z)"
krauss@26056
   807
by (cut_tac zle_zdiff_iff_lemma [ OF intify_in_int intify_in_int], simp)
krauss@26056
   808
wenzelm@60770
   809
text\<open>This list of rewrites simplifies (in)equalities by bringing subtractions
paulson@46953
   810
  to the top and then moving negative terms to the other side.
wenzelm@60770
   811
  Use with @{text zadd_ac}\<close>
krauss@26056
   812
lemmas zcompare_rls =
krauss@26056
   813
     zdiff_def [symmetric]
paulson@46953
   814
     zadd_zdiff_eq zdiff_zadd_eq zdiff_zdiff_eq zdiff_zdiff_eq2
paulson@46953
   815
     zdiff_zless_iff zless_zdiff_iff zdiff_zle_iff zle_zdiff_iff
krauss@26056
   816
     zdiff_eq_iff eq_zdiff_iff
krauss@26056
   817
krauss@26056
   818
wenzelm@60770
   819
subsection\<open>Monotonicity and Cancellation Results for Instantiation
wenzelm@60770
   820
     of the CancelNumerals Simprocs\<close>
krauss@26056
   821
krauss@26056
   822
lemma zadd_left_cancel:
paulson@46953
   823
     "[| w \<in> int; w': int |] ==> (z $+ w' = z $+ w) \<longleftrightarrow> (w' = w)"
krauss@26056
   824
apply safe
krauss@26056
   825
apply (drule_tac t = "%x. x $+ ($-z) " in subst_context)
krauss@26056
   826
apply (simp add: zadd_ac)
krauss@26056
   827
done
krauss@26056
   828
krauss@26056
   829
lemma zadd_left_cancel_intify [simp]:
paulson@46821
   830
     "(z $+ w' = z $+ w) \<longleftrightarrow> intify(w') = intify(w)"
krauss@26056
   831
apply (rule iff_trans)
krauss@26056
   832
apply (rule_tac [2] zadd_left_cancel, auto)
krauss@26056
   833
done
krauss@26056
   834
krauss@26056
   835
lemma zadd_right_cancel:
paulson@46953
   836
     "[| w \<in> int; w': int |] ==> (w' $+ z = w $+ z) \<longleftrightarrow> (w' = w)"
krauss@26056
   837
apply safe
krauss@26056
   838
apply (drule_tac t = "%x. x $+ ($-z) " in subst_context)
krauss@26056
   839
apply (simp add: zadd_ac)
krauss@26056
   840
done
krauss@26056
   841
krauss@26056
   842
lemma zadd_right_cancel_intify [simp]:
paulson@46821
   843
     "(w' $+ z = w $+ z) \<longleftrightarrow> intify(w') = intify(w)"
krauss@26056
   844
apply (rule iff_trans)
krauss@26056
   845
apply (rule_tac [2] zadd_right_cancel, auto)
krauss@26056
   846
done
krauss@26056
   847
paulson@46821
   848
lemma zadd_right_cancel_zless [simp]: "(w' $+ z $< w $+ z) \<longleftrightarrow> (w' $< w)"
krauss@26056
   849
by (simp add: zdiff_zless_iff [THEN iff_sym] zdiff_def zadd_assoc)
krauss@26056
   850
paulson@46821
   851
lemma zadd_left_cancel_zless [simp]: "(z $+ w' $< z $+ w) \<longleftrightarrow> (w' $< w)"
krauss@26056
   852
by (simp add: zadd_commute [of z] zadd_right_cancel_zless)
krauss@26056
   853
wenzelm@61395
   854
lemma zadd_right_cancel_zle [simp]: "(w' $+ z $\<le> w $+ z) \<longleftrightarrow> w' $\<le> w"
krauss@26056
   855
by (simp add: zle_def)
krauss@26056
   856
wenzelm@61395
   857
lemma zadd_left_cancel_zle [simp]: "(z $+ w' $\<le> z $+ w) \<longleftrightarrow>  w' $\<le> w"
krauss@26056
   858
by (simp add: zadd_commute [of z]  zadd_right_cancel_zle)
krauss@26056
   859
krauss@26056
   860
wenzelm@61395
   861
(*"v $\<le> w ==> v$+z $\<le> w$+z"*)
wenzelm@45602
   862
lemmas zadd_zless_mono1 = zadd_right_cancel_zless [THEN iffD2]
krauss@26056
   863
wenzelm@61395
   864
(*"v $\<le> w ==> z$+v $\<le> z$+w"*)
wenzelm@45602
   865
lemmas zadd_zless_mono2 = zadd_left_cancel_zless [THEN iffD2]
krauss@26056
   866
wenzelm@61395
   867
(*"v $\<le> w ==> v$+z $\<le> w$+z"*)
wenzelm@45602
   868
lemmas zadd_zle_mono1 = zadd_right_cancel_zle [THEN iffD2]
krauss@26056
   869
wenzelm@61395
   870
(*"v $\<le> w ==> z$+v $\<le> z$+w"*)
wenzelm@45602
   871
lemmas zadd_zle_mono2 = zadd_left_cancel_zle [THEN iffD2]
krauss@26056
   872
wenzelm@61395
   873
lemma zadd_zle_mono: "[| w' $\<le> w; z' $\<le> z |] ==> w' $+ z' $\<le> w $+ z"
krauss@26056
   874
by (erule zadd_zle_mono1 [THEN zle_trans], simp)
krauss@26056
   875
wenzelm@61395
   876
lemma zadd_zless_mono: "[| w' $< w; z' $\<le> z |] ==> w' $+ z' $< w $+ z"
krauss@26056
   877
by (erule zadd_zless_mono1 [THEN zless_zle_trans], simp)
krauss@26056
   878
krauss@26056
   879
wenzelm@60770
   880
subsection\<open>Comparison laws\<close>
krauss@26056
   881
paulson@46821
   882
lemma zminus_zless_zminus [simp]: "($- x $< $- y) \<longleftrightarrow> (y $< x)"
krauss@26056
   883
by (simp add: zless_def zdiff_def zadd_ac)
krauss@26056
   884
wenzelm@61395
   885
lemma zminus_zle_zminus [simp]: "($- x $\<le> $- y) \<longleftrightarrow> (y $\<le> x)"
krauss@26056
   886
by (simp add: not_zless_iff_zle [THEN iff_sym])
krauss@26056
   887
wenzelm@60770
   888
subsubsection\<open>More inequality lemmas\<close>
krauss@26056
   889
paulson@46953
   890
lemma equation_zminus: "[| x \<in> int;  y \<in> int |] ==> (x = $- y) \<longleftrightarrow> (y = $- x)"
krauss@26056
   891
by auto
krauss@26056
   892
paulson@46953
   893
lemma zminus_equation: "[| x \<in> int;  y \<in> int |] ==> ($- x = y) \<longleftrightarrow> ($- y = x)"
krauss@26056
   894
by auto
krauss@26056
   895
paulson@46821
   896
lemma equation_zminus_intify: "(intify(x) = $- y) \<longleftrightarrow> (intify(y) = $- x)"
krauss@26056
   897
apply (cut_tac x = "intify (x) " and y = "intify (y) " in equation_zminus)
krauss@26056
   898
apply auto
krauss@26056
   899
done
krauss@26056
   900
paulson@46821
   901
lemma zminus_equation_intify: "($- x = intify(y)) \<longleftrightarrow> ($- y = intify(x))"
krauss@26056
   902
apply (cut_tac x = "intify (x) " and y = "intify (y) " in zminus_equation)
krauss@26056
   903
apply auto
krauss@26056
   904
done
krauss@26056
   905
krauss@26056
   906
wenzelm@60770
   907
subsubsection\<open>The next several equations are permutative: watch out!\<close>
krauss@26056
   908
paulson@46821
   909
lemma zless_zminus: "(x $< $- y) \<longleftrightarrow> (y $< $- x)"
krauss@26056
   910
by (simp add: zless_def zdiff_def zadd_ac)
krauss@26056
   911
paulson@46821
   912
lemma zminus_zless: "($- x $< y) \<longleftrightarrow> ($- y $< x)"
krauss@26056
   913
by (simp add: zless_def zdiff_def zadd_ac)
krauss@26056
   914
wenzelm@61395
   915
lemma zle_zminus: "(x $\<le> $- y) \<longleftrightarrow> (y $\<le> $- x)"
krauss@26056
   916
by (simp add: not_zless_iff_zle [THEN iff_sym] zminus_zless)
krauss@26056
   917
wenzelm@61395
   918
lemma zminus_zle: "($- x $\<le> y) \<longleftrightarrow> ($- y $\<le> x)"
krauss@26056
   919
by (simp add: not_zless_iff_zle [THEN iff_sym] zless_zminus)
krauss@26056
   920
krauss@26056
   921
end