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