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