src/HOL/Fields.thy
author haftmann
Thu May 06 23:11:56 2010 +0200 (2010-05-06)
changeset 36719 d396f6f63d94
parent 36425 a0297b98728c
child 36774 9e444b09fbef
permissions -rw-r--r--
moved some lemmas from Groebner_Basis here
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
haftmann@36348
   400
lemma pos_le_divide_eq [field_simps]: "0 < c ==> (a \<le> b/c) = (a*c \<le> b)"
haftmann@36301
   401
proof -
haftmann@36301
   402
  assume less: "0<c"
haftmann@36301
   403
  hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
haftmann@36304
   404
    by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   405
  also have "... = (a*c \<le> b)"
haftmann@36301
   406
    by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
haftmann@36301
   407
  finally show ?thesis .
haftmann@36301
   408
qed
haftmann@36301
   409
haftmann@36348
   410
lemma neg_le_divide_eq [field_simps]: "c < 0 ==> (a \<le> b/c) = (b \<le> a*c)"
haftmann@36301
   411
proof -
haftmann@36301
   412
  assume less: "c<0"
haftmann@36301
   413
  hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
haftmann@36304
   414
    by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   415
  also have "... = (b \<le> a*c)"
haftmann@36301
   416
    by (simp add: less_imp_not_eq [OF less] divide_inverse mult_assoc) 
haftmann@36301
   417
  finally show ?thesis .
haftmann@36301
   418
qed
haftmann@36301
   419
haftmann@36348
   420
lemma pos_less_divide_eq [field_simps]:
haftmann@36301
   421
     "0 < c ==> (a < b/c) = (a*c < b)"
haftmann@36301
   422
proof -
haftmann@36301
   423
  assume less: "0<c"
haftmann@36301
   424
  hence "(a < b/c) = (a*c < (b/c)*c)"
haftmann@36304
   425
    by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   426
  also have "... = (a*c < b)"
haftmann@36301
   427
    by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
haftmann@36301
   428
  finally show ?thesis .
haftmann@36301
   429
qed
haftmann@36301
   430
haftmann@36348
   431
lemma neg_less_divide_eq [field_simps]:
haftmann@36301
   432
 "c < 0 ==> (a < b/c) = (b < a*c)"
haftmann@36301
   433
proof -
haftmann@36301
   434
  assume less: "c<0"
haftmann@36301
   435
  hence "(a < b/c) = ((b/c)*c < a*c)"
haftmann@36304
   436
    by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   437
  also have "... = (b < a*c)"
haftmann@36301
   438
    by (simp add: less_imp_not_eq [OF less] divide_inverse mult_assoc) 
haftmann@36301
   439
  finally show ?thesis .
haftmann@36301
   440
qed
haftmann@36301
   441
haftmann@36348
   442
lemma pos_divide_less_eq [field_simps]:
haftmann@36301
   443
     "0 < c ==> (b/c < a) = (b < a*c)"
haftmann@36301
   444
proof -
haftmann@36301
   445
  assume less: "0<c"
haftmann@36301
   446
  hence "(b/c < a) = ((b/c)*c < a*c)"
haftmann@36304
   447
    by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   448
  also have "... = (b < a*c)"
haftmann@36301
   449
    by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
haftmann@36301
   450
  finally show ?thesis .
haftmann@36301
   451
qed
haftmann@36301
   452
haftmann@36348
   453
lemma neg_divide_less_eq [field_simps]:
haftmann@36301
   454
 "c < 0 ==> (b/c < a) = (a*c < b)"
haftmann@36301
   455
proof -
haftmann@36301
   456
  assume less: "c<0"
haftmann@36301
   457
  hence "(b/c < a) = (a*c < (b/c)*c)"
haftmann@36304
   458
    by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   459
  also have "... = (a*c < b)"
haftmann@36301
   460
    by (simp add: less_imp_not_eq [OF less] divide_inverse mult_assoc) 
haftmann@36301
   461
  finally show ?thesis .
haftmann@36301
   462
qed
haftmann@36301
   463
haftmann@36348
   464
lemma pos_divide_le_eq [field_simps]: "0 < c ==> (b/c \<le> a) = (b \<le> a*c)"
haftmann@36301
   465
proof -
haftmann@36301
   466
  assume less: "0<c"
haftmann@36301
   467
  hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
haftmann@36304
   468
    by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   469
  also have "... = (b \<le> a*c)"
haftmann@36301
   470
    by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
haftmann@36301
   471
  finally show ?thesis .
haftmann@36301
   472
qed
haftmann@36301
   473
haftmann@36348
   474
lemma neg_divide_le_eq [field_simps]: "c < 0 ==> (b/c \<le> a) = (a*c \<le> b)"
haftmann@36301
   475
proof -
haftmann@36301
   476
  assume less: "c<0"
haftmann@36301
   477
  hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
haftmann@36304
   478
    by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   479
  also have "... = (a*c \<le> b)"
haftmann@36301
   480
    by (simp add: less_imp_not_eq [OF less] divide_inverse mult_assoc) 
haftmann@36301
   481
  finally show ?thesis .
haftmann@36301
   482
qed
haftmann@36301
   483
haftmann@36301
   484
text{* Lemmas @{text sign_simps} is a first attempt to automate proofs
haftmann@36301
   485
of positivity/negativity needed for @{text field_simps}. Have not added @{text
haftmann@36301
   486
sign_simps} to @{text field_simps} because the former can lead to case
haftmann@36301
   487
explosions. *}
haftmann@36301
   488
haftmann@36348
   489
lemmas sign_simps [no_atp] = algebra_simps
haftmann@36348
   490
  zero_less_mult_iff mult_less_0_iff
haftmann@36348
   491
haftmann@36348
   492
lemmas (in -) sign_simps [no_atp] = algebra_simps
haftmann@36301
   493
  zero_less_mult_iff mult_less_0_iff
haftmann@36301
   494
haftmann@36301
   495
(* Only works once linear arithmetic is installed:
haftmann@36301
   496
text{*An example:*}
haftmann@36301
   497
lemma fixes a b c d e f :: "'a::linordered_field"
haftmann@36301
   498
shows "\<lbrakk>a>b; c<d; e<f; 0 < u \<rbrakk> \<Longrightarrow>
haftmann@36301
   499
 ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) <
haftmann@36301
   500
 ((e-f)*(a-b)*(c-d))/((e-f)*(a-b)*(c-d)) + u"
haftmann@36301
   501
apply(subgoal_tac "(c-d)*(e-f)*(a-b) > 0")
haftmann@36301
   502
 prefer 2 apply(simp add:sign_simps)
haftmann@36301
   503
apply(subgoal_tac "(c-d)*(e-f)*(a-b)*u > 0")
haftmann@36301
   504
 prefer 2 apply(simp add:sign_simps)
haftmann@36301
   505
apply(simp add:field_simps)
haftmann@36301
   506
done
haftmann@36301
   507
*)
haftmann@36301
   508
haftmann@36301
   509
lemma divide_pos_pos:
haftmann@36301
   510
  "0 < x ==> 0 < y ==> 0 < x / y"
haftmann@36301
   511
by(simp add:field_simps)
haftmann@36301
   512
haftmann@36301
   513
lemma divide_nonneg_pos:
haftmann@36301
   514
  "0 <= x ==> 0 < y ==> 0 <= x / y"
haftmann@36301
   515
by(simp add:field_simps)
haftmann@36301
   516
haftmann@36301
   517
lemma divide_neg_pos:
haftmann@36301
   518
  "x < 0 ==> 0 < y ==> x / y < 0"
haftmann@36301
   519
by(simp add:field_simps)
haftmann@36301
   520
haftmann@36301
   521
lemma divide_nonpos_pos:
haftmann@36301
   522
  "x <= 0 ==> 0 < y ==> x / y <= 0"
haftmann@36301
   523
by(simp add:field_simps)
haftmann@36301
   524
haftmann@36301
   525
lemma divide_pos_neg:
haftmann@36301
   526
  "0 < x ==> y < 0 ==> x / y < 0"
haftmann@36301
   527
by(simp add:field_simps)
haftmann@36301
   528
haftmann@36301
   529
lemma divide_nonneg_neg:
haftmann@36301
   530
  "0 <= x ==> y < 0 ==> x / y <= 0" 
haftmann@36301
   531
by(simp add:field_simps)
haftmann@36301
   532
haftmann@36301
   533
lemma divide_neg_neg:
haftmann@36301
   534
  "x < 0 ==> y < 0 ==> 0 < x / y"
haftmann@36301
   535
by(simp add:field_simps)
haftmann@36301
   536
haftmann@36301
   537
lemma divide_nonpos_neg:
haftmann@36301
   538
  "x <= 0 ==> y < 0 ==> 0 <= x / y"
haftmann@36301
   539
by(simp add:field_simps)
haftmann@36301
   540
haftmann@36301
   541
lemma divide_strict_right_mono:
haftmann@36301
   542
     "[|a < b; 0 < c|] ==> a / c < b / c"
haftmann@36301
   543
by (simp add: less_imp_not_eq2 divide_inverse mult_strict_right_mono 
haftmann@36301
   544
              positive_imp_inverse_positive)
haftmann@36301
   545
haftmann@36301
   546
haftmann@36301
   547
lemma divide_strict_right_mono_neg:
haftmann@36301
   548
     "[|b < a; c < 0|] ==> a / c < b / c"
haftmann@36301
   549
apply (drule divide_strict_right_mono [of _ _ "-c"], simp)
haftmann@36301
   550
apply (simp add: less_imp_not_eq nonzero_minus_divide_right [symmetric])
haftmann@36301
   551
done
haftmann@36301
   552
haftmann@36301
   553
text{*The last premise ensures that @{term a} and @{term b} 
haftmann@36301
   554
      have the same sign*}
haftmann@36301
   555
lemma divide_strict_left_mono:
haftmann@36301
   556
  "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / b"
haftmann@36301
   557
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono)
haftmann@36301
   558
haftmann@36301
   559
lemma divide_left_mono:
haftmann@36301
   560
  "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / b"
haftmann@36301
   561
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_right_mono)
haftmann@36301
   562
haftmann@36301
   563
lemma divide_strict_left_mono_neg:
haftmann@36301
   564
  "[|a < b; c < 0; 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_neg)
haftmann@36301
   566
haftmann@36301
   567
lemma mult_imp_div_pos_le: "0 < y ==> x <= z * y ==>
haftmann@36301
   568
    x / y <= z"
haftmann@36301
   569
by (subst pos_divide_le_eq, assumption+)
haftmann@36301
   570
haftmann@36301
   571
lemma mult_imp_le_div_pos: "0 < y ==> z * y <= x ==>
haftmann@36301
   572
    z <= x / y"
haftmann@36301
   573
by(simp add:field_simps)
haftmann@36301
   574
haftmann@36301
   575
lemma mult_imp_div_pos_less: "0 < y ==> x < z * y ==>
haftmann@36301
   576
    x / y < z"
haftmann@36301
   577
by(simp add:field_simps)
haftmann@36301
   578
haftmann@36301
   579
lemma mult_imp_less_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 frac_le: "0 <= x ==> 
haftmann@36301
   584
    x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
haftmann@36301
   585
  apply (rule mult_imp_div_pos_le)
haftmann@36301
   586
  apply simp
haftmann@36301
   587
  apply (subst times_divide_eq_left)
haftmann@36301
   588
  apply (rule mult_imp_le_div_pos, assumption)
haftmann@36301
   589
  apply (rule mult_mono)
haftmann@36301
   590
  apply simp_all
haftmann@36301
   591
done
haftmann@36301
   592
haftmann@36301
   593
lemma frac_less: "0 <= x ==> 
haftmann@36301
   594
    x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
haftmann@36301
   595
  apply (rule mult_imp_div_pos_less)
haftmann@36301
   596
  apply simp
haftmann@36301
   597
  apply (subst times_divide_eq_left)
haftmann@36301
   598
  apply (rule mult_imp_less_div_pos, assumption)
haftmann@36301
   599
  apply (erule mult_less_le_imp_less)
haftmann@36301
   600
  apply simp_all
haftmann@36301
   601
done
haftmann@36301
   602
haftmann@36301
   603
lemma frac_less2: "0 < x ==> 
haftmann@36301
   604
    x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
haftmann@36301
   605
  apply (rule mult_imp_div_pos_less)
haftmann@36301
   606
  apply simp_all
haftmann@36301
   607
  apply (rule mult_imp_less_div_pos, assumption)
haftmann@36301
   608
  apply (erule mult_le_less_imp_less)
haftmann@36301
   609
  apply simp_all
haftmann@36301
   610
done
haftmann@36301
   611
haftmann@36301
   612
text{*It's not obvious whether these should be simprules or not. 
haftmann@36301
   613
  Their effect is to gather terms into one big fraction, like
haftmann@36301
   614
  a*b*c / x*y*z. The rationale for that is unclear, but many proofs 
haftmann@36301
   615
  seem to need them.*}
haftmann@36301
   616
haftmann@36301
   617
lemma less_half_sum: "a < b ==> a < (a+b) / (1+1)"
haftmann@36301
   618
by (simp add: field_simps zero_less_two)
haftmann@36301
   619
haftmann@36301
   620
lemma gt_half_sum: "a < b ==> (a+b)/(1+1) < b"
haftmann@36301
   621
by (simp add: field_simps zero_less_two)
haftmann@36301
   622
haftmann@36301
   623
subclass dense_linorder
haftmann@36301
   624
proof
haftmann@36301
   625
  fix x y :: 'a
haftmann@36301
   626
  from less_add_one show "\<exists>y. x < y" .. 
haftmann@36301
   627
  from less_add_one have "x + (- 1) < (x + 1) + (- 1)" by (rule add_strict_right_mono)
haftmann@36301
   628
  then have "x - 1 < x + 1 - 1" by (simp only: diff_minus [symmetric])
haftmann@36301
   629
  then have "x - 1 < x" by (simp add: algebra_simps)
haftmann@36301
   630
  then show "\<exists>y. y < x" ..
haftmann@36301
   631
  show "x < y \<Longrightarrow> \<exists>z>x. z < y" by (blast intro!: less_half_sum gt_half_sum)
haftmann@36301
   632
qed
haftmann@36301
   633
haftmann@36301
   634
lemma nonzero_abs_inverse:
haftmann@36301
   635
     "a \<noteq> 0 ==> \<bar>inverse a\<bar> = inverse \<bar>a\<bar>"
haftmann@36301
   636
apply (auto simp add: neq_iff abs_if nonzero_inverse_minus_eq 
haftmann@36301
   637
                      negative_imp_inverse_negative)
haftmann@36301
   638
apply (blast intro: positive_imp_inverse_positive elim: less_asym) 
haftmann@36301
   639
done
haftmann@36301
   640
haftmann@36301
   641
lemma nonzero_abs_divide:
haftmann@36301
   642
     "b \<noteq> 0 ==> \<bar>a / b\<bar> = \<bar>a\<bar> / \<bar>b\<bar>"
haftmann@36301
   643
  by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
haftmann@36301
   644
haftmann@36301
   645
lemma field_le_epsilon:
haftmann@36301
   646
  assumes e: "\<And>e. 0 < e \<Longrightarrow> x \<le> y + e"
haftmann@36301
   647
  shows "x \<le> y"
haftmann@36301
   648
proof (rule dense_le)
haftmann@36301
   649
  fix t assume "t < x"
haftmann@36301
   650
  hence "0 < x - t" by (simp add: less_diff_eq)
haftmann@36301
   651
  from e [OF this] have "x + 0 \<le> x + (y - t)" by (simp add: algebra_simps)
haftmann@36301
   652
  then have "0 \<le> y - t" by (simp only: add_le_cancel_left)
haftmann@36301
   653
  then show "t \<le> y" by (simp add: algebra_simps)
haftmann@36301
   654
qed
haftmann@36301
   655
haftmann@36301
   656
end
haftmann@36301
   657
haftmann@36414
   658
class linordered_field_inverse_zero = linordered_field + field_inverse_zero
haftmann@36348
   659
begin
haftmann@36348
   660
haftmann@36301
   661
lemma le_divide_eq:
haftmann@36301
   662
  "(a \<le> b/c) = 
haftmann@36301
   663
   (if 0 < c then a*c \<le> b
haftmann@36301
   664
             else if c < 0 then b \<le> a*c
haftmann@36409
   665
             else  a \<le> 0)"
haftmann@36301
   666
apply (cases "c=0", simp) 
haftmann@36301
   667
apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
haftmann@36301
   668
done
haftmann@36301
   669
paulson@14277
   670
lemma inverse_positive_iff_positive [simp]:
haftmann@36409
   671
  "(0 < inverse a) = (0 < a)"
haftmann@21328
   672
apply (cases "a = 0", simp)
paulson@14277
   673
apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
paulson@14277
   674
done
paulson@14277
   675
paulson@14277
   676
lemma inverse_negative_iff_negative [simp]:
haftmann@36409
   677
  "(inverse a < 0) = (a < 0)"
haftmann@21328
   678
apply (cases "a = 0", simp)
paulson@14277
   679
apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
paulson@14277
   680
done
paulson@14277
   681
paulson@14277
   682
lemma inverse_nonnegative_iff_nonnegative [simp]:
haftmann@36409
   683
  "0 \<le> inverse a \<longleftrightarrow> 0 \<le> a"
haftmann@36409
   684
  by (simp add: not_less [symmetric])
paulson@14277
   685
paulson@14277
   686
lemma inverse_nonpositive_iff_nonpositive [simp]:
haftmann@36409
   687
  "inverse a \<le> 0 \<longleftrightarrow> a \<le> 0"
haftmann@36409
   688
  by (simp add: not_less [symmetric])
paulson@14277
   689
paulson@14365
   690
lemma one_less_inverse_iff:
haftmann@36409
   691
  "1 < inverse x \<longleftrightarrow> 0 < x \<and> x < 1"
nipkow@23482
   692
proof cases
paulson@14365
   693
  assume "0 < x"
paulson@14365
   694
    with inverse_less_iff_less [OF zero_less_one, of x]
paulson@14365
   695
    show ?thesis by simp
paulson@14365
   696
next
paulson@14365
   697
  assume notless: "~ (0 < x)"
paulson@14365
   698
  have "~ (1 < inverse x)"
paulson@14365
   699
  proof
paulson@14365
   700
    assume "1 < inverse x"
haftmann@36409
   701
    also with notless have "... \<le> 0" by simp
paulson@14365
   702
    also have "... < 1" by (rule zero_less_one) 
paulson@14365
   703
    finally show False by auto
paulson@14365
   704
  qed
paulson@14365
   705
  with notless show ?thesis by simp
paulson@14365
   706
qed
paulson@14365
   707
paulson@14365
   708
lemma one_le_inverse_iff:
haftmann@36409
   709
  "1 \<le> inverse x \<longleftrightarrow> 0 < x \<and> x \<le> 1"
haftmann@36409
   710
proof (cases "x = 1")
haftmann@36409
   711
  case True then show ?thesis by simp
haftmann@36409
   712
next
haftmann@36409
   713
  case False then have "inverse x \<noteq> 1" by simp
haftmann@36409
   714
  then have "1 \<noteq> inverse x" by blast
haftmann@36409
   715
  then have "1 \<le> inverse x \<longleftrightarrow> 1 < inverse x" by (simp add: le_less)
haftmann@36409
   716
  with False show ?thesis by (auto simp add: one_less_inverse_iff)
haftmann@36409
   717
qed
paulson@14365
   718
paulson@14365
   719
lemma inverse_less_1_iff:
haftmann@36409
   720
  "inverse x < 1 \<longleftrightarrow> x \<le> 0 \<or> 1 < x"
haftmann@36409
   721
  by (simp add: not_le [symmetric] one_le_inverse_iff) 
paulson@14365
   722
paulson@14365
   723
lemma inverse_le_1_iff:
haftmann@36409
   724
  "inverse x \<le> 1 \<longleftrightarrow> x \<le> 0 \<or> 1 \<le> x"
haftmann@36409
   725
  by (simp add: not_less [symmetric] one_less_inverse_iff) 
paulson@14365
   726
paulson@14288
   727
lemma divide_le_eq:
paulson@14288
   728
  "(b/c \<le> a) = 
paulson@14288
   729
   (if 0 < c then b \<le> a*c
paulson@14288
   730
             else if c < 0 then a*c \<le> b
haftmann@36409
   731
             else 0 \<le> a)"
haftmann@21328
   732
apply (cases "c=0", simp) 
haftmann@36409
   733
apply (force simp add: pos_divide_le_eq neg_divide_le_eq) 
paulson@14288
   734
done
paulson@14288
   735
paulson@14288
   736
lemma less_divide_eq:
paulson@14288
   737
  "(a < b/c) = 
paulson@14288
   738
   (if 0 < c then a*c < b
paulson@14288
   739
             else if c < 0 then b < a*c
haftmann@36409
   740
             else  a < 0)"
haftmann@21328
   741
apply (cases "c=0", simp) 
haftmann@36409
   742
apply (force simp add: pos_less_divide_eq neg_less_divide_eq) 
paulson@14288
   743
done
paulson@14288
   744
paulson@14288
   745
lemma divide_less_eq:
paulson@14288
   746
  "(b/c < a) = 
paulson@14288
   747
   (if 0 < c then b < a*c
paulson@14288
   748
             else if c < 0 then a*c < b
haftmann@36409
   749
             else 0 < a)"
haftmann@21328
   750
apply (cases "c=0", simp) 
haftmann@36409
   751
apply (force simp add: pos_divide_less_eq neg_divide_less_eq)
paulson@14288
   752
done
paulson@14288
   753
haftmann@36301
   754
text {*Division and Signs*}
avigad@16775
   755
avigad@16775
   756
lemma zero_less_divide_iff:
haftmann@36409
   757
     "(0 < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
avigad@16775
   758
by (simp add: divide_inverse zero_less_mult_iff)
avigad@16775
   759
avigad@16775
   760
lemma divide_less_0_iff:
haftmann@36409
   761
     "(a/b < 0) = 
avigad@16775
   762
      (0 < a & b < 0 | a < 0 & 0 < b)"
avigad@16775
   763
by (simp add: divide_inverse mult_less_0_iff)
avigad@16775
   764
avigad@16775
   765
lemma zero_le_divide_iff:
haftmann@36409
   766
     "(0 \<le> a/b) =
avigad@16775
   767
      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
avigad@16775
   768
by (simp add: divide_inverse zero_le_mult_iff)
avigad@16775
   769
avigad@16775
   770
lemma divide_le_0_iff:
haftmann@36409
   771
     "(a/b \<le> 0) =
avigad@16775
   772
      (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
avigad@16775
   773
by (simp add: divide_inverse mult_le_0_iff)
avigad@16775
   774
haftmann@36301
   775
text {* Division and the Number One *}
paulson@14353
   776
paulson@14353
   777
text{*Simplify expressions equated with 1*}
paulson@14353
   778
blanchet@35828
   779
lemma zero_eq_1_divide_iff [simp,no_atp]:
haftmann@36409
   780
     "(0 = 1/a) = (a = 0)"
nipkow@23482
   781
apply (cases "a=0", simp)
nipkow@23482
   782
apply (auto simp add: nonzero_eq_divide_eq)
paulson@14353
   783
done
paulson@14353
   784
blanchet@35828
   785
lemma one_divide_eq_0_iff [simp,no_atp]:
haftmann@36409
   786
     "(1/a = 0) = (a = 0)"
nipkow@23482
   787
apply (cases "a=0", simp)
nipkow@23482
   788
apply (insert zero_neq_one [THEN not_sym])
nipkow@23482
   789
apply (auto simp add: nonzero_divide_eq_eq)
paulson@14353
   790
done
paulson@14353
   791
paulson@14353
   792
text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
haftmann@36423
   793
haftmann@36423
   794
lemma zero_le_divide_1_iff [simp, no_atp]:
haftmann@36423
   795
  "0 \<le> 1 / a \<longleftrightarrow> 0 \<le> a"
haftmann@36423
   796
  by (simp add: zero_le_divide_iff)
paulson@17085
   797
haftmann@36423
   798
lemma zero_less_divide_1_iff [simp, no_atp]:
haftmann@36423
   799
  "0 < 1 / a \<longleftrightarrow> 0 < a"
haftmann@36423
   800
  by (simp add: zero_less_divide_iff)
haftmann@36423
   801
haftmann@36423
   802
lemma divide_le_0_1_iff [simp, no_atp]:
haftmann@36423
   803
  "1 / a \<le> 0 \<longleftrightarrow> a \<le> 0"
haftmann@36423
   804
  by (simp add: divide_le_0_iff)
haftmann@36423
   805
haftmann@36423
   806
lemma divide_less_0_1_iff [simp, no_atp]:
haftmann@36423
   807
  "1 / a < 0 \<longleftrightarrow> a < 0"
haftmann@36423
   808
  by (simp add: divide_less_0_iff)
paulson@14353
   809
paulson@14293
   810
lemma divide_right_mono:
haftmann@36409
   811
     "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/c"
haftmann@36409
   812
by (force simp add: divide_strict_right_mono le_less)
paulson@14293
   813
haftmann@36409
   814
lemma divide_right_mono_neg: "a <= b 
avigad@16775
   815
    ==> c <= 0 ==> b / c <= a / c"
nipkow@23482
   816
apply (drule divide_right_mono [of _ _ "- c"])
nipkow@23482
   817
apply auto
avigad@16775
   818
done
avigad@16775
   819
haftmann@36409
   820
lemma divide_left_mono_neg: "a <= b 
avigad@16775
   821
    ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
avigad@16775
   822
  apply (drule divide_left_mono [of _ _ "- c"])
avigad@16775
   823
  apply (auto simp add: mult_commute)
avigad@16775
   824
done
avigad@16775
   825
avigad@16775
   826
text{*Simplify quotients that are compared with the value 1.*}
avigad@16775
   827
blanchet@35828
   828
lemma le_divide_eq_1 [no_atp]:
haftmann@36409
   829
  "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
avigad@16775
   830
by (auto simp add: le_divide_eq)
avigad@16775
   831
blanchet@35828
   832
lemma divide_le_eq_1 [no_atp]:
haftmann@36409
   833
  "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
avigad@16775
   834
by (auto simp add: divide_le_eq)
avigad@16775
   835
blanchet@35828
   836
lemma less_divide_eq_1 [no_atp]:
haftmann@36409
   837
  "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
avigad@16775
   838
by (auto simp add: less_divide_eq)
avigad@16775
   839
blanchet@35828
   840
lemma divide_less_eq_1 [no_atp]:
haftmann@36409
   841
  "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
avigad@16775
   842
by (auto simp add: divide_less_eq)
avigad@16775
   843
wenzelm@23389
   844
haftmann@36301
   845
text {*Conditional Simplification Rules: No Case Splits*}
avigad@16775
   846
blanchet@35828
   847
lemma le_divide_eq_1_pos [simp,no_atp]:
haftmann@36409
   848
  "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
avigad@16775
   849
by (auto simp add: le_divide_eq)
avigad@16775
   850
blanchet@35828
   851
lemma le_divide_eq_1_neg [simp,no_atp]:
haftmann@36409
   852
  "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
avigad@16775
   853
by (auto simp add: le_divide_eq)
avigad@16775
   854
blanchet@35828
   855
lemma divide_le_eq_1_pos [simp,no_atp]:
haftmann@36409
   856
  "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
avigad@16775
   857
by (auto simp add: divide_le_eq)
avigad@16775
   858
blanchet@35828
   859
lemma divide_le_eq_1_neg [simp,no_atp]:
haftmann@36409
   860
  "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
avigad@16775
   861
by (auto simp add: divide_le_eq)
avigad@16775
   862
blanchet@35828
   863
lemma less_divide_eq_1_pos [simp,no_atp]:
haftmann@36409
   864
  "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
avigad@16775
   865
by (auto simp add: less_divide_eq)
avigad@16775
   866
blanchet@35828
   867
lemma less_divide_eq_1_neg [simp,no_atp]:
haftmann@36409
   868
  "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
avigad@16775
   869
by (auto simp add: less_divide_eq)
avigad@16775
   870
blanchet@35828
   871
lemma divide_less_eq_1_pos [simp,no_atp]:
haftmann@36409
   872
  "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
paulson@18649
   873
by (auto simp add: divide_less_eq)
paulson@18649
   874
blanchet@35828
   875
lemma divide_less_eq_1_neg [simp,no_atp]:
haftmann@36409
   876
  "a < 0 \<Longrightarrow> b/a < 1 <-> a < b"
avigad@16775
   877
by (auto simp add: divide_less_eq)
avigad@16775
   878
blanchet@35828
   879
lemma eq_divide_eq_1 [simp,no_atp]:
haftmann@36409
   880
  "(1 = b/a) = ((a \<noteq> 0 & a = b))"
avigad@16775
   881
by (auto simp add: eq_divide_eq)
avigad@16775
   882
blanchet@35828
   883
lemma divide_eq_eq_1 [simp,no_atp]:
haftmann@36409
   884
  "(b/a = 1) = ((a \<noteq> 0 & a = b))"
avigad@16775
   885
by (auto simp add: divide_eq_eq)
avigad@16775
   886
paulson@14294
   887
lemma abs_inverse [simp]:
haftmann@36409
   888
     "\<bar>inverse a\<bar> = 
haftmann@36301
   889
      inverse \<bar>a\<bar>"
haftmann@21328
   890
apply (cases "a=0", simp) 
paulson@14294
   891
apply (simp add: nonzero_abs_inverse) 
paulson@14294
   892
done
paulson@14294
   893
paulson@15234
   894
lemma abs_divide [simp]:
haftmann@36409
   895
     "\<bar>a / b\<bar> = \<bar>a\<bar> / \<bar>b\<bar>"
haftmann@21328
   896
apply (cases "b=0", simp) 
paulson@14294
   897
apply (simp add: nonzero_abs_divide) 
paulson@14294
   898
done
paulson@14294
   899
haftmann@36409
   900
lemma abs_div_pos: "0 < y ==> 
haftmann@36301
   901
    \<bar>x\<bar> / y = \<bar>x / y\<bar>"
haftmann@25304
   902
  apply (subst abs_divide)
haftmann@25304
   903
  apply (simp add: order_less_imp_le)
haftmann@25304
   904
done
avigad@16775
   905
hoelzl@35579
   906
lemma field_le_mult_one_interval:
hoelzl@35579
   907
  assumes *: "\<And>z. \<lbrakk> 0 < z ; z < 1 \<rbrakk> \<Longrightarrow> z * x \<le> y"
hoelzl@35579
   908
  shows "x \<le> y"
hoelzl@35579
   909
proof (cases "0 < x")
hoelzl@35579
   910
  assume "0 < x"
hoelzl@35579
   911
  thus ?thesis
hoelzl@35579
   912
    using dense_le_bounded[of 0 1 "y/x"] *
hoelzl@35579
   913
    unfolding le_divide_eq if_P[OF `0 < x`] by simp
hoelzl@35579
   914
next
hoelzl@35579
   915
  assume "\<not>0 < x" hence "x \<le> 0" by simp
hoelzl@35579
   916
  obtain s::'a where s: "0 < s" "s < 1" using dense[of 0 "1\<Colon>'a"] by auto
hoelzl@35579
   917
  hence "x \<le> s * x" using mult_le_cancel_right[of 1 x s] `x \<le> 0` by auto
hoelzl@35579
   918
  also note *[OF s]
hoelzl@35579
   919
  finally show ?thesis .
hoelzl@35579
   920
qed
haftmann@35090
   921
haftmann@36409
   922
end
haftmann@36409
   923
haftmann@33364
   924
code_modulename SML
haftmann@35050
   925
  Fields Arith
haftmann@33364
   926
haftmann@33364
   927
code_modulename OCaml
haftmann@35050
   928
  Fields Arith
haftmann@33364
   929
haftmann@33364
   930
code_modulename Haskell
haftmann@35050
   931
  Fields Arith
haftmann@33364
   932
paulson@14265
   933
end