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