1 (* Title: HOL/AxClasses/Group.thy
3 Author: Markus Wenzel, TU Muenchen
4 License: GPL (GNU GENERAL PUBLIC LICENSE)
9 subsection {* Monoids and Groups *}
12 times :: "'a => 'a => 'a" (infixl "[*]" 70)
17 axclass monoid < "term"
18 assoc: "(x [*] y) [*] z = x [*] (y [*] z)"
19 left_unit: "one [*] x = x"
20 right_unit: "x [*] one = x"
22 axclass semigroup < "term"
23 assoc: "(x [*] y) [*] z = x [*] (y [*] z)"
25 axclass group < semigroup
26 left_unit: "one [*] x = x"
27 left_inverse: "invers x [*] x = one"
29 axclass agroup < group
30 commute: "x [*] y = y [*] x"
33 subsection {* Abstract reasoning *}
35 theorem group_right_inverse: "x [*] invers x = (one::'a::group)"
37 have "x [*] invers x = one [*] (x [*] invers x)"
38 by (simp only: group.left_unit)
39 also have "... = one [*] x [*] invers x"
40 by (simp only: semigroup.assoc)
41 also have "... = invers (invers x) [*] invers x [*] x [*] invers x"
42 by (simp only: group.left_inverse)
43 also have "... = invers (invers x) [*] (invers x [*] x) [*] invers x"
44 by (simp only: semigroup.assoc)
45 also have "... = invers (invers x) [*] one [*] invers x"
46 by (simp only: group.left_inverse)
47 also have "... = invers (invers x) [*] (one [*] invers x)"
48 by (simp only: semigroup.assoc)
49 also have "... = invers (invers x) [*] invers x"
50 by (simp only: group.left_unit)
52 by (simp only: group.left_inverse)
53 finally show ?thesis .
56 theorem group_right_unit: "x [*] one = (x::'a::group)"
58 have "x [*] one = x [*] (invers x [*] x)"
59 by (simp only: group.left_inverse)
60 also have "... = x [*] invers x [*] x"
61 by (simp only: semigroup.assoc)
62 also have "... = one [*] x"
63 by (simp only: group_right_inverse)
65 by (simp only: group.left_unit)
66 finally show ?thesis .
70 subsection {* Abstract instantiation *}
72 instance monoid < semigroup
74 fix x y z :: "'a::monoid"
75 show "x [*] y [*] z = x [*] (y [*] z)"
76 by (rule monoid.assoc)
79 instance group < monoid
81 fix x y z :: "'a::group"
82 show "x [*] y [*] z = x [*] (y [*] z)"
83 by (rule semigroup.assoc)
85 by (rule group.left_unit)
87 by (rule group_right_unit)
91 subsection {* Concrete instantiation *}
94 times_bool_def: "x [*] y == x ~= (y::bool)"
95 inverse_bool_def: "invers x == x::bool"
96 unit_bool_def: "one == False"
98 instance bool :: agroup
100 unfold times_bool_def inverse_bool_def unit_bool_def)
102 show "((x ~= y) ~= z) = (x ~= (y ~= z))" by blast
103 show "(False ~= x) = x" by blast
104 show "(x ~= x) = False" by blast
105 show "(x ~= y) = (y ~= x)" by blast
109 subsection {* Lifting and Functors *}
112 times_prod_def: "p [*] q == (fst p [*] fst q, snd p [*] snd q)"
114 instance * :: (semigroup, semigroup) semigroup
115 proof (intro_classes, unfold times_prod_def)
116 fix p q r :: "'a::semigroup * 'b::semigroup"
118 "(fst (fst p [*] fst q, snd p [*] snd q) [*] fst r,
119 snd (fst p [*] fst q, snd p [*] snd q) [*] snd r) =
120 (fst p [*] fst (fst q [*] fst r, snd q [*] snd r),
121 snd p [*] snd (fst q [*] fst r, snd q [*] snd r))"
122 by (simp add: semigroup.assoc)