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