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