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