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