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