src/HOL/Fields.thy
author haftmann
Mon Feb 08 17:12:38 2010 +0100 (2010-02-08)
changeset 35050 9f841f20dca6
parent 35043 src/HOL/Ring_and_Field.thy@07dbdf60d5ad
child 35084 e25eedfc15ce
permissions -rw-r--r--
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann@35050
     1
(*  Title:      HOL/Fields.thy
wenzelm@32960
     2
    Author:     Gertrud Bauer
wenzelm@32960
     3
    Author:     Steven Obua
wenzelm@32960
     4
    Author:     Tobias Nipkow
wenzelm@32960
     5
    Author:     Lawrence C Paulson
wenzelm@32960
     6
    Author:     Markus Wenzel
wenzelm@32960
     7
    Author:     Jeremy Avigad
paulson@14265
     8
*)
paulson@14265
     9
haftmann@35050
    10
header {* Fields *}
haftmann@25152
    11
haftmann@35050
    12
theory Fields
haftmann@35050
    13
imports Rings
haftmann@25186
    14
begin
paulson@14421
    15
huffman@22987
    16
class field = comm_ring_1 + inverse +
haftmann@25062
    17
  assumes field_inverse:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
haftmann@25062
    18
  assumes divide_inverse: "a / b = a * inverse b"
haftmann@25267
    19
begin
huffman@20496
    20
haftmann@25267
    21
subclass division_ring
haftmann@28823
    22
proof
huffman@22987
    23
  fix a :: 'a
huffman@22987
    24
  assume "a \<noteq> 0"
huffman@22987
    25
  thus "inverse a * a = 1" by (rule field_inverse)
huffman@22987
    26
  thus "a * inverse a = 1" by (simp only: mult_commute)
obua@14738
    27
qed
haftmann@25230
    28
huffman@27516
    29
subclass idom ..
haftmann@25230
    30
haftmann@25230
    31
lemma right_inverse_eq: "b \<noteq> 0 \<Longrightarrow> a / b = 1 \<longleftrightarrow> a = b"
haftmann@25230
    32
proof
haftmann@25230
    33
  assume neq: "b \<noteq> 0"
haftmann@25230
    34
  {
haftmann@25230
    35
    hence "a = (a / b) * b" by (simp add: divide_inverse mult_ac)
haftmann@25230
    36
    also assume "a / b = 1"
haftmann@25230
    37
    finally show "a = b" by simp
haftmann@25230
    38
  next
haftmann@25230
    39
    assume "a = b"
haftmann@25230
    40
    with neq show "a / b = 1" by (simp add: divide_inverse)
haftmann@25230
    41
  }
haftmann@25230
    42
qed
haftmann@25230
    43
haftmann@25230
    44
lemma nonzero_inverse_eq_divide: "a \<noteq> 0 \<Longrightarrow> inverse a = 1 / a"
nipkow@29667
    45
by (simp add: divide_inverse)
haftmann@25230
    46
haftmann@25230
    47
lemma divide_self [simp]: "a \<noteq> 0 \<Longrightarrow> a / a = 1"
nipkow@29667
    48
by (simp add: divide_inverse)
haftmann@25230
    49
haftmann@25230
    50
lemma divide_zero_left [simp]: "0 / a = 0"
nipkow@29667
    51
by (simp add: divide_inverse)
haftmann@25230
    52
haftmann@25230
    53
lemma inverse_eq_divide: "inverse a = 1 / a"
nipkow@29667
    54
by (simp add: divide_inverse)
haftmann@25230
    55
haftmann@25230
    56
lemma add_divide_distrib: "(a+b) / c = a/c + b/c"
huffman@30630
    57
by (simp add: divide_inverse algebra_simps)
huffman@30630
    58
huffman@30630
    59
text{*There is no slick version using division by zero.*}
huffman@30630
    60
lemma inverse_add:
huffman@30630
    61
  "[| a \<noteq> 0;  b \<noteq> 0 |]
huffman@30630
    62
   ==> inverse a + inverse b = (a + b) * inverse a * inverse b"
huffman@30630
    63
by (simp add: division_ring_inverse_add mult_ac)
huffman@30630
    64
huffman@30630
    65
lemma nonzero_mult_divide_mult_cancel_left [simp, noatp]:
huffman@30630
    66
assumes [simp]: "b\<noteq>0" and [simp]: "c\<noteq>0" shows "(c*a)/(c*b) = a/b"
huffman@30630
    67
proof -
huffman@30630
    68
  have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
huffman@30630
    69
    by (simp add: divide_inverse nonzero_inverse_mult_distrib)
huffman@30630
    70
  also have "... =  a * inverse b * (inverse c * c)"
huffman@30630
    71
    by (simp only: mult_ac)
huffman@30630
    72
  also have "... =  a * inverse b" by simp
huffman@30630
    73
    finally show ?thesis by (simp add: divide_inverse)
huffman@30630
    74
qed
huffman@30630
    75
huffman@30630
    76
lemma nonzero_mult_divide_mult_cancel_right [simp, noatp]:
huffman@30630
    77
  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (a * c) / (b * c) = a / b"
huffman@30630
    78
by (simp add: mult_commute [of _ c])
huffman@30630
    79
huffman@30630
    80
lemma divide_1 [simp]: "a / 1 = a"
huffman@30630
    81
by (simp add: divide_inverse)
huffman@30630
    82
huffman@30630
    83
lemma times_divide_eq_right: "a * (b / c) = (a * b) / c"
huffman@30630
    84
by (simp add: divide_inverse mult_assoc)
huffman@30630
    85
huffman@30630
    86
lemma times_divide_eq_left: "(b / c) * a = (b * a) / c"
huffman@30630
    87
by (simp add: divide_inverse mult_ac)
huffman@30630
    88
huffman@30630
    89
text {* These are later declared as simp rules. *}
huffman@30630
    90
lemmas times_divide_eq [noatp] = times_divide_eq_right times_divide_eq_left
huffman@30630
    91
huffman@30630
    92
lemma add_frac_eq:
huffman@30630
    93
  assumes "y \<noteq> 0" and "z \<noteq> 0"
huffman@30630
    94
  shows "x / y + w / z = (x * z + w * y) / (y * z)"
huffman@30630
    95
proof -
huffman@30630
    96
  have "x / y + w / z = (x * z) / (y * z) + (y * w) / (y * z)"
huffman@30630
    97
    using assms by simp
huffman@30630
    98
  also have "\<dots> = (x * z + y * w) / (y * z)"
huffman@30630
    99
    by (simp only: add_divide_distrib)
huffman@30630
   100
  finally show ?thesis
huffman@30630
   101
    by (simp only: mult_commute)
huffman@30630
   102
qed
huffman@30630
   103
huffman@30630
   104
text{*Special Cancellation Simprules for Division*}
huffman@30630
   105
huffman@30630
   106
lemma nonzero_mult_divide_cancel_right [simp, noatp]:
huffman@30630
   107
  "b \<noteq> 0 \<Longrightarrow> a * b / b = a"
huffman@30630
   108
using nonzero_mult_divide_mult_cancel_right [of 1 b a] by simp
huffman@30630
   109
huffman@30630
   110
lemma nonzero_mult_divide_cancel_left [simp, noatp]:
huffman@30630
   111
  "a \<noteq> 0 \<Longrightarrow> a * b / a = b"
huffman@30630
   112
using nonzero_mult_divide_mult_cancel_left [of 1 a b] by simp
huffman@30630
   113
huffman@30630
   114
lemma nonzero_divide_mult_cancel_right [simp, noatp]:
huffman@30630
   115
  "\<lbrakk>a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> b / (a * b) = 1 / a"
huffman@30630
   116
using nonzero_mult_divide_mult_cancel_right [of a b 1] by simp
huffman@30630
   117
huffman@30630
   118
lemma nonzero_divide_mult_cancel_left [simp, noatp]:
huffman@30630
   119
  "\<lbrakk>a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / (a * b) = 1 / b"
huffman@30630
   120
using nonzero_mult_divide_mult_cancel_left [of b a 1] by simp
huffman@30630
   121
huffman@30630
   122
lemma nonzero_mult_divide_mult_cancel_left2 [simp, noatp]:
huffman@30630
   123
  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (c * a) / (b * c) = a / b"
huffman@30630
   124
using nonzero_mult_divide_mult_cancel_left [of b c a] by (simp add: mult_ac)
huffman@30630
   125
huffman@30630
   126
lemma nonzero_mult_divide_mult_cancel_right2 [simp, noatp]:
huffman@30630
   127
  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (a * c) / (c * b) = a / b"
huffman@30630
   128
using nonzero_mult_divide_mult_cancel_right [of b c a] by (simp add: mult_ac)
huffman@30630
   129
huffman@30630
   130
lemma minus_divide_left: "- (a / b) = (-a) / b"
huffman@30630
   131
by (simp add: divide_inverse)
huffman@30630
   132
huffman@30630
   133
lemma nonzero_minus_divide_right: "b \<noteq> 0 ==> - (a / b) = a / (- b)"
huffman@30630
   134
by (simp add: divide_inverse nonzero_inverse_minus_eq)
huffman@30630
   135
huffman@30630
   136
lemma nonzero_minus_divide_divide: "b \<noteq> 0 ==> (-a) / (-b) = a / b"
huffman@30630
   137
by (simp add: divide_inverse nonzero_inverse_minus_eq)
huffman@30630
   138
huffman@30630
   139
lemma divide_minus_left [simp, noatp]: "(-a) / b = - (a / b)"
huffman@30630
   140
by (simp add: divide_inverse)
huffman@30630
   141
huffman@30630
   142
lemma diff_divide_distrib: "(a - b) / c = a / c - b / c"
huffman@30630
   143
by (simp add: diff_minus add_divide_distrib)
huffman@30630
   144
huffman@30630
   145
lemma add_divide_eq_iff:
huffman@30630
   146
  "z \<noteq> 0 \<Longrightarrow> x + y / z = (z * x + y) / z"
huffman@30630
   147
by (simp add: add_divide_distrib)
huffman@30630
   148
huffman@30630
   149
lemma divide_add_eq_iff:
huffman@30630
   150
  "z \<noteq> 0 \<Longrightarrow> x / z + y = (x + z * y) / z"
huffman@30630
   151
by (simp add: add_divide_distrib)
huffman@30630
   152
huffman@30630
   153
lemma diff_divide_eq_iff:
huffman@30630
   154
  "z \<noteq> 0 \<Longrightarrow> x - y / z = (z * x - y) / z"
huffman@30630
   155
by (simp add: diff_divide_distrib)
huffman@30630
   156
huffman@30630
   157
lemma divide_diff_eq_iff:
huffman@30630
   158
  "z \<noteq> 0 \<Longrightarrow> x / z - y = (x - z * y) / z"
huffman@30630
   159
by (simp add: diff_divide_distrib)
huffman@30630
   160
huffman@30630
   161
lemma nonzero_eq_divide_eq: "c \<noteq> 0 \<Longrightarrow> a = b / c \<longleftrightarrow> a * c = b"
huffman@30630
   162
proof -
huffman@30630
   163
  assume [simp]: "c \<noteq> 0"
huffman@30630
   164
  have "a = b / c \<longleftrightarrow> a * c = (b / c) * c" by simp
huffman@30630
   165
  also have "... \<longleftrightarrow> a * c = b" by (simp add: divide_inverse mult_assoc)
huffman@30630
   166
  finally show ?thesis .
huffman@30630
   167
qed
huffman@30630
   168
huffman@30630
   169
lemma nonzero_divide_eq_eq: "c \<noteq> 0 \<Longrightarrow> b / c = a \<longleftrightarrow> b = a * c"
huffman@30630
   170
proof -
huffman@30630
   171
  assume [simp]: "c \<noteq> 0"
huffman@30630
   172
  have "b / c = a \<longleftrightarrow> (b / c) * c = a * c" by simp
huffman@30630
   173
  also have "... \<longleftrightarrow> b = a * c" by (simp add: divide_inverse mult_assoc) 
huffman@30630
   174
  finally show ?thesis .
huffman@30630
   175
qed
huffman@30630
   176
huffman@30630
   177
lemma divide_eq_imp: "c \<noteq> 0 \<Longrightarrow> b = a * c \<Longrightarrow> b / c = a"
huffman@30630
   178
by simp
huffman@30630
   179
huffman@30630
   180
lemma eq_divide_imp: "c \<noteq> 0 \<Longrightarrow> a * c = b \<Longrightarrow> a = b / c"
huffman@30630
   181
by (erule subst, simp)
huffman@30630
   182
huffman@30630
   183
lemmas field_eq_simps[noatp] = algebra_simps
huffman@30630
   184
  (* pull / out*)
huffman@30630
   185
  add_divide_eq_iff divide_add_eq_iff
huffman@30630
   186
  diff_divide_eq_iff divide_diff_eq_iff
huffman@30630
   187
  (* multiply eqn *)
huffman@30630
   188
  nonzero_eq_divide_eq nonzero_divide_eq_eq
huffman@30630
   189
(* is added later:
huffman@30630
   190
  times_divide_eq_left times_divide_eq_right
huffman@30630
   191
*)
huffman@30630
   192
huffman@30630
   193
text{*An example:*}
huffman@30630
   194
lemma "\<lbrakk>a\<noteq>b; c\<noteq>d; e\<noteq>f\<rbrakk> \<Longrightarrow> ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) = 1"
huffman@30630
   195
apply(subgoal_tac "(c-d)*(e-f)*(a-b) \<noteq> 0")
huffman@30630
   196
 apply(simp add:field_eq_simps)
huffman@30630
   197
apply(simp)
huffman@30630
   198
done
huffman@30630
   199
huffman@30630
   200
lemma diff_frac_eq:
huffman@30630
   201
  "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> x / y - w / z = (x * z - w * y) / (y * z)"
huffman@30630
   202
by (simp add: field_eq_simps times_divide_eq)
huffman@30630
   203
huffman@30630
   204
lemma frac_eq_eq:
huffman@30630
   205
  "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> (x / y = w / z) = (x * z = w * y)"
huffman@30630
   206
by (simp add: field_eq_simps times_divide_eq)
haftmann@25230
   207
haftmann@25230
   208
end
haftmann@25230
   209
haftmann@22390
   210
class division_by_zero = zero + inverse +
haftmann@25062
   211
  assumes inverse_zero [simp]: "inverse 0 = 0"
paulson@14265
   212
haftmann@25230
   213
lemma divide_zero [simp]:
haftmann@25230
   214
  "a / 0 = (0::'a::{field,division_by_zero})"
nipkow@29667
   215
by (simp add: divide_inverse)
haftmann@25230
   216
haftmann@25230
   217
lemma divide_self_if [simp]:
haftmann@25230
   218
  "a / (a::'a::{field,division_by_zero}) = (if a=0 then 0 else 1)"
nipkow@29667
   219
by simp
haftmann@25230
   220
haftmann@35028
   221
class linordered_field = field + linordered_idom
haftmann@25230
   222
paulson@14268
   223
lemma inverse_nonzero_iff_nonzero [simp]:
huffman@20496
   224
   "(inverse a = 0) = (a = (0::'a::{division_ring,division_by_zero}))"
haftmann@26274
   225
by (force dest: inverse_zero_imp_zero) 
paulson@14268
   226
paulson@14268
   227
lemma inverse_minus_eq [simp]:
huffman@20496
   228
   "inverse(-a) = -inverse(a::'a::{division_ring,division_by_zero})"
paulson@14377
   229
proof cases
paulson@14377
   230
  assume "a=0" thus ?thesis by (simp add: inverse_zero)
paulson@14377
   231
next
paulson@14377
   232
  assume "a\<noteq>0" 
paulson@14377
   233
  thus ?thesis by (simp add: nonzero_inverse_minus_eq)
paulson@14377
   234
qed
paulson@14268
   235
paulson@14268
   236
lemma inverse_eq_imp_eq:
huffman@20496
   237
  "inverse a = inverse b ==> a = (b::'a::{division_ring,division_by_zero})"
haftmann@21328
   238
apply (cases "a=0 | b=0") 
paulson@14268
   239
 apply (force dest!: inverse_zero_imp_zero
paulson@14268
   240
              simp add: eq_commute [of "0::'a"])
paulson@14268
   241
apply (force dest!: nonzero_inverse_eq_imp_eq) 
paulson@14268
   242
done
paulson@14268
   243
paulson@14268
   244
lemma inverse_eq_iff_eq [simp]:
huffman@20496
   245
  "(inverse a = inverse b) = (a = (b::'a::{division_ring,division_by_zero}))"
huffman@20496
   246
by (force dest!: inverse_eq_imp_eq)
paulson@14268
   247
paulson@14270
   248
lemma inverse_inverse_eq [simp]:
huffman@20496
   249
     "inverse(inverse (a::'a::{division_ring,division_by_zero})) = a"
paulson@14270
   250
  proof cases
paulson@14270
   251
    assume "a=0" thus ?thesis by simp
paulson@14270
   252
  next
paulson@14270
   253
    assume "a\<noteq>0" 
paulson@14270
   254
    thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
paulson@14270
   255
  qed
paulson@14270
   256
paulson@14270
   257
text{*This version builds in division by zero while also re-orienting
paulson@14270
   258
      the right-hand side.*}
paulson@14270
   259
lemma inverse_mult_distrib [simp]:
paulson@14270
   260
     "inverse(a*b) = inverse(a) * inverse(b::'a::{field,division_by_zero})"
paulson@14270
   261
  proof cases
paulson@14270
   262
    assume "a \<noteq> 0 & b \<noteq> 0" 
nipkow@29667
   263
    thus ?thesis by (simp add: nonzero_inverse_mult_distrib mult_commute)
paulson@14270
   264
  next
paulson@14270
   265
    assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
nipkow@29667
   266
    thus ?thesis by force
paulson@14270
   267
  qed
paulson@14270
   268
paulson@14365
   269
lemma inverse_divide [simp]:
nipkow@23477
   270
  "inverse (a/b) = b / (a::'a::{field,division_by_zero})"
nipkow@23477
   271
by (simp add: divide_inverse mult_commute)
paulson@14365
   272
wenzelm@23389
   273
avigad@16775
   274
subsection {* Calculations with fractions *}
avigad@16775
   275
nipkow@23413
   276
text{* There is a whole bunch of simp-rules just for class @{text
nipkow@23413
   277
field} but none for class @{text field} and @{text nonzero_divides}
nipkow@23413
   278
because the latter are covered by a simproc. *}
nipkow@23413
   279
nipkow@23413
   280
lemma mult_divide_mult_cancel_left:
nipkow@23477
   281
  "c\<noteq>0 ==> (c*a) / (c*b) = a / (b::'a::{field,division_by_zero})"
haftmann@21328
   282
apply (cases "b = 0")
nipkow@23413
   283
apply (simp_all add: nonzero_mult_divide_mult_cancel_left)
paulson@14277
   284
done
paulson@14277
   285
nipkow@23413
   286
lemma mult_divide_mult_cancel_right:
nipkow@23477
   287
  "c\<noteq>0 ==> (a*c) / (b*c) = a / (b::'a::{field,division_by_zero})"
haftmann@21328
   288
apply (cases "b = 0")
nipkow@23413
   289
apply (simp_all add: nonzero_mult_divide_mult_cancel_right)
paulson@14321
   290
done
nipkow@23413
   291
paulson@24286
   292
lemma divide_divide_eq_right [simp,noatp]:
nipkow@23477
   293
  "a / (b/c) = (a*c) / (b::'a::{field,division_by_zero})"
paulson@14430
   294
by (simp add: divide_inverse mult_ac)
paulson@14288
   295
paulson@24286
   296
lemma divide_divide_eq_left [simp,noatp]:
nipkow@23477
   297
  "(a / b) / (c::'a::{field,division_by_zero}) = a / (b*c)"
paulson@14430
   298
by (simp add: divide_inverse mult_assoc)
paulson@14288
   299
wenzelm@23389
   300
paulson@15234
   301
subsubsection{*Special Cancellation Simprules for Division*}
paulson@15234
   302
paulson@24427
   303
lemma mult_divide_mult_cancel_left_if[simp,noatp]:
nipkow@23477
   304
fixes c :: "'a :: {field,division_by_zero}"
nipkow@23477
   305
shows "(c*a) / (c*b) = (if c=0 then 0 else a/b)"
nipkow@23413
   306
by (simp add: mult_divide_mult_cancel_left)
nipkow@23413
   307
paulson@15234
   308
paulson@14293
   309
subsection {* Division and Unary Minus *}
paulson@14293
   310
paulson@14293
   311
lemma minus_divide_right: "- (a/b) = a / -(b::'a::{field,division_by_zero})"
huffman@29407
   312
by (simp add: divide_inverse)
paulson@14430
   313
huffman@30630
   314
lemma divide_minus_right [simp, noatp]:
huffman@30630
   315
  "a / -(b::'a::{field,division_by_zero}) = -(a / b)"
huffman@30630
   316
by (simp add: divide_inverse)
huffman@30630
   317
huffman@30630
   318
lemma minus_divide_divide:
nipkow@23477
   319
  "(-a)/(-b) = a / (b::'a::{field,division_by_zero})"
haftmann@21328
   320
apply (cases "b=0", simp) 
paulson@14293
   321
apply (simp add: nonzero_minus_divide_divide) 
paulson@14293
   322
done
paulson@14293
   323
nipkow@23482
   324
lemma eq_divide_eq:
nipkow@23482
   325
  "((a::'a::{field,division_by_zero}) = b/c) = (if c\<noteq>0 then a*c = b else a=0)"
huffman@30630
   326
by (simp add: nonzero_eq_divide_eq)
nipkow@23482
   327
nipkow@23482
   328
lemma divide_eq_eq:
nipkow@23482
   329
  "(b/c = (a::'a::{field,division_by_zero})) = (if c\<noteq>0 then b = a*c else a=0)"
huffman@30630
   330
by (force simp add: nonzero_divide_eq_eq)
paulson@14293
   331
wenzelm@23389
   332
paulson@14268
   333
subsection {* Ordered Fields *}
paulson@14268
   334
paulson@14277
   335
lemma positive_imp_inverse_positive: 
haftmann@35028
   336
assumes a_gt_0: "0 < a"  shows "0 < inverse (a::'a::linordered_field)"
nipkow@23482
   337
proof -
paulson@14268
   338
  have "0 < a * inverse a" 
paulson@14268
   339
    by (simp add: a_gt_0 [THEN order_less_imp_not_eq2] zero_less_one)
paulson@14268
   340
  thus "0 < inverse a" 
paulson@14268
   341
    by (simp add: a_gt_0 [THEN order_less_not_sym] zero_less_mult_iff)
nipkow@23482
   342
qed
paulson@14268
   343
paulson@14277
   344
lemma negative_imp_inverse_negative:
haftmann@35028
   345
  "a < 0 ==> inverse a < (0::'a::linordered_field)"
nipkow@23482
   346
by (insert positive_imp_inverse_positive [of "-a"], 
nipkow@23482
   347
    simp add: nonzero_inverse_minus_eq order_less_imp_not_eq)
paulson@14268
   348
paulson@14268
   349
lemma inverse_le_imp_le:
nipkow@23482
   350
assumes invle: "inverse a \<le> inverse b" and apos:  "0 < a"
haftmann@35028
   351
shows "b \<le> (a::'a::linordered_field)"
nipkow@23482
   352
proof (rule classical)
paulson@14268
   353
  assume "~ b \<le> a"
nipkow@23482
   354
  hence "a < b"  by (simp add: linorder_not_le)
nipkow@23482
   355
  hence bpos: "0 < b"  by (blast intro: apos order_less_trans)
paulson@14268
   356
  hence "a * inverse a \<le> a * inverse b"
paulson@14268
   357
    by (simp add: apos invle order_less_imp_le mult_left_mono)
paulson@14268
   358
  hence "(a * inverse a) * b \<le> (a * inverse b) * b"
paulson@14268
   359
    by (simp add: bpos order_less_imp_le mult_right_mono)
nipkow@23482
   360
  thus "b \<le> a"  by (simp add: mult_assoc apos bpos order_less_imp_not_eq2)
nipkow@23482
   361
qed
paulson@14268
   362
paulson@14277
   363
lemma inverse_positive_imp_positive:
nipkow@23482
   364
assumes inv_gt_0: "0 < inverse a" and nz: "a \<noteq> 0"
haftmann@35028
   365
shows "0 < (a::'a::linordered_field)"
wenzelm@23389
   366
proof -
paulson@14277
   367
  have "0 < inverse (inverse a)"
wenzelm@23389
   368
    using inv_gt_0 by (rule positive_imp_inverse_positive)
paulson@14277
   369
  thus "0 < a"
wenzelm@23389
   370
    using nz by (simp add: nonzero_inverse_inverse_eq)
wenzelm@23389
   371
qed
paulson@14277
   372
paulson@14277
   373
lemma inverse_positive_iff_positive [simp]:
haftmann@35028
   374
  "(0 < inverse a) = (0 < (a::'a::{linordered_field,division_by_zero}))"
haftmann@21328
   375
apply (cases "a = 0", simp)
paulson@14277
   376
apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
paulson@14277
   377
done
paulson@14277
   378
paulson@14277
   379
lemma inverse_negative_imp_negative:
nipkow@23482
   380
assumes inv_less_0: "inverse a < 0" and nz:  "a \<noteq> 0"
haftmann@35028
   381
shows "a < (0::'a::linordered_field)"
wenzelm@23389
   382
proof -
paulson@14277
   383
  have "inverse (inverse a) < 0"
wenzelm@23389
   384
    using inv_less_0 by (rule negative_imp_inverse_negative)
nipkow@23482
   385
  thus "a < 0" using nz by (simp add: nonzero_inverse_inverse_eq)
wenzelm@23389
   386
qed
paulson@14277
   387
paulson@14277
   388
lemma inverse_negative_iff_negative [simp]:
haftmann@35028
   389
  "(inverse a < 0) = (a < (0::'a::{linordered_field,division_by_zero}))"
haftmann@21328
   390
apply (cases "a = 0", simp)
paulson@14277
   391
apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
paulson@14277
   392
done
paulson@14277
   393
paulson@14277
   394
lemma inverse_nonnegative_iff_nonnegative [simp]:
haftmann@35028
   395
  "(0 \<le> inverse a) = (0 \<le> (a::'a::{linordered_field,division_by_zero}))"
paulson@14277
   396
by (simp add: linorder_not_less [symmetric])
paulson@14277
   397
paulson@14277
   398
lemma inverse_nonpositive_iff_nonpositive [simp]:
haftmann@35028
   399
  "(inverse a \<le> 0) = (a \<le> (0::'a::{linordered_field,division_by_zero}))"
paulson@14277
   400
by (simp add: linorder_not_less [symmetric])
paulson@14277
   401
haftmann@35043
   402
lemma linordered_field_no_lb: "\<forall> x. \<exists>y. y < (x::'a::linordered_field)"
chaieb@23406
   403
proof
chaieb@23406
   404
  fix x::'a
chaieb@23406
   405
  have m1: "- (1::'a) < 0" by simp
chaieb@23406
   406
  from add_strict_right_mono[OF m1, where c=x] 
chaieb@23406
   407
  have "(- 1) + x < x" by simp
chaieb@23406
   408
  thus "\<exists>y. y < x" by blast
chaieb@23406
   409
qed
chaieb@23406
   410
haftmann@35043
   411
lemma linordered_field_no_ub: "\<forall> x. \<exists>y. y > (x::'a::linordered_field)"
chaieb@23406
   412
proof
chaieb@23406
   413
  fix x::'a
chaieb@23406
   414
  have m1: " (1::'a) > 0" by simp
chaieb@23406
   415
  from add_strict_right_mono[OF m1, where c=x] 
chaieb@23406
   416
  have "1 + x > x" by simp
chaieb@23406
   417
  thus "\<exists>y. y > x" by blast
chaieb@23406
   418
qed
paulson@14277
   419
paulson@14277
   420
subsection{*Anti-Monotonicity of @{term inverse}*}
paulson@14277
   421
paulson@14268
   422
lemma less_imp_inverse_less:
nipkow@23482
   423
assumes less: "a < b" and apos:  "0 < a"
haftmann@35028
   424
shows "inverse b < inverse (a::'a::linordered_field)"
nipkow@23482
   425
proof (rule ccontr)
paulson@14268
   426
  assume "~ inverse b < inverse a"
nipkow@29667
   427
  hence "inverse a \<le> inverse b" by (simp add: linorder_not_less)
paulson@14268
   428
  hence "~ (a < b)"
paulson@14268
   429
    by (simp add: linorder_not_less inverse_le_imp_le [OF _ apos])
nipkow@29667
   430
  thus False by (rule notE [OF _ less])
nipkow@23482
   431
qed
paulson@14268
   432
paulson@14268
   433
lemma inverse_less_imp_less:
haftmann@35028
   434
  "[|inverse a < inverse b; 0 < a|] ==> b < (a::'a::linordered_field)"
paulson@14268
   435
apply (simp add: order_less_le [of "inverse a"] order_less_le [of "b"])
paulson@14268
   436
apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
paulson@14268
   437
done
paulson@14268
   438
paulson@14268
   439
text{*Both premises are essential. Consider -1 and 1.*}
paulson@24286
   440
lemma inverse_less_iff_less [simp,noatp]:
haftmann@35028
   441
  "[|0 < a; 0 < b|] ==> (inverse a < inverse b) = (b < (a::'a::linordered_field))"
paulson@14268
   442
by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
paulson@14268
   443
paulson@14268
   444
lemma le_imp_inverse_le:
haftmann@35028
   445
  "[|a \<le> b; 0 < a|] ==> inverse b \<le> inverse (a::'a::linordered_field)"
nipkow@23482
   446
by (force simp add: order_le_less less_imp_inverse_less)
paulson@14268
   447
paulson@24286
   448
lemma inverse_le_iff_le [simp,noatp]:
haftmann@35028
   449
 "[|0 < a; 0 < b|] ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::linordered_field))"
paulson@14268
   450
by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
paulson@14268
   451
paulson@14268
   452
paulson@14268
   453
text{*These results refer to both operands being negative.  The opposite-sign
paulson@14268
   454
case is trivial, since inverse preserves signs.*}
paulson@14268
   455
lemma inverse_le_imp_le_neg:
haftmann@35028
   456
  "[|inverse a \<le> inverse b; b < 0|] ==> b \<le> (a::'a::linordered_field)"
nipkow@23482
   457
apply (rule classical) 
nipkow@23482
   458
apply (subgoal_tac "a < 0") 
nipkow@23482
   459
 prefer 2 apply (force simp add: linorder_not_le intro: order_less_trans) 
nipkow@23482
   460
apply (insert inverse_le_imp_le [of "-b" "-a"])
nipkow@23482
   461
apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
nipkow@23482
   462
done
paulson@14268
   463
paulson@14268
   464
lemma less_imp_inverse_less_neg:
haftmann@35028
   465
   "[|a < b; b < 0|] ==> inverse b < inverse (a::'a::linordered_field)"
nipkow@23482
   466
apply (subgoal_tac "a < 0") 
nipkow@23482
   467
 prefer 2 apply (blast intro: order_less_trans) 
nipkow@23482
   468
apply (insert less_imp_inverse_less [of "-b" "-a"])
nipkow@23482
   469
apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
nipkow@23482
   470
done
paulson@14268
   471
paulson@14268
   472
lemma inverse_less_imp_less_neg:
haftmann@35028
   473
   "[|inverse a < inverse b; b < 0|] ==> b < (a::'a::linordered_field)"
nipkow@23482
   474
apply (rule classical) 
nipkow@23482
   475
apply (subgoal_tac "a < 0") 
nipkow@23482
   476
 prefer 2
nipkow@23482
   477
 apply (force simp add: linorder_not_less intro: order_le_less_trans) 
nipkow@23482
   478
apply (insert inverse_less_imp_less [of "-b" "-a"])
nipkow@23482
   479
apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
nipkow@23482
   480
done
paulson@14268
   481
paulson@24286
   482
lemma inverse_less_iff_less_neg [simp,noatp]:
haftmann@35028
   483
  "[|a < 0; b < 0|] ==> (inverse a < inverse b) = (b < (a::'a::linordered_field))"
nipkow@23482
   484
apply (insert inverse_less_iff_less [of "-b" "-a"])
nipkow@23482
   485
apply (simp del: inverse_less_iff_less 
nipkow@23482
   486
            add: order_less_imp_not_eq nonzero_inverse_minus_eq)
nipkow@23482
   487
done
paulson@14268
   488
paulson@14268
   489
lemma le_imp_inverse_le_neg:
haftmann@35028
   490
  "[|a \<le> b; b < 0|] ==> inverse b \<le> inverse (a::'a::linordered_field)"
nipkow@23482
   491
by (force simp add: order_le_less less_imp_inverse_less_neg)
paulson@14268
   492
paulson@24286
   493
lemma inverse_le_iff_le_neg [simp,noatp]:
haftmann@35028
   494
 "[|a < 0; b < 0|] ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::linordered_field))"
paulson@14268
   495
by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
paulson@14265
   496
paulson@14277
   497
paulson@14365
   498
subsection{*Inverses and the Number One*}
paulson@14365
   499
paulson@14365
   500
lemma one_less_inverse_iff:
haftmann@35028
   501
  "(1 < inverse x) = (0 < x & x < (1::'a::{linordered_field,division_by_zero}))"
nipkow@23482
   502
proof cases
paulson@14365
   503
  assume "0 < x"
paulson@14365
   504
    with inverse_less_iff_less [OF zero_less_one, of x]
paulson@14365
   505
    show ?thesis by simp
paulson@14365
   506
next
paulson@14365
   507
  assume notless: "~ (0 < x)"
paulson@14365
   508
  have "~ (1 < inverse x)"
paulson@14365
   509
  proof
paulson@14365
   510
    assume "1 < inverse x"
paulson@14365
   511
    also with notless have "... \<le> 0" by (simp add: linorder_not_less)
paulson@14365
   512
    also have "... < 1" by (rule zero_less_one) 
paulson@14365
   513
    finally show False by auto
paulson@14365
   514
  qed
paulson@14365
   515
  with notless show ?thesis by simp
paulson@14365
   516
qed
paulson@14365
   517
paulson@14365
   518
lemma inverse_eq_1_iff [simp]:
nipkow@23482
   519
  "(inverse x = 1) = (x = (1::'a::{field,division_by_zero}))"
paulson@14365
   520
by (insert inverse_eq_iff_eq [of x 1], simp) 
paulson@14365
   521
paulson@14365
   522
lemma one_le_inverse_iff:
haftmann@35028
   523
  "(1 \<le> inverse x) = (0 < x & x \<le> (1::'a::{linordered_field,division_by_zero}))"
paulson@14365
   524
by (force simp add: order_le_less one_less_inverse_iff zero_less_one 
paulson@14365
   525
                    eq_commute [of 1]) 
paulson@14365
   526
paulson@14365
   527
lemma inverse_less_1_iff:
haftmann@35028
   528
  "(inverse x < 1) = (x \<le> 0 | 1 < (x::'a::{linordered_field,division_by_zero}))"
paulson@14365
   529
by (simp add: linorder_not_le [symmetric] one_le_inverse_iff) 
paulson@14365
   530
paulson@14365
   531
lemma inverse_le_1_iff:
haftmann@35028
   532
  "(inverse x \<le> 1) = (x \<le> 0 | 1 \<le> (x::'a::{linordered_field,division_by_zero}))"
paulson@14365
   533
by (simp add: linorder_not_less [symmetric] one_less_inverse_iff) 
paulson@14365
   534
wenzelm@23389
   535
paulson@14288
   536
subsection{*Simplification of Inequalities Involving Literal Divisors*}
paulson@14288
   537
haftmann@35028
   538
lemma pos_le_divide_eq: "0 < (c::'a::linordered_field) ==> (a \<le> b/c) = (a*c \<le> b)"
paulson@14288
   539
proof -
paulson@14288
   540
  assume less: "0<c"
paulson@14288
   541
  hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
paulson@14288
   542
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
   543
  also have "... = (a*c \<le> b)"
paulson@14288
   544
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
   545
  finally show ?thesis .
paulson@14288
   546
qed
paulson@14288
   547
haftmann@35028
   548
lemma neg_le_divide_eq: "c < (0::'a::linordered_field) ==> (a \<le> b/c) = (b \<le> a*c)"
paulson@14288
   549
proof -
paulson@14288
   550
  assume less: "c<0"
paulson@14288
   551
  hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
paulson@14288
   552
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
   553
  also have "... = (b \<le> a*c)"
paulson@14288
   554
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
   555
  finally show ?thesis .
paulson@14288
   556
qed
paulson@14288
   557
paulson@14288
   558
lemma le_divide_eq:
paulson@14288
   559
  "(a \<le> b/c) = 
paulson@14288
   560
   (if 0 < c then a*c \<le> b
paulson@14288
   561
             else if c < 0 then b \<le> a*c
haftmann@35028
   562
             else  a \<le> (0::'a::{linordered_field,division_by_zero}))"
haftmann@21328
   563
apply (cases "c=0", simp) 
paulson@14288
   564
apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
paulson@14288
   565
done
paulson@14288
   566
haftmann@35028
   567
lemma pos_divide_le_eq: "0 < (c::'a::linordered_field) ==> (b/c \<le> a) = (b \<le> a*c)"
paulson@14288
   568
proof -
paulson@14288
   569
  assume less: "0<c"
paulson@14288
   570
  hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
paulson@14288
   571
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
   572
  also have "... = (b \<le> a*c)"
paulson@14288
   573
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
   574
  finally show ?thesis .
paulson@14288
   575
qed
paulson@14288
   576
haftmann@35028
   577
lemma neg_divide_le_eq: "c < (0::'a::linordered_field) ==> (b/c \<le> a) = (a*c \<le> b)"
paulson@14288
   578
proof -
paulson@14288
   579
  assume less: "c<0"
paulson@14288
   580
  hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
paulson@14288
   581
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
   582
  also have "... = (a*c \<le> b)"
paulson@14288
   583
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
   584
  finally show ?thesis .
paulson@14288
   585
qed
paulson@14288
   586
paulson@14288
   587
lemma divide_le_eq:
paulson@14288
   588
  "(b/c \<le> a) = 
paulson@14288
   589
   (if 0 < c then b \<le> a*c
paulson@14288
   590
             else if c < 0 then a*c \<le> b
haftmann@35028
   591
             else 0 \<le> (a::'a::{linordered_field,division_by_zero}))"
haftmann@21328
   592
apply (cases "c=0", simp) 
paulson@14288
   593
apply (force simp add: pos_divide_le_eq neg_divide_le_eq linorder_neq_iff) 
paulson@14288
   594
done
paulson@14288
   595
paulson@14288
   596
lemma pos_less_divide_eq:
haftmann@35028
   597
     "0 < (c::'a::linordered_field) ==> (a < b/c) = (a*c < b)"
paulson@14288
   598
proof -
paulson@14288
   599
  assume less: "0<c"
paulson@14288
   600
  hence "(a < b/c) = (a*c < (b/c)*c)"
paulson@15234
   601
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
   602
  also have "... = (a*c < b)"
paulson@14288
   603
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
   604
  finally show ?thesis .
paulson@14288
   605
qed
paulson@14288
   606
paulson@14288
   607
lemma neg_less_divide_eq:
haftmann@35028
   608
 "c < (0::'a::linordered_field) ==> (a < b/c) = (b < a*c)"
paulson@14288
   609
proof -
paulson@14288
   610
  assume less: "c<0"
paulson@14288
   611
  hence "(a < b/c) = ((b/c)*c < a*c)"
paulson@15234
   612
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
   613
  also have "... = (b < a*c)"
paulson@14288
   614
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
   615
  finally show ?thesis .
paulson@14288
   616
qed
paulson@14288
   617
paulson@14288
   618
lemma less_divide_eq:
paulson@14288
   619
  "(a < b/c) = 
paulson@14288
   620
   (if 0 < c then a*c < b
paulson@14288
   621
             else if c < 0 then b < a*c
haftmann@35028
   622
             else  a < (0::'a::{linordered_field,division_by_zero}))"
haftmann@21328
   623
apply (cases "c=0", simp) 
paulson@14288
   624
apply (force simp add: pos_less_divide_eq neg_less_divide_eq linorder_neq_iff) 
paulson@14288
   625
done
paulson@14288
   626
paulson@14288
   627
lemma pos_divide_less_eq:
haftmann@35028
   628
     "0 < (c::'a::linordered_field) ==> (b/c < a) = (b < a*c)"
paulson@14288
   629
proof -
paulson@14288
   630
  assume less: "0<c"
paulson@14288
   631
  hence "(b/c < a) = ((b/c)*c < a*c)"
paulson@15234
   632
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
   633
  also have "... = (b < a*c)"
paulson@14288
   634
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
   635
  finally show ?thesis .
paulson@14288
   636
qed
paulson@14288
   637
paulson@14288
   638
lemma neg_divide_less_eq:
haftmann@35028
   639
 "c < (0::'a::linordered_field) ==> (b/c < a) = (a*c < b)"
paulson@14288
   640
proof -
paulson@14288
   641
  assume less: "c<0"
paulson@14288
   642
  hence "(b/c < a) = (a*c < (b/c)*c)"
paulson@15234
   643
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
   644
  also have "... = (a*c < b)"
paulson@14288
   645
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
   646
  finally show ?thesis .
paulson@14288
   647
qed
paulson@14288
   648
paulson@14288
   649
lemma divide_less_eq:
paulson@14288
   650
  "(b/c < a) = 
paulson@14288
   651
   (if 0 < c then b < a*c
paulson@14288
   652
             else if c < 0 then a*c < b
haftmann@35028
   653
             else 0 < (a::'a::{linordered_field,division_by_zero}))"
haftmann@21328
   654
apply (cases "c=0", simp) 
paulson@14288
   655
apply (force simp add: pos_divide_less_eq neg_divide_less_eq linorder_neq_iff) 
paulson@14288
   656
done
paulson@14288
   657
nipkow@23482
   658
nipkow@23482
   659
subsection{*Field simplification*}
nipkow@23482
   660
nipkow@29667
   661
text{* Lemmas @{text field_simps} multiply with denominators in in(equations)
nipkow@29667
   662
if they can be proved to be non-zero (for equations) or positive/negative
nipkow@29667
   663
(for inequations). Can be too aggressive and is therefore separate from the
nipkow@29667
   664
more benign @{text algebra_simps}. *}
paulson@14288
   665
nipkow@29833
   666
lemmas field_simps[noatp] = field_eq_simps
nipkow@23482
   667
  (* multiply ineqn *)
nipkow@23482
   668
  pos_divide_less_eq neg_divide_less_eq
nipkow@23482
   669
  pos_less_divide_eq neg_less_divide_eq
nipkow@23482
   670
  pos_divide_le_eq neg_divide_le_eq
nipkow@23482
   671
  pos_le_divide_eq neg_le_divide_eq
paulson@14288
   672
nipkow@23482
   673
text{* Lemmas @{text sign_simps} is a first attempt to automate proofs
nipkow@23483
   674
of positivity/negativity needed for @{text field_simps}. Have not added @{text
nipkow@23482
   675
sign_simps} to @{text field_simps} because the former can lead to case
nipkow@23482
   676
explosions. *}
paulson@14288
   677
nipkow@29833
   678
lemmas sign_simps[noatp] = group_simps
nipkow@23482
   679
  zero_less_mult_iff  mult_less_0_iff
paulson@14288
   680
nipkow@23482
   681
(* Only works once linear arithmetic is installed:
nipkow@23482
   682
text{*An example:*}
haftmann@35028
   683
lemma fixes a b c d e f :: "'a::linordered_field"
nipkow@23482
   684
shows "\<lbrakk>a>b; c<d; e<f; 0 < u \<rbrakk> \<Longrightarrow>
nipkow@23482
   685
 ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) <
nipkow@23482
   686
 ((e-f)*(a-b)*(c-d))/((e-f)*(a-b)*(c-d)) + u"
nipkow@23482
   687
apply(subgoal_tac "(c-d)*(e-f)*(a-b) > 0")
nipkow@23482
   688
 prefer 2 apply(simp add:sign_simps)
nipkow@23482
   689
apply(subgoal_tac "(c-d)*(e-f)*(a-b)*u > 0")
nipkow@23482
   690
 prefer 2 apply(simp add:sign_simps)
nipkow@23482
   691
apply(simp add:field_simps)
avigad@16775
   692
done
nipkow@23482
   693
*)
avigad@16775
   694
wenzelm@23389
   695
avigad@16775
   696
subsection{*Division and Signs*}
avigad@16775
   697
avigad@16775
   698
lemma zero_less_divide_iff:
haftmann@35028
   699
     "((0::'a::{linordered_field,division_by_zero}) < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
avigad@16775
   700
by (simp add: divide_inverse zero_less_mult_iff)
avigad@16775
   701
avigad@16775
   702
lemma divide_less_0_iff:
haftmann@35028
   703
     "(a/b < (0::'a::{linordered_field,division_by_zero})) = 
avigad@16775
   704
      (0 < a & b < 0 | a < 0 & 0 < b)"
avigad@16775
   705
by (simp add: divide_inverse mult_less_0_iff)
avigad@16775
   706
avigad@16775
   707
lemma zero_le_divide_iff:
haftmann@35028
   708
     "((0::'a::{linordered_field,division_by_zero}) \<le> a/b) =
avigad@16775
   709
      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
avigad@16775
   710
by (simp add: divide_inverse zero_le_mult_iff)
avigad@16775
   711
avigad@16775
   712
lemma divide_le_0_iff:
haftmann@35028
   713
     "(a/b \<le> (0::'a::{linordered_field,division_by_zero})) =
avigad@16775
   714
      (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
avigad@16775
   715
by (simp add: divide_inverse mult_le_0_iff)
avigad@16775
   716
paulson@24286
   717
lemma divide_eq_0_iff [simp,noatp]:
avigad@16775
   718
     "(a/b = 0) = (a=0 | b=(0::'a::{field,division_by_zero}))"
nipkow@23482
   719
by (simp add: divide_inverse)
avigad@16775
   720
nipkow@23482
   721
lemma divide_pos_pos:
haftmann@35028
   722
  "0 < (x::'a::linordered_field) ==> 0 < y ==> 0 < x / y"
nipkow@23482
   723
by(simp add:field_simps)
nipkow@23482
   724
avigad@16775
   725
nipkow@23482
   726
lemma divide_nonneg_pos:
haftmann@35028
   727
  "0 <= (x::'a::linordered_field) ==> 0 < y ==> 0 <= x / y"
nipkow@23482
   728
by(simp add:field_simps)
avigad@16775
   729
nipkow@23482
   730
lemma divide_neg_pos:
haftmann@35028
   731
  "(x::'a::linordered_field) < 0 ==> 0 < y ==> x / y < 0"
nipkow@23482
   732
by(simp add:field_simps)
avigad@16775
   733
nipkow@23482
   734
lemma divide_nonpos_pos:
haftmann@35028
   735
  "(x::'a::linordered_field) <= 0 ==> 0 < y ==> x / y <= 0"
nipkow@23482
   736
by(simp add:field_simps)
avigad@16775
   737
nipkow@23482
   738
lemma divide_pos_neg:
haftmann@35028
   739
  "0 < (x::'a::linordered_field) ==> y < 0 ==> x / y < 0"
nipkow@23482
   740
by(simp add:field_simps)
avigad@16775
   741
nipkow@23482
   742
lemma divide_nonneg_neg:
haftmann@35028
   743
  "0 <= (x::'a::linordered_field) ==> y < 0 ==> x / y <= 0" 
nipkow@23482
   744
by(simp add:field_simps)
avigad@16775
   745
nipkow@23482
   746
lemma divide_neg_neg:
haftmann@35028
   747
  "(x::'a::linordered_field) < 0 ==> y < 0 ==> 0 < x / y"
nipkow@23482
   748
by(simp add:field_simps)
avigad@16775
   749
nipkow@23482
   750
lemma divide_nonpos_neg:
haftmann@35028
   751
  "(x::'a::linordered_field) <= 0 ==> y < 0 ==> 0 <= x / y"
nipkow@23482
   752
by(simp add:field_simps)
paulson@15234
   753
wenzelm@23389
   754
paulson@14288
   755
subsection{*Cancellation Laws for Division*}
paulson@14288
   756
paulson@24286
   757
lemma divide_cancel_right [simp,noatp]:
paulson@14288
   758
     "(a/c = b/c) = (c = 0 | a = (b::'a::{field,division_by_zero}))"
nipkow@23482
   759
apply (cases "c=0", simp)
nipkow@23496
   760
apply (simp add: divide_inverse)
paulson@14288
   761
done
paulson@14288
   762
paulson@24286
   763
lemma divide_cancel_left [simp,noatp]:
paulson@14288
   764
     "(c/a = c/b) = (c = 0 | a = (b::'a::{field,division_by_zero}))" 
nipkow@23482
   765
apply (cases "c=0", simp)
nipkow@23496
   766
apply (simp add: divide_inverse)
paulson@14288
   767
done
paulson@14288
   768
wenzelm@23389
   769
paulson@14353
   770
subsection {* Division and the Number One *}
paulson@14353
   771
paulson@14353
   772
text{*Simplify expressions equated with 1*}
paulson@24286
   773
lemma divide_eq_1_iff [simp,noatp]:
paulson@14353
   774
     "(a/b = 1) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
nipkow@23482
   775
apply (cases "b=0", simp)
nipkow@23482
   776
apply (simp add: right_inverse_eq)
paulson@14353
   777
done
paulson@14353
   778
paulson@24286
   779
lemma one_eq_divide_iff [simp,noatp]:
paulson@14353
   780
     "(1 = a/b) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
nipkow@23482
   781
by (simp add: eq_commute [of 1])
paulson@14353
   782
paulson@24286
   783
lemma zero_eq_1_divide_iff [simp,noatp]:
haftmann@35028
   784
     "((0::'a::{linordered_field,division_by_zero}) = 1/a) = (a = 0)"
nipkow@23482
   785
apply (cases "a=0", simp)
nipkow@23482
   786
apply (auto simp add: nonzero_eq_divide_eq)
paulson@14353
   787
done
paulson@14353
   788
paulson@24286
   789
lemma one_divide_eq_0_iff [simp,noatp]:
haftmann@35028
   790
     "(1/a = (0::'a::{linordered_field,division_by_zero})) = (a = 0)"
nipkow@23482
   791
apply (cases "a=0", simp)
nipkow@23482
   792
apply (insert zero_neq_one [THEN not_sym])
nipkow@23482
   793
apply (auto simp add: nonzero_divide_eq_eq)
paulson@14353
   794
done
paulson@14353
   795
paulson@14353
   796
text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
paulson@18623
   797
lemmas zero_less_divide_1_iff = zero_less_divide_iff [of 1, simplified]
paulson@18623
   798
lemmas divide_less_0_1_iff = divide_less_0_iff [of 1, simplified]
paulson@18623
   799
lemmas zero_le_divide_1_iff = zero_le_divide_iff [of 1, simplified]
paulson@18623
   800
lemmas divide_le_0_1_iff = divide_le_0_iff [of 1, simplified]
paulson@17085
   801
nipkow@29833
   802
declare zero_less_divide_1_iff [simp,noatp]
paulson@24286
   803
declare divide_less_0_1_iff [simp,noatp]
nipkow@29833
   804
declare zero_le_divide_1_iff [simp,noatp]
paulson@24286
   805
declare divide_le_0_1_iff [simp,noatp]
paulson@14353
   806
wenzelm@23389
   807
paulson@14293
   808
subsection {* Ordering Rules for Division *}
paulson@14293
   809
paulson@14293
   810
lemma divide_strict_right_mono:
haftmann@35028
   811
     "[|a < b; 0 < c|] ==> a / c < b / (c::'a::linordered_field)"
paulson@14293
   812
by (simp add: order_less_imp_not_eq2 divide_inverse mult_strict_right_mono 
nipkow@23482
   813
              positive_imp_inverse_positive)
paulson@14293
   814
paulson@14293
   815
lemma divide_right_mono:
haftmann@35028
   816
     "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/(c::'a::{linordered_field,division_by_zero})"
nipkow@23482
   817
by (force simp add: divide_strict_right_mono order_le_less)
paulson@14293
   818
haftmann@35028
   819
lemma divide_right_mono_neg: "(a::'a::{division_by_zero,linordered_field}) <= b 
avigad@16775
   820
    ==> c <= 0 ==> b / c <= a / c"
nipkow@23482
   821
apply (drule divide_right_mono [of _ _ "- c"])
nipkow@23482
   822
apply auto
avigad@16775
   823
done
avigad@16775
   824
avigad@16775
   825
lemma divide_strict_right_mono_neg:
haftmann@35028
   826
     "[|b < a; c < 0|] ==> a / c < b / (c::'a::linordered_field)"
nipkow@23482
   827
apply (drule divide_strict_right_mono [of _ _ "-c"], simp)
nipkow@23482
   828
apply (simp add: order_less_imp_not_eq nonzero_minus_divide_right [symmetric])
avigad@16775
   829
done
paulson@14293
   830
paulson@14293
   831
text{*The last premise ensures that @{term a} and @{term b} 
paulson@14293
   832
      have the same sign*}
paulson@14293
   833
lemma divide_strict_left_mono:
haftmann@35028
   834
  "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / (b::'a::linordered_field)"
nipkow@23482
   835
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono)
paulson@14293
   836
paulson@14293
   837
lemma divide_left_mono:
haftmann@35028
   838
  "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / (b::'a::linordered_field)"
nipkow@23482
   839
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_right_mono)
paulson@14293
   840
haftmann@35028
   841
lemma divide_left_mono_neg: "(a::'a::{division_by_zero,linordered_field}) <= b 
avigad@16775
   842
    ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
avigad@16775
   843
  apply (drule divide_left_mono [of _ _ "- c"])
avigad@16775
   844
  apply (auto simp add: mult_commute)
avigad@16775
   845
done
avigad@16775
   846
paulson@14293
   847
lemma divide_strict_left_mono_neg:
haftmann@35028
   848
  "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / (b::'a::linordered_field)"
nipkow@23482
   849
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono_neg)
nipkow@23482
   850
paulson@14293
   851
avigad@16775
   852
text{*Simplify quotients that are compared with the value 1.*}
avigad@16775
   853
paulson@24286
   854
lemma le_divide_eq_1 [noatp]:
haftmann@35028
   855
  fixes a :: "'a :: {linordered_field,division_by_zero}"
avigad@16775
   856
  shows "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
avigad@16775
   857
by (auto simp add: le_divide_eq)
avigad@16775
   858
paulson@24286
   859
lemma divide_le_eq_1 [noatp]:
haftmann@35028
   860
  fixes a :: "'a :: {linordered_field,division_by_zero}"
avigad@16775
   861
  shows "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
avigad@16775
   862
by (auto simp add: divide_le_eq)
avigad@16775
   863
paulson@24286
   864
lemma less_divide_eq_1 [noatp]:
haftmann@35028
   865
  fixes a :: "'a :: {linordered_field,division_by_zero}"
avigad@16775
   866
  shows "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
avigad@16775
   867
by (auto simp add: less_divide_eq)
avigad@16775
   868
paulson@24286
   869
lemma divide_less_eq_1 [noatp]:
haftmann@35028
   870
  fixes a :: "'a :: {linordered_field,division_by_zero}"
avigad@16775
   871
  shows "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
avigad@16775
   872
by (auto simp add: divide_less_eq)
avigad@16775
   873
wenzelm@23389
   874
avigad@16775
   875
subsection{*Conditional Simplification Rules: No Case Splits*}
avigad@16775
   876
paulson@24286
   877
lemma le_divide_eq_1_pos [simp,noatp]:
haftmann@35028
   878
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   879
  shows "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
avigad@16775
   880
by (auto simp add: le_divide_eq)
avigad@16775
   881
paulson@24286
   882
lemma le_divide_eq_1_neg [simp,noatp]:
haftmann@35028
   883
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   884
  shows "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
avigad@16775
   885
by (auto simp add: le_divide_eq)
avigad@16775
   886
paulson@24286
   887
lemma divide_le_eq_1_pos [simp,noatp]:
haftmann@35028
   888
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   889
  shows "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
avigad@16775
   890
by (auto simp add: divide_le_eq)
avigad@16775
   891
paulson@24286
   892
lemma divide_le_eq_1_neg [simp,noatp]:
haftmann@35028
   893
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   894
  shows "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
avigad@16775
   895
by (auto simp add: divide_le_eq)
avigad@16775
   896
paulson@24286
   897
lemma less_divide_eq_1_pos [simp,noatp]:
haftmann@35028
   898
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   899
  shows "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
avigad@16775
   900
by (auto simp add: less_divide_eq)
avigad@16775
   901
paulson@24286
   902
lemma less_divide_eq_1_neg [simp,noatp]:
haftmann@35028
   903
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   904
  shows "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
avigad@16775
   905
by (auto simp add: less_divide_eq)
avigad@16775
   906
paulson@24286
   907
lemma divide_less_eq_1_pos [simp,noatp]:
haftmann@35028
   908
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   909
  shows "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
paulson@18649
   910
by (auto simp add: divide_less_eq)
paulson@18649
   911
paulson@24286
   912
lemma divide_less_eq_1_neg [simp,noatp]:
haftmann@35028
   913
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   914
  shows "a < 0 \<Longrightarrow> b/a < 1 <-> a < b"
avigad@16775
   915
by (auto simp add: divide_less_eq)
avigad@16775
   916
paulson@24286
   917
lemma eq_divide_eq_1 [simp,noatp]:
haftmann@35028
   918
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   919
  shows "(1 = b/a) = ((a \<noteq> 0 & a = b))"
avigad@16775
   920
by (auto simp add: eq_divide_eq)
avigad@16775
   921
paulson@24286
   922
lemma divide_eq_eq_1 [simp,noatp]:
haftmann@35028
   923
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   924
  shows "(b/a = 1) = ((a \<noteq> 0 & a = b))"
avigad@16775
   925
by (auto simp add: divide_eq_eq)
avigad@16775
   926
wenzelm@23389
   927
avigad@16775
   928
subsection {* Reasoning about inequalities with division *}
avigad@16775
   929
haftmann@35028
   930
lemma mult_imp_div_pos_le: "0 < (y::'a::linordered_field) ==> x <= z * y ==>
haftmann@33319
   931
    x / y <= z"
haftmann@33319
   932
by (subst pos_divide_le_eq, assumption+)
avigad@16775
   933
haftmann@35028
   934
lemma mult_imp_le_div_pos: "0 < (y::'a::linordered_field) ==> z * y <= x ==>
nipkow@23482
   935
    z <= x / y"
nipkow@23482
   936
by(simp add:field_simps)
avigad@16775
   937
haftmann@35028
   938
lemma mult_imp_div_pos_less: "0 < (y::'a::linordered_field) ==> x < z * y ==>
avigad@16775
   939
    x / y < z"
nipkow@23482
   940
by(simp add:field_simps)
avigad@16775
   941
haftmann@35028
   942
lemma mult_imp_less_div_pos: "0 < (y::'a::linordered_field) ==> z * y < x ==>
avigad@16775
   943
    z < x / y"
nipkow@23482
   944
by(simp add:field_simps)
avigad@16775
   945
haftmann@35028
   946
lemma frac_le: "(0::'a::linordered_field) <= x ==> 
avigad@16775
   947
    x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
avigad@16775
   948
  apply (rule mult_imp_div_pos_le)
haftmann@25230
   949
  apply simp
haftmann@25230
   950
  apply (subst times_divide_eq_left)
avigad@16775
   951
  apply (rule mult_imp_le_div_pos, assumption)
avigad@16775
   952
  apply (rule mult_mono)
avigad@16775
   953
  apply simp_all
paulson@14293
   954
done
paulson@14293
   955
haftmann@35028
   956
lemma frac_less: "(0::'a::linordered_field) <= x ==> 
avigad@16775
   957
    x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
avigad@16775
   958
  apply (rule mult_imp_div_pos_less)
haftmann@33319
   959
  apply simp
haftmann@33319
   960
  apply (subst times_divide_eq_left)
avigad@16775
   961
  apply (rule mult_imp_less_div_pos, assumption)
avigad@16775
   962
  apply (erule mult_less_le_imp_less)
avigad@16775
   963
  apply simp_all
avigad@16775
   964
done
avigad@16775
   965
haftmann@35028
   966
lemma frac_less2: "(0::'a::linordered_field) < x ==> 
avigad@16775
   967
    x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
avigad@16775
   968
  apply (rule mult_imp_div_pos_less)
avigad@16775
   969
  apply simp_all
haftmann@33319
   970
  apply (subst times_divide_eq_left)
avigad@16775
   971
  apply (rule mult_imp_less_div_pos, assumption)
avigad@16775
   972
  apply (erule mult_le_less_imp_less)
avigad@16775
   973
  apply simp_all
avigad@16775
   974
done
avigad@16775
   975
avigad@16775
   976
text{*It's not obvious whether these should be simprules or not. 
avigad@16775
   977
  Their effect is to gather terms into one big fraction, like
avigad@16775
   978
  a*b*c / x*y*z. The rationale for that is unclear, but many proofs 
avigad@16775
   979
  seem to need them.*}
avigad@16775
   980
avigad@16775
   981
declare times_divide_eq [simp]
paulson@14293
   982
wenzelm@23389
   983
paulson@14293
   984
subsection {* Ordered Fields are Dense *}
paulson@14293
   985
haftmann@35028
   986
lemma less_half_sum: "a < b ==> a < (a+b) / (1+1::'a::linordered_field)"
nipkow@23482
   987
by (simp add: field_simps zero_less_two)
paulson@14293
   988
haftmann@35028
   989
lemma gt_half_sum: "a < b ==> (a+b)/(1+1::'a::linordered_field) < b"
nipkow@23482
   990
by (simp add: field_simps zero_less_two)
paulson@14293
   991
haftmann@35028
   992
instance linordered_field < dense_linorder
haftmann@24422
   993
proof
haftmann@24422
   994
  fix x y :: 'a
haftmann@24422
   995
  have "x < x + 1" by simp
haftmann@24422
   996
  then show "\<exists>y. x < y" .. 
haftmann@24422
   997
  have "x - 1 < x" by simp
haftmann@24422
   998
  then show "\<exists>y. y < x" ..
haftmann@24422
   999
  show "x < y \<Longrightarrow> \<exists>z>x. z < y" by (blast intro!: less_half_sum gt_half_sum)
haftmann@24422
  1000
qed
paulson@14293
  1001
paulson@15234
  1002
paulson@14293
  1003
subsection {* Absolute Value *}
paulson@14293
  1004
paulson@14294
  1005
lemma nonzero_abs_inverse:
haftmann@35028
  1006
     "a \<noteq> 0 ==> abs (inverse (a::'a::linordered_field)) = inverse (abs a)"
paulson@14294
  1007
apply (auto simp add: linorder_neq_iff abs_if nonzero_inverse_minus_eq 
paulson@14294
  1008
                      negative_imp_inverse_negative)
paulson@14294
  1009
apply (blast intro: positive_imp_inverse_positive elim: order_less_asym) 
paulson@14294
  1010
done
paulson@14294
  1011
paulson@14294
  1012
lemma abs_inverse [simp]:
haftmann@35028
  1013
     "abs (inverse (a::'a::{linordered_field,division_by_zero})) = 
paulson@14294
  1014
      inverse (abs a)"
haftmann@21328
  1015
apply (cases "a=0", simp) 
paulson@14294
  1016
apply (simp add: nonzero_abs_inverse) 
paulson@14294
  1017
done
paulson@14294
  1018
paulson@14294
  1019
lemma nonzero_abs_divide:
haftmann@35028
  1020
     "b \<noteq> 0 ==> abs (a / (b::'a::linordered_field)) = abs a / abs b"
paulson@14294
  1021
by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
paulson@14294
  1022
paulson@15234
  1023
lemma abs_divide [simp]:
haftmann@35028
  1024
     "abs (a / (b::'a::{linordered_field,division_by_zero})) = abs a / abs b"
haftmann@21328
  1025
apply (cases "b=0", simp) 
paulson@14294
  1026
apply (simp add: nonzero_abs_divide) 
paulson@14294
  1027
done
paulson@14294
  1028
haftmann@35028
  1029
lemma abs_div_pos: "(0::'a::{division_by_zero,linordered_field}) < y ==> 
haftmann@25304
  1030
    abs x / y = abs (x / y)"
haftmann@25304
  1031
  apply (subst abs_divide)
haftmann@25304
  1032
  apply (simp add: order_less_imp_le)
haftmann@25304
  1033
done
avigad@16775
  1034
haftmann@33364
  1035
code_modulename SML
haftmann@35050
  1036
  Fields Arith
haftmann@33364
  1037
haftmann@33364
  1038
code_modulename OCaml
haftmann@35050
  1039
  Fields Arith
haftmann@33364
  1040
haftmann@33364
  1041
code_modulename Haskell
haftmann@35050
  1042
  Fields Arith
haftmann@33364
  1043
paulson@14265
  1044
end