src/HOL/Fields.thy
 author hoelzl Fri Feb 19 13:40:50 2016 +0100 (2016-02-19) changeset 62378 85ed00c1fe7c parent 62347 2230b7047376 child 62481 b5d8e57826df permissions -rw-r--r--
generalize more theorems to support enat and ennreal
1 (*  Title:      HOL/Fields.thy
2     Author:     Gertrud Bauer
3     Author:     Steven Obua
4     Author:     Tobias Nipkow
5     Author:     Lawrence C Paulson
6     Author:     Markus Wenzel
8 *)
10 section \<open>Fields\<close>
12 theory Fields
13 imports Rings
14 begin
16 subsection \<open>Division rings\<close>
18 text \<open>
19   A division ring is like a field, but without the commutativity requirement.
20 \<close>
22 class inverse = divide +
23   fixes inverse :: "'a \<Rightarrow> 'a"
24 begin
26 abbreviation inverse_divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "'/" 70)
27 where
28   "inverse_divide \<equiv> divide"
30 end
32 text\<open>Lemmas \<open>divide_simps\<close> move division to the outside and eliminates them on (in)equalities.\<close>
34 named_theorems divide_simps "rewrite rules to eliminate divisions"
36 class division_ring = ring_1 + inverse +
37   assumes left_inverse [simp]:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
38   assumes right_inverse [simp]: "a \<noteq> 0 \<Longrightarrow> a * inverse a = 1"
39   assumes divide_inverse: "a / b = a * inverse b"
40   assumes inverse_zero [simp]: "inverse 0 = 0"
41 begin
43 subclass ring_1_no_zero_divisors
44 proof
45   fix a b :: 'a
46   assume a: "a \<noteq> 0" and b: "b \<noteq> 0"
47   show "a * b \<noteq> 0"
48   proof
49     assume ab: "a * b = 0"
50     hence "0 = inverse a * (a * b) * inverse b" by simp
51     also have "\<dots> = (inverse a * a) * (b * inverse b)"
52       by (simp only: mult.assoc)
53     also have "\<dots> = 1" using a b by simp
54     finally show False by simp
55   qed
56 qed
58 lemma nonzero_imp_inverse_nonzero:
59   "a \<noteq> 0 \<Longrightarrow> inverse a \<noteq> 0"
60 proof
61   assume ianz: "inverse a = 0"
62   assume "a \<noteq> 0"
63   hence "1 = a * inverse a" by simp
64   also have "... = 0" by (simp add: ianz)
65   finally have "1 = 0" .
66   thus False by (simp add: eq_commute)
67 qed
69 lemma inverse_zero_imp_zero:
70   "inverse a = 0 \<Longrightarrow> a = 0"
71 apply (rule classical)
72 apply (drule nonzero_imp_inverse_nonzero)
73 apply auto
74 done
76 lemma inverse_unique:
77   assumes ab: "a * b = 1"
78   shows "inverse a = b"
79 proof -
80   have "a \<noteq> 0" using ab by (cases "a = 0") simp_all
81   moreover have "inverse a * (a * b) = inverse a" by (simp add: ab)
82   ultimately show ?thesis by (simp add: mult.assoc [symmetric])
83 qed
85 lemma nonzero_inverse_minus_eq:
86   "a \<noteq> 0 \<Longrightarrow> inverse (- a) = - inverse a"
87 by (rule inverse_unique) simp
89 lemma nonzero_inverse_inverse_eq:
90   "a \<noteq> 0 \<Longrightarrow> inverse (inverse a) = a"
91 by (rule inverse_unique) simp
93 lemma nonzero_inverse_eq_imp_eq:
94   assumes "inverse a = inverse b" and "a \<noteq> 0" and "b \<noteq> 0"
95   shows "a = b"
96 proof -
97   from \<open>inverse a = inverse b\<close>
98   have "inverse (inverse a) = inverse (inverse b)" by (rule arg_cong)
99   with \<open>a \<noteq> 0\<close> and \<open>b \<noteq> 0\<close> show "a = b"
101 qed
103 lemma inverse_1 [simp]: "inverse 1 = 1"
104 by (rule inverse_unique) simp
106 lemma nonzero_inverse_mult_distrib:
107   assumes "a \<noteq> 0" and "b \<noteq> 0"
108   shows "inverse (a * b) = inverse b * inverse a"
109 proof -
110   have "a * (b * inverse b) * inverse a = 1" using assms by simp
111   hence "a * b * (inverse b * inverse a) = 1" by (simp only: mult.assoc)
112   thus ?thesis by (rule inverse_unique)
113 qed
116   "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a + inverse b = inverse a * (a + b) * inverse b"
119 lemma division_ring_inverse_diff:
120   "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a - inverse b = inverse a * (b - a) * inverse b"
123 lemma right_inverse_eq: "b \<noteq> 0 \<Longrightarrow> a / b = 1 \<longleftrightarrow> a = b"
124 proof
125   assume neq: "b \<noteq> 0"
126   {
127     hence "a = (a / b) * b" by (simp add: divide_inverse mult.assoc)
128     also assume "a / b = 1"
129     finally show "a = b" by simp
130   next
131     assume "a = b"
132     with neq show "a / b = 1" by (simp add: divide_inverse)
133   }
134 qed
136 lemma nonzero_inverse_eq_divide: "a \<noteq> 0 \<Longrightarrow> inverse a = 1 / a"
139 lemma divide_self [simp]: "a \<noteq> 0 \<Longrightarrow> a / a = 1"
142 lemma inverse_eq_divide [field_simps, divide_simps]: "inverse a = 1 / a"
145 lemma add_divide_distrib: "(a+b) / c = a/c + b/c"
146 by (simp add: divide_inverse algebra_simps)
148 lemma times_divide_eq_right [simp]: "a * (b / c) = (a * b) / c"
149   by (simp add: divide_inverse mult.assoc)
151 lemma minus_divide_left: "- (a / b) = (-a) / b"
154 lemma nonzero_minus_divide_right: "b \<noteq> 0 ==> - (a / b) = a / (- b)"
155   by (simp add: divide_inverse nonzero_inverse_minus_eq)
157 lemma nonzero_minus_divide_divide: "b \<noteq> 0 ==> (-a) / (-b) = a / b"
158   by (simp add: divide_inverse nonzero_inverse_minus_eq)
160 lemma divide_minus_left [simp]: "(-a) / b = - (a / b)"
163 lemma diff_divide_distrib: "(a - b) / c = a / c - b / c"
164   using add_divide_distrib [of a "- b" c] by simp
166 lemma nonzero_eq_divide_eq [field_simps]: "c \<noteq> 0 \<Longrightarrow> a = b / c \<longleftrightarrow> a * c = b"
167 proof -
168   assume [simp]: "c \<noteq> 0"
169   have "a = b / c \<longleftrightarrow> a * c = (b / c) * c" by simp
170   also have "... \<longleftrightarrow> a * c = b" by (simp add: divide_inverse mult.assoc)
171   finally show ?thesis .
172 qed
174 lemma nonzero_divide_eq_eq [field_simps]: "c \<noteq> 0 \<Longrightarrow> b / c = a \<longleftrightarrow> b = a * c"
175 proof -
176   assume [simp]: "c \<noteq> 0"
177   have "b / c = a \<longleftrightarrow> (b / c) * c = a * c" by simp
178   also have "... \<longleftrightarrow> b = a * c" by (simp add: divide_inverse mult.assoc)
179   finally show ?thesis .
180 qed
182 lemma nonzero_neg_divide_eq_eq [field_simps]: "b \<noteq> 0 \<Longrightarrow> - (a / b) = c \<longleftrightarrow> - a = c * b"
183   using nonzero_divide_eq_eq[of b "-a" c] by simp
185 lemma nonzero_neg_divide_eq_eq2 [field_simps]: "b \<noteq> 0 \<Longrightarrow> c = - (a / b) \<longleftrightarrow> c * b = - a"
186   using nonzero_neg_divide_eq_eq[of b a c] by auto
188 lemma divide_eq_imp: "c \<noteq> 0 \<Longrightarrow> b = a * c \<Longrightarrow> b / c = a"
189   by (simp add: divide_inverse mult.assoc)
191 lemma eq_divide_imp: "c \<noteq> 0 \<Longrightarrow> a * c = b \<Longrightarrow> a = b / c"
192   by (drule sym) (simp add: divide_inverse mult.assoc)
195   "z \<noteq> 0 \<Longrightarrow> x + y / z = (x * z + y) / z"
199   "z \<noteq> 0 \<Longrightarrow> x / z + y = (x + y * z) / z"
202 lemma diff_divide_eq_iff [field_simps]:
203   "z \<noteq> 0 \<Longrightarrow> x - y / z = (x * z - y) / z"
204   by (simp add: diff_divide_distrib nonzero_eq_divide_eq eq_diff_eq)
207   "z \<noteq> 0 \<Longrightarrow> - (x / z) + y = (- x + y * z) / z"
210 lemma divide_diff_eq_iff [field_simps]:
211   "z \<noteq> 0 \<Longrightarrow> x / z - y = (x - y * z) / z"
214 lemma minus_divide_diff_eq_iff [field_simps]:
215   "z \<noteq> 0 \<Longrightarrow> - (x / z) - y = (- x - y * z) / z"
218 lemma division_ring_divide_zero [simp]:
219   "a / 0 = 0"
222 lemma divide_self_if [simp]:
223   "a / a = (if a = 0 then 0 else 1)"
224   by simp
226 lemma inverse_nonzero_iff_nonzero [simp]:
227   "inverse a = 0 \<longleftrightarrow> a = 0"
228   by rule (fact inverse_zero_imp_zero, simp)
230 lemma inverse_minus_eq [simp]:
231   "inverse (- a) = - inverse a"
232 proof cases
233   assume "a=0" thus ?thesis by simp
234 next
235   assume "a\<noteq>0"
236   thus ?thesis by (simp add: nonzero_inverse_minus_eq)
237 qed
239 lemma inverse_inverse_eq [simp]:
240   "inverse (inverse a) = a"
241 proof cases
242   assume "a=0" thus ?thesis by simp
243 next
244   assume "a\<noteq>0"
245   thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
246 qed
248 lemma inverse_eq_imp_eq:
249   "inverse a = inverse b \<Longrightarrow> a = b"
250   by (drule arg_cong [where f="inverse"], simp)
252 lemma inverse_eq_iff_eq [simp]:
253   "inverse a = inverse b \<longleftrightarrow> a = b"
254   by (force dest!: inverse_eq_imp_eq)
257     "a + b / z = (if z = 0 then a else (a * z + b) / z)"
258     "a / z + b = (if z = 0 then b else (a + b * z) / z)"
259     "- (a / z) + b = (if z = 0 then b else (-a + b * z) / z)"
260     "a - b / z = (if z = 0 then a else (a * z - b) / z)"
261     "a / z - b = (if z = 0 then -b else (a - b * z) / z)"
262     "- (a / z) - b = (if z = 0 then -b else (- a - b * z) / z)"
264       minus_divide_diff_eq_iff)
266 lemma [divide_simps]:
267   shows divide_eq_eq: "b / c = a \<longleftrightarrow> (if c \<noteq> 0 then b = a * c else a = 0)"
268     and eq_divide_eq: "a = b / c \<longleftrightarrow> (if c \<noteq> 0 then a * c = b else a = 0)"
269     and minus_divide_eq_eq: "- (b / c) = a \<longleftrightarrow> (if c \<noteq> 0 then - b = a * c else a = 0)"
270     and eq_minus_divide_eq: "a = - (b / c) \<longleftrightarrow> (if c \<noteq> 0 then a * c = - b else a = 0)"
271   by (auto simp add:  field_simps)
273 end
275 subsection \<open>Fields\<close>
277 class field = comm_ring_1 + inverse +
278   assumes field_inverse: "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
279   assumes field_divide_inverse: "a / b = a * inverse b"
280   assumes field_inverse_zero: "inverse 0 = 0"
281 begin
283 subclass division_ring
284 proof
285   fix a :: 'a
286   assume "a \<noteq> 0"
287   thus "inverse a * a = 1" by (rule field_inverse)
288   thus "a * inverse a = 1" by (simp only: mult.commute)
289 next
290   fix a b :: 'a
291   show "a / b = a * inverse b" by (rule field_divide_inverse)
292 next
293   show "inverse 0 = 0"
294     by (fact field_inverse_zero)
295 qed
297 subclass idom_divide
298 proof
299   fix b a
300   assume "b \<noteq> 0"
301   then show "a * b / b = a"
302     by (simp add: divide_inverse ac_simps)
303 next
304   fix a
305   show "a / 0 = 0"
307 qed
309 text\<open>There is no slick version using division by zero.\<close>
311   "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a + inverse b = (a + b) * inverse a * inverse b"
314 lemma nonzero_mult_divide_mult_cancel_left [simp]:
315   assumes [simp]: "c \<noteq> 0"
316   shows "(c * a) / (c * b) = a / b"
317 proof (cases "b = 0")
318   case True then show ?thesis by simp
319 next
320   case False
321   then have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
322     by (simp add: divide_inverse nonzero_inverse_mult_distrib)
323   also have "... =  a * inverse b * (inverse c * c)"
324     by (simp only: ac_simps)
325   also have "... =  a * inverse b" by simp
326     finally show ?thesis by (simp add: divide_inverse)
327 qed
329 lemma nonzero_mult_divide_mult_cancel_right [simp]:
330   "c \<noteq> 0 \<Longrightarrow> (a * c) / (b * c) = a / b"
331   using nonzero_mult_divide_mult_cancel_left [of c a b] by (simp add: ac_simps)
333 lemma times_divide_eq_left [simp]: "(b / c) * a = (b * a) / c"
334   by (simp add: divide_inverse ac_simps)
336 lemma divide_inverse_commute: "a / b = inverse b * a"
337   by (simp add: divide_inverse mult.commute)
340   assumes "y \<noteq> 0" and "z \<noteq> 0"
341   shows "x / y + w / z = (x * z + w * y) / (y * z)"
342 proof -
343   have "x / y + w / z = (x * z) / (y * z) + (y * w) / (y * z)"
344     using assms by simp
345   also have "\<dots> = (x * z + y * w) / (y * z)"
347   finally show ?thesis
348     by (simp only: mult.commute)
349 qed
351 text\<open>Special Cancellation Simprules for Division\<close>
353 lemma nonzero_divide_mult_cancel_right [simp]:
354   "b \<noteq> 0 \<Longrightarrow> b / (a * b) = 1 / a"
355   using nonzero_mult_divide_mult_cancel_right [of b 1 a] by simp
357 lemma nonzero_divide_mult_cancel_left [simp]:
358   "a \<noteq> 0 \<Longrightarrow> a / (a * b) = 1 / b"
359   using nonzero_mult_divide_mult_cancel_left [of a 1 b] by simp
361 lemma nonzero_mult_divide_mult_cancel_left2 [simp]:
362   "c \<noteq> 0 \<Longrightarrow> (c * a) / (b * c) = a / b"
363   using nonzero_mult_divide_mult_cancel_left [of c a b] by (simp add: ac_simps)
365 lemma nonzero_mult_divide_mult_cancel_right2 [simp]:
366   "c \<noteq> 0 \<Longrightarrow> (a * c) / (c * b) = a / b"
367   using nonzero_mult_divide_mult_cancel_right [of b c a] by (simp add: ac_simps)
369 lemma diff_frac_eq:
370   "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> x / y - w / z = (x * z - w * y) / (y * z)"
373 lemma frac_eq_eq:
374   "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> (x / y = w / z) = (x * z = w * y)"
377 lemma divide_minus1 [simp]: "x / - 1 = - x"
378   using nonzero_minus_divide_right [of "1" x] by simp
380 text\<open>This version builds in division by zero while also re-orienting
381       the right-hand side.\<close>
382 lemma inverse_mult_distrib [simp]:
383   "inverse (a * b) = inverse a * inverse b"
384 proof cases
385   assume "a \<noteq> 0 & b \<noteq> 0"
386   thus ?thesis by (simp add: nonzero_inverse_mult_distrib ac_simps)
387 next
388   assume "~ (a \<noteq> 0 & b \<noteq> 0)"
389   thus ?thesis by force
390 qed
392 lemma inverse_divide [simp]:
393   "inverse (a / b) = b / a"
394   by (simp add: divide_inverse mult.commute)
397 text \<open>Calculations with fractions\<close>
399 text\<open>There is a whole bunch of simp-rules just for class \<open>field\<close> but none for class \<open>field\<close> and \<open>nonzero_divides\<close>
400 because the latter are covered by a simproc.\<close>
402 lemma mult_divide_mult_cancel_left:
403   "c \<noteq> 0 \<Longrightarrow> (c * a) / (c * b) = a / b"
404 apply (cases "b = 0")
405 apply simp_all
406 done
408 lemma mult_divide_mult_cancel_right:
409   "c \<noteq> 0 \<Longrightarrow> (a * c) / (b * c) = a / b"
410 apply (cases "b = 0")
411 apply simp_all
412 done
414 lemma divide_divide_eq_right [simp]:
415   "a / (b / c) = (a * c) / b"
416   by (simp add: divide_inverse ac_simps)
418 lemma divide_divide_eq_left [simp]:
419   "(a / b) / c = a / (b * c)"
420   by (simp add: divide_inverse mult.assoc)
422 lemma divide_divide_times_eq:
423   "(x / y) / (z / w) = (x * w) / (y * z)"
424   by simp
426 text \<open>Special Cancellation Simprules for Division\<close>
428 lemma mult_divide_mult_cancel_left_if [simp]:
429   shows "(c * a) / (c * b) = (if c = 0 then 0 else a / b)"
430   by simp
433 text \<open>Division and Unary Minus\<close>
435 lemma minus_divide_right:
436   "- (a / b) = a / - b"
439 lemma divide_minus_right [simp]:
440   "a / - b = - (a / b)"
443 lemma minus_divide_divide:
444   "(- a) / (- b) = a / b"
445 apply (cases "b=0", simp)
447 done
449 lemma inverse_eq_1_iff [simp]:
450   "inverse x = 1 \<longleftrightarrow> x = 1"
451   by (insert inverse_eq_iff_eq [of x 1], simp)
453 lemma divide_eq_0_iff [simp]:
454   "a / b = 0 \<longleftrightarrow> a = 0 \<or> b = 0"
457 lemma divide_cancel_right [simp]:
458   "a / c = b / c \<longleftrightarrow> c = 0 \<or> a = b"
459   apply (cases "c=0", simp)
461   done
463 lemma divide_cancel_left [simp]:
464   "c / a = c / b \<longleftrightarrow> c = 0 \<or> a = b"
465   apply (cases "c=0", simp)
467   done
469 lemma divide_eq_1_iff [simp]:
470   "a / b = 1 \<longleftrightarrow> b \<noteq> 0 \<and> a = b"
471   apply (cases "b=0", simp)
473   done
475 lemma one_eq_divide_iff [simp]:
476   "1 = a / b \<longleftrightarrow> b \<noteq> 0 \<and> a = b"
477   by (simp add: eq_commute [of 1])
479 lemma times_divide_times_eq:
480   "(x / y) * (z / w) = (x * z) / (y * w)"
481   by simp
484   "y \<noteq> 0 \<Longrightarrow> x / y + z = (x + z * y) / y"
488   "y \<noteq> 0 \<Longrightarrow> z + x / y = (x + z * y) / y"
491 end
494 subsection \<open>Ordered fields\<close>
496 class linordered_field = field + linordered_idom
497 begin
499 lemma positive_imp_inverse_positive:
500   assumes a_gt_0: "0 < a"
501   shows "0 < inverse a"
502 proof -
503   have "0 < a * inverse a"
504     by (simp add: a_gt_0 [THEN less_imp_not_eq2])
505   thus "0 < inverse a"
506     by (simp add: a_gt_0 [THEN less_not_sym] zero_less_mult_iff)
507 qed
509 lemma negative_imp_inverse_negative:
510   "a < 0 \<Longrightarrow> inverse a < 0"
511   by (insert positive_imp_inverse_positive [of "-a"],
514 lemma inverse_le_imp_le:
515   assumes invle: "inverse a \<le> inverse b" and apos: "0 < a"
516   shows "b \<le> a"
517 proof (rule classical)
518   assume "~ b \<le> a"
519   hence "a < b"  by (simp add: linorder_not_le)
520   hence bpos: "0 < b"  by (blast intro: apos less_trans)
521   hence "a * inverse a \<le> a * inverse b"
522     by (simp add: apos invle less_imp_le mult_left_mono)
523   hence "(a * inverse a) * b \<le> (a * inverse b) * b"
524     by (simp add: bpos less_imp_le mult_right_mono)
525   thus "b \<le> a"  by (simp add: mult.assoc apos bpos less_imp_not_eq2)
526 qed
528 lemma inverse_positive_imp_positive:
529   assumes inv_gt_0: "0 < inverse a" and nz: "a \<noteq> 0"
530   shows "0 < a"
531 proof -
532   have "0 < inverse (inverse a)"
533     using inv_gt_0 by (rule positive_imp_inverse_positive)
534   thus "0 < a"
535     using nz by (simp add: nonzero_inverse_inverse_eq)
536 qed
538 lemma inverse_negative_imp_negative:
539   assumes inv_less_0: "inverse a < 0" and nz: "a \<noteq> 0"
540   shows "a < 0"
541 proof -
542   have "inverse (inverse a) < 0"
543     using inv_less_0 by (rule negative_imp_inverse_negative)
544   thus "a < 0" using nz by (simp add: nonzero_inverse_inverse_eq)
545 qed
547 lemma linordered_field_no_lb:
548   "\<forall>x. \<exists>y. y < x"
549 proof
550   fix x::'a
551   have m1: "- (1::'a) < 0" by simp
552   from add_strict_right_mono[OF m1, where c=x]
553   have "(- 1) + x < x" by simp
554   thus "\<exists>y. y < x" by blast
555 qed
557 lemma linordered_field_no_ub:
558   "\<forall> x. \<exists>y. y > x"
559 proof
560   fix x::'a
561   have m1: " (1::'a) > 0" by simp
562   from add_strict_right_mono[OF m1, where c=x]
563   have "1 + x > x" by simp
564   thus "\<exists>y. y > x" by blast
565 qed
567 lemma less_imp_inverse_less:
568   assumes less: "a < b" and apos:  "0 < a"
569   shows "inverse b < inverse a"
570 proof (rule ccontr)
571   assume "~ inverse b < inverse a"
572   hence "inverse a \<le> inverse b" by simp
573   hence "~ (a < b)"
574     by (simp add: not_less inverse_le_imp_le [OF _ apos])
575   thus False by (rule notE [OF _ less])
576 qed
578 lemma inverse_less_imp_less:
579   "inverse a < inverse b \<Longrightarrow> 0 < a \<Longrightarrow> b < a"
580 apply (simp add: less_le [of "inverse a"] less_le [of "b"])
581 apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq)
582 done
584 text\<open>Both premises are essential. Consider -1 and 1.\<close>
585 lemma inverse_less_iff_less [simp]:
586   "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> inverse a < inverse b \<longleftrightarrow> b < a"
587   by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less)
589 lemma le_imp_inverse_le:
590   "a \<le> b \<Longrightarrow> 0 < a \<Longrightarrow> inverse b \<le> inverse a"
591   by (force simp add: le_less less_imp_inverse_less)
593 lemma inverse_le_iff_le [simp]:
594   "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> inverse a \<le> inverse b \<longleftrightarrow> b \<le> a"
595   by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le)
598 text\<open>These results refer to both operands being negative.  The opposite-sign
599 case is trivial, since inverse preserves signs.\<close>
600 lemma inverse_le_imp_le_neg:
601   "inverse a \<le> inverse b \<Longrightarrow> b < 0 \<Longrightarrow> b \<le> a"
602 apply (rule classical)
603 apply (subgoal_tac "a < 0")
604  prefer 2 apply force
605 apply (insert inverse_le_imp_le [of "-b" "-a"])
607 done
609 lemma less_imp_inverse_less_neg:
610    "a < b \<Longrightarrow> b < 0 \<Longrightarrow> inverse b < inverse a"
611 apply (subgoal_tac "a < 0")
612  prefer 2 apply (blast intro: less_trans)
613 apply (insert less_imp_inverse_less [of "-b" "-a"])
615 done
617 lemma inverse_less_imp_less_neg:
618    "inverse a < inverse b \<Longrightarrow> b < 0 \<Longrightarrow> b < a"
619 apply (rule classical)
620 apply (subgoal_tac "a < 0")
621  prefer 2
622  apply force
623 apply (insert inverse_less_imp_less [of "-b" "-a"])
625 done
627 lemma inverse_less_iff_less_neg [simp]:
628   "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> inverse a < inverse b \<longleftrightarrow> b < a"
629 apply (insert inverse_less_iff_less [of "-b" "-a"])
630 apply (simp del: inverse_less_iff_less
632 done
634 lemma le_imp_inverse_le_neg:
635   "a \<le> b \<Longrightarrow> b < 0 ==> inverse b \<le> inverse a"
636   by (force simp add: le_less less_imp_inverse_less_neg)
638 lemma inverse_le_iff_le_neg [simp]:
639   "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> inverse a \<le> inverse b \<longleftrightarrow> b \<le> a"
640   by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg)
642 lemma one_less_inverse:
643   "0 < a \<Longrightarrow> a < 1 \<Longrightarrow> 1 < inverse a"
644   using less_imp_inverse_less [of a 1, unfolded inverse_1] .
646 lemma one_le_inverse:
647   "0 < a \<Longrightarrow> a \<le> 1 \<Longrightarrow> 1 \<le> inverse a"
648   using le_imp_inverse_le [of a 1, unfolded inverse_1] .
650 lemma pos_le_divide_eq [field_simps]:
651   assumes "0 < c"
652   shows "a \<le> b / c \<longleftrightarrow> a * c \<le> b"
653 proof -
654   from assms have "a \<le> b / c \<longleftrightarrow> a * c \<le> (b / c) * c"
655     using mult_le_cancel_right [of a c "b * inverse c"] by (auto simp add: field_simps)
656   also have "... \<longleftrightarrow> a * c \<le> b"
657     by (simp add: less_imp_not_eq2 [OF assms] divide_inverse mult.assoc)
658   finally show ?thesis .
659 qed
661 lemma pos_less_divide_eq [field_simps]:
662   assumes "0 < c"
663   shows "a < b / c \<longleftrightarrow> a * c < b"
664 proof -
665   from assms have "a < b / c \<longleftrightarrow> a * c < (b / c) * c"
666     using mult_less_cancel_right [of a c "b / c"] by auto
667   also have "... = (a*c < b)"
668     by (simp add: less_imp_not_eq2 [OF assms] divide_inverse mult.assoc)
669   finally show ?thesis .
670 qed
672 lemma neg_less_divide_eq [field_simps]:
673   assumes "c < 0"
674   shows "a < b / c \<longleftrightarrow> b < a * c"
675 proof -
676   from assms have "a < b / c \<longleftrightarrow> (b / c) * c < a * c"
677     using mult_less_cancel_right [of "b / c" c a] by auto
678   also have "... \<longleftrightarrow> b < a * c"
679     by (simp add: less_imp_not_eq [OF assms] divide_inverse mult.assoc)
680   finally show ?thesis .
681 qed
683 lemma neg_le_divide_eq [field_simps]:
684   assumes "c < 0"
685   shows "a \<le> b / c \<longleftrightarrow> b \<le> a * c"
686 proof -
687   from assms have "a \<le> b / c \<longleftrightarrow> (b / c) * c \<le> a * c"
688     using mult_le_cancel_right [of "b * inverse c" c a] by (auto simp add: field_simps)
689   also have "... \<longleftrightarrow> b \<le> a * c"
690     by (simp add: less_imp_not_eq [OF assms] divide_inverse mult.assoc)
691   finally show ?thesis .
692 qed
694 lemma pos_divide_le_eq [field_simps]:
695   assumes "0 < c"
696   shows "b / c \<le> a \<longleftrightarrow> b \<le> a * c"
697 proof -
698   from assms have "b / c \<le> a \<longleftrightarrow> (b / c) * c \<le> a * c"
699     using mult_le_cancel_right [of "b / c" c a] by auto
700   also have "... \<longleftrightarrow> b \<le> a * c"
701     by (simp add: less_imp_not_eq2 [OF assms] divide_inverse mult.assoc)
702   finally show ?thesis .
703 qed
705 lemma pos_divide_less_eq [field_simps]:
706   assumes "0 < c"
707   shows "b / c < a \<longleftrightarrow> b < a * c"
708 proof -
709   from assms have "b / c < a \<longleftrightarrow> (b / c) * c < a * c"
710     using mult_less_cancel_right [of "b / c" c a] by auto
711   also have "... \<longleftrightarrow> b < a * c"
712     by (simp add: less_imp_not_eq2 [OF assms] divide_inverse mult.assoc)
713   finally show ?thesis .
714 qed
716 lemma neg_divide_le_eq [field_simps]:
717   assumes "c < 0"
718   shows "b / c \<le> a \<longleftrightarrow> a * c \<le> b"
719 proof -
720   from assms have "b / c \<le> a \<longleftrightarrow> a * c \<le> (b / c) * c"
721     using mult_le_cancel_right [of a c "b / c"] by auto
722   also have "... \<longleftrightarrow> a * c \<le> b"
723     by (simp add: less_imp_not_eq [OF assms] divide_inverse mult.assoc)
724   finally show ?thesis .
725 qed
727 lemma neg_divide_less_eq [field_simps]:
728   assumes "c < 0"
729   shows "b / c < a \<longleftrightarrow> a * c < b"
730 proof -
731   from assms have "b / c < a \<longleftrightarrow> a * c < b / c * c"
732     using mult_less_cancel_right [of a c "b / c"] by auto
733   also have "... \<longleftrightarrow> a * c < b"
734     by (simp add: less_imp_not_eq [OF assms] divide_inverse mult.assoc)
735   finally show ?thesis .
736 qed
738 text\<open>The following \<open>field_simps\<close> rules are necessary, as minus is always moved atop of
739 division but we want to get rid of division.\<close>
741 lemma pos_le_minus_divide_eq [field_simps]: "0 < c \<Longrightarrow> a \<le> - (b / c) \<longleftrightarrow> a * c \<le> - b"
742   unfolding minus_divide_left by (rule pos_le_divide_eq)
744 lemma neg_le_minus_divide_eq [field_simps]: "c < 0 \<Longrightarrow> a \<le> - (b / c) \<longleftrightarrow> - b \<le> a * c"
745   unfolding minus_divide_left by (rule neg_le_divide_eq)
747 lemma pos_less_minus_divide_eq [field_simps]: "0 < c \<Longrightarrow> a < - (b / c) \<longleftrightarrow> a * c < - b"
748   unfolding minus_divide_left by (rule pos_less_divide_eq)
750 lemma neg_less_minus_divide_eq [field_simps]: "c < 0 \<Longrightarrow> a < - (b / c) \<longleftrightarrow> - b < a * c"
751   unfolding minus_divide_left by (rule neg_less_divide_eq)
753 lemma pos_minus_divide_less_eq [field_simps]: "0 < c \<Longrightarrow> - (b / c) < a \<longleftrightarrow> - b < a * c"
754   unfolding minus_divide_left by (rule pos_divide_less_eq)
756 lemma neg_minus_divide_less_eq [field_simps]: "c < 0 \<Longrightarrow> - (b / c) < a \<longleftrightarrow> a * c < - b"
757   unfolding minus_divide_left by (rule neg_divide_less_eq)
759 lemma pos_minus_divide_le_eq [field_simps]: "0 < c \<Longrightarrow> - (b / c) \<le> a \<longleftrightarrow> - b \<le> a * c"
760   unfolding minus_divide_left by (rule pos_divide_le_eq)
762 lemma neg_minus_divide_le_eq [field_simps]: "c < 0 \<Longrightarrow> - (b / c) \<le> a \<longleftrightarrow> a * c \<le> - b"
763   unfolding minus_divide_left by (rule neg_divide_le_eq)
765 lemma frac_less_eq:
766   "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> x / y < w / z \<longleftrightarrow> (x * z - w * y) / (y * z) < 0"
767   by (subst less_iff_diff_less_0) (simp add: diff_frac_eq )
769 lemma frac_le_eq:
770   "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> x / y \<le> w / z \<longleftrightarrow> (x * z - w * y) / (y * z) \<le> 0"
771   by (subst le_iff_diff_le_0) (simp add: diff_frac_eq )
773 text\<open>Lemmas \<open>sign_simps\<close> is a first attempt to automate proofs
774 of positivity/negativity needed for \<open>field_simps\<close>. Have not added \<open>sign_simps\<close> to \<open>field_simps\<close> because the former can lead to case
775 explosions.\<close>
777 lemmas sign_simps = algebra_simps zero_less_mult_iff mult_less_0_iff
779 lemmas (in -) sign_simps = algebra_simps zero_less_mult_iff mult_less_0_iff
781 (* Only works once linear arithmetic is installed:
782 text{*An example:*}
783 lemma fixes a b c d e f :: "'a::linordered_field"
784 shows "\<lbrakk>a>b; c<d; e<f; 0 < u \<rbrakk> \<Longrightarrow>
785  ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) <
786  ((e-f)*(a-b)*(c-d))/((e-f)*(a-b)*(c-d)) + u"
787 apply(subgoal_tac "(c-d)*(e-f)*(a-b) > 0")
789 apply(subgoal_tac "(c-d)*(e-f)*(a-b)*u > 0")
792 done
793 *)
795 lemma divide_pos_pos[simp]:
796   "0 < x ==> 0 < y ==> 0 < x / y"
799 lemma divide_nonneg_pos:
800   "0 <= x ==> 0 < y ==> 0 <= x / y"
803 lemma divide_neg_pos:
804   "x < 0 ==> 0 < y ==> x / y < 0"
807 lemma divide_nonpos_pos:
808   "x <= 0 ==> 0 < y ==> x / y <= 0"
811 lemma divide_pos_neg:
812   "0 < x ==> y < 0 ==> x / y < 0"
815 lemma divide_nonneg_neg:
816   "0 <= x ==> y < 0 ==> x / y <= 0"
819 lemma divide_neg_neg:
820   "x < 0 ==> y < 0 ==> 0 < x / y"
823 lemma divide_nonpos_neg:
824   "x <= 0 ==> y < 0 ==> 0 <= x / y"
827 lemma divide_strict_right_mono:
828      "[|a < b; 0 < c|] ==> a / c < b / c"
829 by (simp add: less_imp_not_eq2 divide_inverse mult_strict_right_mono
830               positive_imp_inverse_positive)
833 lemma divide_strict_right_mono_neg:
834      "[|b < a; c < 0|] ==> a / c < b / c"
835 apply (drule divide_strict_right_mono [of _ _ "-c"], simp)
836 apply (simp add: less_imp_not_eq nonzero_minus_divide_right [symmetric])
837 done
839 text\<open>The last premise ensures that @{term a} and @{term b}
840       have the same sign\<close>
841 lemma divide_strict_left_mono:
842   "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / b"
843   by (auto simp: field_simps zero_less_mult_iff mult_strict_right_mono)
845 lemma divide_left_mono:
846   "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / b"
847   by (auto simp: field_simps zero_less_mult_iff mult_right_mono)
849 lemma divide_strict_left_mono_neg:
850   "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / b"
851   by (auto simp: field_simps zero_less_mult_iff mult_strict_right_mono_neg)
853 lemma mult_imp_div_pos_le: "0 < y ==> x <= z * y ==>
854     x / y <= z"
855 by (subst pos_divide_le_eq, assumption+)
857 lemma mult_imp_le_div_pos: "0 < y ==> z * y <= x ==>
858     z <= x / y"
861 lemma mult_imp_div_pos_less: "0 < y ==> x < z * y ==>
862     x / y < z"
865 lemma mult_imp_less_div_pos: "0 < y ==> z * y < x ==>
866     z < x / y"
869 lemma frac_le: "0 <= x ==>
870     x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
871   apply (rule mult_imp_div_pos_le)
872   apply simp
873   apply (subst times_divide_eq_left)
874   apply (rule mult_imp_le_div_pos, assumption)
875   apply (rule mult_mono)
876   apply simp_all
877 done
879 lemma frac_less: "0 <= x ==>
880     x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
881   apply (rule mult_imp_div_pos_less)
882   apply simp
883   apply (subst times_divide_eq_left)
884   apply (rule mult_imp_less_div_pos, assumption)
885   apply (erule mult_less_le_imp_less)
886   apply simp_all
887 done
889 lemma frac_less2: "0 < x ==>
890     x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
891   apply (rule mult_imp_div_pos_less)
892   apply simp_all
893   apply (rule mult_imp_less_div_pos, assumption)
894   apply (erule mult_le_less_imp_less)
895   apply simp_all
896 done
898 lemma less_half_sum: "a < b ==> a < (a+b) / (1+1)"
899 by (simp add: field_simps zero_less_two)
901 lemma gt_half_sum: "a < b ==> (a+b)/(1+1) < b"
902 by (simp add: field_simps zero_less_two)
904 subclass unbounded_dense_linorder
905 proof
906   fix x y :: 'a
907   from less_add_one show "\<exists>y. x < y" ..
908   from less_add_one have "x + (- 1) < (x + 1) + (- 1)" by (rule add_strict_right_mono)
909   then have "x - 1 < x + 1 - 1" by simp
910   then have "x - 1 < x" by (simp add: algebra_simps)
911   then show "\<exists>y. y < x" ..
912   show "x < y \<Longrightarrow> \<exists>z>x. z < y" by (blast intro!: less_half_sum gt_half_sum)
913 qed
915 lemma nonzero_abs_inverse:
916      "a \<noteq> 0 ==> \<bar>inverse a\<bar> = inverse \<bar>a\<bar>"
917 apply (auto simp add: neq_iff abs_if nonzero_inverse_minus_eq
918                       negative_imp_inverse_negative)
919 apply (blast intro: positive_imp_inverse_positive elim: less_asym)
920 done
922 lemma nonzero_abs_divide:
923      "b \<noteq> 0 ==> \<bar>a / b\<bar> = \<bar>a\<bar> / \<bar>b\<bar>"
924   by (simp add: divide_inverse abs_mult nonzero_abs_inverse)
926 lemma field_le_epsilon:
927   assumes e: "\<And>e. 0 < e \<Longrightarrow> x \<le> y + e"
928   shows "x \<le> y"
929 proof (rule dense_le)
930   fix t assume "t < x"
931   hence "0 < x - t" by (simp add: less_diff_eq)
932   from e [OF this] have "x + 0 \<le> x + (y - t)" by (simp add: algebra_simps)
933   then have "0 \<le> y - t" by (simp only: add_le_cancel_left)
934   then show "t \<le> y" by (simp add: algebra_simps)
935 qed
937 lemma inverse_positive_iff_positive [simp]:
938   "(0 < inverse a) = (0 < a)"
939 apply (cases "a = 0", simp)
940 apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
941 done
943 lemma inverse_negative_iff_negative [simp]:
944   "(inverse a < 0) = (a < 0)"
945 apply (cases "a = 0", simp)
946 apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
947 done
949 lemma inverse_nonnegative_iff_nonnegative [simp]:
950   "0 \<le> inverse a \<longleftrightarrow> 0 \<le> a"
951   by (simp add: not_less [symmetric])
953 lemma inverse_nonpositive_iff_nonpositive [simp]:
954   "inverse a \<le> 0 \<longleftrightarrow> a \<le> 0"
955   by (simp add: not_less [symmetric])
957 lemma one_less_inverse_iff: "1 < inverse x \<longleftrightarrow> 0 < x \<and> x < 1"
958   using less_trans[of 1 x 0 for x]
959   by (cases x 0 rule: linorder_cases) (auto simp add: field_simps)
961 lemma one_le_inverse_iff: "1 \<le> inverse x \<longleftrightarrow> 0 < x \<and> x \<le> 1"
962 proof (cases "x = 1")
963   case True then show ?thesis by simp
964 next
965   case False then have "inverse x \<noteq> 1" by simp
966   then have "1 \<noteq> inverse x" by blast
967   then have "1 \<le> inverse x \<longleftrightarrow> 1 < inverse x" by (simp add: le_less)
968   with False show ?thesis by (auto simp add: one_less_inverse_iff)
969 qed
971 lemma inverse_less_1_iff: "inverse x < 1 \<longleftrightarrow> x \<le> 0 \<or> 1 < x"
972   by (simp add: not_le [symmetric] one_le_inverse_iff)
974 lemma inverse_le_1_iff: "inverse x \<le> 1 \<longleftrightarrow> x \<le> 0 \<or> 1 \<le> x"
975   by (simp add: not_less [symmetric] one_less_inverse_iff)
977 lemma [divide_simps]:
978   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)"
979     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)"
980     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)"
981     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)"
982     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)"
983     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)"
984     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)"
985     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)"
986   by (auto simp: field_simps not_less dest: antisym)
988 text \<open>Division and Signs\<close>
990 lemma
991   shows zero_less_divide_iff: "0 < a / b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0"
992     and divide_less_0_iff: "a / b < 0 \<longleftrightarrow> 0 < a \<and> b < 0 \<or> a < 0 \<and> 0 < b"
993     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"
994     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"
995   by (auto simp add: divide_simps)
997 text \<open>Division and the Number One\<close>
999 text\<open>Simplify expressions equated with 1\<close>
1001 lemma zero_eq_1_divide_iff [simp]: "0 = 1 / a \<longleftrightarrow> a = 0"
1002   by (cases "a = 0") (auto simp: field_simps)
1004 lemma one_divide_eq_0_iff [simp]: "1 / a = 0 \<longleftrightarrow> a = 0"
1005   using zero_eq_1_divide_iff[of a] by simp
1007 text\<open>Simplify expressions such as \<open>0 < 1/x\<close> to \<open>0 < x\<close>\<close>
1009 lemma zero_le_divide_1_iff [simp]:
1010   "0 \<le> 1 / a \<longleftrightarrow> 0 \<le> a"
1013 lemma zero_less_divide_1_iff [simp]:
1014   "0 < 1 / a \<longleftrightarrow> 0 < a"
1017 lemma divide_le_0_1_iff [simp]:
1018   "1 / a \<le> 0 \<longleftrightarrow> a \<le> 0"
1021 lemma divide_less_0_1_iff [simp]:
1022   "1 / a < 0 \<longleftrightarrow> a < 0"
1025 lemma divide_right_mono:
1026      "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/c"
1027 by (force simp add: divide_strict_right_mono le_less)
1029 lemma divide_right_mono_neg: "a <= b
1030     ==> c <= 0 ==> b / c <= a / c"
1031 apply (drule divide_right_mono [of _ _ "- c"])
1032 apply auto
1033 done
1035 lemma divide_left_mono_neg: "a <= b
1036     ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
1037   apply (drule divide_left_mono [of _ _ "- c"])
1038   apply (auto simp add: mult.commute)
1039 done
1041 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)"
1042   by (cases a 0 b 0 rule: linorder_cases[case_product linorder_cases])
1043      (auto simp add: field_simps zero_less_mult_iff mult_le_0_iff)
1045 lemma inverse_less_iff: "inverse a < inverse b \<longleftrightarrow> (0 < a * b \<longrightarrow> b < a) \<and> (a * b \<le> 0 \<longrightarrow> a < b)"
1046   by (subst less_le) (auto simp: inverse_le_iff)
1048 lemma divide_le_cancel: "a / c \<le> b / c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
1049   by (simp add: divide_inverse mult_le_cancel_right)
1051 lemma divide_less_cancel: "a / c < b / c \<longleftrightarrow> (0 < c \<longrightarrow> a < b) \<and> (c < 0 \<longrightarrow> b < a) \<and> c \<noteq> 0"
1052   by (auto simp add: divide_inverse mult_less_cancel_right)
1054 text\<open>Simplify quotients that are compared with the value 1.\<close>
1056 lemma le_divide_eq_1:
1057   "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
1058 by (auto simp add: le_divide_eq)
1060 lemma divide_le_eq_1:
1061   "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
1062 by (auto simp add: divide_le_eq)
1064 lemma less_divide_eq_1:
1065   "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
1066 by (auto simp add: less_divide_eq)
1068 lemma divide_less_eq_1:
1069   "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
1070 by (auto simp add: divide_less_eq)
1072 lemma divide_nonneg_nonneg [simp]:
1073   "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> 0 \<le> x / y"
1074   by (auto simp add: divide_simps)
1076 lemma divide_nonpos_nonpos:
1077   "x \<le> 0 \<Longrightarrow> y \<le> 0 \<Longrightarrow> 0 \<le> x / y"
1078   by (auto simp add: divide_simps)
1080 lemma divide_nonneg_nonpos:
1081   "0 \<le> x \<Longrightarrow> y \<le> 0 \<Longrightarrow> x / y \<le> 0"
1082   by (auto simp add: divide_simps)
1084 lemma divide_nonpos_nonneg:
1085   "x \<le> 0 \<Longrightarrow> 0 \<le> y \<Longrightarrow> x / y \<le> 0"
1086   by (auto simp add: divide_simps)
1088 text \<open>Conditional Simplification Rules: No Case Splits\<close>
1090 lemma le_divide_eq_1_pos [simp]:
1091   "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
1092 by (auto simp add: le_divide_eq)
1094 lemma le_divide_eq_1_neg [simp]:
1095   "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
1096 by (auto simp add: le_divide_eq)
1098 lemma divide_le_eq_1_pos [simp]:
1099   "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
1100 by (auto simp add: divide_le_eq)
1102 lemma divide_le_eq_1_neg [simp]:
1103   "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
1104 by (auto simp add: divide_le_eq)
1106 lemma less_divide_eq_1_pos [simp]:
1107   "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
1108 by (auto simp add: less_divide_eq)
1110 lemma less_divide_eq_1_neg [simp]:
1111   "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
1112 by (auto simp add: less_divide_eq)
1114 lemma divide_less_eq_1_pos [simp]:
1115   "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
1116 by (auto simp add: divide_less_eq)
1118 lemma divide_less_eq_1_neg [simp]:
1119   "a < 0 \<Longrightarrow> b/a < 1 \<longleftrightarrow> a < b"
1120 by (auto simp add: divide_less_eq)
1122 lemma eq_divide_eq_1 [simp]:
1123   "(1 = b/a) = ((a \<noteq> 0 & a = b))"
1124 by (auto simp add: eq_divide_eq)
1126 lemma divide_eq_eq_1 [simp]:
1127   "(b/a = 1) = ((a \<noteq> 0 & a = b))"
1128 by (auto simp add: divide_eq_eq)
1130 lemma abs_inverse [simp]:
1131      "\<bar>inverse a\<bar> =
1132       inverse \<bar>a\<bar>"
1133 apply (cases "a=0", simp)
1135 done
1137 lemma abs_divide [simp]:
1138      "\<bar>a / b\<bar> = \<bar>a\<bar> / \<bar>b\<bar>"
1139 apply (cases "b=0", simp)
1141 done
1143 lemma abs_div_pos: "0 < y ==>
1144     \<bar>x\<bar> / y = \<bar>x / y\<bar>"
1145   apply (subst abs_divide)
1147 done
1149 lemma zero_le_divide_abs_iff [simp]: "(0 \<le> a / \<bar>b\<bar>) = (0 \<le> a | b = 0)"
1150 by (auto simp: zero_le_divide_iff)
1152 lemma divide_le_0_abs_iff [simp]: "(a / \<bar>b\<bar> \<le> 0) = (a \<le> 0 | b = 0)"
1153 by (auto simp: divide_le_0_iff)
1155 lemma inverse_sgn:
1156   "sgn (inverse a) = inverse (sgn a)"
1159 lemma field_le_mult_one_interval:
1160   assumes *: "\<And>z. \<lbrakk> 0 < z ; z < 1 \<rbrakk> \<Longrightarrow> z * x \<le> y"
1161   shows "x \<le> y"
1162 proof (cases "0 < x")
1163   assume "0 < x"
1164   thus ?thesis
1165     using dense_le_bounded[of 0 1 "y/x"] *
1166     unfolding le_divide_eq if_P[OF \<open>0 < x\<close>] by simp
1167 next
1168   assume "\<not>0 < x" hence "x \<le> 0" by simp
1169   obtain s::'a where s: "0 < s" "s < 1" using dense[of 0 "1::'a"] by auto
1170   hence "x \<le> s * x" using mult_le_cancel_right[of 1 x s] \<open>x \<le> 0\<close> by auto
1171   also note *[OF s]
1172   finally show ?thesis .
1173 qed
1175 end
1177 text \<open>Min/max Simplification Rules\<close>
1179 lemma min_mult_distrib_left:
1180   fixes x::"'a::linordered_idom"
1181   shows "p * min x y = (if 0 \<le> p then min (p*x) (p*y) else max (p*x) (p*y))"
1182 by (auto simp add: min_def max_def mult_le_cancel_left)
1184 lemma min_mult_distrib_right:
1185   fixes x::"'a::linordered_idom"
1186   shows "min x y * p = (if 0 \<le> p then min (x*p) (y*p) else max (x*p) (y*p))"
1187 by (auto simp add: min_def max_def mult_le_cancel_right)
1189 lemma min_divide_distrib_right:
1190   fixes x::"'a::linordered_field"
1191   shows "min x y / p = (if 0 \<le> p then min (x/p) (y/p) else max (x/p) (y/p))"
1192 by (simp add: min_mult_distrib_right divide_inverse)
1194 lemma max_mult_distrib_left:
1195   fixes x::"'a::linordered_idom"
1196   shows "p * max x y = (if 0 \<le> p then max (p*x) (p*y) else min (p*x) (p*y))"
1197 by (auto simp add: min_def max_def mult_le_cancel_left)
1199 lemma max_mult_distrib_right:
1200   fixes x::"'a::linordered_idom"
1201   shows "max x y * p = (if 0 \<le> p then max (x*p) (y*p) else min (x*p) (y*p))"
1202 by (auto simp add: min_def max_def mult_le_cancel_right)
1204 lemma max_divide_distrib_right:
1205   fixes x::"'a::linordered_field"
1206   shows "max x y / p = (if 0 \<le> p then max (x/p) (y/p) else min (x/p) (y/p))"
1207 by (simp add: max_mult_distrib_right divide_inverse)
1209 hide_fact (open) field_inverse field_divide_inverse field_inverse_zero
1211 code_identifier
1212   code_module Fields \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith
1214 end