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