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