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