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