src/HOL/Rings.thy
author haftmann
Wed Feb 10 15:52:12 2010 +0100 (2010-02-10)
changeset 35097 4554bb2abfa3
parent 35092 cfe605c54e50
child 35216 7641e8d831d2
permissions -rw-r--r--
dropped last occurence of the linlinordered accident
haftmann@35050
     1
(*  Title:      HOL/Rings.thy
wenzelm@32960
     2
    Author:     Gertrud Bauer
wenzelm@32960
     3
    Author:     Steven Obua
wenzelm@32960
     4
    Author:     Tobias Nipkow
wenzelm@32960
     5
    Author:     Lawrence C Paulson
wenzelm@32960
     6
    Author:     Markus Wenzel
wenzelm@32960
     7
    Author:     Jeremy Avigad
paulson@14265
     8
*)
paulson@14265
     9
haftmann@35050
    10
header {* Rings *}
paulson@14265
    11
haftmann@35050
    12
theory Rings
haftmann@35050
    13
imports Groups
nipkow@15131
    14
begin
paulson@14504
    15
obua@14738
    16
text {*
obua@14738
    17
  The theory of partially ordered rings is taken from the books:
obua@14738
    18
  \begin{itemize}
obua@14738
    19
  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
obua@14738
    20
  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
obua@14738
    21
  \end{itemize}
obua@14738
    22
  Most of the used notions can also be looked up in 
obua@14738
    23
  \begin{itemize}
wenzelm@14770
    24
  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
obua@14738
    25
  \item \emph{Algebra I} by van der Waerden, Springer.
obua@14738
    26
  \end{itemize}
obua@14738
    27
*}
paulson@14504
    28
haftmann@22390
    29
class semiring = ab_semigroup_add + semigroup_mult +
nipkow@29667
    30
  assumes left_distrib[algebra_simps]: "(a + b) * c = a * c + b * c"
nipkow@29667
    31
  assumes right_distrib[algebra_simps]: "a * (b + c) = a * b + a * c"
haftmann@25152
    32
begin
haftmann@25152
    33
haftmann@25152
    34
text{*For the @{text combine_numerals} simproc*}
haftmann@25152
    35
lemma combine_common_factor:
haftmann@25152
    36
  "a * e + (b * e + c) = (a + b) * e + c"
nipkow@29667
    37
by (simp add: left_distrib add_ac)
haftmann@25152
    38
haftmann@25152
    39
end
paulson@14504
    40
haftmann@22390
    41
class mult_zero = times + zero +
haftmann@25062
    42
  assumes mult_zero_left [simp]: "0 * a = 0"
haftmann@25062
    43
  assumes mult_zero_right [simp]: "a * 0 = 0"
krauss@21199
    44
haftmann@22390
    45
class semiring_0 = semiring + comm_monoid_add + mult_zero
krauss@21199
    46
huffman@29904
    47
class semiring_0_cancel = semiring + cancel_comm_monoid_add
haftmann@25186
    48
begin
paulson@14504
    49
haftmann@25186
    50
subclass semiring_0
haftmann@28823
    51
proof
krauss@21199
    52
  fix a :: 'a
nipkow@29667
    53
  have "0 * a + 0 * a = 0 * a + 0" by (simp add: left_distrib [symmetric])
nipkow@29667
    54
  thus "0 * a = 0" by (simp only: add_left_cancel)
haftmann@25152
    55
next
haftmann@25152
    56
  fix a :: 'a
nipkow@29667
    57
  have "a * 0 + a * 0 = a * 0 + 0" by (simp add: right_distrib [symmetric])
nipkow@29667
    58
  thus "a * 0 = 0" by (simp only: add_left_cancel)
krauss@21199
    59
qed
obua@14940
    60
haftmann@25186
    61
end
haftmann@25152
    62
haftmann@22390
    63
class comm_semiring = ab_semigroup_add + ab_semigroup_mult +
haftmann@25062
    64
  assumes distrib: "(a + b) * c = a * c + b * c"
haftmann@25152
    65
begin
paulson@14504
    66
haftmann@25152
    67
subclass semiring
haftmann@28823
    68
proof
obua@14738
    69
  fix a b c :: 'a
obua@14738
    70
  show "(a + b) * c = a * c + b * c" by (simp add: distrib)
obua@14738
    71
  have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
obua@14738
    72
  also have "... = b * a + c * a" by (simp only: distrib)
obua@14738
    73
  also have "... = a * b + a * c" by (simp add: mult_ac)
obua@14738
    74
  finally show "a * (b + c) = a * b + a * c" by blast
paulson@14504
    75
qed
paulson@14504
    76
haftmann@25152
    77
end
paulson@14504
    78
haftmann@25152
    79
class comm_semiring_0 = comm_semiring + comm_monoid_add + mult_zero
haftmann@25152
    80
begin
haftmann@25152
    81
huffman@27516
    82
subclass semiring_0 ..
haftmann@25152
    83
haftmann@25152
    84
end
paulson@14504
    85
huffman@29904
    86
class comm_semiring_0_cancel = comm_semiring + cancel_comm_monoid_add
haftmann@25186
    87
begin
obua@14940
    88
huffman@27516
    89
subclass semiring_0_cancel ..
obua@14940
    90
huffman@28141
    91
subclass comm_semiring_0 ..
huffman@28141
    92
haftmann@25186
    93
end
krauss@21199
    94
haftmann@22390
    95
class zero_neq_one = zero + one +
haftmann@25062
    96
  assumes zero_neq_one [simp]: "0 \<noteq> 1"
haftmann@26193
    97
begin
haftmann@26193
    98
haftmann@26193
    99
lemma one_neq_zero [simp]: "1 \<noteq> 0"
nipkow@29667
   100
by (rule not_sym) (rule zero_neq_one)
haftmann@26193
   101
haftmann@26193
   102
end
paulson@14265
   103
haftmann@22390
   104
class semiring_1 = zero_neq_one + semiring_0 + monoid_mult
paulson@14504
   105
haftmann@27651
   106
text {* Abstract divisibility *}
haftmann@27651
   107
haftmann@27651
   108
class dvd = times
haftmann@27651
   109
begin
haftmann@27651
   110
haftmann@28559
   111
definition dvd :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "dvd" 50) where
haftmann@28559
   112
  [code del]: "b dvd a \<longleftrightarrow> (\<exists>k. a = b * k)"
haftmann@27651
   113
haftmann@27651
   114
lemma dvdI [intro?]: "a = b * k \<Longrightarrow> b dvd a"
haftmann@27651
   115
  unfolding dvd_def ..
haftmann@27651
   116
haftmann@27651
   117
lemma dvdE [elim?]: "b dvd a \<Longrightarrow> (\<And>k. a = b * k \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@27651
   118
  unfolding dvd_def by blast 
haftmann@27651
   119
haftmann@27651
   120
end
haftmann@27651
   121
haftmann@27651
   122
class comm_semiring_1 = zero_neq_one + comm_semiring_0 + comm_monoid_mult + dvd
haftmann@22390
   123
  (*previously almost_semiring*)
haftmann@25152
   124
begin
obua@14738
   125
huffman@27516
   126
subclass semiring_1 ..
haftmann@25152
   127
nipkow@29925
   128
lemma dvd_refl[simp]: "a dvd a"
haftmann@28559
   129
proof
haftmann@28559
   130
  show "a = a * 1" by simp
haftmann@27651
   131
qed
haftmann@27651
   132
haftmann@27651
   133
lemma dvd_trans:
haftmann@27651
   134
  assumes "a dvd b" and "b dvd c"
haftmann@27651
   135
  shows "a dvd c"
haftmann@27651
   136
proof -
haftmann@28559
   137
  from assms obtain v where "b = a * v" by (auto elim!: dvdE)
haftmann@28559
   138
  moreover from assms obtain w where "c = b * w" by (auto elim!: dvdE)
haftmann@27651
   139
  ultimately have "c = a * (v * w)" by (simp add: mult_assoc)
haftmann@28559
   140
  then show ?thesis ..
haftmann@27651
   141
qed
haftmann@27651
   142
haftmann@27651
   143
lemma dvd_0_left_iff [noatp, simp]: "0 dvd a \<longleftrightarrow> a = 0"
nipkow@29667
   144
by (auto intro: dvd_refl elim!: dvdE)
haftmann@28559
   145
haftmann@28559
   146
lemma dvd_0_right [iff]: "a dvd 0"
haftmann@28559
   147
proof
haftmann@27651
   148
  show "0 = a * 0" by simp
haftmann@27651
   149
qed
haftmann@27651
   150
haftmann@27651
   151
lemma one_dvd [simp]: "1 dvd a"
nipkow@29667
   152
by (auto intro!: dvdI)
haftmann@27651
   153
nipkow@30042
   154
lemma dvd_mult[simp]: "a dvd c \<Longrightarrow> a dvd (b * c)"
nipkow@29667
   155
by (auto intro!: mult_left_commute dvdI elim!: dvdE)
haftmann@27651
   156
nipkow@30042
   157
lemma dvd_mult2[simp]: "a dvd b \<Longrightarrow> a dvd (b * c)"
haftmann@27651
   158
  apply (subst mult_commute)
haftmann@27651
   159
  apply (erule dvd_mult)
haftmann@27651
   160
  done
haftmann@27651
   161
haftmann@27651
   162
lemma dvd_triv_right [simp]: "a dvd b * a"
nipkow@29667
   163
by (rule dvd_mult) (rule dvd_refl)
haftmann@27651
   164
haftmann@27651
   165
lemma dvd_triv_left [simp]: "a dvd a * b"
nipkow@29667
   166
by (rule dvd_mult2) (rule dvd_refl)
haftmann@27651
   167
haftmann@27651
   168
lemma mult_dvd_mono:
nipkow@30042
   169
  assumes "a dvd b"
nipkow@30042
   170
    and "c dvd d"
haftmann@27651
   171
  shows "a * c dvd b * d"
haftmann@27651
   172
proof -
nipkow@30042
   173
  from `a dvd b` obtain b' where "b = a * b'" ..
nipkow@30042
   174
  moreover from `c dvd d` obtain d' where "d = c * d'" ..
haftmann@27651
   175
  ultimately have "b * d = (a * c) * (b' * d')" by (simp add: mult_ac)
haftmann@27651
   176
  then show ?thesis ..
haftmann@27651
   177
qed
haftmann@27651
   178
haftmann@27651
   179
lemma dvd_mult_left: "a * b dvd c \<Longrightarrow> a dvd c"
nipkow@29667
   180
by (simp add: dvd_def mult_assoc, blast)
haftmann@27651
   181
haftmann@27651
   182
lemma dvd_mult_right: "a * b dvd c \<Longrightarrow> b dvd c"
haftmann@27651
   183
  unfolding mult_ac [of a] by (rule dvd_mult_left)
haftmann@27651
   184
haftmann@27651
   185
lemma dvd_0_left: "0 dvd a \<Longrightarrow> a = 0"
nipkow@29667
   186
by simp
haftmann@27651
   187
nipkow@29925
   188
lemma dvd_add[simp]:
nipkow@29925
   189
  assumes "a dvd b" and "a dvd c" shows "a dvd (b + c)"
haftmann@27651
   190
proof -
nipkow@29925
   191
  from `a dvd b` obtain b' where "b = a * b'" ..
nipkow@29925
   192
  moreover from `a dvd c` obtain c' where "c = a * c'" ..
haftmann@27651
   193
  ultimately have "b + c = a * (b' + c')" by (simp add: right_distrib)
haftmann@27651
   194
  then show ?thesis ..
haftmann@27651
   195
qed
haftmann@27651
   196
haftmann@25152
   197
end
paulson@14421
   198
nipkow@29925
   199
haftmann@22390
   200
class no_zero_divisors = zero + times +
haftmann@25062
   201
  assumes no_zero_divisors: "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a * b \<noteq> 0"
paulson@14504
   202
huffman@29904
   203
class semiring_1_cancel = semiring + cancel_comm_monoid_add
huffman@29904
   204
  + zero_neq_one + monoid_mult
haftmann@25267
   205
begin
obua@14940
   206
huffman@27516
   207
subclass semiring_0_cancel ..
haftmann@25512
   208
huffman@27516
   209
subclass semiring_1 ..
haftmann@25267
   210
haftmann@25267
   211
end
krauss@21199
   212
huffman@29904
   213
class comm_semiring_1_cancel = comm_semiring + cancel_comm_monoid_add
huffman@29904
   214
  + zero_neq_one + comm_monoid_mult
haftmann@25267
   215
begin
obua@14738
   216
huffman@27516
   217
subclass semiring_1_cancel ..
huffman@27516
   218
subclass comm_semiring_0_cancel ..
huffman@27516
   219
subclass comm_semiring_1 ..
haftmann@25267
   220
haftmann@25267
   221
end
haftmann@25152
   222
haftmann@22390
   223
class ring = semiring + ab_group_add
haftmann@25267
   224
begin
haftmann@25152
   225
huffman@27516
   226
subclass semiring_0_cancel ..
haftmann@25152
   227
haftmann@25152
   228
text {* Distribution rules *}
haftmann@25152
   229
haftmann@25152
   230
lemma minus_mult_left: "- (a * b) = - a * b"
huffman@34146
   231
by (rule minus_unique) (simp add: left_distrib [symmetric]) 
haftmann@25152
   232
haftmann@25152
   233
lemma minus_mult_right: "- (a * b) = a * - b"
huffman@34146
   234
by (rule minus_unique) (simp add: right_distrib [symmetric]) 
haftmann@25152
   235
huffman@29407
   236
text{*Extract signs from products*}
nipkow@29833
   237
lemmas mult_minus_left [simp, noatp] = minus_mult_left [symmetric]
nipkow@29833
   238
lemmas mult_minus_right [simp,noatp] = minus_mult_right [symmetric]
huffman@29407
   239
haftmann@25152
   240
lemma minus_mult_minus [simp]: "- a * - b = a * b"
nipkow@29667
   241
by simp
haftmann@25152
   242
haftmann@25152
   243
lemma minus_mult_commute: "- a * b = a * - b"
nipkow@29667
   244
by simp
nipkow@29667
   245
nipkow@29667
   246
lemma right_diff_distrib[algebra_simps]: "a * (b - c) = a * b - a * c"
nipkow@29667
   247
by (simp add: right_distrib diff_minus)
nipkow@29667
   248
nipkow@29667
   249
lemma left_diff_distrib[algebra_simps]: "(a - b) * c = a * c - b * c"
nipkow@29667
   250
by (simp add: left_distrib diff_minus)
haftmann@25152
   251
nipkow@29833
   252
lemmas ring_distribs[noatp] =
haftmann@25152
   253
  right_distrib left_distrib left_diff_distrib right_diff_distrib
haftmann@25152
   254
nipkow@29667
   255
text{*Legacy - use @{text algebra_simps} *}
nipkow@29833
   256
lemmas ring_simps[noatp] = algebra_simps
haftmann@25230
   257
haftmann@25230
   258
lemma eq_add_iff1:
haftmann@25230
   259
  "a * e + c = b * e + d \<longleftrightarrow> (a - b) * e + c = d"
nipkow@29667
   260
by (simp add: algebra_simps)
haftmann@25230
   261
haftmann@25230
   262
lemma eq_add_iff2:
haftmann@25230
   263
  "a * e + c = b * e + d \<longleftrightarrow> c = (b - a) * e + d"
nipkow@29667
   264
by (simp add: algebra_simps)
haftmann@25230
   265
haftmann@25152
   266
end
haftmann@25152
   267
nipkow@29833
   268
lemmas ring_distribs[noatp] =
haftmann@25152
   269
  right_distrib left_distrib left_diff_distrib right_diff_distrib
haftmann@25152
   270
haftmann@22390
   271
class comm_ring = comm_semiring + ab_group_add
haftmann@25267
   272
begin
obua@14738
   273
huffman@27516
   274
subclass ring ..
huffman@28141
   275
subclass comm_semiring_0_cancel ..
haftmann@25267
   276
haftmann@25267
   277
end
obua@14738
   278
haftmann@22390
   279
class ring_1 = ring + zero_neq_one + monoid_mult
haftmann@25267
   280
begin
paulson@14265
   281
huffman@27516
   282
subclass semiring_1_cancel ..
haftmann@25267
   283
haftmann@25267
   284
end
haftmann@25152
   285
haftmann@22390
   286
class comm_ring_1 = comm_ring + zero_neq_one + comm_monoid_mult
haftmann@22390
   287
  (*previously ring*)
haftmann@25267
   288
begin
obua@14738
   289
huffman@27516
   290
subclass ring_1 ..
huffman@27516
   291
subclass comm_semiring_1_cancel ..
haftmann@25267
   292
huffman@29465
   293
lemma dvd_minus_iff [simp]: "x dvd - y \<longleftrightarrow> x dvd y"
huffman@29408
   294
proof
huffman@29408
   295
  assume "x dvd - y"
huffman@29408
   296
  then have "x dvd - 1 * - y" by (rule dvd_mult)
huffman@29408
   297
  then show "x dvd y" by simp
huffman@29408
   298
next
huffman@29408
   299
  assume "x dvd y"
huffman@29408
   300
  then have "x dvd - 1 * y" by (rule dvd_mult)
huffman@29408
   301
  then show "x dvd - y" by simp
huffman@29408
   302
qed
huffman@29408
   303
huffman@29465
   304
lemma minus_dvd_iff [simp]: "- x dvd y \<longleftrightarrow> x dvd y"
huffman@29408
   305
proof
huffman@29408
   306
  assume "- x dvd y"
huffman@29408
   307
  then obtain k where "y = - x * k" ..
huffman@29408
   308
  then have "y = x * - k" by simp
huffman@29408
   309
  then show "x dvd y" ..
huffman@29408
   310
next
huffman@29408
   311
  assume "x dvd y"
huffman@29408
   312
  then obtain k where "y = x * k" ..
huffman@29408
   313
  then have "y = - x * - k" by simp
huffman@29408
   314
  then show "- x dvd y" ..
huffman@29408
   315
qed
huffman@29408
   316
nipkow@30042
   317
lemma dvd_diff[simp]: "x dvd y \<Longrightarrow> x dvd z \<Longrightarrow> x dvd (y - z)"
nipkow@30042
   318
by (simp add: diff_minus dvd_minus_iff)
huffman@29409
   319
haftmann@25267
   320
end
haftmann@25152
   321
huffman@22990
   322
class ring_no_zero_divisors = ring + no_zero_divisors
haftmann@25230
   323
begin
haftmann@25230
   324
haftmann@25230
   325
lemma mult_eq_0_iff [simp]:
haftmann@25230
   326
  shows "a * b = 0 \<longleftrightarrow> (a = 0 \<or> b = 0)"
haftmann@25230
   327
proof (cases "a = 0 \<or> b = 0")
haftmann@25230
   328
  case False then have "a \<noteq> 0" and "b \<noteq> 0" by auto
haftmann@25230
   329
    then show ?thesis using no_zero_divisors by simp
haftmann@25230
   330
next
haftmann@25230
   331
  case True then show ?thesis by auto
haftmann@25230
   332
qed
haftmann@25230
   333
haftmann@26193
   334
text{*Cancellation of equalities with a common factor*}
haftmann@26193
   335
lemma mult_cancel_right [simp, noatp]:
haftmann@26193
   336
  "a * c = b * c \<longleftrightarrow> c = 0 \<or> a = b"
haftmann@26193
   337
proof -
haftmann@26193
   338
  have "(a * c = b * c) = ((a - b) * c = 0)"
nipkow@29667
   339
    by (simp add: algebra_simps right_minus_eq)
nipkow@29667
   340
  thus ?thesis by (simp add: disj_commute right_minus_eq)
haftmann@26193
   341
qed
haftmann@26193
   342
haftmann@26193
   343
lemma mult_cancel_left [simp, noatp]:
haftmann@26193
   344
  "c * a = c * b \<longleftrightarrow> c = 0 \<or> a = b"
haftmann@26193
   345
proof -
haftmann@26193
   346
  have "(c * a = c * b) = (c * (a - b) = 0)"
nipkow@29667
   347
    by (simp add: algebra_simps right_minus_eq)
nipkow@29667
   348
  thus ?thesis by (simp add: right_minus_eq)
haftmann@26193
   349
qed
haftmann@26193
   350
haftmann@25230
   351
end
huffman@22990
   352
huffman@23544
   353
class ring_1_no_zero_divisors = ring_1 + ring_no_zero_divisors
haftmann@26274
   354
begin
haftmann@26274
   355
haftmann@26274
   356
lemma mult_cancel_right1 [simp]:
haftmann@26274
   357
  "c = b * c \<longleftrightarrow> c = 0 \<or> b = 1"
nipkow@29667
   358
by (insert mult_cancel_right [of 1 c b], force)
haftmann@26274
   359
haftmann@26274
   360
lemma mult_cancel_right2 [simp]:
haftmann@26274
   361
  "a * c = c \<longleftrightarrow> c = 0 \<or> a = 1"
nipkow@29667
   362
by (insert mult_cancel_right [of a c 1], simp)
haftmann@26274
   363
 
haftmann@26274
   364
lemma mult_cancel_left1 [simp]:
haftmann@26274
   365
  "c = c * b \<longleftrightarrow> c = 0 \<or> b = 1"
nipkow@29667
   366
by (insert mult_cancel_left [of c 1 b], force)
haftmann@26274
   367
haftmann@26274
   368
lemma mult_cancel_left2 [simp]:
haftmann@26274
   369
  "c * a = c \<longleftrightarrow> c = 0 \<or> a = 1"
nipkow@29667
   370
by (insert mult_cancel_left [of c a 1], simp)
haftmann@26274
   371
haftmann@26274
   372
end
huffman@22990
   373
haftmann@22390
   374
class idom = comm_ring_1 + no_zero_divisors
haftmann@25186
   375
begin
paulson@14421
   376
huffman@27516
   377
subclass ring_1_no_zero_divisors ..
huffman@22990
   378
huffman@29915
   379
lemma square_eq_iff: "a * a = b * b \<longleftrightarrow> (a = b \<or> a = - b)"
huffman@29915
   380
proof
huffman@29915
   381
  assume "a * a = b * b"
huffman@29915
   382
  then have "(a - b) * (a + b) = 0"
huffman@29915
   383
    by (simp add: algebra_simps)
huffman@29915
   384
  then show "a = b \<or> a = - b"
huffman@29915
   385
    by (simp add: right_minus_eq eq_neg_iff_add_eq_0)
huffman@29915
   386
next
huffman@29915
   387
  assume "a = b \<or> a = - b"
huffman@29915
   388
  then show "a * a = b * b" by auto
huffman@29915
   389
qed
huffman@29915
   390
huffman@29981
   391
lemma dvd_mult_cancel_right [simp]:
huffman@29981
   392
  "a * c dvd b * c \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   393
proof -
huffman@29981
   394
  have "a * c dvd b * c \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
huffman@29981
   395
    unfolding dvd_def by (simp add: mult_ac)
huffman@29981
   396
  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   397
    unfolding dvd_def by simp
huffman@29981
   398
  finally show ?thesis .
huffman@29981
   399
qed
huffman@29981
   400
huffman@29981
   401
lemma dvd_mult_cancel_left [simp]:
huffman@29981
   402
  "c * a dvd c * b \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   403
proof -
huffman@29981
   404
  have "c * a dvd c * b \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
huffman@29981
   405
    unfolding dvd_def by (simp add: mult_ac)
huffman@29981
   406
  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   407
    unfolding dvd_def by simp
huffman@29981
   408
  finally show ?thesis .
huffman@29981
   409
qed
huffman@29981
   410
haftmann@25186
   411
end
haftmann@25152
   412
haftmann@35083
   413
class inverse =
haftmann@35083
   414
  fixes inverse :: "'a \<Rightarrow> 'a"
haftmann@35083
   415
    and divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "'/" 70)
haftmann@35083
   416
haftmann@22390
   417
class division_ring = ring_1 + inverse +
haftmann@25062
   418
  assumes left_inverse [simp]:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
haftmann@25062
   419
  assumes right_inverse [simp]: "a \<noteq> 0 \<Longrightarrow> a * inverse a = 1"
haftmann@35083
   420
  assumes divide_inverse: "a / b = a * inverse b"
haftmann@25186
   421
begin
huffman@20496
   422
haftmann@25186
   423
subclass ring_1_no_zero_divisors
haftmann@28823
   424
proof
huffman@22987
   425
  fix a b :: 'a
huffman@22987
   426
  assume a: "a \<noteq> 0" and b: "b \<noteq> 0"
huffman@22987
   427
  show "a * b \<noteq> 0"
huffman@22987
   428
  proof
huffman@22987
   429
    assume ab: "a * b = 0"
nipkow@29667
   430
    hence "0 = inverse a * (a * b) * inverse b" by simp
huffman@22987
   431
    also have "\<dots> = (inverse a * a) * (b * inverse b)"
huffman@22987
   432
      by (simp only: mult_assoc)
nipkow@29667
   433
    also have "\<dots> = 1" using a b by simp
nipkow@29667
   434
    finally show False by simp
huffman@22987
   435
  qed
huffman@22987
   436
qed
huffman@20496
   437
haftmann@26274
   438
lemma nonzero_imp_inverse_nonzero:
haftmann@26274
   439
  "a \<noteq> 0 \<Longrightarrow> inverse a \<noteq> 0"
haftmann@26274
   440
proof
haftmann@26274
   441
  assume ianz: "inverse a = 0"
haftmann@26274
   442
  assume "a \<noteq> 0"
haftmann@26274
   443
  hence "1 = a * inverse a" by simp
haftmann@26274
   444
  also have "... = 0" by (simp add: ianz)
haftmann@26274
   445
  finally have "1 = 0" .
haftmann@26274
   446
  thus False by (simp add: eq_commute)
haftmann@26274
   447
qed
haftmann@26274
   448
haftmann@26274
   449
lemma inverse_zero_imp_zero:
haftmann@26274
   450
  "inverse a = 0 \<Longrightarrow> a = 0"
haftmann@26274
   451
apply (rule classical)
haftmann@26274
   452
apply (drule nonzero_imp_inverse_nonzero)
haftmann@26274
   453
apply auto
haftmann@26274
   454
done
haftmann@26274
   455
haftmann@26274
   456
lemma inverse_unique: 
haftmann@26274
   457
  assumes ab: "a * b = 1"
haftmann@26274
   458
  shows "inverse a = b"
haftmann@26274
   459
proof -
haftmann@26274
   460
  have "a \<noteq> 0" using ab by (cases "a = 0") simp_all
huffman@29406
   461
  moreover have "inverse a * (a * b) = inverse a" by (simp add: ab)
huffman@29406
   462
  ultimately show ?thesis by (simp add: mult_assoc [symmetric])
haftmann@26274
   463
qed
haftmann@26274
   464
huffman@29406
   465
lemma nonzero_inverse_minus_eq:
huffman@29406
   466
  "a \<noteq> 0 \<Longrightarrow> inverse (- a) = - inverse a"
nipkow@29667
   467
by (rule inverse_unique) simp
huffman@29406
   468
huffman@29406
   469
lemma nonzero_inverse_inverse_eq:
huffman@29406
   470
  "a \<noteq> 0 \<Longrightarrow> inverse (inverse a) = a"
nipkow@29667
   471
by (rule inverse_unique) simp
huffman@29406
   472
huffman@29406
   473
lemma nonzero_inverse_eq_imp_eq:
huffman@29406
   474
  assumes "inverse a = inverse b" and "a \<noteq> 0" and "b \<noteq> 0"
huffman@29406
   475
  shows "a = b"
huffman@29406
   476
proof -
huffman@29406
   477
  from `inverse a = inverse b`
nipkow@29667
   478
  have "inverse (inverse a) = inverse (inverse b)" by (rule arg_cong)
huffman@29406
   479
  with `a \<noteq> 0` and `b \<noteq> 0` show "a = b"
huffman@29406
   480
    by (simp add: nonzero_inverse_inverse_eq)
huffman@29406
   481
qed
huffman@29406
   482
huffman@29406
   483
lemma inverse_1 [simp]: "inverse 1 = 1"
nipkow@29667
   484
by (rule inverse_unique) simp
huffman@29406
   485
haftmann@26274
   486
lemma nonzero_inverse_mult_distrib: 
huffman@29406
   487
  assumes "a \<noteq> 0" and "b \<noteq> 0"
haftmann@26274
   488
  shows "inverse (a * b) = inverse b * inverse a"
haftmann@26274
   489
proof -
nipkow@29667
   490
  have "a * (b * inverse b) * inverse a = 1" using assms by simp
nipkow@29667
   491
  hence "a * b * (inverse b * inverse a) = 1" by (simp only: mult_assoc)
nipkow@29667
   492
  thus ?thesis by (rule inverse_unique)
haftmann@26274
   493
qed
haftmann@26274
   494
haftmann@26274
   495
lemma division_ring_inverse_add:
haftmann@26274
   496
  "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a + inverse b = inverse a * (a + b) * inverse b"
nipkow@29667
   497
by (simp add: algebra_simps)
haftmann@26274
   498
haftmann@26274
   499
lemma division_ring_inverse_diff:
haftmann@26274
   500
  "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a - inverse b = inverse a * (b - a) * inverse b"
nipkow@29667
   501
by (simp add: algebra_simps)
haftmann@26274
   502
haftmann@25186
   503
end
haftmann@25152
   504
haftmann@22390
   505
class mult_mono = times + zero + ord +
haftmann@25062
   506
  assumes mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
haftmann@25062
   507
  assumes mult_right_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c"
paulson@14267
   508
haftmann@35028
   509
class ordered_semiring = mult_mono + semiring_0 + ordered_ab_semigroup_add 
haftmann@25230
   510
begin
haftmann@25230
   511
haftmann@25230
   512
lemma mult_mono:
haftmann@25230
   513
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> c
haftmann@25230
   514
     \<Longrightarrow> a * c \<le> b * d"
haftmann@25230
   515
apply (erule mult_right_mono [THEN order_trans], assumption)
haftmann@25230
   516
apply (erule mult_left_mono, assumption)
haftmann@25230
   517
done
haftmann@25230
   518
haftmann@25230
   519
lemma mult_mono':
haftmann@25230
   520
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> a \<Longrightarrow> 0 \<le> c
haftmann@25230
   521
     \<Longrightarrow> a * c \<le> b * d"
haftmann@25230
   522
apply (rule mult_mono)
haftmann@25230
   523
apply (fast intro: order_trans)+
haftmann@25230
   524
done
haftmann@25230
   525
haftmann@25230
   526
end
krauss@21199
   527
haftmann@35028
   528
class ordered_cancel_semiring = mult_mono + ordered_ab_semigroup_add
huffman@29904
   529
  + semiring + cancel_comm_monoid_add
haftmann@25267
   530
begin
paulson@14268
   531
huffman@27516
   532
subclass semiring_0_cancel ..
haftmann@35028
   533
subclass ordered_semiring ..
obua@23521
   534
haftmann@25230
   535
lemma mult_nonneg_nonneg: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a * b"
huffman@30692
   536
using mult_left_mono [of zero b a] by simp
haftmann@25230
   537
haftmann@25230
   538
lemma mult_nonneg_nonpos: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> a * b \<le> 0"
huffman@30692
   539
using mult_left_mono [of b zero a] by simp
huffman@30692
   540
huffman@30692
   541
lemma mult_nonpos_nonneg: "a \<le> 0 \<Longrightarrow> 0 \<le> b \<Longrightarrow> a * b \<le> 0"
huffman@30692
   542
using mult_right_mono [of a zero b] by simp
huffman@30692
   543
huffman@30692
   544
text {* Legacy - use @{text mult_nonpos_nonneg} *}
haftmann@25230
   545
lemma mult_nonneg_nonpos2: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> b * a \<le> 0" 
nipkow@29667
   546
by (drule mult_right_mono [of b zero], auto)
haftmann@25230
   547
haftmann@26234
   548
lemma split_mult_neg_le: "(0 \<le> a & b \<le> 0) | (a \<le> 0 & 0 \<le> b) \<Longrightarrow> a * b \<le> 0" 
nipkow@29667
   549
by (auto simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)
haftmann@25230
   550
haftmann@25230
   551
end
haftmann@25230
   552
haftmann@35028
   553
class linordered_semiring = semiring + comm_monoid_add + linordered_cancel_ab_semigroup_add + mult_mono
haftmann@25267
   554
begin
haftmann@25230
   555
haftmann@35028
   556
subclass ordered_cancel_semiring ..
haftmann@35028
   557
haftmann@35028
   558
subclass ordered_comm_monoid_add ..
haftmann@25304
   559
haftmann@25230
   560
lemma mult_left_less_imp_less:
haftmann@25230
   561
  "c * a < c * b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
nipkow@29667
   562
by (force simp add: mult_left_mono not_le [symmetric])
haftmann@25230
   563
 
haftmann@25230
   564
lemma mult_right_less_imp_less:
haftmann@25230
   565
  "a * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
nipkow@29667
   566
by (force simp add: mult_right_mono not_le [symmetric])
obua@23521
   567
haftmann@25186
   568
end
haftmann@25152
   569
haftmann@35043
   570
class linordered_semiring_1 = linordered_semiring + semiring_1
haftmann@35043
   571
haftmann@35043
   572
class linordered_semiring_strict = semiring + comm_monoid_add + linordered_cancel_ab_semigroup_add +
haftmann@25062
   573
  assumes mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
haftmann@25062
   574
  assumes mult_strict_right_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> a * c < b * c"
haftmann@25267
   575
begin
paulson@14341
   576
huffman@27516
   577
subclass semiring_0_cancel ..
obua@14940
   578
haftmann@35028
   579
subclass linordered_semiring
haftmann@28823
   580
proof
huffman@23550
   581
  fix a b c :: 'a
huffman@23550
   582
  assume A: "a \<le> b" "0 \<le> c"
huffman@23550
   583
  from A show "c * a \<le> c * b"
haftmann@25186
   584
    unfolding le_less
haftmann@25186
   585
    using mult_strict_left_mono by (cases "c = 0") auto
huffman@23550
   586
  from A show "a * c \<le> b * c"
haftmann@25152
   587
    unfolding le_less
haftmann@25186
   588
    using mult_strict_right_mono by (cases "c = 0") auto
haftmann@25152
   589
qed
haftmann@25152
   590
haftmann@25230
   591
lemma mult_left_le_imp_le:
haftmann@25230
   592
  "c * a \<le> c * b \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
nipkow@29667
   593
by (force simp add: mult_strict_left_mono _not_less [symmetric])
haftmann@25230
   594
 
haftmann@25230
   595
lemma mult_right_le_imp_le:
haftmann@25230
   596
  "a * c \<le> b * c \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
nipkow@29667
   597
by (force simp add: mult_strict_right_mono not_less [symmetric])
haftmann@25230
   598
huffman@30692
   599
lemma mult_pos_pos: "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> 0 < a * b"
huffman@30692
   600
using mult_strict_left_mono [of zero b a] by simp
huffman@30692
   601
huffman@30692
   602
lemma mult_pos_neg: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> a * b < 0"
huffman@30692
   603
using mult_strict_left_mono [of b zero a] by simp
huffman@30692
   604
huffman@30692
   605
lemma mult_neg_pos: "a < 0 \<Longrightarrow> 0 < b \<Longrightarrow> a * b < 0"
huffman@30692
   606
using mult_strict_right_mono [of a zero b] by simp
huffman@30692
   607
huffman@30692
   608
text {* Legacy - use @{text mult_neg_pos} *}
huffman@30692
   609
lemma mult_pos_neg2: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> b * a < 0" 
nipkow@29667
   610
by (drule mult_strict_right_mono [of b zero], auto)
haftmann@25230
   611
haftmann@25230
   612
lemma zero_less_mult_pos:
haftmann@25230
   613
  "0 < a * b \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
huffman@30692
   614
apply (cases "b\<le>0")
haftmann@25230
   615
 apply (auto simp add: le_less not_less)
huffman@30692
   616
apply (drule_tac mult_pos_neg [of a b])
haftmann@25230
   617
 apply (auto dest: less_not_sym)
haftmann@25230
   618
done
haftmann@25230
   619
haftmann@25230
   620
lemma zero_less_mult_pos2:
haftmann@25230
   621
  "0 < b * a \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
huffman@30692
   622
apply (cases "b\<le>0")
haftmann@25230
   623
 apply (auto simp add: le_less not_less)
huffman@30692
   624
apply (drule_tac mult_pos_neg2 [of a b])
haftmann@25230
   625
 apply (auto dest: less_not_sym)
haftmann@25230
   626
done
haftmann@25230
   627
haftmann@26193
   628
text{*Strict monotonicity in both arguments*}
haftmann@26193
   629
lemma mult_strict_mono:
haftmann@26193
   630
  assumes "a < b" and "c < d" and "0 < b" and "0 \<le> c"
haftmann@26193
   631
  shows "a * c < b * d"
haftmann@26193
   632
  using assms apply (cases "c=0")
huffman@30692
   633
  apply (simp add: mult_pos_pos)
haftmann@26193
   634
  apply (erule mult_strict_right_mono [THEN less_trans])
huffman@30692
   635
  apply (force simp add: le_less)
haftmann@26193
   636
  apply (erule mult_strict_left_mono, assumption)
haftmann@26193
   637
  done
haftmann@26193
   638
haftmann@26193
   639
text{*This weaker variant has more natural premises*}
haftmann@26193
   640
lemma mult_strict_mono':
haftmann@26193
   641
  assumes "a < b" and "c < d" and "0 \<le> a" and "0 \<le> c"
haftmann@26193
   642
  shows "a * c < b * d"
nipkow@29667
   643
by (rule mult_strict_mono) (insert assms, auto)
haftmann@26193
   644
haftmann@26193
   645
lemma mult_less_le_imp_less:
haftmann@26193
   646
  assumes "a < b" and "c \<le> d" and "0 \<le> a" and "0 < c"
haftmann@26193
   647
  shows "a * c < b * d"
haftmann@26193
   648
  using assms apply (subgoal_tac "a * c < b * c")
haftmann@26193
   649
  apply (erule less_le_trans)
haftmann@26193
   650
  apply (erule mult_left_mono)
haftmann@26193
   651
  apply simp
haftmann@26193
   652
  apply (erule mult_strict_right_mono)
haftmann@26193
   653
  apply assumption
haftmann@26193
   654
  done
haftmann@26193
   655
haftmann@26193
   656
lemma mult_le_less_imp_less:
haftmann@26193
   657
  assumes "a \<le> b" and "c < d" and "0 < a" and "0 \<le> c"
haftmann@26193
   658
  shows "a * c < b * d"
haftmann@26193
   659
  using assms apply (subgoal_tac "a * c \<le> b * c")
haftmann@26193
   660
  apply (erule le_less_trans)
haftmann@26193
   661
  apply (erule mult_strict_left_mono)
haftmann@26193
   662
  apply simp
haftmann@26193
   663
  apply (erule mult_right_mono)
haftmann@26193
   664
  apply simp
haftmann@26193
   665
  done
haftmann@26193
   666
haftmann@26193
   667
lemma mult_less_imp_less_left:
haftmann@26193
   668
  assumes less: "c * a < c * b" and nonneg: "0 \<le> c"
haftmann@26193
   669
  shows "a < b"
haftmann@26193
   670
proof (rule ccontr)
haftmann@26193
   671
  assume "\<not>  a < b"
haftmann@26193
   672
  hence "b \<le> a" by (simp add: linorder_not_less)
haftmann@26193
   673
  hence "c * b \<le> c * a" using nonneg by (rule mult_left_mono)
nipkow@29667
   674
  with this and less show False by (simp add: not_less [symmetric])
haftmann@26193
   675
qed
haftmann@26193
   676
haftmann@26193
   677
lemma mult_less_imp_less_right:
haftmann@26193
   678
  assumes less: "a * c < b * c" and nonneg: "0 \<le> c"
haftmann@26193
   679
  shows "a < b"
haftmann@26193
   680
proof (rule ccontr)
haftmann@26193
   681
  assume "\<not> a < b"
haftmann@26193
   682
  hence "b \<le> a" by (simp add: linorder_not_less)
haftmann@26193
   683
  hence "b * c \<le> a * c" using nonneg by (rule mult_right_mono)
nipkow@29667
   684
  with this and less show False by (simp add: not_less [symmetric])
haftmann@26193
   685
qed  
haftmann@26193
   686
haftmann@25230
   687
end
haftmann@25230
   688
haftmann@35097
   689
class linordered_semiring_1_strict = linordered_semiring_strict + semiring_1
haftmann@33319
   690
haftmann@22390
   691
class mult_mono1 = times + zero + ord +
haftmann@25230
   692
  assumes mult_mono1: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
paulson@14270
   693
haftmann@35028
   694
class ordered_comm_semiring = comm_semiring_0
haftmann@35028
   695
  + ordered_ab_semigroup_add + mult_mono1
haftmann@25186
   696
begin
haftmann@25152
   697
haftmann@35028
   698
subclass ordered_semiring
haftmann@28823
   699
proof
krauss@21199
   700
  fix a b c :: 'a
huffman@23550
   701
  assume "a \<le> b" "0 \<le> c"
haftmann@25230
   702
  thus "c * a \<le> c * b" by (rule mult_mono1)
huffman@23550
   703
  thus "a * c \<le> b * c" by (simp only: mult_commute)
krauss@21199
   704
qed
paulson@14265
   705
haftmann@25267
   706
end
haftmann@25267
   707
haftmann@35028
   708
class ordered_cancel_comm_semiring = comm_semiring_0_cancel
haftmann@35028
   709
  + ordered_ab_semigroup_add + mult_mono1
haftmann@25267
   710
begin
paulson@14265
   711
haftmann@35028
   712
subclass ordered_comm_semiring ..
haftmann@35028
   713
subclass ordered_cancel_semiring ..
haftmann@25267
   714
haftmann@25267
   715
end
haftmann@25267
   716
haftmann@35028
   717
class linordered_comm_semiring_strict = comm_semiring_0 + linordered_cancel_ab_semigroup_add +
haftmann@26193
   718
  assumes mult_strict_left_mono_comm: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
haftmann@25267
   719
begin
haftmann@25267
   720
haftmann@35043
   721
subclass linordered_semiring_strict
haftmann@28823
   722
proof
huffman@23550
   723
  fix a b c :: 'a
huffman@23550
   724
  assume "a < b" "0 < c"
haftmann@26193
   725
  thus "c * a < c * b" by (rule mult_strict_left_mono_comm)
huffman@23550
   726
  thus "a * c < b * c" by (simp only: mult_commute)
huffman@23550
   727
qed
paulson@14272
   728
haftmann@35028
   729
subclass ordered_cancel_comm_semiring
haftmann@28823
   730
proof
huffman@23550
   731
  fix a b c :: 'a
huffman@23550
   732
  assume "a \<le> b" "0 \<le> c"
huffman@23550
   733
  thus "c * a \<le> c * b"
haftmann@25186
   734
    unfolding le_less
haftmann@26193
   735
    using mult_strict_left_mono by (cases "c = 0") auto
huffman@23550
   736
qed
paulson@14272
   737
haftmann@25267
   738
end
haftmann@25230
   739
haftmann@35028
   740
class ordered_ring = ring + ordered_cancel_semiring 
haftmann@25267
   741
begin
haftmann@25230
   742
haftmann@35028
   743
subclass ordered_ab_group_add ..
paulson@14270
   744
nipkow@29667
   745
text{*Legacy - use @{text algebra_simps} *}
nipkow@29833
   746
lemmas ring_simps[noatp] = algebra_simps
haftmann@25230
   747
haftmann@25230
   748
lemma less_add_iff1:
haftmann@25230
   749
  "a * e + c < b * e + d \<longleftrightarrow> (a - b) * e + c < d"
nipkow@29667
   750
by (simp add: algebra_simps)
haftmann@25230
   751
haftmann@25230
   752
lemma less_add_iff2:
haftmann@25230
   753
  "a * e + c < b * e + d \<longleftrightarrow> c < (b - a) * e + d"
nipkow@29667
   754
by (simp add: algebra_simps)
haftmann@25230
   755
haftmann@25230
   756
lemma le_add_iff1:
haftmann@25230
   757
  "a * e + c \<le> b * e + d \<longleftrightarrow> (a - b) * e + c \<le> d"
nipkow@29667
   758
by (simp add: algebra_simps)
haftmann@25230
   759
haftmann@25230
   760
lemma le_add_iff2:
haftmann@25230
   761
  "a * e + c \<le> b * e + d \<longleftrightarrow> c \<le> (b - a) * e + d"
nipkow@29667
   762
by (simp add: algebra_simps)
haftmann@25230
   763
haftmann@25230
   764
lemma mult_left_mono_neg:
haftmann@25230
   765
  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> c * a \<le> c * b"
haftmann@25230
   766
  apply (drule mult_left_mono [of _ _ "uminus c"])
haftmann@25230
   767
  apply (simp_all add: minus_mult_left [symmetric]) 
haftmann@25230
   768
  done
haftmann@25230
   769
haftmann@25230
   770
lemma mult_right_mono_neg:
haftmann@25230
   771
  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> a * c \<le> b * c"
haftmann@25230
   772
  apply (drule mult_right_mono [of _ _ "uminus c"])
haftmann@25230
   773
  apply (simp_all add: minus_mult_right [symmetric]) 
haftmann@25230
   774
  done
haftmann@25230
   775
huffman@30692
   776
lemma mult_nonpos_nonpos: "a \<le> 0 \<Longrightarrow> b \<le> 0 \<Longrightarrow> 0 \<le> a * b"
huffman@30692
   777
using mult_right_mono_neg [of a zero b] by simp
haftmann@25230
   778
haftmann@25230
   779
lemma split_mult_pos_le:
haftmann@25230
   780
  "(0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0) \<Longrightarrow> 0 \<le> a * b"
nipkow@29667
   781
by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos)
haftmann@25186
   782
haftmann@25186
   783
end
paulson@14270
   784
haftmann@35028
   785
class linordered_ring = ring + linordered_semiring + linordered_ab_group_add + abs_if
haftmann@25304
   786
begin
haftmann@25304
   787
haftmann@35028
   788
subclass ordered_ring ..
haftmann@35028
   789
haftmann@35028
   790
subclass ordered_ab_group_add_abs
haftmann@28823
   791
proof
haftmann@25304
   792
  fix a b
haftmann@25304
   793
  show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@35028
   794
    by (auto simp add: abs_if not_less neg_less_eq_nonneg less_eq_neg_nonpos)
haftmann@35028
   795
    (auto simp del: minus_add_distrib simp add: minus_add_distrib [symmetric]
haftmann@25304
   796
     neg_less_eq_nonneg less_eq_neg_nonpos, auto intro: add_nonneg_nonneg,
haftmann@25304
   797
      auto intro!: less_imp_le add_neg_neg)
haftmann@25304
   798
qed (auto simp add: abs_if less_eq_neg_nonpos neg_equal_zero)
haftmann@25304
   799
haftmann@25304
   800
end
obua@23521
   801
haftmann@35028
   802
(* The "strict" suffix can be seen as describing the combination of linordered_ring and no_zero_divisors.
haftmann@35043
   803
   Basically, linordered_ring + no_zero_divisors = linordered_ring_strict.
haftmann@25230
   804
 *)
haftmann@35043
   805
class linordered_ring_strict = ring + linordered_semiring_strict
haftmann@25304
   806
  + ordered_ab_group_add + abs_if
haftmann@25230
   807
begin
paulson@14348
   808
haftmann@35028
   809
subclass linordered_ring ..
haftmann@25304
   810
huffman@30692
   811
lemma mult_strict_left_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> c * a < c * b"
huffman@30692
   812
using mult_strict_left_mono [of b a "- c"] by simp
huffman@30692
   813
huffman@30692
   814
lemma mult_strict_right_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> a * c < b * c"
huffman@30692
   815
using mult_strict_right_mono [of b a "- c"] by simp
huffman@30692
   816
huffman@30692
   817
lemma mult_neg_neg: "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> 0 < a * b"
huffman@30692
   818
using mult_strict_right_mono_neg [of a zero b] by simp
obua@14738
   819
haftmann@25917
   820
subclass ring_no_zero_divisors
haftmann@28823
   821
proof
haftmann@25917
   822
  fix a b
haftmann@25917
   823
  assume "a \<noteq> 0" then have A: "a < 0 \<or> 0 < a" by (simp add: neq_iff)
haftmann@25917
   824
  assume "b \<noteq> 0" then have B: "b < 0 \<or> 0 < b" by (simp add: neq_iff)
haftmann@25917
   825
  have "a * b < 0 \<or> 0 < a * b"
haftmann@25917
   826
  proof (cases "a < 0")
haftmann@25917
   827
    case True note A' = this
haftmann@25917
   828
    show ?thesis proof (cases "b < 0")
haftmann@25917
   829
      case True with A'
haftmann@25917
   830
      show ?thesis by (auto dest: mult_neg_neg)
haftmann@25917
   831
    next
haftmann@25917
   832
      case False with B have "0 < b" by auto
haftmann@25917
   833
      with A' show ?thesis by (auto dest: mult_strict_right_mono)
haftmann@25917
   834
    qed
haftmann@25917
   835
  next
haftmann@25917
   836
    case False with A have A': "0 < a" by auto
haftmann@25917
   837
    show ?thesis proof (cases "b < 0")
haftmann@25917
   838
      case True with A'
haftmann@25917
   839
      show ?thesis by (auto dest: mult_strict_right_mono_neg)
haftmann@25917
   840
    next
haftmann@25917
   841
      case False with B have "0 < b" by auto
haftmann@25917
   842
      with A' show ?thesis by (auto dest: mult_pos_pos)
haftmann@25917
   843
    qed
haftmann@25917
   844
  qed
haftmann@25917
   845
  then show "a * b \<noteq> 0" by (simp add: neq_iff)
haftmann@25917
   846
qed
haftmann@25304
   847
paulson@14265
   848
lemma zero_less_mult_iff:
haftmann@25917
   849
  "0 < a * b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0"
haftmann@25917
   850
  apply (auto simp add: mult_pos_pos mult_neg_neg)
haftmann@25917
   851
  apply (simp_all add: not_less le_less)
haftmann@25917
   852
  apply (erule disjE) apply assumption defer
haftmann@25917
   853
  apply (erule disjE) defer apply (drule sym) apply simp
haftmann@25917
   854
  apply (erule disjE) defer apply (drule sym) apply simp
haftmann@25917
   855
  apply (erule disjE) apply assumption apply (drule sym) apply simp
haftmann@25917
   856
  apply (drule sym) apply simp
haftmann@25917
   857
  apply (blast dest: zero_less_mult_pos)
haftmann@25230
   858
  apply (blast dest: zero_less_mult_pos2)
haftmann@25230
   859
  done
huffman@22990
   860
paulson@14265
   861
lemma zero_le_mult_iff:
haftmann@25917
   862
  "0 \<le> a * b \<longleftrightarrow> 0 \<le> a \<and> 0 \<le> b \<or> a \<le> 0 \<and> b \<le> 0"
nipkow@29667
   863
by (auto simp add: eq_commute [of 0] le_less not_less zero_less_mult_iff)
paulson@14265
   864
paulson@14265
   865
lemma mult_less_0_iff:
haftmann@25917
   866
  "a * b < 0 \<longleftrightarrow> 0 < a \<and> b < 0 \<or> a < 0 \<and> 0 < b"
haftmann@25917
   867
  apply (insert zero_less_mult_iff [of "-a" b]) 
haftmann@25917
   868
  apply (force simp add: minus_mult_left[symmetric]) 
haftmann@25917
   869
  done
paulson@14265
   870
paulson@14265
   871
lemma mult_le_0_iff:
haftmann@25917
   872
  "a * b \<le> 0 \<longleftrightarrow> 0 \<le> a \<and> b \<le> 0 \<or> a \<le> 0 \<and> 0 \<le> b"
haftmann@25917
   873
  apply (insert zero_le_mult_iff [of "-a" b]) 
haftmann@25917
   874
  apply (force simp add: minus_mult_left[symmetric]) 
haftmann@25917
   875
  done
haftmann@25917
   876
haftmann@25917
   877
lemma zero_le_square [simp]: "0 \<le> a * a"
nipkow@29667
   878
by (simp add: zero_le_mult_iff linear)
haftmann@25917
   879
haftmann@25917
   880
lemma not_square_less_zero [simp]: "\<not> (a * a < 0)"
nipkow@29667
   881
by (simp add: not_less)
haftmann@25917
   882
haftmann@26193
   883
text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
haftmann@26193
   884
   also with the relations @{text "\<le>"} and equality.*}
haftmann@26193
   885
haftmann@26193
   886
text{*These ``disjunction'' versions produce two cases when the comparison is
haftmann@26193
   887
 an assumption, but effectively four when the comparison is a goal.*}
haftmann@26193
   888
haftmann@26193
   889
lemma mult_less_cancel_right_disj:
haftmann@26193
   890
  "a * c < b * c \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
   891
  apply (cases "c = 0")
haftmann@26193
   892
  apply (auto simp add: neq_iff mult_strict_right_mono 
haftmann@26193
   893
                      mult_strict_right_mono_neg)
haftmann@26193
   894
  apply (auto simp add: not_less 
haftmann@26193
   895
                      not_le [symmetric, of "a*c"]
haftmann@26193
   896
                      not_le [symmetric, of a])
haftmann@26193
   897
  apply (erule_tac [!] notE)
haftmann@26193
   898
  apply (auto simp add: less_imp_le mult_right_mono 
haftmann@26193
   899
                      mult_right_mono_neg)
haftmann@26193
   900
  done
haftmann@26193
   901
haftmann@26193
   902
lemma mult_less_cancel_left_disj:
haftmann@26193
   903
  "c * a < c * b \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
   904
  apply (cases "c = 0")
haftmann@26193
   905
  apply (auto simp add: neq_iff mult_strict_left_mono 
haftmann@26193
   906
                      mult_strict_left_mono_neg)
haftmann@26193
   907
  apply (auto simp add: not_less 
haftmann@26193
   908
                      not_le [symmetric, of "c*a"]
haftmann@26193
   909
                      not_le [symmetric, of a])
haftmann@26193
   910
  apply (erule_tac [!] notE)
haftmann@26193
   911
  apply (auto simp add: less_imp_le mult_left_mono 
haftmann@26193
   912
                      mult_left_mono_neg)
haftmann@26193
   913
  done
haftmann@26193
   914
haftmann@26193
   915
text{*The ``conjunction of implication'' lemmas produce two cases when the
haftmann@26193
   916
comparison is a goal, but give four when the comparison is an assumption.*}
haftmann@26193
   917
haftmann@26193
   918
lemma mult_less_cancel_right:
haftmann@26193
   919
  "a * c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
   920
  using mult_less_cancel_right_disj [of a c b] by auto
haftmann@26193
   921
haftmann@26193
   922
lemma mult_less_cancel_left:
haftmann@26193
   923
  "c * a < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
   924
  using mult_less_cancel_left_disj [of c a b] by auto
haftmann@26193
   925
haftmann@26193
   926
lemma mult_le_cancel_right:
haftmann@26193
   927
   "a * c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
nipkow@29667
   928
by (simp add: not_less [symmetric] mult_less_cancel_right_disj)
haftmann@26193
   929
haftmann@26193
   930
lemma mult_le_cancel_left:
haftmann@26193
   931
  "c * a \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
nipkow@29667
   932
by (simp add: not_less [symmetric] mult_less_cancel_left_disj)
haftmann@26193
   933
nipkow@30649
   934
lemma mult_le_cancel_left_pos:
nipkow@30649
   935
  "0 < c \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> a \<le> b"
nipkow@30649
   936
by (auto simp: mult_le_cancel_left)
nipkow@30649
   937
nipkow@30649
   938
lemma mult_le_cancel_left_neg:
nipkow@30649
   939
  "c < 0 \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> b \<le> a"
nipkow@30649
   940
by (auto simp: mult_le_cancel_left)
nipkow@30649
   941
nipkow@30649
   942
lemma mult_less_cancel_left_pos:
nipkow@30649
   943
  "0 < c \<Longrightarrow> c * a < c * b \<longleftrightarrow> a < b"
nipkow@30649
   944
by (auto simp: mult_less_cancel_left)
nipkow@30649
   945
nipkow@30649
   946
lemma mult_less_cancel_left_neg:
nipkow@30649
   947
  "c < 0 \<Longrightarrow> c * a < c * b \<longleftrightarrow> b < a"
nipkow@30649
   948
by (auto simp: mult_less_cancel_left)
nipkow@30649
   949
haftmann@25917
   950
end
paulson@14265
   951
nipkow@29667
   952
text{*Legacy - use @{text algebra_simps} *}
nipkow@29833
   953
lemmas ring_simps[noatp] = algebra_simps
haftmann@25230
   954
huffman@30692
   955
lemmas mult_sign_intros =
huffman@30692
   956
  mult_nonneg_nonneg mult_nonneg_nonpos
huffman@30692
   957
  mult_nonpos_nonneg mult_nonpos_nonpos
huffman@30692
   958
  mult_pos_pos mult_pos_neg
huffman@30692
   959
  mult_neg_pos mult_neg_neg
haftmann@25230
   960
haftmann@35028
   961
class ordered_comm_ring = comm_ring + ordered_comm_semiring
haftmann@25267
   962
begin
haftmann@25230
   963
haftmann@35028
   964
subclass ordered_ring ..
haftmann@35028
   965
subclass ordered_cancel_comm_semiring ..
haftmann@25230
   966
haftmann@25267
   967
end
haftmann@25230
   968
haftmann@35028
   969
class linordered_semidom = comm_semiring_1_cancel + linordered_comm_semiring_strict +
haftmann@35028
   970
  (*previously linordered_semiring*)
haftmann@25230
   971
  assumes zero_less_one [simp]: "0 < 1"
haftmann@25230
   972
begin
haftmann@25230
   973
haftmann@25230
   974
lemma pos_add_strict:
haftmann@25230
   975
  shows "0 < a \<Longrightarrow> b < c \<Longrightarrow> b < a + c"
haftmann@25230
   976
  using add_strict_mono [of zero a b c] by simp
haftmann@25230
   977
haftmann@26193
   978
lemma zero_le_one [simp]: "0 \<le> 1"
nipkow@29667
   979
by (rule zero_less_one [THEN less_imp_le]) 
haftmann@26193
   980
haftmann@26193
   981
lemma not_one_le_zero [simp]: "\<not> 1 \<le> 0"
nipkow@29667
   982
by (simp add: not_le) 
haftmann@26193
   983
haftmann@26193
   984
lemma not_one_less_zero [simp]: "\<not> 1 < 0"
nipkow@29667
   985
by (simp add: not_less) 
haftmann@26193
   986
haftmann@26193
   987
lemma less_1_mult:
haftmann@26193
   988
  assumes "1 < m" and "1 < n"
haftmann@26193
   989
  shows "1 < m * n"
haftmann@26193
   990
  using assms mult_strict_mono [of 1 m 1 n]
haftmann@26193
   991
    by (simp add:  less_trans [OF zero_less_one]) 
haftmann@26193
   992
haftmann@25230
   993
end
haftmann@25230
   994
haftmann@35028
   995
class linordered_idom = comm_ring_1 +
haftmann@35028
   996
  linordered_comm_semiring_strict + ordered_ab_group_add +
haftmann@25230
   997
  abs_if + sgn_if
haftmann@35028
   998
  (*previously linordered_ring*)
haftmann@25917
   999
begin
haftmann@25917
  1000
haftmann@35043
  1001
subclass linordered_ring_strict ..
haftmann@35028
  1002
subclass ordered_comm_ring ..
huffman@27516
  1003
subclass idom ..
haftmann@25917
  1004
haftmann@35028
  1005
subclass linordered_semidom
haftmann@28823
  1006
proof
haftmann@26193
  1007
  have "0 \<le> 1 * 1" by (rule zero_le_square)
haftmann@26193
  1008
  thus "0 < 1" by (simp add: le_less)
haftmann@25917
  1009
qed 
haftmann@25917
  1010
haftmann@35028
  1011
lemma linorder_neqE_linordered_idom:
haftmann@26193
  1012
  assumes "x \<noteq> y" obtains "x < y" | "y < x"
haftmann@26193
  1013
  using assms by (rule neqE)
haftmann@26193
  1014
haftmann@26274
  1015
text {* These cancellation simprules also produce two cases when the comparison is a goal. *}
haftmann@26274
  1016
haftmann@26274
  1017
lemma mult_le_cancel_right1:
haftmann@26274
  1018
  "c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
nipkow@29667
  1019
by (insert mult_le_cancel_right [of 1 c b], simp)
haftmann@26274
  1020
haftmann@26274
  1021
lemma mult_le_cancel_right2:
haftmann@26274
  1022
  "a * c \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
nipkow@29667
  1023
by (insert mult_le_cancel_right [of a c 1], simp)
haftmann@26274
  1024
haftmann@26274
  1025
lemma mult_le_cancel_left1:
haftmann@26274
  1026
  "c \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
nipkow@29667
  1027
by (insert mult_le_cancel_left [of c 1 b], simp)
haftmann@26274
  1028
haftmann@26274
  1029
lemma mult_le_cancel_left2:
haftmann@26274
  1030
  "c * a \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
nipkow@29667
  1031
by (insert mult_le_cancel_left [of c a 1], simp)
haftmann@26274
  1032
haftmann@26274
  1033
lemma mult_less_cancel_right1:
haftmann@26274
  1034
  "c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
nipkow@29667
  1035
by (insert mult_less_cancel_right [of 1 c b], simp)
haftmann@26274
  1036
haftmann@26274
  1037
lemma mult_less_cancel_right2:
haftmann@26274
  1038
  "a * c < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
nipkow@29667
  1039
by (insert mult_less_cancel_right [of a c 1], simp)
haftmann@26274
  1040
haftmann@26274
  1041
lemma mult_less_cancel_left1:
haftmann@26274
  1042
  "c < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
nipkow@29667
  1043
by (insert mult_less_cancel_left [of c 1 b], simp)
haftmann@26274
  1044
haftmann@26274
  1045
lemma mult_less_cancel_left2:
haftmann@26274
  1046
  "c * a < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
nipkow@29667
  1047
by (insert mult_less_cancel_left [of c a 1], simp)
haftmann@26274
  1048
haftmann@27651
  1049
lemma sgn_sgn [simp]:
haftmann@27651
  1050
  "sgn (sgn a) = sgn a"
nipkow@29700
  1051
unfolding sgn_if by simp
haftmann@27651
  1052
haftmann@27651
  1053
lemma sgn_0_0:
haftmann@27651
  1054
  "sgn a = 0 \<longleftrightarrow> a = 0"
nipkow@29700
  1055
unfolding sgn_if by simp
haftmann@27651
  1056
haftmann@27651
  1057
lemma sgn_1_pos:
haftmann@27651
  1058
  "sgn a = 1 \<longleftrightarrow> a > 0"
nipkow@29700
  1059
unfolding sgn_if by (simp add: neg_equal_zero)
haftmann@27651
  1060
haftmann@27651
  1061
lemma sgn_1_neg:
haftmann@27651
  1062
  "sgn a = - 1 \<longleftrightarrow> a < 0"
nipkow@29700
  1063
unfolding sgn_if by (auto simp add: equal_neg_zero)
haftmann@27651
  1064
haftmann@29940
  1065
lemma sgn_pos [simp]:
haftmann@29940
  1066
  "0 < a \<Longrightarrow> sgn a = 1"
haftmann@29940
  1067
unfolding sgn_1_pos .
haftmann@29940
  1068
haftmann@29940
  1069
lemma sgn_neg [simp]:
haftmann@29940
  1070
  "a < 0 \<Longrightarrow> sgn a = - 1"
haftmann@29940
  1071
unfolding sgn_1_neg .
haftmann@29940
  1072
haftmann@27651
  1073
lemma sgn_times:
haftmann@27651
  1074
  "sgn (a * b) = sgn a * sgn b"
nipkow@29667
  1075
by (auto simp add: sgn_if zero_less_mult_iff)
haftmann@27651
  1076
haftmann@29653
  1077
lemma abs_sgn: "abs k = k * sgn k"
nipkow@29700
  1078
unfolding sgn_if abs_if by auto
nipkow@29700
  1079
haftmann@29940
  1080
lemma sgn_greater [simp]:
haftmann@29940
  1081
  "0 < sgn a \<longleftrightarrow> 0 < a"
haftmann@29940
  1082
  unfolding sgn_if by auto
haftmann@29940
  1083
haftmann@29940
  1084
lemma sgn_less [simp]:
haftmann@29940
  1085
  "sgn a < 0 \<longleftrightarrow> a < 0"
haftmann@29940
  1086
  unfolding sgn_if by auto
haftmann@29940
  1087
huffman@29949
  1088
lemma abs_dvd_iff [simp]: "(abs m) dvd k \<longleftrightarrow> m dvd k"
huffman@29949
  1089
  by (simp add: abs_if)
huffman@29949
  1090
huffman@29949
  1091
lemma dvd_abs_iff [simp]: "m dvd (abs k) \<longleftrightarrow> m dvd k"
huffman@29949
  1092
  by (simp add: abs_if)
haftmann@29653
  1093
nipkow@33676
  1094
lemma dvd_if_abs_eq:
nipkow@33676
  1095
  "abs l = abs (k) \<Longrightarrow> l dvd k"
nipkow@33676
  1096
by(subst abs_dvd_iff[symmetric]) simp
nipkow@33676
  1097
haftmann@25917
  1098
end
haftmann@25230
  1099
haftmann@26274
  1100
text {* Simprules for comparisons where common factors can be cancelled. *}
paulson@15234
  1101
nipkow@29833
  1102
lemmas mult_compare_simps[noatp] =
paulson@15234
  1103
    mult_le_cancel_right mult_le_cancel_left
paulson@15234
  1104
    mult_le_cancel_right1 mult_le_cancel_right2
paulson@15234
  1105
    mult_le_cancel_left1 mult_le_cancel_left2
paulson@15234
  1106
    mult_less_cancel_right mult_less_cancel_left
paulson@15234
  1107
    mult_less_cancel_right1 mult_less_cancel_right2
paulson@15234
  1108
    mult_less_cancel_left1 mult_less_cancel_left2
paulson@15234
  1109
    mult_cancel_right mult_cancel_left
paulson@15234
  1110
    mult_cancel_right1 mult_cancel_right2
paulson@15234
  1111
    mult_cancel_left1 mult_cancel_left2
paulson@15234
  1112
haftmann@26274
  1113
-- {* FIXME continue localization here *}
paulson@14268
  1114
avigad@16775
  1115
subsection {* Reasoning about inequalities with division *}
avigad@16775
  1116
haftmann@35028
  1117
lemma mult_right_le_one_le: "0 <= (x::'a::linordered_idom) ==> 0 <= y ==> y <= 1
avigad@16775
  1118
    ==> x * y <= x"
haftmann@33319
  1119
by (auto simp add: mult_compare_simps)
avigad@16775
  1120
haftmann@35028
  1121
lemma mult_left_le_one_le: "0 <= (x::'a::linordered_idom) ==> 0 <= y ==> y <= 1
avigad@16775
  1122
    ==> y * x <= x"
haftmann@33319
  1123
by (auto simp add: mult_compare_simps)
avigad@16775
  1124
haftmann@35028
  1125
context linordered_semidom
haftmann@25193
  1126
begin
haftmann@25193
  1127
haftmann@25193
  1128
lemma less_add_one: "a < a + 1"
paulson@14293
  1129
proof -
haftmann@25193
  1130
  have "a + 0 < a + 1"
nipkow@23482
  1131
    by (blast intro: zero_less_one add_strict_left_mono)
paulson@14293
  1132
  thus ?thesis by simp
paulson@14293
  1133
qed
paulson@14293
  1134
haftmann@25193
  1135
lemma zero_less_two: "0 < 1 + 1"
nipkow@29667
  1136
by (blast intro: less_trans zero_less_one less_add_one)
haftmann@25193
  1137
haftmann@25193
  1138
end
paulson@14365
  1139
paulson@15234
  1140
paulson@14293
  1141
subsection {* Absolute Value *}
paulson@14293
  1142
haftmann@35028
  1143
context linordered_idom
haftmann@25304
  1144
begin
haftmann@25304
  1145
haftmann@25304
  1146
lemma mult_sgn_abs: "sgn x * abs x = x"
haftmann@25304
  1147
  unfolding abs_if sgn_if by auto
haftmann@25304
  1148
haftmann@25304
  1149
end
nipkow@24491
  1150
haftmann@35028
  1151
lemma abs_one [simp]: "abs 1 = (1::'a::linordered_idom)"
nipkow@29667
  1152
by (simp add: abs_if zero_less_one [THEN order_less_not_sym])
haftmann@25304
  1153
haftmann@35028
  1154
class ordered_ring_abs = ordered_ring + ordered_ab_group_add_abs +
haftmann@25304
  1155
  assumes abs_eq_mult:
haftmann@25304
  1156
    "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0) \<Longrightarrow> \<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>"
haftmann@25304
  1157
haftmann@35028
  1158
context linordered_idom
haftmann@30961
  1159
begin
haftmann@30961
  1160
haftmann@35028
  1161
subclass ordered_ring_abs proof
haftmann@30961
  1162
qed (auto simp add: abs_if not_less equal_neg_zero neg_equal_zero mult_less_0_iff)
haftmann@30961
  1163
haftmann@30961
  1164
lemma abs_mult:
haftmann@30961
  1165
  "abs (a * b) = abs a * abs b" 
haftmann@30961
  1166
  by (rule abs_eq_mult) auto
haftmann@30961
  1167
haftmann@30961
  1168
lemma abs_mult_self:
haftmann@30961
  1169
  "abs a * abs a = a * a"
haftmann@30961
  1170
  by (simp add: abs_if) 
haftmann@30961
  1171
haftmann@30961
  1172
end
paulson@14294
  1173
paulson@14294
  1174
lemma abs_mult_less:
haftmann@35028
  1175
     "[| abs a < c; abs b < d |] ==> abs a * abs b < c*(d::'a::linordered_idom)"
paulson@14294
  1176
proof -
paulson@14294
  1177
  assume ac: "abs a < c"
paulson@14294
  1178
  hence cpos: "0<c" by (blast intro: order_le_less_trans abs_ge_zero)
paulson@14294
  1179
  assume "abs b < d"
paulson@14294
  1180
  thus ?thesis by (simp add: ac cpos mult_strict_mono) 
paulson@14294
  1181
qed
paulson@14293
  1182
nipkow@29833
  1183
lemmas eq_minus_self_iff[noatp] = equal_neg_zero
obua@14738
  1184
haftmann@35028
  1185
lemma less_minus_self_iff: "(a < -a) = (a < (0::'a::linordered_idom))"
haftmann@25304
  1186
  unfolding order_less_le less_eq_neg_nonpos equal_neg_zero ..
obua@14738
  1187
haftmann@35028
  1188
lemma abs_less_iff: "(abs a < b) = (a < b & -a < (b::'a::linordered_idom))" 
obua@14738
  1189
apply (simp add: order_less_le abs_le_iff)  
haftmann@25304
  1190
apply (auto simp add: abs_if neg_less_eq_nonneg less_eq_neg_nonpos)
obua@14738
  1191
done
obua@14738
  1192
haftmann@35028
  1193
lemma abs_mult_pos: "(0::'a::linordered_idom) <= x ==> 
haftmann@25304
  1194
    (abs y) * x = abs (y * x)"
haftmann@25304
  1195
  apply (subst abs_mult)
haftmann@25304
  1196
  apply simp
haftmann@25304
  1197
done
avigad@16775
  1198
haftmann@33364
  1199
code_modulename SML
haftmann@35050
  1200
  Rings Arith
haftmann@33364
  1201
haftmann@33364
  1202
code_modulename OCaml
haftmann@35050
  1203
  Rings Arith
haftmann@33364
  1204
haftmann@33364
  1205
code_modulename Haskell
haftmann@35050
  1206
  Rings Arith
haftmann@33364
  1207
paulson@14265
  1208
end