src/HOL/Rings.thy
author hoelzl
Wed Apr 09 09:37:48 2014 +0200 (2014-04-09)
changeset 56480 093ea91498e6
parent 56217 dc429a5b13c4
child 56536 aefb4a8da31f
permissions -rw-r--r--
field_simps: better support for negation and division, and power
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
lp15@56217
   379
lemma mult_left_cancel: "c \<noteq> 0 \<Longrightarrow> (c*a=c*b) = (a=b)"
lp15@56217
   380
by simp 
lp15@56217
   381
lp15@56217
   382
lemma mult_right_cancel: "c \<noteq> 0 \<Longrightarrow> (a*c=b*c) = (a=b)"
lp15@56217
   383
by simp 
lp15@56217
   384
haftmann@25230
   385
end
huffman@22990
   386
huffman@23544
   387
class ring_1_no_zero_divisors = ring_1 + ring_no_zero_divisors
haftmann@26274
   388
begin
haftmann@26274
   389
huffman@36970
   390
lemma square_eq_1_iff:
huffman@36821
   391
  "x * x = 1 \<longleftrightarrow> x = 1 \<or> x = - 1"
huffman@36821
   392
proof -
huffman@36821
   393
  have "(x - 1) * (x + 1) = x * x - 1"
huffman@36821
   394
    by (simp add: algebra_simps)
huffman@36821
   395
  hence "x * x = 1 \<longleftrightarrow> (x - 1) * (x + 1) = 0"
huffman@36821
   396
    by simp
huffman@36821
   397
  thus ?thesis
huffman@36821
   398
    by (simp add: eq_neg_iff_add_eq_0)
huffman@36821
   399
qed
huffman@36821
   400
haftmann@26274
   401
lemma mult_cancel_right1 [simp]:
haftmann@26274
   402
  "c = b * c \<longleftrightarrow> c = 0 \<or> b = 1"
nipkow@29667
   403
by (insert mult_cancel_right [of 1 c b], force)
haftmann@26274
   404
haftmann@26274
   405
lemma mult_cancel_right2 [simp]:
haftmann@26274
   406
  "a * c = c \<longleftrightarrow> c = 0 \<or> a = 1"
nipkow@29667
   407
by (insert mult_cancel_right [of a c 1], simp)
haftmann@26274
   408
 
haftmann@26274
   409
lemma mult_cancel_left1 [simp]:
haftmann@26274
   410
  "c = c * b \<longleftrightarrow> c = 0 \<or> b = 1"
nipkow@29667
   411
by (insert mult_cancel_left [of c 1 b], force)
haftmann@26274
   412
haftmann@26274
   413
lemma mult_cancel_left2 [simp]:
haftmann@26274
   414
  "c * a = c \<longleftrightarrow> c = 0 \<or> a = 1"
nipkow@29667
   415
by (insert mult_cancel_left [of c a 1], simp)
haftmann@26274
   416
haftmann@26274
   417
end
huffman@22990
   418
haftmann@22390
   419
class idom = comm_ring_1 + no_zero_divisors
haftmann@25186
   420
begin
paulson@14421
   421
huffman@27516
   422
subclass ring_1_no_zero_divisors ..
huffman@22990
   423
huffman@29915
   424
lemma square_eq_iff: "a * a = b * b \<longleftrightarrow> (a = b \<or> a = - b)"
huffman@29915
   425
proof
huffman@29915
   426
  assume "a * a = b * b"
huffman@29915
   427
  then have "(a - b) * (a + b) = 0"
huffman@29915
   428
    by (simp add: algebra_simps)
huffman@29915
   429
  then show "a = b \<or> a = - b"
huffman@35216
   430
    by (simp add: eq_neg_iff_add_eq_0)
huffman@29915
   431
next
huffman@29915
   432
  assume "a = b \<or> a = - b"
huffman@29915
   433
  then show "a * a = b * b" by auto
huffman@29915
   434
qed
huffman@29915
   435
huffman@29981
   436
lemma dvd_mult_cancel_right [simp]:
huffman@29981
   437
  "a * c dvd b * c \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   438
proof -
huffman@29981
   439
  have "a * c dvd b * c \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
huffman@29981
   440
    unfolding dvd_def by (simp add: mult_ac)
huffman@29981
   441
  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   442
    unfolding dvd_def by simp
huffman@29981
   443
  finally show ?thesis .
huffman@29981
   444
qed
huffman@29981
   445
huffman@29981
   446
lemma dvd_mult_cancel_left [simp]:
huffman@29981
   447
  "c * a dvd c * b \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   448
proof -
huffman@29981
   449
  have "c * a dvd c * b \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
huffman@29981
   450
    unfolding dvd_def by (simp add: mult_ac)
huffman@29981
   451
  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   452
    unfolding dvd_def by simp
huffman@29981
   453
  finally show ?thesis .
huffman@29981
   454
qed
huffman@29981
   455
haftmann@25186
   456
end
haftmann@25152
   457
haftmann@35302
   458
text {*
haftmann@35302
   459
  The theory of partially ordered rings is taken from the books:
haftmann@35302
   460
  \begin{itemize}
haftmann@35302
   461
  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
haftmann@35302
   462
  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
haftmann@35302
   463
  \end{itemize}
haftmann@35302
   464
  Most of the used notions can also be looked up in 
haftmann@35302
   465
  \begin{itemize}
wenzelm@54703
   466
  \item @{url "http://www.mathworld.com"} by Eric Weisstein et. al.
haftmann@35302
   467
  \item \emph{Algebra I} by van der Waerden, Springer.
haftmann@35302
   468
  \end{itemize}
haftmann@35302
   469
*}
haftmann@35302
   470
haftmann@38642
   471
class ordered_semiring = semiring + comm_monoid_add + ordered_ab_semigroup_add +
haftmann@38642
   472
  assumes mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
haftmann@38642
   473
  assumes mult_right_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c"
haftmann@25230
   474
begin
haftmann@25230
   475
haftmann@25230
   476
lemma mult_mono:
haftmann@38642
   477
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * d"
haftmann@25230
   478
apply (erule mult_right_mono [THEN order_trans], assumption)
haftmann@25230
   479
apply (erule mult_left_mono, assumption)
haftmann@25230
   480
done
haftmann@25230
   481
haftmann@25230
   482
lemma mult_mono':
haftmann@38642
   483
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> a \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * d"
haftmann@25230
   484
apply (rule mult_mono)
haftmann@25230
   485
apply (fast intro: order_trans)+
haftmann@25230
   486
done
haftmann@25230
   487
haftmann@25230
   488
end
krauss@21199
   489
haftmann@38642
   490
class ordered_cancel_semiring = ordered_semiring + cancel_comm_monoid_add
haftmann@25267
   491
begin
paulson@14268
   492
huffman@27516
   493
subclass semiring_0_cancel ..
obua@23521
   494
haftmann@25230
   495
lemma mult_nonneg_nonneg: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a * b"
haftmann@36301
   496
using mult_left_mono [of 0 b a] by simp
haftmann@25230
   497
haftmann@25230
   498
lemma mult_nonneg_nonpos: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> a * b \<le> 0"
haftmann@36301
   499
using mult_left_mono [of b 0 a] by simp
huffman@30692
   500
huffman@30692
   501
lemma mult_nonpos_nonneg: "a \<le> 0 \<Longrightarrow> 0 \<le> b \<Longrightarrow> a * b \<le> 0"
haftmann@36301
   502
using mult_right_mono [of a 0 b] by simp
huffman@30692
   503
huffman@30692
   504
text {* Legacy - use @{text mult_nonpos_nonneg} *}
haftmann@25230
   505
lemma mult_nonneg_nonpos2: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> b * a \<le> 0" 
haftmann@36301
   506
by (drule mult_right_mono [of b 0], auto)
haftmann@25230
   507
haftmann@26234
   508
lemma split_mult_neg_le: "(0 \<le> a & b \<le> 0) | (a \<le> 0 & 0 \<le> b) \<Longrightarrow> a * b \<le> 0" 
nipkow@29667
   509
by (auto simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)
haftmann@25230
   510
haftmann@25230
   511
end
haftmann@25230
   512
haftmann@38642
   513
class linordered_semiring = ordered_semiring + linordered_cancel_ab_semigroup_add
haftmann@25267
   514
begin
haftmann@25230
   515
haftmann@35028
   516
subclass ordered_cancel_semiring ..
haftmann@35028
   517
haftmann@35028
   518
subclass ordered_comm_monoid_add ..
haftmann@25304
   519
haftmann@25230
   520
lemma mult_left_less_imp_less:
haftmann@25230
   521
  "c * a < c * b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
nipkow@29667
   522
by (force simp add: mult_left_mono not_le [symmetric])
haftmann@25230
   523
 
haftmann@25230
   524
lemma mult_right_less_imp_less:
haftmann@25230
   525
  "a * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
nipkow@29667
   526
by (force simp add: mult_right_mono not_le [symmetric])
obua@23521
   527
haftmann@25186
   528
end
haftmann@25152
   529
haftmann@35043
   530
class linordered_semiring_1 = linordered_semiring + semiring_1
hoelzl@36622
   531
begin
hoelzl@36622
   532
hoelzl@36622
   533
lemma convex_bound_le:
hoelzl@36622
   534
  assumes "x \<le> a" "y \<le> a" "0 \<le> u" "0 \<le> v" "u + v = 1"
hoelzl@36622
   535
  shows "u * x + v * y \<le> a"
hoelzl@36622
   536
proof-
hoelzl@36622
   537
  from assms have "u * x + v * y \<le> u * a + v * a"
hoelzl@36622
   538
    by (simp add: add_mono mult_left_mono)
webertj@49962
   539
  thus ?thesis using assms unfolding distrib_right[symmetric] by simp
hoelzl@36622
   540
qed
hoelzl@36622
   541
hoelzl@36622
   542
end
haftmann@35043
   543
haftmann@35043
   544
class linordered_semiring_strict = semiring + comm_monoid_add + linordered_cancel_ab_semigroup_add +
haftmann@25062
   545
  assumes mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
haftmann@25062
   546
  assumes mult_strict_right_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> a * c < b * c"
haftmann@25267
   547
begin
paulson@14341
   548
huffman@27516
   549
subclass semiring_0_cancel ..
obua@14940
   550
haftmann@35028
   551
subclass linordered_semiring
haftmann@28823
   552
proof
huffman@23550
   553
  fix a b c :: 'a
huffman@23550
   554
  assume A: "a \<le> b" "0 \<le> c"
huffman@23550
   555
  from A show "c * a \<le> c * b"
haftmann@25186
   556
    unfolding le_less
haftmann@25186
   557
    using mult_strict_left_mono by (cases "c = 0") auto
huffman@23550
   558
  from A show "a * c \<le> b * c"
haftmann@25152
   559
    unfolding le_less
haftmann@25186
   560
    using mult_strict_right_mono by (cases "c = 0") auto
haftmann@25152
   561
qed
haftmann@25152
   562
haftmann@25230
   563
lemma mult_left_le_imp_le:
haftmann@25230
   564
  "c * a \<le> c * b \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
nipkow@29667
   565
by (force simp add: mult_strict_left_mono _not_less [symmetric])
haftmann@25230
   566
 
haftmann@25230
   567
lemma mult_right_le_imp_le:
haftmann@25230
   568
  "a * c \<le> b * c \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
nipkow@29667
   569
by (force simp add: mult_strict_right_mono not_less [symmetric])
haftmann@25230
   570
huffman@30692
   571
lemma mult_pos_pos: "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> 0 < a * b"
haftmann@36301
   572
using mult_strict_left_mono [of 0 b a] by simp
huffman@30692
   573
huffman@30692
   574
lemma mult_pos_neg: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> a * b < 0"
haftmann@36301
   575
using mult_strict_left_mono [of b 0 a] by simp
huffman@30692
   576
huffman@30692
   577
lemma mult_neg_pos: "a < 0 \<Longrightarrow> 0 < b \<Longrightarrow> a * b < 0"
haftmann@36301
   578
using mult_strict_right_mono [of a 0 b] by simp
huffman@30692
   579
huffman@30692
   580
text {* Legacy - use @{text mult_neg_pos} *}
huffman@30692
   581
lemma mult_pos_neg2: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> b * a < 0" 
haftmann@36301
   582
by (drule mult_strict_right_mono [of b 0], auto)
haftmann@25230
   583
haftmann@25230
   584
lemma zero_less_mult_pos:
haftmann@25230
   585
  "0 < a * b \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
huffman@30692
   586
apply (cases "b\<le>0")
haftmann@25230
   587
 apply (auto simp add: le_less not_less)
huffman@30692
   588
apply (drule_tac mult_pos_neg [of a b])
haftmann@25230
   589
 apply (auto dest: less_not_sym)
haftmann@25230
   590
done
haftmann@25230
   591
haftmann@25230
   592
lemma zero_less_mult_pos2:
haftmann@25230
   593
  "0 < b * a \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
huffman@30692
   594
apply (cases "b\<le>0")
haftmann@25230
   595
 apply (auto simp add: le_less not_less)
huffman@30692
   596
apply (drule_tac mult_pos_neg2 [of a b])
haftmann@25230
   597
 apply (auto dest: less_not_sym)
haftmann@25230
   598
done
haftmann@25230
   599
haftmann@26193
   600
text{*Strict monotonicity in both arguments*}
haftmann@26193
   601
lemma mult_strict_mono:
haftmann@26193
   602
  assumes "a < b" and "c < d" and "0 < b" and "0 \<le> c"
haftmann@26193
   603
  shows "a * c < b * d"
haftmann@26193
   604
  using assms apply (cases "c=0")
huffman@30692
   605
  apply (simp add: mult_pos_pos)
haftmann@26193
   606
  apply (erule mult_strict_right_mono [THEN less_trans])
huffman@30692
   607
  apply (force simp add: le_less)
haftmann@26193
   608
  apply (erule mult_strict_left_mono, assumption)
haftmann@26193
   609
  done
haftmann@26193
   610
haftmann@26193
   611
text{*This weaker variant has more natural premises*}
haftmann@26193
   612
lemma mult_strict_mono':
haftmann@26193
   613
  assumes "a < b" and "c < d" and "0 \<le> a" and "0 \<le> c"
haftmann@26193
   614
  shows "a * c < b * d"
nipkow@29667
   615
by (rule mult_strict_mono) (insert assms, auto)
haftmann@26193
   616
haftmann@26193
   617
lemma mult_less_le_imp_less:
haftmann@26193
   618
  assumes "a < b" and "c \<le> d" and "0 \<le> a" and "0 < c"
haftmann@26193
   619
  shows "a * c < b * d"
haftmann@26193
   620
  using assms apply (subgoal_tac "a * c < b * c")
haftmann@26193
   621
  apply (erule less_le_trans)
haftmann@26193
   622
  apply (erule mult_left_mono)
haftmann@26193
   623
  apply simp
haftmann@26193
   624
  apply (erule mult_strict_right_mono)
haftmann@26193
   625
  apply assumption
haftmann@26193
   626
  done
haftmann@26193
   627
haftmann@26193
   628
lemma mult_le_less_imp_less:
haftmann@26193
   629
  assumes "a \<le> b" and "c < d" and "0 < a" and "0 \<le> c"
haftmann@26193
   630
  shows "a * c < b * d"
haftmann@26193
   631
  using assms apply (subgoal_tac "a * c \<le> b * c")
haftmann@26193
   632
  apply (erule le_less_trans)
haftmann@26193
   633
  apply (erule mult_strict_left_mono)
haftmann@26193
   634
  apply simp
haftmann@26193
   635
  apply (erule mult_right_mono)
haftmann@26193
   636
  apply simp
haftmann@26193
   637
  done
haftmann@26193
   638
haftmann@26193
   639
lemma mult_less_imp_less_left:
haftmann@26193
   640
  assumes less: "c * a < c * b" and nonneg: "0 \<le> c"
haftmann@26193
   641
  shows "a < b"
haftmann@26193
   642
proof (rule ccontr)
haftmann@26193
   643
  assume "\<not>  a < b"
haftmann@26193
   644
  hence "b \<le> a" by (simp add: linorder_not_less)
haftmann@26193
   645
  hence "c * b \<le> c * a" using nonneg by (rule mult_left_mono)
nipkow@29667
   646
  with this and less show False by (simp add: not_less [symmetric])
haftmann@26193
   647
qed
haftmann@26193
   648
haftmann@26193
   649
lemma mult_less_imp_less_right:
haftmann@26193
   650
  assumes less: "a * c < b * c" and nonneg: "0 \<le> c"
haftmann@26193
   651
  shows "a < b"
haftmann@26193
   652
proof (rule ccontr)
haftmann@26193
   653
  assume "\<not> a < b"
haftmann@26193
   654
  hence "b \<le> a" by (simp add: linorder_not_less)
haftmann@26193
   655
  hence "b * c \<le> a * c" using nonneg by (rule mult_right_mono)
nipkow@29667
   656
  with this and less show False by (simp add: not_less [symmetric])
haftmann@26193
   657
qed  
haftmann@26193
   658
haftmann@25230
   659
end
haftmann@25230
   660
haftmann@35097
   661
class linordered_semiring_1_strict = linordered_semiring_strict + semiring_1
hoelzl@36622
   662
begin
hoelzl@36622
   663
hoelzl@36622
   664
subclass linordered_semiring_1 ..
hoelzl@36622
   665
hoelzl@36622
   666
lemma convex_bound_lt:
hoelzl@36622
   667
  assumes "x < a" "y < a" "0 \<le> u" "0 \<le> v" "u + v = 1"
hoelzl@36622
   668
  shows "u * x + v * y < a"
hoelzl@36622
   669
proof -
hoelzl@36622
   670
  from assms have "u * x + v * y < u * a + v * a"
hoelzl@36622
   671
    by (cases "u = 0")
hoelzl@36622
   672
       (auto intro!: add_less_le_mono mult_strict_left_mono mult_left_mono)
webertj@49962
   673
  thus ?thesis using assms unfolding distrib_right[symmetric] by simp
hoelzl@36622
   674
qed
hoelzl@36622
   675
hoelzl@36622
   676
end
haftmann@33319
   677
haftmann@38642
   678
class ordered_comm_semiring = comm_semiring_0 + ordered_ab_semigroup_add + 
haftmann@38642
   679
  assumes comm_mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
haftmann@25186
   680
begin
haftmann@25152
   681
haftmann@35028
   682
subclass ordered_semiring
haftmann@28823
   683
proof
krauss@21199
   684
  fix a b c :: 'a
huffman@23550
   685
  assume "a \<le> b" "0 \<le> c"
haftmann@38642
   686
  thus "c * a \<le> c * b" by (rule comm_mult_left_mono)
huffman@23550
   687
  thus "a * c \<le> b * c" by (simp only: mult_commute)
krauss@21199
   688
qed
paulson@14265
   689
haftmann@25267
   690
end
haftmann@25267
   691
haftmann@38642
   692
class ordered_cancel_comm_semiring = ordered_comm_semiring + cancel_comm_monoid_add
haftmann@25267
   693
begin
paulson@14265
   694
haftmann@38642
   695
subclass comm_semiring_0_cancel ..
haftmann@35028
   696
subclass ordered_comm_semiring ..
haftmann@35028
   697
subclass ordered_cancel_semiring ..
haftmann@25267
   698
haftmann@25267
   699
end
haftmann@25267
   700
haftmann@35028
   701
class linordered_comm_semiring_strict = comm_semiring_0 + linordered_cancel_ab_semigroup_add +
haftmann@38642
   702
  assumes comm_mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
haftmann@25267
   703
begin
haftmann@25267
   704
haftmann@35043
   705
subclass linordered_semiring_strict
haftmann@28823
   706
proof
huffman@23550
   707
  fix a b c :: 'a
huffman@23550
   708
  assume "a < b" "0 < c"
haftmann@38642
   709
  thus "c * a < c * b" by (rule comm_mult_strict_left_mono)
huffman@23550
   710
  thus "a * c < b * c" by (simp only: mult_commute)
huffman@23550
   711
qed
paulson@14272
   712
haftmann@35028
   713
subclass ordered_cancel_comm_semiring
haftmann@28823
   714
proof
huffman@23550
   715
  fix a b c :: 'a
huffman@23550
   716
  assume "a \<le> b" "0 \<le> c"
huffman@23550
   717
  thus "c * a \<le> c * b"
haftmann@25186
   718
    unfolding le_less
haftmann@26193
   719
    using mult_strict_left_mono by (cases "c = 0") auto
huffman@23550
   720
qed
paulson@14272
   721
haftmann@25267
   722
end
haftmann@25230
   723
haftmann@35028
   724
class ordered_ring = ring + ordered_cancel_semiring 
haftmann@25267
   725
begin
haftmann@25230
   726
haftmann@35028
   727
subclass ordered_ab_group_add ..
paulson@14270
   728
haftmann@25230
   729
lemma less_add_iff1:
haftmann@25230
   730
  "a * e + c < b * e + d \<longleftrightarrow> (a - b) * e + c < d"
nipkow@29667
   731
by (simp add: algebra_simps)
haftmann@25230
   732
haftmann@25230
   733
lemma less_add_iff2:
haftmann@25230
   734
  "a * e + c < b * e + d \<longleftrightarrow> c < (b - a) * e + d"
nipkow@29667
   735
by (simp add: algebra_simps)
haftmann@25230
   736
haftmann@25230
   737
lemma le_add_iff1:
haftmann@25230
   738
  "a * e + c \<le> b * e + d \<longleftrightarrow> (a - b) * e + c \<le> d"
nipkow@29667
   739
by (simp add: algebra_simps)
haftmann@25230
   740
haftmann@25230
   741
lemma le_add_iff2:
haftmann@25230
   742
  "a * e + c \<le> b * e + d \<longleftrightarrow> c \<le> (b - a) * e + d"
nipkow@29667
   743
by (simp add: algebra_simps)
haftmann@25230
   744
haftmann@25230
   745
lemma mult_left_mono_neg:
haftmann@25230
   746
  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> c * a \<le> c * b"
haftmann@36301
   747
  apply (drule mult_left_mono [of _ _ "- c"])
huffman@35216
   748
  apply simp_all
haftmann@25230
   749
  done
haftmann@25230
   750
haftmann@25230
   751
lemma mult_right_mono_neg:
haftmann@25230
   752
  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> a * c \<le> b * c"
haftmann@36301
   753
  apply (drule mult_right_mono [of _ _ "- c"])
huffman@35216
   754
  apply simp_all
haftmann@25230
   755
  done
haftmann@25230
   756
huffman@30692
   757
lemma mult_nonpos_nonpos: "a \<le> 0 \<Longrightarrow> b \<le> 0 \<Longrightarrow> 0 \<le> a * b"
haftmann@36301
   758
using mult_right_mono_neg [of a 0 b] by simp
haftmann@25230
   759
haftmann@25230
   760
lemma split_mult_pos_le:
haftmann@25230
   761
  "(0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0) \<Longrightarrow> 0 \<le> a * b"
nipkow@29667
   762
by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos)
haftmann@25186
   763
haftmann@25186
   764
end
paulson@14270
   765
haftmann@35028
   766
class linordered_ring = ring + linordered_semiring + linordered_ab_group_add + abs_if
haftmann@25304
   767
begin
haftmann@25304
   768
haftmann@35028
   769
subclass ordered_ring ..
haftmann@35028
   770
haftmann@35028
   771
subclass ordered_ab_group_add_abs
haftmann@28823
   772
proof
haftmann@25304
   773
  fix a b
haftmann@25304
   774
  show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
haftmann@54230
   775
    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
   776
qed (auto simp add: abs_if)
haftmann@25304
   777
huffman@35631
   778
lemma zero_le_square [simp]: "0 \<le> a * a"
huffman@35631
   779
  using linear [of 0 a]
huffman@35631
   780
  by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos)
huffman@35631
   781
huffman@35631
   782
lemma not_square_less_zero [simp]: "\<not> (a * a < 0)"
huffman@35631
   783
  by (simp add: not_less)
huffman@35631
   784
haftmann@25304
   785
end
obua@23521
   786
haftmann@35028
   787
(* The "strict" suffix can be seen as describing the combination of linordered_ring and no_zero_divisors.
haftmann@35043
   788
   Basically, linordered_ring + no_zero_divisors = linordered_ring_strict.
haftmann@25230
   789
 *)
haftmann@35043
   790
class linordered_ring_strict = ring + linordered_semiring_strict
haftmann@25304
   791
  + ordered_ab_group_add + abs_if
haftmann@25230
   792
begin
paulson@14348
   793
haftmann@35028
   794
subclass linordered_ring ..
haftmann@25304
   795
huffman@30692
   796
lemma mult_strict_left_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> c * a < c * b"
huffman@30692
   797
using mult_strict_left_mono [of b a "- c"] by simp
huffman@30692
   798
huffman@30692
   799
lemma mult_strict_right_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> a * c < b * c"
huffman@30692
   800
using mult_strict_right_mono [of b a "- c"] by simp
huffman@30692
   801
huffman@30692
   802
lemma mult_neg_neg: "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> 0 < a * b"
haftmann@36301
   803
using mult_strict_right_mono_neg [of a 0 b] by simp
obua@14738
   804
haftmann@25917
   805
subclass ring_no_zero_divisors
haftmann@28823
   806
proof
haftmann@25917
   807
  fix a b
haftmann@25917
   808
  assume "a \<noteq> 0" then have A: "a < 0 \<or> 0 < a" by (simp add: neq_iff)
haftmann@25917
   809
  assume "b \<noteq> 0" then have B: "b < 0 \<or> 0 < b" by (simp add: neq_iff)
haftmann@25917
   810
  have "a * b < 0 \<or> 0 < a * b"
haftmann@25917
   811
  proof (cases "a < 0")
haftmann@25917
   812
    case True note A' = this
haftmann@25917
   813
    show ?thesis proof (cases "b < 0")
haftmann@25917
   814
      case True with A'
haftmann@25917
   815
      show ?thesis by (auto dest: mult_neg_neg)
haftmann@25917
   816
    next
haftmann@25917
   817
      case False with B have "0 < b" by auto
haftmann@25917
   818
      with A' show ?thesis by (auto dest: mult_strict_right_mono)
haftmann@25917
   819
    qed
haftmann@25917
   820
  next
haftmann@25917
   821
    case False with A have A': "0 < a" by auto
haftmann@25917
   822
    show ?thesis proof (cases "b < 0")
haftmann@25917
   823
      case True with A'
haftmann@25917
   824
      show ?thesis by (auto dest: mult_strict_right_mono_neg)
haftmann@25917
   825
    next
haftmann@25917
   826
      case False with B have "0 < b" by auto
haftmann@25917
   827
      with A' show ?thesis by (auto dest: mult_pos_pos)
haftmann@25917
   828
    qed
haftmann@25917
   829
  qed
haftmann@25917
   830
  then show "a * b \<noteq> 0" by (simp add: neq_iff)
haftmann@25917
   831
qed
haftmann@25304
   832
hoelzl@56480
   833
lemma zero_less_mult_iff: "0 < a * b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0"
hoelzl@56480
   834
  by (cases a 0 b 0 rule: linorder_cases[case_product linorder_cases])
hoelzl@56480
   835
     (auto simp add: mult_pos_pos mult_neg_neg not_less le_less dest: zero_less_mult_pos zero_less_mult_pos2)
huffman@22990
   836
hoelzl@56480
   837
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
   838
  by (auto simp add: eq_commute [of 0] le_less not_less zero_less_mult_iff)
paulson@14265
   839
paulson@14265
   840
lemma mult_less_0_iff:
haftmann@25917
   841
  "a * b < 0 \<longleftrightarrow> 0 < a \<and> b < 0 \<or> a < 0 \<and> 0 < b"
huffman@35216
   842
  apply (insert zero_less_mult_iff [of "-a" b])
huffman@35216
   843
  apply force
haftmann@25917
   844
  done
paulson@14265
   845
paulson@14265
   846
lemma mult_le_0_iff:
haftmann@25917
   847
  "a * b \<le> 0 \<longleftrightarrow> 0 \<le> a \<and> b \<le> 0 \<or> a \<le> 0 \<and> 0 \<le> b"
haftmann@25917
   848
  apply (insert zero_le_mult_iff [of "-a" b]) 
huffman@35216
   849
  apply force
haftmann@25917
   850
  done
haftmann@25917
   851
haftmann@26193
   852
text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
haftmann@26193
   853
   also with the relations @{text "\<le>"} and equality.*}
haftmann@26193
   854
haftmann@26193
   855
text{*These ``disjunction'' versions produce two cases when the comparison is
haftmann@26193
   856
 an assumption, but effectively four when the comparison is a goal.*}
haftmann@26193
   857
haftmann@26193
   858
lemma mult_less_cancel_right_disj:
haftmann@26193
   859
  "a * c < b * c \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
   860
  apply (cases "c = 0")
haftmann@26193
   861
  apply (auto simp add: neq_iff mult_strict_right_mono 
haftmann@26193
   862
                      mult_strict_right_mono_neg)
haftmann@26193
   863
  apply (auto simp add: not_less 
haftmann@26193
   864
                      not_le [symmetric, of "a*c"]
haftmann@26193
   865
                      not_le [symmetric, of a])
haftmann@26193
   866
  apply (erule_tac [!] notE)
haftmann@26193
   867
  apply (auto simp add: less_imp_le mult_right_mono 
haftmann@26193
   868
                      mult_right_mono_neg)
haftmann@26193
   869
  done
haftmann@26193
   870
haftmann@26193
   871
lemma mult_less_cancel_left_disj:
haftmann@26193
   872
  "c * a < c * b \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
   873
  apply (cases "c = 0")
haftmann@26193
   874
  apply (auto simp add: neq_iff mult_strict_left_mono 
haftmann@26193
   875
                      mult_strict_left_mono_neg)
haftmann@26193
   876
  apply (auto simp add: not_less 
haftmann@26193
   877
                      not_le [symmetric, of "c*a"]
haftmann@26193
   878
                      not_le [symmetric, of a])
haftmann@26193
   879
  apply (erule_tac [!] notE)
haftmann@26193
   880
  apply (auto simp add: less_imp_le mult_left_mono 
haftmann@26193
   881
                      mult_left_mono_neg)
haftmann@26193
   882
  done
haftmann@26193
   883
haftmann@26193
   884
text{*The ``conjunction of implication'' lemmas produce two cases when the
haftmann@26193
   885
comparison is a goal, but give four when the comparison is an assumption.*}
haftmann@26193
   886
haftmann@26193
   887
lemma mult_less_cancel_right:
haftmann@26193
   888
  "a * c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
   889
  using mult_less_cancel_right_disj [of a c b] by auto
haftmann@26193
   890
haftmann@26193
   891
lemma mult_less_cancel_left:
haftmann@26193
   892
  "c * a < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
   893
  using mult_less_cancel_left_disj [of c a b] by auto
haftmann@26193
   894
haftmann@26193
   895
lemma mult_le_cancel_right:
haftmann@26193
   896
   "a * c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
nipkow@29667
   897
by (simp add: not_less [symmetric] mult_less_cancel_right_disj)
haftmann@26193
   898
haftmann@26193
   899
lemma mult_le_cancel_left:
haftmann@26193
   900
  "c * a \<le> c * b \<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_left_disj)
haftmann@26193
   902
nipkow@30649
   903
lemma mult_le_cancel_left_pos:
nipkow@30649
   904
  "0 < c \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> a \<le> b"
nipkow@30649
   905
by (auto simp: mult_le_cancel_left)
nipkow@30649
   906
nipkow@30649
   907
lemma mult_le_cancel_left_neg:
nipkow@30649
   908
  "c < 0 \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> b \<le> a"
nipkow@30649
   909
by (auto simp: mult_le_cancel_left)
nipkow@30649
   910
nipkow@30649
   911
lemma mult_less_cancel_left_pos:
nipkow@30649
   912
  "0 < c \<Longrightarrow> c * a < c * b \<longleftrightarrow> a < b"
nipkow@30649
   913
by (auto simp: mult_less_cancel_left)
nipkow@30649
   914
nipkow@30649
   915
lemma mult_less_cancel_left_neg:
nipkow@30649
   916
  "c < 0 \<Longrightarrow> c * a < c * b \<longleftrightarrow> b < a"
nipkow@30649
   917
by (auto simp: mult_less_cancel_left)
nipkow@30649
   918
haftmann@25917
   919
end
paulson@14265
   920
huffman@30692
   921
lemmas mult_sign_intros =
huffman@30692
   922
  mult_nonneg_nonneg mult_nonneg_nonpos
huffman@30692
   923
  mult_nonpos_nonneg mult_nonpos_nonpos
huffman@30692
   924
  mult_pos_pos mult_pos_neg
huffman@30692
   925
  mult_neg_pos mult_neg_neg
haftmann@25230
   926
haftmann@35028
   927
class ordered_comm_ring = comm_ring + ordered_comm_semiring
haftmann@25267
   928
begin
haftmann@25230
   929
haftmann@35028
   930
subclass ordered_ring ..
haftmann@35028
   931
subclass ordered_cancel_comm_semiring ..
haftmann@25230
   932
haftmann@25267
   933
end
haftmann@25230
   934
haftmann@35028
   935
class linordered_semidom = comm_semiring_1_cancel + linordered_comm_semiring_strict +
haftmann@35028
   936
  (*previously linordered_semiring*)
haftmann@25230
   937
  assumes zero_less_one [simp]: "0 < 1"
haftmann@25230
   938
begin
haftmann@25230
   939
haftmann@25230
   940
lemma pos_add_strict:
haftmann@25230
   941
  shows "0 < a \<Longrightarrow> b < c \<Longrightarrow> b < a + c"
haftmann@36301
   942
  using add_strict_mono [of 0 a b c] by simp
haftmann@25230
   943
haftmann@26193
   944
lemma zero_le_one [simp]: "0 \<le> 1"
nipkow@29667
   945
by (rule zero_less_one [THEN less_imp_le]) 
haftmann@26193
   946
haftmann@26193
   947
lemma not_one_le_zero [simp]: "\<not> 1 \<le> 0"
nipkow@29667
   948
by (simp add: not_le) 
haftmann@26193
   949
haftmann@26193
   950
lemma not_one_less_zero [simp]: "\<not> 1 < 0"
nipkow@29667
   951
by (simp add: not_less) 
haftmann@26193
   952
haftmann@26193
   953
lemma less_1_mult:
haftmann@26193
   954
  assumes "1 < m" and "1 < n"
haftmann@26193
   955
  shows "1 < m * n"
haftmann@26193
   956
  using assms mult_strict_mono [of 1 m 1 n]
haftmann@26193
   957
    by (simp add:  less_trans [OF zero_less_one]) 
haftmann@26193
   958
haftmann@25230
   959
end
haftmann@25230
   960
haftmann@35028
   961
class linordered_idom = comm_ring_1 +
haftmann@35028
   962
  linordered_comm_semiring_strict + ordered_ab_group_add +
haftmann@25230
   963
  abs_if + sgn_if
haftmann@35028
   964
  (*previously linordered_ring*)
haftmann@25917
   965
begin
haftmann@25917
   966
hoelzl@36622
   967
subclass linordered_semiring_1_strict ..
haftmann@35043
   968
subclass linordered_ring_strict ..
haftmann@35028
   969
subclass ordered_comm_ring ..
huffman@27516
   970
subclass idom ..
haftmann@25917
   971
haftmann@35028
   972
subclass linordered_semidom
haftmann@28823
   973
proof
haftmann@26193
   974
  have "0 \<le> 1 * 1" by (rule zero_le_square)
haftmann@26193
   975
  thus "0 < 1" by (simp add: le_less)
haftmann@25917
   976
qed 
haftmann@25917
   977
haftmann@35028
   978
lemma linorder_neqE_linordered_idom:
haftmann@26193
   979
  assumes "x \<noteq> y" obtains "x < y" | "y < x"
haftmann@26193
   980
  using assms by (rule neqE)
haftmann@26193
   981
haftmann@26274
   982
text {* These cancellation simprules also produce two cases when the comparison is a goal. *}
haftmann@26274
   983
haftmann@26274
   984
lemma mult_le_cancel_right1:
haftmann@26274
   985
  "c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
nipkow@29667
   986
by (insert mult_le_cancel_right [of 1 c b], simp)
haftmann@26274
   987
haftmann@26274
   988
lemma mult_le_cancel_right2:
haftmann@26274
   989
  "a * c \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
nipkow@29667
   990
by (insert mult_le_cancel_right [of a c 1], simp)
haftmann@26274
   991
haftmann@26274
   992
lemma mult_le_cancel_left1:
haftmann@26274
   993
  "c \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
nipkow@29667
   994
by (insert mult_le_cancel_left [of c 1 b], simp)
haftmann@26274
   995
haftmann@26274
   996
lemma mult_le_cancel_left2:
haftmann@26274
   997
  "c * a \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
nipkow@29667
   998
by (insert mult_le_cancel_left [of c a 1], simp)
haftmann@26274
   999
haftmann@26274
  1000
lemma mult_less_cancel_right1:
haftmann@26274
  1001
  "c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
nipkow@29667
  1002
by (insert mult_less_cancel_right [of 1 c b], simp)
haftmann@26274
  1003
haftmann@26274
  1004
lemma mult_less_cancel_right2:
haftmann@26274
  1005
  "a * c < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
nipkow@29667
  1006
by (insert mult_less_cancel_right [of a c 1], simp)
haftmann@26274
  1007
haftmann@26274
  1008
lemma mult_less_cancel_left1:
haftmann@26274
  1009
  "c < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
nipkow@29667
  1010
by (insert mult_less_cancel_left [of c 1 b], simp)
haftmann@26274
  1011
haftmann@26274
  1012
lemma mult_less_cancel_left2:
haftmann@26274
  1013
  "c * a < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
nipkow@29667
  1014
by (insert mult_less_cancel_left [of c a 1], simp)
haftmann@26274
  1015
haftmann@27651
  1016
lemma sgn_sgn [simp]:
haftmann@27651
  1017
  "sgn (sgn a) = sgn a"
nipkow@29700
  1018
unfolding sgn_if by simp
haftmann@27651
  1019
haftmann@27651
  1020
lemma sgn_0_0:
haftmann@27651
  1021
  "sgn a = 0 \<longleftrightarrow> a = 0"
nipkow@29700
  1022
unfolding sgn_if by simp
haftmann@27651
  1023
haftmann@27651
  1024
lemma sgn_1_pos:
haftmann@27651
  1025
  "sgn a = 1 \<longleftrightarrow> a > 0"
huffman@35216
  1026
unfolding sgn_if by simp
haftmann@27651
  1027
haftmann@27651
  1028
lemma sgn_1_neg:
haftmann@27651
  1029
  "sgn a = - 1 \<longleftrightarrow> a < 0"
huffman@35216
  1030
unfolding sgn_if by auto
haftmann@27651
  1031
haftmann@29940
  1032
lemma sgn_pos [simp]:
haftmann@29940
  1033
  "0 < a \<Longrightarrow> sgn a = 1"
haftmann@29940
  1034
unfolding sgn_1_pos .
haftmann@29940
  1035
haftmann@29940
  1036
lemma sgn_neg [simp]:
haftmann@29940
  1037
  "a < 0 \<Longrightarrow> sgn a = - 1"
haftmann@29940
  1038
unfolding sgn_1_neg .
haftmann@29940
  1039
haftmann@27651
  1040
lemma sgn_times:
haftmann@27651
  1041
  "sgn (a * b) = sgn a * sgn b"
nipkow@29667
  1042
by (auto simp add: sgn_if zero_less_mult_iff)
haftmann@27651
  1043
haftmann@36301
  1044
lemma abs_sgn: "\<bar>k\<bar> = k * sgn k"
nipkow@29700
  1045
unfolding sgn_if abs_if by auto
nipkow@29700
  1046
haftmann@29940
  1047
lemma sgn_greater [simp]:
haftmann@29940
  1048
  "0 < sgn a \<longleftrightarrow> 0 < a"
haftmann@29940
  1049
  unfolding sgn_if by auto
haftmann@29940
  1050
haftmann@29940
  1051
lemma sgn_less [simp]:
haftmann@29940
  1052
  "sgn a < 0 \<longleftrightarrow> a < 0"
haftmann@29940
  1053
  unfolding sgn_if by auto
haftmann@29940
  1054
haftmann@36301
  1055
lemma abs_dvd_iff [simp]: "\<bar>m\<bar> dvd k \<longleftrightarrow> m dvd k"
huffman@29949
  1056
  by (simp add: abs_if)
huffman@29949
  1057
haftmann@36301
  1058
lemma dvd_abs_iff [simp]: "m dvd \<bar>k\<bar> \<longleftrightarrow> m dvd k"
huffman@29949
  1059
  by (simp add: abs_if)
haftmann@29653
  1060
nipkow@33676
  1061
lemma dvd_if_abs_eq:
haftmann@36301
  1062
  "\<bar>l\<bar> = \<bar>k\<bar> \<Longrightarrow> l dvd k"
nipkow@33676
  1063
by(subst abs_dvd_iff[symmetric]) simp
nipkow@33676
  1064
huffman@55912
  1065
text {* The following lemmas can be proven in more general structures, but
haftmann@54489
  1066
are dangerous as simp rules in absence of @{thm neg_equal_zero}, 
haftmann@54489
  1067
@{thm neg_less_pos}, @{thm neg_less_eq_nonneg}. *}
haftmann@54489
  1068
haftmann@54489
  1069
lemma equation_minus_iff_1 [simp, no_atp]:
haftmann@54489
  1070
  "1 = - a \<longleftrightarrow> a = - 1"
haftmann@54489
  1071
  by (fact equation_minus_iff)
haftmann@54489
  1072
haftmann@54489
  1073
lemma minus_equation_iff_1 [simp, no_atp]:
haftmann@54489
  1074
  "- a = 1 \<longleftrightarrow> a = - 1"
haftmann@54489
  1075
  by (subst minus_equation_iff, auto)
haftmann@54489
  1076
haftmann@54489
  1077
lemma le_minus_iff_1 [simp, no_atp]:
haftmann@54489
  1078
  "1 \<le> - b \<longleftrightarrow> b \<le> - 1"
haftmann@54489
  1079
  by (fact le_minus_iff)
haftmann@54489
  1080
haftmann@54489
  1081
lemma minus_le_iff_1 [simp, no_atp]:
haftmann@54489
  1082
  "- a \<le> 1 \<longleftrightarrow> - 1 \<le> a"
haftmann@54489
  1083
  by (fact minus_le_iff)
haftmann@54489
  1084
haftmann@54489
  1085
lemma less_minus_iff_1 [simp, no_atp]:
haftmann@54489
  1086
  "1 < - b \<longleftrightarrow> b < - 1"
haftmann@54489
  1087
  by (fact less_minus_iff)
haftmann@54489
  1088
haftmann@54489
  1089
lemma minus_less_iff_1 [simp, no_atp]:
haftmann@54489
  1090
  "- a < 1 \<longleftrightarrow> - 1 < a"
haftmann@54489
  1091
  by (fact minus_less_iff)
haftmann@54489
  1092
haftmann@25917
  1093
end
haftmann@25230
  1094
haftmann@26274
  1095
text {* Simprules for comparisons where common factors can be cancelled. *}
paulson@15234
  1096
blanchet@54147
  1097
lemmas mult_compare_simps =
paulson@15234
  1098
    mult_le_cancel_right mult_le_cancel_left
paulson@15234
  1099
    mult_le_cancel_right1 mult_le_cancel_right2
paulson@15234
  1100
    mult_le_cancel_left1 mult_le_cancel_left2
paulson@15234
  1101
    mult_less_cancel_right mult_less_cancel_left
paulson@15234
  1102
    mult_less_cancel_right1 mult_less_cancel_right2
paulson@15234
  1103
    mult_less_cancel_left1 mult_less_cancel_left2
paulson@15234
  1104
    mult_cancel_right mult_cancel_left
paulson@15234
  1105
    mult_cancel_right1 mult_cancel_right2
paulson@15234
  1106
    mult_cancel_left1 mult_cancel_left2
paulson@15234
  1107
haftmann@36301
  1108
text {* Reasoning about inequalities with division *}
avigad@16775
  1109
haftmann@35028
  1110
context linordered_semidom
haftmann@25193
  1111
begin
haftmann@25193
  1112
haftmann@25193
  1113
lemma less_add_one: "a < a + 1"
paulson@14293
  1114
proof -
haftmann@25193
  1115
  have "a + 0 < a + 1"
nipkow@23482
  1116
    by (blast intro: zero_less_one add_strict_left_mono)
paulson@14293
  1117
  thus ?thesis by simp
paulson@14293
  1118
qed
paulson@14293
  1119
haftmann@25193
  1120
lemma zero_less_two: "0 < 1 + 1"
nipkow@29667
  1121
by (blast intro: less_trans zero_less_one less_add_one)
haftmann@25193
  1122
haftmann@25193
  1123
end
paulson@14365
  1124
haftmann@36301
  1125
context linordered_idom
haftmann@36301
  1126
begin
paulson@15234
  1127
haftmann@36301
  1128
lemma mult_right_le_one_le:
haftmann@36301
  1129
  "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> y \<le> 1 \<Longrightarrow> x * y \<le> x"
haftmann@36301
  1130
  by (auto simp add: mult_le_cancel_left2)
haftmann@36301
  1131
haftmann@36301
  1132
lemma mult_left_le_one_le:
haftmann@36301
  1133
  "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> y \<le> 1 \<Longrightarrow> y * x \<le> x"
haftmann@36301
  1134
  by (auto simp add: mult_le_cancel_right2)
haftmann@36301
  1135
haftmann@36301
  1136
end
haftmann@36301
  1137
haftmann@36301
  1138
text {* Absolute Value *}
paulson@14293
  1139
haftmann@35028
  1140
context linordered_idom
haftmann@25304
  1141
begin
haftmann@25304
  1142
haftmann@36301
  1143
lemma mult_sgn_abs:
haftmann@36301
  1144
  "sgn x * \<bar>x\<bar> = x"
haftmann@25304
  1145
  unfolding abs_if sgn_if by auto
haftmann@25304
  1146
haftmann@36301
  1147
lemma abs_one [simp]:
haftmann@36301
  1148
  "\<bar>1\<bar> = 1"
huffman@44921
  1149
  by (simp add: abs_if)
haftmann@36301
  1150
haftmann@25304
  1151
end
nipkow@24491
  1152
haftmann@35028
  1153
class ordered_ring_abs = ordered_ring + ordered_ab_group_add_abs +
haftmann@25304
  1154
  assumes abs_eq_mult:
haftmann@25304
  1155
    "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0) \<Longrightarrow> \<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>"
haftmann@25304
  1156
haftmann@35028
  1157
context linordered_idom
haftmann@30961
  1158
begin
haftmann@30961
  1159
haftmann@35028
  1160
subclass ordered_ring_abs proof
huffman@35216
  1161
qed (auto simp add: abs_if not_less mult_less_0_iff)
haftmann@30961
  1162
haftmann@30961
  1163
lemma abs_mult:
haftmann@36301
  1164
  "\<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>" 
haftmann@30961
  1165
  by (rule abs_eq_mult) auto
haftmann@30961
  1166
haftmann@30961
  1167
lemma abs_mult_self:
haftmann@36301
  1168
  "\<bar>a\<bar> * \<bar>a\<bar> = a * a"
haftmann@30961
  1169
  by (simp add: abs_if) 
haftmann@30961
  1170
paulson@14294
  1171
lemma abs_mult_less:
haftmann@36301
  1172
  "\<bar>a\<bar> < c \<Longrightarrow> \<bar>b\<bar> < d \<Longrightarrow> \<bar>a\<bar> * \<bar>b\<bar> < c * d"
paulson@14294
  1173
proof -
haftmann@36301
  1174
  assume ac: "\<bar>a\<bar> < c"
haftmann@36301
  1175
  hence cpos: "0<c" by (blast intro: le_less_trans abs_ge_zero)
haftmann@36301
  1176
  assume "\<bar>b\<bar> < d"
paulson@14294
  1177
  thus ?thesis by (simp add: ac cpos mult_strict_mono) 
paulson@14294
  1178
qed
paulson@14293
  1179
haftmann@36301
  1180
lemma abs_less_iff:
haftmann@36301
  1181
  "\<bar>a\<bar> < b \<longleftrightarrow> a < b \<and> - a < b" 
haftmann@36301
  1182
  by (simp add: less_le abs_le_iff) (auto simp add: abs_if)
obua@14738
  1183
haftmann@36301
  1184
lemma abs_mult_pos:
haftmann@36301
  1185
  "0 \<le> x \<Longrightarrow> \<bar>y\<bar> * x = \<bar>y * x\<bar>"
haftmann@36301
  1186
  by (simp add: abs_mult)
haftmann@36301
  1187
hoelzl@51520
  1188
lemma abs_diff_less_iff:
hoelzl@51520
  1189
  "\<bar>x - a\<bar> < r \<longleftrightarrow> a - r < x \<and> x < a + r"
hoelzl@51520
  1190
  by (auto simp add: diff_less_eq ac_simps abs_less_iff)
hoelzl@51520
  1191
haftmann@36301
  1192
end
avigad@16775
  1193
haftmann@52435
  1194
code_identifier
haftmann@52435
  1195
  code_module Rings \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith
haftmann@33364
  1196
paulson@14265
  1197
end
haftmann@52435
  1198