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