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