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