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