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