src/HOL/Fields.thy
author huffman
Sat Sep 03 09:12:19 2011 -0700 (2011-09-03)
changeset 44680 761f427ef1ab
parent 44064 5bce8ff0d9ae
child 44921 58eef4843641
permissions -rw-r--r--
simplify proof
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@44064
    16
subsection {* Division rings *}
huffman@44064
    17
huffman@44064
    18
text {*
huffman@44064
    19
  A division ring is like a field, but without the commutativity requirement.
huffman@44064
    20
*}
huffman@44064
    21
huffman@44064
    22
class inverse =
huffman@44064
    23
  fixes inverse :: "'a \<Rightarrow> 'a"
huffman@44064
    24
    and divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "'/" 70)
huffman@44064
    25
huffman@44064
    26
class division_ring = ring_1 + inverse +
huffman@44064
    27
  assumes left_inverse [simp]:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
huffman@44064
    28
  assumes right_inverse [simp]: "a \<noteq> 0 \<Longrightarrow> a * inverse a = 1"
huffman@44064
    29
  assumes divide_inverse: "a / b = a * inverse b"
huffman@44064
    30
begin
huffman@44064
    31
huffman@44064
    32
subclass ring_1_no_zero_divisors
huffman@44064
    33
proof
huffman@44064
    34
  fix a b :: 'a
huffman@44064
    35
  assume a: "a \<noteq> 0" and b: "b \<noteq> 0"
huffman@44064
    36
  show "a * b \<noteq> 0"
huffman@44064
    37
  proof
huffman@44064
    38
    assume ab: "a * b = 0"
huffman@44064
    39
    hence "0 = inverse a * (a * b) * inverse b" by simp
huffman@44064
    40
    also have "\<dots> = (inverse a * a) * (b * inverse b)"
huffman@44064
    41
      by (simp only: mult_assoc)
huffman@44064
    42
    also have "\<dots> = 1" using a b by simp
huffman@44064
    43
    finally show False by simp
huffman@44064
    44
  qed
huffman@44064
    45
qed
huffman@44064
    46
huffman@44064
    47
lemma nonzero_imp_inverse_nonzero:
huffman@44064
    48
  "a \<noteq> 0 \<Longrightarrow> inverse a \<noteq> 0"
huffman@44064
    49
proof
huffman@44064
    50
  assume ianz: "inverse a = 0"
huffman@44064
    51
  assume "a \<noteq> 0"
huffman@44064
    52
  hence "1 = a * inverse a" by simp
huffman@44064
    53
  also have "... = 0" by (simp add: ianz)
huffman@44064
    54
  finally have "1 = 0" .
huffman@44064
    55
  thus False by (simp add: eq_commute)
huffman@44064
    56
qed
huffman@44064
    57
huffman@44064
    58
lemma inverse_zero_imp_zero:
huffman@44064
    59
  "inverse a = 0 \<Longrightarrow> a = 0"
huffman@44064
    60
apply (rule classical)
huffman@44064
    61
apply (drule nonzero_imp_inverse_nonzero)
huffman@44064
    62
apply auto
huffman@44064
    63
done
huffman@44064
    64
huffman@44064
    65
lemma inverse_unique: 
huffman@44064
    66
  assumes ab: "a * b = 1"
huffman@44064
    67
  shows "inverse a = b"
huffman@44064
    68
proof -
huffman@44064
    69
  have "a \<noteq> 0" using ab by (cases "a = 0") simp_all
huffman@44064
    70
  moreover have "inverse a * (a * b) = inverse a" by (simp add: ab)
huffman@44064
    71
  ultimately show ?thesis by (simp add: mult_assoc [symmetric])
huffman@44064
    72
qed
huffman@44064
    73
huffman@44064
    74
lemma nonzero_inverse_minus_eq:
huffman@44064
    75
  "a \<noteq> 0 \<Longrightarrow> inverse (- a) = - inverse a"
huffman@44064
    76
by (rule inverse_unique) simp
huffman@44064
    77
huffman@44064
    78
lemma nonzero_inverse_inverse_eq:
huffman@44064
    79
  "a \<noteq> 0 \<Longrightarrow> inverse (inverse a) = a"
huffman@44064
    80
by (rule inverse_unique) simp
huffman@44064
    81
huffman@44064
    82
lemma nonzero_inverse_eq_imp_eq:
huffman@44064
    83
  assumes "inverse a = inverse b" and "a \<noteq> 0" and "b \<noteq> 0"
huffman@44064
    84
  shows "a = b"
huffman@44064
    85
proof -
huffman@44064
    86
  from `inverse a = inverse b`
huffman@44064
    87
  have "inverse (inverse a) = inverse (inverse b)" by (rule arg_cong)
huffman@44064
    88
  with `a \<noteq> 0` and `b \<noteq> 0` show "a = b"
huffman@44064
    89
    by (simp add: nonzero_inverse_inverse_eq)
huffman@44064
    90
qed
huffman@44064
    91
huffman@44064
    92
lemma inverse_1 [simp]: "inverse 1 = 1"
huffman@44064
    93
by (rule inverse_unique) simp
huffman@44064
    94
huffman@44064
    95
lemma nonzero_inverse_mult_distrib: 
huffman@44064
    96
  assumes "a \<noteq> 0" and "b \<noteq> 0"
huffman@44064
    97
  shows "inverse (a * b) = inverse b * inverse a"
huffman@44064
    98
proof -
huffman@44064
    99
  have "a * (b * inverse b) * inverse a = 1" using assms by simp
huffman@44064
   100
  hence "a * b * (inverse b * inverse a) = 1" by (simp only: mult_assoc)
huffman@44064
   101
  thus ?thesis by (rule inverse_unique)
huffman@44064
   102
qed
huffman@44064
   103
huffman@44064
   104
lemma division_ring_inverse_add:
huffman@44064
   105
  "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a + inverse b = inverse a * (a + b) * inverse b"
huffman@44064
   106
by (simp add: algebra_simps)
huffman@44064
   107
huffman@44064
   108
lemma division_ring_inverse_diff:
huffman@44064
   109
  "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a - inverse b = inverse a * (b - a) * inverse b"
huffman@44064
   110
by (simp add: algebra_simps)
huffman@44064
   111
huffman@44064
   112
lemma right_inverse_eq: "b \<noteq> 0 \<Longrightarrow> a / b = 1 \<longleftrightarrow> a = b"
huffman@44064
   113
proof
huffman@44064
   114
  assume neq: "b \<noteq> 0"
huffman@44064
   115
  {
huffman@44064
   116
    hence "a = (a / b) * b" by (simp add: divide_inverse mult_assoc)
huffman@44064
   117
    also assume "a / b = 1"
huffman@44064
   118
    finally show "a = b" by simp
huffman@44064
   119
  next
huffman@44064
   120
    assume "a = b"
huffman@44064
   121
    with neq show "a / b = 1" by (simp add: divide_inverse)
huffman@44064
   122
  }
huffman@44064
   123
qed
huffman@44064
   124
huffman@44064
   125
lemma nonzero_inverse_eq_divide: "a \<noteq> 0 \<Longrightarrow> inverse a = 1 / a"
huffman@44064
   126
by (simp add: divide_inverse)
huffman@44064
   127
huffman@44064
   128
lemma divide_self [simp]: "a \<noteq> 0 \<Longrightarrow> a / a = 1"
huffman@44064
   129
by (simp add: divide_inverse)
huffman@44064
   130
huffman@44064
   131
lemma divide_zero_left [simp]: "0 / a = 0"
huffman@44064
   132
by (simp add: divide_inverse)
huffman@44064
   133
huffman@44064
   134
lemma inverse_eq_divide: "inverse a = 1 / a"
huffman@44064
   135
by (simp add: divide_inverse)
huffman@44064
   136
huffman@44064
   137
lemma add_divide_distrib: "(a+b) / c = a/c + b/c"
huffman@44064
   138
by (simp add: divide_inverse algebra_simps)
huffman@44064
   139
huffman@44064
   140
lemma divide_1 [simp]: "a / 1 = a"
huffman@44064
   141
  by (simp add: divide_inverse)
huffman@44064
   142
huffman@44064
   143
lemma times_divide_eq_right [simp]: "a * (b / c) = (a * b) / c"
huffman@44064
   144
  by (simp add: divide_inverse mult_assoc)
huffman@44064
   145
huffman@44064
   146
lemma minus_divide_left: "- (a / b) = (-a) / b"
huffman@44064
   147
  by (simp add: divide_inverse)
huffman@44064
   148
huffman@44064
   149
lemma nonzero_minus_divide_right: "b \<noteq> 0 ==> - (a / b) = a / (- b)"
huffman@44064
   150
  by (simp add: divide_inverse nonzero_inverse_minus_eq)
huffman@44064
   151
huffman@44064
   152
lemma nonzero_minus_divide_divide: "b \<noteq> 0 ==> (-a) / (-b) = a / b"
huffman@44064
   153
  by (simp add: divide_inverse nonzero_inverse_minus_eq)
huffman@44064
   154
huffman@44064
   155
lemma divide_minus_left [simp, no_atp]: "(-a) / b = - (a / b)"
huffman@44064
   156
  by (simp add: divide_inverse)
huffman@44064
   157
huffman@44064
   158
lemma diff_divide_distrib: "(a - b) / c = a / c - b / c"
huffman@44064
   159
  by (simp add: diff_minus add_divide_distrib)
huffman@44064
   160
huffman@44064
   161
lemma nonzero_eq_divide_eq [field_simps]: "c \<noteq> 0 \<Longrightarrow> a = b / c \<longleftrightarrow> a * c = b"
huffman@44064
   162
proof -
huffman@44064
   163
  assume [simp]: "c \<noteq> 0"
huffman@44064
   164
  have "a = b / c \<longleftrightarrow> a * c = (b / c) * c" by simp
huffman@44064
   165
  also have "... \<longleftrightarrow> a * c = b" by (simp add: divide_inverse mult_assoc)
huffman@44064
   166
  finally show ?thesis .
huffman@44064
   167
qed
huffman@44064
   168
huffman@44064
   169
lemma nonzero_divide_eq_eq [field_simps]: "c \<noteq> 0 \<Longrightarrow> b / c = a \<longleftrightarrow> b = a * c"
huffman@44064
   170
proof -
huffman@44064
   171
  assume [simp]: "c \<noteq> 0"
huffman@44064
   172
  have "b / c = a \<longleftrightarrow> (b / c) * c = a * c" by simp
huffman@44064
   173
  also have "... \<longleftrightarrow> b = a * c" by (simp add: divide_inverse mult_assoc) 
huffman@44064
   174
  finally show ?thesis .
huffman@44064
   175
qed
huffman@44064
   176
huffman@44064
   177
lemma divide_eq_imp: "c \<noteq> 0 \<Longrightarrow> b = a * c \<Longrightarrow> b / c = a"
huffman@44064
   178
  by (simp add: divide_inverse mult_assoc)
huffman@44064
   179
huffman@44064
   180
lemma eq_divide_imp: "c \<noteq> 0 \<Longrightarrow> a * c = b \<Longrightarrow> a = b / c"
huffman@44064
   181
  by (drule sym) (simp add: divide_inverse mult_assoc)
huffman@44064
   182
huffman@44064
   183
end
huffman@44064
   184
huffman@44064
   185
class division_ring_inverse_zero = division_ring +
huffman@44064
   186
  assumes inverse_zero [simp]: "inverse 0 = 0"
huffman@44064
   187
begin
huffman@44064
   188
huffman@44064
   189
lemma divide_zero [simp]:
huffman@44064
   190
  "a / 0 = 0"
huffman@44064
   191
  by (simp add: divide_inverse)
huffman@44064
   192
huffman@44064
   193
lemma divide_self_if [simp]:
huffman@44064
   194
  "a / a = (if a = 0 then 0 else 1)"
huffman@44064
   195
  by simp
huffman@44064
   196
huffman@44064
   197
lemma inverse_nonzero_iff_nonzero [simp]:
huffman@44064
   198
  "inverse a = 0 \<longleftrightarrow> a = 0"
huffman@44064
   199
  by rule (fact inverse_zero_imp_zero, simp)
huffman@44064
   200
huffman@44064
   201
lemma inverse_minus_eq [simp]:
huffman@44064
   202
  "inverse (- a) = - inverse a"
huffman@44064
   203
proof cases
huffman@44064
   204
  assume "a=0" thus ?thesis by simp
huffman@44064
   205
next
huffman@44064
   206
  assume "a\<noteq>0" 
huffman@44064
   207
  thus ?thesis by (simp add: nonzero_inverse_minus_eq)
huffman@44064
   208
qed
huffman@44064
   209
huffman@44064
   210
lemma inverse_inverse_eq [simp]:
huffman@44064
   211
  "inverse (inverse a) = a"
huffman@44064
   212
proof cases
huffman@44064
   213
  assume "a=0" thus ?thesis by simp
huffman@44064
   214
next
huffman@44064
   215
  assume "a\<noteq>0" 
huffman@44064
   216
  thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
huffman@44064
   217
qed
huffman@44064
   218
huffman@44680
   219
lemma inverse_eq_imp_eq:
huffman@44680
   220
  "inverse a = inverse b \<Longrightarrow> a = b"
huffman@44680
   221
  by (drule arg_cong [where f="inverse"], simp)
huffman@44680
   222
huffman@44680
   223
lemma inverse_eq_iff_eq [simp]:
huffman@44680
   224
  "inverse a = inverse b \<longleftrightarrow> a = b"
huffman@44680
   225
  by (force dest!: inverse_eq_imp_eq)
huffman@44680
   226
huffman@44064
   227
end
huffman@44064
   228
huffman@44064
   229
subsection {* Fields *}
huffman@44064
   230
huffman@22987
   231
class field = comm_ring_1 + inverse +
haftmann@35084
   232
  assumes field_inverse: "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
haftmann@35084
   233
  assumes field_divide_inverse: "a / b = a * inverse b"
haftmann@25267
   234
begin
huffman@20496
   235
haftmann@25267
   236
subclass division_ring
haftmann@28823
   237
proof
huffman@22987
   238
  fix a :: 'a
huffman@22987
   239
  assume "a \<noteq> 0"
huffman@22987
   240
  thus "inverse a * a = 1" by (rule field_inverse)
huffman@22987
   241
  thus "a * inverse a = 1" by (simp only: mult_commute)
haftmann@35084
   242
next
haftmann@35084
   243
  fix a b :: 'a
haftmann@35084
   244
  show "a / b = a * inverse b" by (rule field_divide_inverse)
obua@14738
   245
qed
haftmann@25230
   246
huffman@27516
   247
subclass idom ..
haftmann@25230
   248
huffman@30630
   249
text{*There is no slick version using division by zero.*}
huffman@30630
   250
lemma inverse_add:
huffman@30630
   251
  "[| a \<noteq> 0;  b \<noteq> 0 |]
huffman@30630
   252
   ==> inverse a + inverse b = (a + b) * inverse a * inverse b"
huffman@30630
   253
by (simp add: division_ring_inverse_add mult_ac)
huffman@30630
   254
blanchet@35828
   255
lemma nonzero_mult_divide_mult_cancel_left [simp, no_atp]:
huffman@30630
   256
assumes [simp]: "b\<noteq>0" and [simp]: "c\<noteq>0" shows "(c*a)/(c*b) = a/b"
huffman@30630
   257
proof -
huffman@30630
   258
  have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
huffman@30630
   259
    by (simp add: divide_inverse nonzero_inverse_mult_distrib)
huffman@30630
   260
  also have "... =  a * inverse b * (inverse c * c)"
huffman@30630
   261
    by (simp only: mult_ac)
huffman@30630
   262
  also have "... =  a * inverse b" by simp
huffman@30630
   263
    finally show ?thesis by (simp add: divide_inverse)
huffman@30630
   264
qed
huffman@30630
   265
blanchet@35828
   266
lemma nonzero_mult_divide_mult_cancel_right [simp, no_atp]:
huffman@30630
   267
  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (a * c) / (b * c) = a / b"
huffman@30630
   268
by (simp add: mult_commute [of _ c])
huffman@30630
   269
haftmann@36304
   270
lemma times_divide_eq_left [simp]: "(b / c) * a = (b * a) / c"
haftmann@36301
   271
  by (simp add: divide_inverse mult_ac)
huffman@30630
   272
huffman@30630
   273
text {* These are later declared as simp rules. *}
blanchet@35828
   274
lemmas times_divide_eq [no_atp] = times_divide_eq_right times_divide_eq_left
huffman@30630
   275
huffman@30630
   276
lemma add_frac_eq:
huffman@30630
   277
  assumes "y \<noteq> 0" and "z \<noteq> 0"
huffman@30630
   278
  shows "x / y + w / z = (x * z + w * y) / (y * z)"
huffman@30630
   279
proof -
huffman@30630
   280
  have "x / y + w / z = (x * z) / (y * z) + (y * w) / (y * z)"
huffman@30630
   281
    using assms by simp
huffman@30630
   282
  also have "\<dots> = (x * z + y * w) / (y * z)"
huffman@30630
   283
    by (simp only: add_divide_distrib)
huffman@30630
   284
  finally show ?thesis
huffman@30630
   285
    by (simp only: mult_commute)
huffman@30630
   286
qed
huffman@30630
   287
huffman@30630
   288
text{*Special Cancellation Simprules for Division*}
huffman@30630
   289
blanchet@35828
   290
lemma nonzero_mult_divide_cancel_right [simp, no_atp]:
huffman@30630
   291
  "b \<noteq> 0 \<Longrightarrow> a * b / b = a"
haftmann@36301
   292
  using nonzero_mult_divide_mult_cancel_right [of 1 b a] by simp
huffman@30630
   293
blanchet@35828
   294
lemma nonzero_mult_divide_cancel_left [simp, no_atp]:
huffman@30630
   295
  "a \<noteq> 0 \<Longrightarrow> a * b / a = b"
huffman@30630
   296
using nonzero_mult_divide_mult_cancel_left [of 1 a b] by simp
huffman@30630
   297
blanchet@35828
   298
lemma nonzero_divide_mult_cancel_right [simp, no_atp]:
huffman@30630
   299
  "\<lbrakk>a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> b / (a * b) = 1 / a"
huffman@30630
   300
using nonzero_mult_divide_mult_cancel_right [of a b 1] by simp
huffman@30630
   301
blanchet@35828
   302
lemma nonzero_divide_mult_cancel_left [simp, no_atp]:
huffman@30630
   303
  "\<lbrakk>a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / (a * b) = 1 / b"
huffman@30630
   304
using nonzero_mult_divide_mult_cancel_left [of b a 1] by simp
huffman@30630
   305
blanchet@35828
   306
lemma nonzero_mult_divide_mult_cancel_left2 [simp, no_atp]:
huffman@30630
   307
  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (c * a) / (b * c) = a / b"
huffman@30630
   308
using nonzero_mult_divide_mult_cancel_left [of b c a] by (simp add: mult_ac)
huffman@30630
   309
blanchet@35828
   310
lemma nonzero_mult_divide_mult_cancel_right2 [simp, no_atp]:
huffman@30630
   311
  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (a * c) / (c * b) = a / b"
huffman@30630
   312
using nonzero_mult_divide_mult_cancel_right [of b c a] by (simp add: mult_ac)
huffman@30630
   313
haftmann@36348
   314
lemma add_divide_eq_iff [field_simps]:
huffman@30630
   315
  "z \<noteq> 0 \<Longrightarrow> x + y / z = (z * x + y) / z"
haftmann@36301
   316
  by (simp add: add_divide_distrib)
huffman@30630
   317
haftmann@36348
   318
lemma divide_add_eq_iff [field_simps]:
huffman@30630
   319
  "z \<noteq> 0 \<Longrightarrow> x / z + y = (x + z * y) / z"
haftmann@36301
   320
  by (simp add: add_divide_distrib)
huffman@30630
   321
haftmann@36348
   322
lemma diff_divide_eq_iff [field_simps]:
huffman@30630
   323
  "z \<noteq> 0 \<Longrightarrow> x - y / z = (z * x - y) / z"
haftmann@36301
   324
  by (simp add: diff_divide_distrib)
huffman@30630
   325
haftmann@36348
   326
lemma divide_diff_eq_iff [field_simps]:
huffman@30630
   327
  "z \<noteq> 0 \<Longrightarrow> x / z - y = (x - z * y) / z"
haftmann@36301
   328
  by (simp add: diff_divide_distrib)
huffman@30630
   329
huffman@30630
   330
lemma diff_frac_eq:
huffman@30630
   331
  "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> x / y - w / z = (x * z - w * y) / (y * z)"
haftmann@36348
   332
  by (simp add: field_simps)
huffman@30630
   333
huffman@30630
   334
lemma frac_eq_eq:
huffman@30630
   335
  "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> (x / y = w / z) = (x * z = w * y)"
haftmann@36348
   336
  by (simp add: field_simps)
haftmann@36348
   337
haftmann@36348
   338
end
haftmann@36348
   339
haftmann@36348
   340
class field_inverse_zero = field +
haftmann@36348
   341
  assumes field_inverse_zero: "inverse 0 = 0"
haftmann@36348
   342
begin
haftmann@36348
   343
haftmann@36348
   344
subclass division_ring_inverse_zero proof
haftmann@36348
   345
qed (fact field_inverse_zero)
haftmann@25230
   346
paulson@14270
   347
text{*This version builds in division by zero while also re-orienting
paulson@14270
   348
      the right-hand side.*}
paulson@14270
   349
lemma inverse_mult_distrib [simp]:
haftmann@36409
   350
  "inverse (a * b) = inverse a * inverse b"
haftmann@36409
   351
proof cases
haftmann@36409
   352
  assume "a \<noteq> 0 & b \<noteq> 0" 
haftmann@36409
   353
  thus ?thesis by (simp add: nonzero_inverse_mult_distrib mult_ac)
haftmann@36409
   354
next
haftmann@36409
   355
  assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
haftmann@36409
   356
  thus ?thesis by force
haftmann@36409
   357
qed
paulson@14270
   358
paulson@14365
   359
lemma inverse_divide [simp]:
haftmann@36409
   360
  "inverse (a / b) = b / a"
haftmann@36301
   361
  by (simp add: divide_inverse mult_commute)
paulson@14365
   362
wenzelm@23389
   363
haftmann@36301
   364
text {* Calculations with fractions *}
avigad@16775
   365
nipkow@23413
   366
text{* There is a whole bunch of simp-rules just for class @{text
nipkow@23413
   367
field} but none for class @{text field} and @{text nonzero_divides}
nipkow@23413
   368
because the latter are covered by a simproc. *}
nipkow@23413
   369
nipkow@23413
   370
lemma mult_divide_mult_cancel_left:
haftmann@36409
   371
  "c \<noteq> 0 \<Longrightarrow> (c * a) / (c * b) = a / b"
haftmann@21328
   372
apply (cases "b = 0")
huffman@35216
   373
apply simp_all
paulson@14277
   374
done
paulson@14277
   375
nipkow@23413
   376
lemma mult_divide_mult_cancel_right:
haftmann@36409
   377
  "c \<noteq> 0 \<Longrightarrow> (a * c) / (b * c) = a / b"
haftmann@21328
   378
apply (cases "b = 0")
huffman@35216
   379
apply simp_all
paulson@14321
   380
done
nipkow@23413
   381
haftmann@36409
   382
lemma divide_divide_eq_right [simp, no_atp]:
haftmann@36409
   383
  "a / (b / c) = (a * c) / b"
haftmann@36409
   384
  by (simp add: divide_inverse mult_ac)
paulson@14288
   385
haftmann@36409
   386
lemma divide_divide_eq_left [simp, no_atp]:
haftmann@36409
   387
  "(a / b) / c = a / (b * c)"
haftmann@36409
   388
  by (simp add: divide_inverse mult_assoc)
paulson@14288
   389
wenzelm@23389
   390
haftmann@36301
   391
text {*Special Cancellation Simprules for Division*}
paulson@15234
   392
haftmann@36409
   393
lemma mult_divide_mult_cancel_left_if [simp,no_atp]:
haftmann@36409
   394
  shows "(c * a) / (c * b) = (if c = 0 then 0 else a / b)"
haftmann@36409
   395
  by (simp add: mult_divide_mult_cancel_left)
nipkow@23413
   396
paulson@15234
   397
haftmann@36301
   398
text {* Division and Unary Minus *}
paulson@14293
   399
haftmann@36409
   400
lemma minus_divide_right:
haftmann@36409
   401
  "- (a / b) = a / - b"
haftmann@36409
   402
  by (simp add: divide_inverse)
paulson@14430
   403
blanchet@35828
   404
lemma divide_minus_right [simp, no_atp]:
haftmann@36409
   405
  "a / - b = - (a / b)"
haftmann@36409
   406
  by (simp add: divide_inverse)
huffman@30630
   407
huffman@30630
   408
lemma minus_divide_divide:
haftmann@36409
   409
  "(- a) / (- b) = a / b"
haftmann@21328
   410
apply (cases "b=0", simp) 
paulson@14293
   411
apply (simp add: nonzero_minus_divide_divide) 
paulson@14293
   412
done
paulson@14293
   413
nipkow@23482
   414
lemma eq_divide_eq:
haftmann@36409
   415
  "a = b / c \<longleftrightarrow> (if c \<noteq> 0 then a * c = b else a = 0)"
haftmann@36409
   416
  by (simp add: nonzero_eq_divide_eq)
nipkow@23482
   417
nipkow@23482
   418
lemma divide_eq_eq:
haftmann@36409
   419
  "b / c = a \<longleftrightarrow> (if c \<noteq> 0 then b = a * c else a = 0)"
haftmann@36409
   420
  by (force simp add: nonzero_divide_eq_eq)
paulson@14293
   421
haftmann@36301
   422
lemma inverse_eq_1_iff [simp]:
haftmann@36409
   423
  "inverse x = 1 \<longleftrightarrow> x = 1"
haftmann@36409
   424
  by (insert inverse_eq_iff_eq [of x 1], simp) 
wenzelm@23389
   425
haftmann@36409
   426
lemma divide_eq_0_iff [simp, no_atp]:
haftmann@36409
   427
  "a / b = 0 \<longleftrightarrow> a = 0 \<or> b = 0"
haftmann@36409
   428
  by (simp add: divide_inverse)
haftmann@36301
   429
haftmann@36409
   430
lemma divide_cancel_right [simp, no_atp]:
haftmann@36409
   431
  "a / c = b / c \<longleftrightarrow> c = 0 \<or> a = b"
haftmann@36409
   432
  apply (cases "c=0", simp)
haftmann@36409
   433
  apply (simp add: divide_inverse)
haftmann@36409
   434
  done
haftmann@36301
   435
haftmann@36409
   436
lemma divide_cancel_left [simp, no_atp]:
haftmann@36409
   437
  "c / a = c / b \<longleftrightarrow> c = 0 \<or> a = b" 
haftmann@36409
   438
  apply (cases "c=0", simp)
haftmann@36409
   439
  apply (simp add: divide_inverse)
haftmann@36409
   440
  done
haftmann@36301
   441
haftmann@36409
   442
lemma divide_eq_1_iff [simp, no_atp]:
haftmann@36409
   443
  "a / b = 1 \<longleftrightarrow> b \<noteq> 0 \<and> a = b"
haftmann@36409
   444
  apply (cases "b=0", simp)
haftmann@36409
   445
  apply (simp add: right_inverse_eq)
haftmann@36409
   446
  done
haftmann@36301
   447
haftmann@36409
   448
lemma one_eq_divide_iff [simp, no_atp]:
haftmann@36409
   449
  "1 = a / b \<longleftrightarrow> b \<noteq> 0 \<and> a = b"
haftmann@36409
   450
  by (simp add: eq_commute [of 1])
haftmann@36409
   451
haftmann@36719
   452
lemma times_divide_times_eq:
haftmann@36719
   453
  "(x / y) * (z / w) = (x * z) / (y * w)"
haftmann@36719
   454
  by simp
haftmann@36719
   455
haftmann@36719
   456
lemma add_frac_num:
haftmann@36719
   457
  "y \<noteq> 0 \<Longrightarrow> x / y + z = (x + z * y) / y"
haftmann@36719
   458
  by (simp add: add_divide_distrib)
haftmann@36719
   459
haftmann@36719
   460
lemma add_num_frac:
haftmann@36719
   461
  "y \<noteq> 0 \<Longrightarrow> z + x / y = (x + z * y) / y"
haftmann@36719
   462
  by (simp add: add_divide_distrib add.commute)
haftmann@36719
   463
haftmann@36409
   464
end
haftmann@36301
   465
haftmann@36301
   466
huffman@44064
   467
subsection {* Ordered fields *}
haftmann@36301
   468
haftmann@36301
   469
class linordered_field = field + linordered_idom
haftmann@36301
   470
begin
paulson@14268
   471
paulson@14277
   472
lemma positive_imp_inverse_positive: 
haftmann@36301
   473
  assumes a_gt_0: "0 < a" 
haftmann@36301
   474
  shows "0 < inverse a"
nipkow@23482
   475
proof -
paulson@14268
   476
  have "0 < a * inverse a" 
haftmann@36301
   477
    by (simp add: a_gt_0 [THEN less_imp_not_eq2])
paulson@14268
   478
  thus "0 < inverse a" 
haftmann@36301
   479
    by (simp add: a_gt_0 [THEN less_not_sym] zero_less_mult_iff)
nipkow@23482
   480
qed
paulson@14268
   481
paulson@14277
   482
lemma negative_imp_inverse_negative:
haftmann@36301
   483
  "a < 0 \<Longrightarrow> inverse a < 0"
haftmann@36301
   484
  by (insert positive_imp_inverse_positive [of "-a"], 
haftmann@36301
   485
    simp add: nonzero_inverse_minus_eq less_imp_not_eq)
paulson@14268
   486
paulson@14268
   487
lemma inverse_le_imp_le:
haftmann@36301
   488
  assumes invle: "inverse a \<le> inverse b" and apos: "0 < a"
haftmann@36301
   489
  shows "b \<le> a"
nipkow@23482
   490
proof (rule classical)
paulson@14268
   491
  assume "~ b \<le> a"
nipkow@23482
   492
  hence "a < b"  by (simp add: linorder_not_le)
haftmann@36301
   493
  hence bpos: "0 < b"  by (blast intro: apos less_trans)
paulson@14268
   494
  hence "a * inverse a \<le> a * inverse b"
haftmann@36301
   495
    by (simp add: apos invle less_imp_le mult_left_mono)
paulson@14268
   496
  hence "(a * inverse a) * b \<le> (a * inverse b) * b"
haftmann@36301
   497
    by (simp add: bpos less_imp_le mult_right_mono)
haftmann@36301
   498
  thus "b \<le> a"  by (simp add: mult_assoc apos bpos less_imp_not_eq2)
nipkow@23482
   499
qed
paulson@14268
   500
paulson@14277
   501
lemma inverse_positive_imp_positive:
haftmann@36301
   502
  assumes inv_gt_0: "0 < inverse a" and nz: "a \<noteq> 0"
haftmann@36301
   503
  shows "0 < a"
wenzelm@23389
   504
proof -
paulson@14277
   505
  have "0 < inverse (inverse a)"
wenzelm@23389
   506
    using inv_gt_0 by (rule positive_imp_inverse_positive)
paulson@14277
   507
  thus "0 < a"
wenzelm@23389
   508
    using nz by (simp add: nonzero_inverse_inverse_eq)
wenzelm@23389
   509
qed
paulson@14277
   510
haftmann@36301
   511
lemma inverse_negative_imp_negative:
haftmann@36301
   512
  assumes inv_less_0: "inverse a < 0" and nz: "a \<noteq> 0"
haftmann@36301
   513
  shows "a < 0"
haftmann@36301
   514
proof -
haftmann@36301
   515
  have "inverse (inverse a) < 0"
haftmann@36301
   516
    using inv_less_0 by (rule negative_imp_inverse_negative)
haftmann@36301
   517
  thus "a < 0" using nz by (simp add: nonzero_inverse_inverse_eq)
haftmann@36301
   518
qed
haftmann@36301
   519
haftmann@36301
   520
lemma linordered_field_no_lb:
haftmann@36301
   521
  "\<forall>x. \<exists>y. y < x"
haftmann@36301
   522
proof
haftmann@36301
   523
  fix x::'a
haftmann@36301
   524
  have m1: "- (1::'a) < 0" by simp
haftmann@36301
   525
  from add_strict_right_mono[OF m1, where c=x] 
haftmann@36301
   526
  have "(- 1) + x < x" by simp
haftmann@36301
   527
  thus "\<exists>y. y < x" by blast
haftmann@36301
   528
qed
haftmann@36301
   529
haftmann@36301
   530
lemma linordered_field_no_ub:
haftmann@36301
   531
  "\<forall> x. \<exists>y. y > x"
haftmann@36301
   532
proof
haftmann@36301
   533
  fix x::'a
haftmann@36301
   534
  have m1: " (1::'a) > 0" by simp
haftmann@36301
   535
  from add_strict_right_mono[OF m1, where c=x] 
haftmann@36301
   536
  have "1 + x > x" by simp
haftmann@36301
   537
  thus "\<exists>y. y > x" by blast
haftmann@36301
   538
qed
haftmann@36301
   539
haftmann@36301
   540
lemma less_imp_inverse_less:
haftmann@36301
   541
  assumes less: "a < b" and apos:  "0 < a"
haftmann@36301
   542
  shows "inverse b < inverse a"
haftmann@36301
   543
proof (rule ccontr)
haftmann@36301
   544
  assume "~ inverse b < inverse a"
haftmann@36301
   545
  hence "inverse a \<le> inverse b" by simp
haftmann@36301
   546
  hence "~ (a < b)"
haftmann@36301
   547
    by (simp add: not_less inverse_le_imp_le [OF _ apos])
haftmann@36301
   548
  thus False by (rule notE [OF _ less])
haftmann@36301
   549
qed
haftmann@36301
   550
haftmann@36301
   551
lemma inverse_less_imp_less:
haftmann@36301
   552
  "inverse a < inverse b \<Longrightarrow> 0 < a \<Longrightarrow> b < a"
haftmann@36301
   553
apply (simp add: less_le [of "inverse a"] less_le [of "b"])
haftmann@36301
   554
apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
haftmann@36301
   555
done
haftmann@36301
   556
haftmann@36301
   557
text{*Both premises are essential. Consider -1 and 1.*}
haftmann@36301
   558
lemma inverse_less_iff_less [simp,no_atp]:
haftmann@36301
   559
  "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> inverse a < inverse b \<longleftrightarrow> b < a"
haftmann@36301
   560
  by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
haftmann@36301
   561
haftmann@36301
   562
lemma le_imp_inverse_le:
haftmann@36301
   563
  "a \<le> b \<Longrightarrow> 0 < a \<Longrightarrow> inverse b \<le> inverse a"
haftmann@36301
   564
  by (force simp add: le_less less_imp_inverse_less)
haftmann@36301
   565
haftmann@36301
   566
lemma inverse_le_iff_le [simp,no_atp]:
haftmann@36301
   567
  "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> inverse a \<le> inverse b \<longleftrightarrow> b \<le> a"
haftmann@36301
   568
  by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
haftmann@36301
   569
haftmann@36301
   570
haftmann@36301
   571
text{*These results refer to both operands being negative.  The opposite-sign
haftmann@36301
   572
case is trivial, since inverse preserves signs.*}
haftmann@36301
   573
lemma inverse_le_imp_le_neg:
haftmann@36301
   574
  "inverse a \<le> inverse b \<Longrightarrow> b < 0 \<Longrightarrow> b \<le> a"
haftmann@36301
   575
apply (rule classical) 
haftmann@36301
   576
apply (subgoal_tac "a < 0") 
haftmann@36301
   577
 prefer 2 apply force
haftmann@36301
   578
apply (insert inverse_le_imp_le [of "-b" "-a"])
haftmann@36301
   579
apply (simp add: nonzero_inverse_minus_eq) 
haftmann@36301
   580
done
haftmann@36301
   581
haftmann@36301
   582
lemma less_imp_inverse_less_neg:
haftmann@36301
   583
   "a < b \<Longrightarrow> b < 0 \<Longrightarrow> inverse b < inverse a"
haftmann@36301
   584
apply (subgoal_tac "a < 0") 
haftmann@36301
   585
 prefer 2 apply (blast intro: less_trans) 
haftmann@36301
   586
apply (insert less_imp_inverse_less [of "-b" "-a"])
haftmann@36301
   587
apply (simp add: nonzero_inverse_minus_eq) 
haftmann@36301
   588
done
haftmann@36301
   589
haftmann@36301
   590
lemma inverse_less_imp_less_neg:
haftmann@36301
   591
   "inverse a < inverse b \<Longrightarrow> b < 0 \<Longrightarrow> b < a"
haftmann@36301
   592
apply (rule classical) 
haftmann@36301
   593
apply (subgoal_tac "a < 0") 
haftmann@36301
   594
 prefer 2
haftmann@36301
   595
 apply force
haftmann@36301
   596
apply (insert inverse_less_imp_less [of "-b" "-a"])
haftmann@36301
   597
apply (simp add: nonzero_inverse_minus_eq) 
haftmann@36301
   598
done
haftmann@36301
   599
haftmann@36301
   600
lemma inverse_less_iff_less_neg [simp,no_atp]:
haftmann@36301
   601
  "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> inverse a < inverse b \<longleftrightarrow> b < a"
haftmann@36301
   602
apply (insert inverse_less_iff_less [of "-b" "-a"])
haftmann@36301
   603
apply (simp del: inverse_less_iff_less 
haftmann@36301
   604
            add: nonzero_inverse_minus_eq)
haftmann@36301
   605
done
haftmann@36301
   606
haftmann@36301
   607
lemma le_imp_inverse_le_neg:
haftmann@36301
   608
  "a \<le> b \<Longrightarrow> b < 0 ==> inverse b \<le> inverse a"
haftmann@36301
   609
  by (force simp add: le_less less_imp_inverse_less_neg)
haftmann@36301
   610
haftmann@36301
   611
lemma inverse_le_iff_le_neg [simp,no_atp]:
haftmann@36301
   612
  "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> inverse a \<le> inverse b \<longleftrightarrow> b \<le> a"
haftmann@36301
   613
  by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
haftmann@36301
   614
huffman@36774
   615
lemma one_less_inverse:
huffman@36774
   616
  "0 < a \<Longrightarrow> a < 1 \<Longrightarrow> 1 < inverse a"
huffman@36774
   617
  using less_imp_inverse_less [of a 1, unfolded inverse_1] .
huffman@36774
   618
huffman@36774
   619
lemma one_le_inverse:
huffman@36774
   620
  "0 < a \<Longrightarrow> a \<le> 1 \<Longrightarrow> 1 \<le> inverse a"
huffman@36774
   621
  using le_imp_inverse_le [of a 1, unfolded inverse_1] .
huffman@36774
   622
haftmann@36348
   623
lemma pos_le_divide_eq [field_simps]: "0 < c ==> (a \<le> b/c) = (a*c \<le> b)"
haftmann@36301
   624
proof -
haftmann@36301
   625
  assume less: "0<c"
haftmann@36301
   626
  hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
haftmann@36304
   627
    by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   628
  also have "... = (a*c \<le> b)"
haftmann@36301
   629
    by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
haftmann@36301
   630
  finally show ?thesis .
haftmann@36301
   631
qed
haftmann@36301
   632
haftmann@36348
   633
lemma neg_le_divide_eq [field_simps]: "c < 0 ==> (a \<le> b/c) = (b \<le> a*c)"
haftmann@36301
   634
proof -
haftmann@36301
   635
  assume less: "c<0"
haftmann@36301
   636
  hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
haftmann@36304
   637
    by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   638
  also have "... = (b \<le> a*c)"
haftmann@36301
   639
    by (simp add: less_imp_not_eq [OF less] divide_inverse mult_assoc) 
haftmann@36301
   640
  finally show ?thesis .
haftmann@36301
   641
qed
haftmann@36301
   642
haftmann@36348
   643
lemma pos_less_divide_eq [field_simps]:
haftmann@36301
   644
     "0 < c ==> (a < b/c) = (a*c < b)"
haftmann@36301
   645
proof -
haftmann@36301
   646
  assume less: "0<c"
haftmann@36301
   647
  hence "(a < b/c) = (a*c < (b/c)*c)"
haftmann@36304
   648
    by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   649
  also have "... = (a*c < b)"
haftmann@36301
   650
    by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
haftmann@36301
   651
  finally show ?thesis .
haftmann@36301
   652
qed
haftmann@36301
   653
haftmann@36348
   654
lemma neg_less_divide_eq [field_simps]:
haftmann@36301
   655
 "c < 0 ==> (a < b/c) = (b < a*c)"
haftmann@36301
   656
proof -
haftmann@36301
   657
  assume less: "c<0"
haftmann@36301
   658
  hence "(a < b/c) = ((b/c)*c < a*c)"
haftmann@36304
   659
    by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   660
  also have "... = (b < a*c)"
haftmann@36301
   661
    by (simp add: less_imp_not_eq [OF less] divide_inverse mult_assoc) 
haftmann@36301
   662
  finally show ?thesis .
haftmann@36301
   663
qed
haftmann@36301
   664
haftmann@36348
   665
lemma pos_divide_less_eq [field_simps]:
haftmann@36301
   666
     "0 < c ==> (b/c < a) = (b < a*c)"
haftmann@36301
   667
proof -
haftmann@36301
   668
  assume less: "0<c"
haftmann@36301
   669
  hence "(b/c < a) = ((b/c)*c < a*c)"
haftmann@36304
   670
    by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   671
  also have "... = (b < a*c)"
haftmann@36301
   672
    by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
haftmann@36301
   673
  finally show ?thesis .
haftmann@36301
   674
qed
haftmann@36301
   675
haftmann@36348
   676
lemma neg_divide_less_eq [field_simps]:
haftmann@36301
   677
 "c < 0 ==> (b/c < a) = (a*c < b)"
haftmann@36301
   678
proof -
haftmann@36301
   679
  assume less: "c<0"
haftmann@36301
   680
  hence "(b/c < a) = (a*c < (b/c)*c)"
haftmann@36304
   681
    by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   682
  also have "... = (a*c < b)"
haftmann@36301
   683
    by (simp add: less_imp_not_eq [OF less] divide_inverse mult_assoc) 
haftmann@36301
   684
  finally show ?thesis .
haftmann@36301
   685
qed
haftmann@36301
   686
haftmann@36348
   687
lemma pos_divide_le_eq [field_simps]: "0 < c ==> (b/c \<le> a) = (b \<le> a*c)"
haftmann@36301
   688
proof -
haftmann@36301
   689
  assume less: "0<c"
haftmann@36301
   690
  hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
haftmann@36304
   691
    by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   692
  also have "... = (b \<le> a*c)"
haftmann@36301
   693
    by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
haftmann@36301
   694
  finally show ?thesis .
haftmann@36301
   695
qed
haftmann@36301
   696
haftmann@36348
   697
lemma neg_divide_le_eq [field_simps]: "c < 0 ==> (b/c \<le> a) = (a*c \<le> b)"
haftmann@36301
   698
proof -
haftmann@36301
   699
  assume less: "c<0"
haftmann@36301
   700
  hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
haftmann@36304
   701
    by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
haftmann@36301
   702
  also have "... = (a*c \<le> b)"
haftmann@36301
   703
    by (simp add: less_imp_not_eq [OF less] divide_inverse mult_assoc) 
haftmann@36301
   704
  finally show ?thesis .
haftmann@36301
   705
qed
haftmann@36301
   706
haftmann@36301
   707
text{* Lemmas @{text sign_simps} is a first attempt to automate proofs
haftmann@36301
   708
of positivity/negativity needed for @{text field_simps}. Have not added @{text
haftmann@36301
   709
sign_simps} to @{text field_simps} because the former can lead to case
haftmann@36301
   710
explosions. *}
haftmann@36301
   711
haftmann@36348
   712
lemmas sign_simps [no_atp] = algebra_simps
haftmann@36348
   713
  zero_less_mult_iff mult_less_0_iff
haftmann@36348
   714
haftmann@36348
   715
lemmas (in -) sign_simps [no_atp] = algebra_simps
haftmann@36301
   716
  zero_less_mult_iff mult_less_0_iff
haftmann@36301
   717
haftmann@36301
   718
(* Only works once linear arithmetic is installed:
haftmann@36301
   719
text{*An example:*}
haftmann@36301
   720
lemma fixes a b c d e f :: "'a::linordered_field"
haftmann@36301
   721
shows "\<lbrakk>a>b; c<d; e<f; 0 < u \<rbrakk> \<Longrightarrow>
haftmann@36301
   722
 ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) <
haftmann@36301
   723
 ((e-f)*(a-b)*(c-d))/((e-f)*(a-b)*(c-d)) + u"
haftmann@36301
   724
apply(subgoal_tac "(c-d)*(e-f)*(a-b) > 0")
haftmann@36301
   725
 prefer 2 apply(simp add:sign_simps)
haftmann@36301
   726
apply(subgoal_tac "(c-d)*(e-f)*(a-b)*u > 0")
haftmann@36301
   727
 prefer 2 apply(simp add:sign_simps)
haftmann@36301
   728
apply(simp add:field_simps)
haftmann@36301
   729
done
haftmann@36301
   730
*)
haftmann@36301
   731
haftmann@36301
   732
lemma divide_pos_pos:
haftmann@36301
   733
  "0 < x ==> 0 < y ==> 0 < x / y"
haftmann@36301
   734
by(simp add:field_simps)
haftmann@36301
   735
haftmann@36301
   736
lemma divide_nonneg_pos:
haftmann@36301
   737
  "0 <= x ==> 0 < y ==> 0 <= x / y"
haftmann@36301
   738
by(simp add:field_simps)
haftmann@36301
   739
haftmann@36301
   740
lemma divide_neg_pos:
haftmann@36301
   741
  "x < 0 ==> 0 < y ==> x / y < 0"
haftmann@36301
   742
by(simp add:field_simps)
haftmann@36301
   743
haftmann@36301
   744
lemma divide_nonpos_pos:
haftmann@36301
   745
  "x <= 0 ==> 0 < y ==> x / y <= 0"
haftmann@36301
   746
by(simp add:field_simps)
haftmann@36301
   747
haftmann@36301
   748
lemma divide_pos_neg:
haftmann@36301
   749
  "0 < x ==> y < 0 ==> x / y < 0"
haftmann@36301
   750
by(simp add:field_simps)
haftmann@36301
   751
haftmann@36301
   752
lemma divide_nonneg_neg:
haftmann@36301
   753
  "0 <= x ==> y < 0 ==> x / y <= 0" 
haftmann@36301
   754
by(simp add:field_simps)
haftmann@36301
   755
haftmann@36301
   756
lemma divide_neg_neg:
haftmann@36301
   757
  "x < 0 ==> y < 0 ==> 0 < x / y"
haftmann@36301
   758
by(simp add:field_simps)
haftmann@36301
   759
haftmann@36301
   760
lemma divide_nonpos_neg:
haftmann@36301
   761
  "x <= 0 ==> y < 0 ==> 0 <= x / y"
haftmann@36301
   762
by(simp add:field_simps)
haftmann@36301
   763
haftmann@36301
   764
lemma divide_strict_right_mono:
haftmann@36301
   765
     "[|a < b; 0 < c|] ==> a / c < b / c"
haftmann@36301
   766
by (simp add: less_imp_not_eq2 divide_inverse mult_strict_right_mono 
haftmann@36301
   767
              positive_imp_inverse_positive)
haftmann@36301
   768
haftmann@36301
   769
haftmann@36301
   770
lemma divide_strict_right_mono_neg:
haftmann@36301
   771
     "[|b < a; c < 0|] ==> a / c < b / c"
haftmann@36301
   772
apply (drule divide_strict_right_mono [of _ _ "-c"], simp)
haftmann@36301
   773
apply (simp add: less_imp_not_eq nonzero_minus_divide_right [symmetric])
haftmann@36301
   774
done
haftmann@36301
   775
haftmann@36301
   776
text{*The last premise ensures that @{term a} and @{term b} 
haftmann@36301
   777
      have the same sign*}
haftmann@36301
   778
lemma divide_strict_left_mono:
haftmann@36301
   779
  "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / b"
haftmann@36301
   780
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono)
haftmann@36301
   781
haftmann@36301
   782
lemma divide_left_mono:
haftmann@36301
   783
  "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / b"
haftmann@36301
   784
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_right_mono)
haftmann@36301
   785
haftmann@36301
   786
lemma divide_strict_left_mono_neg:
haftmann@36301
   787
  "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / b"
haftmann@36301
   788
by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono_neg)
haftmann@36301
   789
haftmann@36301
   790
lemma mult_imp_div_pos_le: "0 < y ==> x <= z * y ==>
haftmann@36301
   791
    x / y <= z"
haftmann@36301
   792
by (subst pos_divide_le_eq, assumption+)
haftmann@36301
   793
haftmann@36301
   794
lemma mult_imp_le_div_pos: "0 < y ==> z * y <= x ==>
haftmann@36301
   795
    z <= x / y"
haftmann@36301
   796
by(simp add:field_simps)
haftmann@36301
   797
haftmann@36301
   798
lemma mult_imp_div_pos_less: "0 < y ==> x < z * y ==>
haftmann@36301
   799
    x / y < z"
haftmann@36301
   800
by(simp add:field_simps)
haftmann@36301
   801
haftmann@36301
   802
lemma mult_imp_less_div_pos: "0 < y ==> z * y < x ==>
haftmann@36301
   803
    z < x / y"
haftmann@36301
   804
by(simp add:field_simps)
haftmann@36301
   805
haftmann@36301
   806
lemma frac_le: "0 <= x ==> 
haftmann@36301
   807
    x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
haftmann@36301
   808
  apply (rule mult_imp_div_pos_le)
haftmann@36301
   809
  apply simp
haftmann@36301
   810
  apply (subst times_divide_eq_left)
haftmann@36301
   811
  apply (rule mult_imp_le_div_pos, assumption)
haftmann@36301
   812
  apply (rule mult_mono)
haftmann@36301
   813
  apply simp_all
haftmann@36301
   814
done
haftmann@36301
   815
haftmann@36301
   816
lemma frac_less: "0 <= x ==> 
haftmann@36301
   817
    x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
haftmann@36301
   818
  apply (rule mult_imp_div_pos_less)
haftmann@36301
   819
  apply simp
haftmann@36301
   820
  apply (subst times_divide_eq_left)
haftmann@36301
   821
  apply (rule mult_imp_less_div_pos, assumption)
haftmann@36301
   822
  apply (erule mult_less_le_imp_less)
haftmann@36301
   823
  apply simp_all
haftmann@36301
   824
done
haftmann@36301
   825
haftmann@36301
   826
lemma frac_less2: "0 < x ==> 
haftmann@36301
   827
    x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
haftmann@36301
   828
  apply (rule mult_imp_div_pos_less)
haftmann@36301
   829
  apply simp_all
haftmann@36301
   830
  apply (rule mult_imp_less_div_pos, assumption)
haftmann@36301
   831
  apply (erule mult_le_less_imp_less)
haftmann@36301
   832
  apply simp_all
haftmann@36301
   833
done
haftmann@36301
   834
haftmann@36301
   835
text{*It's not obvious whether these should be simprules or not. 
haftmann@36301
   836
  Their effect is to gather terms into one big fraction, like
haftmann@36301
   837
  a*b*c / x*y*z. The rationale for that is unclear, but many proofs 
haftmann@36301
   838
  seem to need them.*}
haftmann@36301
   839
haftmann@36301
   840
lemma less_half_sum: "a < b ==> a < (a+b) / (1+1)"
haftmann@36301
   841
by (simp add: field_simps zero_less_two)
haftmann@36301
   842
haftmann@36301
   843
lemma gt_half_sum: "a < b ==> (a+b)/(1+1) < b"
haftmann@36301
   844
by (simp add: field_simps zero_less_two)
haftmann@36301
   845
haftmann@36301
   846
subclass dense_linorder
haftmann@36301
   847
proof
haftmann@36301
   848
  fix x y :: 'a
haftmann@36301
   849
  from less_add_one show "\<exists>y. x < y" .. 
haftmann@36301
   850
  from less_add_one have "x + (- 1) < (x + 1) + (- 1)" by (rule add_strict_right_mono)
haftmann@36301
   851
  then have "x - 1 < x + 1 - 1" by (simp only: diff_minus [symmetric])
haftmann@36301
   852
  then have "x - 1 < x" by (simp add: algebra_simps)
haftmann@36301
   853
  then show "\<exists>y. y < x" ..
haftmann@36301
   854
  show "x < y \<Longrightarrow> \<exists>z>x. z < y" by (blast intro!: less_half_sum gt_half_sum)
haftmann@36301
   855
qed
haftmann@36301
   856
haftmann@36301
   857
lemma nonzero_abs_inverse:
haftmann@36301
   858
     "a \<noteq> 0 ==> \<bar>inverse a\<bar> = inverse \<bar>a\<bar>"
haftmann@36301
   859
apply (auto simp add: neq_iff abs_if nonzero_inverse_minus_eq 
haftmann@36301
   860
                      negative_imp_inverse_negative)
haftmann@36301
   861
apply (blast intro: positive_imp_inverse_positive elim: less_asym) 
haftmann@36301
   862
done
haftmann@36301
   863
haftmann@36301
   864
lemma nonzero_abs_divide:
haftmann@36301
   865
     "b \<noteq> 0 ==> \<bar>a / b\<bar> = \<bar>a\<bar> / \<bar>b\<bar>"
haftmann@36301
   866
  by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
haftmann@36301
   867
haftmann@36301
   868
lemma field_le_epsilon:
haftmann@36301
   869
  assumes e: "\<And>e. 0 < e \<Longrightarrow> x \<le> y + e"
haftmann@36301
   870
  shows "x \<le> y"
haftmann@36301
   871
proof (rule dense_le)
haftmann@36301
   872
  fix t assume "t < x"
haftmann@36301
   873
  hence "0 < x - t" by (simp add: less_diff_eq)
haftmann@36301
   874
  from e [OF this] have "x + 0 \<le> x + (y - t)" by (simp add: algebra_simps)
haftmann@36301
   875
  then have "0 \<le> y - t" by (simp only: add_le_cancel_left)
haftmann@36301
   876
  then show "t \<le> y" by (simp add: algebra_simps)
haftmann@36301
   877
qed
haftmann@36301
   878
haftmann@36301
   879
end
haftmann@36301
   880
haftmann@36414
   881
class linordered_field_inverse_zero = linordered_field + field_inverse_zero
haftmann@36348
   882
begin
haftmann@36348
   883
haftmann@36301
   884
lemma le_divide_eq:
haftmann@36301
   885
  "(a \<le> b/c) = 
haftmann@36301
   886
   (if 0 < c then a*c \<le> b
haftmann@36301
   887
             else if c < 0 then b \<le> a*c
haftmann@36409
   888
             else  a \<le> 0)"
haftmann@36301
   889
apply (cases "c=0", simp) 
haftmann@36301
   890
apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
haftmann@36301
   891
done
haftmann@36301
   892
paulson@14277
   893
lemma inverse_positive_iff_positive [simp]:
haftmann@36409
   894
  "(0 < inverse a) = (0 < a)"
haftmann@21328
   895
apply (cases "a = 0", simp)
paulson@14277
   896
apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
paulson@14277
   897
done
paulson@14277
   898
paulson@14277
   899
lemma inverse_negative_iff_negative [simp]:
haftmann@36409
   900
  "(inverse a < 0) = (a < 0)"
haftmann@21328
   901
apply (cases "a = 0", simp)
paulson@14277
   902
apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
paulson@14277
   903
done
paulson@14277
   904
paulson@14277
   905
lemma inverse_nonnegative_iff_nonnegative [simp]:
haftmann@36409
   906
  "0 \<le> inverse a \<longleftrightarrow> 0 \<le> a"
haftmann@36409
   907
  by (simp add: not_less [symmetric])
paulson@14277
   908
paulson@14277
   909
lemma inverse_nonpositive_iff_nonpositive [simp]:
haftmann@36409
   910
  "inverse a \<le> 0 \<longleftrightarrow> a \<le> 0"
haftmann@36409
   911
  by (simp add: not_less [symmetric])
paulson@14277
   912
paulson@14365
   913
lemma one_less_inverse_iff:
haftmann@36409
   914
  "1 < inverse x \<longleftrightarrow> 0 < x \<and> x < 1"
nipkow@23482
   915
proof cases
paulson@14365
   916
  assume "0 < x"
paulson@14365
   917
    with inverse_less_iff_less [OF zero_less_one, of x]
paulson@14365
   918
    show ?thesis by simp
paulson@14365
   919
next
paulson@14365
   920
  assume notless: "~ (0 < x)"
paulson@14365
   921
  have "~ (1 < inverse x)"
paulson@14365
   922
  proof
paulson@14365
   923
    assume "1 < inverse x"
haftmann@36409
   924
    also with notless have "... \<le> 0" by simp
paulson@14365
   925
    also have "... < 1" by (rule zero_less_one) 
paulson@14365
   926
    finally show False by auto
paulson@14365
   927
  qed
paulson@14365
   928
  with notless show ?thesis by simp
paulson@14365
   929
qed
paulson@14365
   930
paulson@14365
   931
lemma one_le_inverse_iff:
haftmann@36409
   932
  "1 \<le> inverse x \<longleftrightarrow> 0 < x \<and> x \<le> 1"
haftmann@36409
   933
proof (cases "x = 1")
haftmann@36409
   934
  case True then show ?thesis by simp
haftmann@36409
   935
next
haftmann@36409
   936
  case False then have "inverse x \<noteq> 1" by simp
haftmann@36409
   937
  then have "1 \<noteq> inverse x" by blast
haftmann@36409
   938
  then have "1 \<le> inverse x \<longleftrightarrow> 1 < inverse x" by (simp add: le_less)
haftmann@36409
   939
  with False show ?thesis by (auto simp add: one_less_inverse_iff)
haftmann@36409
   940
qed
paulson@14365
   941
paulson@14365
   942
lemma inverse_less_1_iff:
haftmann@36409
   943
  "inverse x < 1 \<longleftrightarrow> x \<le> 0 \<or> 1 < x"
haftmann@36409
   944
  by (simp add: not_le [symmetric] one_le_inverse_iff) 
paulson@14365
   945
paulson@14365
   946
lemma inverse_le_1_iff:
haftmann@36409
   947
  "inverse x \<le> 1 \<longleftrightarrow> x \<le> 0 \<or> 1 \<le> x"
haftmann@36409
   948
  by (simp add: not_less [symmetric] one_less_inverse_iff) 
paulson@14365
   949
paulson@14288
   950
lemma divide_le_eq:
paulson@14288
   951
  "(b/c \<le> a) = 
paulson@14288
   952
   (if 0 < c then b \<le> a*c
paulson@14288
   953
             else if c < 0 then a*c \<le> b
haftmann@36409
   954
             else 0 \<le> a)"
haftmann@21328
   955
apply (cases "c=0", simp) 
haftmann@36409
   956
apply (force simp add: pos_divide_le_eq neg_divide_le_eq) 
paulson@14288
   957
done
paulson@14288
   958
paulson@14288
   959
lemma less_divide_eq:
paulson@14288
   960
  "(a < b/c) = 
paulson@14288
   961
   (if 0 < c then a*c < b
paulson@14288
   962
             else if c < 0 then b < a*c
haftmann@36409
   963
             else  a < 0)"
haftmann@21328
   964
apply (cases "c=0", simp) 
haftmann@36409
   965
apply (force simp add: pos_less_divide_eq neg_less_divide_eq) 
paulson@14288
   966
done
paulson@14288
   967
paulson@14288
   968
lemma divide_less_eq:
paulson@14288
   969
  "(b/c < a) = 
paulson@14288
   970
   (if 0 < c then b < a*c
paulson@14288
   971
             else if c < 0 then a*c < b
haftmann@36409
   972
             else 0 < a)"
haftmann@21328
   973
apply (cases "c=0", simp) 
haftmann@36409
   974
apply (force simp add: pos_divide_less_eq neg_divide_less_eq)
paulson@14288
   975
done
paulson@14288
   976
haftmann@36301
   977
text {*Division and Signs*}
avigad@16775
   978
avigad@16775
   979
lemma zero_less_divide_iff:
haftmann@36409
   980
     "(0 < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
avigad@16775
   981
by (simp add: divide_inverse zero_less_mult_iff)
avigad@16775
   982
avigad@16775
   983
lemma divide_less_0_iff:
haftmann@36409
   984
     "(a/b < 0) = 
avigad@16775
   985
      (0 < a & b < 0 | a < 0 & 0 < b)"
avigad@16775
   986
by (simp add: divide_inverse mult_less_0_iff)
avigad@16775
   987
avigad@16775
   988
lemma zero_le_divide_iff:
haftmann@36409
   989
     "(0 \<le> a/b) =
avigad@16775
   990
      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
avigad@16775
   991
by (simp add: divide_inverse zero_le_mult_iff)
avigad@16775
   992
avigad@16775
   993
lemma divide_le_0_iff:
haftmann@36409
   994
     "(a/b \<le> 0) =
avigad@16775
   995
      (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
avigad@16775
   996
by (simp add: divide_inverse mult_le_0_iff)
avigad@16775
   997
haftmann@36301
   998
text {* Division and the Number One *}
paulson@14353
   999
paulson@14353
  1000
text{*Simplify expressions equated with 1*}
paulson@14353
  1001
blanchet@35828
  1002
lemma zero_eq_1_divide_iff [simp,no_atp]:
haftmann@36409
  1003
     "(0 = 1/a) = (a = 0)"
nipkow@23482
  1004
apply (cases "a=0", simp)
nipkow@23482
  1005
apply (auto simp add: nonzero_eq_divide_eq)
paulson@14353
  1006
done
paulson@14353
  1007
blanchet@35828
  1008
lemma one_divide_eq_0_iff [simp,no_atp]:
haftmann@36409
  1009
     "(1/a = 0) = (a = 0)"
nipkow@23482
  1010
apply (cases "a=0", simp)
nipkow@23482
  1011
apply (insert zero_neq_one [THEN not_sym])
nipkow@23482
  1012
apply (auto simp add: nonzero_divide_eq_eq)
paulson@14353
  1013
done
paulson@14353
  1014
paulson@14353
  1015
text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
haftmann@36423
  1016
haftmann@36423
  1017
lemma zero_le_divide_1_iff [simp, no_atp]:
haftmann@36423
  1018
  "0 \<le> 1 / a \<longleftrightarrow> 0 \<le> a"
haftmann@36423
  1019
  by (simp add: zero_le_divide_iff)
paulson@17085
  1020
haftmann@36423
  1021
lemma zero_less_divide_1_iff [simp, no_atp]:
haftmann@36423
  1022
  "0 < 1 / a \<longleftrightarrow> 0 < a"
haftmann@36423
  1023
  by (simp add: zero_less_divide_iff)
haftmann@36423
  1024
haftmann@36423
  1025
lemma divide_le_0_1_iff [simp, no_atp]:
haftmann@36423
  1026
  "1 / a \<le> 0 \<longleftrightarrow> a \<le> 0"
haftmann@36423
  1027
  by (simp add: divide_le_0_iff)
haftmann@36423
  1028
haftmann@36423
  1029
lemma divide_less_0_1_iff [simp, no_atp]:
haftmann@36423
  1030
  "1 / a < 0 \<longleftrightarrow> a < 0"
haftmann@36423
  1031
  by (simp add: divide_less_0_iff)
paulson@14353
  1032
paulson@14293
  1033
lemma divide_right_mono:
haftmann@36409
  1034
     "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/c"
haftmann@36409
  1035
by (force simp add: divide_strict_right_mono le_less)
paulson@14293
  1036
haftmann@36409
  1037
lemma divide_right_mono_neg: "a <= b 
avigad@16775
  1038
    ==> c <= 0 ==> b / c <= a / c"
nipkow@23482
  1039
apply (drule divide_right_mono [of _ _ "- c"])
nipkow@23482
  1040
apply auto
avigad@16775
  1041
done
avigad@16775
  1042
haftmann@36409
  1043
lemma divide_left_mono_neg: "a <= b 
avigad@16775
  1044
    ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
avigad@16775
  1045
  apply (drule divide_left_mono [of _ _ "- c"])
avigad@16775
  1046
  apply (auto simp add: mult_commute)
avigad@16775
  1047
done
avigad@16775
  1048
hoelzl@42904
  1049
lemma inverse_le_iff:
hoelzl@42904
  1050
  "inverse a \<le> inverse b \<longleftrightarrow> (0 < a * b \<longrightarrow> b \<le> a) \<and> (a * b \<le> 0 \<longrightarrow> a \<le> b)"
hoelzl@42904
  1051
proof -
hoelzl@42904
  1052
  { assume "a < 0"
hoelzl@42904
  1053
    then have "inverse a < 0" by simp
hoelzl@42904
  1054
    moreover assume "0 < b"
hoelzl@42904
  1055
    then have "0 < inverse b" by simp
hoelzl@42904
  1056
    ultimately have "inverse a < inverse b" by (rule less_trans)
hoelzl@42904
  1057
    then have "inverse a \<le> inverse b" by simp }
hoelzl@42904
  1058
  moreover
hoelzl@42904
  1059
  { assume "b < 0"
hoelzl@42904
  1060
    then have "inverse b < 0" by simp
hoelzl@42904
  1061
    moreover assume "0 < a"
hoelzl@42904
  1062
    then have "0 < inverse a" by simp
hoelzl@42904
  1063
    ultimately have "inverse b < inverse a" by (rule less_trans)
hoelzl@42904
  1064
    then have "\<not> inverse a \<le> inverse b" by simp }
hoelzl@42904
  1065
  ultimately show ?thesis
hoelzl@42904
  1066
    by (cases a 0 b 0 rule: linorder_cases[case_product linorder_cases])
hoelzl@42904
  1067
       (auto simp: not_less zero_less_mult_iff mult_le_0_iff)
hoelzl@42904
  1068
qed
hoelzl@42904
  1069
hoelzl@42904
  1070
lemma inverse_less_iff:
hoelzl@42904
  1071
  "inverse a < inverse b \<longleftrightarrow> (0 < a * b \<longrightarrow> b < a) \<and> (a * b \<le> 0 \<longrightarrow> a < b)"
hoelzl@42904
  1072
  by (subst less_le) (auto simp: inverse_le_iff)
hoelzl@42904
  1073
hoelzl@42904
  1074
lemma divide_le_cancel:
hoelzl@42904
  1075
  "a / c \<le> b / c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
hoelzl@42904
  1076
  by (simp add: divide_inverse mult_le_cancel_right)
hoelzl@42904
  1077
hoelzl@42904
  1078
lemma divide_less_cancel:
hoelzl@42904
  1079
  "a / c < b / c \<longleftrightarrow> (0 < c \<longrightarrow> a < b) \<and> (c < 0 \<longrightarrow> b < a) \<and> c \<noteq> 0"
hoelzl@42904
  1080
  by (auto simp add: divide_inverse mult_less_cancel_right)
hoelzl@42904
  1081
avigad@16775
  1082
text{*Simplify quotients that are compared with the value 1.*}
avigad@16775
  1083
blanchet@35828
  1084
lemma le_divide_eq_1 [no_atp]:
haftmann@36409
  1085
  "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
avigad@16775
  1086
by (auto simp add: le_divide_eq)
avigad@16775
  1087
blanchet@35828
  1088
lemma divide_le_eq_1 [no_atp]:
haftmann@36409
  1089
  "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
avigad@16775
  1090
by (auto simp add: divide_le_eq)
avigad@16775
  1091
blanchet@35828
  1092
lemma less_divide_eq_1 [no_atp]:
haftmann@36409
  1093
  "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
avigad@16775
  1094
by (auto simp add: less_divide_eq)
avigad@16775
  1095
blanchet@35828
  1096
lemma divide_less_eq_1 [no_atp]:
haftmann@36409
  1097
  "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
avigad@16775
  1098
by (auto simp add: divide_less_eq)
avigad@16775
  1099
wenzelm@23389
  1100
haftmann@36301
  1101
text {*Conditional Simplification Rules: No Case Splits*}
avigad@16775
  1102
blanchet@35828
  1103
lemma le_divide_eq_1_pos [simp,no_atp]:
haftmann@36409
  1104
  "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
avigad@16775
  1105
by (auto simp add: le_divide_eq)
avigad@16775
  1106
blanchet@35828
  1107
lemma le_divide_eq_1_neg [simp,no_atp]:
haftmann@36409
  1108
  "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
avigad@16775
  1109
by (auto simp add: le_divide_eq)
avigad@16775
  1110
blanchet@35828
  1111
lemma divide_le_eq_1_pos [simp,no_atp]:
haftmann@36409
  1112
  "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
avigad@16775
  1113
by (auto simp add: divide_le_eq)
avigad@16775
  1114
blanchet@35828
  1115
lemma divide_le_eq_1_neg [simp,no_atp]:
haftmann@36409
  1116
  "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
avigad@16775
  1117
by (auto simp add: divide_le_eq)
avigad@16775
  1118
blanchet@35828
  1119
lemma less_divide_eq_1_pos [simp,no_atp]:
haftmann@36409
  1120
  "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
avigad@16775
  1121
by (auto simp add: less_divide_eq)
avigad@16775
  1122
blanchet@35828
  1123
lemma less_divide_eq_1_neg [simp,no_atp]:
haftmann@36409
  1124
  "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
avigad@16775
  1125
by (auto simp add: less_divide_eq)
avigad@16775
  1126
blanchet@35828
  1127
lemma divide_less_eq_1_pos [simp,no_atp]:
haftmann@36409
  1128
  "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
paulson@18649
  1129
by (auto simp add: divide_less_eq)
paulson@18649
  1130
blanchet@35828
  1131
lemma divide_less_eq_1_neg [simp,no_atp]:
haftmann@36409
  1132
  "a < 0 \<Longrightarrow> b/a < 1 <-> a < b"
avigad@16775
  1133
by (auto simp add: divide_less_eq)
avigad@16775
  1134
blanchet@35828
  1135
lemma eq_divide_eq_1 [simp,no_atp]:
haftmann@36409
  1136
  "(1 = b/a) = ((a \<noteq> 0 & a = b))"
avigad@16775
  1137
by (auto simp add: eq_divide_eq)
avigad@16775
  1138
blanchet@35828
  1139
lemma divide_eq_eq_1 [simp,no_atp]:
haftmann@36409
  1140
  "(b/a = 1) = ((a \<noteq> 0 & a = b))"
avigad@16775
  1141
by (auto simp add: divide_eq_eq)
avigad@16775
  1142
paulson@14294
  1143
lemma abs_inverse [simp]:
haftmann@36409
  1144
     "\<bar>inverse a\<bar> = 
haftmann@36301
  1145
      inverse \<bar>a\<bar>"
haftmann@21328
  1146
apply (cases "a=0", simp) 
paulson@14294
  1147
apply (simp add: nonzero_abs_inverse) 
paulson@14294
  1148
done
paulson@14294
  1149
paulson@15234
  1150
lemma abs_divide [simp]:
haftmann@36409
  1151
     "\<bar>a / b\<bar> = \<bar>a\<bar> / \<bar>b\<bar>"
haftmann@21328
  1152
apply (cases "b=0", simp) 
paulson@14294
  1153
apply (simp add: nonzero_abs_divide) 
paulson@14294
  1154
done
paulson@14294
  1155
haftmann@36409
  1156
lemma abs_div_pos: "0 < y ==> 
haftmann@36301
  1157
    \<bar>x\<bar> / y = \<bar>x / y\<bar>"
haftmann@25304
  1158
  apply (subst abs_divide)
haftmann@25304
  1159
  apply (simp add: order_less_imp_le)
haftmann@25304
  1160
done
avigad@16775
  1161
hoelzl@35579
  1162
lemma field_le_mult_one_interval:
hoelzl@35579
  1163
  assumes *: "\<And>z. \<lbrakk> 0 < z ; z < 1 \<rbrakk> \<Longrightarrow> z * x \<le> y"
hoelzl@35579
  1164
  shows "x \<le> y"
hoelzl@35579
  1165
proof (cases "0 < x")
hoelzl@35579
  1166
  assume "0 < x"
hoelzl@35579
  1167
  thus ?thesis
hoelzl@35579
  1168
    using dense_le_bounded[of 0 1 "y/x"] *
hoelzl@35579
  1169
    unfolding le_divide_eq if_P[OF `0 < x`] by simp
hoelzl@35579
  1170
next
hoelzl@35579
  1171
  assume "\<not>0 < x" hence "x \<le> 0" by simp
hoelzl@35579
  1172
  obtain s::'a where s: "0 < s" "s < 1" using dense[of 0 "1\<Colon>'a"] by auto
hoelzl@35579
  1173
  hence "x \<le> s * x" using mult_le_cancel_right[of 1 x s] `x \<le> 0` by auto
hoelzl@35579
  1174
  also note *[OF s]
hoelzl@35579
  1175
  finally show ?thesis .
hoelzl@35579
  1176
qed
haftmann@35090
  1177
haftmann@36409
  1178
end
haftmann@36409
  1179
haftmann@33364
  1180
code_modulename SML
haftmann@35050
  1181
  Fields Arith
haftmann@33364
  1182
haftmann@33364
  1183
code_modulename OCaml
haftmann@35050
  1184
  Fields Arith
haftmann@33364
  1185
haftmann@33364
  1186
code_modulename Haskell
haftmann@35050
  1187
  Fields Arith
haftmann@33364
  1188
paulson@14265
  1189
end