src/HOL/Ring_and_Field.thy
author haftmann
Mon Apr 27 10:11:44 2009 +0200 (2009-04-27)
changeset 31001 7e6ffd8f51a9
parent 30961 541bfff659af
child 32960 69916a850301
permissions -rw-r--r--
cleaned up theory power further
paulson@14265
     1
(*  Title:   HOL/Ring_and_Field.thy
nipkow@23477
     2
    Author:  Gertrud Bauer, Steven Obua, Tobias Nipkow, Lawrence C Paulson, and Markus Wenzel,
avigad@16775
     3
             with contributions by Jeremy Avigad
paulson@14265
     4
*)
paulson@14265
     5
obua@14738
     6
header {* (Ordered) Rings and Fields *}
paulson@14265
     7
paulson@15229
     8
theory Ring_and_Field
nipkow@15140
     9
imports OrderedGroup
nipkow@15131
    10
begin
paulson@14504
    11
obua@14738
    12
text {*
obua@14738
    13
  The theory of partially ordered rings is taken from the books:
obua@14738
    14
  \begin{itemize}
obua@14738
    15
  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
obua@14738
    16
  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
obua@14738
    17
  \end{itemize}
obua@14738
    18
  Most of the used notions can also be looked up in 
obua@14738
    19
  \begin{itemize}
wenzelm@14770
    20
  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
obua@14738
    21
  \item \emph{Algebra I} by van der Waerden, Springer.
obua@14738
    22
  \end{itemize}
obua@14738
    23
*}
paulson@14504
    24
haftmann@22390
    25
class semiring = ab_semigroup_add + semigroup_mult +
nipkow@29667
    26
  assumes left_distrib[algebra_simps]: "(a + b) * c = a * c + b * c"
nipkow@29667
    27
  assumes right_distrib[algebra_simps]: "a * (b + c) = a * b + a * c"
haftmann@25152
    28
begin
haftmann@25152
    29
haftmann@25152
    30
text{*For the @{text combine_numerals} simproc*}
haftmann@25152
    31
lemma combine_common_factor:
haftmann@25152
    32
  "a * e + (b * e + c) = (a + b) * e + c"
nipkow@29667
    33
by (simp add: left_distrib add_ac)
haftmann@25152
    34
haftmann@25152
    35
end
paulson@14504
    36
haftmann@22390
    37
class mult_zero = times + zero +
haftmann@25062
    38
  assumes mult_zero_left [simp]: "0 * a = 0"
haftmann@25062
    39
  assumes mult_zero_right [simp]: "a * 0 = 0"
krauss@21199
    40
haftmann@22390
    41
class semiring_0 = semiring + comm_monoid_add + mult_zero
krauss@21199
    42
huffman@29904
    43
class semiring_0_cancel = semiring + cancel_comm_monoid_add
haftmann@25186
    44
begin
paulson@14504
    45
haftmann@25186
    46
subclass semiring_0
haftmann@28823
    47
proof
krauss@21199
    48
  fix a :: 'a
nipkow@29667
    49
  have "0 * a + 0 * a = 0 * a + 0" by (simp add: left_distrib [symmetric])
nipkow@29667
    50
  thus "0 * a = 0" by (simp only: add_left_cancel)
haftmann@25152
    51
next
haftmann@25152
    52
  fix a :: 'a
nipkow@29667
    53
  have "a * 0 + a * 0 = a * 0 + 0" by (simp add: right_distrib [symmetric])
nipkow@29667
    54
  thus "a * 0 = 0" by (simp only: add_left_cancel)
krauss@21199
    55
qed
obua@14940
    56
haftmann@25186
    57
end
haftmann@25152
    58
haftmann@22390
    59
class comm_semiring = ab_semigroup_add + ab_semigroup_mult +
haftmann@25062
    60
  assumes distrib: "(a + b) * c = a * c + b * c"
haftmann@25152
    61
begin
paulson@14504
    62
haftmann@25152
    63
subclass semiring
haftmann@28823
    64
proof
obua@14738
    65
  fix a b c :: 'a
obua@14738
    66
  show "(a + b) * c = a * c + b * c" by (simp add: distrib)
obua@14738
    67
  have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
obua@14738
    68
  also have "... = b * a + c * a" by (simp only: distrib)
obua@14738
    69
  also have "... = a * b + a * c" by (simp add: mult_ac)
obua@14738
    70
  finally show "a * (b + c) = a * b + a * c" by blast
paulson@14504
    71
qed
paulson@14504
    72
haftmann@25152
    73
end
paulson@14504
    74
haftmann@25152
    75
class comm_semiring_0 = comm_semiring + comm_monoid_add + mult_zero
haftmann@25152
    76
begin
haftmann@25152
    77
huffman@27516
    78
subclass semiring_0 ..
haftmann@25152
    79
haftmann@25152
    80
end
paulson@14504
    81
huffman@29904
    82
class comm_semiring_0_cancel = comm_semiring + cancel_comm_monoid_add
haftmann@25186
    83
begin
obua@14940
    84
huffman@27516
    85
subclass semiring_0_cancel ..
obua@14940
    86
huffman@28141
    87
subclass comm_semiring_0 ..
huffman@28141
    88
haftmann@25186
    89
end
krauss@21199
    90
haftmann@22390
    91
class zero_neq_one = zero + one +
haftmann@25062
    92
  assumes zero_neq_one [simp]: "0 \<noteq> 1"
haftmann@26193
    93
begin
haftmann@26193
    94
haftmann@26193
    95
lemma one_neq_zero [simp]: "1 \<noteq> 0"
nipkow@29667
    96
by (rule not_sym) (rule zero_neq_one)
haftmann@26193
    97
haftmann@26193
    98
end
paulson@14265
    99
haftmann@22390
   100
class semiring_1 = zero_neq_one + semiring_0 + monoid_mult
paulson@14504
   101
haftmann@27651
   102
text {* Abstract divisibility *}
haftmann@27651
   103
haftmann@27651
   104
class dvd = times
haftmann@27651
   105
begin
haftmann@27651
   106
haftmann@28559
   107
definition dvd :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "dvd" 50) where
haftmann@28559
   108
  [code del]: "b dvd a \<longleftrightarrow> (\<exists>k. a = b * k)"
haftmann@27651
   109
haftmann@27651
   110
lemma dvdI [intro?]: "a = b * k \<Longrightarrow> b dvd a"
haftmann@27651
   111
  unfolding dvd_def ..
haftmann@27651
   112
haftmann@27651
   113
lemma dvdE [elim?]: "b dvd a \<Longrightarrow> (\<And>k. a = b * k \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@27651
   114
  unfolding dvd_def by blast 
haftmann@27651
   115
haftmann@27651
   116
end
haftmann@27651
   117
haftmann@27651
   118
class comm_semiring_1 = zero_neq_one + comm_semiring_0 + comm_monoid_mult + dvd
haftmann@22390
   119
  (*previously almost_semiring*)
haftmann@25152
   120
begin
obua@14738
   121
huffman@27516
   122
subclass semiring_1 ..
haftmann@25152
   123
nipkow@29925
   124
lemma dvd_refl[simp]: "a dvd a"
haftmann@28559
   125
proof
haftmann@28559
   126
  show "a = a * 1" by simp
haftmann@27651
   127
qed
haftmann@27651
   128
haftmann@27651
   129
lemma dvd_trans:
haftmann@27651
   130
  assumes "a dvd b" and "b dvd c"
haftmann@27651
   131
  shows "a dvd c"
haftmann@27651
   132
proof -
haftmann@28559
   133
  from assms obtain v where "b = a * v" by (auto elim!: dvdE)
haftmann@28559
   134
  moreover from assms obtain w where "c = b * w" by (auto elim!: dvdE)
haftmann@27651
   135
  ultimately have "c = a * (v * w)" by (simp add: mult_assoc)
haftmann@28559
   136
  then show ?thesis ..
haftmann@27651
   137
qed
haftmann@27651
   138
haftmann@27651
   139
lemma dvd_0_left_iff [noatp, simp]: "0 dvd a \<longleftrightarrow> a = 0"
nipkow@29667
   140
by (auto intro: dvd_refl elim!: dvdE)
haftmann@28559
   141
haftmann@28559
   142
lemma dvd_0_right [iff]: "a dvd 0"
haftmann@28559
   143
proof
haftmann@27651
   144
  show "0 = a * 0" by simp
haftmann@27651
   145
qed
haftmann@27651
   146
haftmann@27651
   147
lemma one_dvd [simp]: "1 dvd a"
nipkow@29667
   148
by (auto intro!: dvdI)
haftmann@27651
   149
nipkow@30042
   150
lemma dvd_mult[simp]: "a dvd c \<Longrightarrow> a dvd (b * c)"
nipkow@29667
   151
by (auto intro!: mult_left_commute dvdI elim!: dvdE)
haftmann@27651
   152
nipkow@30042
   153
lemma dvd_mult2[simp]: "a dvd b \<Longrightarrow> a dvd (b * c)"
haftmann@27651
   154
  apply (subst mult_commute)
haftmann@27651
   155
  apply (erule dvd_mult)
haftmann@27651
   156
  done
haftmann@27651
   157
haftmann@27651
   158
lemma dvd_triv_right [simp]: "a dvd b * a"
nipkow@29667
   159
by (rule dvd_mult) (rule dvd_refl)
haftmann@27651
   160
haftmann@27651
   161
lemma dvd_triv_left [simp]: "a dvd a * b"
nipkow@29667
   162
by (rule dvd_mult2) (rule dvd_refl)
haftmann@27651
   163
haftmann@27651
   164
lemma mult_dvd_mono:
nipkow@30042
   165
  assumes "a dvd b"
nipkow@30042
   166
    and "c dvd d"
haftmann@27651
   167
  shows "a * c dvd b * d"
haftmann@27651
   168
proof -
nipkow@30042
   169
  from `a dvd b` obtain b' where "b = a * b'" ..
nipkow@30042
   170
  moreover from `c dvd d` obtain d' where "d = c * d'" ..
haftmann@27651
   171
  ultimately have "b * d = (a * c) * (b' * d')" by (simp add: mult_ac)
haftmann@27651
   172
  then show ?thesis ..
haftmann@27651
   173
qed
haftmann@27651
   174
haftmann@27651
   175
lemma dvd_mult_left: "a * b dvd c \<Longrightarrow> a dvd c"
nipkow@29667
   176
by (simp add: dvd_def mult_assoc, blast)
haftmann@27651
   177
haftmann@27651
   178
lemma dvd_mult_right: "a * b dvd c \<Longrightarrow> b dvd c"
haftmann@27651
   179
  unfolding mult_ac [of a] by (rule dvd_mult_left)
haftmann@27651
   180
haftmann@27651
   181
lemma dvd_0_left: "0 dvd a \<Longrightarrow> a = 0"
nipkow@29667
   182
by simp
haftmann@27651
   183
nipkow@29925
   184
lemma dvd_add[simp]:
nipkow@29925
   185
  assumes "a dvd b" and "a dvd c" shows "a dvd (b + c)"
haftmann@27651
   186
proof -
nipkow@29925
   187
  from `a dvd b` obtain b' where "b = a * b'" ..
nipkow@29925
   188
  moreover from `a dvd c` obtain c' where "c = a * c'" ..
haftmann@27651
   189
  ultimately have "b + c = a * (b' + c')" by (simp add: right_distrib)
haftmann@27651
   190
  then show ?thesis ..
haftmann@27651
   191
qed
haftmann@27651
   192
haftmann@25152
   193
end
paulson@14421
   194
nipkow@29925
   195
haftmann@22390
   196
class no_zero_divisors = zero + times +
haftmann@25062
   197
  assumes no_zero_divisors: "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a * b \<noteq> 0"
paulson@14504
   198
huffman@29904
   199
class semiring_1_cancel = semiring + cancel_comm_monoid_add
huffman@29904
   200
  + zero_neq_one + monoid_mult
haftmann@25267
   201
begin
obua@14940
   202
huffman@27516
   203
subclass semiring_0_cancel ..
haftmann@25512
   204
huffman@27516
   205
subclass semiring_1 ..
haftmann@25267
   206
haftmann@25267
   207
end
krauss@21199
   208
huffman@29904
   209
class comm_semiring_1_cancel = comm_semiring + cancel_comm_monoid_add
huffman@29904
   210
  + zero_neq_one + comm_monoid_mult
haftmann@25267
   211
begin
obua@14738
   212
huffman@27516
   213
subclass semiring_1_cancel ..
huffman@27516
   214
subclass comm_semiring_0_cancel ..
huffman@27516
   215
subclass comm_semiring_1 ..
haftmann@25267
   216
haftmann@25267
   217
end
haftmann@25152
   218
haftmann@22390
   219
class ring = semiring + ab_group_add
haftmann@25267
   220
begin
haftmann@25152
   221
huffman@27516
   222
subclass semiring_0_cancel ..
haftmann@25152
   223
haftmann@25152
   224
text {* Distribution rules *}
haftmann@25152
   225
haftmann@25152
   226
lemma minus_mult_left: "- (a * b) = - a * b"
nipkow@29667
   227
by (rule equals_zero_I) (simp add: left_distrib [symmetric]) 
haftmann@25152
   228
haftmann@25152
   229
lemma minus_mult_right: "- (a * b) = a * - b"
nipkow@29667
   230
by (rule equals_zero_I) (simp add: right_distrib [symmetric]) 
haftmann@25152
   231
huffman@29407
   232
text{*Extract signs from products*}
nipkow@29833
   233
lemmas mult_minus_left [simp, noatp] = minus_mult_left [symmetric]
nipkow@29833
   234
lemmas mult_minus_right [simp,noatp] = minus_mult_right [symmetric]
huffman@29407
   235
haftmann@25152
   236
lemma minus_mult_minus [simp]: "- a * - b = a * b"
nipkow@29667
   237
by simp
haftmann@25152
   238
haftmann@25152
   239
lemma minus_mult_commute: "- a * b = a * - b"
nipkow@29667
   240
by simp
nipkow@29667
   241
nipkow@29667
   242
lemma right_diff_distrib[algebra_simps]: "a * (b - c) = a * b - a * c"
nipkow@29667
   243
by (simp add: right_distrib diff_minus)
nipkow@29667
   244
nipkow@29667
   245
lemma left_diff_distrib[algebra_simps]: "(a - b) * c = a * c - b * c"
nipkow@29667
   246
by (simp add: left_distrib diff_minus)
haftmann@25152
   247
nipkow@29833
   248
lemmas ring_distribs[noatp] =
haftmann@25152
   249
  right_distrib left_distrib left_diff_distrib right_diff_distrib
haftmann@25152
   250
nipkow@29667
   251
text{*Legacy - use @{text algebra_simps} *}
nipkow@29833
   252
lemmas ring_simps[noatp] = algebra_simps
haftmann@25230
   253
haftmann@25230
   254
lemma eq_add_iff1:
haftmann@25230
   255
  "a * e + c = b * e + d \<longleftrightarrow> (a - b) * e + c = d"
nipkow@29667
   256
by (simp add: algebra_simps)
haftmann@25230
   257
haftmann@25230
   258
lemma eq_add_iff2:
haftmann@25230
   259
  "a * e + c = b * e + d \<longleftrightarrow> c = (b - a) * e + d"
nipkow@29667
   260
by (simp add: algebra_simps)
haftmann@25230
   261
haftmann@25152
   262
end
haftmann@25152
   263
nipkow@29833
   264
lemmas ring_distribs[noatp] =
haftmann@25152
   265
  right_distrib left_distrib left_diff_distrib right_diff_distrib
haftmann@25152
   266
haftmann@22390
   267
class comm_ring = comm_semiring + ab_group_add
haftmann@25267
   268
begin
obua@14738
   269
huffman@27516
   270
subclass ring ..
huffman@28141
   271
subclass comm_semiring_0_cancel ..
haftmann@25267
   272
haftmann@25267
   273
end
obua@14738
   274
haftmann@22390
   275
class ring_1 = ring + zero_neq_one + monoid_mult
haftmann@25267
   276
begin
paulson@14265
   277
huffman@27516
   278
subclass semiring_1_cancel ..
haftmann@25267
   279
haftmann@25267
   280
end
haftmann@25152
   281
haftmann@22390
   282
class comm_ring_1 = comm_ring + zero_neq_one + comm_monoid_mult
haftmann@22390
   283
  (*previously ring*)
haftmann@25267
   284
begin
obua@14738
   285
huffman@27516
   286
subclass ring_1 ..
huffman@27516
   287
subclass comm_semiring_1_cancel ..
haftmann@25267
   288
huffman@29465
   289
lemma dvd_minus_iff [simp]: "x dvd - y \<longleftrightarrow> x dvd y"
huffman@29408
   290
proof
huffman@29408
   291
  assume "x dvd - y"
huffman@29408
   292
  then have "x dvd - 1 * - y" by (rule dvd_mult)
huffman@29408
   293
  then show "x dvd y" by simp
huffman@29408
   294
next
huffman@29408
   295
  assume "x dvd y"
huffman@29408
   296
  then have "x dvd - 1 * y" by (rule dvd_mult)
huffman@29408
   297
  then show "x dvd - y" by simp
huffman@29408
   298
qed
huffman@29408
   299
huffman@29465
   300
lemma minus_dvd_iff [simp]: "- x dvd y \<longleftrightarrow> x dvd y"
huffman@29408
   301
proof
huffman@29408
   302
  assume "- x dvd y"
huffman@29408
   303
  then obtain k where "y = - x * k" ..
huffman@29408
   304
  then have "y = x * - k" by simp
huffman@29408
   305
  then show "x dvd y" ..
huffman@29408
   306
next
huffman@29408
   307
  assume "x dvd y"
huffman@29408
   308
  then obtain k where "y = x * k" ..
huffman@29408
   309
  then have "y = - x * - k" by simp
huffman@29408
   310
  then show "- x dvd y" ..
huffman@29408
   311
qed
huffman@29408
   312
nipkow@30042
   313
lemma dvd_diff[simp]: "x dvd y \<Longrightarrow> x dvd z \<Longrightarrow> x dvd (y - z)"
nipkow@30042
   314
by (simp add: diff_minus dvd_minus_iff)
huffman@29409
   315
haftmann@25267
   316
end
haftmann@25152
   317
huffman@22990
   318
class ring_no_zero_divisors = ring + no_zero_divisors
haftmann@25230
   319
begin
haftmann@25230
   320
haftmann@25230
   321
lemma mult_eq_0_iff [simp]:
haftmann@25230
   322
  shows "a * b = 0 \<longleftrightarrow> (a = 0 \<or> b = 0)"
haftmann@25230
   323
proof (cases "a = 0 \<or> b = 0")
haftmann@25230
   324
  case False then have "a \<noteq> 0" and "b \<noteq> 0" by auto
haftmann@25230
   325
    then show ?thesis using no_zero_divisors by simp
haftmann@25230
   326
next
haftmann@25230
   327
  case True then show ?thesis by auto
haftmann@25230
   328
qed
haftmann@25230
   329
haftmann@26193
   330
text{*Cancellation of equalities with a common factor*}
haftmann@26193
   331
lemma mult_cancel_right [simp, noatp]:
haftmann@26193
   332
  "a * c = b * c \<longleftrightarrow> c = 0 \<or> a = b"
haftmann@26193
   333
proof -
haftmann@26193
   334
  have "(a * c = b * c) = ((a - b) * c = 0)"
nipkow@29667
   335
    by (simp add: algebra_simps right_minus_eq)
nipkow@29667
   336
  thus ?thesis by (simp add: disj_commute right_minus_eq)
haftmann@26193
   337
qed
haftmann@26193
   338
haftmann@26193
   339
lemma mult_cancel_left [simp, noatp]:
haftmann@26193
   340
  "c * a = c * b \<longleftrightarrow> c = 0 \<or> a = b"
haftmann@26193
   341
proof -
haftmann@26193
   342
  have "(c * a = c * b) = (c * (a - b) = 0)"
nipkow@29667
   343
    by (simp add: algebra_simps right_minus_eq)
nipkow@29667
   344
  thus ?thesis by (simp add: right_minus_eq)
haftmann@26193
   345
qed
haftmann@26193
   346
haftmann@25230
   347
end
huffman@22990
   348
huffman@23544
   349
class ring_1_no_zero_divisors = ring_1 + ring_no_zero_divisors
haftmann@26274
   350
begin
haftmann@26274
   351
haftmann@26274
   352
lemma mult_cancel_right1 [simp]:
haftmann@26274
   353
  "c = b * c \<longleftrightarrow> c = 0 \<or> b = 1"
nipkow@29667
   354
by (insert mult_cancel_right [of 1 c b], force)
haftmann@26274
   355
haftmann@26274
   356
lemma mult_cancel_right2 [simp]:
haftmann@26274
   357
  "a * c = c \<longleftrightarrow> c = 0 \<or> a = 1"
nipkow@29667
   358
by (insert mult_cancel_right [of a c 1], simp)
haftmann@26274
   359
 
haftmann@26274
   360
lemma mult_cancel_left1 [simp]:
haftmann@26274
   361
  "c = c * b \<longleftrightarrow> c = 0 \<or> b = 1"
nipkow@29667
   362
by (insert mult_cancel_left [of c 1 b], force)
haftmann@26274
   363
haftmann@26274
   364
lemma mult_cancel_left2 [simp]:
haftmann@26274
   365
  "c * a = c \<longleftrightarrow> c = 0 \<or> a = 1"
nipkow@29667
   366
by (insert mult_cancel_left [of c a 1], simp)
haftmann@26274
   367
haftmann@26274
   368
end
huffman@22990
   369
haftmann@22390
   370
class idom = comm_ring_1 + no_zero_divisors
haftmann@25186
   371
begin
paulson@14421
   372
huffman@27516
   373
subclass ring_1_no_zero_divisors ..
huffman@22990
   374
huffman@29915
   375
lemma square_eq_iff: "a * a = b * b \<longleftrightarrow> (a = b \<or> a = - b)"
huffman@29915
   376
proof
huffman@29915
   377
  assume "a * a = b * b"
huffman@29915
   378
  then have "(a - b) * (a + b) = 0"
huffman@29915
   379
    by (simp add: algebra_simps)
huffman@29915
   380
  then show "a = b \<or> a = - b"
huffman@29915
   381
    by (simp add: right_minus_eq eq_neg_iff_add_eq_0)
huffman@29915
   382
next
huffman@29915
   383
  assume "a = b \<or> a = - b"
huffman@29915
   384
  then show "a * a = b * b" by auto
huffman@29915
   385
qed
huffman@29915
   386
huffman@29981
   387
lemma dvd_mult_cancel_right [simp]:
huffman@29981
   388
  "a * c dvd b * c \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   389
proof -
huffman@29981
   390
  have "a * c dvd b * c \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
huffman@29981
   391
    unfolding dvd_def by (simp add: mult_ac)
huffman@29981
   392
  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   393
    unfolding dvd_def by simp
huffman@29981
   394
  finally show ?thesis .
huffman@29981
   395
qed
huffman@29981
   396
huffman@29981
   397
lemma dvd_mult_cancel_left [simp]:
huffman@29981
   398
  "c * a dvd c * b \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   399
proof -
huffman@29981
   400
  have "c * a dvd c * b \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
huffman@29981
   401
    unfolding dvd_def by (simp add: mult_ac)
huffman@29981
   402
  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
huffman@29981
   403
    unfolding dvd_def by simp
huffman@29981
   404
  finally show ?thesis .
huffman@29981
   405
qed
huffman@29981
   406
haftmann@25186
   407
end
haftmann@25152
   408
haftmann@22390
   409
class division_ring = ring_1 + inverse +
haftmann@25062
   410
  assumes left_inverse [simp]:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
haftmann@25062
   411
  assumes right_inverse [simp]: "a \<noteq> 0 \<Longrightarrow> a * inverse a = 1"
haftmann@25186
   412
begin
huffman@20496
   413
haftmann@25186
   414
subclass ring_1_no_zero_divisors
haftmann@28823
   415
proof
huffman@22987
   416
  fix a b :: 'a
huffman@22987
   417
  assume a: "a \<noteq> 0" and b: "b \<noteq> 0"
huffman@22987
   418
  show "a * b \<noteq> 0"
huffman@22987
   419
  proof
huffman@22987
   420
    assume ab: "a * b = 0"
nipkow@29667
   421
    hence "0 = inverse a * (a * b) * inverse b" by simp
huffman@22987
   422
    also have "\<dots> = (inverse a * a) * (b * inverse b)"
huffman@22987
   423
      by (simp only: mult_assoc)
nipkow@29667
   424
    also have "\<dots> = 1" using a b by simp
nipkow@29667
   425
    finally show False by simp
huffman@22987
   426
  qed
huffman@22987
   427
qed
huffman@20496
   428
haftmann@26274
   429
lemma nonzero_imp_inverse_nonzero:
haftmann@26274
   430
  "a \<noteq> 0 \<Longrightarrow> inverse a \<noteq> 0"
haftmann@26274
   431
proof
haftmann@26274
   432
  assume ianz: "inverse a = 0"
haftmann@26274
   433
  assume "a \<noteq> 0"
haftmann@26274
   434
  hence "1 = a * inverse a" by simp
haftmann@26274
   435
  also have "... = 0" by (simp add: ianz)
haftmann@26274
   436
  finally have "1 = 0" .
haftmann@26274
   437
  thus False by (simp add: eq_commute)
haftmann@26274
   438
qed
haftmann@26274
   439
haftmann@26274
   440
lemma inverse_zero_imp_zero:
haftmann@26274
   441
  "inverse a = 0 \<Longrightarrow> a = 0"
haftmann@26274
   442
apply (rule classical)
haftmann@26274
   443
apply (drule nonzero_imp_inverse_nonzero)
haftmann@26274
   444
apply auto
haftmann@26274
   445
done
haftmann@26274
   446
haftmann@26274
   447
lemma inverse_unique: 
haftmann@26274
   448
  assumes ab: "a * b = 1"
haftmann@26274
   449
  shows "inverse a = b"
haftmann@26274
   450
proof -
haftmann@26274
   451
  have "a \<noteq> 0" using ab by (cases "a = 0") simp_all
huffman@29406
   452
  moreover have "inverse a * (a * b) = inverse a" by (simp add: ab)
huffman@29406
   453
  ultimately show ?thesis by (simp add: mult_assoc [symmetric])
haftmann@26274
   454
qed
haftmann@26274
   455
huffman@29406
   456
lemma nonzero_inverse_minus_eq:
huffman@29406
   457
  "a \<noteq> 0 \<Longrightarrow> inverse (- a) = - inverse a"
nipkow@29667
   458
by (rule inverse_unique) simp
huffman@29406
   459
huffman@29406
   460
lemma nonzero_inverse_inverse_eq:
huffman@29406
   461
  "a \<noteq> 0 \<Longrightarrow> inverse (inverse a) = a"
nipkow@29667
   462
by (rule inverse_unique) simp
huffman@29406
   463
huffman@29406
   464
lemma nonzero_inverse_eq_imp_eq:
huffman@29406
   465
  assumes "inverse a = inverse b" and "a \<noteq> 0" and "b \<noteq> 0"
huffman@29406
   466
  shows "a = b"
huffman@29406
   467
proof -
huffman@29406
   468
  from `inverse a = inverse b`
nipkow@29667
   469
  have "inverse (inverse a) = inverse (inverse b)" by (rule arg_cong)
huffman@29406
   470
  with `a \<noteq> 0` and `b \<noteq> 0` show "a = b"
huffman@29406
   471
    by (simp add: nonzero_inverse_inverse_eq)
huffman@29406
   472
qed
huffman@29406
   473
huffman@29406
   474
lemma inverse_1 [simp]: "inverse 1 = 1"
nipkow@29667
   475
by (rule inverse_unique) simp
huffman@29406
   476
haftmann@26274
   477
lemma nonzero_inverse_mult_distrib: 
huffman@29406
   478
  assumes "a \<noteq> 0" and "b \<noteq> 0"
haftmann@26274
   479
  shows "inverse (a * b) = inverse b * inverse a"
haftmann@26274
   480
proof -
nipkow@29667
   481
  have "a * (b * inverse b) * inverse a = 1" using assms by simp
nipkow@29667
   482
  hence "a * b * (inverse b * inverse a) = 1" by (simp only: mult_assoc)
nipkow@29667
   483
  thus ?thesis by (rule inverse_unique)
haftmann@26274
   484
qed
haftmann@26274
   485
haftmann@26274
   486
lemma division_ring_inverse_add:
haftmann@26274
   487
  "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a + inverse b = inverse a * (a + b) * inverse b"
nipkow@29667
   488
by (simp add: algebra_simps)
haftmann@26274
   489
haftmann@26274
   490
lemma division_ring_inverse_diff:
haftmann@26274
   491
  "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a - inverse b = inverse a * (b - a) * inverse b"
nipkow@29667
   492
by (simp add: algebra_simps)
haftmann@26274
   493
haftmann@25186
   494
end
haftmann@25152
   495
huffman@22987
   496
class field = comm_ring_1 + inverse +
haftmann@25062
   497
  assumes field_inverse:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
haftmann@25062
   498
  assumes divide_inverse: "a / b = a * inverse b"
haftmann@25267
   499
begin
huffman@20496
   500
haftmann@25267
   501
subclass division_ring
haftmann@28823
   502
proof
huffman@22987
   503
  fix a :: 'a
huffman@22987
   504
  assume "a \<noteq> 0"
huffman@22987
   505
  thus "inverse a * a = 1" by (rule field_inverse)
huffman@22987
   506
  thus "a * inverse a = 1" by (simp only: mult_commute)
obua@14738
   507
qed
haftmann@25230
   508
huffman@27516
   509
subclass idom ..
haftmann@25230
   510
haftmann@25230
   511
lemma right_inverse_eq: "b \<noteq> 0 \<Longrightarrow> a / b = 1 \<longleftrightarrow> a = b"
haftmann@25230
   512
proof
haftmann@25230
   513
  assume neq: "b \<noteq> 0"
haftmann@25230
   514
  {
haftmann@25230
   515
    hence "a = (a / b) * b" by (simp add: divide_inverse mult_ac)
haftmann@25230
   516
    also assume "a / b = 1"
haftmann@25230
   517
    finally show "a = b" by simp
haftmann@25230
   518
  next
haftmann@25230
   519
    assume "a = b"
haftmann@25230
   520
    with neq show "a / b = 1" by (simp add: divide_inverse)
haftmann@25230
   521
  }
haftmann@25230
   522
qed
haftmann@25230
   523
haftmann@25230
   524
lemma nonzero_inverse_eq_divide: "a \<noteq> 0 \<Longrightarrow> inverse a = 1 / a"
nipkow@29667
   525
by (simp add: divide_inverse)
haftmann@25230
   526
haftmann@25230
   527
lemma divide_self [simp]: "a \<noteq> 0 \<Longrightarrow> a / a = 1"
nipkow@29667
   528
by (simp add: divide_inverse)
haftmann@25230
   529
haftmann@25230
   530
lemma divide_zero_left [simp]: "0 / a = 0"
nipkow@29667
   531
by (simp add: divide_inverse)
haftmann@25230
   532
haftmann@25230
   533
lemma inverse_eq_divide: "inverse a = 1 / a"
nipkow@29667
   534
by (simp add: divide_inverse)
haftmann@25230
   535
haftmann@25230
   536
lemma add_divide_distrib: "(a+b) / c = a/c + b/c"
huffman@30630
   537
by (simp add: divide_inverse algebra_simps)
huffman@30630
   538
huffman@30630
   539
text{*There is no slick version using division by zero.*}
huffman@30630
   540
lemma inverse_add:
huffman@30630
   541
  "[| a \<noteq> 0;  b \<noteq> 0 |]
huffman@30630
   542
   ==> inverse a + inverse b = (a + b) * inverse a * inverse b"
huffman@30630
   543
by (simp add: division_ring_inverse_add mult_ac)
huffman@30630
   544
huffman@30630
   545
lemma nonzero_mult_divide_mult_cancel_left [simp, noatp]:
huffman@30630
   546
assumes [simp]: "b\<noteq>0" and [simp]: "c\<noteq>0" shows "(c*a)/(c*b) = a/b"
huffman@30630
   547
proof -
huffman@30630
   548
  have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
huffman@30630
   549
    by (simp add: divide_inverse nonzero_inverse_mult_distrib)
huffman@30630
   550
  also have "... =  a * inverse b * (inverse c * c)"
huffman@30630
   551
    by (simp only: mult_ac)
huffman@30630
   552
  also have "... =  a * inverse b" by simp
huffman@30630
   553
    finally show ?thesis by (simp add: divide_inverse)
huffman@30630
   554
qed
huffman@30630
   555
huffman@30630
   556
lemma nonzero_mult_divide_mult_cancel_right [simp, noatp]:
huffman@30630
   557
  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (a * c) / (b * c) = a / b"
huffman@30630
   558
by (simp add: mult_commute [of _ c])
huffman@30630
   559
huffman@30630
   560
lemma divide_1 [simp]: "a / 1 = a"
huffman@30630
   561
by (simp add: divide_inverse)
huffman@30630
   562
huffman@30630
   563
lemma times_divide_eq_right: "a * (b / c) = (a * b) / c"
huffman@30630
   564
by (simp add: divide_inverse mult_assoc)
huffman@30630
   565
huffman@30630
   566
lemma times_divide_eq_left: "(b / c) * a = (b * a) / c"
huffman@30630
   567
by (simp add: divide_inverse mult_ac)
huffman@30630
   568
huffman@30630
   569
text {* These are later declared as simp rules. *}
huffman@30630
   570
lemmas times_divide_eq [noatp] = times_divide_eq_right times_divide_eq_left
huffman@30630
   571
huffman@30630
   572
lemma add_frac_eq:
huffman@30630
   573
  assumes "y \<noteq> 0" and "z \<noteq> 0"
huffman@30630
   574
  shows "x / y + w / z = (x * z + w * y) / (y * z)"
huffman@30630
   575
proof -
huffman@30630
   576
  have "x / y + w / z = (x * z) / (y * z) + (y * w) / (y * z)"
huffman@30630
   577
    using assms by simp
huffman@30630
   578
  also have "\<dots> = (x * z + y * w) / (y * z)"
huffman@30630
   579
    by (simp only: add_divide_distrib)
huffman@30630
   580
  finally show ?thesis
huffman@30630
   581
    by (simp only: mult_commute)
huffman@30630
   582
qed
huffman@30630
   583
huffman@30630
   584
text{*Special Cancellation Simprules for Division*}
huffman@30630
   585
huffman@30630
   586
lemma nonzero_mult_divide_cancel_right [simp, noatp]:
huffman@30630
   587
  "b \<noteq> 0 \<Longrightarrow> a * b / b = a"
huffman@30630
   588
using nonzero_mult_divide_mult_cancel_right [of 1 b a] by simp
huffman@30630
   589
huffman@30630
   590
lemma nonzero_mult_divide_cancel_left [simp, noatp]:
huffman@30630
   591
  "a \<noteq> 0 \<Longrightarrow> a * b / a = b"
huffman@30630
   592
using nonzero_mult_divide_mult_cancel_left [of 1 a b] by simp
huffman@30630
   593
huffman@30630
   594
lemma nonzero_divide_mult_cancel_right [simp, noatp]:
huffman@30630
   595
  "\<lbrakk>a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> b / (a * b) = 1 / a"
huffman@30630
   596
using nonzero_mult_divide_mult_cancel_right [of a b 1] by simp
huffman@30630
   597
huffman@30630
   598
lemma nonzero_divide_mult_cancel_left [simp, noatp]:
huffman@30630
   599
  "\<lbrakk>a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / (a * b) = 1 / b"
huffman@30630
   600
using nonzero_mult_divide_mult_cancel_left [of b a 1] by simp
huffman@30630
   601
huffman@30630
   602
lemma nonzero_mult_divide_mult_cancel_left2 [simp, noatp]:
huffman@30630
   603
  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (c * a) / (b * c) = a / b"
huffman@30630
   604
using nonzero_mult_divide_mult_cancel_left [of b c a] by (simp add: mult_ac)
huffman@30630
   605
huffman@30630
   606
lemma nonzero_mult_divide_mult_cancel_right2 [simp, noatp]:
huffman@30630
   607
  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (a * c) / (c * b) = a / b"
huffman@30630
   608
using nonzero_mult_divide_mult_cancel_right [of b c a] by (simp add: mult_ac)
huffman@30630
   609
huffman@30630
   610
lemma minus_divide_left: "- (a / b) = (-a) / b"
huffman@30630
   611
by (simp add: divide_inverse)
huffman@30630
   612
huffman@30630
   613
lemma nonzero_minus_divide_right: "b \<noteq> 0 ==> - (a / b) = a / (- b)"
huffman@30630
   614
by (simp add: divide_inverse nonzero_inverse_minus_eq)
huffman@30630
   615
huffman@30630
   616
lemma nonzero_minus_divide_divide: "b \<noteq> 0 ==> (-a) / (-b) = a / b"
huffman@30630
   617
by (simp add: divide_inverse nonzero_inverse_minus_eq)
huffman@30630
   618
huffman@30630
   619
lemma divide_minus_left [simp, noatp]: "(-a) / b = - (a / b)"
huffman@30630
   620
by (simp add: divide_inverse)
huffman@30630
   621
huffman@30630
   622
lemma diff_divide_distrib: "(a - b) / c = a / c - b / c"
huffman@30630
   623
by (simp add: diff_minus add_divide_distrib)
huffman@30630
   624
huffman@30630
   625
lemma add_divide_eq_iff:
huffman@30630
   626
  "z \<noteq> 0 \<Longrightarrow> x + y / z = (z * x + y) / z"
huffman@30630
   627
by (simp add: add_divide_distrib)
huffman@30630
   628
huffman@30630
   629
lemma divide_add_eq_iff:
huffman@30630
   630
  "z \<noteq> 0 \<Longrightarrow> x / z + y = (x + z * y) / z"
huffman@30630
   631
by (simp add: add_divide_distrib)
huffman@30630
   632
huffman@30630
   633
lemma diff_divide_eq_iff:
huffman@30630
   634
  "z \<noteq> 0 \<Longrightarrow> x - y / z = (z * x - y) / z"
huffman@30630
   635
by (simp add: diff_divide_distrib)
huffman@30630
   636
huffman@30630
   637
lemma divide_diff_eq_iff:
huffman@30630
   638
  "z \<noteq> 0 \<Longrightarrow> x / z - y = (x - z * y) / z"
huffman@30630
   639
by (simp add: diff_divide_distrib)
huffman@30630
   640
huffman@30630
   641
lemma nonzero_eq_divide_eq: "c \<noteq> 0 \<Longrightarrow> a = b / c \<longleftrightarrow> a * c = b"
huffman@30630
   642
proof -
huffman@30630
   643
  assume [simp]: "c \<noteq> 0"
huffman@30630
   644
  have "a = b / c \<longleftrightarrow> a * c = (b / c) * c" by simp
huffman@30630
   645
  also have "... \<longleftrightarrow> a * c = b" by (simp add: divide_inverse mult_assoc)
huffman@30630
   646
  finally show ?thesis .
huffman@30630
   647
qed
huffman@30630
   648
huffman@30630
   649
lemma nonzero_divide_eq_eq: "c \<noteq> 0 \<Longrightarrow> b / c = a \<longleftrightarrow> b = a * c"
huffman@30630
   650
proof -
huffman@30630
   651
  assume [simp]: "c \<noteq> 0"
huffman@30630
   652
  have "b / c = a \<longleftrightarrow> (b / c) * c = a * c" by simp
huffman@30630
   653
  also have "... \<longleftrightarrow> b = a * c" by (simp add: divide_inverse mult_assoc) 
huffman@30630
   654
  finally show ?thesis .
huffman@30630
   655
qed
huffman@30630
   656
huffman@30630
   657
lemma divide_eq_imp: "c \<noteq> 0 \<Longrightarrow> b = a * c \<Longrightarrow> b / c = a"
huffman@30630
   658
by simp
huffman@30630
   659
huffman@30630
   660
lemma eq_divide_imp: "c \<noteq> 0 \<Longrightarrow> a * c = b \<Longrightarrow> a = b / c"
huffman@30630
   661
by (erule subst, simp)
huffman@30630
   662
huffman@30630
   663
lemmas field_eq_simps[noatp] = algebra_simps
huffman@30630
   664
  (* pull / out*)
huffman@30630
   665
  add_divide_eq_iff divide_add_eq_iff
huffman@30630
   666
  diff_divide_eq_iff divide_diff_eq_iff
huffman@30630
   667
  (* multiply eqn *)
huffman@30630
   668
  nonzero_eq_divide_eq nonzero_divide_eq_eq
huffman@30630
   669
(* is added later:
huffman@30630
   670
  times_divide_eq_left times_divide_eq_right
huffman@30630
   671
*)
huffman@30630
   672
huffman@30630
   673
text{*An example:*}
huffman@30630
   674
lemma "\<lbrakk>a\<noteq>b; c\<noteq>d; e\<noteq>f\<rbrakk> \<Longrightarrow> ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) = 1"
huffman@30630
   675
apply(subgoal_tac "(c-d)*(e-f)*(a-b) \<noteq> 0")
huffman@30630
   676
 apply(simp add:field_eq_simps)
huffman@30630
   677
apply(simp)
huffman@30630
   678
done
huffman@30630
   679
huffman@30630
   680
lemma diff_frac_eq:
huffman@30630
   681
  "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> x / y - w / z = (x * z - w * y) / (y * z)"
huffman@30630
   682
by (simp add: field_eq_simps times_divide_eq)
huffman@30630
   683
huffman@30630
   684
lemma frac_eq_eq:
huffman@30630
   685
  "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> (x / y = w / z) = (x * z = w * y)"
huffman@30630
   686
by (simp add: field_eq_simps times_divide_eq)
haftmann@25230
   687
haftmann@25230
   688
end
haftmann@25230
   689
haftmann@22390
   690
class division_by_zero = zero + inverse +
haftmann@25062
   691
  assumes inverse_zero [simp]: "inverse 0 = 0"
paulson@14265
   692
haftmann@25230
   693
lemma divide_zero [simp]:
haftmann@25230
   694
  "a / 0 = (0::'a::{field,division_by_zero})"
nipkow@29667
   695
by (simp add: divide_inverse)
haftmann@25230
   696
haftmann@25230
   697
lemma divide_self_if [simp]:
haftmann@25230
   698
  "a / (a::'a::{field,division_by_zero}) = (if a=0 then 0 else 1)"
nipkow@29667
   699
by simp
haftmann@25230
   700
haftmann@22390
   701
class mult_mono = times + zero + ord +
haftmann@25062
   702
  assumes mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
haftmann@25062
   703
  assumes mult_right_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c"
paulson@14267
   704
haftmann@22390
   705
class pordered_semiring = mult_mono + semiring_0 + pordered_ab_semigroup_add 
haftmann@25230
   706
begin
haftmann@25230
   707
haftmann@25230
   708
lemma mult_mono:
haftmann@25230
   709
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> c
haftmann@25230
   710
     \<Longrightarrow> a * c \<le> b * d"
haftmann@25230
   711
apply (erule mult_right_mono [THEN order_trans], assumption)
haftmann@25230
   712
apply (erule mult_left_mono, assumption)
haftmann@25230
   713
done
haftmann@25230
   714
haftmann@25230
   715
lemma mult_mono':
haftmann@25230
   716
  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> a \<Longrightarrow> 0 \<le> c
haftmann@25230
   717
     \<Longrightarrow> a * c \<le> b * d"
haftmann@25230
   718
apply (rule mult_mono)
haftmann@25230
   719
apply (fast intro: order_trans)+
haftmann@25230
   720
done
haftmann@25230
   721
haftmann@25230
   722
end
krauss@21199
   723
haftmann@22390
   724
class pordered_cancel_semiring = mult_mono + pordered_ab_semigroup_add
huffman@29904
   725
  + semiring + cancel_comm_monoid_add
haftmann@25267
   726
begin
paulson@14268
   727
huffman@27516
   728
subclass semiring_0_cancel ..
huffman@27516
   729
subclass pordered_semiring ..
obua@23521
   730
haftmann@25230
   731
lemma mult_nonneg_nonneg: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a * b"
huffman@30692
   732
using mult_left_mono [of zero b a] by simp
haftmann@25230
   733
haftmann@25230
   734
lemma mult_nonneg_nonpos: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> a * b \<le> 0"
huffman@30692
   735
using mult_left_mono [of b zero a] by simp
huffman@30692
   736
huffman@30692
   737
lemma mult_nonpos_nonneg: "a \<le> 0 \<Longrightarrow> 0 \<le> b \<Longrightarrow> a * b \<le> 0"
huffman@30692
   738
using mult_right_mono [of a zero b] by simp
huffman@30692
   739
huffman@30692
   740
text {* Legacy - use @{text mult_nonpos_nonneg} *}
haftmann@25230
   741
lemma mult_nonneg_nonpos2: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> b * a \<le> 0" 
nipkow@29667
   742
by (drule mult_right_mono [of b zero], auto)
haftmann@25230
   743
haftmann@26234
   744
lemma split_mult_neg_le: "(0 \<le> a & b \<le> 0) | (a \<le> 0 & 0 \<le> b) \<Longrightarrow> a * b \<le> 0" 
nipkow@29667
   745
by (auto simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)
haftmann@25230
   746
haftmann@25230
   747
end
haftmann@25230
   748
haftmann@25230
   749
class ordered_semiring = semiring + comm_monoid_add + ordered_cancel_ab_semigroup_add + mult_mono
haftmann@25267
   750
begin
haftmann@25230
   751
huffman@27516
   752
subclass pordered_cancel_semiring ..
haftmann@25512
   753
huffman@27516
   754
subclass pordered_comm_monoid_add ..
haftmann@25304
   755
haftmann@25230
   756
lemma mult_left_less_imp_less:
haftmann@25230
   757
  "c * a < c * b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
nipkow@29667
   758
by (force simp add: mult_left_mono not_le [symmetric])
haftmann@25230
   759
 
haftmann@25230
   760
lemma mult_right_less_imp_less:
haftmann@25230
   761
  "a * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
nipkow@29667
   762
by (force simp add: mult_right_mono not_le [symmetric])
obua@23521
   763
haftmann@25186
   764
end
haftmann@25152
   765
haftmann@22390
   766
class ordered_semiring_strict = semiring + comm_monoid_add + ordered_cancel_ab_semigroup_add +
haftmann@25062
   767
  assumes mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
haftmann@25062
   768
  assumes mult_strict_right_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> a * c < b * c"
haftmann@25267
   769
begin
paulson@14341
   770
huffman@27516
   771
subclass semiring_0_cancel ..
obua@14940
   772
haftmann@25267
   773
subclass ordered_semiring
haftmann@28823
   774
proof
huffman@23550
   775
  fix a b c :: 'a
huffman@23550
   776
  assume A: "a \<le> b" "0 \<le> c"
huffman@23550
   777
  from A show "c * a \<le> c * b"
haftmann@25186
   778
    unfolding le_less
haftmann@25186
   779
    using mult_strict_left_mono by (cases "c = 0") auto
huffman@23550
   780
  from A show "a * c \<le> b * c"
haftmann@25152
   781
    unfolding le_less
haftmann@25186
   782
    using mult_strict_right_mono by (cases "c = 0") auto
haftmann@25152
   783
qed
haftmann@25152
   784
haftmann@25230
   785
lemma mult_left_le_imp_le:
haftmann@25230
   786
  "c * a \<le> c * b \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
nipkow@29667
   787
by (force simp add: mult_strict_left_mono _not_less [symmetric])
haftmann@25230
   788
 
haftmann@25230
   789
lemma mult_right_le_imp_le:
haftmann@25230
   790
  "a * c \<le> b * c \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
nipkow@29667
   791
by (force simp add: mult_strict_right_mono not_less [symmetric])
haftmann@25230
   792
huffman@30692
   793
lemma mult_pos_pos: "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> 0 < a * b"
huffman@30692
   794
using mult_strict_left_mono [of zero b a] by simp
huffman@30692
   795
huffman@30692
   796
lemma mult_pos_neg: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> a * b < 0"
huffman@30692
   797
using mult_strict_left_mono [of b zero a] by simp
huffman@30692
   798
huffman@30692
   799
lemma mult_neg_pos: "a < 0 \<Longrightarrow> 0 < b \<Longrightarrow> a * b < 0"
huffman@30692
   800
using mult_strict_right_mono [of a zero b] by simp
huffman@30692
   801
huffman@30692
   802
text {* Legacy - use @{text mult_neg_pos} *}
huffman@30692
   803
lemma mult_pos_neg2: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> b * a < 0" 
nipkow@29667
   804
by (drule mult_strict_right_mono [of b zero], auto)
haftmann@25230
   805
haftmann@25230
   806
lemma zero_less_mult_pos:
haftmann@25230
   807
  "0 < a * b \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
huffman@30692
   808
apply (cases "b\<le>0")
haftmann@25230
   809
 apply (auto simp add: le_less not_less)
huffman@30692
   810
apply (drule_tac mult_pos_neg [of a b])
haftmann@25230
   811
 apply (auto dest: less_not_sym)
haftmann@25230
   812
done
haftmann@25230
   813
haftmann@25230
   814
lemma zero_less_mult_pos2:
haftmann@25230
   815
  "0 < b * a \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
huffman@30692
   816
apply (cases "b\<le>0")
haftmann@25230
   817
 apply (auto simp add: le_less not_less)
huffman@30692
   818
apply (drule_tac mult_pos_neg2 [of a b])
haftmann@25230
   819
 apply (auto dest: less_not_sym)
haftmann@25230
   820
done
haftmann@25230
   821
haftmann@26193
   822
text{*Strict monotonicity in both arguments*}
haftmann@26193
   823
lemma mult_strict_mono:
haftmann@26193
   824
  assumes "a < b" and "c < d" and "0 < b" and "0 \<le> c"
haftmann@26193
   825
  shows "a * c < b * d"
haftmann@26193
   826
  using assms apply (cases "c=0")
huffman@30692
   827
  apply (simp add: mult_pos_pos)
haftmann@26193
   828
  apply (erule mult_strict_right_mono [THEN less_trans])
huffman@30692
   829
  apply (force simp add: le_less)
haftmann@26193
   830
  apply (erule mult_strict_left_mono, assumption)
haftmann@26193
   831
  done
haftmann@26193
   832
haftmann@26193
   833
text{*This weaker variant has more natural premises*}
haftmann@26193
   834
lemma mult_strict_mono':
haftmann@26193
   835
  assumes "a < b" and "c < d" and "0 \<le> a" and "0 \<le> c"
haftmann@26193
   836
  shows "a * c < b * d"
nipkow@29667
   837
by (rule mult_strict_mono) (insert assms, auto)
haftmann@26193
   838
haftmann@26193
   839
lemma mult_less_le_imp_less:
haftmann@26193
   840
  assumes "a < b" and "c \<le> d" and "0 \<le> a" and "0 < c"
haftmann@26193
   841
  shows "a * c < b * d"
haftmann@26193
   842
  using assms apply (subgoal_tac "a * c < b * c")
haftmann@26193
   843
  apply (erule less_le_trans)
haftmann@26193
   844
  apply (erule mult_left_mono)
haftmann@26193
   845
  apply simp
haftmann@26193
   846
  apply (erule mult_strict_right_mono)
haftmann@26193
   847
  apply assumption
haftmann@26193
   848
  done
haftmann@26193
   849
haftmann@26193
   850
lemma mult_le_less_imp_less:
haftmann@26193
   851
  assumes "a \<le> b" and "c < d" and "0 < a" and "0 \<le> c"
haftmann@26193
   852
  shows "a * c < b * d"
haftmann@26193
   853
  using assms apply (subgoal_tac "a * c \<le> b * c")
haftmann@26193
   854
  apply (erule le_less_trans)
haftmann@26193
   855
  apply (erule mult_strict_left_mono)
haftmann@26193
   856
  apply simp
haftmann@26193
   857
  apply (erule mult_right_mono)
haftmann@26193
   858
  apply simp
haftmann@26193
   859
  done
haftmann@26193
   860
haftmann@26193
   861
lemma mult_less_imp_less_left:
haftmann@26193
   862
  assumes less: "c * a < c * b" and nonneg: "0 \<le> c"
haftmann@26193
   863
  shows "a < b"
haftmann@26193
   864
proof (rule ccontr)
haftmann@26193
   865
  assume "\<not>  a < b"
haftmann@26193
   866
  hence "b \<le> a" by (simp add: linorder_not_less)
haftmann@26193
   867
  hence "c * b \<le> c * a" using nonneg by (rule mult_left_mono)
nipkow@29667
   868
  with this and less show False by (simp add: not_less [symmetric])
haftmann@26193
   869
qed
haftmann@26193
   870
haftmann@26193
   871
lemma mult_less_imp_less_right:
haftmann@26193
   872
  assumes less: "a * c < b * c" and nonneg: "0 \<le> c"
haftmann@26193
   873
  shows "a < b"
haftmann@26193
   874
proof (rule ccontr)
haftmann@26193
   875
  assume "\<not> a < b"
haftmann@26193
   876
  hence "b \<le> a" by (simp add: linorder_not_less)
haftmann@26193
   877
  hence "b * c \<le> a * c" using nonneg by (rule mult_right_mono)
nipkow@29667
   878
  with this and less show False by (simp add: not_less [symmetric])
haftmann@26193
   879
qed  
haftmann@26193
   880
haftmann@25230
   881
end
haftmann@25230
   882
haftmann@22390
   883
class mult_mono1 = times + zero + ord +
haftmann@25230
   884
  assumes mult_mono1: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
paulson@14270
   885
haftmann@22390
   886
class pordered_comm_semiring = comm_semiring_0
haftmann@22390
   887
  + pordered_ab_semigroup_add + mult_mono1
haftmann@25186
   888
begin
haftmann@25152
   889
haftmann@25267
   890
subclass pordered_semiring
haftmann@28823
   891
proof
krauss@21199
   892
  fix a b c :: 'a
huffman@23550
   893
  assume "a \<le> b" "0 \<le> c"
haftmann@25230
   894
  thus "c * a \<le> c * b" by (rule mult_mono1)
huffman@23550
   895
  thus "a * c \<le> b * c" by (simp only: mult_commute)
krauss@21199
   896
qed
paulson@14265
   897
haftmann@25267
   898
end
haftmann@25267
   899
haftmann@25267
   900
class pordered_cancel_comm_semiring = comm_semiring_0_cancel
haftmann@25267
   901
  + pordered_ab_semigroup_add + mult_mono1
haftmann@25267
   902
begin
paulson@14265
   903
huffman@27516
   904
subclass pordered_comm_semiring ..
huffman@27516
   905
subclass pordered_cancel_semiring ..
haftmann@25267
   906
haftmann@25267
   907
end
haftmann@25267
   908
haftmann@25267
   909
class ordered_comm_semiring_strict = comm_semiring_0 + ordered_cancel_ab_semigroup_add +
haftmann@26193
   910
  assumes mult_strict_left_mono_comm: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
haftmann@25267
   911
begin
haftmann@25267
   912
haftmann@25267
   913
subclass ordered_semiring_strict
haftmann@28823
   914
proof
huffman@23550
   915
  fix a b c :: 'a
huffman@23550
   916
  assume "a < b" "0 < c"
haftmann@26193
   917
  thus "c * a < c * b" by (rule mult_strict_left_mono_comm)
huffman@23550
   918
  thus "a * c < b * c" by (simp only: mult_commute)
huffman@23550
   919
qed
paulson@14272
   920
haftmann@25267
   921
subclass pordered_cancel_comm_semiring
haftmann@28823
   922
proof
huffman@23550
   923
  fix a b c :: 'a
huffman@23550
   924
  assume "a \<le> b" "0 \<le> c"
huffman@23550
   925
  thus "c * a \<le> c * b"
haftmann@25186
   926
    unfolding le_less
haftmann@26193
   927
    using mult_strict_left_mono by (cases "c = 0") auto
huffman@23550
   928
qed
paulson@14272
   929
haftmann@25267
   930
end
haftmann@25230
   931
haftmann@25267
   932
class pordered_ring = ring + pordered_cancel_semiring 
haftmann@25267
   933
begin
haftmann@25230
   934
huffman@27516
   935
subclass pordered_ab_group_add ..
paulson@14270
   936
nipkow@29667
   937
text{*Legacy - use @{text algebra_simps} *}
nipkow@29833
   938
lemmas ring_simps[noatp] = algebra_simps
haftmann@25230
   939
haftmann@25230
   940
lemma less_add_iff1:
haftmann@25230
   941
  "a * e + c < b * e + d \<longleftrightarrow> (a - b) * e + c < d"
nipkow@29667
   942
by (simp add: algebra_simps)
haftmann@25230
   943
haftmann@25230
   944
lemma less_add_iff2:
haftmann@25230
   945
  "a * e + c < b * e + d \<longleftrightarrow> c < (b - a) * e + d"
nipkow@29667
   946
by (simp add: algebra_simps)
haftmann@25230
   947
haftmann@25230
   948
lemma le_add_iff1:
haftmann@25230
   949
  "a * e + c \<le> b * e + d \<longleftrightarrow> (a - b) * e + c \<le> d"
nipkow@29667
   950
by (simp add: algebra_simps)
haftmann@25230
   951
haftmann@25230
   952
lemma le_add_iff2:
haftmann@25230
   953
  "a * e + c \<le> b * e + d \<longleftrightarrow> c \<le> (b - a) * e + d"
nipkow@29667
   954
by (simp add: algebra_simps)
haftmann@25230
   955
haftmann@25230
   956
lemma mult_left_mono_neg:
haftmann@25230
   957
  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> c * a \<le> c * b"
haftmann@25230
   958
  apply (drule mult_left_mono [of _ _ "uminus c"])
haftmann@25230
   959
  apply (simp_all add: minus_mult_left [symmetric]) 
haftmann@25230
   960
  done
haftmann@25230
   961
haftmann@25230
   962
lemma mult_right_mono_neg:
haftmann@25230
   963
  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> a * c \<le> b * c"
haftmann@25230
   964
  apply (drule mult_right_mono [of _ _ "uminus c"])
haftmann@25230
   965
  apply (simp_all add: minus_mult_right [symmetric]) 
haftmann@25230
   966
  done
haftmann@25230
   967
huffman@30692
   968
lemma mult_nonpos_nonpos: "a \<le> 0 \<Longrightarrow> b \<le> 0 \<Longrightarrow> 0 \<le> a * b"
huffman@30692
   969
using mult_right_mono_neg [of a zero b] by simp
haftmann@25230
   970
haftmann@25230
   971
lemma split_mult_pos_le:
haftmann@25230
   972
  "(0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0) \<Longrightarrow> 0 \<le> a * b"
nipkow@29667
   973
by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos)
haftmann@25186
   974
haftmann@25186
   975
end
paulson@14270
   976
haftmann@25762
   977
class abs_if = minus + uminus + ord + zero + abs +
haftmann@25762
   978
  assumes abs_if: "\<bar>a\<bar> = (if a < 0 then - a else a)"
haftmann@25762
   979
haftmann@25762
   980
class sgn_if = minus + uminus + zero + one + ord + sgn +
haftmann@25186
   981
  assumes sgn_if: "sgn x = (if x = 0 then 0 else if 0 < x then 1 else - 1)"
nipkow@24506
   982
nipkow@25564
   983
lemma (in sgn_if) sgn0[simp]: "sgn 0 = 0"
nipkow@25564
   984
by(simp add:sgn_if)
nipkow@25564
   985
haftmann@25230
   986
class ordered_ring = ring + ordered_semiring
haftmann@25304
   987
  + ordered_ab_group_add + abs_if
haftmann@25304
   988
begin
haftmann@25304
   989
huffman@27516
   990
subclass pordered_ring ..
haftmann@25304
   991
haftmann@25304
   992
subclass pordered_ab_group_add_abs
haftmann@28823
   993
proof
haftmann@25304
   994
  fix a b
haftmann@25304
   995
  show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
nipkow@29667
   996
by (auto simp add: abs_if not_less neg_less_eq_nonneg less_eq_neg_nonpos)
haftmann@25304
   997
   (auto simp del: minus_add_distrib simp add: minus_add_distrib [symmetric]
haftmann@25304
   998
     neg_less_eq_nonneg less_eq_neg_nonpos, auto intro: add_nonneg_nonneg,
haftmann@25304
   999
      auto intro!: less_imp_le add_neg_neg)
haftmann@25304
  1000
qed (auto simp add: abs_if less_eq_neg_nonpos neg_equal_zero)
haftmann@25304
  1001
haftmann@25304
  1002
end
obua@23521
  1003
haftmann@25230
  1004
(* The "strict" suffix can be seen as describing the combination of ordered_ring and no_zero_divisors.
haftmann@25230
  1005
   Basically, ordered_ring + no_zero_divisors = ordered_ring_strict.
haftmann@25230
  1006
 *)
haftmann@25230
  1007
class ordered_ring_strict = ring + ordered_semiring_strict
haftmann@25304
  1008
  + ordered_ab_group_add + abs_if
haftmann@25230
  1009
begin
paulson@14348
  1010
huffman@27516
  1011
subclass ordered_ring ..
haftmann@25304
  1012
huffman@30692
  1013
lemma mult_strict_left_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> c * a < c * b"
huffman@30692
  1014
using mult_strict_left_mono [of b a "- c"] by simp
huffman@30692
  1015
huffman@30692
  1016
lemma mult_strict_right_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> a * c < b * c"
huffman@30692
  1017
using mult_strict_right_mono [of b a "- c"] by simp
huffman@30692
  1018
huffman@30692
  1019
lemma mult_neg_neg: "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> 0 < a * b"
huffman@30692
  1020
using mult_strict_right_mono_neg [of a zero b] by simp
obua@14738
  1021
haftmann@25917
  1022
subclass ring_no_zero_divisors
haftmann@28823
  1023
proof
haftmann@25917
  1024
  fix a b
haftmann@25917
  1025
  assume "a \<noteq> 0" then have A: "a < 0 \<or> 0 < a" by (simp add: neq_iff)
haftmann@25917
  1026
  assume "b \<noteq> 0" then have B: "b < 0 \<or> 0 < b" by (simp add: neq_iff)
haftmann@25917
  1027
  have "a * b < 0 \<or> 0 < a * b"
haftmann@25917
  1028
  proof (cases "a < 0")
haftmann@25917
  1029
    case True note A' = this
haftmann@25917
  1030
    show ?thesis proof (cases "b < 0")
haftmann@25917
  1031
      case True with A'
haftmann@25917
  1032
      show ?thesis by (auto dest: mult_neg_neg)
haftmann@25917
  1033
    next
haftmann@25917
  1034
      case False with B have "0 < b" by auto
haftmann@25917
  1035
      with A' show ?thesis by (auto dest: mult_strict_right_mono)
haftmann@25917
  1036
    qed
haftmann@25917
  1037
  next
haftmann@25917
  1038
    case False with A have A': "0 < a" by auto
haftmann@25917
  1039
    show ?thesis proof (cases "b < 0")
haftmann@25917
  1040
      case True with A'
haftmann@25917
  1041
      show ?thesis by (auto dest: mult_strict_right_mono_neg)
haftmann@25917
  1042
    next
haftmann@25917
  1043
      case False with B have "0 < b" by auto
haftmann@25917
  1044
      with A' show ?thesis by (auto dest: mult_pos_pos)
haftmann@25917
  1045
    qed
haftmann@25917
  1046
  qed
haftmann@25917
  1047
  then show "a * b \<noteq> 0" by (simp add: neq_iff)
haftmann@25917
  1048
qed
haftmann@25304
  1049
paulson@14265
  1050
lemma zero_less_mult_iff:
haftmann@25917
  1051
  "0 < a * b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0"
haftmann@25917
  1052
  apply (auto simp add: mult_pos_pos mult_neg_neg)
haftmann@25917
  1053
  apply (simp_all add: not_less le_less)
haftmann@25917
  1054
  apply (erule disjE) apply assumption defer
haftmann@25917
  1055
  apply (erule disjE) defer apply (drule sym) apply simp
haftmann@25917
  1056
  apply (erule disjE) defer apply (drule sym) apply simp
haftmann@25917
  1057
  apply (erule disjE) apply assumption apply (drule sym) apply simp
haftmann@25917
  1058
  apply (drule sym) apply simp
haftmann@25917
  1059
  apply (blast dest: zero_less_mult_pos)
haftmann@25230
  1060
  apply (blast dest: zero_less_mult_pos2)
haftmann@25230
  1061
  done
huffman@22990
  1062
paulson@14265
  1063
lemma zero_le_mult_iff:
haftmann@25917
  1064
  "0 \<le> a * b \<longleftrightarrow> 0 \<le> a \<and> 0 \<le> b \<or> a \<le> 0 \<and> b \<le> 0"
nipkow@29667
  1065
by (auto simp add: eq_commute [of 0] le_less not_less zero_less_mult_iff)
paulson@14265
  1066
paulson@14265
  1067
lemma mult_less_0_iff:
haftmann@25917
  1068
  "a * b < 0 \<longleftrightarrow> 0 < a \<and> b < 0 \<or> a < 0 \<and> 0 < b"
haftmann@25917
  1069
  apply (insert zero_less_mult_iff [of "-a" b]) 
haftmann@25917
  1070
  apply (force simp add: minus_mult_left[symmetric]) 
haftmann@25917
  1071
  done
paulson@14265
  1072
paulson@14265
  1073
lemma mult_le_0_iff:
haftmann@25917
  1074
  "a * b \<le> 0 \<longleftrightarrow> 0 \<le> a \<and> b \<le> 0 \<or> a \<le> 0 \<and> 0 \<le> b"
haftmann@25917
  1075
  apply (insert zero_le_mult_iff [of "-a" b]) 
haftmann@25917
  1076
  apply (force simp add: minus_mult_left[symmetric]) 
haftmann@25917
  1077
  done
haftmann@25917
  1078
haftmann@25917
  1079
lemma zero_le_square [simp]: "0 \<le> a * a"
nipkow@29667
  1080
by (simp add: zero_le_mult_iff linear)
haftmann@25917
  1081
haftmann@25917
  1082
lemma not_square_less_zero [simp]: "\<not> (a * a < 0)"
nipkow@29667
  1083
by (simp add: not_less)
haftmann@25917
  1084
haftmann@26193
  1085
text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
haftmann@26193
  1086
   also with the relations @{text "\<le>"} and equality.*}
haftmann@26193
  1087
haftmann@26193
  1088
text{*These ``disjunction'' versions produce two cases when the comparison is
haftmann@26193
  1089
 an assumption, but effectively four when the comparison is a goal.*}
haftmann@26193
  1090
haftmann@26193
  1091
lemma mult_less_cancel_right_disj:
haftmann@26193
  1092
  "a * c < b * c \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
  1093
  apply (cases "c = 0")
haftmann@26193
  1094
  apply (auto simp add: neq_iff mult_strict_right_mono 
haftmann@26193
  1095
                      mult_strict_right_mono_neg)
haftmann@26193
  1096
  apply (auto simp add: not_less 
haftmann@26193
  1097
                      not_le [symmetric, of "a*c"]
haftmann@26193
  1098
                      not_le [symmetric, of a])
haftmann@26193
  1099
  apply (erule_tac [!] notE)
haftmann@26193
  1100
  apply (auto simp add: less_imp_le mult_right_mono 
haftmann@26193
  1101
                      mult_right_mono_neg)
haftmann@26193
  1102
  done
haftmann@26193
  1103
haftmann@26193
  1104
lemma mult_less_cancel_left_disj:
haftmann@26193
  1105
  "c * a < c * b \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
haftmann@26193
  1106
  apply (cases "c = 0")
haftmann@26193
  1107
  apply (auto simp add: neq_iff mult_strict_left_mono 
haftmann@26193
  1108
                      mult_strict_left_mono_neg)
haftmann@26193
  1109
  apply (auto simp add: not_less 
haftmann@26193
  1110
                      not_le [symmetric, of "c*a"]
haftmann@26193
  1111
                      not_le [symmetric, of a])
haftmann@26193
  1112
  apply (erule_tac [!] notE)
haftmann@26193
  1113
  apply (auto simp add: less_imp_le mult_left_mono 
haftmann@26193
  1114
                      mult_left_mono_neg)
haftmann@26193
  1115
  done
haftmann@26193
  1116
haftmann@26193
  1117
text{*The ``conjunction of implication'' lemmas produce two cases when the
haftmann@26193
  1118
comparison is a goal, but give four when the comparison is an assumption.*}
haftmann@26193
  1119
haftmann@26193
  1120
lemma mult_less_cancel_right:
haftmann@26193
  1121
  "a * c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
  1122
  using mult_less_cancel_right_disj [of a c b] by auto
haftmann@26193
  1123
haftmann@26193
  1124
lemma mult_less_cancel_left:
haftmann@26193
  1125
  "c * a < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
haftmann@26193
  1126
  using mult_less_cancel_left_disj [of c a b] by auto
haftmann@26193
  1127
haftmann@26193
  1128
lemma mult_le_cancel_right:
haftmann@26193
  1129
   "a * c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
nipkow@29667
  1130
by (simp add: not_less [symmetric] mult_less_cancel_right_disj)
haftmann@26193
  1131
haftmann@26193
  1132
lemma mult_le_cancel_left:
haftmann@26193
  1133
  "c * a \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
nipkow@29667
  1134
by (simp add: not_less [symmetric] mult_less_cancel_left_disj)
haftmann@26193
  1135
nipkow@30649
  1136
lemma mult_le_cancel_left_pos:
nipkow@30649
  1137
  "0 < c \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> a \<le> b"
nipkow@30649
  1138
by (auto simp: mult_le_cancel_left)
nipkow@30649
  1139
nipkow@30649
  1140
lemma mult_le_cancel_left_neg:
nipkow@30649
  1141
  "c < 0 \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> b \<le> a"
nipkow@30649
  1142
by (auto simp: mult_le_cancel_left)
nipkow@30649
  1143
nipkow@30649
  1144
lemma mult_less_cancel_left_pos:
nipkow@30649
  1145
  "0 < c \<Longrightarrow> c * a < c * b \<longleftrightarrow> a < b"
nipkow@30649
  1146
by (auto simp: mult_less_cancel_left)
nipkow@30649
  1147
nipkow@30649
  1148
lemma mult_less_cancel_left_neg:
nipkow@30649
  1149
  "c < 0 \<Longrightarrow> c * a < c * b \<longleftrightarrow> b < a"
nipkow@30649
  1150
by (auto simp: mult_less_cancel_left)
nipkow@30649
  1151
haftmann@25917
  1152
end
paulson@14265
  1153
nipkow@29667
  1154
text{*Legacy - use @{text algebra_simps} *}
nipkow@29833
  1155
lemmas ring_simps[noatp] = algebra_simps
haftmann@25230
  1156
huffman@30692
  1157
lemmas mult_sign_intros =
huffman@30692
  1158
  mult_nonneg_nonneg mult_nonneg_nonpos
huffman@30692
  1159
  mult_nonpos_nonneg mult_nonpos_nonpos
huffman@30692
  1160
  mult_pos_pos mult_pos_neg
huffman@30692
  1161
  mult_neg_pos mult_neg_neg
haftmann@25230
  1162
haftmann@25230
  1163
class pordered_comm_ring = comm_ring + pordered_comm_semiring
haftmann@25267
  1164
begin
haftmann@25230
  1165
huffman@27516
  1166
subclass pordered_ring ..
huffman@27516
  1167
subclass pordered_cancel_comm_semiring ..
haftmann@25230
  1168
haftmann@25267
  1169
end
haftmann@25230
  1170
haftmann@25230
  1171
class ordered_semidom = comm_semiring_1_cancel + ordered_comm_semiring_strict +
haftmann@25230
  1172
  (*previously ordered_semiring*)
haftmann@25230
  1173
  assumes zero_less_one [simp]: "0 < 1"
haftmann@25230
  1174
begin
haftmann@25230
  1175
haftmann@25230
  1176
lemma pos_add_strict:
haftmann@25230
  1177
  shows "0 < a \<Longrightarrow> b < c \<Longrightarrow> b < a + c"
haftmann@25230
  1178
  using add_strict_mono [of zero a b c] by simp
haftmann@25230
  1179
haftmann@26193
  1180
lemma zero_le_one [simp]: "0 \<le> 1"
nipkow@29667
  1181
by (rule zero_less_one [THEN less_imp_le]) 
haftmann@26193
  1182
haftmann@26193
  1183
lemma not_one_le_zero [simp]: "\<not> 1 \<le> 0"
nipkow@29667
  1184
by (simp add: not_le) 
haftmann@26193
  1185
haftmann@26193
  1186
lemma not_one_less_zero [simp]: "\<not> 1 < 0"
nipkow@29667
  1187
by (simp add: not_less) 
haftmann@26193
  1188
haftmann@26193
  1189
lemma less_1_mult:
haftmann@26193
  1190
  assumes "1 < m" and "1 < n"
haftmann@26193
  1191
  shows "1 < m * n"
haftmann@26193
  1192
  using assms mult_strict_mono [of 1 m 1 n]
haftmann@26193
  1193
    by (simp add:  less_trans [OF zero_less_one]) 
haftmann@26193
  1194
haftmann@25230
  1195
end
haftmann@25230
  1196
haftmann@26193
  1197
class ordered_idom = comm_ring_1 +
haftmann@26193
  1198
  ordered_comm_semiring_strict + ordered_ab_group_add +
haftmann@25230
  1199
  abs_if + sgn_if
haftmann@25230
  1200
  (*previously ordered_ring*)
haftmann@25917
  1201
begin
haftmann@25917
  1202
huffman@27516
  1203
subclass ordered_ring_strict ..
huffman@27516
  1204
subclass pordered_comm_ring ..
huffman@27516
  1205
subclass idom ..
haftmann@25917
  1206
haftmann@25917
  1207
subclass ordered_semidom
haftmann@28823
  1208
proof
haftmann@26193
  1209
  have "0 \<le> 1 * 1" by (rule zero_le_square)
haftmann@26193
  1210
  thus "0 < 1" by (simp add: le_less)
haftmann@25917
  1211
qed 
haftmann@25917
  1212
haftmann@26193
  1213
lemma linorder_neqE_ordered_idom:
haftmann@26193
  1214
  assumes "x \<noteq> y" obtains "x < y" | "y < x"
haftmann@26193
  1215
  using assms by (rule neqE)
haftmann@26193
  1216
haftmann@26274
  1217
text {* These cancellation simprules also produce two cases when the comparison is a goal. *}
haftmann@26274
  1218
haftmann@26274
  1219
lemma mult_le_cancel_right1:
haftmann@26274
  1220
  "c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
nipkow@29667
  1221
by (insert mult_le_cancel_right [of 1 c b], simp)
haftmann@26274
  1222
haftmann@26274
  1223
lemma mult_le_cancel_right2:
haftmann@26274
  1224
  "a * c \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
nipkow@29667
  1225
by (insert mult_le_cancel_right [of a c 1], simp)
haftmann@26274
  1226
haftmann@26274
  1227
lemma mult_le_cancel_left1:
haftmann@26274
  1228
  "c \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
nipkow@29667
  1229
by (insert mult_le_cancel_left [of c 1 b], simp)
haftmann@26274
  1230
haftmann@26274
  1231
lemma mult_le_cancel_left2:
haftmann@26274
  1232
  "c * a \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
nipkow@29667
  1233
by (insert mult_le_cancel_left [of c a 1], simp)
haftmann@26274
  1234
haftmann@26274
  1235
lemma mult_less_cancel_right1:
haftmann@26274
  1236
  "c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
nipkow@29667
  1237
by (insert mult_less_cancel_right [of 1 c b], simp)
haftmann@26274
  1238
haftmann@26274
  1239
lemma mult_less_cancel_right2:
haftmann@26274
  1240
  "a * c < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
nipkow@29667
  1241
by (insert mult_less_cancel_right [of a c 1], simp)
haftmann@26274
  1242
haftmann@26274
  1243
lemma mult_less_cancel_left1:
haftmann@26274
  1244
  "c < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
nipkow@29667
  1245
by (insert mult_less_cancel_left [of c 1 b], simp)
haftmann@26274
  1246
haftmann@26274
  1247
lemma mult_less_cancel_left2:
haftmann@26274
  1248
  "c * a < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
nipkow@29667
  1249
by (insert mult_less_cancel_left [of c a 1], simp)
haftmann@26274
  1250
haftmann@27651
  1251
lemma sgn_sgn [simp]:
haftmann@27651
  1252
  "sgn (sgn a) = sgn a"
nipkow@29700
  1253
unfolding sgn_if by simp
haftmann@27651
  1254
haftmann@27651
  1255
lemma sgn_0_0:
haftmann@27651
  1256
  "sgn a = 0 \<longleftrightarrow> a = 0"
nipkow@29700
  1257
unfolding sgn_if by simp
haftmann@27651
  1258
haftmann@27651
  1259
lemma sgn_1_pos:
haftmann@27651
  1260
  "sgn a = 1 \<longleftrightarrow> a > 0"
nipkow@29700
  1261
unfolding sgn_if by (simp add: neg_equal_zero)
haftmann@27651
  1262
haftmann@27651
  1263
lemma sgn_1_neg:
haftmann@27651
  1264
  "sgn a = - 1 \<longleftrightarrow> a < 0"
nipkow@29700
  1265
unfolding sgn_if by (auto simp add: equal_neg_zero)
haftmann@27651
  1266
haftmann@29940
  1267
lemma sgn_pos [simp]:
haftmann@29940
  1268
  "0 < a \<Longrightarrow> sgn a = 1"
haftmann@29940
  1269
unfolding sgn_1_pos .
haftmann@29940
  1270
haftmann@29940
  1271
lemma sgn_neg [simp]:
haftmann@29940
  1272
  "a < 0 \<Longrightarrow> sgn a = - 1"
haftmann@29940
  1273
unfolding sgn_1_neg .
haftmann@29940
  1274
haftmann@27651
  1275
lemma sgn_times:
haftmann@27651
  1276
  "sgn (a * b) = sgn a * sgn b"
nipkow@29667
  1277
by (auto simp add: sgn_if zero_less_mult_iff)
haftmann@27651
  1278
haftmann@29653
  1279
lemma abs_sgn: "abs k = k * sgn k"
nipkow@29700
  1280
unfolding sgn_if abs_if by auto
nipkow@29700
  1281
haftmann@29940
  1282
lemma sgn_greater [simp]:
haftmann@29940
  1283
  "0 < sgn a \<longleftrightarrow> 0 < a"
haftmann@29940
  1284
  unfolding sgn_if by auto
haftmann@29940
  1285
haftmann@29940
  1286
lemma sgn_less [simp]:
haftmann@29940
  1287
  "sgn a < 0 \<longleftrightarrow> a < 0"
haftmann@29940
  1288
  unfolding sgn_if by auto
haftmann@29940
  1289
huffman@29949
  1290
lemma abs_dvd_iff [simp]: "(abs m) dvd k \<longleftrightarrow> m dvd k"
huffman@29949
  1291
  by (simp add: abs_if)
huffman@29949
  1292
huffman@29949
  1293
lemma dvd_abs_iff [simp]: "m dvd (abs k) \<longleftrightarrow> m dvd k"
huffman@29949
  1294
  by (simp add: abs_if)
haftmann@29653
  1295
haftmann@25917
  1296
end
haftmann@25230
  1297
haftmann@25230
  1298
class ordered_field = field + ordered_idom
haftmann@25230
  1299
haftmann@26274
  1300
text {* Simprules for comparisons where common factors can be cancelled. *}
paulson@15234
  1301
nipkow@29833
  1302
lemmas mult_compare_simps[noatp] =
paulson@15234
  1303
    mult_le_cancel_right mult_le_cancel_left
paulson@15234
  1304
    mult_le_cancel_right1 mult_le_cancel_right2
paulson@15234
  1305
    mult_le_cancel_left1 mult_le_cancel_left2
paulson@15234
  1306
    mult_less_cancel_right mult_less_cancel_left
paulson@15234
  1307
    mult_less_cancel_right1 mult_less_cancel_right2
paulson@15234
  1308
    mult_less_cancel_left1 mult_less_cancel_left2
paulson@15234
  1309
    mult_cancel_right mult_cancel_left
paulson@15234
  1310
    mult_cancel_right1 mult_cancel_right2
paulson@15234
  1311
    mult_cancel_left1 mult_cancel_left2
paulson@15234
  1312
haftmann@26274
  1313
-- {* FIXME continue localization here *}
paulson@14268
  1314
paulson@14268
  1315
lemma inverse_nonzero_iff_nonzero [simp]:
huffman@20496
  1316
   "(inverse a = 0) = (a = (0::'a::{division_ring,division_by_zero}))"
haftmann@26274
  1317
by (force dest: inverse_zero_imp_zero) 
paulson@14268
  1318
paulson@14268
  1319
lemma inverse_minus_eq [simp]:
huffman@20496
  1320
   "inverse(-a) = -inverse(a::'a::{division_ring,division_by_zero})"
paulson@14377
  1321
proof cases
paulson@14377
  1322
  assume "a=0" thus ?thesis by (simp add: inverse_zero)
paulson@14377
  1323
next
paulson@14377
  1324
  assume "a\<noteq>0" 
paulson@14377
  1325
  thus ?thesis by (simp add: nonzero_inverse_minus_eq)
paulson@14377
  1326
qed
paulson@14268
  1327
paulson@14268
  1328
lemma inverse_eq_imp_eq:
huffman@20496
  1329
  "inverse a = inverse b ==> a = (b::'a::{division_ring,division_by_zero})"
haftmann@21328
  1330
apply (cases "a=0 | b=0") 
paulson@14268
  1331
 apply (force dest!: inverse_zero_imp_zero
paulson@14268
  1332
              simp add: eq_commute [of "0::'a"])
paulson@14268
  1333
apply (force dest!: nonzero_inverse_eq_imp_eq) 
paulson@14268
  1334
done
paulson@14268
  1335
paulson@14268
  1336
lemma inverse_eq_iff_eq [simp]:
huffman@20496
  1337
  "(inverse a = inverse b) = (a = (b::'a::{division_ring,division_by_zero}))"
huffman@20496
  1338
by (force dest!: inverse_eq_imp_eq)
paulson@14268
  1339
paulson@14270
  1340
lemma inverse_inverse_eq [simp]:
huffman@20496
  1341
     "inverse(inverse (a::'a::{division_ring,division_by_zero})) = a"
paulson@14270
  1342
  proof cases
paulson@14270
  1343
    assume "a=0" thus ?thesis by simp
paulson@14270
  1344
  next
paulson@14270
  1345
    assume "a\<noteq>0" 
paulson@14270
  1346
    thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
paulson@14270
  1347
  qed
paulson@14270
  1348
paulson@14270
  1349
text{*This version builds in division by zero while also re-orienting
paulson@14270
  1350
      the right-hand side.*}
paulson@14270
  1351
lemma inverse_mult_distrib [simp]:
paulson@14270
  1352
     "inverse(a*b) = inverse(a) * inverse(b::'a::{field,division_by_zero})"
paulson@14270
  1353
  proof cases
paulson@14270
  1354
    assume "a \<noteq> 0 & b \<noteq> 0" 
nipkow@29667
  1355
    thus ?thesis by (simp add: nonzero_inverse_mult_distrib mult_commute)
paulson@14270
  1356
  next
paulson@14270
  1357
    assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
nipkow@29667
  1358
    thus ?thesis by force
paulson@14270
  1359
  qed
paulson@14270
  1360
paulson@14365
  1361
lemma inverse_divide [simp]:
nipkow@23477
  1362
  "inverse (a/b) = b / (a::'a::{field,division_by_zero})"
nipkow@23477
  1363
by (simp add: divide_inverse mult_commute)
paulson@14365
  1364
wenzelm@23389
  1365
avigad@16775
  1366
subsection {* Calculations with fractions *}
avigad@16775
  1367
nipkow@23413
  1368
text{* There is a whole bunch of simp-rules just for class @{text
nipkow@23413
  1369
field} but none for class @{text field} and @{text nonzero_divides}
nipkow@23413
  1370
because the latter are covered by a simproc. *}
nipkow@23413
  1371
nipkow@23413
  1372
lemma mult_divide_mult_cancel_left:
nipkow@23477
  1373
  "c\<noteq>0 ==> (c*a) / (c*b) = a / (b::'a::{field,division_by_zero})"
haftmann@21328
  1374
apply (cases "b = 0")
nipkow@23413
  1375
apply (simp_all add: nonzero_mult_divide_mult_cancel_left)
paulson@14277
  1376
done
paulson@14277
  1377
nipkow@23413
  1378
lemma mult_divide_mult_cancel_right:
nipkow@23477
  1379
  "c\<noteq>0 ==> (a*c) / (b*c) = a / (b::'a::{field,division_by_zero})"
haftmann@21328
  1380
apply (cases "b = 0")
nipkow@23413
  1381
apply (simp_all add: nonzero_mult_divide_mult_cancel_right)
paulson@14321
  1382
done
nipkow@23413
  1383
paulson@24286
  1384
lemma divide_divide_eq_right [simp,noatp]:
nipkow@23477
  1385
  "a / (b/c) = (a*c) / (b::'a::{field,division_by_zero})"
paulson@14430
  1386
by (simp add: divide_inverse mult_ac)
paulson@14288
  1387
paulson@24286
  1388
lemma divide_divide_eq_left [simp,noatp]:
nipkow@23477
  1389
  "(a / b) / (c::'a::{field,division_by_zero}) = a / (b*c)"
paulson@14430
  1390
by (simp add: divide_inverse mult_assoc)
paulson@14288
  1391
wenzelm@23389
  1392
paulson@15234
  1393
subsubsection{*Special Cancellation Simprules for Division*}
paulson@15234
  1394
paulson@24427
  1395
lemma mult_divide_mult_cancel_left_if[simp,noatp]:
nipkow@23477
  1396
fixes c :: "'a :: {field,division_by_zero}"
nipkow@23477
  1397
shows "(c*a) / (c*b) = (if c=0 then 0 else a/b)"
nipkow@23413
  1398
by (simp add: mult_divide_mult_cancel_left)
nipkow@23413
  1399
paulson@15234
  1400
paulson@14293
  1401
subsection {* Division and Unary Minus *}
paulson@14293
  1402
paulson@14293
  1403
lemma minus_divide_right: "- (a/b) = a / -(b::'a::{field,division_by_zero})"
huffman@29407
  1404
by (simp add: divide_inverse)
paulson@14430
  1405
huffman@30630
  1406
lemma divide_minus_right [simp, noatp]:
huffman@30630
  1407
  "a / -(b::'a::{field,division_by_zero}) = -(a / b)"
huffman@30630
  1408
by (simp add: divide_inverse)
huffman@30630
  1409
huffman@30630
  1410
lemma minus_divide_divide:
nipkow@23477
  1411
  "(-a)/(-b) = a / (b::'a::{field,division_by_zero})"
haftmann@21328
  1412
apply (cases "b=0", simp) 
paulson@14293
  1413
apply (simp add: nonzero_minus_divide_divide) 
paulson@14293
  1414
done
paulson@14293
  1415
nipkow@23482
  1416
lemma eq_divide_eq:
nipkow@23482
  1417
  "((a::'a::{field,division_by_zero}) = b/c) = (if c\<noteq>0 then a*c = b else a=0)"
huffman@30630
  1418
by (simp add: nonzero_eq_divide_eq)
nipkow@23482
  1419
nipkow@23482
  1420
lemma divide_eq_eq:
nipkow@23482
  1421
  "(b/c = (a::'a::{field,division_by_zero})) = (if c\<noteq>0 then b = a*c else a=0)"
huffman@30630
  1422
by (force simp add: nonzero_divide_eq_eq)
paulson@14293
  1423
wenzelm@23389
  1424
paulson@14268
  1425
subsection {* Ordered Fields *}
paulson@14268
  1426
paulson@14277
  1427
lemma positive_imp_inverse_positive: 
nipkow@23482
  1428
assumes a_gt_0: "0 < a"  shows "0 < inverse (a::'a::ordered_field)"
nipkow@23482
  1429
proof -
paulson@14268
  1430
  have "0 < a * inverse a" 
paulson@14268
  1431
    by (simp add: a_gt_0 [THEN order_less_imp_not_eq2] zero_less_one)
paulson@14268
  1432
  thus "0 < inverse a" 
paulson@14268
  1433
    by (simp add: a_gt_0 [THEN order_less_not_sym] zero_less_mult_iff)
nipkow@23482
  1434
qed
paulson@14268
  1435
paulson@14277
  1436
lemma negative_imp_inverse_negative:
nipkow@23482
  1437
  "a < 0 ==> inverse a < (0::'a::ordered_field)"
nipkow@23482
  1438
by (insert positive_imp_inverse_positive [of "-a"], 
nipkow@23482
  1439
    simp add: nonzero_inverse_minus_eq order_less_imp_not_eq)
paulson@14268
  1440
paulson@14268
  1441
lemma inverse_le_imp_le:
nipkow@23482
  1442
assumes invle: "inverse a \<le> inverse b" and apos:  "0 < a"
nipkow@23482
  1443
shows "b \<le> (a::'a::ordered_field)"
nipkow@23482
  1444
proof (rule classical)
paulson@14268
  1445
  assume "~ b \<le> a"
nipkow@23482
  1446
  hence "a < b"  by (simp add: linorder_not_le)
nipkow@23482
  1447
  hence bpos: "0 < b"  by (blast intro: apos order_less_trans)
paulson@14268
  1448
  hence "a * inverse a \<le> a * inverse b"
paulson@14268
  1449
    by (simp add: apos invle order_less_imp_le mult_left_mono)
paulson@14268
  1450
  hence "(a * inverse a) * b \<le> (a * inverse b) * b"
paulson@14268
  1451
    by (simp add: bpos order_less_imp_le mult_right_mono)
nipkow@23482
  1452
  thus "b \<le> a"  by (simp add: mult_assoc apos bpos order_less_imp_not_eq2)
nipkow@23482
  1453
qed
paulson@14268
  1454
paulson@14277
  1455
lemma inverse_positive_imp_positive:
nipkow@23482
  1456
assumes inv_gt_0: "0 < inverse a" and nz: "a \<noteq> 0"
nipkow@23482
  1457
shows "0 < (a::'a::ordered_field)"
wenzelm@23389
  1458
proof -
paulson@14277
  1459
  have "0 < inverse (inverse a)"
wenzelm@23389
  1460
    using inv_gt_0 by (rule positive_imp_inverse_positive)
paulson@14277
  1461
  thus "0 < a"
wenzelm@23389
  1462
    using nz by (simp add: nonzero_inverse_inverse_eq)
wenzelm@23389
  1463
qed
paulson@14277
  1464
paulson@14277
  1465
lemma inverse_positive_iff_positive [simp]:
nipkow@23482
  1466
  "(0 < inverse a) = (0 < (a::'a::{ordered_field,division_by_zero}))"
haftmann@21328
  1467
apply (cases "a = 0", simp)
paulson@14277
  1468
apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
paulson@14277
  1469
done
paulson@14277
  1470
paulson@14277
  1471
lemma inverse_negative_imp_negative:
nipkow@23482
  1472
assumes inv_less_0: "inverse a < 0" and nz:  "a \<noteq> 0"
nipkow@23482
  1473
shows "a < (0::'a::ordered_field)"
wenzelm@23389
  1474
proof -
paulson@14277
  1475
  have "inverse (inverse a) < 0"
wenzelm@23389
  1476
    using inv_less_0 by (rule negative_imp_inverse_negative)
nipkow@23482
  1477
  thus "a < 0" using nz by (simp add: nonzero_inverse_inverse_eq)
wenzelm@23389
  1478
qed
paulson@14277
  1479
paulson@14277
  1480
lemma inverse_negative_iff_negative [simp]:
nipkow@23482
  1481
  "(inverse a < 0) = (a < (0::'a::{ordered_field,division_by_zero}))"
haftmann@21328
  1482
apply (cases "a = 0", simp)
paulson@14277
  1483
apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
paulson@14277
  1484
done
paulson@14277
  1485
paulson@14277
  1486
lemma inverse_nonnegative_iff_nonnegative [simp]:
nipkow@23482
  1487
  "(0 \<le> inverse a) = (0 \<le> (a::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1488
by (simp add: linorder_not_less [symmetric])
paulson@14277
  1489
paulson@14277
  1490
lemma inverse_nonpositive_iff_nonpositive [simp]:
nipkow@23482
  1491
  "(inverse a \<le> 0) = (a \<le> (0::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1492
by (simp add: linorder_not_less [symmetric])
paulson@14277
  1493
chaieb@23406
  1494
lemma ordered_field_no_lb: "\<forall> x. \<exists>y. y < (x::'a::ordered_field)"
chaieb@23406
  1495
proof
chaieb@23406
  1496
  fix x::'a
chaieb@23406
  1497
  have m1: "- (1::'a) < 0" by simp
chaieb@23406
  1498
  from add_strict_right_mono[OF m1, where c=x] 
chaieb@23406
  1499
  have "(- 1) + x < x" by simp
chaieb@23406
  1500
  thus "\<exists>y. y < x" by blast
chaieb@23406
  1501
qed
chaieb@23406
  1502
chaieb@23406
  1503
lemma ordered_field_no_ub: "\<forall> x. \<exists>y. y > (x::'a::ordered_field)"
chaieb@23406
  1504
proof
chaieb@23406
  1505
  fix x::'a
chaieb@23406
  1506
  have m1: " (1::'a) > 0" by simp
chaieb@23406
  1507
  from add_strict_right_mono[OF m1, where c=x] 
chaieb@23406
  1508
  have "1 + x > x" by simp
chaieb@23406
  1509
  thus "\<exists>y. y > x" by blast
chaieb@23406
  1510
qed
paulson@14277
  1511
paulson@14277
  1512
subsection{*Anti-Monotonicity of @{term inverse}*}
paulson@14277
  1513
paulson@14268
  1514
lemma less_imp_inverse_less:
nipkow@23482
  1515
assumes less: "a < b" and apos:  "0 < a"
nipkow@23482
  1516
shows "inverse b < inverse (a::'a::ordered_field)"
nipkow@23482
  1517
proof (rule ccontr)
paulson@14268
  1518
  assume "~ inverse b < inverse a"
nipkow@29667
  1519
  hence "inverse a \<le> inverse b" by (simp add: linorder_not_less)
paulson@14268
  1520
  hence "~ (a < b)"
paulson@14268
  1521
    by (simp add: linorder_not_less inverse_le_imp_le [OF _ apos])
nipkow@29667
  1522
  thus False by (rule notE [OF _ less])
nipkow@23482
  1523
qed
paulson@14268
  1524
paulson@14268
  1525
lemma inverse_less_imp_less:
nipkow@23482
  1526
  "[|inverse a < inverse b; 0 < a|] ==> b < (a::'a::ordered_field)"
paulson@14268
  1527
apply (simp add: order_less_le [of "inverse a"] order_less_le [of "b"])
paulson@14268
  1528
apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
paulson@14268
  1529
done
paulson@14268
  1530
paulson@14268
  1531
text{*Both premises are essential. Consider -1 and 1.*}
paulson@24286
  1532
lemma inverse_less_iff_less [simp,noatp]:
nipkow@23482
  1533
  "[|0 < a; 0 < b|] ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
  1534
by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
paulson@14268
  1535
paulson@14268
  1536
lemma le_imp_inverse_le:
nipkow@23482
  1537
  "[|a \<le> b; 0 < a|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
nipkow@23482
  1538
by (force simp add: order_le_less less_imp_inverse_less)
paulson@14268
  1539
paulson@24286
  1540
lemma inverse_le_iff_le [simp,noatp]:
nipkow@23482
  1541
 "[|0 < a; 0 < b|] ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1542
by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
paulson@14268
  1543
paulson@14268
  1544
paulson@14268
  1545
text{*These results refer to both operands being negative.  The opposite-sign
paulson@14268
  1546
case is trivial, since inverse preserves signs.*}
paulson@14268
  1547
lemma inverse_le_imp_le_neg:
nipkow@23482
  1548
  "[|inverse a \<le> inverse b; b < 0|] ==> b \<le> (a::'a::ordered_field)"
nipkow@23482
  1549
apply (rule classical) 
nipkow@23482
  1550
apply (subgoal_tac "a < 0") 
nipkow@23482
  1551
 prefer 2 apply (force simp add: linorder_not_le intro: order_less_trans) 
nipkow@23482
  1552
apply (insert inverse_le_imp_le [of "-b" "-a"])
nipkow@23482
  1553
apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
nipkow@23482
  1554
done
paulson@14268
  1555
paulson@14268
  1556
lemma less_imp_inverse_less_neg:
paulson@14268
  1557
   "[|a < b; b < 0|] ==> inverse b < inverse (a::'a::ordered_field)"
nipkow@23482
  1558
apply (subgoal_tac "a < 0") 
nipkow@23482
  1559
 prefer 2 apply (blast intro: order_less_trans) 
nipkow@23482
  1560
apply (insert less_imp_inverse_less [of "-b" "-a"])
nipkow@23482
  1561
apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
nipkow@23482
  1562
done
paulson@14268
  1563
paulson@14268
  1564
lemma inverse_less_imp_less_neg:
paulson@14268
  1565
   "[|inverse a < inverse b; b < 0|] ==> b < (a::'a::ordered_field)"
nipkow@23482
  1566
apply (rule classical) 
nipkow@23482
  1567
apply (subgoal_tac "a < 0") 
nipkow@23482
  1568
 prefer 2
nipkow@23482
  1569
 apply (force simp add: linorder_not_less intro: order_le_less_trans) 
nipkow@23482
  1570
apply (insert inverse_less_imp_less [of "-b" "-a"])
nipkow@23482
  1571
apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
nipkow@23482
  1572
done
paulson@14268
  1573
paulson@24286
  1574
lemma inverse_less_iff_less_neg [simp,noatp]:
nipkow@23482
  1575
  "[|a < 0; b < 0|] ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
nipkow@23482
  1576
apply (insert inverse_less_iff_less [of "-b" "-a"])
nipkow@23482
  1577
apply (simp del: inverse_less_iff_less 
nipkow@23482
  1578
            add: order_less_imp_not_eq nonzero_inverse_minus_eq)
nipkow@23482
  1579
done
paulson@14268
  1580
paulson@14268
  1581
lemma le_imp_inverse_le_neg:
nipkow@23482
  1582
  "[|a \<le> b; b < 0|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
nipkow@23482
  1583
by (force simp add: order_le_less less_imp_inverse_less_neg)
paulson@14268
  1584
paulson@24286
  1585
lemma inverse_le_iff_le_neg [simp,noatp]:
nipkow@23482
  1586
 "[|a < 0; b < 0|] ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1587
by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
paulson@14265
  1588
paulson@14277
  1589
paulson@14365
  1590
subsection{*Inverses and the Number One*}
paulson@14365
  1591
paulson@14365
  1592
lemma one_less_inverse_iff:
nipkow@23482
  1593
  "(1 < inverse x) = (0 < x & x < (1::'a::{ordered_field,division_by_zero}))"
nipkow@23482
  1594
proof cases
paulson@14365
  1595
  assume "0 < x"
paulson@14365
  1596
    with inverse_less_iff_less [OF zero_less_one, of x]
paulson@14365
  1597
    show ?thesis by simp
paulson@14365
  1598
next
paulson@14365
  1599
  assume notless: "~ (0 < x)"
paulson@14365
  1600
  have "~ (1 < inverse x)"
paulson@14365
  1601
  proof
paulson@14365
  1602
    assume "1 < inverse x"
paulson@14365
  1603
    also with notless have "... \<le> 0" by (simp add: linorder_not_less)
paulson@14365
  1604
    also have "... < 1" by (rule zero_less_one) 
paulson@14365
  1605
    finally show False by auto
paulson@14365
  1606
  qed
paulson@14365
  1607
  with notless show ?thesis by simp
paulson@14365
  1608
qed
paulson@14365
  1609
paulson@14365
  1610
lemma inverse_eq_1_iff [simp]:
nipkow@23482
  1611
  "(inverse x = 1) = (x = (1::'a::{field,division_by_zero}))"
paulson@14365
  1612
by (insert inverse_eq_iff_eq [of x 1], simp) 
paulson@14365
  1613
paulson@14365
  1614
lemma one_le_inverse_iff:
nipkow@23482
  1615
  "(1 \<le> inverse x) = (0 < x & x \<le> (1::'a::{ordered_field,division_by_zero}))"
paulson@14365
  1616
by (force simp add: order_le_less one_less_inverse_iff zero_less_one 
paulson@14365
  1617
                    eq_commute [of 1]) 
paulson@14365
  1618
paulson@14365
  1619
lemma inverse_less_1_iff:
nipkow@23482
  1620
  "(inverse x < 1) = (x \<le> 0 | 1 < (x::'a::{ordered_field,division_by_zero}))"
paulson@14365
  1621
by (simp add: linorder_not_le [symmetric] one_le_inverse_iff) 
paulson@14365
  1622
paulson@14365
  1623
lemma inverse_le_1_iff:
nipkow@23482
  1624
  "(inverse x \<le> 1) = (x \<le> 0 | 1 \<le> (x::'a::{ordered_field,division_by_zero}))"
paulson@14365
  1625
by (simp add: linorder_not_less [symmetric] one_less_inverse_iff) 
paulson@14365
  1626
wenzelm@23389
  1627
paulson@14288
  1628
subsection{*Simplification of Inequalities Involving Literal Divisors*}
paulson@14288
  1629
paulson@14288
  1630
lemma pos_le_divide_eq: "0 < (c::'a::ordered_field) ==> (a \<le> b/c) = (a*c \<le> b)"
paulson@14288
  1631
proof -
paulson@14288
  1632
  assume less: "0<c"
paulson@14288
  1633
  hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
paulson@14288
  1634
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1635
  also have "... = (a*c \<le> b)"
paulson@14288
  1636
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1637
  finally show ?thesis .
paulson@14288
  1638
qed
paulson@14288
  1639
paulson@14288
  1640
lemma neg_le_divide_eq: "c < (0::'a::ordered_field) ==> (a \<le> b/c) = (b \<le> a*c)"
paulson@14288
  1641
proof -
paulson@14288
  1642
  assume less: "c<0"
paulson@14288
  1643
  hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
paulson@14288
  1644
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1645
  also have "... = (b \<le> a*c)"
paulson@14288
  1646
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1647
  finally show ?thesis .
paulson@14288
  1648
qed
paulson@14288
  1649
paulson@14288
  1650
lemma le_divide_eq:
paulson@14288
  1651
  "(a \<le> b/c) = 
paulson@14288
  1652
   (if 0 < c then a*c \<le> b
paulson@14288
  1653
             else if c < 0 then b \<le> a*c
paulson@14288
  1654
             else  a \<le> (0::'a::{ordered_field,division_by_zero}))"
haftmann@21328
  1655
apply (cases "c=0", simp) 
paulson@14288
  1656
apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
paulson@14288
  1657
done
paulson@14288
  1658
paulson@14288
  1659
lemma pos_divide_le_eq: "0 < (c::'a::ordered_field) ==> (b/c \<le> a) = (b \<le> a*c)"
paulson@14288
  1660
proof -
paulson@14288
  1661
  assume less: "0<c"
paulson@14288
  1662
  hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
paulson@14288
  1663
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1664
  also have "... = (b \<le> a*c)"
paulson@14288
  1665
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1666
  finally show ?thesis .
paulson@14288
  1667
qed
paulson@14288
  1668
paulson@14288
  1669
lemma neg_divide_le_eq: "c < (0::'a::ordered_field) ==> (b/c \<le> a) = (a*c \<le> b)"
paulson@14288
  1670
proof -
paulson@14288
  1671
  assume less: "c<0"
paulson@14288
  1672
  hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
paulson@14288
  1673
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1674
  also have "... = (a*c \<le> b)"
paulson@14288
  1675
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1676
  finally show ?thesis .
paulson@14288
  1677
qed
paulson@14288
  1678
paulson@14288
  1679
lemma divide_le_eq:
paulson@14288
  1680
  "(b/c \<le> a) = 
paulson@14288
  1681
   (if 0 < c then b \<le> a*c
paulson@14288
  1682
             else if c < 0 then a*c \<le> b
paulson@14288
  1683
             else 0 \<le> (a::'a::{ordered_field,division_by_zero}))"
haftmann@21328
  1684
apply (cases "c=0", simp) 
paulson@14288
  1685
apply (force simp add: pos_divide_le_eq neg_divide_le_eq linorder_neq_iff) 
paulson@14288
  1686
done
paulson@14288
  1687
paulson@14288
  1688
lemma pos_less_divide_eq:
paulson@14288
  1689
     "0 < (c::'a::ordered_field) ==> (a < b/c) = (a*c < b)"
paulson@14288
  1690
proof -
paulson@14288
  1691
  assume less: "0<c"
paulson@14288
  1692
  hence "(a < b/c) = (a*c < (b/c)*c)"
paulson@15234
  1693
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
  1694
  also have "... = (a*c < b)"
paulson@14288
  1695
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1696
  finally show ?thesis .
paulson@14288
  1697
qed
paulson@14288
  1698
paulson@14288
  1699
lemma neg_less_divide_eq:
paulson@14288
  1700
 "c < (0::'a::ordered_field) ==> (a < b/c) = (b < a*c)"
paulson@14288
  1701
proof -
paulson@14288
  1702
  assume less: "c<0"
paulson@14288
  1703
  hence "(a < b/c) = ((b/c)*c < a*c)"
paulson@15234
  1704
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
  1705
  also have "... = (b < a*c)"
paulson@14288
  1706
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1707
  finally show ?thesis .
paulson@14288
  1708
qed
paulson@14288
  1709
paulson@14288
  1710
lemma less_divide_eq:
paulson@14288
  1711
  "(a < b/c) = 
paulson@14288
  1712
   (if 0 < c then a*c < b
paulson@14288
  1713
             else if c < 0 then b < a*c
paulson@14288
  1714
             else  a < (0::'a::{ordered_field,division_by_zero}))"
haftmann@21328
  1715
apply (cases "c=0", simp) 
paulson@14288
  1716
apply (force simp add: pos_less_divide_eq neg_less_divide_eq linorder_neq_iff) 
paulson@14288
  1717
done
paulson@14288
  1718
paulson@14288
  1719
lemma pos_divide_less_eq:
paulson@14288
  1720
     "0 < (c::'a::ordered_field) ==> (b/c < a) = (b < a*c)"
paulson@14288
  1721
proof -
paulson@14288
  1722
  assume less: "0<c"
paulson@14288
  1723
  hence "(b/c < a) = ((b/c)*c < a*c)"
paulson@15234
  1724
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
  1725
  also have "... = (b < a*c)"
paulson@14288
  1726
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1727
  finally show ?thesis .
paulson@14288
  1728
qed
paulson@14288
  1729
paulson@14288
  1730
lemma neg_divide_less_eq:
paulson@14288
  1731
 "c < (0::'a::ordered_field) ==> (b/c < a) = (a*c < b)"
paulson@14288
  1732
proof -
paulson@14288
  1733
  assume less: "c<0"
paulson@14288
  1734
  hence "(b/c < a) = (a*c < (b/c)*c)"
paulson@15234
  1735
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
  1736
  also have "... = (a*c < b)"
paulson@14288
  1737
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1738
  finally show ?thesis .
paulson@14288
  1739
qed
paulson@14288
  1740
paulson@14288
  1741
lemma divide_less_eq:
paulson@14288
  1742
  "(b/c < a) = 
paulson@14288
  1743
   (if 0 < c then b < a*c
paulson@14288
  1744
             else if c < 0 then a*c < b
paulson@14288
  1745
             else 0 < (a::'a::{ordered_field,division_by_zero}))"
haftmann@21328
  1746
apply (cases "c=0", simp) 
paulson@14288
  1747
apply (force simp add: pos_divide_less_eq neg_divide_less_eq linorder_neq_iff) 
paulson@14288
  1748
done
paulson@14288
  1749
nipkow@23482
  1750
nipkow@23482
  1751
subsection{*Field simplification*}
nipkow@23482
  1752
nipkow@29667
  1753
text{* Lemmas @{text field_simps} multiply with denominators in in(equations)
nipkow@29667
  1754
if they can be proved to be non-zero (for equations) or positive/negative
nipkow@29667
  1755
(for inequations). Can be too aggressive and is therefore separate from the
nipkow@29667
  1756
more benign @{text algebra_simps}. *}
paulson@14288
  1757
nipkow@29833
  1758
lemmas field_simps[noatp] = field_eq_simps
nipkow@23482
  1759
  (* multiply ineqn *)
nipkow@23482
  1760
  pos_divide_less_eq neg_divide_less_eq
nipkow@23482
  1761
  pos_less_divide_eq neg_less_divide_eq
nipkow@23482
  1762
  pos_divide_le_eq neg_divide_le_eq
nipkow@23482
  1763
  pos_le_divide_eq neg_le_divide_eq
paulson@14288
  1764
nipkow@23482
  1765
text{* Lemmas @{text sign_simps} is a first attempt to automate proofs
nipkow@23483
  1766
of positivity/negativity needed for @{text field_simps}. Have not added @{text
nipkow@23482
  1767
sign_simps} to @{text field_simps} because the former can lead to case
nipkow@23482
  1768
explosions. *}
paulson@14288
  1769
nipkow@29833
  1770
lemmas sign_simps[noatp] = group_simps
nipkow@23482
  1771
  zero_less_mult_iff  mult_less_0_iff
paulson@14288
  1772
nipkow@23482
  1773
(* Only works once linear arithmetic is installed:
nipkow@23482
  1774
text{*An example:*}
nipkow@23482
  1775
lemma fixes a b c d e f :: "'a::ordered_field"
nipkow@23482
  1776
shows "\<lbrakk>a>b; c<d; e<f; 0 < u \<rbrakk> \<Longrightarrow>
nipkow@23482
  1777
 ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) <
nipkow@23482
  1778
 ((e-f)*(a-b)*(c-d))/((e-f)*(a-b)*(c-d)) + u"
nipkow@23482
  1779
apply(subgoal_tac "(c-d)*(e-f)*(a-b) > 0")
nipkow@23482
  1780
 prefer 2 apply(simp add:sign_simps)
nipkow@23482
  1781
apply(subgoal_tac "(c-d)*(e-f)*(a-b)*u > 0")
nipkow@23482
  1782
 prefer 2 apply(simp add:sign_simps)
nipkow@23482
  1783
apply(simp add:field_simps)
avigad@16775
  1784
done
nipkow@23482
  1785
*)
avigad@16775
  1786
wenzelm@23389
  1787
avigad@16775
  1788
subsection{*Division and Signs*}
avigad@16775
  1789
avigad@16775
  1790
lemma zero_less_divide_iff:
avigad@16775
  1791
     "((0::'a::{ordered_field,division_by_zero}) < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
avigad@16775
  1792
by (simp add: divide_inverse zero_less_mult_iff)
avigad@16775
  1793
avigad@16775
  1794
lemma divide_less_0_iff:
avigad@16775
  1795
     "(a/b < (0::'a::{ordered_field,division_by_zero})) = 
avigad@16775
  1796
      (0 < a & b < 0 | a < 0 & 0 < b)"
avigad@16775
  1797
by (simp add: divide_inverse mult_less_0_iff)
avigad@16775
  1798
avigad@16775
  1799
lemma zero_le_divide_iff:
avigad@16775
  1800
     "((0::'a::{ordered_field,division_by_zero}) \<le> a/b) =
avigad@16775
  1801
      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
avigad@16775
  1802
by (simp add: divide_inverse zero_le_mult_iff)
avigad@16775
  1803
avigad@16775
  1804
lemma divide_le_0_iff:
avigad@16775
  1805
     "(a/b \<le> (0::'a::{ordered_field,division_by_zero})) =
avigad@16775
  1806
      (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
avigad@16775
  1807
by (simp add: divide_inverse mult_le_0_iff)
avigad@16775
  1808
paulson@24286
  1809
lemma divide_eq_0_iff [simp,noatp]:
avigad@16775
  1810
     "(a/b = 0) = (a=0 | b=(0::'a::{field,division_by_zero}))"
nipkow@23482
  1811
by (simp add: divide_inverse)
avigad@16775
  1812
nipkow@23482
  1813
lemma divide_pos_pos:
nipkow@23482
  1814
  "0 < (x::'a::ordered_field) ==> 0 < y ==> 0 < x / y"
nipkow@23482
  1815
by(simp add:field_simps)
nipkow@23482
  1816
avigad@16775
  1817
nipkow@23482
  1818
lemma divide_nonneg_pos:
nipkow@23482
  1819
  "0 <= (x::'a::ordered_field) ==> 0 < y ==> 0 <= x / y"
nipkow@23482
  1820
by(simp add:field_simps)
avigad@16775
  1821
nipkow@23482
  1822
lemma divide_neg_pos:
nipkow@23482
  1823
  "(x::'a::ordered_field) < 0 ==> 0 < y ==> x / y < 0"
nipkow@23482
  1824
by(simp add:field_simps)
avigad@16775
  1825
nipkow@23482
  1826
lemma divide_nonpos_pos:
nipkow@23482
  1827
  "(x::'a::ordered_field) <= 0 ==> 0 < y ==> x / y <= 0"
nipkow@23482
  1828
by(simp add:field_simps)
avigad@16775
  1829
nipkow@23482
  1830
lemma divide_pos_neg:
nipkow@23482
  1831
  "0 < (x::'a::ordered_field) ==> y < 0 ==> x / y < 0"
nipkow@23482
  1832
by(simp add:field_simps)
avigad@16775
  1833
nipkow@23482
  1834
lemma divide_nonneg_neg:
nipkow@23482
  1835
  "0 <= (x::'a::ordered_field) ==> y < 0 ==> x / y <= 0" 
nipkow@23482
  1836
by(simp add:field_simps)
avigad@16775
  1837
nipkow@23482
  1838
lemma divide_neg_neg:
nipkow@23482
  1839
  "(x::'a::ordered_field) < 0 ==> y < 0 ==> 0 < x / y"
nipkow@23482
  1840
by(simp add:field_simps)
avigad@16775
  1841
nipkow@23482
  1842
lemma divide_nonpos_neg:
nipkow@23482
  1843
  "(x::'a::ordered_field) <= 0 ==> y < 0 ==> 0 <= x / y"
nipkow@23482
  1844
by(simp add:field_simps)
paulson@15234
  1845
wenzelm@23389
  1846
paulson@14288
  1847
subsection{*Cancellation Laws for Division*}
paulson@14288
  1848
paulson@24286
  1849
lemma divide_cancel_right [simp,noatp]:
paulson@14288
  1850
     "(a/c = b/c) = (c = 0 | a = (b::'a::{field,division_by_zero}))"
nipkow@23482
  1851
apply (cases "c=0", simp)
nipkow@23496
  1852
apply (simp add: divide_inverse)
paulson@14288
  1853
done
paulson@14288
  1854
paulson@24286
  1855
lemma divide_cancel_left [simp,noatp]:
paulson@14288
  1856
     "(c/a = c/b) = (c = 0 | a = (b::'a::{field,division_by_zero}))" 
nipkow@23482
  1857
apply (cases "c=0", simp)
nipkow@23496
  1858
apply (simp add: divide_inverse)
paulson@14288
  1859
done
paulson@14288
  1860
wenzelm@23389
  1861
paulson@14353
  1862
subsection {* Division and the Number One *}
paulson@14353
  1863
paulson@14353
  1864
text{*Simplify expressions equated with 1*}
paulson@24286
  1865
lemma divide_eq_1_iff [simp,noatp]:
paulson@14353
  1866
     "(a/b = 1) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
nipkow@23482
  1867
apply (cases "b=0", simp)
nipkow@23482
  1868
apply (simp add: right_inverse_eq)
paulson@14353
  1869
done
paulson@14353
  1870
paulson@24286
  1871
lemma one_eq_divide_iff [simp,noatp]:
paulson@14353
  1872
     "(1 = a/b) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
nipkow@23482
  1873
by (simp add: eq_commute [of 1])
paulson@14353
  1874
paulson@24286
  1875
lemma zero_eq_1_divide_iff [simp,noatp]:
paulson@14353
  1876
     "((0::'a::{ordered_field,division_by_zero}) = 1/a) = (a = 0)"
nipkow@23482
  1877
apply (cases "a=0", simp)
nipkow@23482
  1878
apply (auto simp add: nonzero_eq_divide_eq)
paulson@14353
  1879
done
paulson@14353
  1880
paulson@24286
  1881
lemma one_divide_eq_0_iff [simp,noatp]:
paulson@14353
  1882
     "(1/a = (0::'a::{ordered_field,division_by_zero})) = (a = 0)"
nipkow@23482
  1883
apply (cases "a=0", simp)
nipkow@23482
  1884
apply (insert zero_neq_one [THEN not_sym])
nipkow@23482
  1885
apply (auto simp add: nonzero_divide_eq_eq)
paulson@14353
  1886
done
paulson@14353
  1887
paulson@14353
  1888
text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
paulson@18623
  1889
lemmas zero_less_divide_1_iff = zero_less_divide_iff [of 1, simplified]
paulson@18623
  1890
lemmas divide_less_0_1_iff = divide_less_0_iff [of 1, simplified]
paulson@18623
  1891
lemmas zero_le_divide_1_iff = zero_le_divide_iff [of 1, simplified]
paulson@18623
  1892
lemmas divide_le_0_1_iff = divide_le_0_iff [of 1, simplified]
paulson@17085
  1893
nipkow@29833
  1894
declare zero_less_divide_1_iff [simp,noatp]
paulson@24286
  1895
declare divide_less_0_1_iff [simp,noatp]
nipkow@29833
  1896
declare zero_le_divide_1_iff [simp,noatp]
paulson@24286
  1897
declare divide_le_0_1_iff [simp,noatp]
paulson@14353
  1898
wenzelm@23389
  1899
paulson@14293
  1900
subsection {* Ordering Rules for Division *}
paulson@14293
  1901
paulson@14293
  1902
lemma divide_strict_right_mono:
paulson@14293
  1903
     "[|a < b; 0 < c|] ==> a / c < b / (c::'a::ordered_field)"
paulson@14293
  1904
by (simp add: order_less_imp_not_eq2 divide_inverse mult_strict_right_mono 
nipkow@23482
  1905
              positive_imp_inverse_positive)
paulson@14293
  1906
paulson@14293
  1907
lemma divide_right_mono:
paulson@14293
  1908
     "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/(c::'a::{ordered_field,division_by_zero})"
nipkow@23482
  1909
by (force simp add: divide_strict_right_mono order_le_less)
paulson@14293
  1910
avigad@16775
  1911
lemma divide_right_mono_neg: "(a::'a::{division_by_zero,ordered_field}) <= b 
avigad@16775
  1912
    ==> c <= 0 ==> b / c <= a / c"
nipkow@23482
  1913
apply (drule divide_right_mono [of _ _ "- c"])
nipkow@23482
  1914
apply auto
avigad@16775
  1915
done
avigad@16775
  1916
avigad@16775
  1917
lemma divide_strict_right_mono_neg:
avigad@16775
  1918
     "[|b < a; c < 0|] ==> a / c < b / (c::'a::ordered_field)"
nipkow@23482
  1919
apply (drule divide_strict_right_mono [of _ _ "-c"], simp)
nipkow@23482
  1920
apply (simp add: order_less_imp_not_eq nonzero_minus_divide_right [symmetric])
avigad@16775
  1921
done
paulson@14293
  1922
paulson@14293
  1923
text{*The last premise ensures that @{term a} and @{term b} 
paulson@14293
  1924
      have the same sign*}
paulson@14293
  1925
lemma divide_strict_left_mono:
nipkow@23482
  1926
  "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / (b::'a::ordered_field)"
nipkow@23482
  1927
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono)
paulson@14293
  1928
paulson@14293
  1929
lemma divide_left_mono:
nipkow@23482
  1930
  "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / (b::'a::ordered_field)"
nipkow@23482
  1931
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_right_mono)
paulson@14293
  1932
avigad@16775
  1933
lemma divide_left_mono_neg: "(a::'a::{division_by_zero,ordered_field}) <= b 
avigad@16775
  1934
    ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
avigad@16775
  1935
  apply (drule divide_left_mono [of _ _ "- c"])
avigad@16775
  1936
  apply (auto simp add: mult_commute)
avigad@16775
  1937
done
avigad@16775
  1938
paulson@14293
  1939
lemma divide_strict_left_mono_neg:
nipkow@23482
  1940
  "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / (b::'a::ordered_field)"
nipkow@23482
  1941
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono_neg)
nipkow@23482
  1942
paulson@14293
  1943
avigad@16775
  1944
text{*Simplify quotients that are compared with the value 1.*}
avigad@16775
  1945
paulson@24286
  1946
lemma le_divide_eq_1 [noatp]:
avigad@16775
  1947
  fixes a :: "'a :: {ordered_field,division_by_zero}"
avigad@16775
  1948
  shows "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
avigad@16775
  1949
by (auto simp add: le_divide_eq)
avigad@16775
  1950
paulson@24286
  1951
lemma divide_le_eq_1 [noatp]:
avigad@16775
  1952
  fixes a :: "'a :: {ordered_field,division_by_zero}"
avigad@16775
  1953
  shows "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
avigad@16775
  1954
by (auto simp add: divide_le_eq)
avigad@16775
  1955
paulson@24286
  1956
lemma less_divide_eq_1 [noatp]:
avigad@16775
  1957
  fixes a :: "'a :: {ordered_field,division_by_zero}"
avigad@16775
  1958
  shows "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
avigad@16775
  1959
by (auto simp add: less_divide_eq)
avigad@16775
  1960
paulson@24286
  1961
lemma divide_less_eq_1 [noatp]:
avigad@16775
  1962
  fixes a :: "'a :: {ordered_field,division_by_zero}"
avigad@16775
  1963
  shows "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
avigad@16775
  1964
by (auto simp add: divide_less_eq)
avigad@16775
  1965
wenzelm@23389
  1966
avigad@16775
  1967
subsection{*Conditional Simplification Rules: No Case Splits*}
avigad@16775
  1968
paulson@24286
  1969
lemma le_divide_eq_1_pos [simp,noatp]:
avigad@16775
  1970
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1971
  shows "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
avigad@16775
  1972
by (auto simp add: le_divide_eq)
avigad@16775
  1973
paulson@24286
  1974
lemma le_divide_eq_1_neg [simp,noatp]:
avigad@16775
  1975
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1976
  shows "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
avigad@16775
  1977
by (auto simp add: le_divide_eq)
avigad@16775
  1978
paulson@24286
  1979
lemma divide_le_eq_1_pos [simp,noatp]:
avigad@16775
  1980
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1981
  shows "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
avigad@16775
  1982
by (auto simp add: divide_le_eq)
avigad@16775
  1983
paulson@24286
  1984
lemma divide_le_eq_1_neg [simp,noatp]:
avigad@16775
  1985
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1986
  shows "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
avigad@16775
  1987
by (auto simp add: divide_le_eq)
avigad@16775
  1988
paulson@24286
  1989
lemma less_divide_eq_1_pos [simp,noatp]:
avigad@16775
  1990
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1991
  shows "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
avigad@16775
  1992
by (auto simp add: less_divide_eq)
avigad@16775
  1993
paulson@24286
  1994
lemma less_divide_eq_1_neg [simp,noatp]:
avigad@16775
  1995
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  1996
  shows "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
avigad@16775
  1997
by (auto simp add: less_divide_eq)
avigad@16775
  1998
paulson@24286
  1999
lemma divide_less_eq_1_pos [simp,noatp]:
avigad@16775
  2000
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  2001
  shows "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
paulson@18649
  2002
by (auto simp add: divide_less_eq)
paulson@18649
  2003
paulson@24286
  2004
lemma divide_less_eq_1_neg [simp,noatp]:
paulson@18649
  2005
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  2006
  shows "a < 0 \<Longrightarrow> b/a < 1 <-> a < b"
avigad@16775
  2007
by (auto simp add: divide_less_eq)
avigad@16775
  2008
paulson@24286
  2009
lemma eq_divide_eq_1 [simp,noatp]:
avigad@16775
  2010
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  2011
  shows "(1 = b/a) = ((a \<noteq> 0 & a = b))"
avigad@16775
  2012
by (auto simp add: eq_divide_eq)
avigad@16775
  2013
paulson@24286
  2014
lemma divide_eq_eq_1 [simp,noatp]:
avigad@16775
  2015
  fixes a :: "'a :: {ordered_field,division_by_zero}"
paulson@18649
  2016
  shows "(b/a = 1) = ((a \<noteq> 0 & a = b))"
avigad@16775
  2017
by (auto simp add: divide_eq_eq)
avigad@16775
  2018
wenzelm@23389
  2019
avigad@16775
  2020
subsection {* Reasoning about inequalities with division *}
avigad@16775
  2021
avigad@16775
  2022
lemma mult_right_le_one_le: "0 <= (x::'a::ordered_idom) ==> 0 <= y ==> y <= 1
avigad@16775
  2023
    ==> x * y <= x"
nipkow@29667
  2024
by (auto simp add: mult_compare_simps);
avigad@16775
  2025
avigad@16775
  2026
lemma mult_left_le_one_le: "0 <= (x::'a::ordered_idom) ==> 0 <= y ==> y <= 1
avigad@16775
  2027
    ==> y * x <= x"
nipkow@29667
  2028
by (auto simp add: mult_compare_simps);
avigad@16775
  2029
avigad@16775
  2030
lemma mult_imp_div_pos_le: "0 < (y::'a::ordered_field) ==> x <= z * y ==>
avigad@16775
  2031
    x / y <= z";
nipkow@29667
  2032
by (subst pos_divide_le_eq, assumption+);
avigad@16775
  2033
avigad@16775
  2034
lemma mult_imp_le_div_pos: "0 < (y::'a::ordered_field) ==> z * y <= x ==>
nipkow@23482
  2035
    z <= x / y"
nipkow@23482
  2036
by(simp add:field_simps)
avigad@16775
  2037
avigad@16775
  2038
lemma mult_imp_div_pos_less: "0 < (y::'a::ordered_field) ==> x < z * y ==>
avigad@16775
  2039
    x / y < z"
nipkow@23482
  2040
by(simp add:field_simps)
avigad@16775
  2041
avigad@16775
  2042
lemma mult_imp_less_div_pos: "0 < (y::'a::ordered_field) ==> z * y < x ==>
avigad@16775
  2043
    z < x / y"
nipkow@23482
  2044
by(simp add:field_simps)
avigad@16775
  2045
avigad@16775
  2046
lemma frac_le: "(0::'a::ordered_field) <= x ==> 
avigad@16775
  2047
    x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
avigad@16775
  2048
  apply (rule mult_imp_div_pos_le)
haftmann@25230
  2049
  apply simp
haftmann@25230
  2050
  apply (subst times_divide_eq_left)
avigad@16775
  2051
  apply (rule mult_imp_le_div_pos, assumption)
avigad@16775
  2052
  apply (rule mult_mono)
avigad@16775
  2053
  apply simp_all
paulson@14293
  2054
done
paulson@14293
  2055
avigad@16775
  2056
lemma frac_less: "(0::'a::ordered_field) <= x ==> 
avigad@16775
  2057
    x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
avigad@16775
  2058
  apply (rule mult_imp_div_pos_less)
avigad@16775
  2059
  apply simp;
avigad@16775
  2060
  apply (subst times_divide_eq_left);
avigad@16775
  2061
  apply (rule mult_imp_less_div_pos, assumption)
avigad@16775
  2062
  apply (erule mult_less_le_imp_less)
avigad@16775
  2063
  apply simp_all
avigad@16775
  2064
done
avigad@16775
  2065
avigad@16775
  2066
lemma frac_less2: "(0::'a::ordered_field) < x ==> 
avigad@16775
  2067
    x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
avigad@16775
  2068
  apply (rule mult_imp_div_pos_less)
avigad@16775
  2069
  apply simp_all
avigad@16775
  2070
  apply (subst times_divide_eq_left);
avigad@16775
  2071
  apply (rule mult_imp_less_div_pos, assumption)
avigad@16775
  2072
  apply (erule mult_le_less_imp_less)
avigad@16775
  2073
  apply simp_all
avigad@16775
  2074
done
avigad@16775
  2075
avigad@16775
  2076
text{*It's not obvious whether these should be simprules or not. 
avigad@16775
  2077
  Their effect is to gather terms into one big fraction, like
avigad@16775
  2078
  a*b*c / x*y*z. The rationale for that is unclear, but many proofs 
avigad@16775
  2079
  seem to need them.*}
avigad@16775
  2080
avigad@16775
  2081
declare times_divide_eq [simp]
paulson@14293
  2082
wenzelm@23389
  2083
paulson@14293
  2084
subsection {* Ordered Fields are Dense *}
paulson@14293
  2085
haftmann@25193
  2086
context ordered_semidom
haftmann@25193
  2087
begin
haftmann@25193
  2088
haftmann@25193
  2089
lemma less_add_one: "a < a + 1"
paulson@14293
  2090
proof -
haftmann@25193
  2091
  have "a + 0 < a + 1"
nipkow@23482
  2092
    by (blast intro: zero_less_one add_strict_left_mono)
paulson@14293
  2093
  thus ?thesis by simp
paulson@14293
  2094
qed
paulson@14293
  2095
haftmann@25193
  2096
lemma zero_less_two: "0 < 1 + 1"
nipkow@29667
  2097
by (blast intro: less_trans zero_less_one less_add_one)
haftmann@25193
  2098
haftmann@25193
  2099
end
paulson@14365
  2100
paulson@14293
  2101
lemma less_half_sum: "a < b ==> a < (a+b) / (1+1::'a::ordered_field)"
nipkow@23482
  2102
by (simp add: field_simps zero_less_two)
paulson@14293
  2103
paulson@14293
  2104
lemma gt_half_sum: "a < b ==> (a+b)/(1+1::'a::ordered_field) < b"
nipkow@23482
  2105
by (simp add: field_simps zero_less_two)
paulson@14293
  2106
haftmann@24422
  2107
instance ordered_field < dense_linear_order
haftmann@24422
  2108
proof
haftmann@24422
  2109
  fix x y :: 'a
haftmann@24422
  2110
  have "x < x + 1" by simp
haftmann@24422
  2111
  then show "\<exists>y. x < y" .. 
haftmann@24422
  2112
  have "x - 1 < x" by simp
haftmann@24422
  2113
  then show "\<exists>y. y < x" ..
haftmann@24422
  2114
  show "x < y \<Longrightarrow> \<exists>z>x. z < y" by (blast intro!: less_half_sum gt_half_sum)
haftmann@24422
  2115
qed
paulson@14293
  2116
paulson@15234
  2117
paulson@14293
  2118
subsection {* Absolute Value *}
paulson@14293
  2119
haftmann@25304
  2120
context ordered_idom
haftmann@25304
  2121
begin
haftmann@25304
  2122
haftmann@25304
  2123
lemma mult_sgn_abs: "sgn x * abs x = x"
haftmann@25304
  2124
  unfolding abs_if sgn_if by auto
haftmann@25304
  2125
haftmann@25304
  2126
end
nipkow@24491
  2127
obua@14738
  2128
lemma abs_one [simp]: "abs 1 = (1::'a::ordered_idom)"
nipkow@29667
  2129
by (simp add: abs_if zero_less_one [THEN order_less_not_sym])
haftmann@25304
  2130
haftmann@25304
  2131
class pordered_ring_abs = pordered_ring + pordered_ab_group_add_abs +
haftmann@25304
  2132
  assumes abs_eq_mult:
haftmann@25304
  2133
    "(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
  2134
haftmann@25304
  2135
haftmann@25304
  2136
class lordered_ring = pordered_ring + lordered_ab_group_add_abs
haftmann@25304
  2137
begin
haftmann@25304
  2138
huffman@27516
  2139
subclass lordered_ab_group_add_meet ..
huffman@27516
  2140
subclass lordered_ab_group_add_join ..
haftmann@25304
  2141
haftmann@25304
  2142
end
paulson@14294
  2143
obua@14738
  2144
lemma abs_le_mult: "abs (a * b) \<le> (abs a) * (abs (b::'a::lordered_ring))" 
obua@14738
  2145
proof -
obua@14738
  2146
  let ?x = "pprt a * pprt b - pprt a * nprt b - nprt a * pprt b + nprt a * nprt b"
obua@14738
  2147
  let ?y = "pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
obua@14738
  2148
  have a: "(abs a) * (abs b) = ?x"
nipkow@29667
  2149
    by (simp only: abs_prts[of a] abs_prts[of b] algebra_simps)
obua@14738
  2150
  {
obua@14738
  2151
    fix u v :: 'a
paulson@15481
  2152
    have bh: "\<lbrakk>u = a; v = b\<rbrakk> \<Longrightarrow> 
paulson@15481
  2153
              u * v = pprt a * pprt b + pprt a * nprt b + 
paulson@15481
  2154
                      nprt a * pprt b + nprt a * nprt b"
obua@14738
  2155
      apply (subst prts[of u], subst prts[of v])
nipkow@29667
  2156
      apply (simp add: algebra_simps) 
obua@14738
  2157
      done
obua@14738
  2158
  }
obua@14738
  2159
  note b = this[OF refl[of a] refl[of b]]
obua@14738
  2160
  note addm = add_mono[of "0::'a" _ "0::'a", simplified]
obua@14738
  2161
  note addm2 = add_mono[of _ "0::'a" _ "0::'a", simplified]
obua@14738
  2162
  have xy: "- ?x <= ?y"
obua@14754
  2163
    apply (simp)
obua@14754
  2164
    apply (rule_tac y="0::'a" in order_trans)
nipkow@16568
  2165
    apply (rule addm2)
avigad@16775
  2166
    apply (simp_all add: mult_nonneg_nonneg mult_nonpos_nonpos)
nipkow@16568
  2167
    apply (rule addm)
avigad@16775
  2168
    apply (simp_all add: mult_nonneg_nonneg mult_nonpos_nonpos)
obua@14754
  2169
    done
obua@14738
  2170
  have yx: "?y <= ?x"
nipkow@16568
  2171
    apply (simp add:diff_def)
obua@14754
  2172
    apply (rule_tac y=0 in order_trans)
avigad@16775
  2173
    apply (rule addm2, (simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)+)
avigad@16775
  2174
    apply (rule addm, (simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)+)
obua@14738
  2175
    done
obua@14738
  2176
  have i1: "a*b <= abs a * abs b" by (simp only: a b yx)
obua@14738
  2177
  have i2: "- (abs a * abs b) <= a*b" by (simp only: a b xy)
obua@14738
  2178
  show ?thesis
obua@14738
  2179
    apply (rule abs_leI)
obua@14738
  2180
    apply (simp add: i1)
obua@14738
  2181
    apply (simp add: i2[simplified minus_le_iff])
obua@14738
  2182
    done
obua@14738
  2183
qed
paulson@14294
  2184
haftmann@25304
  2185
instance lordered_ring \<subseteq> pordered_ring_abs
haftmann@25304
  2186
proof
haftmann@25304
  2187
  fix a b :: "'a\<Colon> lordered_ring"
haftmann@25304
  2188
  assume "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0)"
haftmann@25304
  2189
  show "abs (a*b) = abs a * abs b"
obua@14738
  2190
proof -
obua@14738
  2191
  have s: "(0 <= a*b) | (a*b <= 0)"
obua@14738
  2192
    apply (auto)    
obua@14738
  2193
    apply (rule_tac split_mult_pos_le)
obua@14738
  2194
    apply (rule_tac contrapos_np[of "a*b <= 0"])
obua@14738
  2195
    apply (simp)
obua@14738
  2196
    apply (rule_tac split_mult_neg_le)
obua@14738
  2197
    apply (insert prems)
obua@14738
  2198
    apply (blast)
obua@14738
  2199
    done
obua@14738
  2200
  have mulprts: "a * b = (pprt a + nprt a) * (pprt b + nprt b)"
obua@14738
  2201
    by (simp add: prts[symmetric])
obua@14738
  2202
  show ?thesis
obua@14738
  2203
  proof cases
obua@14738
  2204
    assume "0 <= a * b"
obua@14738
  2205
    then show ?thesis
obua@14738
  2206
      apply (simp_all add: mulprts abs_prts)
obua@14738
  2207
      apply (insert prems)
obua@14754
  2208
      apply (auto simp add: 
nipkow@29667
  2209
	algebra_simps 
haftmann@25078
  2210
	iffD1[OF zero_le_iff_zero_nprt] iffD1[OF le_zero_iff_zero_pprt]
haftmann@25078
  2211
	iffD1[OF le_zero_iff_pprt_id] iffD1[OF zero_le_iff_nprt_id])
avigad@16775
  2212
	apply(drule (1) mult_nonneg_nonpos[of a b], simp)
avigad@16775
  2213
	apply(drule (1) mult_nonneg_nonpos2[of b a], simp)
obua@14738
  2214
      done
obua@14738
  2215
  next
obua@14738
  2216
    assume "~(0 <= a*b)"
obua@14738
  2217
    with s have "a*b <= 0" by simp
obua@14738
  2218
    then show ?thesis
obua@14738
  2219
      apply (simp_all add: mulprts abs_prts)
obua@14738
  2220
      apply (insert prems)
nipkow@29667
  2221
      apply (auto simp add: algebra_simps)
avigad@16775
  2222
      apply(drule (1) mult_nonneg_nonneg[of a b],simp)
avigad@16775
  2223
      apply(drule (1) mult_nonpos_nonpos[of a b],simp)
obua@14738
  2224
      done
obua@14738
  2225
  qed
obua@14738
  2226
qed
haftmann@25304
  2227
qed
haftmann@25304
  2228
haftmann@30961
  2229
context ordered_idom
haftmann@30961
  2230
begin
haftmann@30961
  2231
haftmann@30961
  2232
subclass pordered_ring_abs proof
haftmann@30961
  2233
qed (auto simp add: abs_if not_less equal_neg_zero neg_equal_zero mult_less_0_iff)
haftmann@30961
  2234
haftmann@30961
  2235
lemma abs_mult:
haftmann@30961
  2236
  "abs (a * b) = abs a * abs b" 
haftmann@30961
  2237
  by (rule abs_eq_mult) auto
haftmann@30961
  2238
haftmann@30961
  2239
lemma abs_mult_self:
haftmann@30961
  2240
  "abs a * abs a = a * a"
haftmann@30961
  2241
  by (simp add: abs_if) 
haftmann@30961
  2242
haftmann@30961
  2243
end
paulson@14294
  2244
paulson@14294
  2245
lemma nonzero_abs_inverse:
paulson@14294
  2246
     "a \<noteq> 0 ==> abs (inverse (a::'a::ordered_field)) = inverse (abs a)"
paulson@14294
  2247
apply (auto simp add: linorder_neq_iff abs_if nonzero_inverse_minus_eq 
paulson@14294
  2248
                      negative_imp_inverse_negative)
paulson@14294
  2249
apply (blast intro: positive_imp_inverse_positive elim: order_less_asym) 
paulson@14294
  2250
done
paulson@14294
  2251
paulson@14294
  2252
lemma abs_inverse [simp]:
paulson@14294
  2253
     "abs (inverse (a::'a::{ordered_field,division_by_zero})) = 
paulson@14294
  2254
      inverse (abs a)"
haftmann@21328
  2255
apply (cases "a=0", simp) 
paulson@14294
  2256
apply (simp add: nonzero_abs_inverse) 
paulson@14294
  2257
done
paulson@14294
  2258
paulson@14294
  2259
lemma nonzero_abs_divide:
paulson@14294
  2260
     "b \<noteq> 0 ==> abs (a / (b::'a::ordered_field)) = abs a / abs b"
paulson@14294
  2261
by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
paulson@14294
  2262
paulson@15234
  2263
lemma abs_divide [simp]:
paulson@14294
  2264
     "abs (a / (b::'a::{ordered_field,division_by_zero})) = abs a / abs b"
haftmann@21328
  2265
apply (cases "b=0", simp) 
paulson@14294
  2266
apply (simp add: nonzero_abs_divide) 
paulson@14294
  2267
done
paulson@14294
  2268
paulson@14294
  2269
lemma abs_mult_less:
obua@14738
  2270
     "[| abs a < c; abs b < d |] ==> abs a * abs b < c*(d::'a::ordered_idom)"
paulson@14294
  2271
proof -
paulson@14294
  2272
  assume ac: "abs a < c"
paulson@14294
  2273
  hence cpos: "0<c" by (blast intro: order_le_less_trans abs_ge_zero)
paulson@14294
  2274
  assume "abs b < d"
paulson@14294
  2275
  thus ?thesis by (simp add: ac cpos mult_strict_mono) 
paulson@14294
  2276
qed
paulson@14293
  2277
nipkow@29833
  2278
lemmas eq_minus_self_iff[noatp] = equal_neg_zero
obua@14738
  2279
obua@14738
  2280
lemma less_minus_self_iff: "(a < -a) = (a < (0::'a::ordered_idom))"
haftmann@25304
  2281
  unfolding order_less_le less_eq_neg_nonpos equal_neg_zero ..
obua@14738
  2282
obua@14738
  2283
lemma abs_less_iff: "(abs a < b) = (a < b & -a < (b::'a::ordered_idom))" 
obua@14738
  2284
apply (simp add: order_less_le abs_le_iff)  
haftmann@25304
  2285
apply (auto simp add: abs_if neg_less_eq_nonneg less_eq_neg_nonpos)
obua@14738
  2286
done
obua@14738
  2287
avigad@16775
  2288
lemma abs_mult_pos: "(0::'a::ordered_idom) <= x ==> 
haftmann@25304
  2289
    (abs y) * x = abs (y * x)"
haftmann@25304
  2290
  apply (subst abs_mult)
haftmann@25304
  2291
  apply simp
haftmann@25304
  2292
done
avigad@16775
  2293
avigad@16775
  2294
lemma abs_div_pos: "(0::'a::{division_by_zero,ordered_field}) < y ==> 
haftmann@25304
  2295
    abs x / y = abs (x / y)"
haftmann@25304
  2296
  apply (subst abs_divide)
haftmann@25304
  2297
  apply (simp add: order_less_imp_le)
haftmann@25304
  2298
done
avigad@16775
  2299
wenzelm@23389
  2300
obua@19404
  2301
subsection {* Bounds of products via negative and positive Part *}
obua@15178
  2302
obua@15580
  2303
lemma mult_le_prts:
obua@15580
  2304
  assumes
obua@15580
  2305
  "a1 <= (a::'a::lordered_ring)"
obua@15580
  2306
  "a <= a2"
obua@15580
  2307
  "b1 <= b"
obua@15580
  2308
  "b <= b2"
obua@15580
  2309
  shows
obua@15580
  2310
  "a * b <= pprt a2 * pprt b2 + pprt a1 * nprt b2 + nprt a2 * pprt b1 + nprt a1 * nprt b1"
obua@15580
  2311
proof - 
obua@15580
  2312
  have "a * b = (pprt a + nprt a) * (pprt b + nprt b)" 
obua@15580
  2313
    apply (subst prts[symmetric])+
obua@15580
  2314
    apply simp
obua@15580
  2315
    done
obua@15580
  2316
  then have "a * b = pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
nipkow@29667
  2317
    by (simp add: algebra_simps)
obua@15580
  2318
  moreover have "pprt a * pprt b <= pprt a2 * pprt b2"
obua@15580
  2319
    by (simp_all add: prems mult_mono)
obua@15580
  2320
  moreover have "pprt a * nprt b <= pprt a1 * nprt b2"
obua@15580
  2321
  proof -
obua@15580
  2322
    have "pprt a * nprt b <= pprt a * nprt b2"
obua@15580
  2323
      by (simp add: mult_left_mono prems)
obua@15580
  2324
    moreover have "pprt a * nprt b2 <= pprt a1 * nprt b2"
obua@15580
  2325
      by (simp add: mult_right_mono_neg prems)
obua@15580
  2326
    ultimately show ?thesis
obua@15580
  2327
      by simp
obua@15580
  2328
  qed
obua@15580
  2329
  moreover have "nprt a * pprt b <= nprt a2 * pprt b1"
obua@15580
  2330
  proof - 
obua@15580
  2331
    have "nprt a * pprt b <= nprt a2 * pprt b"
obua@15580
  2332
      by (simp add: mult_right_mono prems)
obua@15580
  2333
    moreover have "nprt a2 * pprt b <= nprt a2 * pprt b1"
obua@15580
  2334
      by (simp add: mult_left_mono_neg prems)
obua@15580
  2335
    ultimately show ?thesis
obua@15580
  2336
      by simp
obua@15580
  2337
  qed
obua@15580
  2338
  moreover have "nprt a * nprt b <= nprt a1 * nprt b1"
obua@15580
  2339
  proof -
obua@15580
  2340
    have "nprt a * nprt b <= nprt a * nprt b1"
obua@15580
  2341
      by (simp add: mult_left_mono_neg prems)
obua@15580
  2342
    moreover have "nprt a * nprt b1 <= nprt a1 * nprt b1"
obua@15580
  2343
      by (simp add: mult_right_mono_neg prems)
obua@15580
  2344
    ultimately show ?thesis
obua@15580
  2345
      by simp
obua@15580
  2346
  qed
obua@15580
  2347
  ultimately show ?thesis
obua@15580
  2348
    by - (rule add_mono | simp)+
obua@15580
  2349
qed
obua@19404
  2350
obua@19404
  2351
lemma mult_ge_prts:
obua@15178
  2352
  assumes
obua@19404
  2353
  "a1 <= (a::'a::lordered_ring)"
obua@19404
  2354
  "a <= a2"
obua@19404
  2355
  "b1 <= b"
obua@19404
  2356
  "b <= b2"
obua@15178
  2357
  shows
obua@19404
  2358
  "a * b >= nprt a1 * pprt b2 + nprt a2 * nprt b2 + pprt a1 * pprt b1 + pprt a2 * nprt b1"
obua@19404
  2359
proof - 
obua@19404
  2360
  from prems have a1:"- a2 <= -a" by auto
obua@19404
  2361
  from prems have a2: "-a <= -a1" by auto
obua@19404
  2362
  from mult_le_prts[of "-a2" "-a" "-a1" "b1" b "b2", OF a1 a2 prems(3) prems(4), simplified nprt_neg pprt_neg] 
obua@19404
  2363
  have le: "- (a * b) <= - nprt a1 * pprt b2 + - nprt a2 * nprt b2 + - pprt a1 * pprt b1 + - pprt a2 * nprt b1" by simp  
obua@19404
  2364
  then have "-(- nprt a1 * pprt b2 + - nprt a2 * nprt b2 + - pprt a1 * pprt b1 + - pprt a2 * nprt b1) <= a * b"
obua@19404
  2365
    by (simp only: minus_le_iff)
obua@19404
  2366
  then show ?thesis by simp
obua@15178
  2367
qed
obua@15178
  2368
paulson@14265
  2369
end