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