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