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