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