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