src/HOL/Rings.thy
author haftmann
Mon Feb 22 15:53:18 2010 +0100 (2010-02-22)
changeset 35302 4bc6b4d70e08
parent 35216 7641e8d831d2
child 35631 0b8a5fd339ab
permissions -rw-r--r--
tuned text
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
haftmann@22390
    16
class semiring = ab_semigroup_add + semigroup_mult +
nipkow@29667
    17
  assumes left_distrib[algebra_simps]: "(a + b) * c = a * c + b * c"
nipkow@29667
    18
  assumes right_distrib[algebra_simps]: "a * (b + c) = a * b + a * c"
haftmann@25152
    19
begin
haftmann@25152
    20
haftmann@25152
    21
text{*For the @{text combine_numerals} simproc*}
haftmann@25152
    22
lemma combine_common_factor:
haftmann@25152
    23
  "a * e + (b * e + c) = (a + b) * e + c"
nipkow@29667
    24
by (simp add: left_distrib add_ac)
haftmann@25152
    25
haftmann@25152
    26
end
paulson@14504
    27
haftmann@22390
    28
class mult_zero = times + zero +
haftmann@25062
    29
  assumes mult_zero_left [simp]: "0 * a = 0"
haftmann@25062
    30
  assumes mult_zero_right [simp]: "a * 0 = 0"
krauss@21199
    31
haftmann@22390
    32
class semiring_0 = semiring + comm_monoid_add + mult_zero
krauss@21199
    33
huffman@29904
    34
class semiring_0_cancel = semiring + cancel_comm_monoid_add
haftmann@25186
    35
begin
paulson@14504
    36
haftmann@25186
    37
subclass semiring_0
haftmann@28823
    38
proof
krauss@21199
    39
  fix a :: 'a
nipkow@29667
    40
  have "0 * a + 0 * a = 0 * a + 0" by (simp add: left_distrib [symmetric])
nipkow@29667
    41
  thus "0 * a = 0" by (simp only: add_left_cancel)
haftmann@25152
    42
next
haftmann@25152
    43
  fix a :: 'a
nipkow@29667
    44
  have "a * 0 + a * 0 = a * 0 + 0" by (simp add: right_distrib [symmetric])
nipkow@29667
    45
  thus "a * 0 = 0" by (simp only: add_left_cancel)
krauss@21199
    46
qed
obua@14940
    47
haftmann@25186
    48
end
haftmann@25152
    49
haftmann@22390
    50
class comm_semiring = ab_semigroup_add + ab_semigroup_mult +
haftmann@25062
    51
  assumes distrib: "(a + b) * c = a * c + b * c"
haftmann@25152
    52
begin
paulson@14504
    53
haftmann@25152
    54
subclass semiring
haftmann@28823
    55
proof
obua@14738
    56
  fix a b c :: 'a
obua@14738
    57
  show "(a + b) * c = a * c + b * c" by (simp add: distrib)
obua@14738
    58
  have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
obua@14738
    59
  also have "... = b * a + c * a" by (simp only: distrib)
obua@14738
    60
  also have "... = a * b + a * c" by (simp add: mult_ac)
obua@14738
    61
  finally show "a * (b + c) = a * b + a * c" by blast
paulson@14504
    62
qed
paulson@14504
    63
haftmann@25152
    64
end
paulson@14504
    65
haftmann@25152
    66
class comm_semiring_0 = comm_semiring + comm_monoid_add + mult_zero
haftmann@25152
    67
begin
haftmann@25152
    68
huffman@27516
    69
subclass semiring_0 ..
haftmann@25152
    70
haftmann@25152
    71
end
paulson@14504
    72
huffman@29904
    73
class comm_semiring_0_cancel = comm_semiring + cancel_comm_monoid_add
haftmann@25186
    74
begin
obua@14940
    75
huffman@27516
    76
subclass semiring_0_cancel ..
obua@14940
    77
huffman@28141
    78
subclass comm_semiring_0 ..
huffman@28141
    79
haftmann@25186
    80
end
krauss@21199
    81
haftmann@22390
    82
class zero_neq_one = zero + one +
haftmann@25062
    83
  assumes zero_neq_one [simp]: "0 \<noteq> 1"
haftmann@26193
    84
begin
haftmann@26193
    85
haftmann@26193
    86
lemma one_neq_zero [simp]: "1 \<noteq> 0"
nipkow@29667
    87
by (rule not_sym) (rule zero_neq_one)
haftmann@26193
    88
haftmann@26193
    89
end
paulson@14265
    90
haftmann@22390
    91
class semiring_1 = zero_neq_one + semiring_0 + monoid_mult
paulson@14504
    92
haftmann@27651
    93
text {* Abstract divisibility *}
haftmann@27651
    94
haftmann@27651
    95
class dvd = times
haftmann@27651
    96
begin
haftmann@27651
    97
haftmann@28559
    98
definition dvd :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "dvd" 50) where
haftmann@28559
    99
  [code del]: "b dvd a \<longleftrightarrow> (\<exists>k. a = b * k)"
haftmann@27651
   100
haftmann@27651
   101
lemma dvdI [intro?]: "a = b * k \<Longrightarrow> b dvd a"
haftmann@27651
   102
  unfolding dvd_def ..
haftmann@27651
   103
haftmann@27651
   104
lemma dvdE [elim?]: "b dvd a \<Longrightarrow> (\<And>k. a = b * k \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@27651
   105
  unfolding dvd_def by blast 
haftmann@27651
   106
haftmann@27651
   107
end
haftmann@27651
   108
haftmann@27651
   109
class comm_semiring_1 = zero_neq_one + comm_semiring_0 + comm_monoid_mult + dvd
haftmann@22390
   110
  (*previously almost_semiring*)
haftmann@25152
   111
begin
obua@14738
   112
huffman@27516
   113
subclass semiring_1 ..
haftmann@25152
   114
nipkow@29925
   115
lemma dvd_refl[simp]: "a dvd a"
haftmann@28559
   116
proof
haftmann@28559
   117
  show "a = a * 1" by simp
haftmann@27651
   118
qed
haftmann@27651
   119
haftmann@27651
   120
lemma dvd_trans:
haftmann@27651
   121
  assumes "a dvd b" and "b dvd c"
haftmann@27651
   122
  shows "a dvd c"
haftmann@27651
   123
proof -
haftmann@28559
   124
  from assms obtain v where "b = a * v" by (auto elim!: dvdE)
haftmann@28559
   125
  moreover from assms obtain w where "c = b * w" by (auto elim!: dvdE)
haftmann@27651
   126
  ultimately have "c = a * (v * w)" by (simp add: mult_assoc)
haftmann@28559
   127
  then show ?thesis ..
haftmann@27651
   128
qed
haftmann@27651
   129
haftmann@27651
   130
lemma dvd_0_left_iff [noatp, simp]: "0 dvd a \<longleftrightarrow> a = 0"
nipkow@29667
   131
by (auto intro: dvd_refl elim!: dvdE)
haftmann@28559
   132
haftmann@28559
   133
lemma dvd_0_right [iff]: "a dvd 0"
haftmann@28559
   134
proof
haftmann@27651
   135
  show "0 = a * 0" by simp
haftmann@27651
   136
qed
haftmann@27651
   137
haftmann@27651
   138
lemma one_dvd [simp]: "1 dvd a"
nipkow@29667
   139
by (auto intro!: dvdI)
haftmann@27651
   140
nipkow@30042
   141
lemma dvd_mult[simp]: "a dvd c \<Longrightarrow> a dvd (b * c)"
nipkow@29667
   142
by (auto intro!: mult_left_commute dvdI elim!: dvdE)
haftmann@27651
   143
nipkow@30042
   144
lemma dvd_mult2[simp]: "a dvd b \<Longrightarrow> a dvd (b * c)"
haftmann@27651
   145
  apply (subst mult_commute)
haftmann@27651
   146
  apply (erule dvd_mult)
haftmann@27651
   147
  done
haftmann@27651
   148
haftmann@27651
   149
lemma dvd_triv_right [simp]: "a dvd b * a"
nipkow@29667
   150
by (rule dvd_mult) (rule dvd_refl)
haftmann@27651
   151
haftmann@27651
   152
lemma dvd_triv_left [simp]: "a dvd a * b"
nipkow@29667
   153
by (rule dvd_mult2) (rule dvd_refl)
haftmann@27651
   154
haftmann@27651
   155
lemma mult_dvd_mono:
nipkow@30042
   156
  assumes "a dvd b"
nipkow@30042
   157
    and "c dvd d"
haftmann@27651
   158
  shows "a * c dvd b * d"
haftmann@27651
   159
proof -
nipkow@30042
   160
  from `a dvd b` obtain b' where "b = a * b'" ..
nipkow@30042
   161
  moreover from `c dvd d` obtain d' where "d = c * d'" ..
haftmann@27651
   162
  ultimately have "b * d = (a * c) * (b' * d')" by (simp add: mult_ac)
haftmann@27651
   163
  then show ?thesis ..
haftmann@27651
   164
qed
haftmann@27651
   165
haftmann@27651
   166
lemma dvd_mult_left: "a * b dvd c \<Longrightarrow> a dvd c"
nipkow@29667
   167
by (simp add: dvd_def mult_assoc, blast)
haftmann@27651
   168
haftmann@27651
   169
lemma dvd_mult_right: "a * b dvd c \<Longrightarrow> b dvd c"
haftmann@27651
   170
  unfolding mult_ac [of a] by (rule dvd_mult_left)
haftmann@27651
   171
haftmann@27651
   172
lemma dvd_0_left: "0 dvd a \<Longrightarrow> a = 0"
nipkow@29667
   173
by simp
haftmann@27651
   174
nipkow@29925
   175
lemma dvd_add[simp]:
nipkow@29925
   176
  assumes "a dvd b" and "a dvd c" shows "a dvd (b + c)"
haftmann@27651
   177
proof -
nipkow@29925
   178
  from `a dvd b` obtain b' where "b = a * b'" ..
nipkow@29925
   179
  moreover from `a dvd c` obtain c' where "c = a * c'" ..
haftmann@27651
   180
  ultimately have "b + c = a * (b' + c')" by (simp add: right_distrib)
haftmann@27651
   181
  then show ?thesis ..
haftmann@27651
   182
qed
haftmann@27651
   183
haftmann@25152
   184
end
paulson@14421
   185
nipkow@29925
   186
haftmann@22390
   187
class no_zero_divisors = zero + times +
haftmann@25062
   188
  assumes no_zero_divisors: "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a * b \<noteq> 0"
paulson@14504
   189
huffman@29904
   190
class semiring_1_cancel = semiring + cancel_comm_monoid_add
huffman@29904
   191
  + zero_neq_one + monoid_mult
haftmann@25267
   192
begin
obua@14940
   193
huffman@27516
   194
subclass semiring_0_cancel ..
haftmann@25512
   195
huffman@27516
   196
subclass semiring_1 ..
haftmann@25267
   197
haftmann@25267
   198
end
krauss@21199
   199
huffman@29904
   200
class comm_semiring_1_cancel = comm_semiring + cancel_comm_monoid_add
huffman@29904
   201
  + zero_neq_one + comm_monoid_mult
haftmann@25267
   202
begin
obua@14738
   203
huffman@27516
   204
subclass semiring_1_cancel ..
huffman@27516
   205
subclass comm_semiring_0_cancel ..
huffman@27516
   206
subclass comm_semiring_1 ..
haftmann@25267
   207
haftmann@25267
   208
end
haftmann@25152
   209
haftmann@22390
   210
class ring = semiring + ab_group_add
haftmann@25267
   211
begin
haftmann@25152
   212
huffman@27516
   213
subclass semiring_0_cancel ..
haftmann@25152
   214
haftmann@25152
   215
text {* Distribution rules *}
haftmann@25152
   216
haftmann@25152
   217
lemma minus_mult_left: "- (a * b) = - a * b"
huffman@34146
   218
by (rule minus_unique) (simp add: left_distrib [symmetric]) 
haftmann@25152
   219
haftmann@25152
   220
lemma minus_mult_right: "- (a * b) = a * - b"
huffman@34146
   221
by (rule minus_unique) (simp add: right_distrib [symmetric]) 
haftmann@25152
   222
huffman@29407
   223
text{*Extract signs from products*}
nipkow@29833
   224
lemmas mult_minus_left [simp, noatp] = minus_mult_left [symmetric]
nipkow@29833
   225
lemmas mult_minus_right [simp,noatp] = minus_mult_right [symmetric]
huffman@29407
   226
haftmann@25152
   227
lemma minus_mult_minus [simp]: "- a * - b = a * b"
nipkow@29667
   228
by simp
haftmann@25152
   229
haftmann@25152
   230
lemma minus_mult_commute: "- a * b = a * - b"
nipkow@29667
   231
by simp
nipkow@29667
   232
nipkow@29667
   233
lemma right_diff_distrib[algebra_simps]: "a * (b - c) = a * b - a * c"
nipkow@29667
   234
by (simp add: right_distrib diff_minus)
nipkow@29667
   235
nipkow@29667
   236
lemma left_diff_distrib[algebra_simps]: "(a - b) * c = a * c - b * c"
nipkow@29667
   237
by (simp add: left_distrib diff_minus)
haftmann@25152
   238
nipkow@29833
   239
lemmas ring_distribs[noatp] =
haftmann@25152
   240
  right_distrib left_distrib left_diff_distrib right_diff_distrib
haftmann@25152
   241
nipkow@29667
   242
text{*Legacy - use @{text algebra_simps} *}
nipkow@29833
   243
lemmas ring_simps[noatp] = algebra_simps
haftmann@25230
   244
haftmann@25230
   245
lemma eq_add_iff1:
haftmann@25230
   246
  "a * e + c = b * e + d \<longleftrightarrow> (a - b) * e + c = d"
nipkow@29667
   247
by (simp add: algebra_simps)
haftmann@25230
   248
haftmann@25230
   249
lemma eq_add_iff2:
haftmann@25230
   250
  "a * e + c = b * e + d \<longleftrightarrow> c = (b - a) * e + d"
nipkow@29667
   251
by (simp add: algebra_simps)
haftmann@25230
   252
haftmann@25152
   253
end
haftmann@25152
   254
nipkow@29833
   255
lemmas ring_distribs[noatp] =
haftmann@25152
   256
  right_distrib left_distrib left_diff_distrib right_diff_distrib
haftmann@25152
   257
haftmann@22390
   258
class comm_ring = comm_semiring + ab_group_add
haftmann@25267
   259
begin
obua@14738
   260
huffman@27516
   261
subclass ring ..
huffman@28141
   262
subclass comm_semiring_0_cancel ..
haftmann@25267
   263
haftmann@25267
   264
end
obua@14738
   265
haftmann@22390
   266
class ring_1 = ring + zero_neq_one + monoid_mult
haftmann@25267
   267
begin
paulson@14265
   268
huffman@27516
   269
subclass semiring_1_cancel ..
haftmann@25267
   270
haftmann@25267
   271
end
haftmann@25152
   272
haftmann@22390
   273
class comm_ring_1 = comm_ring + zero_neq_one + comm_monoid_mult
haftmann@22390
   274
  (*previously ring*)
haftmann@25267
   275
begin
obua@14738
   276
huffman@27516
   277
subclass ring_1 ..
huffman@27516
   278
subclass comm_semiring_1_cancel ..
haftmann@25267
   279
huffman@29465
   280
lemma dvd_minus_iff [simp]: "x dvd - y \<longleftrightarrow> x dvd y"
huffman@29408
   281
proof
huffman@29408
   282
  assume "x dvd - y"
huffman@29408
   283
  then have "x dvd - 1 * - y" by (rule dvd_mult)
huffman@29408
   284
  then show "x dvd y" by simp
huffman@29408
   285
next
huffman@29408
   286
  assume "x dvd y"
huffman@29408
   287
  then have "x dvd - 1 * y" by (rule dvd_mult)
huffman@29408
   288
  then show "x dvd - y" by simp
huffman@29408
   289
qed
huffman@29408
   290
huffman@29465
   291
lemma minus_dvd_iff [simp]: "- x dvd y \<longleftrightarrow> x dvd y"
huffman@29408
   292
proof
huffman@29408
   293
  assume "- x dvd y"
huffman@29408
   294
  then obtain k where "y = - x * k" ..
huffman@29408
   295
  then have "y = x * - k" by simp
huffman@29408
   296
  then show "x dvd y" ..
huffman@29408
   297
next
huffman@29408
   298
  assume "x dvd y"
huffman@29408
   299
  then obtain k where "y = x * k" ..
huffman@29408
   300
  then have "y = - x * - k" by simp
huffman@29408
   301
  then show "- x dvd y" ..
huffman@29408
   302
qed
huffman@29408
   303
nipkow@30042
   304
lemma dvd_diff[simp]: "x dvd y \<Longrightarrow> x dvd z \<Longrightarrow> x dvd (y - z)"
huffman@35216
   305
by (simp only: diff_minus dvd_add dvd_minus_iff)
huffman@29409
   306
haftmann@25267
   307
end
haftmann@25152
   308
huffman@22990
   309
class ring_no_zero_divisors = ring + no_zero_divisors
haftmann@25230
   310
begin
haftmann@25230
   311
haftmann@25230
   312
lemma mult_eq_0_iff [simp]:
haftmann@25230
   313
  shows "a * b = 0 \<longleftrightarrow> (a = 0 \<or> b = 0)"
haftmann@25230
   314
proof (cases "a = 0 \<or> b = 0")
haftmann@25230
   315
  case False then have "a \<noteq> 0" and "b \<noteq> 0" by auto
haftmann@25230
   316
    then show ?thesis using no_zero_divisors by simp
haftmann@25230
   317
next
haftmann@25230
   318
  case True then show ?thesis by auto
haftmann@25230
   319
qed
haftmann@25230
   320
haftmann@26193
   321
text{*Cancellation of equalities with a common factor*}
haftmann@26193
   322
lemma mult_cancel_right [simp, noatp]:
haftmann@26193
   323
  "a * c = b * c \<longleftrightarrow> c = 0 \<or> a = b"
haftmann@26193
   324
proof -
haftmann@26193
   325
  have "(a * c = b * c) = ((a - b) * c = 0)"
huffman@35216
   326
    by (simp add: algebra_simps)
huffman@35216
   327
  thus ?thesis by (simp add: disj_commute)
haftmann@26193
   328
qed
haftmann@26193
   329
haftmann@26193
   330
lemma mult_cancel_left [simp, noatp]:
haftmann@26193
   331
  "c * a = c * b \<longleftrightarrow> c = 0 \<or> a = b"
haftmann@26193
   332
proof -
haftmann@26193
   333
  have "(c * a = c * b) = (c * (a - b) = 0)"
huffman@35216
   334
    by (simp add: algebra_simps)
huffman@35216
   335
  thus ?thesis by simp
haftmann@26193
   336
qed
haftmann@26193
   337
haftmann@25230
   338
end
huffman@22990
   339
huffman@23544
   340
class ring_1_no_zero_divisors = ring_1 + ring_no_zero_divisors
haftmann@26274
   341
begin
haftmann@26274
   342
haftmann@26274
   343
lemma mult_cancel_right1 [simp]:
haftmann@26274
   344
  "c = b * c \<longleftrightarrow> c = 0 \<or> b = 1"
nipkow@29667
   345
by (insert mult_cancel_right [of 1 c b], force)
haftmann@26274
   346
haftmann@26274
   347
lemma mult_cancel_right2 [simp]:
haftmann@26274
   348
  "a * c = c \<longleftrightarrow> c = 0 \<or> a = 1"
nipkow@29667
   349
by (insert mult_cancel_right [of a c 1], simp)
haftmann@26274
   350
 
haftmann@26274
   351
lemma mult_cancel_left1 [simp]:
haftmann@26274
   352
  "c = c * b \<longleftrightarrow> c = 0 \<or> b = 1"
nipkow@29667
   353
by (insert mult_cancel_left [of c 1 b], force)
haftmann@26274
   354
haftmann@26274
   355
lemma mult_cancel_left2 [simp]:
haftmann@26274
   356
  "c * a = c \<longleftrightarrow> c = 0 \<or> a = 1"
nipkow@29667
   357
by (insert mult_cancel_left [of c a 1], simp)
haftmann@26274
   358
haftmann@26274
   359
end
huffman@22990
   360
haftmann@22390
   361
class idom = comm_ring_1 + no_zero_divisors
haftmann@25186
   362
begin
paulson@14421
   363
huffman@27516
   364
subclass ring_1_no_zero_divisors ..
huffman@22990
   365
huffman@29915
   366
lemma square_eq_iff: "a * a = b * b \<longleftrightarrow> (a = b \<or> a = - b)"
huffman@29915
   367
proof
huffman@29915
   368
  assume "a * a = b * b"
huffman@29915
   369
  then have "(a - b) * (a + b) = 0"
huffman@29915
   370
    by (simp add: algebra_simps)
huffman@29915
   371
  then show "a = b \<or> a = - b"
huffman@35216
   372
    by (simp add: eq_neg_iff_add_eq_0)
huffman@29915
   373
next
huffman@29915
   374
  assume "a = b \<or> a = - b"
huffman@29915
   375
  then show "a * a = b * b" by auto
huffman@29915
   376
qed
huffman@29915
   377
huffman@29981
   378
lemma dvd_mult_cancel_right [simp]:
huffman@29981
   379
  "a * c dvd b * c \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   380
proof -
huffman@29981
   381
  have "a * c dvd b * c \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
huffman@29981
   382
    unfolding dvd_def by (simp add: mult_ac)
huffman@29981
   383
  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   384
    unfolding dvd_def by simp
huffman@29981
   385
  finally show ?thesis .
huffman@29981
   386
qed
huffman@29981
   387
huffman@29981
   388
lemma dvd_mult_cancel_left [simp]:
huffman@29981
   389
  "c * a dvd c * b \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   390
proof -
huffman@29981
   391
  have "c * a dvd c * b \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
huffman@29981
   392
    unfolding dvd_def by (simp add: mult_ac)
huffman@29981
   393
  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   394
    unfolding dvd_def by simp
huffman@29981
   395
  finally show ?thesis .
huffman@29981
   396
qed
huffman@29981
   397
haftmann@25186
   398
end
haftmann@25152
   399
haftmann@35083
   400
class inverse =
haftmann@35083
   401
  fixes inverse :: "'a \<Rightarrow> 'a"
haftmann@35083
   402
    and divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "'/" 70)
haftmann@35083
   403
haftmann@22390
   404
class division_ring = ring_1 + inverse +
haftmann@25062
   405
  assumes left_inverse [simp]:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
haftmann@25062
   406
  assumes right_inverse [simp]: "a \<noteq> 0 \<Longrightarrow> a * inverse a = 1"
haftmann@35083
   407
  assumes divide_inverse: "a / b = a * inverse b"
haftmann@25186
   408
begin
huffman@20496
   409
haftmann@25186
   410
subclass ring_1_no_zero_divisors
haftmann@28823
   411
proof
huffman@22987
   412
  fix a b :: 'a
huffman@22987
   413
  assume a: "a \<noteq> 0" and b: "b \<noteq> 0"
huffman@22987
   414
  show "a * b \<noteq> 0"
huffman@22987
   415
  proof
huffman@22987
   416
    assume ab: "a * b = 0"
nipkow@29667
   417
    hence "0 = inverse a * (a * b) * inverse b" by simp
huffman@22987
   418
    also have "\<dots> = (inverse a * a) * (b * inverse b)"
huffman@22987
   419
      by (simp only: mult_assoc)
nipkow@29667
   420
    also have "\<dots> = 1" using a b by simp
nipkow@29667
   421
    finally show False by simp
huffman@22987
   422
  qed
huffman@22987
   423
qed
huffman@20496
   424
haftmann@26274
   425
lemma nonzero_imp_inverse_nonzero:
haftmann@26274
   426
  "a \<noteq> 0 \<Longrightarrow> inverse a \<noteq> 0"
haftmann@26274
   427
proof
haftmann@26274
   428
  assume ianz: "inverse a = 0"
haftmann@26274
   429
  assume "a \<noteq> 0"
haftmann@26274
   430
  hence "1 = a * inverse a" by simp
haftmann@26274
   431
  also have "... = 0" by (simp add: ianz)
haftmann@26274
   432
  finally have "1 = 0" .
haftmann@26274
   433
  thus False by (simp add: eq_commute)
haftmann@26274
   434
qed
haftmann@26274
   435
haftmann@26274
   436
lemma inverse_zero_imp_zero:
haftmann@26274
   437
  "inverse a = 0 \<Longrightarrow> a = 0"
haftmann@26274
   438
apply (rule classical)
haftmann@26274
   439
apply (drule nonzero_imp_inverse_nonzero)
haftmann@26274
   440
apply auto
haftmann@26274
   441
done
haftmann@26274
   442
haftmann@26274
   443
lemma inverse_unique: 
haftmann@26274
   444
  assumes ab: "a * b = 1"
haftmann@26274
   445
  shows "inverse a = b"
haftmann@26274
   446
proof -
haftmann@26274
   447
  have "a \<noteq> 0" using ab by (cases "a = 0") simp_all
huffman@29406
   448
  moreover have "inverse a * (a * b) = inverse a" by (simp add: ab)
huffman@29406
   449
  ultimately show ?thesis by (simp add: mult_assoc [symmetric])
haftmann@26274
   450
qed
haftmann@26274
   451
huffman@29406
   452
lemma nonzero_inverse_minus_eq:
huffman@29406
   453
  "a \<noteq> 0 \<Longrightarrow> inverse (- a) = - inverse a"
nipkow@29667
   454
by (rule inverse_unique) simp
huffman@29406
   455
huffman@29406
   456
lemma nonzero_inverse_inverse_eq:
huffman@29406
   457
  "a \<noteq> 0 \<Longrightarrow> inverse (inverse a) = a"
nipkow@29667
   458
by (rule inverse_unique) simp
huffman@29406
   459
huffman@29406
   460
lemma nonzero_inverse_eq_imp_eq:
huffman@29406
   461
  assumes "inverse a = inverse b" and "a \<noteq> 0" and "b \<noteq> 0"
huffman@29406
   462
  shows "a = b"
huffman@29406
   463
proof -
huffman@29406
   464
  from `inverse a = inverse b`
nipkow@29667
   465
  have "inverse (inverse a) = inverse (inverse b)" by (rule arg_cong)
huffman@29406
   466
  with `a \<noteq> 0` and `b \<noteq> 0` show "a = b"
huffman@29406
   467
    by (simp add: nonzero_inverse_inverse_eq)
huffman@29406
   468
qed
huffman@29406
   469
huffman@29406
   470
lemma inverse_1 [simp]: "inverse 1 = 1"
nipkow@29667
   471
by (rule inverse_unique) simp
huffman@29406
   472
haftmann@26274
   473
lemma nonzero_inverse_mult_distrib: 
huffman@29406
   474
  assumes "a \<noteq> 0" and "b \<noteq> 0"
haftmann@26274
   475
  shows "inverse (a * b) = inverse b * inverse a"
haftmann@26274
   476
proof -
nipkow@29667
   477
  have "a * (b * inverse b) * inverse a = 1" using assms by simp
nipkow@29667
   478
  hence "a * b * (inverse b * inverse a) = 1" by (simp only: mult_assoc)
nipkow@29667
   479
  thus ?thesis by (rule inverse_unique)
haftmann@26274
   480
qed
haftmann@26274
   481
haftmann@26274
   482
lemma division_ring_inverse_add:
haftmann@26274
   483
  "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a + inverse b = inverse a * (a + b) * inverse b"
nipkow@29667
   484
by (simp add: algebra_simps)
haftmann@26274
   485
haftmann@26274
   486
lemma division_ring_inverse_diff:
haftmann@26274
   487
  "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a - inverse b = inverse a * (b - a) * inverse b"
nipkow@29667
   488
by (simp add: algebra_simps)
haftmann@26274
   489
haftmann@25186
   490
end
haftmann@25152
   491
haftmann@22390
   492
class mult_mono = times + zero + ord +
haftmann@25062
   493
  assumes mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
haftmann@25062
   494
  assumes mult_right_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c"
paulson@14267
   495
haftmann@35302
   496
text {*
haftmann@35302
   497
  The theory of partially ordered rings is taken from the books:
haftmann@35302
   498
  \begin{itemize}
haftmann@35302
   499
  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
haftmann@35302
   500
  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
haftmann@35302
   501
  \end{itemize}
haftmann@35302
   502
  Most of the used notions can also be looked up in 
haftmann@35302
   503
  \begin{itemize}
haftmann@35302
   504
  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
haftmann@35302
   505
  \item \emph{Algebra I} by van der Waerden, Springer.
haftmann@35302
   506
  \end{itemize}
haftmann@35302
   507
*}
haftmann@35302
   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"])
huffman@35216
   767
  apply simp_all
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"])
huffman@35216
   773
  apply simp_all
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>"
huffman@35216
   794
    by (auto simp add: abs_if not_less)
huffman@35216
   795
    (auto simp del: minus_add_distrib simp add: minus_add_distrib [symmetric],
huffman@35216
   796
     auto intro: add_nonneg_nonneg, auto intro!: less_imp_le add_neg_neg)
huffman@35216
   797
qed (auto simp add: abs_if)
haftmann@25304
   798
haftmann@25304
   799
end
obua@23521
   800
haftmann@35028
   801
(* The "strict" suffix can be seen as describing the combination of linordered_ring and no_zero_divisors.
haftmann@35043
   802
   Basically, linordered_ring + no_zero_divisors = linordered_ring_strict.
haftmann@25230
   803
 *)
haftmann@35043
   804
class linordered_ring_strict = ring + linordered_semiring_strict
haftmann@25304
   805
  + ordered_ab_group_add + abs_if
haftmann@25230
   806
begin
paulson@14348
   807
haftmann@35028
   808
subclass linordered_ring ..
haftmann@25304
   809
huffman@30692
   810
lemma mult_strict_left_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> c * a < c * b"
huffman@30692
   811
using mult_strict_left_mono [of b a "- c"] by simp
huffman@30692
   812
huffman@30692
   813
lemma mult_strict_right_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> a * c < b * c"
huffman@30692
   814
using mult_strict_right_mono [of b a "- c"] by simp
huffman@30692
   815
huffman@30692
   816
lemma mult_neg_neg: "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> 0 < a * b"
huffman@30692
   817
using mult_strict_right_mono_neg [of a zero b] by simp
obua@14738
   818
haftmann@25917
   819
subclass ring_no_zero_divisors
haftmann@28823
   820
proof
haftmann@25917
   821
  fix a b
haftmann@25917
   822
  assume "a \<noteq> 0" then have A: "a < 0 \<or> 0 < a" by (simp add: neq_iff)
haftmann@25917
   823
  assume "b \<noteq> 0" then have B: "b < 0 \<or> 0 < b" by (simp add: neq_iff)
haftmann@25917
   824
  have "a * b < 0 \<or> 0 < a * b"
haftmann@25917
   825
  proof (cases "a < 0")
haftmann@25917
   826
    case True note A' = this
haftmann@25917
   827
    show ?thesis proof (cases "b < 0")
haftmann@25917
   828
      case True with A'
haftmann@25917
   829
      show ?thesis by (auto dest: mult_neg_neg)
haftmann@25917
   830
    next
haftmann@25917
   831
      case False with B have "0 < b" by auto
haftmann@25917
   832
      with A' show ?thesis by (auto dest: mult_strict_right_mono)
haftmann@25917
   833
    qed
haftmann@25917
   834
  next
haftmann@25917
   835
    case False with A have A': "0 < a" by auto
haftmann@25917
   836
    show ?thesis proof (cases "b < 0")
haftmann@25917
   837
      case True with A'
haftmann@25917
   838
      show ?thesis by (auto dest: mult_strict_right_mono_neg)
haftmann@25917
   839
    next
haftmann@25917
   840
      case False with B have "0 < b" by auto
haftmann@25917
   841
      with A' show ?thesis by (auto dest: mult_pos_pos)
haftmann@25917
   842
    qed
haftmann@25917
   843
  qed
haftmann@25917
   844
  then show "a * b \<noteq> 0" by (simp add: neq_iff)
haftmann@25917
   845
qed
haftmann@25304
   846
paulson@14265
   847
lemma zero_less_mult_iff:
haftmann@25917
   848
  "0 < a * b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0"
haftmann@25917
   849
  apply (auto simp add: mult_pos_pos mult_neg_neg)
haftmann@25917
   850
  apply (simp_all add: not_less le_less)
haftmann@25917
   851
  apply (erule disjE) apply assumption defer
haftmann@25917
   852
  apply (erule disjE) defer apply (drule sym) apply simp
haftmann@25917
   853
  apply (erule disjE) defer apply (drule sym) apply simp
haftmann@25917
   854
  apply (erule disjE) apply assumption apply (drule sym) apply simp
haftmann@25917
   855
  apply (drule sym) apply simp
haftmann@25917
   856
  apply (blast dest: zero_less_mult_pos)
haftmann@25230
   857
  apply (blast dest: zero_less_mult_pos2)
haftmann@25230
   858
  done
huffman@22990
   859
paulson@14265
   860
lemma zero_le_mult_iff:
haftmann@25917
   861
  "0 \<le> a * b \<longleftrightarrow> 0 \<le> a \<and> 0 \<le> b \<or> a \<le> 0 \<and> b \<le> 0"
nipkow@29667
   862
by (auto simp add: eq_commute [of 0] le_less not_less zero_less_mult_iff)
paulson@14265
   863
paulson@14265
   864
lemma mult_less_0_iff:
haftmann@25917
   865
  "a * b < 0 \<longleftrightarrow> 0 < a \<and> b < 0 \<or> a < 0 \<and> 0 < b"
huffman@35216
   866
  apply (insert zero_less_mult_iff [of "-a" b])
huffman@35216
   867
  apply force
haftmann@25917
   868
  done
paulson@14265
   869
paulson@14265
   870
lemma mult_le_0_iff:
haftmann@25917
   871
  "a * b \<le> 0 \<longleftrightarrow> 0 \<le> a \<and> b \<le> 0 \<or> a \<le> 0 \<and> 0 \<le> b"
haftmann@25917
   872
  apply (insert zero_le_mult_iff [of "-a" b]) 
huffman@35216
   873
  apply force
haftmann@25917
   874
  done
haftmann@25917
   875
haftmann@25917
   876
lemma zero_le_square [simp]: "0 \<le> a * a"
nipkow@29667
   877
by (simp add: zero_le_mult_iff linear)
haftmann@25917
   878
haftmann@25917
   879
lemma not_square_less_zero [simp]: "\<not> (a * a < 0)"
nipkow@29667
   880
by (simp add: not_less)
haftmann@25917
   881
haftmann@26193
   882
text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
haftmann@26193
   883
   also with the relations @{text "\<le>"} and equality.*}
haftmann@26193
   884
haftmann@26193
   885
text{*These ``disjunction'' versions produce two cases when the comparison is
haftmann@26193
   886
 an assumption, but effectively four when the comparison is a goal.*}
haftmann@26193
   887
haftmann@26193
   888
lemma mult_less_cancel_right_disj:
haftmann@26193
   889
  "a * c < b * c \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
   890
  apply (cases "c = 0")
haftmann@26193
   891
  apply (auto simp add: neq_iff mult_strict_right_mono 
haftmann@26193
   892
                      mult_strict_right_mono_neg)
haftmann@26193
   893
  apply (auto simp add: not_less 
haftmann@26193
   894
                      not_le [symmetric, of "a*c"]
haftmann@26193
   895
                      not_le [symmetric, of a])
haftmann@26193
   896
  apply (erule_tac [!] notE)
haftmann@26193
   897
  apply (auto simp add: less_imp_le mult_right_mono 
haftmann@26193
   898
                      mult_right_mono_neg)
haftmann@26193
   899
  done
haftmann@26193
   900
haftmann@26193
   901
lemma mult_less_cancel_left_disj:
haftmann@26193
   902
  "c * a < c * b \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
   903
  apply (cases "c = 0")
haftmann@26193
   904
  apply (auto simp add: neq_iff mult_strict_left_mono 
haftmann@26193
   905
                      mult_strict_left_mono_neg)
haftmann@26193
   906
  apply (auto simp add: not_less 
haftmann@26193
   907
                      not_le [symmetric, of "c*a"]
haftmann@26193
   908
                      not_le [symmetric, of a])
haftmann@26193
   909
  apply (erule_tac [!] notE)
haftmann@26193
   910
  apply (auto simp add: less_imp_le mult_left_mono 
haftmann@26193
   911
                      mult_left_mono_neg)
haftmann@26193
   912
  done
haftmann@26193
   913
haftmann@26193
   914
text{*The ``conjunction of implication'' lemmas produce two cases when the
haftmann@26193
   915
comparison is a goal, but give four when the comparison is an assumption.*}
haftmann@26193
   916
haftmann@26193
   917
lemma mult_less_cancel_right:
haftmann@26193
   918
  "a * c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
   919
  using mult_less_cancel_right_disj [of a c b] by auto
haftmann@26193
   920
haftmann@26193
   921
lemma mult_less_cancel_left:
haftmann@26193
   922
  "c * a < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
   923
  using mult_less_cancel_left_disj [of c a b] by auto
haftmann@26193
   924
haftmann@26193
   925
lemma mult_le_cancel_right:
haftmann@26193
   926
   "a * c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
nipkow@29667
   927
by (simp add: not_less [symmetric] mult_less_cancel_right_disj)
haftmann@26193
   928
haftmann@26193
   929
lemma mult_le_cancel_left:
haftmann@26193
   930
  "c * a \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
nipkow@29667
   931
by (simp add: not_less [symmetric] mult_less_cancel_left_disj)
haftmann@26193
   932
nipkow@30649
   933
lemma mult_le_cancel_left_pos:
nipkow@30649
   934
  "0 < c \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> a \<le> b"
nipkow@30649
   935
by (auto simp: mult_le_cancel_left)
nipkow@30649
   936
nipkow@30649
   937
lemma mult_le_cancel_left_neg:
nipkow@30649
   938
  "c < 0 \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> b \<le> a"
nipkow@30649
   939
by (auto simp: mult_le_cancel_left)
nipkow@30649
   940
nipkow@30649
   941
lemma mult_less_cancel_left_pos:
nipkow@30649
   942
  "0 < c \<Longrightarrow> c * a < c * b \<longleftrightarrow> a < b"
nipkow@30649
   943
by (auto simp: mult_less_cancel_left)
nipkow@30649
   944
nipkow@30649
   945
lemma mult_less_cancel_left_neg:
nipkow@30649
   946
  "c < 0 \<Longrightarrow> c * a < c * b \<longleftrightarrow> b < a"
nipkow@30649
   947
by (auto simp: mult_less_cancel_left)
nipkow@30649
   948
haftmann@25917
   949
end
paulson@14265
   950
nipkow@29667
   951
text{*Legacy - use @{text algebra_simps} *}
nipkow@29833
   952
lemmas ring_simps[noatp] = algebra_simps
haftmann@25230
   953
huffman@30692
   954
lemmas mult_sign_intros =
huffman@30692
   955
  mult_nonneg_nonneg mult_nonneg_nonpos
huffman@30692
   956
  mult_nonpos_nonneg mult_nonpos_nonpos
huffman@30692
   957
  mult_pos_pos mult_pos_neg
huffman@30692
   958
  mult_neg_pos mult_neg_neg
haftmann@25230
   959
haftmann@35028
   960
class ordered_comm_ring = comm_ring + ordered_comm_semiring
haftmann@25267
   961
begin
haftmann@25230
   962
haftmann@35028
   963
subclass ordered_ring ..
haftmann@35028
   964
subclass ordered_cancel_comm_semiring ..
haftmann@25230
   965
haftmann@25267
   966
end
haftmann@25230
   967
haftmann@35028
   968
class linordered_semidom = comm_semiring_1_cancel + linordered_comm_semiring_strict +
haftmann@35028
   969
  (*previously linordered_semiring*)
haftmann@25230
   970
  assumes zero_less_one [simp]: "0 < 1"
haftmann@25230
   971
begin
haftmann@25230
   972
haftmann@25230
   973
lemma pos_add_strict:
haftmann@25230
   974
  shows "0 < a \<Longrightarrow> b < c \<Longrightarrow> b < a + c"
haftmann@25230
   975
  using add_strict_mono [of zero a b c] by simp
haftmann@25230
   976
haftmann@26193
   977
lemma zero_le_one [simp]: "0 \<le> 1"
nipkow@29667
   978
by (rule zero_less_one [THEN less_imp_le]) 
haftmann@26193
   979
haftmann@26193
   980
lemma not_one_le_zero [simp]: "\<not> 1 \<le> 0"
nipkow@29667
   981
by (simp add: not_le) 
haftmann@26193
   982
haftmann@26193
   983
lemma not_one_less_zero [simp]: "\<not> 1 < 0"
nipkow@29667
   984
by (simp add: not_less) 
haftmann@26193
   985
haftmann@26193
   986
lemma less_1_mult:
haftmann@26193
   987
  assumes "1 < m" and "1 < n"
haftmann@26193
   988
  shows "1 < m * n"
haftmann@26193
   989
  using assms mult_strict_mono [of 1 m 1 n]
haftmann@26193
   990
    by (simp add:  less_trans [OF zero_less_one]) 
haftmann@26193
   991
haftmann@25230
   992
end
haftmann@25230
   993
haftmann@35028
   994
class linordered_idom = comm_ring_1 +
haftmann@35028
   995
  linordered_comm_semiring_strict + ordered_ab_group_add +
haftmann@25230
   996
  abs_if + sgn_if
haftmann@35028
   997
  (*previously linordered_ring*)
haftmann@25917
   998
begin
haftmann@25917
   999
haftmann@35043
  1000
subclass linordered_ring_strict ..
haftmann@35028
  1001
subclass ordered_comm_ring ..
huffman@27516
  1002
subclass idom ..
haftmann@25917
  1003
haftmann@35028
  1004
subclass linordered_semidom
haftmann@28823
  1005
proof
haftmann@26193
  1006
  have "0 \<le> 1 * 1" by (rule zero_le_square)
haftmann@26193
  1007
  thus "0 < 1" by (simp add: le_less)
haftmann@25917
  1008
qed 
haftmann@25917
  1009
haftmann@35028
  1010
lemma linorder_neqE_linordered_idom:
haftmann@26193
  1011
  assumes "x \<noteq> y" obtains "x < y" | "y < x"
haftmann@26193
  1012
  using assms by (rule neqE)
haftmann@26193
  1013
haftmann@26274
  1014
text {* These cancellation simprules also produce two cases when the comparison is a goal. *}
haftmann@26274
  1015
haftmann@26274
  1016
lemma mult_le_cancel_right1:
haftmann@26274
  1017
  "c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
nipkow@29667
  1018
by (insert mult_le_cancel_right [of 1 c b], simp)
haftmann@26274
  1019
haftmann@26274
  1020
lemma mult_le_cancel_right2:
haftmann@26274
  1021
  "a * c \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
nipkow@29667
  1022
by (insert mult_le_cancel_right [of a c 1], simp)
haftmann@26274
  1023
haftmann@26274
  1024
lemma mult_le_cancel_left1:
haftmann@26274
  1025
  "c \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
nipkow@29667
  1026
by (insert mult_le_cancel_left [of c 1 b], simp)
haftmann@26274
  1027
haftmann@26274
  1028
lemma mult_le_cancel_left2:
haftmann@26274
  1029
  "c * a \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
nipkow@29667
  1030
by (insert mult_le_cancel_left [of c a 1], simp)
haftmann@26274
  1031
haftmann@26274
  1032
lemma mult_less_cancel_right1:
haftmann@26274
  1033
  "c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
nipkow@29667
  1034
by (insert mult_less_cancel_right [of 1 c b], simp)
haftmann@26274
  1035
haftmann@26274
  1036
lemma mult_less_cancel_right2:
haftmann@26274
  1037
  "a * c < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
nipkow@29667
  1038
by (insert mult_less_cancel_right [of a c 1], simp)
haftmann@26274
  1039
haftmann@26274
  1040
lemma mult_less_cancel_left1:
haftmann@26274
  1041
  "c < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
nipkow@29667
  1042
by (insert mult_less_cancel_left [of c 1 b], simp)
haftmann@26274
  1043
haftmann@26274
  1044
lemma mult_less_cancel_left2:
haftmann@26274
  1045
  "c * a < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
nipkow@29667
  1046
by (insert mult_less_cancel_left [of c a 1], simp)
haftmann@26274
  1047
haftmann@27651
  1048
lemma sgn_sgn [simp]:
haftmann@27651
  1049
  "sgn (sgn a) = sgn a"
nipkow@29700
  1050
unfolding sgn_if by simp
haftmann@27651
  1051
haftmann@27651
  1052
lemma sgn_0_0:
haftmann@27651
  1053
  "sgn a = 0 \<longleftrightarrow> a = 0"
nipkow@29700
  1054
unfolding sgn_if by simp
haftmann@27651
  1055
haftmann@27651
  1056
lemma sgn_1_pos:
haftmann@27651
  1057
  "sgn a = 1 \<longleftrightarrow> a > 0"
huffman@35216
  1058
unfolding sgn_if by simp
haftmann@27651
  1059
haftmann@27651
  1060
lemma sgn_1_neg:
haftmann@27651
  1061
  "sgn a = - 1 \<longleftrightarrow> a < 0"
huffman@35216
  1062
unfolding sgn_if by auto
haftmann@27651
  1063
haftmann@29940
  1064
lemma sgn_pos [simp]:
haftmann@29940
  1065
  "0 < a \<Longrightarrow> sgn a = 1"
haftmann@29940
  1066
unfolding sgn_1_pos .
haftmann@29940
  1067
haftmann@29940
  1068
lemma sgn_neg [simp]:
haftmann@29940
  1069
  "a < 0 \<Longrightarrow> sgn a = - 1"
haftmann@29940
  1070
unfolding sgn_1_neg .
haftmann@29940
  1071
haftmann@27651
  1072
lemma sgn_times:
haftmann@27651
  1073
  "sgn (a * b) = sgn a * sgn b"
nipkow@29667
  1074
by (auto simp add: sgn_if zero_less_mult_iff)
haftmann@27651
  1075
haftmann@29653
  1076
lemma abs_sgn: "abs k = k * sgn k"
nipkow@29700
  1077
unfolding sgn_if abs_if by auto
nipkow@29700
  1078
haftmann@29940
  1079
lemma sgn_greater [simp]:
haftmann@29940
  1080
  "0 < sgn a \<longleftrightarrow> 0 < a"
haftmann@29940
  1081
  unfolding sgn_if by auto
haftmann@29940
  1082
haftmann@29940
  1083
lemma sgn_less [simp]:
haftmann@29940
  1084
  "sgn a < 0 \<longleftrightarrow> a < 0"
haftmann@29940
  1085
  unfolding sgn_if by auto
haftmann@29940
  1086
huffman@29949
  1087
lemma abs_dvd_iff [simp]: "(abs m) dvd k \<longleftrightarrow> m dvd k"
huffman@29949
  1088
  by (simp add: abs_if)
huffman@29949
  1089
huffman@29949
  1090
lemma dvd_abs_iff [simp]: "m dvd (abs k) \<longleftrightarrow> m dvd k"
huffman@29949
  1091
  by (simp add: abs_if)
haftmann@29653
  1092
nipkow@33676
  1093
lemma dvd_if_abs_eq:
nipkow@33676
  1094
  "abs l = abs (k) \<Longrightarrow> l dvd k"
nipkow@33676
  1095
by(subst abs_dvd_iff[symmetric]) simp
nipkow@33676
  1096
haftmann@25917
  1097
end
haftmann@25230
  1098
haftmann@26274
  1099
text {* Simprules for comparisons where common factors can be cancelled. *}
paulson@15234
  1100
nipkow@29833
  1101
lemmas mult_compare_simps[noatp] =
paulson@15234
  1102
    mult_le_cancel_right mult_le_cancel_left
paulson@15234
  1103
    mult_le_cancel_right1 mult_le_cancel_right2
paulson@15234
  1104
    mult_le_cancel_left1 mult_le_cancel_left2
paulson@15234
  1105
    mult_less_cancel_right mult_less_cancel_left
paulson@15234
  1106
    mult_less_cancel_right1 mult_less_cancel_right2
paulson@15234
  1107
    mult_less_cancel_left1 mult_less_cancel_left2
paulson@15234
  1108
    mult_cancel_right mult_cancel_left
paulson@15234
  1109
    mult_cancel_right1 mult_cancel_right2
paulson@15234
  1110
    mult_cancel_left1 mult_cancel_left2
paulson@15234
  1111
haftmann@26274
  1112
-- {* FIXME continue localization here *}
paulson@14268
  1113
avigad@16775
  1114
subsection {* Reasoning about inequalities with division *}
avigad@16775
  1115
haftmann@35028
  1116
lemma mult_right_le_one_le: "0 <= (x::'a::linordered_idom) ==> 0 <= y ==> y <= 1
avigad@16775
  1117
    ==> x * y <= x"
huffman@35216
  1118
by (auto simp add: mult_le_cancel_left2)
avigad@16775
  1119
haftmann@35028
  1120
lemma mult_left_le_one_le: "0 <= (x::'a::linordered_idom) ==> 0 <= y ==> y <= 1
avigad@16775
  1121
    ==> y * x <= x"
huffman@35216
  1122
by (auto simp add: mult_le_cancel_right2)
avigad@16775
  1123
haftmann@35028
  1124
context linordered_semidom
haftmann@25193
  1125
begin
haftmann@25193
  1126
haftmann@25193
  1127
lemma less_add_one: "a < a + 1"
paulson@14293
  1128
proof -
haftmann@25193
  1129
  have "a + 0 < a + 1"
nipkow@23482
  1130
    by (blast intro: zero_less_one add_strict_left_mono)
paulson@14293
  1131
  thus ?thesis by simp
paulson@14293
  1132
qed
paulson@14293
  1133
haftmann@25193
  1134
lemma zero_less_two: "0 < 1 + 1"
nipkow@29667
  1135
by (blast intro: less_trans zero_less_one less_add_one)
haftmann@25193
  1136
haftmann@25193
  1137
end
paulson@14365
  1138
paulson@15234
  1139
paulson@14293
  1140
subsection {* Absolute Value *}
paulson@14293
  1141
haftmann@35028
  1142
context linordered_idom
haftmann@25304
  1143
begin
haftmann@25304
  1144
haftmann@25304
  1145
lemma mult_sgn_abs: "sgn x * abs x = x"
haftmann@25304
  1146
  unfolding abs_if sgn_if by auto
haftmann@25304
  1147
haftmann@25304
  1148
end
nipkow@24491
  1149
haftmann@35028
  1150
lemma abs_one [simp]: "abs 1 = (1::'a::linordered_idom)"
nipkow@29667
  1151
by (simp add: abs_if zero_less_one [THEN order_less_not_sym])
haftmann@25304
  1152
haftmann@35028
  1153
class ordered_ring_abs = ordered_ring + ordered_ab_group_add_abs +
haftmann@25304
  1154
  assumes abs_eq_mult:
haftmann@25304
  1155
    "(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
  1156
haftmann@35028
  1157
context linordered_idom
haftmann@30961
  1158
begin
haftmann@30961
  1159
haftmann@35028
  1160
subclass ordered_ring_abs proof
huffman@35216
  1161
qed (auto simp add: abs_if not_less mult_less_0_iff)
haftmann@30961
  1162
haftmann@30961
  1163
lemma abs_mult:
haftmann@30961
  1164
  "abs (a * b) = abs a * abs b" 
haftmann@30961
  1165
  by (rule abs_eq_mult) auto
haftmann@30961
  1166
haftmann@30961
  1167
lemma abs_mult_self:
haftmann@30961
  1168
  "abs a * abs a = a * a"
haftmann@30961
  1169
  by (simp add: abs_if) 
haftmann@30961
  1170
haftmann@30961
  1171
end
paulson@14294
  1172
paulson@14294
  1173
lemma abs_mult_less:
haftmann@35028
  1174
     "[| abs a < c; abs b < d |] ==> abs a * abs b < c*(d::'a::linordered_idom)"
paulson@14294
  1175
proof -
paulson@14294
  1176
  assume ac: "abs a < c"
paulson@14294
  1177
  hence cpos: "0<c" by (blast intro: order_le_less_trans abs_ge_zero)
paulson@14294
  1178
  assume "abs b < d"
paulson@14294
  1179
  thus ?thesis by (simp add: ac cpos mult_strict_mono) 
paulson@14294
  1180
qed
paulson@14293
  1181
nipkow@29833
  1182
lemmas eq_minus_self_iff[noatp] = equal_neg_zero
obua@14738
  1183
haftmann@35028
  1184
lemma less_minus_self_iff: "(a < -a) = (a < (0::'a::linordered_idom))"
haftmann@25304
  1185
  unfolding order_less_le less_eq_neg_nonpos equal_neg_zero ..
obua@14738
  1186
haftmann@35028
  1187
lemma abs_less_iff: "(abs a < b) = (a < b & -a < (b::'a::linordered_idom))" 
obua@14738
  1188
apply (simp add: order_less_le abs_le_iff)  
huffman@35216
  1189
apply (auto simp add: abs_if)
obua@14738
  1190
done
obua@14738
  1191
haftmann@35028
  1192
lemma abs_mult_pos: "(0::'a::linordered_idom) <= x ==> 
haftmann@25304
  1193
    (abs y) * x = abs (y * x)"
haftmann@25304
  1194
  apply (subst abs_mult)
haftmann@25304
  1195
  apply simp
haftmann@25304
  1196
done
avigad@16775
  1197
haftmann@33364
  1198
code_modulename SML
haftmann@35050
  1199
  Rings Arith
haftmann@33364
  1200
haftmann@33364
  1201
code_modulename OCaml
haftmann@35050
  1202
  Rings Arith
haftmann@33364
  1203
haftmann@33364
  1204
code_modulename Haskell
haftmann@35050
  1205
  Rings Arith
haftmann@33364
  1206
paulson@14265
  1207
end