src/HOL/Fields.thy
author hoelzl
Fri May 20 21:38:32 2011 +0200 (2011-05-20)
changeset 42904 4aedcff42de6
parent 36774 9e444b09fbef
child 44064 5bce8ff0d9ae
permissions -rw-r--r--
add divide_.._cancel, inverse_.._iff
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@36719
   237
lemma times_divide_times_eq:
haftmann@36719
   238
  "(x / y) * (z / w) = (x * z) / (y * w)"
haftmann@36719
   239
  by simp
haftmann@36719
   240
haftmann@36719
   241
lemma add_frac_num:
haftmann@36719
   242
  "y \<noteq> 0 \<Longrightarrow> x / y + z = (x + z * y) / y"
haftmann@36719
   243
  by (simp add: add_divide_distrib)
haftmann@36719
   244
haftmann@36719
   245
lemma add_num_frac:
haftmann@36719
   246
  "y \<noteq> 0 \<Longrightarrow> z + x / y = (x + z * y) / y"
haftmann@36719
   247
  by (simp add: add_divide_distrib add.commute)
haftmann@36719
   248
haftmann@36409
   249
end
haftmann@36301
   250
haftmann@36301
   251
haftmann@36301
   252
text {* Ordered Fields *}
haftmann@36301
   253
haftmann@36301
   254
class linordered_field = field + linordered_idom
haftmann@36301
   255
begin
paulson@14268
   256
paulson@14277
   257
lemma positive_imp_inverse_positive: 
haftmann@36301
   258
  assumes a_gt_0: "0 < a" 
haftmann@36301
   259
  shows "0 < inverse a"
nipkow@23482
   260
proof -
paulson@14268
   261
  have "0 < a * inverse a" 
haftmann@36301
   262
    by (simp add: a_gt_0 [THEN less_imp_not_eq2])
paulson@14268
   263
  thus "0 < inverse a" 
haftmann@36301
   264
    by (simp add: a_gt_0 [THEN less_not_sym] zero_less_mult_iff)
nipkow@23482
   265
qed
paulson@14268
   266
paulson@14277
   267
lemma negative_imp_inverse_negative:
haftmann@36301
   268
  "a < 0 \<Longrightarrow> inverse a < 0"
haftmann@36301
   269
  by (insert positive_imp_inverse_positive [of "-a"], 
haftmann@36301
   270
    simp add: nonzero_inverse_minus_eq less_imp_not_eq)
paulson@14268
   271
paulson@14268
   272
lemma inverse_le_imp_le:
haftmann@36301
   273
  assumes invle: "inverse a \<le> inverse b" and apos: "0 < a"
haftmann@36301
   274
  shows "b \<le> a"
nipkow@23482
   275
proof (rule classical)
paulson@14268
   276
  assume "~ b \<le> a"
nipkow@23482
   277
  hence "a < b"  by (simp add: linorder_not_le)
haftmann@36301
   278
  hence bpos: "0 < b"  by (blast intro: apos less_trans)
paulson@14268
   279
  hence "a * inverse a \<le> a * inverse b"
haftmann@36301
   280
    by (simp add: apos invle less_imp_le mult_left_mono)
paulson@14268
   281
  hence "(a * inverse a) * b \<le> (a * inverse b) * b"
haftmann@36301
   282
    by (simp add: bpos less_imp_le mult_right_mono)
haftmann@36301
   283
  thus "b \<le> a"  by (simp add: mult_assoc apos bpos less_imp_not_eq2)
nipkow@23482
   284
qed
paulson@14268
   285
paulson@14277
   286
lemma inverse_positive_imp_positive:
haftmann@36301
   287
  assumes inv_gt_0: "0 < inverse a" and nz: "a \<noteq> 0"
haftmann@36301
   288
  shows "0 < a"
wenzelm@23389
   289
proof -
paulson@14277
   290
  have "0 < inverse (inverse a)"
wenzelm@23389
   291
    using inv_gt_0 by (rule positive_imp_inverse_positive)
paulson@14277
   292
  thus "0 < a"
wenzelm@23389
   293
    using nz by (simp add: nonzero_inverse_inverse_eq)
wenzelm@23389
   294
qed
paulson@14277
   295
haftmann@36301
   296
lemma inverse_negative_imp_negative:
haftmann@36301
   297
  assumes inv_less_0: "inverse a < 0" and nz: "a \<noteq> 0"
haftmann@36301
   298
  shows "a < 0"
haftmann@36301
   299
proof -
haftmann@36301
   300
  have "inverse (inverse a) < 0"
haftmann@36301
   301
    using inv_less_0 by (rule negative_imp_inverse_negative)
haftmann@36301
   302
  thus "a < 0" using nz by (simp add: nonzero_inverse_inverse_eq)
haftmann@36301
   303
qed
haftmann@36301
   304
haftmann@36301
   305
lemma linordered_field_no_lb:
haftmann@36301
   306
  "\<forall>x. \<exists>y. y < x"
haftmann@36301
   307
proof
haftmann@36301
   308
  fix x::'a
haftmann@36301
   309
  have m1: "- (1::'a) < 0" by simp
haftmann@36301
   310
  from add_strict_right_mono[OF m1, where c=x] 
haftmann@36301
   311
  have "(- 1) + x < x" by simp
haftmann@36301
   312
  thus "\<exists>y. y < x" by blast
haftmann@36301
   313
qed
haftmann@36301
   314
haftmann@36301
   315
lemma linordered_field_no_ub:
haftmann@36301
   316
  "\<forall> x. \<exists>y. y > x"
haftmann@36301
   317
proof
haftmann@36301
   318
  fix x::'a
haftmann@36301
   319
  have m1: " (1::'a) > 0" by simp
haftmann@36301
   320
  from add_strict_right_mono[OF m1, where c=x] 
haftmann@36301
   321
  have "1 + x > x" by simp
haftmann@36301
   322
  thus "\<exists>y. y > x" by blast
haftmann@36301
   323
qed
haftmann@36301
   324
haftmann@36301
   325
lemma less_imp_inverse_less:
haftmann@36301
   326
  assumes less: "a < b" and apos:  "0 < a"
haftmann@36301
   327
  shows "inverse b < inverse a"
haftmann@36301
   328
proof (rule ccontr)
haftmann@36301
   329
  assume "~ inverse b < inverse a"
haftmann@36301
   330
  hence "inverse a \<le> inverse b" by simp
haftmann@36301
   331
  hence "~ (a < b)"
haftmann@36301
   332
    by (simp add: not_less inverse_le_imp_le [OF _ apos])
haftmann@36301
   333
  thus False by (rule notE [OF _ less])
haftmann@36301
   334
qed
haftmann@36301
   335
haftmann@36301
   336
lemma inverse_less_imp_less:
haftmann@36301
   337
  "inverse a < inverse b \<Longrightarrow> 0 < a \<Longrightarrow> b < a"
haftmann@36301
   338
apply (simp add: less_le [of "inverse a"] less_le [of "b"])
haftmann@36301
   339
apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
haftmann@36301
   340
done
haftmann@36301
   341
haftmann@36301
   342
text{*Both premises are essential. Consider -1 and 1.*}
haftmann@36301
   343
lemma inverse_less_iff_less [simp,no_atp]:
haftmann@36301
   344
  "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> inverse a < inverse b \<longleftrightarrow> b < a"
haftmann@36301
   345
  by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
haftmann@36301
   346
haftmann@36301
   347
lemma le_imp_inverse_le:
haftmann@36301
   348
  "a \<le> b \<Longrightarrow> 0 < a \<Longrightarrow> inverse b \<le> inverse a"
haftmann@36301
   349
  by (force simp add: le_less less_imp_inverse_less)
haftmann@36301
   350
haftmann@36301
   351
lemma inverse_le_iff_le [simp,no_atp]:
haftmann@36301
   352
  "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> inverse a \<le> inverse b \<longleftrightarrow> b \<le> a"
haftmann@36301
   353
  by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
haftmann@36301
   354
haftmann@36301
   355
haftmann@36301
   356
text{*These results refer to both operands being negative.  The opposite-sign
haftmann@36301
   357
case is trivial, since inverse preserves signs.*}
haftmann@36301
   358
lemma inverse_le_imp_le_neg:
haftmann@36301
   359
  "inverse a \<le> inverse b \<Longrightarrow> b < 0 \<Longrightarrow> b \<le> a"
haftmann@36301
   360
apply (rule classical) 
haftmann@36301
   361
apply (subgoal_tac "a < 0") 
haftmann@36301
   362
 prefer 2 apply force
haftmann@36301
   363
apply (insert inverse_le_imp_le [of "-b" "-a"])
haftmann@36301
   364
apply (simp add: nonzero_inverse_minus_eq) 
haftmann@36301
   365
done
haftmann@36301
   366
haftmann@36301
   367
lemma less_imp_inverse_less_neg:
haftmann@36301
   368
   "a < b \<Longrightarrow> b < 0 \<Longrightarrow> inverse b < inverse a"
haftmann@36301
   369
apply (subgoal_tac "a < 0") 
haftmann@36301
   370
 prefer 2 apply (blast intro: less_trans) 
haftmann@36301
   371
apply (insert less_imp_inverse_less [of "-b" "-a"])
haftmann@36301
   372
apply (simp add: nonzero_inverse_minus_eq) 
haftmann@36301
   373
done
haftmann@36301
   374
haftmann@36301
   375
lemma inverse_less_imp_less_neg:
haftmann@36301
   376
   "inverse a < inverse b \<Longrightarrow> b < 0 \<Longrightarrow> b < a"
haftmann@36301
   377
apply (rule classical) 
haftmann@36301
   378
apply (subgoal_tac "a < 0") 
haftmann@36301
   379
 prefer 2
haftmann@36301
   380
 apply force
haftmann@36301
   381
apply (insert inverse_less_imp_less [of "-b" "-a"])
haftmann@36301
   382
apply (simp add: nonzero_inverse_minus_eq) 
haftmann@36301
   383
done
haftmann@36301
   384
haftmann@36301
   385
lemma inverse_less_iff_less_neg [simp,no_atp]:
haftmann@36301
   386
  "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> inverse a < inverse b \<longleftrightarrow> b < a"
haftmann@36301
   387
apply (insert inverse_less_iff_less [of "-b" "-a"])
haftmann@36301
   388
apply (simp del: inverse_less_iff_less 
haftmann@36301
   389
            add: nonzero_inverse_minus_eq)
haftmann@36301
   390
done
haftmann@36301
   391
haftmann@36301
   392
lemma le_imp_inverse_le_neg:
haftmann@36301
   393
  "a \<le> b \<Longrightarrow> b < 0 ==> inverse b \<le> inverse a"
haftmann@36301
   394
  by (force simp add: le_less less_imp_inverse_less_neg)
haftmann@36301
   395
haftmann@36301
   396
lemma inverse_le_iff_le_neg [simp,no_atp]:
haftmann@36301
   397
  "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> inverse a \<le> inverse b \<longleftrightarrow> b \<le> a"
haftmann@36301
   398
  by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
haftmann@36301
   399
huffman@36774
   400
lemma one_less_inverse:
huffman@36774
   401
  "0 < a \<Longrightarrow> a < 1 \<Longrightarrow> 1 < inverse a"
huffman@36774
   402
  using less_imp_inverse_less [of a 1, unfolded inverse_1] .
huffman@36774
   403
huffman@36774
   404
lemma one_le_inverse:
huffman@36774
   405
  "0 < a \<Longrightarrow> a \<le> 1 \<Longrightarrow> 1 \<le> inverse a"
huffman@36774
   406
  using le_imp_inverse_le [of a 1, unfolded inverse_1] .
huffman@36774
   407
haftmann@36348
   408
lemma pos_le_divide_eq [field_simps]: "0 < c ==> (a \<le> b/c) = (a*c \<le> b)"
haftmann@36301
   409
proof -
haftmann@36301
   410
  assume less: "0<c"
haftmann@36301
   411
  hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
haftmann@36304
   412
    by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   413
  also have "... = (a*c \<le> b)"
haftmann@36301
   414
    by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
haftmann@36301
   415
  finally show ?thesis .
haftmann@36301
   416
qed
haftmann@36301
   417
haftmann@36348
   418
lemma neg_le_divide_eq [field_simps]: "c < 0 ==> (a \<le> b/c) = (b \<le> a*c)"
haftmann@36301
   419
proof -
haftmann@36301
   420
  assume less: "c<0"
haftmann@36301
   421
  hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
haftmann@36304
   422
    by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   423
  also have "... = (b \<le> a*c)"
haftmann@36301
   424
    by (simp add: less_imp_not_eq [OF less] divide_inverse mult_assoc) 
haftmann@36301
   425
  finally show ?thesis .
haftmann@36301
   426
qed
haftmann@36301
   427
haftmann@36348
   428
lemma pos_less_divide_eq [field_simps]:
haftmann@36301
   429
     "0 < c ==> (a < b/c) = (a*c < b)"
haftmann@36301
   430
proof -
haftmann@36301
   431
  assume less: "0<c"
haftmann@36301
   432
  hence "(a < b/c) = (a*c < (b/c)*c)"
haftmann@36304
   433
    by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   434
  also have "... = (a*c < b)"
haftmann@36301
   435
    by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
haftmann@36301
   436
  finally show ?thesis .
haftmann@36301
   437
qed
haftmann@36301
   438
haftmann@36348
   439
lemma neg_less_divide_eq [field_simps]:
haftmann@36301
   440
 "c < 0 ==> (a < b/c) = (b < a*c)"
haftmann@36301
   441
proof -
haftmann@36301
   442
  assume less: "c<0"
haftmann@36301
   443
  hence "(a < b/c) = ((b/c)*c < a*c)"
haftmann@36304
   444
    by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   445
  also have "... = (b < a*c)"
haftmann@36301
   446
    by (simp add: less_imp_not_eq [OF less] divide_inverse mult_assoc) 
haftmann@36301
   447
  finally show ?thesis .
haftmann@36301
   448
qed
haftmann@36301
   449
haftmann@36348
   450
lemma pos_divide_less_eq [field_simps]:
haftmann@36301
   451
     "0 < c ==> (b/c < a) = (b < a*c)"
haftmann@36301
   452
proof -
haftmann@36301
   453
  assume less: "0<c"
haftmann@36301
   454
  hence "(b/c < a) = ((b/c)*c < a*c)"
haftmann@36304
   455
    by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   456
  also have "... = (b < a*c)"
haftmann@36301
   457
    by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
haftmann@36301
   458
  finally show ?thesis .
haftmann@36301
   459
qed
haftmann@36301
   460
haftmann@36348
   461
lemma neg_divide_less_eq [field_simps]:
haftmann@36301
   462
 "c < 0 ==> (b/c < a) = (a*c < b)"
haftmann@36301
   463
proof -
haftmann@36301
   464
  assume less: "c<0"
haftmann@36301
   465
  hence "(b/c < a) = (a*c < (b/c)*c)"
haftmann@36304
   466
    by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   467
  also have "... = (a*c < 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@36348
   472
lemma pos_divide_le_eq [field_simps]: "0 < c ==> (b/c \<le> a) = (b \<le> a*c)"
haftmann@36301
   473
proof -
haftmann@36301
   474
  assume less: "0<c"
haftmann@36301
   475
  hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
haftmann@36304
   476
    by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   477
  also have "... = (b \<le> a*c)"
haftmann@36301
   478
    by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
haftmann@36301
   479
  finally show ?thesis .
haftmann@36301
   480
qed
haftmann@36301
   481
haftmann@36348
   482
lemma neg_divide_le_eq [field_simps]: "c < 0 ==> (b/c \<le> a) = (a*c \<le> b)"
haftmann@36301
   483
proof -
haftmann@36301
   484
  assume less: "c<0"
haftmann@36301
   485
  hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
haftmann@36304
   486
    by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   487
  also have "... = (a*c \<le> b)"
haftmann@36301
   488
    by (simp add: less_imp_not_eq [OF less] divide_inverse mult_assoc) 
haftmann@36301
   489
  finally show ?thesis .
haftmann@36301
   490
qed
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@36348
   497
lemmas sign_simps [no_atp] = algebra_simps
haftmann@36348
   498
  zero_less_mult_iff mult_less_0_iff
haftmann@36348
   499
haftmann@36348
   500
lemmas (in -) sign_simps [no_atp] = algebra_simps
haftmann@36301
   501
  zero_less_mult_iff mult_less_0_iff
haftmann@36301
   502
haftmann@36301
   503
(* Only works once linear arithmetic is installed:
haftmann@36301
   504
text{*An example:*}
haftmann@36301
   505
lemma fixes a b c d e f :: "'a::linordered_field"
haftmann@36301
   506
shows "\<lbrakk>a>b; c<d; e<f; 0 < u \<rbrakk> \<Longrightarrow>
haftmann@36301
   507
 ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) <
haftmann@36301
   508
 ((e-f)*(a-b)*(c-d))/((e-f)*(a-b)*(c-d)) + u"
haftmann@36301
   509
apply(subgoal_tac "(c-d)*(e-f)*(a-b) > 0")
haftmann@36301
   510
 prefer 2 apply(simp add:sign_simps)
haftmann@36301
   511
apply(subgoal_tac "(c-d)*(e-f)*(a-b)*u > 0")
haftmann@36301
   512
 prefer 2 apply(simp add:sign_simps)
haftmann@36301
   513
apply(simp add:field_simps)
haftmann@36301
   514
done
haftmann@36301
   515
*)
haftmann@36301
   516
haftmann@36301
   517
lemma divide_pos_pos:
haftmann@36301
   518
  "0 < x ==> 0 < y ==> 0 < x / y"
haftmann@36301
   519
by(simp add:field_simps)
haftmann@36301
   520
haftmann@36301
   521
lemma divide_nonneg_pos:
haftmann@36301
   522
  "0 <= x ==> 0 < y ==> 0 <= x / y"
haftmann@36301
   523
by(simp add:field_simps)
haftmann@36301
   524
haftmann@36301
   525
lemma divide_neg_pos:
haftmann@36301
   526
  "x < 0 ==> 0 < y ==> x / y < 0"
haftmann@36301
   527
by(simp add:field_simps)
haftmann@36301
   528
haftmann@36301
   529
lemma divide_nonpos_pos:
haftmann@36301
   530
  "x <= 0 ==> 0 < y ==> x / y <= 0"
haftmann@36301
   531
by(simp add:field_simps)
haftmann@36301
   532
haftmann@36301
   533
lemma divide_pos_neg:
haftmann@36301
   534
  "0 < x ==> y < 0 ==> x / y < 0"
haftmann@36301
   535
by(simp add:field_simps)
haftmann@36301
   536
haftmann@36301
   537
lemma divide_nonneg_neg:
haftmann@36301
   538
  "0 <= x ==> y < 0 ==> x / y <= 0" 
haftmann@36301
   539
by(simp add:field_simps)
haftmann@36301
   540
haftmann@36301
   541
lemma divide_neg_neg:
haftmann@36301
   542
  "x < 0 ==> y < 0 ==> 0 < x / y"
haftmann@36301
   543
by(simp add:field_simps)
haftmann@36301
   544
haftmann@36301
   545
lemma divide_nonpos_neg:
haftmann@36301
   546
  "x <= 0 ==> y < 0 ==> 0 <= x / y"
haftmann@36301
   547
by(simp add:field_simps)
haftmann@36301
   548
haftmann@36301
   549
lemma divide_strict_right_mono:
haftmann@36301
   550
     "[|a < b; 0 < c|] ==> a / c < b / c"
haftmann@36301
   551
by (simp add: less_imp_not_eq2 divide_inverse mult_strict_right_mono 
haftmann@36301
   552
              positive_imp_inverse_positive)
haftmann@36301
   553
haftmann@36301
   554
haftmann@36301
   555
lemma divide_strict_right_mono_neg:
haftmann@36301
   556
     "[|b < a; c < 0|] ==> a / c < b / c"
haftmann@36301
   557
apply (drule divide_strict_right_mono [of _ _ "-c"], simp)
haftmann@36301
   558
apply (simp add: less_imp_not_eq nonzero_minus_divide_right [symmetric])
haftmann@36301
   559
done
haftmann@36301
   560
haftmann@36301
   561
text{*The last premise ensures that @{term a} and @{term b} 
haftmann@36301
   562
      have the same sign*}
haftmann@36301
   563
lemma divide_strict_left_mono:
haftmann@36301
   564
  "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / b"
haftmann@36301
   565
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono)
haftmann@36301
   566
haftmann@36301
   567
lemma divide_left_mono:
haftmann@36301
   568
  "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / b"
haftmann@36301
   569
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_right_mono)
haftmann@36301
   570
haftmann@36301
   571
lemma divide_strict_left_mono_neg:
haftmann@36301
   572
  "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / b"
haftmann@36301
   573
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono_neg)
haftmann@36301
   574
haftmann@36301
   575
lemma mult_imp_div_pos_le: "0 < y ==> x <= z * y ==>
haftmann@36301
   576
    x / y <= z"
haftmann@36301
   577
by (subst pos_divide_le_eq, assumption+)
haftmann@36301
   578
haftmann@36301
   579
lemma mult_imp_le_div_pos: "0 < y ==> z * y <= x ==>
haftmann@36301
   580
    z <= x / y"
haftmann@36301
   581
by(simp add:field_simps)
haftmann@36301
   582
haftmann@36301
   583
lemma mult_imp_div_pos_less: "0 < y ==> x < z * y ==>
haftmann@36301
   584
    x / y < z"
haftmann@36301
   585
by(simp add:field_simps)
haftmann@36301
   586
haftmann@36301
   587
lemma mult_imp_less_div_pos: "0 < y ==> z * y < x ==>
haftmann@36301
   588
    z < x / y"
haftmann@36301
   589
by(simp add:field_simps)
haftmann@36301
   590
haftmann@36301
   591
lemma frac_le: "0 <= x ==> 
haftmann@36301
   592
    x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
haftmann@36301
   593
  apply (rule mult_imp_div_pos_le)
haftmann@36301
   594
  apply simp
haftmann@36301
   595
  apply (subst times_divide_eq_left)
haftmann@36301
   596
  apply (rule mult_imp_le_div_pos, assumption)
haftmann@36301
   597
  apply (rule mult_mono)
haftmann@36301
   598
  apply simp_all
haftmann@36301
   599
done
haftmann@36301
   600
haftmann@36301
   601
lemma frac_less: "0 <= x ==> 
haftmann@36301
   602
    x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
haftmann@36301
   603
  apply (rule mult_imp_div_pos_less)
haftmann@36301
   604
  apply simp
haftmann@36301
   605
  apply (subst times_divide_eq_left)
haftmann@36301
   606
  apply (rule mult_imp_less_div_pos, assumption)
haftmann@36301
   607
  apply (erule mult_less_le_imp_less)
haftmann@36301
   608
  apply simp_all
haftmann@36301
   609
done
haftmann@36301
   610
haftmann@36301
   611
lemma frac_less2: "0 < x ==> 
haftmann@36301
   612
    x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
haftmann@36301
   613
  apply (rule mult_imp_div_pos_less)
haftmann@36301
   614
  apply simp_all
haftmann@36301
   615
  apply (rule mult_imp_less_div_pos, assumption)
haftmann@36301
   616
  apply (erule mult_le_less_imp_less)
haftmann@36301
   617
  apply simp_all
haftmann@36301
   618
done
haftmann@36301
   619
haftmann@36301
   620
text{*It's not obvious whether these should be simprules or not. 
haftmann@36301
   621
  Their effect is to gather terms into one big fraction, like
haftmann@36301
   622
  a*b*c / x*y*z. The rationale for that is unclear, but many proofs 
haftmann@36301
   623
  seem to need them.*}
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@36414
   666
class linordered_field_inverse_zero = linordered_field + field_inverse_zero
haftmann@36348
   667
begin
haftmann@36348
   668
haftmann@36301
   669
lemma le_divide_eq:
haftmann@36301
   670
  "(a \<le> b/c) = 
haftmann@36301
   671
   (if 0 < c then a*c \<le> b
haftmann@36301
   672
             else if c < 0 then b \<le> a*c
haftmann@36409
   673
             else  a \<le> 0)"
haftmann@36301
   674
apply (cases "c=0", simp) 
haftmann@36301
   675
apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
haftmann@36301
   676
done
haftmann@36301
   677
paulson@14277
   678
lemma inverse_positive_iff_positive [simp]:
haftmann@36409
   679
  "(0 < inverse a) = (0 < a)"
haftmann@21328
   680
apply (cases "a = 0", simp)
paulson@14277
   681
apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
paulson@14277
   682
done
paulson@14277
   683
paulson@14277
   684
lemma inverse_negative_iff_negative [simp]:
haftmann@36409
   685
  "(inverse a < 0) = (a < 0)"
haftmann@21328
   686
apply (cases "a = 0", simp)
paulson@14277
   687
apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
paulson@14277
   688
done
paulson@14277
   689
paulson@14277
   690
lemma inverse_nonnegative_iff_nonnegative [simp]:
haftmann@36409
   691
  "0 \<le> inverse a \<longleftrightarrow> 0 \<le> a"
haftmann@36409
   692
  by (simp add: not_less [symmetric])
paulson@14277
   693
paulson@14277
   694
lemma inverse_nonpositive_iff_nonpositive [simp]:
haftmann@36409
   695
  "inverse a \<le> 0 \<longleftrightarrow> a \<le> 0"
haftmann@36409
   696
  by (simp add: not_less [symmetric])
paulson@14277
   697
paulson@14365
   698
lemma one_less_inverse_iff:
haftmann@36409
   699
  "1 < inverse x \<longleftrightarrow> 0 < x \<and> x < 1"
nipkow@23482
   700
proof cases
paulson@14365
   701
  assume "0 < x"
paulson@14365
   702
    with inverse_less_iff_less [OF zero_less_one, of x]
paulson@14365
   703
    show ?thesis by simp
paulson@14365
   704
next
paulson@14365
   705
  assume notless: "~ (0 < x)"
paulson@14365
   706
  have "~ (1 < inverse x)"
paulson@14365
   707
  proof
paulson@14365
   708
    assume "1 < inverse x"
haftmann@36409
   709
    also with notless have "... \<le> 0" by simp
paulson@14365
   710
    also have "... < 1" by (rule zero_less_one) 
paulson@14365
   711
    finally show False by auto
paulson@14365
   712
  qed
paulson@14365
   713
  with notless show ?thesis by simp
paulson@14365
   714
qed
paulson@14365
   715
paulson@14365
   716
lemma one_le_inverse_iff:
haftmann@36409
   717
  "1 \<le> inverse x \<longleftrightarrow> 0 < x \<and> x \<le> 1"
haftmann@36409
   718
proof (cases "x = 1")
haftmann@36409
   719
  case True then show ?thesis by simp
haftmann@36409
   720
next
haftmann@36409
   721
  case False then have "inverse x \<noteq> 1" by simp
haftmann@36409
   722
  then have "1 \<noteq> inverse x" by blast
haftmann@36409
   723
  then have "1 \<le> inverse x \<longleftrightarrow> 1 < inverse x" by (simp add: le_less)
haftmann@36409
   724
  with False show ?thesis by (auto simp add: one_less_inverse_iff)
haftmann@36409
   725
qed
paulson@14365
   726
paulson@14365
   727
lemma inverse_less_1_iff:
haftmann@36409
   728
  "inverse x < 1 \<longleftrightarrow> x \<le> 0 \<or> 1 < x"
haftmann@36409
   729
  by (simp add: not_le [symmetric] one_le_inverse_iff) 
paulson@14365
   730
paulson@14365
   731
lemma inverse_le_1_iff:
haftmann@36409
   732
  "inverse x \<le> 1 \<longleftrightarrow> x \<le> 0 \<or> 1 \<le> x"
haftmann@36409
   733
  by (simp add: not_less [symmetric] one_less_inverse_iff) 
paulson@14365
   734
paulson@14288
   735
lemma divide_le_eq:
paulson@14288
   736
  "(b/c \<le> a) = 
paulson@14288
   737
   (if 0 < c then b \<le> a*c
paulson@14288
   738
             else if c < 0 then a*c \<le> b
haftmann@36409
   739
             else 0 \<le> a)"
haftmann@21328
   740
apply (cases "c=0", simp) 
haftmann@36409
   741
apply (force simp add: pos_divide_le_eq neg_divide_le_eq) 
paulson@14288
   742
done
paulson@14288
   743
paulson@14288
   744
lemma less_divide_eq:
paulson@14288
   745
  "(a < b/c) = 
paulson@14288
   746
   (if 0 < c then a*c < b
paulson@14288
   747
             else if c < 0 then b < a*c
haftmann@36409
   748
             else  a < 0)"
haftmann@21328
   749
apply (cases "c=0", simp) 
haftmann@36409
   750
apply (force simp add: pos_less_divide_eq neg_less_divide_eq) 
paulson@14288
   751
done
paulson@14288
   752
paulson@14288
   753
lemma divide_less_eq:
paulson@14288
   754
  "(b/c < a) = 
paulson@14288
   755
   (if 0 < c then b < a*c
paulson@14288
   756
             else if c < 0 then a*c < b
haftmann@36409
   757
             else 0 < a)"
haftmann@21328
   758
apply (cases "c=0", simp) 
haftmann@36409
   759
apply (force simp add: pos_divide_less_eq neg_divide_less_eq)
paulson@14288
   760
done
paulson@14288
   761
haftmann@36301
   762
text {*Division and Signs*}
avigad@16775
   763
avigad@16775
   764
lemma zero_less_divide_iff:
haftmann@36409
   765
     "(0 < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
avigad@16775
   766
by (simp add: divide_inverse zero_less_mult_iff)
avigad@16775
   767
avigad@16775
   768
lemma divide_less_0_iff:
haftmann@36409
   769
     "(a/b < 0) = 
avigad@16775
   770
      (0 < a & b < 0 | a < 0 & 0 < b)"
avigad@16775
   771
by (simp add: divide_inverse mult_less_0_iff)
avigad@16775
   772
avigad@16775
   773
lemma zero_le_divide_iff:
haftmann@36409
   774
     "(0 \<le> a/b) =
avigad@16775
   775
      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
avigad@16775
   776
by (simp add: divide_inverse zero_le_mult_iff)
avigad@16775
   777
avigad@16775
   778
lemma divide_le_0_iff:
haftmann@36409
   779
     "(a/b \<le> 0) =
avigad@16775
   780
      (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
avigad@16775
   781
by (simp add: divide_inverse mult_le_0_iff)
avigad@16775
   782
haftmann@36301
   783
text {* Division and the Number One *}
paulson@14353
   784
paulson@14353
   785
text{*Simplify expressions equated with 1*}
paulson@14353
   786
blanchet@35828
   787
lemma zero_eq_1_divide_iff [simp,no_atp]:
haftmann@36409
   788
     "(0 = 1/a) = (a = 0)"
nipkow@23482
   789
apply (cases "a=0", simp)
nipkow@23482
   790
apply (auto simp add: nonzero_eq_divide_eq)
paulson@14353
   791
done
paulson@14353
   792
blanchet@35828
   793
lemma one_divide_eq_0_iff [simp,no_atp]:
haftmann@36409
   794
     "(1/a = 0) = (a = 0)"
nipkow@23482
   795
apply (cases "a=0", simp)
nipkow@23482
   796
apply (insert zero_neq_one [THEN not_sym])
nipkow@23482
   797
apply (auto simp add: nonzero_divide_eq_eq)
paulson@14353
   798
done
paulson@14353
   799
paulson@14353
   800
text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
haftmann@36423
   801
haftmann@36423
   802
lemma zero_le_divide_1_iff [simp, no_atp]:
haftmann@36423
   803
  "0 \<le> 1 / a \<longleftrightarrow> 0 \<le> a"
haftmann@36423
   804
  by (simp add: zero_le_divide_iff)
paulson@17085
   805
haftmann@36423
   806
lemma zero_less_divide_1_iff [simp, no_atp]:
haftmann@36423
   807
  "0 < 1 / a \<longleftrightarrow> 0 < a"
haftmann@36423
   808
  by (simp add: zero_less_divide_iff)
haftmann@36423
   809
haftmann@36423
   810
lemma divide_le_0_1_iff [simp, no_atp]:
haftmann@36423
   811
  "1 / a \<le> 0 \<longleftrightarrow> a \<le> 0"
haftmann@36423
   812
  by (simp add: divide_le_0_iff)
haftmann@36423
   813
haftmann@36423
   814
lemma divide_less_0_1_iff [simp, no_atp]:
haftmann@36423
   815
  "1 / a < 0 \<longleftrightarrow> a < 0"
haftmann@36423
   816
  by (simp add: divide_less_0_iff)
paulson@14353
   817
paulson@14293
   818
lemma divide_right_mono:
haftmann@36409
   819
     "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/c"
haftmann@36409
   820
by (force simp add: divide_strict_right_mono le_less)
paulson@14293
   821
haftmann@36409
   822
lemma divide_right_mono_neg: "a <= b 
avigad@16775
   823
    ==> c <= 0 ==> b / c <= a / c"
nipkow@23482
   824
apply (drule divide_right_mono [of _ _ "- c"])
nipkow@23482
   825
apply auto
avigad@16775
   826
done
avigad@16775
   827
haftmann@36409
   828
lemma divide_left_mono_neg: "a <= b 
avigad@16775
   829
    ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
avigad@16775
   830
  apply (drule divide_left_mono [of _ _ "- c"])
avigad@16775
   831
  apply (auto simp add: mult_commute)
avigad@16775
   832
done
avigad@16775
   833
hoelzl@42904
   834
lemma inverse_le_iff:
hoelzl@42904
   835
  "inverse a \<le> inverse b \<longleftrightarrow> (0 < a * b \<longrightarrow> b \<le> a) \<and> (a * b \<le> 0 \<longrightarrow> a \<le> b)"
hoelzl@42904
   836
proof -
hoelzl@42904
   837
  { assume "a < 0"
hoelzl@42904
   838
    then have "inverse a < 0" by simp
hoelzl@42904
   839
    moreover assume "0 < b"
hoelzl@42904
   840
    then have "0 < inverse b" by simp
hoelzl@42904
   841
    ultimately have "inverse a < inverse b" by (rule less_trans)
hoelzl@42904
   842
    then have "inverse a \<le> inverse b" by simp }
hoelzl@42904
   843
  moreover
hoelzl@42904
   844
  { assume "b < 0"
hoelzl@42904
   845
    then have "inverse b < 0" by simp
hoelzl@42904
   846
    moreover assume "0 < a"
hoelzl@42904
   847
    then have "0 < inverse a" by simp
hoelzl@42904
   848
    ultimately have "inverse b < inverse a" by (rule less_trans)
hoelzl@42904
   849
    then have "\<not> inverse a \<le> inverse b" by simp }
hoelzl@42904
   850
  ultimately show ?thesis
hoelzl@42904
   851
    by (cases a 0 b 0 rule: linorder_cases[case_product linorder_cases])
hoelzl@42904
   852
       (auto simp: not_less zero_less_mult_iff mult_le_0_iff)
hoelzl@42904
   853
qed
hoelzl@42904
   854
hoelzl@42904
   855
lemma inverse_less_iff:
hoelzl@42904
   856
  "inverse a < inverse b \<longleftrightarrow> (0 < a * b \<longrightarrow> b < a) \<and> (a * b \<le> 0 \<longrightarrow> a < b)"
hoelzl@42904
   857
  by (subst less_le) (auto simp: inverse_le_iff)
hoelzl@42904
   858
hoelzl@42904
   859
lemma divide_le_cancel:
hoelzl@42904
   860
  "a / c \<le> b / c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
hoelzl@42904
   861
  by (simp add: divide_inverse mult_le_cancel_right)
hoelzl@42904
   862
hoelzl@42904
   863
lemma divide_less_cancel:
hoelzl@42904
   864
  "a / c < b / c \<longleftrightarrow> (0 < c \<longrightarrow> a < b) \<and> (c < 0 \<longrightarrow> b < a) \<and> c \<noteq> 0"
hoelzl@42904
   865
  by (auto simp add: divide_inverse mult_less_cancel_right)
hoelzl@42904
   866
avigad@16775
   867
text{*Simplify quotients that are compared with the value 1.*}
avigad@16775
   868
blanchet@35828
   869
lemma le_divide_eq_1 [no_atp]:
haftmann@36409
   870
  "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
avigad@16775
   871
by (auto simp add: le_divide_eq)
avigad@16775
   872
blanchet@35828
   873
lemma divide_le_eq_1 [no_atp]:
haftmann@36409
   874
  "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
avigad@16775
   875
by (auto simp add: divide_le_eq)
avigad@16775
   876
blanchet@35828
   877
lemma less_divide_eq_1 [no_atp]:
haftmann@36409
   878
  "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
avigad@16775
   879
by (auto simp add: less_divide_eq)
avigad@16775
   880
blanchet@35828
   881
lemma divide_less_eq_1 [no_atp]:
haftmann@36409
   882
  "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
avigad@16775
   883
by (auto simp add: divide_less_eq)
avigad@16775
   884
wenzelm@23389
   885
haftmann@36301
   886
text {*Conditional Simplification Rules: No Case Splits*}
avigad@16775
   887
blanchet@35828
   888
lemma le_divide_eq_1_pos [simp,no_atp]:
haftmann@36409
   889
  "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
avigad@16775
   890
by (auto simp add: le_divide_eq)
avigad@16775
   891
blanchet@35828
   892
lemma le_divide_eq_1_neg [simp,no_atp]:
haftmann@36409
   893
  "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
avigad@16775
   894
by (auto simp add: le_divide_eq)
avigad@16775
   895
blanchet@35828
   896
lemma divide_le_eq_1_pos [simp,no_atp]:
haftmann@36409
   897
  "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
avigad@16775
   898
by (auto simp add: divide_le_eq)
avigad@16775
   899
blanchet@35828
   900
lemma divide_le_eq_1_neg [simp,no_atp]:
haftmann@36409
   901
  "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
avigad@16775
   902
by (auto simp add: divide_le_eq)
avigad@16775
   903
blanchet@35828
   904
lemma less_divide_eq_1_pos [simp,no_atp]:
haftmann@36409
   905
  "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
avigad@16775
   906
by (auto simp add: less_divide_eq)
avigad@16775
   907
blanchet@35828
   908
lemma less_divide_eq_1_neg [simp,no_atp]:
haftmann@36409
   909
  "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
avigad@16775
   910
by (auto simp add: less_divide_eq)
avigad@16775
   911
blanchet@35828
   912
lemma divide_less_eq_1_pos [simp,no_atp]:
haftmann@36409
   913
  "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
paulson@18649
   914
by (auto simp add: divide_less_eq)
paulson@18649
   915
blanchet@35828
   916
lemma divide_less_eq_1_neg [simp,no_atp]:
haftmann@36409
   917
  "a < 0 \<Longrightarrow> b/a < 1 <-> a < b"
avigad@16775
   918
by (auto simp add: divide_less_eq)
avigad@16775
   919
blanchet@35828
   920
lemma eq_divide_eq_1 [simp,no_atp]:
haftmann@36409
   921
  "(1 = b/a) = ((a \<noteq> 0 & a = b))"
avigad@16775
   922
by (auto simp add: eq_divide_eq)
avigad@16775
   923
blanchet@35828
   924
lemma divide_eq_eq_1 [simp,no_atp]:
haftmann@36409
   925
  "(b/a = 1) = ((a \<noteq> 0 & a = b))"
avigad@16775
   926
by (auto simp add: divide_eq_eq)
avigad@16775
   927
paulson@14294
   928
lemma abs_inverse [simp]:
haftmann@36409
   929
     "\<bar>inverse a\<bar> = 
haftmann@36301
   930
      inverse \<bar>a\<bar>"
haftmann@21328
   931
apply (cases "a=0", simp) 
paulson@14294
   932
apply (simp add: nonzero_abs_inverse) 
paulson@14294
   933
done
paulson@14294
   934
paulson@15234
   935
lemma abs_divide [simp]:
haftmann@36409
   936
     "\<bar>a / b\<bar> = \<bar>a\<bar> / \<bar>b\<bar>"
haftmann@21328
   937
apply (cases "b=0", simp) 
paulson@14294
   938
apply (simp add: nonzero_abs_divide) 
paulson@14294
   939
done
paulson@14294
   940
haftmann@36409
   941
lemma abs_div_pos: "0 < y ==> 
haftmann@36301
   942
    \<bar>x\<bar> / y = \<bar>x / y\<bar>"
haftmann@25304
   943
  apply (subst abs_divide)
haftmann@25304
   944
  apply (simp add: order_less_imp_le)
haftmann@25304
   945
done
avigad@16775
   946
hoelzl@35579
   947
lemma field_le_mult_one_interval:
hoelzl@35579
   948
  assumes *: "\<And>z. \<lbrakk> 0 < z ; z < 1 \<rbrakk> \<Longrightarrow> z * x \<le> y"
hoelzl@35579
   949
  shows "x \<le> y"
hoelzl@35579
   950
proof (cases "0 < x")
hoelzl@35579
   951
  assume "0 < x"
hoelzl@35579
   952
  thus ?thesis
hoelzl@35579
   953
    using dense_le_bounded[of 0 1 "y/x"] *
hoelzl@35579
   954
    unfolding le_divide_eq if_P[OF `0 < x`] by simp
hoelzl@35579
   955
next
hoelzl@35579
   956
  assume "\<not>0 < x" hence "x \<le> 0" by simp
hoelzl@35579
   957
  obtain s::'a where s: "0 < s" "s < 1" using dense[of 0 "1\<Colon>'a"] by auto
hoelzl@35579
   958
  hence "x \<le> s * x" using mult_le_cancel_right[of 1 x s] `x \<le> 0` by auto
hoelzl@35579
   959
  also note *[OF s]
hoelzl@35579
   960
  finally show ?thesis .
hoelzl@35579
   961
qed
haftmann@35090
   962
haftmann@36409
   963
end
haftmann@36409
   964
haftmann@33364
   965
code_modulename SML
haftmann@35050
   966
  Fields Arith
haftmann@33364
   967
haftmann@33364
   968
code_modulename OCaml
haftmann@35050
   969
  Fields Arith
haftmann@33364
   970
haftmann@33364
   971
code_modulename Haskell
haftmann@35050
   972
  Fields Arith
haftmann@33364
   973
paulson@14265
   974
end