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