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