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