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