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