src/HOL/Ring_and_Field.thy
author krauss
Tue Nov 07 09:33:47 2006 +0100 (2006-11-07)
changeset 21199 2d83f93c3580
parent 20633 e98f59806244
child 21258 62f25a96f0c1
permissions -rw-r--r--
* Added annihilation axioms ("x * 0 = 0") to axclass semiring_0.
Richer structures do not inherit from semiring_0 anymore, because
anihilation is a theorem there, not an axiom.

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