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