src/HOL/Fields.thy
author haftmann
Wed Feb 10 08:49:26 2010 +0100 (2010-02-10)
changeset 35084 e25eedfc15ce
parent 35050 9f841f20dca6
child 35090 88cc65ae046e
permissions -rw-r--r--
moved constants inverse and divide to Ring.thy
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
huffman@30630
    68
lemma nonzero_mult_divide_mult_cancel_left [simp, noatp]:
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
huffman@30630
    79
lemma nonzero_mult_divide_mult_cancel_right [simp, noatp]:
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. *}
huffman@30630
    93
lemmas times_divide_eq [noatp] = 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
huffman@30630
   109
lemma nonzero_mult_divide_cancel_right [simp, noatp]:
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
huffman@30630
   113
lemma nonzero_mult_divide_cancel_left [simp, noatp]:
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
huffman@30630
   117
lemma nonzero_divide_mult_cancel_right [simp, noatp]:
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
huffman@30630
   121
lemma nonzero_divide_mult_cancel_left [simp, noatp]:
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
huffman@30630
   125
lemma nonzero_mult_divide_mult_cancel_left2 [simp, noatp]:
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
huffman@30630
   129
lemma nonzero_mult_divide_mult_cancel_right2 [simp, noatp]:
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
huffman@30630
   142
lemma divide_minus_left [simp, noatp]: "(-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
huffman@30630
   186
lemmas field_eq_simps[noatp] = 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
paulson@14377
   233
  assume "a=0" thus ?thesis by (simp add: inverse_zero)
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")
nipkow@23413
   286
apply (simp_all add: nonzero_mult_divide_mult_cancel_left)
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")
nipkow@23413
   292
apply (simp_all add: nonzero_mult_divide_mult_cancel_right)
paulson@14321
   293
done
nipkow@23413
   294
paulson@24286
   295
lemma divide_divide_eq_right [simp,noatp]:
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
paulson@24286
   299
lemma divide_divide_eq_left [simp,noatp]:
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
paulson@24427
   306
lemma mult_divide_mult_cancel_left_if[simp,noatp]:
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
huffman@30630
   317
lemma divide_minus_right [simp, noatp]:
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" 
paulson@14268
   342
    by (simp add: a_gt_0 [THEN order_less_imp_not_eq2] zero_less_one)
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.*}
paulson@24286
   443
lemma inverse_less_iff_less [simp,noatp]:
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
paulson@24286
   451
lemma inverse_le_iff_le [simp,noatp]:
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
paulson@24286
   485
lemma inverse_less_iff_less_neg [simp,noatp]:
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
paulson@24286
   496
lemma inverse_le_iff_le_neg [simp,noatp]:
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}))"
paulson@14365
   527
by (force simp add: order_le_less one_less_inverse_iff zero_less_one 
paulson@14365
   528
                    eq_commute [of 1]) 
paulson@14365
   529
paulson@14365
   530
lemma inverse_less_1_iff:
haftmann@35028
   531
  "(inverse x < 1) = (x \<le> 0 | 1 < (x::'a::{linordered_field,division_by_zero}))"
paulson@14365
   532
by (simp add: linorder_not_le [symmetric] one_le_inverse_iff) 
paulson@14365
   533
paulson@14365
   534
lemma inverse_le_1_iff:
haftmann@35028
   535
  "(inverse x \<le> 1) = (x \<le> 0 | 1 \<le> (x::'a::{linordered_field,division_by_zero}))"
paulson@14365
   536
by (simp add: linorder_not_less [symmetric] one_less_inverse_iff) 
paulson@14365
   537
wenzelm@23389
   538
paulson@14288
   539
subsection{*Simplification of Inequalities Involving Literal Divisors*}
paulson@14288
   540
haftmann@35028
   541
lemma pos_le_divide_eq: "0 < (c::'a::linordered_field) ==> (a \<le> b/c) = (a*c \<le> b)"
paulson@14288
   542
proof -
paulson@14288
   543
  assume less: "0<c"
paulson@14288
   544
  hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
paulson@14288
   545
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
   546
  also have "... = (a*c \<le> b)"
paulson@14288
   547
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
   548
  finally show ?thesis .
paulson@14288
   549
qed
paulson@14288
   550
haftmann@35028
   551
lemma neg_le_divide_eq: "c < (0::'a::linordered_field) ==> (a \<le> b/c) = (b \<le> a*c)"
paulson@14288
   552
proof -
paulson@14288
   553
  assume less: "c<0"
paulson@14288
   554
  hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
paulson@14288
   555
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
   556
  also have "... = (b \<le> a*c)"
paulson@14288
   557
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
   558
  finally show ?thesis .
paulson@14288
   559
qed
paulson@14288
   560
paulson@14288
   561
lemma le_divide_eq:
paulson@14288
   562
  "(a \<le> b/c) = 
paulson@14288
   563
   (if 0 < c then a*c \<le> b
paulson@14288
   564
             else if c < 0 then b \<le> a*c
haftmann@35028
   565
             else  a \<le> (0::'a::{linordered_field,division_by_zero}))"
haftmann@21328
   566
apply (cases "c=0", simp) 
paulson@14288
   567
apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
paulson@14288
   568
done
paulson@14288
   569
haftmann@35028
   570
lemma pos_divide_le_eq: "0 < (c::'a::linordered_field) ==> (b/c \<le> a) = (b \<le> a*c)"
paulson@14288
   571
proof -
paulson@14288
   572
  assume less: "0<c"
paulson@14288
   573
  hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
paulson@14288
   574
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
   575
  also have "... = (b \<le> a*c)"
paulson@14288
   576
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
   577
  finally show ?thesis .
paulson@14288
   578
qed
paulson@14288
   579
haftmann@35028
   580
lemma neg_divide_le_eq: "c < (0::'a::linordered_field) ==> (b/c \<le> a) = (a*c \<le> b)"
paulson@14288
   581
proof -
paulson@14288
   582
  assume less: "c<0"
paulson@14288
   583
  hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
paulson@14288
   584
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
   585
  also have "... = (a*c \<le> b)"
paulson@14288
   586
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
   587
  finally show ?thesis .
paulson@14288
   588
qed
paulson@14288
   589
paulson@14288
   590
lemma divide_le_eq:
paulson@14288
   591
  "(b/c \<le> a) = 
paulson@14288
   592
   (if 0 < c then b \<le> a*c
paulson@14288
   593
             else if c < 0 then a*c \<le> b
haftmann@35028
   594
             else 0 \<le> (a::'a::{linordered_field,division_by_zero}))"
haftmann@21328
   595
apply (cases "c=0", simp) 
paulson@14288
   596
apply (force simp add: pos_divide_le_eq neg_divide_le_eq linorder_neq_iff) 
paulson@14288
   597
done
paulson@14288
   598
paulson@14288
   599
lemma pos_less_divide_eq:
haftmann@35028
   600
     "0 < (c::'a::linordered_field) ==> (a < b/c) = (a*c < b)"
paulson@14288
   601
proof -
paulson@14288
   602
  assume less: "0<c"
paulson@14288
   603
  hence "(a < b/c) = (a*c < (b/c)*c)"
paulson@15234
   604
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
   605
  also have "... = (a*c < b)"
paulson@14288
   606
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
   607
  finally show ?thesis .
paulson@14288
   608
qed
paulson@14288
   609
paulson@14288
   610
lemma neg_less_divide_eq:
haftmann@35028
   611
 "c < (0::'a::linordered_field) ==> (a < b/c) = (b < a*c)"
paulson@14288
   612
proof -
paulson@14288
   613
  assume less: "c<0"
paulson@14288
   614
  hence "(a < b/c) = ((b/c)*c < a*c)"
paulson@15234
   615
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
   616
  also have "... = (b < a*c)"
paulson@14288
   617
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
   618
  finally show ?thesis .
paulson@14288
   619
qed
paulson@14288
   620
paulson@14288
   621
lemma less_divide_eq:
paulson@14288
   622
  "(a < b/c) = 
paulson@14288
   623
   (if 0 < c then a*c < b
paulson@14288
   624
             else if c < 0 then b < a*c
haftmann@35028
   625
             else  a < (0::'a::{linordered_field,division_by_zero}))"
haftmann@21328
   626
apply (cases "c=0", simp) 
paulson@14288
   627
apply (force simp add: pos_less_divide_eq neg_less_divide_eq linorder_neq_iff) 
paulson@14288
   628
done
paulson@14288
   629
paulson@14288
   630
lemma pos_divide_less_eq:
haftmann@35028
   631
     "0 < (c::'a::linordered_field) ==> (b/c < a) = (b < a*c)"
paulson@14288
   632
proof -
paulson@14288
   633
  assume less: "0<c"
paulson@14288
   634
  hence "(b/c < a) = ((b/c)*c < a*c)"
paulson@15234
   635
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
   636
  also have "... = (b < a*c)"
paulson@14288
   637
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
   638
  finally show ?thesis .
paulson@14288
   639
qed
paulson@14288
   640
paulson@14288
   641
lemma neg_divide_less_eq:
haftmann@35028
   642
 "c < (0::'a::linordered_field) ==> (b/c < a) = (a*c < b)"
paulson@14288
   643
proof -
paulson@14288
   644
  assume less: "c<0"
paulson@14288
   645
  hence "(b/c < a) = (a*c < (b/c)*c)"
paulson@15234
   646
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
   647
  also have "... = (a*c < b)"
paulson@14288
   648
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
   649
  finally show ?thesis .
paulson@14288
   650
qed
paulson@14288
   651
paulson@14288
   652
lemma divide_less_eq:
paulson@14288
   653
  "(b/c < a) = 
paulson@14288
   654
   (if 0 < c then b < a*c
paulson@14288
   655
             else if c < 0 then a*c < b
haftmann@35028
   656
             else 0 < (a::'a::{linordered_field,division_by_zero}))"
haftmann@21328
   657
apply (cases "c=0", simp) 
paulson@14288
   658
apply (force simp add: pos_divide_less_eq neg_divide_less_eq linorder_neq_iff) 
paulson@14288
   659
done
paulson@14288
   660
nipkow@23482
   661
nipkow@23482
   662
subsection{*Field simplification*}
nipkow@23482
   663
nipkow@29667
   664
text{* Lemmas @{text field_simps} multiply with denominators in in(equations)
nipkow@29667
   665
if they can be proved to be non-zero (for equations) or positive/negative
nipkow@29667
   666
(for inequations). Can be too aggressive and is therefore separate from the
nipkow@29667
   667
more benign @{text algebra_simps}. *}
paulson@14288
   668
nipkow@29833
   669
lemmas field_simps[noatp] = field_eq_simps
nipkow@23482
   670
  (* multiply ineqn *)
nipkow@23482
   671
  pos_divide_less_eq neg_divide_less_eq
nipkow@23482
   672
  pos_less_divide_eq neg_less_divide_eq
nipkow@23482
   673
  pos_divide_le_eq neg_divide_le_eq
nipkow@23482
   674
  pos_le_divide_eq neg_le_divide_eq
paulson@14288
   675
nipkow@23482
   676
text{* Lemmas @{text sign_simps} is a first attempt to automate proofs
nipkow@23483
   677
of positivity/negativity needed for @{text field_simps}. Have not added @{text
nipkow@23482
   678
sign_simps} to @{text field_simps} because the former can lead to case
nipkow@23482
   679
explosions. *}
paulson@14288
   680
nipkow@29833
   681
lemmas sign_simps[noatp] = group_simps
nipkow@23482
   682
  zero_less_mult_iff  mult_less_0_iff
paulson@14288
   683
nipkow@23482
   684
(* Only works once linear arithmetic is installed:
nipkow@23482
   685
text{*An example:*}
haftmann@35028
   686
lemma fixes a b c d e f :: "'a::linordered_field"
nipkow@23482
   687
shows "\<lbrakk>a>b; c<d; e<f; 0 < u \<rbrakk> \<Longrightarrow>
nipkow@23482
   688
 ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) <
nipkow@23482
   689
 ((e-f)*(a-b)*(c-d))/((e-f)*(a-b)*(c-d)) + u"
nipkow@23482
   690
apply(subgoal_tac "(c-d)*(e-f)*(a-b) > 0")
nipkow@23482
   691
 prefer 2 apply(simp add:sign_simps)
nipkow@23482
   692
apply(subgoal_tac "(c-d)*(e-f)*(a-b)*u > 0")
nipkow@23482
   693
 prefer 2 apply(simp add:sign_simps)
nipkow@23482
   694
apply(simp add:field_simps)
avigad@16775
   695
done
nipkow@23482
   696
*)
avigad@16775
   697
wenzelm@23389
   698
avigad@16775
   699
subsection{*Division and Signs*}
avigad@16775
   700
avigad@16775
   701
lemma zero_less_divide_iff:
haftmann@35028
   702
     "((0::'a::{linordered_field,division_by_zero}) < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
avigad@16775
   703
by (simp add: divide_inverse zero_less_mult_iff)
avigad@16775
   704
avigad@16775
   705
lemma divide_less_0_iff:
haftmann@35028
   706
     "(a/b < (0::'a::{linordered_field,division_by_zero})) = 
avigad@16775
   707
      (0 < a & b < 0 | a < 0 & 0 < b)"
avigad@16775
   708
by (simp add: divide_inverse mult_less_0_iff)
avigad@16775
   709
avigad@16775
   710
lemma zero_le_divide_iff:
haftmann@35028
   711
     "((0::'a::{linordered_field,division_by_zero}) \<le> a/b) =
avigad@16775
   712
      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
avigad@16775
   713
by (simp add: divide_inverse zero_le_mult_iff)
avigad@16775
   714
avigad@16775
   715
lemma divide_le_0_iff:
haftmann@35028
   716
     "(a/b \<le> (0::'a::{linordered_field,division_by_zero})) =
avigad@16775
   717
      (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
avigad@16775
   718
by (simp add: divide_inverse mult_le_0_iff)
avigad@16775
   719
paulson@24286
   720
lemma divide_eq_0_iff [simp,noatp]:
avigad@16775
   721
     "(a/b = 0) = (a=0 | b=(0::'a::{field,division_by_zero}))"
nipkow@23482
   722
by (simp add: divide_inverse)
avigad@16775
   723
nipkow@23482
   724
lemma divide_pos_pos:
haftmann@35028
   725
  "0 < (x::'a::linordered_field) ==> 0 < y ==> 0 < x / y"
nipkow@23482
   726
by(simp add:field_simps)
nipkow@23482
   727
avigad@16775
   728
nipkow@23482
   729
lemma divide_nonneg_pos:
haftmann@35028
   730
  "0 <= (x::'a::linordered_field) ==> 0 < y ==> 0 <= x / y"
nipkow@23482
   731
by(simp add:field_simps)
avigad@16775
   732
nipkow@23482
   733
lemma divide_neg_pos:
haftmann@35028
   734
  "(x::'a::linordered_field) < 0 ==> 0 < y ==> x / y < 0"
nipkow@23482
   735
by(simp add:field_simps)
avigad@16775
   736
nipkow@23482
   737
lemma divide_nonpos_pos:
haftmann@35028
   738
  "(x::'a::linordered_field) <= 0 ==> 0 < y ==> x / y <= 0"
nipkow@23482
   739
by(simp add:field_simps)
avigad@16775
   740
nipkow@23482
   741
lemma divide_pos_neg:
haftmann@35028
   742
  "0 < (x::'a::linordered_field) ==> y < 0 ==> x / y < 0"
nipkow@23482
   743
by(simp add:field_simps)
avigad@16775
   744
nipkow@23482
   745
lemma divide_nonneg_neg:
haftmann@35028
   746
  "0 <= (x::'a::linordered_field) ==> y < 0 ==> x / y <= 0" 
nipkow@23482
   747
by(simp add:field_simps)
avigad@16775
   748
nipkow@23482
   749
lemma divide_neg_neg:
haftmann@35028
   750
  "(x::'a::linordered_field) < 0 ==> y < 0 ==> 0 < x / y"
nipkow@23482
   751
by(simp add:field_simps)
avigad@16775
   752
nipkow@23482
   753
lemma divide_nonpos_neg:
haftmann@35028
   754
  "(x::'a::linordered_field) <= 0 ==> y < 0 ==> 0 <= x / y"
nipkow@23482
   755
by(simp add:field_simps)
paulson@15234
   756
wenzelm@23389
   757
paulson@14288
   758
subsection{*Cancellation Laws for Division*}
paulson@14288
   759
paulson@24286
   760
lemma divide_cancel_right [simp,noatp]:
paulson@14288
   761
     "(a/c = b/c) = (c = 0 | a = (b::'a::{field,division_by_zero}))"
nipkow@23482
   762
apply (cases "c=0", simp)
nipkow@23496
   763
apply (simp add: divide_inverse)
paulson@14288
   764
done
paulson@14288
   765
paulson@24286
   766
lemma divide_cancel_left [simp,noatp]:
paulson@14288
   767
     "(c/a = c/b) = (c = 0 | a = (b::'a::{field,division_by_zero}))" 
nipkow@23482
   768
apply (cases "c=0", simp)
nipkow@23496
   769
apply (simp add: divide_inverse)
paulson@14288
   770
done
paulson@14288
   771
wenzelm@23389
   772
paulson@14353
   773
subsection {* Division and the Number One *}
paulson@14353
   774
paulson@14353
   775
text{*Simplify expressions equated with 1*}
paulson@24286
   776
lemma divide_eq_1_iff [simp,noatp]:
paulson@14353
   777
     "(a/b = 1) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
nipkow@23482
   778
apply (cases "b=0", simp)
nipkow@23482
   779
apply (simp add: right_inverse_eq)
paulson@14353
   780
done
paulson@14353
   781
paulson@24286
   782
lemma one_eq_divide_iff [simp,noatp]:
paulson@14353
   783
     "(1 = a/b) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
nipkow@23482
   784
by (simp add: eq_commute [of 1])
paulson@14353
   785
paulson@24286
   786
lemma zero_eq_1_divide_iff [simp,noatp]:
haftmann@35028
   787
     "((0::'a::{linordered_field,division_by_zero}) = 1/a) = (a = 0)"
nipkow@23482
   788
apply (cases "a=0", simp)
nipkow@23482
   789
apply (auto simp add: nonzero_eq_divide_eq)
paulson@14353
   790
done
paulson@14353
   791
paulson@24286
   792
lemma one_divide_eq_0_iff [simp,noatp]:
haftmann@35028
   793
     "(1/a = (0::'a::{linordered_field,division_by_zero})) = (a = 0)"
nipkow@23482
   794
apply (cases "a=0", simp)
nipkow@23482
   795
apply (insert zero_neq_one [THEN not_sym])
nipkow@23482
   796
apply (auto simp add: nonzero_divide_eq_eq)
paulson@14353
   797
done
paulson@14353
   798
paulson@14353
   799
text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
paulson@18623
   800
lemmas zero_less_divide_1_iff = zero_less_divide_iff [of 1, simplified]
paulson@18623
   801
lemmas divide_less_0_1_iff = divide_less_0_iff [of 1, simplified]
paulson@18623
   802
lemmas zero_le_divide_1_iff = zero_le_divide_iff [of 1, simplified]
paulson@18623
   803
lemmas divide_le_0_1_iff = divide_le_0_iff [of 1, simplified]
paulson@17085
   804
nipkow@29833
   805
declare zero_less_divide_1_iff [simp,noatp]
paulson@24286
   806
declare divide_less_0_1_iff [simp,noatp]
nipkow@29833
   807
declare zero_le_divide_1_iff [simp,noatp]
paulson@24286
   808
declare divide_le_0_1_iff [simp,noatp]
paulson@14353
   809
wenzelm@23389
   810
paulson@14293
   811
subsection {* Ordering Rules for Division *}
paulson@14293
   812
paulson@14293
   813
lemma divide_strict_right_mono:
haftmann@35028
   814
     "[|a < b; 0 < c|] ==> a / c < b / (c::'a::linordered_field)"
paulson@14293
   815
by (simp add: order_less_imp_not_eq2 divide_inverse mult_strict_right_mono 
nipkow@23482
   816
              positive_imp_inverse_positive)
paulson@14293
   817
paulson@14293
   818
lemma divide_right_mono:
haftmann@35028
   819
     "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/(c::'a::{linordered_field,division_by_zero})"
nipkow@23482
   820
by (force simp add: divide_strict_right_mono order_le_less)
paulson@14293
   821
haftmann@35028
   822
lemma divide_right_mono_neg: "(a::'a::{division_by_zero,linordered_field}) <= b 
avigad@16775
   823
    ==> c <= 0 ==> b / c <= a / c"
nipkow@23482
   824
apply (drule divide_right_mono [of _ _ "- c"])
nipkow@23482
   825
apply auto
avigad@16775
   826
done
avigad@16775
   827
avigad@16775
   828
lemma divide_strict_right_mono_neg:
haftmann@35028
   829
     "[|b < a; c < 0|] ==> a / c < b / (c::'a::linordered_field)"
nipkow@23482
   830
apply (drule divide_strict_right_mono [of _ _ "-c"], simp)
nipkow@23482
   831
apply (simp add: order_less_imp_not_eq nonzero_minus_divide_right [symmetric])
avigad@16775
   832
done
paulson@14293
   833
paulson@14293
   834
text{*The last premise ensures that @{term a} and @{term b} 
paulson@14293
   835
      have the same sign*}
paulson@14293
   836
lemma divide_strict_left_mono:
haftmann@35028
   837
  "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / (b::'a::linordered_field)"
nipkow@23482
   838
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono)
paulson@14293
   839
paulson@14293
   840
lemma divide_left_mono:
haftmann@35028
   841
  "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / (b::'a::linordered_field)"
nipkow@23482
   842
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_right_mono)
paulson@14293
   843
haftmann@35028
   844
lemma divide_left_mono_neg: "(a::'a::{division_by_zero,linordered_field}) <= b 
avigad@16775
   845
    ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
avigad@16775
   846
  apply (drule divide_left_mono [of _ _ "- c"])
avigad@16775
   847
  apply (auto simp add: mult_commute)
avigad@16775
   848
done
avigad@16775
   849
paulson@14293
   850
lemma divide_strict_left_mono_neg:
haftmann@35028
   851
  "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / (b::'a::linordered_field)"
nipkow@23482
   852
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono_neg)
nipkow@23482
   853
paulson@14293
   854
avigad@16775
   855
text{*Simplify quotients that are compared with the value 1.*}
avigad@16775
   856
paulson@24286
   857
lemma le_divide_eq_1 [noatp]:
haftmann@35028
   858
  fixes a :: "'a :: {linordered_field,division_by_zero}"
avigad@16775
   859
  shows "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
avigad@16775
   860
by (auto simp add: le_divide_eq)
avigad@16775
   861
paulson@24286
   862
lemma divide_le_eq_1 [noatp]:
haftmann@35028
   863
  fixes a :: "'a :: {linordered_field,division_by_zero}"
avigad@16775
   864
  shows "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
avigad@16775
   865
by (auto simp add: divide_le_eq)
avigad@16775
   866
paulson@24286
   867
lemma less_divide_eq_1 [noatp]:
haftmann@35028
   868
  fixes a :: "'a :: {linordered_field,division_by_zero}"
avigad@16775
   869
  shows "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
avigad@16775
   870
by (auto simp add: less_divide_eq)
avigad@16775
   871
paulson@24286
   872
lemma divide_less_eq_1 [noatp]:
haftmann@35028
   873
  fixes a :: "'a :: {linordered_field,division_by_zero}"
avigad@16775
   874
  shows "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
avigad@16775
   875
by (auto simp add: divide_less_eq)
avigad@16775
   876
wenzelm@23389
   877
avigad@16775
   878
subsection{*Conditional Simplification Rules: No Case Splits*}
avigad@16775
   879
paulson@24286
   880
lemma le_divide_eq_1_pos [simp,noatp]:
haftmann@35028
   881
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   882
  shows "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
avigad@16775
   883
by (auto simp add: le_divide_eq)
avigad@16775
   884
paulson@24286
   885
lemma le_divide_eq_1_neg [simp,noatp]:
haftmann@35028
   886
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   887
  shows "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
avigad@16775
   888
by (auto simp add: le_divide_eq)
avigad@16775
   889
paulson@24286
   890
lemma divide_le_eq_1_pos [simp,noatp]:
haftmann@35028
   891
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   892
  shows "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
avigad@16775
   893
by (auto simp add: divide_le_eq)
avigad@16775
   894
paulson@24286
   895
lemma divide_le_eq_1_neg [simp,noatp]:
haftmann@35028
   896
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   897
  shows "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
avigad@16775
   898
by (auto simp add: divide_le_eq)
avigad@16775
   899
paulson@24286
   900
lemma less_divide_eq_1_pos [simp,noatp]:
haftmann@35028
   901
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   902
  shows "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
avigad@16775
   903
by (auto simp add: less_divide_eq)
avigad@16775
   904
paulson@24286
   905
lemma less_divide_eq_1_neg [simp,noatp]:
haftmann@35028
   906
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   907
  shows "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
avigad@16775
   908
by (auto simp add: less_divide_eq)
avigad@16775
   909
paulson@24286
   910
lemma divide_less_eq_1_pos [simp,noatp]:
haftmann@35028
   911
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   912
  shows "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
paulson@18649
   913
by (auto simp add: divide_less_eq)
paulson@18649
   914
paulson@24286
   915
lemma divide_less_eq_1_neg [simp,noatp]:
haftmann@35028
   916
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   917
  shows "a < 0 \<Longrightarrow> b/a < 1 <-> a < b"
avigad@16775
   918
by (auto simp add: divide_less_eq)
avigad@16775
   919
paulson@24286
   920
lemma eq_divide_eq_1 [simp,noatp]:
haftmann@35028
   921
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   922
  shows "(1 = b/a) = ((a \<noteq> 0 & a = b))"
avigad@16775
   923
by (auto simp add: eq_divide_eq)
avigad@16775
   924
paulson@24286
   925
lemma divide_eq_eq_1 [simp,noatp]:
haftmann@35028
   926
  fixes a :: "'a :: {linordered_field,division_by_zero}"
paulson@18649
   927
  shows "(b/a = 1) = ((a \<noteq> 0 & a = b))"
avigad@16775
   928
by (auto simp add: divide_eq_eq)
avigad@16775
   929
wenzelm@23389
   930
avigad@16775
   931
subsection {* Reasoning about inequalities with division *}
avigad@16775
   932
haftmann@35028
   933
lemma mult_imp_div_pos_le: "0 < (y::'a::linordered_field) ==> x <= z * y ==>
haftmann@33319
   934
    x / y <= z"
haftmann@33319
   935
by (subst pos_divide_le_eq, assumption+)
avigad@16775
   936
haftmann@35028
   937
lemma mult_imp_le_div_pos: "0 < (y::'a::linordered_field) ==> z * y <= x ==>
nipkow@23482
   938
    z <= x / y"
nipkow@23482
   939
by(simp add:field_simps)
avigad@16775
   940
haftmann@35028
   941
lemma mult_imp_div_pos_less: "0 < (y::'a::linordered_field) ==> x < z * y ==>
avigad@16775
   942
    x / y < z"
nipkow@23482
   943
by(simp add:field_simps)
avigad@16775
   944
haftmann@35028
   945
lemma mult_imp_less_div_pos: "0 < (y::'a::linordered_field) ==> z * y < x ==>
avigad@16775
   946
    z < x / y"
nipkow@23482
   947
by(simp add:field_simps)
avigad@16775
   948
haftmann@35028
   949
lemma frac_le: "(0::'a::linordered_field) <= x ==> 
avigad@16775
   950
    x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
avigad@16775
   951
  apply (rule mult_imp_div_pos_le)
haftmann@25230
   952
  apply simp
haftmann@25230
   953
  apply (subst times_divide_eq_left)
avigad@16775
   954
  apply (rule mult_imp_le_div_pos, assumption)
avigad@16775
   955
  apply (rule mult_mono)
avigad@16775
   956
  apply simp_all
paulson@14293
   957
done
paulson@14293
   958
haftmann@35028
   959
lemma frac_less: "(0::'a::linordered_field) <= x ==> 
avigad@16775
   960
    x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
avigad@16775
   961
  apply (rule mult_imp_div_pos_less)
haftmann@33319
   962
  apply simp
haftmann@33319
   963
  apply (subst times_divide_eq_left)
avigad@16775
   964
  apply (rule mult_imp_less_div_pos, assumption)
avigad@16775
   965
  apply (erule mult_less_le_imp_less)
avigad@16775
   966
  apply simp_all
avigad@16775
   967
done
avigad@16775
   968
haftmann@35028
   969
lemma frac_less2: "(0::'a::linordered_field) < x ==> 
avigad@16775
   970
    x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
avigad@16775
   971
  apply (rule mult_imp_div_pos_less)
avigad@16775
   972
  apply simp_all
haftmann@33319
   973
  apply (subst times_divide_eq_left)
avigad@16775
   974
  apply (rule mult_imp_less_div_pos, assumption)
avigad@16775
   975
  apply (erule mult_le_less_imp_less)
avigad@16775
   976
  apply simp_all
avigad@16775
   977
done
avigad@16775
   978
avigad@16775
   979
text{*It's not obvious whether these should be simprules or not. 
avigad@16775
   980
  Their effect is to gather terms into one big fraction, like
avigad@16775
   981
  a*b*c / x*y*z. The rationale for that is unclear, but many proofs 
avigad@16775
   982
  seem to need them.*}
avigad@16775
   983
avigad@16775
   984
declare times_divide_eq [simp]
paulson@14293
   985
wenzelm@23389
   986
paulson@14293
   987
subsection {* Ordered Fields are Dense *}
paulson@14293
   988
haftmann@35028
   989
lemma less_half_sum: "a < b ==> a < (a+b) / (1+1::'a::linordered_field)"
nipkow@23482
   990
by (simp add: field_simps zero_less_two)
paulson@14293
   991
haftmann@35028
   992
lemma gt_half_sum: "a < b ==> (a+b)/(1+1::'a::linordered_field) < b"
nipkow@23482
   993
by (simp add: field_simps zero_less_two)
paulson@14293
   994
haftmann@35028
   995
instance linordered_field < dense_linorder
haftmann@24422
   996
proof
haftmann@24422
   997
  fix x y :: 'a
haftmann@24422
   998
  have "x < x + 1" by simp
haftmann@24422
   999
  then show "\<exists>y. x < y" .. 
haftmann@24422
  1000
  have "x - 1 < x" by simp
haftmann@24422
  1001
  then show "\<exists>y. y < x" ..
haftmann@24422
  1002
  show "x < y \<Longrightarrow> \<exists>z>x. z < y" by (blast intro!: less_half_sum gt_half_sum)
haftmann@24422
  1003
qed
paulson@14293
  1004
paulson@15234
  1005
paulson@14293
  1006
subsection {* Absolute Value *}
paulson@14293
  1007
paulson@14294
  1008
lemma nonzero_abs_inverse:
haftmann@35028
  1009
     "a \<noteq> 0 ==> abs (inverse (a::'a::linordered_field)) = inverse (abs a)"
paulson@14294
  1010
apply (auto simp add: linorder_neq_iff abs_if nonzero_inverse_minus_eq 
paulson@14294
  1011
                      negative_imp_inverse_negative)
paulson@14294
  1012
apply (blast intro: positive_imp_inverse_positive elim: order_less_asym) 
paulson@14294
  1013
done
paulson@14294
  1014
paulson@14294
  1015
lemma abs_inverse [simp]:
haftmann@35028
  1016
     "abs (inverse (a::'a::{linordered_field,division_by_zero})) = 
paulson@14294
  1017
      inverse (abs a)"
haftmann@21328
  1018
apply (cases "a=0", simp) 
paulson@14294
  1019
apply (simp add: nonzero_abs_inverse) 
paulson@14294
  1020
done
paulson@14294
  1021
paulson@14294
  1022
lemma nonzero_abs_divide:
haftmann@35028
  1023
     "b \<noteq> 0 ==> abs (a / (b::'a::linordered_field)) = abs a / abs b"
paulson@14294
  1024
by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
paulson@14294
  1025
paulson@15234
  1026
lemma abs_divide [simp]:
haftmann@35028
  1027
     "abs (a / (b::'a::{linordered_field,division_by_zero})) = abs a / abs b"
haftmann@21328
  1028
apply (cases "b=0", simp) 
paulson@14294
  1029
apply (simp add: nonzero_abs_divide) 
paulson@14294
  1030
done
paulson@14294
  1031
haftmann@35028
  1032
lemma abs_div_pos: "(0::'a::{division_by_zero,linordered_field}) < y ==> 
haftmann@25304
  1033
    abs x / y = abs (x / y)"
haftmann@25304
  1034
  apply (subst abs_divide)
haftmann@25304
  1035
  apply (simp add: order_less_imp_le)
haftmann@25304
  1036
done
avigad@16775
  1037
haftmann@33364
  1038
code_modulename SML
haftmann@35050
  1039
  Fields Arith
haftmann@33364
  1040
haftmann@33364
  1041
code_modulename OCaml
haftmann@35050
  1042
  Fields Arith
haftmann@33364
  1043
haftmann@33364
  1044
code_modulename Haskell
haftmann@35050
  1045
  Fields Arith
haftmann@33364
  1046
paulson@14265
  1047
end