src/HOL/Rings.thy
author haftmann
Thu Oct 31 11:44:20 2013 +0100 (2013-10-31)
changeset 54225 8a49a5a30284
parent 54147 97a8ff4e4ac9
child 54230 b1d955791529
permissions -rw-r--r--
generalized of_bool conversion
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 +
webertj@49962
    17
  assumes distrib_right[algebra_simps, field_simps]: "(a + b) * c = a * c + b * c"
webertj@49962
    18
  assumes distrib_left[algebra_simps, field_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"
webertj@49962
    24
by (simp add: distrib_right 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
webertj@49962
    40
  have "0 * a + 0 * a = 0 * a + 0" by (simp add: distrib_right [symmetric])
nipkow@29667
    41
  thus "0 * a = 0" by (simp only: add_left_cancel)
haftmann@25152
    42
next
haftmann@25152
    43
  fix a :: 'a
webertj@49962
    44
  have "a * 0 + a * 0 = a * 0 + 0" by (simp add: distrib_left [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@54225
    89
definition of_bool :: "bool \<Rightarrow> 'a"
haftmann@54225
    90
where
haftmann@54225
    91
  "of_bool p = (if p then 1 else 0)" 
haftmann@54225
    92
haftmann@54225
    93
lemma of_bool_eq [simp, code]:
haftmann@54225
    94
  "of_bool False = 0"
haftmann@54225
    95
  "of_bool True = 1"
haftmann@54225
    96
  by (simp_all add: of_bool_def)
haftmann@54225
    97
haftmann@54225
    98
lemma of_bool_eq_iff:
haftmann@54225
    99
  "of_bool p = of_bool q \<longleftrightarrow> p = q"
haftmann@54225
   100
  by (simp add: of_bool_def)
haftmann@54225
   101
haftmann@54225
   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
nipkow@50420
   111
definition dvd :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "dvd" 50) where
haftmann@37767
   112
  "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
blanchet@54147
   143
lemma dvd_0_left_iff [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'" ..
webertj@49962
   193
  ultimately have "b + c = a * (b' + c')" by (simp add: distrib_left)
haftmann@27651
   194
  then show ?thesis ..
haftmann@27651
   195
qed
haftmann@27651
   196
haftmann@25152
   197
end
paulson@14421
   198
haftmann@22390
   199
class no_zero_divisors = zero + times +
haftmann@25062
   200
  assumes no_zero_divisors: "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a * b \<noteq> 0"
haftmann@36719
   201
begin
haftmann@36719
   202
haftmann@36719
   203
lemma divisors_zero:
haftmann@36719
   204
  assumes "a * b = 0"
haftmann@36719
   205
  shows "a = 0 \<or> b = 0"
haftmann@36719
   206
proof (rule classical)
haftmann@36719
   207
  assume "\<not> (a = 0 \<or> b = 0)"
haftmann@36719
   208
  then have "a \<noteq> 0" and "b \<noteq> 0" by auto
haftmann@36719
   209
  with no_zero_divisors have "a * b \<noteq> 0" by blast
haftmann@36719
   210
  with assms show ?thesis by simp
haftmann@36719
   211
qed
haftmann@36719
   212
haftmann@36719
   213
end
paulson@14504
   214
huffman@29904
   215
class semiring_1_cancel = semiring + cancel_comm_monoid_add
huffman@29904
   216
  + zero_neq_one + monoid_mult
haftmann@25267
   217
begin
obua@14940
   218
huffman@27516
   219
subclass semiring_0_cancel ..
haftmann@25512
   220
huffman@27516
   221
subclass semiring_1 ..
haftmann@25267
   222
haftmann@25267
   223
end
krauss@21199
   224
huffman@29904
   225
class comm_semiring_1_cancel = comm_semiring + cancel_comm_monoid_add
huffman@29904
   226
  + zero_neq_one + comm_monoid_mult
haftmann@25267
   227
begin
obua@14738
   228
huffman@27516
   229
subclass semiring_1_cancel ..
huffman@27516
   230
subclass comm_semiring_0_cancel ..
huffman@27516
   231
subclass comm_semiring_1 ..
haftmann@25267
   232
haftmann@25267
   233
end
haftmann@25152
   234
haftmann@22390
   235
class ring = semiring + ab_group_add
haftmann@25267
   236
begin
haftmann@25152
   237
huffman@27516
   238
subclass semiring_0_cancel ..
haftmann@25152
   239
haftmann@25152
   240
text {* Distribution rules *}
haftmann@25152
   241
haftmann@25152
   242
lemma minus_mult_left: "- (a * b) = - a * b"
webertj@49962
   243
by (rule minus_unique) (simp add: distrib_right [symmetric]) 
haftmann@25152
   244
haftmann@25152
   245
lemma minus_mult_right: "- (a * b) = a * - b"
webertj@49962
   246
by (rule minus_unique) (simp add: distrib_left [symmetric]) 
haftmann@25152
   247
huffman@29407
   248
text{*Extract signs from products*}
blanchet@54147
   249
lemmas mult_minus_left [simp] = minus_mult_left [symmetric]
blanchet@54147
   250
lemmas mult_minus_right [simp] = minus_mult_right [symmetric]
huffman@29407
   251
haftmann@25152
   252
lemma minus_mult_minus [simp]: "- a * - b = a * b"
nipkow@29667
   253
by simp
haftmann@25152
   254
haftmann@25152
   255
lemma minus_mult_commute: "- a * b = a * - b"
nipkow@29667
   256
by simp
nipkow@29667
   257
haftmann@36348
   258
lemma right_diff_distrib[algebra_simps, field_simps]: "a * (b - c) = a * b - a * c"
webertj@49962
   259
by (simp add: distrib_left diff_minus)
nipkow@29667
   260
haftmann@36348
   261
lemma left_diff_distrib[algebra_simps, field_simps]: "(a - b) * c = a * c - b * c"
webertj@49962
   262
by (simp add: distrib_right diff_minus)
haftmann@25152
   263
blanchet@54147
   264
lemmas ring_distribs =
webertj@49962
   265
  distrib_left distrib_right left_diff_distrib right_diff_distrib
haftmann@25152
   266
haftmann@25230
   267
lemma eq_add_iff1:
haftmann@25230
   268
  "a * e + c = b * e + d \<longleftrightarrow> (a - b) * e + c = d"
nipkow@29667
   269
by (simp add: algebra_simps)
haftmann@25230
   270
haftmann@25230
   271
lemma eq_add_iff2:
haftmann@25230
   272
  "a * e + c = b * e + d \<longleftrightarrow> c = (b - a) * e + d"
nipkow@29667
   273
by (simp add: algebra_simps)
haftmann@25230
   274
haftmann@25152
   275
end
haftmann@25152
   276
blanchet@54147
   277
lemmas ring_distribs =
webertj@49962
   278
  distrib_left distrib_right left_diff_distrib right_diff_distrib
haftmann@25152
   279
haftmann@22390
   280
class comm_ring = comm_semiring + ab_group_add
haftmann@25267
   281
begin
obua@14738
   282
huffman@27516
   283
subclass ring ..
huffman@28141
   284
subclass comm_semiring_0_cancel ..
haftmann@25267
   285
huffman@44350
   286
lemma square_diff_square_factored:
huffman@44350
   287
  "x * x - y * y = (x + y) * (x - y)"
huffman@44350
   288
  by (simp add: algebra_simps)
huffman@44350
   289
haftmann@25267
   290
end
obua@14738
   291
haftmann@22390
   292
class ring_1 = ring + zero_neq_one + monoid_mult
haftmann@25267
   293
begin
paulson@14265
   294
huffman@27516
   295
subclass semiring_1_cancel ..
haftmann@25267
   296
huffman@44346
   297
lemma square_diff_one_factored:
huffman@44346
   298
  "x * x - 1 = (x + 1) * (x - 1)"
huffman@44346
   299
  by (simp add: algebra_simps)
huffman@44346
   300
haftmann@25267
   301
end
haftmann@25152
   302
haftmann@22390
   303
class comm_ring_1 = comm_ring + zero_neq_one + comm_monoid_mult
haftmann@22390
   304
  (*previously ring*)
haftmann@25267
   305
begin
obua@14738
   306
huffman@27516
   307
subclass ring_1 ..
huffman@27516
   308
subclass comm_semiring_1_cancel ..
haftmann@25267
   309
huffman@29465
   310
lemma dvd_minus_iff [simp]: "x dvd - y \<longleftrightarrow> x dvd y"
huffman@29408
   311
proof
huffman@29408
   312
  assume "x dvd - y"
huffman@29408
   313
  then have "x dvd - 1 * - y" by (rule dvd_mult)
huffman@29408
   314
  then show "x dvd y" by simp
huffman@29408
   315
next
huffman@29408
   316
  assume "x dvd y"
huffman@29408
   317
  then have "x dvd - 1 * y" by (rule dvd_mult)
huffman@29408
   318
  then show "x dvd - y" by simp
huffman@29408
   319
qed
huffman@29408
   320
huffman@29465
   321
lemma minus_dvd_iff [simp]: "- x dvd y \<longleftrightarrow> x dvd y"
huffman@29408
   322
proof
huffman@29408
   323
  assume "- x dvd y"
huffman@29408
   324
  then obtain k where "y = - x * k" ..
huffman@29408
   325
  then have "y = x * - k" by simp
huffman@29408
   326
  then show "x dvd y" ..
huffman@29408
   327
next
huffman@29408
   328
  assume "x dvd y"
huffman@29408
   329
  then obtain k where "y = x * k" ..
huffman@29408
   330
  then have "y = - x * - k" by simp
huffman@29408
   331
  then show "- x dvd y" ..
huffman@29408
   332
qed
huffman@29408
   333
nipkow@30042
   334
lemma dvd_diff[simp]: "x dvd y \<Longrightarrow> x dvd z \<Longrightarrow> x dvd (y - z)"
huffman@35216
   335
by (simp only: diff_minus dvd_add dvd_minus_iff)
huffman@29409
   336
haftmann@25267
   337
end
haftmann@25152
   338
huffman@22990
   339
class ring_no_zero_divisors = ring + no_zero_divisors
haftmann@25230
   340
begin
haftmann@25230
   341
haftmann@25230
   342
lemma mult_eq_0_iff [simp]:
haftmann@25230
   343
  shows "a * b = 0 \<longleftrightarrow> (a = 0 \<or> b = 0)"
haftmann@25230
   344
proof (cases "a = 0 \<or> b = 0")
haftmann@25230
   345
  case False then have "a \<noteq> 0" and "b \<noteq> 0" by auto
haftmann@25230
   346
    then show ?thesis using no_zero_divisors by simp
haftmann@25230
   347
next
haftmann@25230
   348
  case True then show ?thesis by auto
haftmann@25230
   349
qed
haftmann@25230
   350
haftmann@26193
   351
text{*Cancellation of equalities with a common factor*}
blanchet@54147
   352
lemma mult_cancel_right [simp]:
haftmann@26193
   353
  "a * c = b * c \<longleftrightarrow> c = 0 \<or> a = b"
haftmann@26193
   354
proof -
haftmann@26193
   355
  have "(a * c = b * c) = ((a - b) * c = 0)"
huffman@35216
   356
    by (simp add: algebra_simps)
huffman@35216
   357
  thus ?thesis by (simp add: disj_commute)
haftmann@26193
   358
qed
haftmann@26193
   359
blanchet@54147
   360
lemma mult_cancel_left [simp]:
haftmann@26193
   361
  "c * a = c * b \<longleftrightarrow> c = 0 \<or> a = b"
haftmann@26193
   362
proof -
haftmann@26193
   363
  have "(c * a = c * b) = (c * (a - b) = 0)"
huffman@35216
   364
    by (simp add: algebra_simps)
huffman@35216
   365
  thus ?thesis by simp
haftmann@26193
   366
qed
haftmann@26193
   367
haftmann@25230
   368
end
huffman@22990
   369
huffman@23544
   370
class ring_1_no_zero_divisors = ring_1 + ring_no_zero_divisors
haftmann@26274
   371
begin
haftmann@26274
   372
huffman@36970
   373
lemma square_eq_1_iff:
huffman@36821
   374
  "x * x = 1 \<longleftrightarrow> x = 1 \<or> x = - 1"
huffman@36821
   375
proof -
huffman@36821
   376
  have "(x - 1) * (x + 1) = x * x - 1"
huffman@36821
   377
    by (simp add: algebra_simps)
huffman@36821
   378
  hence "x * x = 1 \<longleftrightarrow> (x - 1) * (x + 1) = 0"
huffman@36821
   379
    by simp
huffman@36821
   380
  thus ?thesis
huffman@36821
   381
    by (simp add: eq_neg_iff_add_eq_0)
huffman@36821
   382
qed
huffman@36821
   383
haftmann@26274
   384
lemma mult_cancel_right1 [simp]:
haftmann@26274
   385
  "c = b * c \<longleftrightarrow> c = 0 \<or> b = 1"
nipkow@29667
   386
by (insert mult_cancel_right [of 1 c b], force)
haftmann@26274
   387
haftmann@26274
   388
lemma mult_cancel_right2 [simp]:
haftmann@26274
   389
  "a * c = c \<longleftrightarrow> c = 0 \<or> a = 1"
nipkow@29667
   390
by (insert mult_cancel_right [of a c 1], simp)
haftmann@26274
   391
 
haftmann@26274
   392
lemma mult_cancel_left1 [simp]:
haftmann@26274
   393
  "c = c * b \<longleftrightarrow> c = 0 \<or> b = 1"
nipkow@29667
   394
by (insert mult_cancel_left [of c 1 b], force)
haftmann@26274
   395
haftmann@26274
   396
lemma mult_cancel_left2 [simp]:
haftmann@26274
   397
  "c * a = c \<longleftrightarrow> c = 0 \<or> a = 1"
nipkow@29667
   398
by (insert mult_cancel_left [of c a 1], simp)
haftmann@26274
   399
haftmann@26274
   400
end
huffman@22990
   401
haftmann@22390
   402
class idom = comm_ring_1 + no_zero_divisors
haftmann@25186
   403
begin
paulson@14421
   404
huffman@27516
   405
subclass ring_1_no_zero_divisors ..
huffman@22990
   406
huffman@29915
   407
lemma square_eq_iff: "a * a = b * b \<longleftrightarrow> (a = b \<or> a = - b)"
huffman@29915
   408
proof
huffman@29915
   409
  assume "a * a = b * b"
huffman@29915
   410
  then have "(a - b) * (a + b) = 0"
huffman@29915
   411
    by (simp add: algebra_simps)
huffman@29915
   412
  then show "a = b \<or> a = - b"
huffman@35216
   413
    by (simp add: eq_neg_iff_add_eq_0)
huffman@29915
   414
next
huffman@29915
   415
  assume "a = b \<or> a = - b"
huffman@29915
   416
  then show "a * a = b * b" by auto
huffman@29915
   417
qed
huffman@29915
   418
huffman@29981
   419
lemma dvd_mult_cancel_right [simp]:
huffman@29981
   420
  "a * c dvd b * c \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   421
proof -
huffman@29981
   422
  have "a * c dvd b * c \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
huffman@29981
   423
    unfolding dvd_def by (simp add: mult_ac)
huffman@29981
   424
  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   425
    unfolding dvd_def by simp
huffman@29981
   426
  finally show ?thesis .
huffman@29981
   427
qed
huffman@29981
   428
huffman@29981
   429
lemma dvd_mult_cancel_left [simp]:
huffman@29981
   430
  "c * a dvd c * b \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   431
proof -
huffman@29981
   432
  have "c * a dvd c * b \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
huffman@29981
   433
    unfolding dvd_def by (simp add: mult_ac)
huffman@29981
   434
  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   435
    unfolding dvd_def by simp
huffman@29981
   436
  finally show ?thesis .
huffman@29981
   437
qed
huffman@29981
   438
haftmann@25186
   439
end
haftmann@25152
   440
haftmann@35302
   441
text {*
haftmann@35302
   442
  The theory of partially ordered rings is taken from the books:
haftmann@35302
   443
  \begin{itemize}
haftmann@35302
   444
  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
haftmann@35302
   445
  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
haftmann@35302
   446
  \end{itemize}
haftmann@35302
   447
  Most of the used notions can also be looked up in 
haftmann@35302
   448
  \begin{itemize}
haftmann@35302
   449
  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
haftmann@35302
   450
  \item \emph{Algebra I} by van der Waerden, Springer.
haftmann@35302
   451
  \end{itemize}
haftmann@35302
   452
*}
haftmann@35302
   453
haftmann@38642
   454
class ordered_semiring = semiring + comm_monoid_add + ordered_ab_semigroup_add +
haftmann@38642
   455
  assumes mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
haftmann@38642
   456
  assumes mult_right_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c"
haftmann@25230
   457
begin
haftmann@25230
   458
haftmann@25230
   459
lemma mult_mono:
haftmann@38642
   460
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * d"
haftmann@25230
   461
apply (erule mult_right_mono [THEN order_trans], assumption)
haftmann@25230
   462
apply (erule mult_left_mono, assumption)
haftmann@25230
   463
done
haftmann@25230
   464
haftmann@25230
   465
lemma mult_mono':
haftmann@38642
   466
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> a \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * d"
haftmann@25230
   467
apply (rule mult_mono)
haftmann@25230
   468
apply (fast intro: order_trans)+
haftmann@25230
   469
done
haftmann@25230
   470
haftmann@25230
   471
end
krauss@21199
   472
haftmann@38642
   473
class ordered_cancel_semiring = ordered_semiring + cancel_comm_monoid_add
haftmann@25267
   474
begin
paulson@14268
   475
huffman@27516
   476
subclass semiring_0_cancel ..
obua@23521
   477
haftmann@25230
   478
lemma mult_nonneg_nonneg: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a * b"
haftmann@36301
   479
using mult_left_mono [of 0 b a] by simp
haftmann@25230
   480
haftmann@25230
   481
lemma mult_nonneg_nonpos: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> a * b \<le> 0"
haftmann@36301
   482
using mult_left_mono [of b 0 a] by simp
huffman@30692
   483
huffman@30692
   484
lemma mult_nonpos_nonneg: "a \<le> 0 \<Longrightarrow> 0 \<le> b \<Longrightarrow> a * b \<le> 0"
haftmann@36301
   485
using mult_right_mono [of a 0 b] by simp
huffman@30692
   486
huffman@30692
   487
text {* Legacy - use @{text mult_nonpos_nonneg} *}
haftmann@25230
   488
lemma mult_nonneg_nonpos2: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> b * a \<le> 0" 
haftmann@36301
   489
by (drule mult_right_mono [of b 0], auto)
haftmann@25230
   490
haftmann@26234
   491
lemma split_mult_neg_le: "(0 \<le> a & b \<le> 0) | (a \<le> 0 & 0 \<le> b) \<Longrightarrow> a * b \<le> 0" 
nipkow@29667
   492
by (auto simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)
haftmann@25230
   493
haftmann@25230
   494
end
haftmann@25230
   495
haftmann@38642
   496
class linordered_semiring = ordered_semiring + linordered_cancel_ab_semigroup_add
haftmann@25267
   497
begin
haftmann@25230
   498
haftmann@35028
   499
subclass ordered_cancel_semiring ..
haftmann@35028
   500
haftmann@35028
   501
subclass ordered_comm_monoid_add ..
haftmann@25304
   502
haftmann@25230
   503
lemma mult_left_less_imp_less:
haftmann@25230
   504
  "c * a < c * b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
nipkow@29667
   505
by (force simp add: mult_left_mono not_le [symmetric])
haftmann@25230
   506
 
haftmann@25230
   507
lemma mult_right_less_imp_less:
haftmann@25230
   508
  "a * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
nipkow@29667
   509
by (force simp add: mult_right_mono not_le [symmetric])
obua@23521
   510
haftmann@25186
   511
end
haftmann@25152
   512
haftmann@35043
   513
class linordered_semiring_1 = linordered_semiring + semiring_1
hoelzl@36622
   514
begin
hoelzl@36622
   515
hoelzl@36622
   516
lemma convex_bound_le:
hoelzl@36622
   517
  assumes "x \<le> a" "y \<le> a" "0 \<le> u" "0 \<le> v" "u + v = 1"
hoelzl@36622
   518
  shows "u * x + v * y \<le> a"
hoelzl@36622
   519
proof-
hoelzl@36622
   520
  from assms have "u * x + v * y \<le> u * a + v * a"
hoelzl@36622
   521
    by (simp add: add_mono mult_left_mono)
webertj@49962
   522
  thus ?thesis using assms unfolding distrib_right[symmetric] by simp
hoelzl@36622
   523
qed
hoelzl@36622
   524
hoelzl@36622
   525
end
haftmann@35043
   526
haftmann@35043
   527
class linordered_semiring_strict = semiring + comm_monoid_add + linordered_cancel_ab_semigroup_add +
haftmann@25062
   528
  assumes mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
haftmann@25062
   529
  assumes mult_strict_right_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> a * c < b * c"
haftmann@25267
   530
begin
paulson@14341
   531
huffman@27516
   532
subclass semiring_0_cancel ..
obua@14940
   533
haftmann@35028
   534
subclass linordered_semiring
haftmann@28823
   535
proof
huffman@23550
   536
  fix a b c :: 'a
huffman@23550
   537
  assume A: "a \<le> b" "0 \<le> c"
huffman@23550
   538
  from A show "c * a \<le> c * b"
haftmann@25186
   539
    unfolding le_less
haftmann@25186
   540
    using mult_strict_left_mono by (cases "c = 0") auto
huffman@23550
   541
  from A show "a * c \<le> b * c"
haftmann@25152
   542
    unfolding le_less
haftmann@25186
   543
    using mult_strict_right_mono by (cases "c = 0") auto
haftmann@25152
   544
qed
haftmann@25152
   545
haftmann@25230
   546
lemma mult_left_le_imp_le:
haftmann@25230
   547
  "c * a \<le> c * b \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
nipkow@29667
   548
by (force simp add: mult_strict_left_mono _not_less [symmetric])
haftmann@25230
   549
 
haftmann@25230
   550
lemma mult_right_le_imp_le:
haftmann@25230
   551
  "a * c \<le> b * c \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
nipkow@29667
   552
by (force simp add: mult_strict_right_mono not_less [symmetric])
haftmann@25230
   553
huffman@30692
   554
lemma mult_pos_pos: "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> 0 < a * b"
haftmann@36301
   555
using mult_strict_left_mono [of 0 b a] by simp
huffman@30692
   556
huffman@30692
   557
lemma mult_pos_neg: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> a * b < 0"
haftmann@36301
   558
using mult_strict_left_mono [of b 0 a] by simp
huffman@30692
   559
huffman@30692
   560
lemma mult_neg_pos: "a < 0 \<Longrightarrow> 0 < b \<Longrightarrow> a * b < 0"
haftmann@36301
   561
using mult_strict_right_mono [of a 0 b] by simp
huffman@30692
   562
huffman@30692
   563
text {* Legacy - use @{text mult_neg_pos} *}
huffman@30692
   564
lemma mult_pos_neg2: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> b * a < 0" 
haftmann@36301
   565
by (drule mult_strict_right_mono [of b 0], auto)
haftmann@25230
   566
haftmann@25230
   567
lemma zero_less_mult_pos:
haftmann@25230
   568
  "0 < a * b \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
huffman@30692
   569
apply (cases "b\<le>0")
haftmann@25230
   570
 apply (auto simp add: le_less not_less)
huffman@30692
   571
apply (drule_tac mult_pos_neg [of a b])
haftmann@25230
   572
 apply (auto dest: less_not_sym)
haftmann@25230
   573
done
haftmann@25230
   574
haftmann@25230
   575
lemma zero_less_mult_pos2:
haftmann@25230
   576
  "0 < b * a \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
huffman@30692
   577
apply (cases "b\<le>0")
haftmann@25230
   578
 apply (auto simp add: le_less not_less)
huffman@30692
   579
apply (drule_tac mult_pos_neg2 [of a b])
haftmann@25230
   580
 apply (auto dest: less_not_sym)
haftmann@25230
   581
done
haftmann@25230
   582
haftmann@26193
   583
text{*Strict monotonicity in both arguments*}
haftmann@26193
   584
lemma mult_strict_mono:
haftmann@26193
   585
  assumes "a < b" and "c < d" and "0 < b" and "0 \<le> c"
haftmann@26193
   586
  shows "a * c < b * d"
haftmann@26193
   587
  using assms apply (cases "c=0")
huffman@30692
   588
  apply (simp add: mult_pos_pos)
haftmann@26193
   589
  apply (erule mult_strict_right_mono [THEN less_trans])
huffman@30692
   590
  apply (force simp add: le_less)
haftmann@26193
   591
  apply (erule mult_strict_left_mono, assumption)
haftmann@26193
   592
  done
haftmann@26193
   593
haftmann@26193
   594
text{*This weaker variant has more natural premises*}
haftmann@26193
   595
lemma mult_strict_mono':
haftmann@26193
   596
  assumes "a < b" and "c < d" and "0 \<le> a" and "0 \<le> c"
haftmann@26193
   597
  shows "a * c < b * d"
nipkow@29667
   598
by (rule mult_strict_mono) (insert assms, auto)
haftmann@26193
   599
haftmann@26193
   600
lemma mult_less_le_imp_less:
haftmann@26193
   601
  assumes "a < b" and "c \<le> d" and "0 \<le> a" and "0 < c"
haftmann@26193
   602
  shows "a * c < b * d"
haftmann@26193
   603
  using assms apply (subgoal_tac "a * c < b * c")
haftmann@26193
   604
  apply (erule less_le_trans)
haftmann@26193
   605
  apply (erule mult_left_mono)
haftmann@26193
   606
  apply simp
haftmann@26193
   607
  apply (erule mult_strict_right_mono)
haftmann@26193
   608
  apply assumption
haftmann@26193
   609
  done
haftmann@26193
   610
haftmann@26193
   611
lemma mult_le_less_imp_less:
haftmann@26193
   612
  assumes "a \<le> b" and "c < d" and "0 < a" and "0 \<le> c"
haftmann@26193
   613
  shows "a * c < b * d"
haftmann@26193
   614
  using assms apply (subgoal_tac "a * c \<le> b * c")
haftmann@26193
   615
  apply (erule le_less_trans)
haftmann@26193
   616
  apply (erule mult_strict_left_mono)
haftmann@26193
   617
  apply simp
haftmann@26193
   618
  apply (erule mult_right_mono)
haftmann@26193
   619
  apply simp
haftmann@26193
   620
  done
haftmann@26193
   621
haftmann@26193
   622
lemma mult_less_imp_less_left:
haftmann@26193
   623
  assumes less: "c * a < c * b" and nonneg: "0 \<le> c"
haftmann@26193
   624
  shows "a < b"
haftmann@26193
   625
proof (rule ccontr)
haftmann@26193
   626
  assume "\<not>  a < b"
haftmann@26193
   627
  hence "b \<le> a" by (simp add: linorder_not_less)
haftmann@26193
   628
  hence "c * b \<le> c * a" using nonneg by (rule mult_left_mono)
nipkow@29667
   629
  with this and less show False by (simp add: not_less [symmetric])
haftmann@26193
   630
qed
haftmann@26193
   631
haftmann@26193
   632
lemma mult_less_imp_less_right:
haftmann@26193
   633
  assumes less: "a * c < b * c" and nonneg: "0 \<le> c"
haftmann@26193
   634
  shows "a < b"
haftmann@26193
   635
proof (rule ccontr)
haftmann@26193
   636
  assume "\<not> a < b"
haftmann@26193
   637
  hence "b \<le> a" by (simp add: linorder_not_less)
haftmann@26193
   638
  hence "b * c \<le> a * c" using nonneg by (rule mult_right_mono)
nipkow@29667
   639
  with this and less show False by (simp add: not_less [symmetric])
haftmann@26193
   640
qed  
haftmann@26193
   641
haftmann@25230
   642
end
haftmann@25230
   643
haftmann@35097
   644
class linordered_semiring_1_strict = linordered_semiring_strict + semiring_1
hoelzl@36622
   645
begin
hoelzl@36622
   646
hoelzl@36622
   647
subclass linordered_semiring_1 ..
hoelzl@36622
   648
hoelzl@36622
   649
lemma convex_bound_lt:
hoelzl@36622
   650
  assumes "x < a" "y < a" "0 \<le> u" "0 \<le> v" "u + v = 1"
hoelzl@36622
   651
  shows "u * x + v * y < a"
hoelzl@36622
   652
proof -
hoelzl@36622
   653
  from assms have "u * x + v * y < u * a + v * a"
hoelzl@36622
   654
    by (cases "u = 0")
hoelzl@36622
   655
       (auto intro!: add_less_le_mono mult_strict_left_mono mult_left_mono)
webertj@49962
   656
  thus ?thesis using assms unfolding distrib_right[symmetric] by simp
hoelzl@36622
   657
qed
hoelzl@36622
   658
hoelzl@36622
   659
end
haftmann@33319
   660
haftmann@38642
   661
class ordered_comm_semiring = comm_semiring_0 + ordered_ab_semigroup_add + 
haftmann@38642
   662
  assumes comm_mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
haftmann@25186
   663
begin
haftmann@25152
   664
haftmann@35028
   665
subclass ordered_semiring
haftmann@28823
   666
proof
krauss@21199
   667
  fix a b c :: 'a
huffman@23550
   668
  assume "a \<le> b" "0 \<le> c"
haftmann@38642
   669
  thus "c * a \<le> c * b" by (rule comm_mult_left_mono)
huffman@23550
   670
  thus "a * c \<le> b * c" by (simp only: mult_commute)
krauss@21199
   671
qed
paulson@14265
   672
haftmann@25267
   673
end
haftmann@25267
   674
haftmann@38642
   675
class ordered_cancel_comm_semiring = ordered_comm_semiring + cancel_comm_monoid_add
haftmann@25267
   676
begin
paulson@14265
   677
haftmann@38642
   678
subclass comm_semiring_0_cancel ..
haftmann@35028
   679
subclass ordered_comm_semiring ..
haftmann@35028
   680
subclass ordered_cancel_semiring ..
haftmann@25267
   681
haftmann@25267
   682
end
haftmann@25267
   683
haftmann@35028
   684
class linordered_comm_semiring_strict = comm_semiring_0 + linordered_cancel_ab_semigroup_add +
haftmann@38642
   685
  assumes comm_mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
haftmann@25267
   686
begin
haftmann@25267
   687
haftmann@35043
   688
subclass linordered_semiring_strict
haftmann@28823
   689
proof
huffman@23550
   690
  fix a b c :: 'a
huffman@23550
   691
  assume "a < b" "0 < c"
haftmann@38642
   692
  thus "c * a < c * b" by (rule comm_mult_strict_left_mono)
huffman@23550
   693
  thus "a * c < b * c" by (simp only: mult_commute)
huffman@23550
   694
qed
paulson@14272
   695
haftmann@35028
   696
subclass ordered_cancel_comm_semiring
haftmann@28823
   697
proof
huffman@23550
   698
  fix a b c :: 'a
huffman@23550
   699
  assume "a \<le> b" "0 \<le> c"
huffman@23550
   700
  thus "c * a \<le> c * b"
haftmann@25186
   701
    unfolding le_less
haftmann@26193
   702
    using mult_strict_left_mono by (cases "c = 0") auto
huffman@23550
   703
qed
paulson@14272
   704
haftmann@25267
   705
end
haftmann@25230
   706
haftmann@35028
   707
class ordered_ring = ring + ordered_cancel_semiring 
haftmann@25267
   708
begin
haftmann@25230
   709
haftmann@35028
   710
subclass ordered_ab_group_add ..
paulson@14270
   711
haftmann@25230
   712
lemma less_add_iff1:
haftmann@25230
   713
  "a * e + c < b * e + d \<longleftrightarrow> (a - b) * e + c < d"
nipkow@29667
   714
by (simp add: algebra_simps)
haftmann@25230
   715
haftmann@25230
   716
lemma less_add_iff2:
haftmann@25230
   717
  "a * e + c < b * e + d \<longleftrightarrow> c < (b - a) * e + d"
nipkow@29667
   718
by (simp add: algebra_simps)
haftmann@25230
   719
haftmann@25230
   720
lemma le_add_iff1:
haftmann@25230
   721
  "a * e + c \<le> b * e + d \<longleftrightarrow> (a - b) * e + c \<le> d"
nipkow@29667
   722
by (simp add: algebra_simps)
haftmann@25230
   723
haftmann@25230
   724
lemma le_add_iff2:
haftmann@25230
   725
  "a * e + c \<le> b * e + d \<longleftrightarrow> c \<le> (b - a) * e + d"
nipkow@29667
   726
by (simp add: algebra_simps)
haftmann@25230
   727
haftmann@25230
   728
lemma mult_left_mono_neg:
haftmann@25230
   729
  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> c * a \<le> c * b"
haftmann@36301
   730
  apply (drule mult_left_mono [of _ _ "- c"])
huffman@35216
   731
  apply simp_all
haftmann@25230
   732
  done
haftmann@25230
   733
haftmann@25230
   734
lemma mult_right_mono_neg:
haftmann@25230
   735
  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> a * c \<le> b * c"
haftmann@36301
   736
  apply (drule mult_right_mono [of _ _ "- c"])
huffman@35216
   737
  apply simp_all
haftmann@25230
   738
  done
haftmann@25230
   739
huffman@30692
   740
lemma mult_nonpos_nonpos: "a \<le> 0 \<Longrightarrow> b \<le> 0 \<Longrightarrow> 0 \<le> a * b"
haftmann@36301
   741
using mult_right_mono_neg [of a 0 b] by simp
haftmann@25230
   742
haftmann@25230
   743
lemma split_mult_pos_le:
haftmann@25230
   744
  "(0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0) \<Longrightarrow> 0 \<le> a * b"
nipkow@29667
   745
by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos)
haftmann@25186
   746
haftmann@25186
   747
end
paulson@14270
   748
haftmann@35028
   749
class linordered_ring = ring + linordered_semiring + linordered_ab_group_add + abs_if
haftmann@25304
   750
begin
haftmann@25304
   751
haftmann@35028
   752
subclass ordered_ring ..
haftmann@35028
   753
haftmann@35028
   754
subclass ordered_ab_group_add_abs
haftmann@28823
   755
proof
haftmann@25304
   756
  fix a b
haftmann@25304
   757
  show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
huffman@35216
   758
    by (auto simp add: abs_if not_less)
huffman@35216
   759
    (auto simp del: minus_add_distrib simp add: minus_add_distrib [symmetric],
huffman@36977
   760
     auto intro!: less_imp_le add_neg_neg)
huffman@35216
   761
qed (auto simp add: abs_if)
haftmann@25304
   762
huffman@35631
   763
lemma zero_le_square [simp]: "0 \<le> a * a"
huffman@35631
   764
  using linear [of 0 a]
huffman@35631
   765
  by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos)
huffman@35631
   766
huffman@35631
   767
lemma not_square_less_zero [simp]: "\<not> (a * a < 0)"
huffman@35631
   768
  by (simp add: not_less)
huffman@35631
   769
haftmann@25304
   770
end
obua@23521
   771
haftmann@35028
   772
(* The "strict" suffix can be seen as describing the combination of linordered_ring and no_zero_divisors.
haftmann@35043
   773
   Basically, linordered_ring + no_zero_divisors = linordered_ring_strict.
haftmann@25230
   774
 *)
haftmann@35043
   775
class linordered_ring_strict = ring + linordered_semiring_strict
haftmann@25304
   776
  + ordered_ab_group_add + abs_if
haftmann@25230
   777
begin
paulson@14348
   778
haftmann@35028
   779
subclass linordered_ring ..
haftmann@25304
   780
huffman@30692
   781
lemma mult_strict_left_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> c * a < c * b"
huffman@30692
   782
using mult_strict_left_mono [of b a "- c"] by simp
huffman@30692
   783
huffman@30692
   784
lemma mult_strict_right_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> a * c < b * c"
huffman@30692
   785
using mult_strict_right_mono [of b a "- c"] by simp
huffman@30692
   786
huffman@30692
   787
lemma mult_neg_neg: "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> 0 < a * b"
haftmann@36301
   788
using mult_strict_right_mono_neg [of a 0 b] by simp
obua@14738
   789
haftmann@25917
   790
subclass ring_no_zero_divisors
haftmann@28823
   791
proof
haftmann@25917
   792
  fix a b
haftmann@25917
   793
  assume "a \<noteq> 0" then have A: "a < 0 \<or> 0 < a" by (simp add: neq_iff)
haftmann@25917
   794
  assume "b \<noteq> 0" then have B: "b < 0 \<or> 0 < b" by (simp add: neq_iff)
haftmann@25917
   795
  have "a * b < 0 \<or> 0 < a * b"
haftmann@25917
   796
  proof (cases "a < 0")
haftmann@25917
   797
    case True note A' = this
haftmann@25917
   798
    show ?thesis proof (cases "b < 0")
haftmann@25917
   799
      case True with A'
haftmann@25917
   800
      show ?thesis by (auto dest: mult_neg_neg)
haftmann@25917
   801
    next
haftmann@25917
   802
      case False with B have "0 < b" by auto
haftmann@25917
   803
      with A' show ?thesis by (auto dest: mult_strict_right_mono)
haftmann@25917
   804
    qed
haftmann@25917
   805
  next
haftmann@25917
   806
    case False with A have A': "0 < a" by auto
haftmann@25917
   807
    show ?thesis proof (cases "b < 0")
haftmann@25917
   808
      case True with A'
haftmann@25917
   809
      show ?thesis by (auto dest: mult_strict_right_mono_neg)
haftmann@25917
   810
    next
haftmann@25917
   811
      case False with B have "0 < b" by auto
haftmann@25917
   812
      with A' show ?thesis by (auto dest: mult_pos_pos)
haftmann@25917
   813
    qed
haftmann@25917
   814
  qed
haftmann@25917
   815
  then show "a * b \<noteq> 0" by (simp add: neq_iff)
haftmann@25917
   816
qed
haftmann@25304
   817
paulson@14265
   818
lemma zero_less_mult_iff:
haftmann@25917
   819
  "0 < a * b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0"
haftmann@25917
   820
  apply (auto simp add: mult_pos_pos mult_neg_neg)
haftmann@25917
   821
  apply (simp_all add: not_less le_less)
haftmann@25917
   822
  apply (erule disjE) apply assumption defer
haftmann@25917
   823
  apply (erule disjE) defer apply (drule sym) apply simp
haftmann@25917
   824
  apply (erule disjE) defer apply (drule sym) apply simp
haftmann@25917
   825
  apply (erule disjE) apply assumption apply (drule sym) apply simp
haftmann@25917
   826
  apply (drule sym) apply simp
haftmann@25917
   827
  apply (blast dest: zero_less_mult_pos)
haftmann@25230
   828
  apply (blast dest: zero_less_mult_pos2)
haftmann@25230
   829
  done
huffman@22990
   830
paulson@14265
   831
lemma zero_le_mult_iff:
haftmann@25917
   832
  "0 \<le> a * b \<longleftrightarrow> 0 \<le> a \<and> 0 \<le> b \<or> a \<le> 0 \<and> b \<le> 0"
nipkow@29667
   833
by (auto simp add: eq_commute [of 0] le_less not_less zero_less_mult_iff)
paulson@14265
   834
paulson@14265
   835
lemma mult_less_0_iff:
haftmann@25917
   836
  "a * b < 0 \<longleftrightarrow> 0 < a \<and> b < 0 \<or> a < 0 \<and> 0 < b"
huffman@35216
   837
  apply (insert zero_less_mult_iff [of "-a" b])
huffman@35216
   838
  apply force
haftmann@25917
   839
  done
paulson@14265
   840
paulson@14265
   841
lemma mult_le_0_iff:
haftmann@25917
   842
  "a * b \<le> 0 \<longleftrightarrow> 0 \<le> a \<and> b \<le> 0 \<or> a \<le> 0 \<and> 0 \<le> b"
haftmann@25917
   843
  apply (insert zero_le_mult_iff [of "-a" b]) 
huffman@35216
   844
  apply force
haftmann@25917
   845
  done
haftmann@25917
   846
haftmann@26193
   847
text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
haftmann@26193
   848
   also with the relations @{text "\<le>"} and equality.*}
haftmann@26193
   849
haftmann@26193
   850
text{*These ``disjunction'' versions produce two cases when the comparison is
haftmann@26193
   851
 an assumption, but effectively four when the comparison is a goal.*}
haftmann@26193
   852
haftmann@26193
   853
lemma mult_less_cancel_right_disj:
haftmann@26193
   854
  "a * c < b * c \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
   855
  apply (cases "c = 0")
haftmann@26193
   856
  apply (auto simp add: neq_iff mult_strict_right_mono 
haftmann@26193
   857
                      mult_strict_right_mono_neg)
haftmann@26193
   858
  apply (auto simp add: not_less 
haftmann@26193
   859
                      not_le [symmetric, of "a*c"]
haftmann@26193
   860
                      not_le [symmetric, of a])
haftmann@26193
   861
  apply (erule_tac [!] notE)
haftmann@26193
   862
  apply (auto simp add: less_imp_le mult_right_mono 
haftmann@26193
   863
                      mult_right_mono_neg)
haftmann@26193
   864
  done
haftmann@26193
   865
haftmann@26193
   866
lemma mult_less_cancel_left_disj:
haftmann@26193
   867
  "c * a < c * b \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
   868
  apply (cases "c = 0")
haftmann@26193
   869
  apply (auto simp add: neq_iff mult_strict_left_mono 
haftmann@26193
   870
                      mult_strict_left_mono_neg)
haftmann@26193
   871
  apply (auto simp add: not_less 
haftmann@26193
   872
                      not_le [symmetric, of "c*a"]
haftmann@26193
   873
                      not_le [symmetric, of a])
haftmann@26193
   874
  apply (erule_tac [!] notE)
haftmann@26193
   875
  apply (auto simp add: less_imp_le mult_left_mono 
haftmann@26193
   876
                      mult_left_mono_neg)
haftmann@26193
   877
  done
haftmann@26193
   878
haftmann@26193
   879
text{*The ``conjunction of implication'' lemmas produce two cases when the
haftmann@26193
   880
comparison is a goal, but give four when the comparison is an assumption.*}
haftmann@26193
   881
haftmann@26193
   882
lemma mult_less_cancel_right:
haftmann@26193
   883
  "a * c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
   884
  using mult_less_cancel_right_disj [of a c b] by auto
haftmann@26193
   885
haftmann@26193
   886
lemma mult_less_cancel_left:
haftmann@26193
   887
  "c * a < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
   888
  using mult_less_cancel_left_disj [of c a b] by auto
haftmann@26193
   889
haftmann@26193
   890
lemma mult_le_cancel_right:
haftmann@26193
   891
   "a * c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
nipkow@29667
   892
by (simp add: not_less [symmetric] mult_less_cancel_right_disj)
haftmann@26193
   893
haftmann@26193
   894
lemma mult_le_cancel_left:
haftmann@26193
   895
  "c * a \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
nipkow@29667
   896
by (simp add: not_less [symmetric] mult_less_cancel_left_disj)
haftmann@26193
   897
nipkow@30649
   898
lemma mult_le_cancel_left_pos:
nipkow@30649
   899
  "0 < c \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> a \<le> b"
nipkow@30649
   900
by (auto simp: mult_le_cancel_left)
nipkow@30649
   901
nipkow@30649
   902
lemma mult_le_cancel_left_neg:
nipkow@30649
   903
  "c < 0 \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> b \<le> a"
nipkow@30649
   904
by (auto simp: mult_le_cancel_left)
nipkow@30649
   905
nipkow@30649
   906
lemma mult_less_cancel_left_pos:
nipkow@30649
   907
  "0 < c \<Longrightarrow> c * a < c * b \<longleftrightarrow> a < b"
nipkow@30649
   908
by (auto simp: mult_less_cancel_left)
nipkow@30649
   909
nipkow@30649
   910
lemma mult_less_cancel_left_neg:
nipkow@30649
   911
  "c < 0 \<Longrightarrow> c * a < c * b \<longleftrightarrow> b < a"
nipkow@30649
   912
by (auto simp: mult_less_cancel_left)
nipkow@30649
   913
haftmann@25917
   914
end
paulson@14265
   915
huffman@30692
   916
lemmas mult_sign_intros =
huffman@30692
   917
  mult_nonneg_nonneg mult_nonneg_nonpos
huffman@30692
   918
  mult_nonpos_nonneg mult_nonpos_nonpos
huffman@30692
   919
  mult_pos_pos mult_pos_neg
huffman@30692
   920
  mult_neg_pos mult_neg_neg
haftmann@25230
   921
haftmann@35028
   922
class ordered_comm_ring = comm_ring + ordered_comm_semiring
haftmann@25267
   923
begin
haftmann@25230
   924
haftmann@35028
   925
subclass ordered_ring ..
haftmann@35028
   926
subclass ordered_cancel_comm_semiring ..
haftmann@25230
   927
haftmann@25267
   928
end
haftmann@25230
   929
haftmann@35028
   930
class linordered_semidom = comm_semiring_1_cancel + linordered_comm_semiring_strict +
haftmann@35028
   931
  (*previously linordered_semiring*)
haftmann@25230
   932
  assumes zero_less_one [simp]: "0 < 1"
haftmann@25230
   933
begin
haftmann@25230
   934
haftmann@25230
   935
lemma pos_add_strict:
haftmann@25230
   936
  shows "0 < a \<Longrightarrow> b < c \<Longrightarrow> b < a + c"
haftmann@36301
   937
  using add_strict_mono [of 0 a b c] by simp
haftmann@25230
   938
haftmann@26193
   939
lemma zero_le_one [simp]: "0 \<le> 1"
nipkow@29667
   940
by (rule zero_less_one [THEN less_imp_le]) 
haftmann@26193
   941
haftmann@26193
   942
lemma not_one_le_zero [simp]: "\<not> 1 \<le> 0"
nipkow@29667
   943
by (simp add: not_le) 
haftmann@26193
   944
haftmann@26193
   945
lemma not_one_less_zero [simp]: "\<not> 1 < 0"
nipkow@29667
   946
by (simp add: not_less) 
haftmann@26193
   947
haftmann@26193
   948
lemma less_1_mult:
haftmann@26193
   949
  assumes "1 < m" and "1 < n"
haftmann@26193
   950
  shows "1 < m * n"
haftmann@26193
   951
  using assms mult_strict_mono [of 1 m 1 n]
haftmann@26193
   952
    by (simp add:  less_trans [OF zero_less_one]) 
haftmann@26193
   953
haftmann@25230
   954
end
haftmann@25230
   955
haftmann@35028
   956
class linordered_idom = comm_ring_1 +
haftmann@35028
   957
  linordered_comm_semiring_strict + ordered_ab_group_add +
haftmann@25230
   958
  abs_if + sgn_if
haftmann@35028
   959
  (*previously linordered_ring*)
haftmann@25917
   960
begin
haftmann@25917
   961
hoelzl@36622
   962
subclass linordered_semiring_1_strict ..
haftmann@35043
   963
subclass linordered_ring_strict ..
haftmann@35028
   964
subclass ordered_comm_ring ..
huffman@27516
   965
subclass idom ..
haftmann@25917
   966
haftmann@35028
   967
subclass linordered_semidom
haftmann@28823
   968
proof
haftmann@26193
   969
  have "0 \<le> 1 * 1" by (rule zero_le_square)
haftmann@26193
   970
  thus "0 < 1" by (simp add: le_less)
haftmann@25917
   971
qed 
haftmann@25917
   972
haftmann@35028
   973
lemma linorder_neqE_linordered_idom:
haftmann@26193
   974
  assumes "x \<noteq> y" obtains "x < y" | "y < x"
haftmann@26193
   975
  using assms by (rule neqE)
haftmann@26193
   976
haftmann@26274
   977
text {* These cancellation simprules also produce two cases when the comparison is a goal. *}
haftmann@26274
   978
haftmann@26274
   979
lemma mult_le_cancel_right1:
haftmann@26274
   980
  "c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
nipkow@29667
   981
by (insert mult_le_cancel_right [of 1 c b], simp)
haftmann@26274
   982
haftmann@26274
   983
lemma mult_le_cancel_right2:
haftmann@26274
   984
  "a * c \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
nipkow@29667
   985
by (insert mult_le_cancel_right [of a c 1], simp)
haftmann@26274
   986
haftmann@26274
   987
lemma mult_le_cancel_left1:
haftmann@26274
   988
  "c \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
nipkow@29667
   989
by (insert mult_le_cancel_left [of c 1 b], simp)
haftmann@26274
   990
haftmann@26274
   991
lemma mult_le_cancel_left2:
haftmann@26274
   992
  "c * a \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
nipkow@29667
   993
by (insert mult_le_cancel_left [of c a 1], simp)
haftmann@26274
   994
haftmann@26274
   995
lemma mult_less_cancel_right1:
haftmann@26274
   996
  "c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
nipkow@29667
   997
by (insert mult_less_cancel_right [of 1 c b], simp)
haftmann@26274
   998
haftmann@26274
   999
lemma mult_less_cancel_right2:
haftmann@26274
  1000
  "a * c < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
nipkow@29667
  1001
by (insert mult_less_cancel_right [of a c 1], simp)
haftmann@26274
  1002
haftmann@26274
  1003
lemma mult_less_cancel_left1:
haftmann@26274
  1004
  "c < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
nipkow@29667
  1005
by (insert mult_less_cancel_left [of c 1 b], simp)
haftmann@26274
  1006
haftmann@26274
  1007
lemma mult_less_cancel_left2:
haftmann@26274
  1008
  "c * a < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
nipkow@29667
  1009
by (insert mult_less_cancel_left [of c a 1], simp)
haftmann@26274
  1010
haftmann@27651
  1011
lemma sgn_sgn [simp]:
haftmann@27651
  1012
  "sgn (sgn a) = sgn a"
nipkow@29700
  1013
unfolding sgn_if by simp
haftmann@27651
  1014
haftmann@27651
  1015
lemma sgn_0_0:
haftmann@27651
  1016
  "sgn a = 0 \<longleftrightarrow> a = 0"
nipkow@29700
  1017
unfolding sgn_if by simp
haftmann@27651
  1018
haftmann@27651
  1019
lemma sgn_1_pos:
haftmann@27651
  1020
  "sgn a = 1 \<longleftrightarrow> a > 0"
huffman@35216
  1021
unfolding sgn_if by simp
haftmann@27651
  1022
haftmann@27651
  1023
lemma sgn_1_neg:
haftmann@27651
  1024
  "sgn a = - 1 \<longleftrightarrow> a < 0"
huffman@35216
  1025
unfolding sgn_if by auto
haftmann@27651
  1026
haftmann@29940
  1027
lemma sgn_pos [simp]:
haftmann@29940
  1028
  "0 < a \<Longrightarrow> sgn a = 1"
haftmann@29940
  1029
unfolding sgn_1_pos .
haftmann@29940
  1030
haftmann@29940
  1031
lemma sgn_neg [simp]:
haftmann@29940
  1032
  "a < 0 \<Longrightarrow> sgn a = - 1"
haftmann@29940
  1033
unfolding sgn_1_neg .
haftmann@29940
  1034
haftmann@27651
  1035
lemma sgn_times:
haftmann@27651
  1036
  "sgn (a * b) = sgn a * sgn b"
nipkow@29667
  1037
by (auto simp add: sgn_if zero_less_mult_iff)
haftmann@27651
  1038
haftmann@36301
  1039
lemma abs_sgn: "\<bar>k\<bar> = k * sgn k"
nipkow@29700
  1040
unfolding sgn_if abs_if by auto
nipkow@29700
  1041
haftmann@29940
  1042
lemma sgn_greater [simp]:
haftmann@29940
  1043
  "0 < sgn a \<longleftrightarrow> 0 < a"
haftmann@29940
  1044
  unfolding sgn_if by auto
haftmann@29940
  1045
haftmann@29940
  1046
lemma sgn_less [simp]:
haftmann@29940
  1047
  "sgn a < 0 \<longleftrightarrow> a < 0"
haftmann@29940
  1048
  unfolding sgn_if by auto
haftmann@29940
  1049
haftmann@36301
  1050
lemma abs_dvd_iff [simp]: "\<bar>m\<bar> dvd k \<longleftrightarrow> m dvd k"
huffman@29949
  1051
  by (simp add: abs_if)
huffman@29949
  1052
haftmann@36301
  1053
lemma dvd_abs_iff [simp]: "m dvd \<bar>k\<bar> \<longleftrightarrow> m dvd k"
huffman@29949
  1054
  by (simp add: abs_if)
haftmann@29653
  1055
nipkow@33676
  1056
lemma dvd_if_abs_eq:
haftmann@36301
  1057
  "\<bar>l\<bar> = \<bar>k\<bar> \<Longrightarrow> l dvd k"
nipkow@33676
  1058
by(subst abs_dvd_iff[symmetric]) simp
nipkow@33676
  1059
haftmann@25917
  1060
end
haftmann@25230
  1061
haftmann@26274
  1062
text {* Simprules for comparisons where common factors can be cancelled. *}
paulson@15234
  1063
blanchet@54147
  1064
lemmas mult_compare_simps =
paulson@15234
  1065
    mult_le_cancel_right mult_le_cancel_left
paulson@15234
  1066
    mult_le_cancel_right1 mult_le_cancel_right2
paulson@15234
  1067
    mult_le_cancel_left1 mult_le_cancel_left2
paulson@15234
  1068
    mult_less_cancel_right mult_less_cancel_left
paulson@15234
  1069
    mult_less_cancel_right1 mult_less_cancel_right2
paulson@15234
  1070
    mult_less_cancel_left1 mult_less_cancel_left2
paulson@15234
  1071
    mult_cancel_right mult_cancel_left
paulson@15234
  1072
    mult_cancel_right1 mult_cancel_right2
paulson@15234
  1073
    mult_cancel_left1 mult_cancel_left2
paulson@15234
  1074
haftmann@36301
  1075
text {* Reasoning about inequalities with division *}
avigad@16775
  1076
haftmann@35028
  1077
context linordered_semidom
haftmann@25193
  1078
begin
haftmann@25193
  1079
haftmann@25193
  1080
lemma less_add_one: "a < a + 1"
paulson@14293
  1081
proof -
haftmann@25193
  1082
  have "a + 0 < a + 1"
nipkow@23482
  1083
    by (blast intro: zero_less_one add_strict_left_mono)
paulson@14293
  1084
  thus ?thesis by simp
paulson@14293
  1085
qed
paulson@14293
  1086
haftmann@25193
  1087
lemma zero_less_two: "0 < 1 + 1"
nipkow@29667
  1088
by (blast intro: less_trans zero_less_one less_add_one)
haftmann@25193
  1089
haftmann@25193
  1090
end
paulson@14365
  1091
haftmann@36301
  1092
context linordered_idom
haftmann@36301
  1093
begin
paulson@15234
  1094
haftmann@36301
  1095
lemma mult_right_le_one_le:
haftmann@36301
  1096
  "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> y \<le> 1 \<Longrightarrow> x * y \<le> x"
haftmann@36301
  1097
  by (auto simp add: mult_le_cancel_left2)
haftmann@36301
  1098
haftmann@36301
  1099
lemma mult_left_le_one_le:
haftmann@36301
  1100
  "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> y \<le> 1 \<Longrightarrow> y * x \<le> x"
haftmann@36301
  1101
  by (auto simp add: mult_le_cancel_right2)
haftmann@36301
  1102
haftmann@36301
  1103
end
haftmann@36301
  1104
haftmann@36301
  1105
text {* Absolute Value *}
paulson@14293
  1106
haftmann@35028
  1107
context linordered_idom
haftmann@25304
  1108
begin
haftmann@25304
  1109
haftmann@36301
  1110
lemma mult_sgn_abs:
haftmann@36301
  1111
  "sgn x * \<bar>x\<bar> = x"
haftmann@25304
  1112
  unfolding abs_if sgn_if by auto
haftmann@25304
  1113
haftmann@36301
  1114
lemma abs_one [simp]:
haftmann@36301
  1115
  "\<bar>1\<bar> = 1"
huffman@44921
  1116
  by (simp add: abs_if)
haftmann@36301
  1117
haftmann@25304
  1118
end
nipkow@24491
  1119
haftmann@35028
  1120
class ordered_ring_abs = ordered_ring + ordered_ab_group_add_abs +
haftmann@25304
  1121
  assumes abs_eq_mult:
haftmann@25304
  1122
    "(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
  1123
haftmann@35028
  1124
context linordered_idom
haftmann@30961
  1125
begin
haftmann@30961
  1126
haftmann@35028
  1127
subclass ordered_ring_abs proof
huffman@35216
  1128
qed (auto simp add: abs_if not_less mult_less_0_iff)
haftmann@30961
  1129
haftmann@30961
  1130
lemma abs_mult:
haftmann@36301
  1131
  "\<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>" 
haftmann@30961
  1132
  by (rule abs_eq_mult) auto
haftmann@30961
  1133
haftmann@30961
  1134
lemma abs_mult_self:
haftmann@36301
  1135
  "\<bar>a\<bar> * \<bar>a\<bar> = a * a"
haftmann@30961
  1136
  by (simp add: abs_if) 
haftmann@30961
  1137
paulson@14294
  1138
lemma abs_mult_less:
haftmann@36301
  1139
  "\<bar>a\<bar> < c \<Longrightarrow> \<bar>b\<bar> < d \<Longrightarrow> \<bar>a\<bar> * \<bar>b\<bar> < c * d"
paulson@14294
  1140
proof -
haftmann@36301
  1141
  assume ac: "\<bar>a\<bar> < c"
haftmann@36301
  1142
  hence cpos: "0<c" by (blast intro: le_less_trans abs_ge_zero)
haftmann@36301
  1143
  assume "\<bar>b\<bar> < d"
paulson@14294
  1144
  thus ?thesis by (simp add: ac cpos mult_strict_mono) 
paulson@14294
  1145
qed
paulson@14293
  1146
haftmann@36301
  1147
lemma less_minus_self_iff:
haftmann@36301
  1148
  "a < - a \<longleftrightarrow> a < 0"
haftmann@36301
  1149
  by (simp only: less_le less_eq_neg_nonpos equal_neg_zero)
obua@14738
  1150
haftmann@36301
  1151
lemma abs_less_iff:
haftmann@36301
  1152
  "\<bar>a\<bar> < b \<longleftrightarrow> a < b \<and> - a < b" 
haftmann@36301
  1153
  by (simp add: less_le abs_le_iff) (auto simp add: abs_if)
obua@14738
  1154
haftmann@36301
  1155
lemma abs_mult_pos:
haftmann@36301
  1156
  "0 \<le> x \<Longrightarrow> \<bar>y\<bar> * x = \<bar>y * x\<bar>"
haftmann@36301
  1157
  by (simp add: abs_mult)
haftmann@36301
  1158
hoelzl@51520
  1159
lemma abs_diff_less_iff:
hoelzl@51520
  1160
  "\<bar>x - a\<bar> < r \<longleftrightarrow> a - r < x \<and> x < a + r"
hoelzl@51520
  1161
  by (auto simp add: diff_less_eq ac_simps abs_less_iff)
hoelzl@51520
  1162
haftmann@36301
  1163
end
avigad@16775
  1164
haftmann@52435
  1165
code_identifier
haftmann@52435
  1166
  code_module Rings \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith
haftmann@33364
  1167
paulson@14265
  1168
end
haftmann@52435
  1169