10 section \<open>Rings\<close> |
10 section \<open>Rings\<close> |
11 |
11 |
12 theory Rings |
12 theory Rings |
13 imports Groups Set Fun |
13 imports Groups Set Fun |
14 begin |
14 begin |
|
15 |
|
16 subsection \<open>Semirings and rings\<close> |
15 |
17 |
16 class semiring = ab_semigroup_add + semigroup_mult + |
18 class semiring = ab_semigroup_add + semigroup_mult + |
17 assumes distrib_right[algebra_simps]: "(a + b) * c = a * c + b * c" |
19 assumes distrib_right[algebra_simps]: "(a + b) * c = a * c + b * c" |
18 assumes distrib_left[algebra_simps]: "a * (b + c) = a * b + a * c" |
20 assumes distrib_left[algebra_simps]: "a * (b + c) = a * b + a * c" |
19 begin |
21 begin |
401 lemma dvd_diff [simp]: "x dvd y \<Longrightarrow> x dvd z \<Longrightarrow> x dvd (y - z)" |
404 lemma dvd_diff [simp]: "x dvd y \<Longrightarrow> x dvd z \<Longrightarrow> x dvd (y - z)" |
402 using dvd_add [of x y "- z"] by simp |
405 using dvd_add [of x y "- z"] by simp |
403 |
406 |
404 end |
407 end |
405 |
408 |
|
409 |
|
410 subsection \<open>Towards integral domains\<close> |
|
411 |
406 class semiring_no_zero_divisors = semiring_0 + |
412 class semiring_no_zero_divisors = semiring_0 + |
407 assumes no_zero_divisors: "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a * b \<noteq> 0" |
413 assumes no_zero_divisors: "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a * b \<noteq> 0" |
408 begin |
414 begin |
409 |
415 |
410 lemma divisors_zero: |
416 lemma divisors_zero: |
631 by simp |
637 by simp |
632 qed |
638 qed |
633 |
639 |
634 end |
640 end |
635 |
641 |
636 text \<open> |
642 |
637 The theory of partially ordered rings is taken from the books: |
643 subsection \<open>(Partial) Division\<close> |
638 \<^item> \<^emph>\<open>Lattice Theory\<close> by Garret Birkhoff, American Mathematical Society, 1979 |
|
639 \<^item> \<^emph>\<open>Partially Ordered Algebraic Systems\<close>, Pergamon Press, 1963 |
|
640 |
|
641 Most of the used notions can also be looked up in |
|
642 \<^item> \<^url>\<open>http://www.mathworld.com\<close> by Eric Weisstein et. al. |
|
643 \<^item> \<^emph>\<open>Algebra I\<close> by van der Waerden, Springer |
|
644 \<close> |
|
645 |
|
646 text \<open>Syntactic division operator\<close> |
|
647 |
644 |
648 class divide = |
645 class divide = |
649 fixes divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "div" 70) |
646 fixes divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "div" 70) |
650 |
647 |
651 setup \<open>Sign.add_const_constraint (\<^const_name>\<open>divide\<close>, SOME \<^typ>\<open>'a \<Rightarrow> 'a \<Rightarrow> 'a\<close>)\<close> |
648 setup \<open>Sign.add_const_constraint (\<^const_name>\<open>divide\<close>, SOME \<^typ>\<open>'a \<Rightarrow> 'a \<Rightarrow> 'a\<close>)\<close> |
785 by simp |
782 by simp |
786 qed |
783 qed |
787 |
784 |
788 end |
785 end |
789 |
786 |
|
787 text \<open>Integral (semi)domains with cancellation rules\<close> |
|
788 |
|
789 class semidom_divide_cancel = semidom_divide + |
|
790 assumes div_mult_self1: "b \<noteq> 0 \<Longrightarrow> (a + c * b) div b = c + a div b" |
|
791 and div_mult_mult1: "c \<noteq> 0 \<Longrightarrow> (c * a) div (c * b) = a div b" |
|
792 begin |
|
793 |
|
794 context |
|
795 fixes b |
|
796 assumes "b \<noteq> 0" |
|
797 begin |
|
798 |
|
799 lemma div_mult_self2: |
|
800 "(a + b * c) div b = c + a div b" |
|
801 using \<open>b \<noteq> 0\<close> div_mult_self1 [of b a c] by (simp add: ac_simps) |
|
802 |
|
803 lemma div_mult_self3: |
|
804 "(c * b + a) div b = c + a div b" |
|
805 using \<open>b \<noteq> 0\<close> div_mult_self1 [of b a c] by (simp add: ac_simps) |
|
806 |
|
807 lemma div_mult_self4: |
|
808 "(b * c + a) div b = c + a div b" |
|
809 using \<open>b \<noteq> 0\<close> div_mult_self1 [of b a c] by (simp add: ac_simps) |
|
810 |
|
811 lemma div_add_self1: |
|
812 "(b + a) div b = a div b + 1" |
|
813 using \<open>b \<noteq> 0\<close> div_mult_self1 [of b a 1] by (simp add: ac_simps) |
|
814 |
|
815 lemma div_add_self2: |
|
816 "(a + b) div b = a div b + 1" |
|
817 using \<open>b \<noteq> 0\<close> div_add_self1 [of a] by (simp add: ac_simps) |
|
818 |
|
819 end |
|
820 |
|
821 lemma div_mult_mult2: |
|
822 "(a * c) div (b * c) = a div b" if "c \<noteq> 0" |
|
823 using that div_mult_mult1 [of c a b] by (simp add: ac_simps) |
|
824 |
|
825 lemma div_mult_mult1_if [simp]: |
|
826 "(c * a) div (c * b) = (if c = 0 then 0 else a div b)" |
|
827 by (simp add: div_mult_mult1) |
|
828 |
|
829 lemma div_mult_mult2_if [simp]: |
|
830 "(a * c) div (b * c) = (if c = 0 then 0 else a div b)" |
|
831 using div_mult_mult1_if [of c a b] by (simp add: ac_simps) |
|
832 |
|
833 end |
|
834 |
|
835 class idom_divide_cancel = idom_divide + semidom_divide_cancel |
|
836 begin |
|
837 |
|
838 lemma div_minus_minus [simp]: "(- a) div (- b) = a div b" |
|
839 using div_mult_mult1 [of "- 1" a b] by simp |
|
840 |
|
841 lemma div_minus_right: "a div (- b) = (- a) div b" |
|
842 using div_minus_minus [of "- a" b] by simp |
|
843 |
|
844 lemma div_minus1_right [simp]: "a div (- 1) = - a" |
|
845 using div_minus_right [of a 1] by simp |
|
846 |
|
847 end |
|
848 |
|
849 |
|
850 subsection \<open>Basic notions following from divisibility\<close> |
|
851 |
790 class algebraic_semidom = semidom_divide |
852 class algebraic_semidom = semidom_divide |
791 begin |
853 begin |
792 |
854 |
793 text \<open> |
855 text \<open> |
794 Class \<^class>\<open>algebraic_semidom\<close> enriches a integral domain |
856 Class \<^class>\<open>algebraic_semidom\<close> enriches a integral domain |
1697 by (fact minus_div_mult_eq_mod [symmetric]) |
1759 by (fact minus_div_mult_eq_mod [symmetric]) |
1698 |
1760 |
1699 end |
1761 end |
1700 |
1762 |
1701 |
1763 |
1702 text \<open>Integral (semi)domains with cancellation rules\<close> |
1764 subsection \<open>Quotient and remainder in integral domains\<close> |
1703 |
|
1704 class semidom_divide_cancel = semidom_divide + |
|
1705 assumes div_mult_self1: "b \<noteq> 0 \<Longrightarrow> (a + c * b) div b = c + a div b" |
|
1706 and div_mult_mult1: "c \<noteq> 0 \<Longrightarrow> (c * a) div (c * b) = a div b" |
|
1707 begin |
|
1708 |
|
1709 context |
|
1710 fixes b |
|
1711 assumes "b \<noteq> 0" |
|
1712 begin |
|
1713 |
|
1714 lemma div_mult_self2: |
|
1715 "(a + b * c) div b = c + a div b" |
|
1716 using \<open>b \<noteq> 0\<close> div_mult_self1 [of b a c] by (simp add: ac_simps) |
|
1717 |
|
1718 lemma div_mult_self3: |
|
1719 "(c * b + a) div b = c + a div b" |
|
1720 using \<open>b \<noteq> 0\<close> div_mult_self1 [of b a c] by (simp add: ac_simps) |
|
1721 |
|
1722 lemma div_mult_self4: |
|
1723 "(b * c + a) div b = c + a div b" |
|
1724 using \<open>b \<noteq> 0\<close> div_mult_self1 [of b a c] by (simp add: ac_simps) |
|
1725 |
|
1726 lemma div_add_self1: |
|
1727 "(b + a) div b = a div b + 1" |
|
1728 using \<open>b \<noteq> 0\<close> div_mult_self1 [of b a 1] by (simp add: ac_simps) |
|
1729 |
|
1730 lemma div_add_self2: |
|
1731 "(a + b) div b = a div b + 1" |
|
1732 using \<open>b \<noteq> 0\<close> div_add_self1 [of a] by (simp add: ac_simps) |
|
1733 |
|
1734 end |
|
1735 |
|
1736 lemma div_mult_mult2: |
|
1737 "(a * c) div (b * c) = a div b" if "c \<noteq> 0" |
|
1738 using that div_mult_mult1 [of c a b] by (simp add: ac_simps) |
|
1739 |
|
1740 lemma div_mult_mult1_if [simp]: |
|
1741 "(c * a) div (c * b) = (if c = 0 then 0 else a div b)" |
|
1742 by (simp add: div_mult_mult1) |
|
1743 |
|
1744 lemma div_mult_mult2_if [simp]: |
|
1745 "(a * c) div (b * c) = (if c = 0 then 0 else a div b)" |
|
1746 using div_mult_mult1_if [of c a b] by (simp add: ac_simps) |
|
1747 |
|
1748 end |
|
1749 |
|
1750 class idom_divide_cancel = idom_divide + semidom_divide_cancel |
|
1751 begin |
|
1752 |
|
1753 lemma div_minus_minus [simp]: "(- a) div (- b) = a div b" |
|
1754 using div_mult_mult1 [of "- 1" a b] by simp |
|
1755 |
|
1756 lemma div_minus_right: "a div (- b) = (- a) div b" |
|
1757 using div_minus_minus [of "- a" b] by simp |
|
1758 |
|
1759 lemma div_minus1_right [simp]: "a div (- 1) = - a" |
|
1760 using div_minus_right [of a 1] by simp |
|
1761 |
|
1762 end |
|
1763 |
|
1764 |
|
1765 text \<open>Quotient and remainder in integral domains\<close> |
|
1766 |
1765 |
1767 class semidom_modulo = algebraic_semidom + semiring_modulo |
1766 class semidom_modulo = algebraic_semidom + semiring_modulo |
1768 begin |
1767 begin |
1769 |
1768 |
1770 lemma mod_0 [simp]: "0 mod a = 0" |
1769 lemma mod_0 [simp]: "0 mod a = 0" |
1831 "(b * (a div b) + a mod b) + c = a + c" |
1830 "(b * (a div b) + a mod b) + c = a + c" |
1832 by (simp_all add: div_mult_mod_eq mult_div_mod_eq) |
1831 by (simp_all add: div_mult_mod_eq mult_div_mod_eq) |
1833 |
1832 |
1834 end |
1833 end |
1835 |
1834 |
1836 text \<open>Interlude: basic tool support for algebraic and arithmetic calculations\<close> |
1835 class idom_modulo = idom + semidom_modulo |
|
1836 begin |
|
1837 |
|
1838 subclass idom_divide .. |
|
1839 |
|
1840 lemma div_diff [simp]: |
|
1841 "c dvd a \<Longrightarrow> c dvd b \<Longrightarrow> (a - b) div c = a div c - b div c" |
|
1842 using div_add [of _ _ "- b"] by (simp add: dvd_neg_div) |
|
1843 |
|
1844 end |
|
1845 |
|
1846 |
|
1847 subsection \<open>Interlude: basic tool support for algebraic and arithmetic calculations\<close> |
1837 |
1848 |
1838 named_theorems arith "arith facts -- only ground formulas" |
1849 named_theorems arith "arith facts -- only ground formulas" |
1839 ML_file \<open>Tools/arith_data.ML\<close> |
1850 ML_file \<open>Tools/arith_data.ML\<close> |
1840 |
1851 |
1841 ML_file \<open>~~/src/Provers/Arith/cancel_div_mod.ML\<close> |
1852 ML_file \<open>~~/src/Provers/Arith/cancel_div_mod.ML\<close> |
1857 \<close> |
1868 \<close> |
1858 |
1869 |
1859 simproc_setup cancel_div_mod_int ("(a::'a::semidom_modulo) + b") = |
1870 simproc_setup cancel_div_mod_int ("(a::'a::semidom_modulo) + b") = |
1860 \<open>K Cancel_Div_Mod_Ring.proc\<close> |
1871 \<open>K Cancel_Div_Mod_Ring.proc\<close> |
1861 |
1872 |
1862 class idom_modulo = idom + semidom_modulo |
1873 |
1863 begin |
1874 subsection \<open>Ordered semirings and rings\<close> |
1864 |
1875 |
1865 subclass idom_divide .. |
1876 text \<open> |
1866 |
1877 The theory of partially ordered rings is taken from the books: |
1867 lemma div_diff [simp]: |
1878 \<^item> \<^emph>\<open>Lattice Theory\<close> by Garret Birkhoff, American Mathematical Society, 1979 |
1868 "c dvd a \<Longrightarrow> c dvd b \<Longrightarrow> (a - b) div c = a div c - b div c" |
1879 \<^item> \<^emph>\<open>Partially Ordered Algebraic Systems\<close>, Pergamon Press, 1963 |
1869 using div_add [of _ _ "- b"] by (simp add: dvd_neg_div) |
1880 |
1870 |
1881 Most of the used notions can also be looked up in |
1871 end |
1882 \<^item> \<^url>\<open>http://www.mathworld.com\<close> by Eric Weisstein et. al. |
1872 |
1883 \<^item> \<^emph>\<open>Algebra I\<close> by van der Waerden, Springer |
|
1884 \<close> |
1873 |
1885 |
1874 class ordered_semiring = semiring + ordered_comm_monoid_add + |
1886 class ordered_semiring = semiring + ordered_comm_monoid_add + |
1875 assumes mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b" |
1887 assumes mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b" |
1876 assumes mult_right_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c" |
1888 assumes mult_right_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c" |
1877 begin |
1889 begin |
2667 lemma abs_add_one_gt_zero: "0 < 1 + \<bar>x\<bar>" |
2679 lemma abs_add_one_gt_zero: "0 < 1 + \<bar>x\<bar>" |
2668 by (auto simp: abs_if not_less intro: zero_less_one add_strict_increasing less_trans) |
2680 by (auto simp: abs_if not_less intro: zero_less_one add_strict_increasing less_trans) |
2669 |
2681 |
2670 end |
2682 end |
2671 |
2683 |
|
2684 |
2672 subsection \<open>Dioids\<close> |
2685 subsection \<open>Dioids\<close> |
2673 |
2686 |
2674 text \<open> |
2687 text \<open> |
2675 Dioids are the alternative extensions of semirings, a semiring can |
2688 Dioids are the alternative extensions of semirings, a semiring can |
2676 either be a ring or a dioid but never both. |
2689 either be a ring or a dioid but never both. |