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