src/HOL/IntDef.thy
author haftmann
Wed Jan 02 15:14:02 2008 +0100 (2008-01-02)
changeset 25762 c03e9d04b3e4
parent 25571 c9e39eafc7a0
permissions -rw-r--r--
splitted class uminus from class minus
wenzelm@23164
     1
(*  Title:      IntDef.thy
wenzelm@23164
     2
    ID:         $Id$
wenzelm@23164
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
wenzelm@23164
     4
    Copyright   1996  University of Cambridge
wenzelm@23164
     5
wenzelm@23164
     6
*)
wenzelm@23164
     7
wenzelm@23164
     8
header{*The Integers as Equivalence Classes over Pairs of Natural Numbers*} 
wenzelm@23164
     9
wenzelm@23164
    10
theory IntDef
wenzelm@23164
    11
imports Equiv_Relations Nat
wenzelm@23164
    12
begin
wenzelm@23164
    13
wenzelm@23164
    14
text {* the equivalence relation underlying the integers *}
wenzelm@23164
    15
wenzelm@23164
    16
definition
wenzelm@23164
    17
  intrel :: "((nat \<times> nat) \<times> (nat \<times> nat)) set"
wenzelm@23164
    18
where
wenzelm@23164
    19
  "intrel = {((x, y), (u, v)) | x y u v. x + v = u +y }"
wenzelm@23164
    20
wenzelm@23164
    21
typedef (Integ)
wenzelm@23164
    22
  int = "UNIV//intrel"
wenzelm@23164
    23
  by (auto simp add: quotient_def)
wenzelm@23164
    24
haftmann@25762
    25
instantiation int :: "{zero, one, plus, minus, uminus, times, ord, abs, sgn}"
haftmann@25571
    26
begin
haftmann@25571
    27
haftmann@25571
    28
definition
haftmann@25571
    29
  Zero_int_def [code func del]: "0 = Abs_Integ (intrel `` {(0, 0)})"
haftmann@25571
    30
haftmann@25571
    31
definition
haftmann@25571
    32
  One_int_def [code func del]: "1 = Abs_Integ (intrel `` {(1, 0)})"
wenzelm@23164
    33
haftmann@25571
    34
definition
haftmann@25571
    35
  add_int_def [code func del]: "z + w = Abs_Integ
haftmann@25571
    36
    (\<Union>(x, y) \<in> Rep_Integ z. \<Union>(u, v) \<in> Rep_Integ w.
haftmann@25571
    37
      intrel `` {(x + u, y + v)})"
wenzelm@23164
    38
haftmann@25571
    39
definition
haftmann@25571
    40
  minus_int_def [code func del]:
haftmann@25571
    41
    "- z = Abs_Integ (\<Union>(x, y) \<in> Rep_Integ z. intrel `` {(y, x)})"
haftmann@25571
    42
haftmann@25571
    43
definition
haftmann@25571
    44
  diff_int_def [code func del]:  "z - w = z + (-w \<Colon> int)"
wenzelm@23164
    45
haftmann@25571
    46
definition
haftmann@25571
    47
  mult_int_def [code func del]: "z * w = Abs_Integ
wenzelm@23164
    48
    (\<Union>(x, y) \<in> Rep_Integ z. \<Union>(u,v ) \<in> Rep_Integ w.
haftmann@25571
    49
      intrel `` {(x*u + y*v, x*v + y*u)})"
haftmann@25571
    50
haftmann@25571
    51
definition
haftmann@25571
    52
  le_int_def [code func del]:
haftmann@25571
    53
   "z \<le> w \<longleftrightarrow> (\<exists>x y u v. x+v \<le> u+y \<and> (x, y) \<in> Rep_Integ z \<and> (u, v) \<in> Rep_Integ w)"
haftmann@25571
    54
haftmann@25571
    55
definition
haftmann@25571
    56
  less_int_def [code func del]: "(z\<Colon>int) < w \<longleftrightarrow> z \<le> w \<and> z \<noteq> w"
wenzelm@23164
    57
haftmann@25571
    58
definition
haftmann@25571
    59
  zabs_def: "\<bar>i\<Colon>int\<bar> = (if i < 0 then - i else i)"
wenzelm@23164
    60
haftmann@25571
    61
definition
haftmann@25571
    62
  zsgn_def: "sgn (i\<Colon>int) = (if i=0 then 0 else if 0<i then 1 else - 1)"
haftmann@25571
    63
haftmann@25571
    64
instance ..
haftmann@25571
    65
haftmann@25571
    66
end
wenzelm@23164
    67
wenzelm@23164
    68
wenzelm@23164
    69
subsection{*Construction of the Integers*}
wenzelm@23164
    70
wenzelm@23164
    71
lemma intrel_iff [simp]: "(((x,y),(u,v)) \<in> intrel) = (x+v = u+y)"
wenzelm@23164
    72
by (simp add: intrel_def)
wenzelm@23164
    73
wenzelm@23164
    74
lemma equiv_intrel: "equiv UNIV intrel"
wenzelm@23164
    75
by (simp add: intrel_def equiv_def refl_def sym_def trans_def)
wenzelm@23164
    76
wenzelm@23164
    77
text{*Reduces equality of equivalence classes to the @{term intrel} relation:
wenzelm@23164
    78
  @{term "(intrel `` {x} = intrel `` {y}) = ((x,y) \<in> intrel)"} *}
wenzelm@23164
    79
lemmas equiv_intrel_iff [simp] = eq_equiv_class_iff [OF equiv_intrel UNIV_I UNIV_I]
wenzelm@23164
    80
wenzelm@23164
    81
text{*All equivalence classes belong to set of representatives*}
wenzelm@23164
    82
lemma [simp]: "intrel``{(x,y)} \<in> Integ"
wenzelm@23164
    83
by (auto simp add: Integ_def intrel_def quotient_def)
wenzelm@23164
    84
wenzelm@23164
    85
text{*Reduces equality on abstractions to equality on representatives:
wenzelm@23164
    86
  @{prop "\<lbrakk>x \<in> Integ; y \<in> Integ\<rbrakk> \<Longrightarrow> (Abs_Integ x = Abs_Integ y) = (x=y)"} *}
paulson@24286
    87
declare Abs_Integ_inject [simp,noatp]  Abs_Integ_inverse [simp,noatp]
wenzelm@23164
    88
wenzelm@23164
    89
text{*Case analysis on the representation of an integer as an equivalence
wenzelm@23164
    90
      class of pairs of naturals.*}
wenzelm@23164
    91
lemma eq_Abs_Integ [case_names Abs_Integ, cases type: int]:
wenzelm@23164
    92
     "(!!x y. z = Abs_Integ(intrel``{(x,y)}) ==> P) ==> P"
wenzelm@23164
    93
apply (rule Abs_Integ_cases [of z]) 
wenzelm@23164
    94
apply (auto simp add: Integ_def quotient_def) 
wenzelm@23164
    95
done
wenzelm@23164
    96
wenzelm@23164
    97
huffman@23372
    98
subsection{*Arithmetic Operations*}
wenzelm@23164
    99
wenzelm@23164
   100
lemma minus: "- Abs_Integ(intrel``{(x,y)}) = Abs_Integ(intrel `` {(y,x)})"
wenzelm@23164
   101
proof -
wenzelm@23164
   102
  have "(\<lambda>(x,y). intrel``{(y,x)}) respects intrel"
wenzelm@23164
   103
    by (simp add: congruent_def) 
wenzelm@23164
   104
  thus ?thesis
wenzelm@23164
   105
    by (simp add: minus_int_def UN_equiv_class [OF equiv_intrel])
wenzelm@23164
   106
qed
wenzelm@23164
   107
wenzelm@23164
   108
lemma add:
wenzelm@23164
   109
     "Abs_Integ (intrel``{(x,y)}) + Abs_Integ (intrel``{(u,v)}) =
wenzelm@23164
   110
      Abs_Integ (intrel``{(x+u, y+v)})"
wenzelm@23164
   111
proof -
wenzelm@23164
   112
  have "(\<lambda>z w. (\<lambda>(x,y). (\<lambda>(u,v). intrel `` {(x+u, y+v)}) w) z) 
wenzelm@23164
   113
        respects2 intrel"
wenzelm@23164
   114
    by (simp add: congruent2_def)
wenzelm@23164
   115
  thus ?thesis
wenzelm@23164
   116
    by (simp add: add_int_def UN_UN_split_split_eq
wenzelm@23164
   117
                  UN_equiv_class2 [OF equiv_intrel equiv_intrel])
wenzelm@23164
   118
qed
wenzelm@23164
   119
wenzelm@23164
   120
text{*Congruence property for multiplication*}
wenzelm@23164
   121
lemma mult_congruent2:
wenzelm@23164
   122
     "(%p1 p2. (%(x,y). (%(u,v). intrel``{(x*u + y*v, x*v + y*u)}) p2) p1)
wenzelm@23164
   123
      respects2 intrel"
wenzelm@23164
   124
apply (rule equiv_intrel [THEN congruent2_commuteI])
wenzelm@23164
   125
 apply (force simp add: mult_ac, clarify) 
wenzelm@23164
   126
apply (simp add: congruent_def mult_ac)  
wenzelm@23164
   127
apply (rename_tac u v w x y z)
wenzelm@23164
   128
apply (subgoal_tac "u*y + x*y = w*y + v*y  &  u*z + x*z = w*z + v*z")
wenzelm@23164
   129
apply (simp add: mult_ac)
wenzelm@23164
   130
apply (simp add: add_mult_distrib [symmetric])
wenzelm@23164
   131
done
wenzelm@23164
   132
wenzelm@23164
   133
lemma mult:
wenzelm@23164
   134
     "Abs_Integ((intrel``{(x,y)})) * Abs_Integ((intrel``{(u,v)})) =
wenzelm@23164
   135
      Abs_Integ(intrel `` {(x*u + y*v, x*v + y*u)})"
wenzelm@23164
   136
by (simp add: mult_int_def UN_UN_split_split_eq mult_congruent2
wenzelm@23164
   137
              UN_equiv_class2 [OF equiv_intrel equiv_intrel])
wenzelm@23164
   138
wenzelm@23164
   139
text{*The integers form a @{text comm_ring_1}*}
wenzelm@23164
   140
instance int :: comm_ring_1
wenzelm@23164
   141
proof
wenzelm@23164
   142
  fix i j k :: int
huffman@23372
   143
  show "(i + j) + k = i + (j + k)"
huffman@23372
   144
    by (cases i, cases j, cases k) (simp add: add add_assoc)
huffman@23372
   145
  show "i + j = j + i" 
huffman@23372
   146
    by (cases i, cases j) (simp add: add_ac add)
huffman@23372
   147
  show "0 + i = i"
huffman@23372
   148
    by (cases i) (simp add: Zero_int_def add)
huffman@23372
   149
  show "- i + i = 0"
huffman@23372
   150
    by (cases i) (simp add: Zero_int_def minus add)
huffman@23372
   151
  show "i - j = i + - j"
huffman@23372
   152
    by (simp add: diff_int_def)
huffman@23372
   153
  show "(i * j) * k = i * (j * k)"
nipkow@23477
   154
    by (cases i, cases j, cases k) (simp add: mult ring_simps)
huffman@23372
   155
  show "i * j = j * i"
nipkow@23477
   156
    by (cases i, cases j) (simp add: mult ring_simps)
huffman@23372
   157
  show "1 * i = i"
huffman@23372
   158
    by (cases i) (simp add: One_int_def mult)
huffman@23372
   159
  show "(i + j) * k = i * k + j * k"
nipkow@23477
   160
    by (cases i, cases j, cases k) (simp add: add mult ring_simps)
huffman@23372
   161
  show "0 \<noteq> (1::int)"
huffman@23372
   162
    by (simp add: Zero_int_def One_int_def)
wenzelm@23164
   163
qed
wenzelm@23164
   164
haftmann@24196
   165
lemma int_def: "of_nat m = Abs_Integ (intrel `` {(m, 0)})"
huffman@23365
   166
by (induct m, simp_all add: Zero_int_def One_int_def add)
huffman@23303
   167
wenzelm@23164
   168
wenzelm@23164
   169
subsection{*The @{text "\<le>"} Ordering*}
wenzelm@23164
   170
wenzelm@23164
   171
lemma le:
wenzelm@23164
   172
  "(Abs_Integ(intrel``{(x,y)}) \<le> Abs_Integ(intrel``{(u,v)})) = (x+v \<le> u+y)"
wenzelm@23164
   173
by (force simp add: le_int_def)
wenzelm@23164
   174
huffman@23299
   175
lemma less:
huffman@23299
   176
  "(Abs_Integ(intrel``{(x,y)}) < Abs_Integ(intrel``{(u,v)})) = (x+v < u+y)"
huffman@23299
   177
by (simp add: less_int_def le order_less_le)
huffman@23299
   178
wenzelm@23164
   179
instance int :: linorder
huffman@23372
   180
proof
huffman@23372
   181
  fix i j k :: int
huffman@23372
   182
  show "(i < j) = (i \<le> j \<and> i \<noteq> j)"
huffman@23372
   183
    by (simp add: less_int_def)
huffman@23372
   184
  show "i \<le> i"
huffman@23372
   185
    by (cases i) (simp add: le)
huffman@23372
   186
  show "i \<le> j \<Longrightarrow> j \<le> k \<Longrightarrow> i \<le> k"
huffman@23372
   187
    by (cases i, cases j, cases k) (simp add: le)
huffman@23372
   188
  show "i \<le> j \<Longrightarrow> j \<le> i \<Longrightarrow> i = j"
huffman@23372
   189
    by (cases i, cases j) (simp add: le)
huffman@23372
   190
  show "i \<le> j \<or> j \<le> i"
huffman@23372
   191
    by (cases i, cases j) (simp add: le linorder_linear)
huffman@23372
   192
qed
wenzelm@23164
   193
huffman@23299
   194
instance int :: pordered_cancel_ab_semigroup_add
huffman@23299
   195
proof
huffman@23372
   196
  fix i j k :: int
huffman@23372
   197
  show "i \<le> j \<Longrightarrow> k + i \<le> k + j"
huffman@23372
   198
    by (cases i, cases j, cases k) (simp add: le add)
huffman@23299
   199
qed
huffman@23299
   200
huffman@23372
   201
text{*Strict Monotonicity of Multiplication*}
wenzelm@23164
   202
wenzelm@23164
   203
text{*strict, in 1st argument; proof is by induction on k>0*}
wenzelm@23164
   204
lemma zmult_zless_mono2_lemma:
haftmann@24196
   205
     "(i::int)<j ==> 0<k ==> of_nat k * i < of_nat k * j"
wenzelm@23164
   206
apply (induct "k", simp)
huffman@23299
   207
apply (simp add: left_distrib)
wenzelm@23164
   208
apply (case_tac "k=0")
huffman@23299
   209
apply (simp_all add: add_strict_mono)
wenzelm@23164
   210
done
wenzelm@23164
   211
haftmann@24196
   212
lemma zero_le_imp_eq_int: "(0::int) \<le> k ==> \<exists>n. k = of_nat n"
wenzelm@23164
   213
apply (cases k)
huffman@23365
   214
apply (auto simp add: le add int_def Zero_int_def)
huffman@23299
   215
apply (rule_tac x="x-y" in exI, simp)
huffman@23299
   216
done
huffman@23299
   217
haftmann@24196
   218
lemma zero_less_imp_eq_int: "(0::int) < k ==> \<exists>n>0. k = of_nat n"
huffman@23299
   219
apply (cases k)
huffman@23365
   220
apply (simp add: less int_def Zero_int_def)
wenzelm@23164
   221
apply (rule_tac x="x-y" in exI, simp)
wenzelm@23164
   222
done
wenzelm@23164
   223
wenzelm@23164
   224
lemma zmult_zless_mono2: "[| i<j;  (0::int) < k |] ==> k*i < k*j"
huffman@23299
   225
apply (drule zero_less_imp_eq_int)
wenzelm@23164
   226
apply (auto simp add: zmult_zless_mono2_lemma)
wenzelm@23164
   227
done
wenzelm@23164
   228
haftmann@25571
   229
instantiation int :: distrib_lattice
haftmann@25571
   230
begin
wenzelm@23164
   231
haftmann@25571
   232
definition
haftmann@25571
   233
  "(inf \<Colon> int \<Rightarrow> int \<Rightarrow> int) = min"
haftmann@25571
   234
haftmann@25571
   235
definition
haftmann@25571
   236
  "(sup \<Colon> int \<Rightarrow> int \<Rightarrow> int) = max"
haftmann@25571
   237
haftmann@25571
   238
instance
wenzelm@23164
   239
  by intro_classes
wenzelm@23164
   240
    (auto simp add: inf_int_def sup_int_def min_max.sup_inf_distrib1)
wenzelm@23164
   241
haftmann@25571
   242
end
haftmann@25571
   243
huffman@23299
   244
text{*The integers form an ordered integral domain*}
wenzelm@23164
   245
instance int :: ordered_idom
wenzelm@23164
   246
proof
wenzelm@23164
   247
  fix i j k :: int
huffman@23372
   248
  show "i < j \<Longrightarrow> 0 < k \<Longrightarrow> k * i < k * j"
huffman@23372
   249
    by (rule zmult_zless_mono2)
huffman@23372
   250
  show "\<bar>i\<bar> = (if i < 0 then -i else i)"
huffman@23372
   251
    by (simp only: zabs_def)
nipkow@24506
   252
  show "sgn(i\<Colon>int) = (if i=0 then 0 else if 0<i then 1 else - 1)"
nipkow@24506
   253
    by (simp only: zsgn_def)
wenzelm@23164
   254
qed
wenzelm@23164
   255
wenzelm@23164
   256
lemma zless_imp_add1_zle: "w<z ==> w + (1::int) \<le> z"
wenzelm@23164
   257
apply (cases w, cases z) 
huffman@23299
   258
apply (simp add: less le add One_int_def)
wenzelm@23164
   259
done
wenzelm@23164
   260
huffman@23299
   261
huffman@23299
   262
subsection{*Magnitude of an Integer, as a Natural Number: @{term nat}*}
wenzelm@23164
   263
wenzelm@23164
   264
definition
wenzelm@23164
   265
  nat :: "int \<Rightarrow> nat"
wenzelm@23164
   266
where
wenzelm@23164
   267
  [code func del]: "nat z = contents (\<Union>(x, y) \<in> Rep_Integ z. {x-y})"
wenzelm@23164
   268
wenzelm@23164
   269
lemma nat: "nat (Abs_Integ (intrel``{(x,y)})) = x-y"
wenzelm@23164
   270
proof -
wenzelm@23164
   271
  have "(\<lambda>(x,y). {x-y}) respects intrel"
wenzelm@23164
   272
    by (simp add: congruent_def) arith
wenzelm@23164
   273
  thus ?thesis
wenzelm@23164
   274
    by (simp add: nat_def UN_equiv_class [OF equiv_intrel])
wenzelm@23164
   275
qed
wenzelm@23164
   276
haftmann@24196
   277
lemma nat_int [simp]: "nat (of_nat n) = n"
huffman@23365
   278
by (simp add: nat int_def)
wenzelm@23164
   279
wenzelm@23164
   280
lemma nat_zero [simp]: "nat 0 = 0"
huffman@23303
   281
by (simp add: Zero_int_def nat)
wenzelm@23164
   282
haftmann@24196
   283
lemma int_nat_eq [simp]: "of_nat (nat z) = (if 0 \<le> z then z else 0)"
huffman@23365
   284
by (cases z, simp add: nat le int_def Zero_int_def)
wenzelm@23164
   285
haftmann@24196
   286
corollary nat_0_le: "0 \<le> z ==> of_nat (nat z) = z"
wenzelm@23164
   287
by simp
wenzelm@23164
   288
wenzelm@23164
   289
lemma nat_le_0 [simp]: "z \<le> 0 ==> nat z = 0"
huffman@23303
   290
by (cases z, simp add: nat le Zero_int_def)
wenzelm@23164
   291
wenzelm@23164
   292
lemma nat_le_eq_zle: "0 < w | 0 \<le> z ==> (nat w \<le> nat z) = (w\<le>z)"
wenzelm@23164
   293
apply (cases w, cases z) 
huffman@23303
   294
apply (simp add: nat le linorder_not_le [symmetric] Zero_int_def, arith)
wenzelm@23164
   295
done
wenzelm@23164
   296
wenzelm@23164
   297
text{*An alternative condition is @{term "0 \<le> w"} *}
wenzelm@23164
   298
corollary nat_mono_iff: "0 < z ==> (nat w < nat z) = (w < z)"
wenzelm@23164
   299
by (simp add: nat_le_eq_zle linorder_not_le [symmetric]) 
wenzelm@23164
   300
wenzelm@23164
   301
corollary nat_less_eq_zless: "0 \<le> w ==> (nat w < nat z) = (w<z)"
wenzelm@23164
   302
by (simp add: nat_le_eq_zle linorder_not_le [symmetric]) 
wenzelm@23164
   303
huffman@23365
   304
lemma zless_nat_conj [simp]: "(nat w < nat z) = (0 < z & w < z)"
wenzelm@23164
   305
apply (cases w, cases z) 
huffman@23303
   306
apply (simp add: nat le Zero_int_def linorder_not_le [symmetric], arith)
wenzelm@23164
   307
done
wenzelm@23164
   308
haftmann@24196
   309
lemma nonneg_eq_int:
haftmann@24196
   310
  fixes z :: int
haftmann@24196
   311
  assumes "0 \<le> z" and "\<And>m. z = of_nat m \<Longrightarrow> P"
haftmann@24196
   312
  shows P
haftmann@24196
   313
  using assms by (blast dest: nat_0_le sym)
wenzelm@23164
   314
haftmann@24196
   315
lemma nat_eq_iff: "(nat w = m) = (if 0 \<le> w then w = of_nat m else m=0)"
huffman@23365
   316
by (cases w, simp add: nat le int_def Zero_int_def, arith)
wenzelm@23164
   317
haftmann@24196
   318
corollary nat_eq_iff2: "(m = nat w) = (if 0 \<le> w then w = of_nat m else m=0)"
huffman@23365
   319
by (simp only: eq_commute [of m] nat_eq_iff)
wenzelm@23164
   320
haftmann@24196
   321
lemma nat_less_iff: "0 \<le> w ==> (nat w < m) = (w < of_nat m)"
wenzelm@23164
   322
apply (cases w)
huffman@23365
   323
apply (simp add: nat le int_def Zero_int_def linorder_not_le [symmetric], arith)
wenzelm@23164
   324
done
wenzelm@23164
   325
haftmann@24196
   326
lemma int_eq_iff: "(of_nat m = z) = (m = nat z & 0 \<le> z)"
huffman@23365
   327
by (auto simp add: nat_eq_iff2)
wenzelm@23164
   328
wenzelm@23164
   329
lemma zero_less_nat_eq [simp]: "(0 < nat z) = (0 < z)"
wenzelm@23164
   330
by (insert zless_nat_conj [of 0], auto)
wenzelm@23164
   331
wenzelm@23164
   332
lemma nat_add_distrib:
wenzelm@23164
   333
     "[| (0::int) \<le> z;  0 \<le> z' |] ==> nat (z+z') = nat z + nat z'"
huffman@23303
   334
by (cases z, cases z', simp add: nat add le Zero_int_def)
wenzelm@23164
   335
wenzelm@23164
   336
lemma nat_diff_distrib:
wenzelm@23164
   337
     "[| (0::int) \<le> z';  z' \<le> z |] ==> nat (z-z') = nat z - nat z'"
wenzelm@23164
   338
by (cases z, cases z', 
huffman@23303
   339
    simp add: nat add minus diff_minus le Zero_int_def)
wenzelm@23164
   340
haftmann@24196
   341
lemma nat_zminus_int [simp]: "nat (- (of_nat n)) = 0"
huffman@23365
   342
by (simp add: int_def minus nat Zero_int_def) 
wenzelm@23164
   343
haftmann@24196
   344
lemma zless_nat_eq_int_zless: "(m < nat z) = (of_nat m < z)"
huffman@23365
   345
by (cases z, simp add: nat less int_def, arith)
wenzelm@23164
   346
wenzelm@23164
   347
haftmann@24196
   348
subsection{*Lemmas about the Function @{term of_nat} and Orderings*}
wenzelm@23164
   349
haftmann@24196
   350
lemma negative_zless_0: "- (of_nat (Suc n)) < (0 \<Colon> int)"
huffman@23303
   351
by (simp add: order_less_le del: of_nat_Suc)
wenzelm@23164
   352
haftmann@24196
   353
lemma negative_zless [iff]: "- (of_nat (Suc n)) < (of_nat m \<Colon> int)"
huffman@23365
   354
by (rule negative_zless_0 [THEN order_less_le_trans], simp)
wenzelm@23164
   355
haftmann@24196
   356
lemma negative_zle_0: "- of_nat n \<le> (0 \<Colon> int)"
wenzelm@23164
   357
by (simp add: minus_le_iff)
wenzelm@23164
   358
haftmann@24196
   359
lemma negative_zle [iff]: "- of_nat n \<le> (of_nat m \<Colon> int)"
huffman@23365
   360
by (rule order_trans [OF negative_zle_0 of_nat_0_le_iff])
wenzelm@23164
   361
haftmann@24196
   362
lemma not_zle_0_negative [simp]: "~ (0 \<le> - (of_nat (Suc n) \<Colon> int))"
huffman@23303
   363
by (subst le_minus_iff, simp del: of_nat_Suc)
wenzelm@23164
   364
haftmann@24196
   365
lemma int_zle_neg: "((of_nat n \<Colon> int) \<le> - of_nat m) = (n = 0 & m = 0)"
huffman@23365
   366
by (simp add: int_def le minus Zero_int_def)
wenzelm@23164
   367
haftmann@24196
   368
lemma not_int_zless_negative [simp]: "~ ((of_nat n \<Colon> int) < - of_nat m)"
wenzelm@23164
   369
by (simp add: linorder_not_less)
wenzelm@23164
   370
haftmann@24196
   371
lemma negative_eq_positive [simp]: "((- of_nat n \<Colon> int) = of_nat m) = (n = 0 & m = 0)"
haftmann@24196
   372
by (force simp add: order_eq_iff [of "- of_nat n"] int_zle_neg)
wenzelm@23164
   373
haftmann@24196
   374
lemma zle_iff_zadd: "(w\<Colon>int) \<le> z \<longleftrightarrow> (\<exists>n. z = w + of_nat n)"
huffman@23372
   375
proof -
huffman@23372
   376
  have "(w \<le> z) = (0 \<le> z - w)"
huffman@23372
   377
    by (simp only: le_diff_eq add_0_left)
haftmann@24196
   378
  also have "\<dots> = (\<exists>n. z - w = of_nat n)"
huffman@23372
   379
    by (auto elim: zero_le_imp_eq_int)
haftmann@24196
   380
  also have "\<dots> = (\<exists>n. z = w + of_nat n)"
nipkow@23477
   381
    by (simp only: group_simps)
huffman@23372
   382
  finally show ?thesis .
wenzelm@23164
   383
qed
wenzelm@23164
   384
haftmann@24196
   385
lemma zadd_int_left: "of_nat m + (of_nat n + z) = of_nat (m + n) + (z\<Colon>int)"
huffman@23372
   386
by simp
huffman@23372
   387
haftmann@24196
   388
lemma int_Suc0_eq_1: "of_nat (Suc 0) = (1\<Colon>int)"
huffman@23372
   389
by simp
huffman@23372
   390
wenzelm@23164
   391
text{*This version is proved for all ordered rings, not just integers!
wenzelm@23164
   392
      It is proved here because attribute @{text arith_split} is not available
wenzelm@23164
   393
      in theory @{text Ring_and_Field}.
wenzelm@23164
   394
      But is it really better than just rewriting with @{text abs_if}?*}
paulson@24286
   395
lemma abs_split [arith_split,noatp]:
wenzelm@23164
   396
     "P(abs(a::'a::ordered_idom)) = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))"
wenzelm@23164
   397
by (force dest: order_less_le_trans simp add: abs_if linorder_not_less)
wenzelm@23164
   398
wenzelm@23164
   399
wenzelm@23164
   400
subsection {* Constants @{term neg} and @{term iszero} *}
wenzelm@23164
   401
wenzelm@23164
   402
definition
wenzelm@23164
   403
  neg  :: "'a\<Colon>ordered_idom \<Rightarrow> bool"
wenzelm@23164
   404
where
haftmann@25164
   405
  "neg Z \<longleftrightarrow> Z < 0"
wenzelm@23164
   406
wenzelm@23164
   407
definition (*for simplifying equalities*)
huffman@23276
   408
  iszero :: "'a\<Colon>semiring_1 \<Rightarrow> bool"
wenzelm@23164
   409
where
wenzelm@23164
   410
  "iszero z \<longleftrightarrow> z = 0"
wenzelm@23164
   411
haftmann@24196
   412
lemma not_neg_int [simp]: "~ neg (of_nat n)"
wenzelm@23164
   413
by (simp add: neg_def)
wenzelm@23164
   414
haftmann@24196
   415
lemma neg_zminus_int [simp]: "neg (- (of_nat (Suc n)))"
huffman@23303
   416
by (simp add: neg_def neg_less_0_iff_less del: of_nat_Suc)
wenzelm@23164
   417
wenzelm@23164
   418
lemmas neg_eq_less_0 = neg_def
wenzelm@23164
   419
wenzelm@23164
   420
lemma not_neg_eq_ge_0: "(~neg x) = (0 \<le> x)"
wenzelm@23164
   421
by (simp add: neg_def linorder_not_less)
wenzelm@23164
   422
wenzelm@23164
   423
huffman@23372
   424
text{*To simplify inequalities when Numeral1 can get simplified to 1*}
wenzelm@23164
   425
wenzelm@23164
   426
lemma not_neg_0: "~ neg 0"
wenzelm@23164
   427
by (simp add: One_int_def neg_def)
wenzelm@23164
   428
wenzelm@23164
   429
lemma not_neg_1: "~ neg 1"
wenzelm@23164
   430
by (simp add: neg_def linorder_not_less zero_le_one)
wenzelm@23164
   431
wenzelm@23164
   432
lemma iszero_0: "iszero 0"
wenzelm@23164
   433
by (simp add: iszero_def)
wenzelm@23164
   434
wenzelm@23164
   435
lemma not_iszero_1: "~ iszero 1"
wenzelm@23164
   436
by (simp add: iszero_def eq_commute)
wenzelm@23164
   437
wenzelm@23164
   438
lemma neg_nat: "neg z ==> nat z = 0"
wenzelm@23164
   439
by (simp add: neg_def order_less_imp_le) 
wenzelm@23164
   440
haftmann@24196
   441
lemma not_neg_nat: "~ neg z ==> of_nat (nat z) = z"
wenzelm@23164
   442
by (simp add: linorder_not_less neg_def)
wenzelm@23164
   443
wenzelm@23164
   444
haftmann@23852
   445
subsection{*Embedding of the Integers into any @{text ring_1}: @{term of_int}*}
wenzelm@23164
   446
haftmann@25193
   447
context ring_1
haftmann@25193
   448
begin
haftmann@25193
   449
haftmann@25230
   450
term of_nat
haftmann@25230
   451
haftmann@23950
   452
definition
haftmann@25193
   453
  of_int :: "int \<Rightarrow> 'a"
haftmann@23950
   454
where
haftmann@23950
   455
  "of_int z = contents (\<Union>(i, j) \<in> Rep_Integ z. { of_nat i - of_nat j })"
haftmann@23852
   456
lemmas [code func del] = of_int_def
wenzelm@23164
   457
wenzelm@23164
   458
lemma of_int: "of_int (Abs_Integ (intrel `` {(i,j)})) = of_nat i - of_nat j"
wenzelm@23164
   459
proof -
wenzelm@23164
   460
  have "(\<lambda>(i,j). { of_nat i - (of_nat j :: 'a) }) respects intrel"
wenzelm@23164
   461
    by (simp add: congruent_def compare_rls of_nat_add [symmetric]
wenzelm@23164
   462
            del: of_nat_add) 
wenzelm@23164
   463
  thus ?thesis
wenzelm@23164
   464
    by (simp add: of_int_def UN_equiv_class [OF equiv_intrel])
wenzelm@23164
   465
qed
wenzelm@23164
   466
wenzelm@23164
   467
lemma of_int_0 [simp]: "of_int 0 = 0"
huffman@23303
   468
by (simp add: of_int Zero_int_def)
wenzelm@23164
   469
wenzelm@23164
   470
lemma of_int_1 [simp]: "of_int 1 = 1"
huffman@23303
   471
by (simp add: of_int One_int_def)
wenzelm@23164
   472
wenzelm@23164
   473
lemma of_int_add [simp]: "of_int (w+z) = of_int w + of_int z"
wenzelm@23164
   474
by (cases w, cases z, simp add: compare_rls of_int add)
wenzelm@23164
   475
wenzelm@23164
   476
lemma of_int_minus [simp]: "of_int (-z) = - (of_int z)"
wenzelm@23164
   477
by (cases z, simp add: compare_rls of_int minus)
wenzelm@23164
   478
wenzelm@23164
   479
lemma of_int_mult [simp]: "of_int (w*z) = of_int w * of_int z"
wenzelm@23164
   480
apply (cases w, cases z)
wenzelm@23164
   481
apply (simp add: compare_rls of_int left_diff_distrib right_diff_distrib
huffman@23431
   482
                 mult add_ac of_nat_mult)
wenzelm@23164
   483
done
wenzelm@23164
   484
haftmann@25193
   485
text{*Collapse nested embeddings*}
haftmann@25193
   486
lemma of_int_of_nat_eq [simp]: "of_int (Nat.of_nat n) = of_nat n"
haftmann@25193
   487
  by (induct n, auto)
haftmann@25193
   488
haftmann@25193
   489
end
haftmann@25193
   490
haftmann@25193
   491
lemma of_int_diff [simp]: "of_int (w-z) = of_int w - of_int z"
haftmann@25193
   492
by (simp add: diff_minus)
haftmann@25193
   493
wenzelm@23164
   494
lemma of_int_le_iff [simp]:
wenzelm@23164
   495
     "(of_int w \<le> (of_int z::'a::ordered_idom)) = (w \<le> z)"
wenzelm@23164
   496
apply (cases w)
wenzelm@23164
   497
apply (cases z)
wenzelm@23164
   498
apply (simp add: compare_rls of_int le diff_int_def add minus
wenzelm@23164
   499
                 of_nat_add [symmetric]   del: of_nat_add)
wenzelm@23164
   500
done
wenzelm@23164
   501
wenzelm@23164
   502
text{*Special cases where either operand is zero*}
wenzelm@23164
   503
lemmas of_int_0_le_iff [simp] = of_int_le_iff [of 0, simplified]
wenzelm@23164
   504
lemmas of_int_le_0_iff [simp] = of_int_le_iff [of _ 0, simplified]
wenzelm@23164
   505
wenzelm@23164
   506
lemma of_int_less_iff [simp]:
wenzelm@23164
   507
     "(of_int w < (of_int z::'a::ordered_idom)) = (w < z)"
wenzelm@23164
   508
by (simp add: linorder_not_le [symmetric])
wenzelm@23164
   509
wenzelm@23164
   510
text{*Special cases where either operand is zero*}
wenzelm@23164
   511
lemmas of_int_0_less_iff [simp] = of_int_less_iff [of 0, simplified]
wenzelm@23164
   512
lemmas of_int_less_0_iff [simp] = of_int_less_iff [of _ 0, simplified]
wenzelm@23164
   513
wenzelm@23164
   514
text{*Class for unital rings with characteristic zero.
wenzelm@23164
   515
 Includes non-ordered rings like the complex numbers.*}
haftmann@23950
   516
class ring_char_0 = ring_1 + semiring_char_0
haftmann@25193
   517
begin
wenzelm@23164
   518
wenzelm@23164
   519
lemma of_int_eq_iff [simp]:
haftmann@25193
   520
   "of_int w = of_int z \<longleftrightarrow> w = z"
huffman@23282
   521
apply (cases w, cases z, simp add: of_int)
huffman@23282
   522
apply (simp only: diff_eq_eq diff_add_eq eq_diff_eq)
huffman@23282
   523
apply (simp only: of_nat_add [symmetric] of_nat_eq_iff)
huffman@23282
   524
done
wenzelm@23164
   525
wenzelm@23164
   526
text{*Special cases where either operand is zero*}
wenzelm@23164
   527
lemmas of_int_0_eq_iff [simp] = of_int_eq_iff [of 0, simplified]
wenzelm@23164
   528
lemmas of_int_eq_0_iff [simp] = of_int_eq_iff [of _ 0, simplified]
wenzelm@23164
   529
haftmann@25193
   530
end
haftmann@25193
   531
haftmann@25193
   532
text{*Every @{text ordered_idom} has characteristic zero.*}
haftmann@25193
   533
instance ordered_idom \<subseteq> ring_char_0 ..
haftmann@25193
   534
haftmann@25193
   535
lemma of_int_eq_id [simp]: "of_int = id"
wenzelm@23164
   536
proof
haftmann@25193
   537
  fix z show "of_int z = id z"
haftmann@25193
   538
    by (cases z) (simp add: of_int add minus int_def diff_minus)
wenzelm@23164
   539
qed
wenzelm@23164
   540
haftmann@25230
   541
context ring_1
haftmann@25230
   542
begin
haftmann@25230
   543
haftmann@25193
   544
lemma of_nat_nat: "0 \<le> z \<Longrightarrow> of_nat (nat z) = of_int z"
haftmann@25230
   545
  by (cases z rule: eq_Abs_Integ)
huffman@23438
   546
   (simp add: nat le of_int Zero_int_def of_nat_diff)
huffman@23372
   547
haftmann@25230
   548
end
haftmann@25230
   549
wenzelm@23164
   550
wenzelm@23164
   551
subsection{*The Set of Integers*}
wenzelm@23164
   552
haftmann@25193
   553
context ring_1
haftmann@25193
   554
begin
haftmann@25193
   555
haftmann@25193
   556
definition
haftmann@25193
   557
  Ints  :: "'a set"
haftmann@25193
   558
where
haftmann@25193
   559
  "Ints = range of_int"
haftmann@25193
   560
haftmann@25193
   561
end
wenzelm@23164
   562
wenzelm@23164
   563
notation (xsymbols)
wenzelm@23164
   564
  Ints  ("\<int>")
wenzelm@23164
   565
haftmann@25193
   566
context ring_1
haftmann@25193
   567
begin
haftmann@25193
   568
haftmann@25193
   569
lemma Ints_0 [simp]: "0 \<in> \<int>"
wenzelm@23164
   570
apply (simp add: Ints_def)
wenzelm@23164
   571
apply (rule range_eqI)
wenzelm@23164
   572
apply (rule of_int_0 [symmetric])
wenzelm@23164
   573
done
wenzelm@23164
   574
haftmann@25193
   575
lemma Ints_1 [simp]: "1 \<in> \<int>"
wenzelm@23164
   576
apply (simp add: Ints_def)
wenzelm@23164
   577
apply (rule range_eqI)
wenzelm@23164
   578
apply (rule of_int_1 [symmetric])
wenzelm@23164
   579
done
wenzelm@23164
   580
haftmann@25193
   581
lemma Ints_add [simp]: "a \<in> \<int> \<Longrightarrow> b \<in> \<int> \<Longrightarrow> a + b \<in> \<int>"
wenzelm@23164
   582
apply (auto simp add: Ints_def)
wenzelm@23164
   583
apply (rule range_eqI)
wenzelm@23164
   584
apply (rule of_int_add [symmetric])
wenzelm@23164
   585
done
wenzelm@23164
   586
haftmann@25193
   587
lemma Ints_minus [simp]: "a \<in> \<int> \<Longrightarrow> -a \<in> \<int>"
wenzelm@23164
   588
apply (auto simp add: Ints_def)
wenzelm@23164
   589
apply (rule range_eqI)
wenzelm@23164
   590
apply (rule of_int_minus [symmetric])
wenzelm@23164
   591
done
wenzelm@23164
   592
haftmann@25193
   593
lemma Ints_mult [simp]: "a \<in> \<int> \<Longrightarrow> b \<in> \<int> \<Longrightarrow> a * b \<in> \<int>"
wenzelm@23164
   594
apply (auto simp add: Ints_def)
wenzelm@23164
   595
apply (rule range_eqI)
wenzelm@23164
   596
apply (rule of_int_mult [symmetric])
wenzelm@23164
   597
done
wenzelm@23164
   598
wenzelm@23164
   599
lemma Ints_cases [cases set: Ints]:
wenzelm@23164
   600
  assumes "q \<in> \<int>"
wenzelm@23164
   601
  obtains (of_int) z where "q = of_int z"
wenzelm@23164
   602
  unfolding Ints_def
wenzelm@23164
   603
proof -
wenzelm@23164
   604
  from `q \<in> \<int>` have "q \<in> range of_int" unfolding Ints_def .
wenzelm@23164
   605
  then obtain z where "q = of_int z" ..
wenzelm@23164
   606
  then show thesis ..
wenzelm@23164
   607
qed
wenzelm@23164
   608
wenzelm@23164
   609
lemma Ints_induct [case_names of_int, induct set: Ints]:
haftmann@25193
   610
  "q \<in> \<int> \<Longrightarrow> (\<And>z. P (of_int z)) \<Longrightarrow> P q"
wenzelm@23164
   611
  by (rule Ints_cases) auto
wenzelm@23164
   612
haftmann@25193
   613
end
haftmann@25193
   614
haftmann@25193
   615
lemma Ints_diff [simp]: "a \<in> \<int> \<Longrightarrow> b \<in> \<int> \<Longrightarrow> a-b \<in> \<int>"
haftmann@25193
   616
apply (auto simp add: Ints_def)
haftmann@25193
   617
apply (rule range_eqI)
haftmann@25193
   618
apply (rule of_int_diff [symmetric])
haftmann@25193
   619
done
haftmann@25193
   620
wenzelm@23164
   621
haftmann@24728
   622
subsection {* @{term setsum} and @{term setprod} *}
haftmann@24728
   623
haftmann@24728
   624
text {*By Jeremy Avigad*}
haftmann@24728
   625
haftmann@24728
   626
lemma of_nat_setsum: "of_nat (setsum f A) = (\<Sum>x\<in>A. of_nat(f x))"
haftmann@24728
   627
  apply (cases "finite A")
haftmann@24728
   628
  apply (erule finite_induct, auto)
haftmann@24728
   629
  done
haftmann@24728
   630
haftmann@24728
   631
lemma of_int_setsum: "of_int (setsum f A) = (\<Sum>x\<in>A. of_int(f x))"
haftmann@24728
   632
  apply (cases "finite A")
haftmann@24728
   633
  apply (erule finite_induct, auto)
haftmann@24728
   634
  done
haftmann@24728
   635
haftmann@24728
   636
lemma of_nat_setprod: "of_nat (setprod f A) = (\<Prod>x\<in>A. of_nat(f x))"
haftmann@24728
   637
  apply (cases "finite A")
haftmann@24728
   638
  apply (erule finite_induct, auto simp add: of_nat_mult)
haftmann@24728
   639
  done
haftmann@24728
   640
haftmann@24728
   641
lemma of_int_setprod: "of_int (setprod f A) = (\<Prod>x\<in>A. of_int(f x))"
haftmann@24728
   642
  apply (cases "finite A")
haftmann@24728
   643
  apply (erule finite_induct, auto)
haftmann@24728
   644
  done
haftmann@24728
   645
haftmann@24728
   646
lemma setprod_nonzero_nat:
haftmann@24728
   647
    "finite A ==> (\<forall>x \<in> A. f x \<noteq> (0::nat)) ==> setprod f A \<noteq> 0"
haftmann@24728
   648
  by (rule setprod_nonzero, auto)
haftmann@24728
   649
haftmann@24728
   650
lemma setprod_zero_eq_nat:
haftmann@24728
   651
    "finite A ==> (setprod f A = (0::nat)) = (\<exists>x \<in> A. f x = 0)"
haftmann@24728
   652
  by (rule setprod_zero_eq, auto)
haftmann@24728
   653
haftmann@24728
   654
lemma setprod_nonzero_int:
haftmann@24728
   655
    "finite A ==> (\<forall>x \<in> A. f x \<noteq> (0::int)) ==> setprod f A \<noteq> 0"
haftmann@24728
   656
  by (rule setprod_nonzero, auto)
haftmann@24728
   657
haftmann@24728
   658
lemma setprod_zero_eq_int:
haftmann@24728
   659
    "finite A ==> (setprod f A = (0::int)) = (\<exists>x \<in> A. f x = 0)"
haftmann@24728
   660
  by (rule setprod_zero_eq, auto)
haftmann@24728
   661
haftmann@24728
   662
lemmas int_setsum = of_nat_setsum [where 'a=int]
haftmann@24728
   663
lemmas int_setprod = of_nat_setprod [where 'a=int]
haftmann@24728
   664
haftmann@24728
   665
wenzelm@23164
   666
subsection {* Further properties *}
wenzelm@23164
   667
wenzelm@23164
   668
text{*Now we replace the case analysis rule by a more conventional one:
wenzelm@23164
   669
whether an integer is negative or not.*}
wenzelm@23164
   670
huffman@23365
   671
lemma zless_iff_Suc_zadd:
haftmann@24196
   672
  "(w \<Colon> int) < z \<longleftrightarrow> (\<exists>n. z = w + of_nat (Suc n))"
huffman@23303
   673
apply (cases z, cases w)
huffman@23372
   674
apply (auto simp add: less add int_def)
huffman@23303
   675
apply (rename_tac a b c d) 
huffman@23303
   676
apply (rule_tac x="a+d - Suc(c+b)" in exI) 
huffman@23303
   677
apply arith
huffman@23303
   678
done
huffman@23303
   679
haftmann@24196
   680
lemma negD: "(x \<Colon> int) < 0 \<Longrightarrow> \<exists>n. x = - (of_nat (Suc n))"
huffman@23303
   681
apply (cases x)
huffman@23365
   682
apply (auto simp add: le minus Zero_int_def int_def order_less_le)
huffman@23303
   683
apply (rule_tac x="y - Suc x" in exI, arith)
huffman@23303
   684
done
huffman@23303
   685
huffman@23365
   686
theorem int_cases [cases type: int, case_names nonneg neg]:
haftmann@24196
   687
  "[|!! n. (z \<Colon> int) = of_nat n ==> P;  !! n. z =  - (of_nat (Suc n)) ==> P |] ==> P"
huffman@23365
   688
apply (cases "z < 0", blast dest!: negD)
huffman@23303
   689
apply (simp add: linorder_not_less del: of_nat_Suc)
huffman@23365
   690
apply (blast dest: nat_0_le [THEN sym])
huffman@23303
   691
done
huffman@23303
   692
huffman@23372
   693
theorem int_induct [induct type: int, case_names nonneg neg]:
haftmann@24196
   694
     "[|!! n. P (of_nat n \<Colon> int);  !!n. P (- (of_nat (Suc n))) |] ==> P z"
huffman@23365
   695
  by (cases z rule: int_cases) auto
huffman@23303
   696
huffman@23303
   697
text{*Contributed by Brian Huffman*}
wenzelm@25349
   698
theorem int_diff_cases:
wenzelm@25349
   699
  obtains (diff) m n where "(z\<Colon>int) = of_nat m - of_nat n"
huffman@23303
   700
apply (cases z rule: eq_Abs_Integ)
wenzelm@25349
   701
apply (rule_tac m=x and n=y in diff)
huffman@23365
   702
apply (simp add: int_def diff_def minus add)
huffman@23303
   703
done
huffman@23303
   704
huffman@23303
   705
huffman@23365
   706
subsection {* Legacy theorems *}
huffman@23303
   707
wenzelm@25349
   708
lemmas zminus_zminus = minus_minus [of "z::int", standard]
huffman@23372
   709
lemmas zminus_0 = minus_zero [where 'a=int]
wenzelm@25349
   710
lemmas zminus_zadd_distrib = minus_add_distrib [of "z::int" "w", standard]
wenzelm@25349
   711
lemmas zadd_commute = add_commute [of "z::int" "w", standard]
wenzelm@25349
   712
lemmas zadd_assoc = add_assoc [of "z1::int" "z2" "z3", standard]
wenzelm@25349
   713
lemmas zadd_left_commute = add_left_commute [of "x::int" "y" "z", standard]
huffman@23372
   714
lemmas zadd_ac = zadd_assoc zadd_commute zadd_left_commute
huffman@23372
   715
lemmas zmult_ac = OrderedGroup.mult_ac
wenzelm@25349
   716
lemmas zadd_0 = OrderedGroup.add_0_left [of "z::int", standard]
wenzelm@25349
   717
lemmas zadd_0_right = OrderedGroup.add_0_left [of "z::int", standard]
wenzelm@25349
   718
lemmas zadd_zminus_inverse2 = left_minus [of "z::int", standard]
wenzelm@25349
   719
lemmas zmult_zminus = mult_minus_left [of "z::int" "w", standard]
wenzelm@25349
   720
lemmas zmult_commute = mult_commute [of "z::int" "w", standard]
wenzelm@25349
   721
lemmas zmult_assoc = mult_assoc [of "z1::int" "z2" "z3", standard]
wenzelm@25349
   722
lemmas zadd_zmult_distrib = left_distrib [of "z1::int" "z2" "w", standard]
wenzelm@25349
   723
lemmas zadd_zmult_distrib2 = right_distrib [of "w::int" "z1" "z2", standard]
wenzelm@25349
   724
lemmas zdiff_zmult_distrib = left_diff_distrib [of "z1::int" "z2" "w", standard]
wenzelm@25349
   725
lemmas zdiff_zmult_distrib2 = right_diff_distrib [of "w::int" "z1" "z2", standard]
huffman@23303
   726
huffman@23372
   727
lemmas int_distrib =
huffman@23372
   728
  zadd_zmult_distrib zadd_zmult_distrib2
huffman@23372
   729
  zdiff_zmult_distrib zdiff_zmult_distrib2
huffman@23372
   730
wenzelm@25349
   731
lemmas zmult_1 = mult_1_left [of "z::int", standard]
wenzelm@25349
   732
lemmas zmult_1_right = mult_1_right [of "z::int", standard]
huffman@23303
   733
wenzelm@25349
   734
lemmas zle_refl = order_refl [of "w::int", standard]
wenzelm@25349
   735
lemmas zle_trans = order_trans [where 'a=int and x="i" and y="j" and z="k", standard]
wenzelm@25349
   736
lemmas zle_anti_sym = order_antisym [of "z::int" "w", standard]
wenzelm@25349
   737
lemmas zle_linear = linorder_linear [of "z::int" "w", standard]
huffman@23372
   738
lemmas zless_linear = linorder_less_linear [where 'a = int]
huffman@23372
   739
wenzelm@25349
   740
lemmas zadd_left_mono = add_left_mono [of "i::int" "j" "k", standard]
wenzelm@25349
   741
lemmas zadd_strict_right_mono = add_strict_right_mono [of "i::int" "j" "k", standard]
wenzelm@25349
   742
lemmas zadd_zless_mono = add_less_le_mono [of "w'::int" "w" "z'" "z", standard]
huffman@23372
   743
huffman@23372
   744
lemmas int_0_less_1 = zero_less_one [where 'a=int]
huffman@23372
   745
lemmas int_0_neq_1 = zero_neq_one [where 'a=int]
huffman@23303
   746
huffman@23365
   747
lemmas inj_int = inj_of_nat [where 'a=int]
huffman@23365
   748
lemmas int_int_eq = of_nat_eq_iff [where 'a=int]
huffman@23365
   749
lemmas zadd_int = of_nat_add [where 'a=int, symmetric]
huffman@23365
   750
lemmas int_mult = of_nat_mult [where 'a=int]
huffman@23365
   751
lemmas zmult_int = of_nat_mult [where 'a=int, symmetric]
wenzelm@25349
   752
lemmas int_eq_0_conv = of_nat_eq_0_iff [where 'a=int and m="n", standard]
huffman@23365
   753
lemmas zless_int = of_nat_less_iff [where 'a=int]
wenzelm@25349
   754
lemmas int_less_0_conv = of_nat_less_0_iff [where 'a=int and m="k", standard]
huffman@23365
   755
lemmas zero_less_int_conv = of_nat_0_less_iff [where 'a=int]
huffman@23365
   756
lemmas zle_int = of_nat_le_iff [where 'a=int]
huffman@23365
   757
lemmas zero_zle_int = of_nat_0_le_iff [where 'a=int]
wenzelm@25349
   758
lemmas int_le_0_conv = of_nat_le_0_iff [where 'a=int and m="n", standard]
haftmann@24196
   759
lemmas int_0 = of_nat_0 [where 'a=int]
huffman@23365
   760
lemmas int_1 = of_nat_1 [where 'a=int]
haftmann@24196
   761
lemmas int_Suc = of_nat_Suc [where 'a=int]
wenzelm@25349
   762
lemmas abs_int_eq = abs_of_nat [where 'a=int and n="m", standard]
huffman@23365
   763
lemmas of_int_int_eq = of_int_of_nat_eq [where 'a=int]
huffman@23365
   764
lemmas zdiff_int = of_nat_diff [where 'a=int, symmetric]
haftmann@25571
   765
lemmas zless_le = less_int_def
huffman@23365
   766
lemmas int_eq_of_nat = TrueI
wenzelm@23164
   767
huffman@23365
   768
abbreviation
haftmann@24196
   769
  int :: "nat \<Rightarrow> int"
haftmann@24196
   770
where
haftmann@24196
   771
  "int \<equiv> of_nat"
haftmann@24196
   772
wenzelm@23164
   773
end