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