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