351 class ordered_semiring = semiring + comm_monoid_add + ordered_cancel_ab_semigroup_add + mult_mono |
351 class ordered_semiring = semiring + comm_monoid_add + ordered_cancel_ab_semigroup_add + mult_mono |
352 begin |
352 begin |
353 |
353 |
354 subclass pordered_cancel_semiring by unfold_locales |
354 subclass pordered_cancel_semiring by unfold_locales |
355 |
355 |
|
356 subclass pordered_comm_monoid_add by unfold_locales |
|
357 |
356 lemma mult_left_less_imp_less: |
358 lemma mult_left_less_imp_less: |
357 "c * a < c * b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b" |
359 "c * a < c * b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b" |
358 by (force simp add: mult_left_mono not_le [symmetric]) |
360 by (force simp add: mult_left_mono not_le [symmetric]) |
359 |
361 |
360 lemma mult_right_less_imp_less: |
362 lemma mult_right_less_imp_less: |
512 "(0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0) \<Longrightarrow> 0 \<le> a * b" |
514 "(0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0) \<Longrightarrow> 0 \<le> a * b" |
513 by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos) |
515 by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos) |
514 |
516 |
515 end |
517 end |
516 |
518 |
517 class lordered_ring = pordered_ring + lordered_ab_group_abs |
|
518 begin |
|
519 |
|
520 subclass lordered_ab_group_meet by unfold_locales |
|
521 subclass lordered_ab_group_join by unfold_locales |
|
522 |
|
523 end |
|
524 |
|
525 class abs_if = minus + ord + zero + abs + |
519 class abs_if = minus + ord + zero + abs + |
526 assumes abs_if: "\<bar>a\<bar> = (if a < 0 then (- a) else a)" |
520 assumes abs_if: "\<bar>a\<bar> = (if a < 0 then (- a) else a)" |
527 |
521 |
528 class sgn_if = sgn + zero + one + minus + ord + |
522 class sgn_if = sgn + zero + one + minus + ord + |
529 assumes sgn_if: "sgn x = (if x = 0 then 0 else if 0 < x then 1 else - 1)" |
523 assumes sgn_if: "sgn x = (if x = 0 then 0 else if 0 < x then 1 else - 1)" |
530 |
524 |
531 class ordered_ring = ring + ordered_semiring |
525 class ordered_ring = ring + ordered_semiring |
532 + lordered_ab_group + abs_if |
526 + ordered_ab_group_add + abs_if |
533 -- {*FIXME: should inherit from @{text ordered_ab_group_add} rather than |
527 begin |
534 @{text lordered_ab_group}*} |
528 |
535 |
529 subclass pordered_ring by unfold_locales |
536 instance ordered_ring \<subseteq> lordered_ring |
530 |
537 proof |
531 subclass pordered_ab_group_add_abs |
538 fix x :: 'a |
532 proof unfold_locales |
539 show "\<bar>x\<bar> = sup x (- x)" |
533 fix a b |
540 by (simp only: abs_if sup_eq_if) |
534 show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>" |
541 qed |
535 by (auto simp add: abs_if not_less neg_less_eq_nonneg less_eq_neg_nonpos) |
|
536 (auto simp del: minus_add_distrib simp add: minus_add_distrib [symmetric] |
|
537 neg_less_eq_nonneg less_eq_neg_nonpos, auto intro: add_nonneg_nonneg, |
|
538 auto intro!: less_imp_le add_neg_neg) |
|
539 qed (auto simp add: abs_if less_eq_neg_nonpos neg_equal_zero) |
|
540 |
|
541 end |
542 |
542 |
543 (* The "strict" suffix can be seen as describing the combination of ordered_ring and no_zero_divisors. |
543 (* The "strict" suffix can be seen as describing the combination of ordered_ring and no_zero_divisors. |
544 Basically, ordered_ring + no_zero_divisors = ordered_ring_strict. |
544 Basically, ordered_ring + no_zero_divisors = ordered_ring_strict. |
545 *) |
545 *) |
546 class ordered_ring_strict = ring + ordered_semiring_strict |
546 class ordered_ring_strict = ring + ordered_semiring_strict |
547 + lordered_ab_group + abs_if |
547 + ordered_ab_group_add + abs_if |
548 -- {*FIXME: should inherit from @{text ordered_ab_group_add} rather than |
548 begin |
549 @{text lordered_ab_group}*} |
549 |
550 |
550 subclass ordered_ring by unfold_locales |
551 instance ordered_ring_strict \<subseteq> ordered_ring by intro_classes |
|
552 |
|
553 context ordered_ring_strict |
|
554 begin |
|
555 |
551 |
556 lemma mult_strict_left_mono_neg: |
552 lemma mult_strict_left_mono_neg: |
557 "b < a \<Longrightarrow> c < 0 \<Longrightarrow> c * a < c * b" |
553 "b < a \<Longrightarrow> c < 0 \<Longrightarrow> c * a < c * b" |
558 apply (drule mult_strict_left_mono [of _ _ "uminus c"]) |
554 apply (drule mult_strict_left_mono [of _ _ "uminus c"]) |
559 apply (simp_all add: minus_mult_left [symmetric]) |
555 apply (simp_all add: minus_mult_left [symmetric]) |
568 lemma mult_neg_neg: |
564 lemma mult_neg_neg: |
569 "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> 0 < a * b" |
565 "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> 0 < a * b" |
570 by (drule mult_strict_right_mono_neg, auto) |
566 by (drule mult_strict_right_mono_neg, auto) |
571 |
567 |
572 end |
568 end |
|
569 |
|
570 instance ordered_ring_strict \<subseteq> ring_no_zero_divisors |
|
571 apply intro_classes |
|
572 apply (auto simp add: linorder_not_less order_le_less linorder_neq_iff) |
|
573 apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono)+ |
|
574 done |
573 |
575 |
574 lemma zero_less_mult_iff: |
576 lemma zero_less_mult_iff: |
575 fixes a :: "'a::ordered_ring_strict" |
577 fixes a :: "'a::ordered_ring_strict" |
576 shows "0 < a * b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0" |
578 shows "0 < a * b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0" |
577 apply (auto simp add: le_less not_less mult_pos_pos mult_neg_neg) |
579 apply (auto simp add: le_less not_less mult_pos_pos mult_neg_neg) |
578 apply (blast dest: zero_less_mult_pos) |
580 apply (blast dest: zero_less_mult_pos) |
579 apply (blast dest: zero_less_mult_pos2) |
581 apply (blast dest: zero_less_mult_pos2) |
580 done |
582 done |
581 |
583 |
582 instance ordered_ring_strict \<subseteq> ring_no_zero_divisors |
|
583 apply intro_classes |
|
584 apply (auto simp add: linorder_not_less order_le_less linorder_neq_iff) |
|
585 apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono)+ |
|
586 done |
|
587 |
|
588 lemma zero_le_mult_iff: |
584 lemma zero_le_mult_iff: |
589 "((0::'a::ordered_ring_strict) \<le> a*b) = (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)" |
585 "((0::'a::ordered_ring_strict) \<le> a*b) = (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)" |
590 by (auto simp add: eq_commute [of 0] order_le_less linorder_not_less |
586 by (auto simp add: eq_commute [of 0] order_le_less linorder_not_less |
591 zero_less_mult_iff) |
587 zero_less_mult_iff) |
592 |
588 |
649 |
645 |
650 lemma linorder_neqE_ordered_idom: |
646 lemma linorder_neqE_ordered_idom: |
651 fixes x y :: "'a :: ordered_idom" |
647 fixes x y :: "'a :: ordered_idom" |
652 assumes "x \<noteq> y" obtains "x < y" | "y < x" |
648 assumes "x \<noteq> y" obtains "x < y" | "y < x" |
653 using assms by (rule linorder_neqE) |
649 using assms by (rule linorder_neqE) |
654 |
|
655 -- {* FIXME continue localization here *} |
|
656 |
650 |
657 |
651 |
658 text{*Proving axiom @{text zero_less_one} makes all @{text ordered_semidom} |
652 text{*Proving axiom @{text zero_less_one} makes all @{text ordered_semidom} |
659 theorems available to members of @{term ordered_idom} *} |
653 theorems available to members of @{term ordered_idom} *} |
660 |
654 |
2004 qed |
1998 qed |
2005 |
1999 |
2006 |
2000 |
2007 subsection {* Absolute Value *} |
2001 subsection {* Absolute Value *} |
2008 |
2002 |
2009 lemma mult_sgn_abs: "sgn x * abs x = (x::'a::{ordered_idom,linorder})" |
2003 context ordered_idom |
2010 using less_linear[of x 0] |
2004 begin |
2011 by(auto simp: sgn_if abs_if) |
2005 |
|
2006 lemma mult_sgn_abs: "sgn x * abs x = x" |
|
2007 unfolding abs_if sgn_if by auto |
|
2008 |
|
2009 end |
2012 |
2010 |
2013 lemma abs_one [simp]: "abs 1 = (1::'a::ordered_idom)" |
2011 lemma abs_one [simp]: "abs 1 = (1::'a::ordered_idom)" |
2014 by (simp add: abs_if zero_less_one [THEN order_less_not_sym]) |
2012 by (simp add: abs_if zero_less_one [THEN order_less_not_sym]) |
|
2013 |
|
2014 class pordered_ring_abs = pordered_ring + pordered_ab_group_add_abs + |
|
2015 assumes abs_eq_mult: |
|
2016 "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0) \<Longrightarrow> \<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>" |
|
2017 |
|
2018 |
|
2019 class lordered_ring = pordered_ring + lordered_ab_group_add_abs |
|
2020 begin |
|
2021 |
|
2022 subclass lordered_ab_group_add_meet by unfold_locales |
|
2023 subclass lordered_ab_group_add_join by unfold_locales |
|
2024 |
|
2025 end |
2015 |
2026 |
2016 lemma abs_le_mult: "abs (a * b) \<le> (abs a) * (abs (b::'a::lordered_ring))" |
2027 lemma abs_le_mult: "abs (a * b) \<le> (abs a) * (abs (b::'a::lordered_ring))" |
2017 proof - |
2028 proof - |
2018 let ?x = "pprt a * pprt b - pprt a * nprt b - nprt a * pprt b + nprt a * nprt b" |
2029 let ?x = "pprt a * pprt b - pprt a * nprt b - nprt a * pprt b + nprt a * nprt b" |
2019 let ?y = "pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b" |
2030 let ?y = "pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b" |
2052 apply (simp add: i1) |
2063 apply (simp add: i1) |
2053 apply (simp add: i2[simplified minus_le_iff]) |
2064 apply (simp add: i2[simplified minus_le_iff]) |
2054 done |
2065 done |
2055 qed |
2066 qed |
2056 |
2067 |
2057 lemma abs_eq_mult: |
2068 instance lordered_ring \<subseteq> pordered_ring_abs |
2058 assumes "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0)" |
2069 proof |
2059 shows "abs (a*b) = abs a * abs (b::'a::lordered_ring)" |
2070 fix a b :: "'a\<Colon> lordered_ring" |
|
2071 assume "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0)" |
|
2072 show "abs (a*b) = abs a * abs b" |
2060 proof - |
2073 proof - |
2061 have s: "(0 <= a*b) | (a*b <= 0)" |
2074 have s: "(0 <= a*b) | (a*b <= 0)" |
2062 apply (auto) |
2075 apply (auto) |
2063 apply (rule_tac split_mult_pos_le) |
2076 apply (rule_tac split_mult_pos_le) |
2064 apply (rule_tac contrapos_np[of "a*b <= 0"]) |
2077 apply (rule_tac contrapos_np[of "a*b <= 0"]) |
2092 apply(drule (1) mult_nonneg_nonneg[of a b],simp) |
2105 apply(drule (1) mult_nonneg_nonneg[of a b],simp) |
2093 apply(drule (1) mult_nonpos_nonpos[of a b],simp) |
2106 apply(drule (1) mult_nonpos_nonpos[of a b],simp) |
2094 done |
2107 done |
2095 qed |
2108 qed |
2096 qed |
2109 qed |
|
2110 qed |
|
2111 |
|
2112 instance ordered_idom \<subseteq> pordered_ring_abs |
|
2113 by default (auto simp add: abs_if not_less |
|
2114 equal_neg_zero neg_equal_zero mult_less_0_iff) |
2097 |
2115 |
2098 lemma abs_mult: "abs (a * b) = abs a * abs (b::'a::ordered_idom)" |
2116 lemma abs_mult: "abs (a * b) = abs a * abs (b::'a::ordered_idom)" |
2099 by (simp add: abs_eq_mult linorder_linear) |
2117 by (simp add: abs_eq_mult linorder_linear) |
2100 |
2118 |
2101 lemma abs_mult_self: "abs a * abs a = a * (a::'a::ordered_idom)" |
2119 lemma abs_mult_self: "abs a * abs a = a * (a::'a::ordered_idom)" |
2102 by (simp add: abs_if) |
2120 by (simp add: abs_if) |
2103 |
2121 |
2104 lemma nonzero_abs_inverse: |
2122 lemma nonzero_abs_inverse: |
2105 "a \<noteq> 0 ==> abs (inverse (a::'a::ordered_field)) = inverse (abs a)" |
2123 "a \<noteq> 0 ==> abs (inverse (a::'a::ordered_field)) = inverse (abs a)" |
2106 apply (auto simp add: linorder_neq_iff abs_if nonzero_inverse_minus_eq |
2124 apply (auto simp add: linorder_neq_iff abs_if nonzero_inverse_minus_eq |
2107 negative_imp_inverse_negative) |
2125 negative_imp_inverse_negative) |
2132 hence cpos: "0<c" by (blast intro: order_le_less_trans abs_ge_zero) |
2150 hence cpos: "0<c" by (blast intro: order_le_less_trans abs_ge_zero) |
2133 assume "abs b < d" |
2151 assume "abs b < d" |
2134 thus ?thesis by (simp add: ac cpos mult_strict_mono) |
2152 thus ?thesis by (simp add: ac cpos mult_strict_mono) |
2135 qed |
2153 qed |
2136 |
2154 |
2137 lemma eq_minus_self_iff: "(a = -a) = (a = (0::'a::ordered_idom))" |
2155 lemmas eq_minus_self_iff = equal_neg_zero |
2138 by (force simp add: order_eq_iff le_minus_self_iff minus_le_self_iff) |
|
2139 |
2156 |
2140 lemma less_minus_self_iff: "(a < -a) = (a < (0::'a::ordered_idom))" |
2157 lemma less_minus_self_iff: "(a < -a) = (a < (0::'a::ordered_idom))" |
2141 by (simp add: order_less_le le_minus_self_iff eq_minus_self_iff) |
2158 unfolding order_less_le less_eq_neg_nonpos equal_neg_zero .. |
2142 |
2159 |
2143 lemma abs_less_iff: "(abs a < b) = (a < b & -a < (b::'a::ordered_idom))" |
2160 lemma abs_less_iff: "(abs a < b) = (a < b & -a < (b::'a::ordered_idom))" |
2144 apply (simp add: order_less_le abs_le_iff) |
2161 apply (simp add: order_less_le abs_le_iff) |
2145 apply (auto simp add: abs_if minus_le_self_iff eq_minus_self_iff) |
2162 apply (auto simp add: abs_if neg_less_eq_nonneg less_eq_neg_nonpos) |
2146 apply (simp add: le_minus_self_iff linorder_neq_iff) |
|
2147 done |
2163 done |
2148 |
2164 |
2149 lemma abs_mult_pos: "(0::'a::ordered_idom) <= x ==> |
2165 lemma abs_mult_pos: "(0::'a::ordered_idom) <= x ==> |
2150 (abs y) * x = abs (y * x)"; |
2166 (abs y) * x = abs (y * x)" |
2151 apply (subst abs_mult); |
2167 apply (subst abs_mult) |
2152 apply simp; |
2168 apply simp |
2153 done; |
2169 done |
2154 |
2170 |
2155 lemma abs_div_pos: "(0::'a::{division_by_zero,ordered_field}) < y ==> |
2171 lemma abs_div_pos: "(0::'a::{division_by_zero,ordered_field}) < y ==> |
2156 abs x / y = abs (x / y)"; |
2172 abs x / y = abs (x / y)" |
2157 apply (subst abs_divide); |
2173 apply (subst abs_divide) |
2158 apply (simp add: order_less_imp_le); |
2174 apply (simp add: order_less_imp_le) |
2159 done; |
2175 done |
2160 |
2176 |
2161 |
2177 |
2162 subsection {* Bounds of products via negative and positive Part *} |
2178 subsection {* Bounds of products via negative and positive Part *} |
2163 |
2179 |
2164 lemma mult_le_prts: |
2180 lemma mult_le_prts: |