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