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