9767
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
9921
|
3 |
\def\isabellecontext{Group}%
|
8903
|
4 |
%
|
10395
|
5 |
\isamarkupheader{Basic group theory%
|
|
6 |
}
|
11964
|
7 |
\isamarkuptrue%
|
|
8 |
\isacommand{theory}\ Group\ {\isacharequal}\ Main{\isacharcolon}\isamarkupfalse%
|
|
9 |
%
|
8903
|
10 |
\begin{isamarkuptext}%
|
10140
|
11 |
\medskip\noindent The meta-level type system of Isabelle supports
|
8903
|
12 |
\emph{intersections} and \emph{inclusions} of type classes. These
|
|
13 |
directly correspond to intersections and inclusions of type
|
|
14 |
predicates in a purely set theoretic sense. This is sufficient as a
|
|
15 |
means to describe simple hierarchies of structures. As an
|
|
16 |
illustration, we use the well-known example of semigroups, monoids,
|
8907
|
17 |
general groups and Abelian groups.%
|
8903
|
18 |
\end{isamarkuptext}%
|
11964
|
19 |
\isamarkuptrue%
|
8903
|
20 |
%
|
10395
|
21 |
\isamarkupsubsection{Monoids and Groups%
|
|
22 |
}
|
11964
|
23 |
\isamarkuptrue%
|
8903
|
24 |
%
|
|
25 |
\begin{isamarkuptext}%
|
|
26 |
First we declare some polymorphic constants required later for the
|
|
27 |
signature parts of our structures.%
|
|
28 |
\end{isamarkuptext}%
|
11964
|
29 |
\isamarkuptrue%
|
8890
|
30 |
\isacommand{consts}\isanewline
|
10207
|
31 |
\ \ times\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isasymodot}{\isachardoublequote}\ {\isadigit{7}}{\isadigit{0}}{\isacharparenright}\isanewline
|
11071
|
32 |
\ \ invers\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequote}\ \ \ \ {\isacharparenleft}{\isachardoublequote}{\isacharparenleft}{\isacharunderscore}{\isasyminv}{\isacharparenright}{\isachardoublequote}\ {\isacharbrackleft}{\isadigit{1}}{\isadigit{0}}{\isadigit{0}}{\isadigit{0}}{\isacharbrackright}\ {\isadigit{9}}{\isadigit{9}}{\isadigit{9}}{\isacharparenright}\isanewline
|
11964
|
33 |
\ \ one\ {\isacharcolon}{\isacharcolon}\ {\isacharprime}a\ \ \ \ {\isacharparenleft}{\isachardoublequote}{\isasymunit}{\isachardoublequote}{\isacharparenright}\isamarkupfalse%
|
|
34 |
%
|
8903
|
35 |
\begin{isamarkuptext}%
|
10140
|
36 |
\noindent Next we define class \isa{monoid} of monoids with
|
|
37 |
operations \isa{{\isasymodot}} and \isa{{\isasymunit}}. Note that multiple class
|
|
38 |
axioms are allowed for user convenience --- they simply represent the
|
|
39 |
conjunction of their respective universal closures.%
|
8903
|
40 |
\end{isamarkuptext}%
|
11964
|
41 |
\isamarkuptrue%
|
11099
|
42 |
\isacommand{axclass}\ monoid\ {\isasymsubseteq}\ {\isachardoublequote}term{\isachardoublequote}\isanewline
|
10140
|
43 |
\ \ assoc{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}x\ {\isasymodot}\ y{\isacharparenright}\ {\isasymodot}\ z\ {\isacharequal}\ x\ {\isasymodot}\ {\isacharparenleft}y\ {\isasymodot}\ z{\isacharparenright}{\isachardoublequote}\isanewline
|
|
44 |
\ \ left{\isacharunderscore}unit{\isacharcolon}\ {\isachardoublequote}{\isasymunit}\ {\isasymodot}\ x\ {\isacharequal}\ x{\isachardoublequote}\isanewline
|
11964
|
45 |
\ \ right{\isacharunderscore}unit{\isacharcolon}\ {\isachardoublequote}x\ {\isasymodot}\ {\isasymunit}\ {\isacharequal}\ x{\isachardoublequote}\isamarkupfalse%
|
|
46 |
%
|
8903
|
47 |
\begin{isamarkuptext}%
|
10140
|
48 |
\noindent So class \isa{monoid} contains exactly those types \isa{{\isasymtau}} where \isa{{\isasymodot}\ {\isasymColon}\ {\isasymtau}\ {\isasymRightarrow}\ {\isasymtau}\ {\isasymRightarrow}\ {\isasymtau}} and \isa{{\isasymunit}\ {\isasymColon}\ {\isasymtau}} are
|
|
49 |
specified appropriately, such that \isa{{\isasymodot}} is associative and
|
|
50 |
\isa{{\isasymunit}} is a left and right unit element for the \isa{{\isasymodot}}
|
|
51 |
operation.%
|
8903
|
52 |
\end{isamarkuptext}%
|
11964
|
53 |
\isamarkuptrue%
|
8903
|
54 |
%
|
|
55 |
\begin{isamarkuptext}%
|
10140
|
56 |
\medskip Independently of \isa{monoid}, we now define a linear
|
|
57 |
hierarchy of semigroups, general groups and Abelian groups. Note
|
|
58 |
that the names of class axioms are automatically qualified with each
|
|
59 |
class name, so we may re-use common names such as \isa{assoc}.%
|
8903
|
60 |
\end{isamarkuptext}%
|
11964
|
61 |
\isamarkuptrue%
|
11099
|
62 |
\isacommand{axclass}\ semigroup\ {\isasymsubseteq}\ {\isachardoublequote}term{\isachardoublequote}\isanewline
|
10140
|
63 |
\ \ assoc{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}x\ {\isasymodot}\ y{\isacharparenright}\ {\isasymodot}\ z\ {\isacharequal}\ x\ {\isasymodot}\ {\isacharparenleft}y\ {\isasymodot}\ z{\isacharparenright}{\isachardoublequote}\isanewline
|
8890
|
64 |
\isanewline
|
11964
|
65 |
\isamarkupfalse%
|
11099
|
66 |
\isacommand{axclass}\ group\ {\isasymsubseteq}\ semigroup\isanewline
|
10140
|
67 |
\ \ left{\isacharunderscore}unit{\isacharcolon}\ {\isachardoublequote}{\isasymunit}\ {\isasymodot}\ x\ {\isacharequal}\ x{\isachardoublequote}\isanewline
|
|
68 |
\ \ left{\isacharunderscore}inverse{\isacharcolon}\ {\isachardoublequote}x{\isasyminv}\ {\isasymodot}\ x\ {\isacharequal}\ {\isasymunit}{\isachardoublequote}\isanewline
|
8903
|
69 |
\isanewline
|
11964
|
70 |
\isamarkupfalse%
|
11099
|
71 |
\isacommand{axclass}\ agroup\ {\isasymsubseteq}\ group\isanewline
|
11964
|
72 |
\ \ commute{\isacharcolon}\ {\isachardoublequote}x\ {\isasymodot}\ y\ {\isacharequal}\ y\ {\isasymodot}\ x{\isachardoublequote}\isamarkupfalse%
|
|
73 |
%
|
8903
|
74 |
\begin{isamarkuptext}%
|
10140
|
75 |
\noindent Class \isa{group} inherits associativity of \isa{{\isasymodot}}
|
|
76 |
from \isa{semigroup} and adds two further group axioms. Similarly,
|
|
77 |
\isa{agroup} is defined as the subset of \isa{group} such that
|
11071
|
78 |
for all of its elements \isa{{\isasymtau}}, the operation \isa{{\isasymodot}\ {\isasymColon}\ {\isasymtau}\ {\isasymRightarrow}\ {\isasymtau}\ {\isasymRightarrow}\ {\isasymtau}} is even commutative.%
|
8903
|
79 |
\end{isamarkuptext}%
|
11964
|
80 |
\isamarkuptrue%
|
8903
|
81 |
%
|
10395
|
82 |
\isamarkupsubsection{Abstract reasoning%
|
|
83 |
}
|
11964
|
84 |
\isamarkuptrue%
|
8903
|
85 |
%
|
8890
|
86 |
\begin{isamarkuptext}%
|
8903
|
87 |
In a sense, axiomatic type classes may be viewed as \emph{abstract
|
|
88 |
theories}. Above class definitions gives rise to abstract axioms
|
10140
|
89 |
\isa{assoc}, \isa{left{\isacharunderscore}unit}, \isa{left{\isacharunderscore}inverse}, \isa{commute}, where any of these contain a type variable \isa{{\isacharprime}a\ {\isasymColon}\ c}
|
|
90 |
that is restricted to types of the corresponding class \isa{c}.
|
|
91 |
\emph{Sort constraints} like this express a logical precondition for
|
|
92 |
the whole formula. For example, \isa{assoc} states that for all
|
|
93 |
\isa{{\isasymtau}}, provided that \isa{{\isasymtau}\ {\isasymColon}\ semigroup}, the operation
|
|
94 |
\isa{{\isasymodot}\ {\isasymColon}\ {\isasymtau}\ {\isasymRightarrow}\ {\isasymtau}\ {\isasymRightarrow}\ {\isasymtau}} is associative.
|
8903
|
95 |
|
|
96 |
\medskip From a technical point of view, abstract axioms are just
|
|
97 |
ordinary Isabelle theorems, which may be used in proofs without
|
|
98 |
special treatment. Such ``abstract proofs'' usually yield new
|
|
99 |
``abstract theorems''. For example, we may now derive the following
|
8907
|
100 |
well-known laws of general groups.%
|
8890
|
101 |
\end{isamarkuptext}%
|
11964
|
102 |
\isamarkuptrue%
|
10140
|
103 |
\isacommand{theorem}\ group{\isacharunderscore}right{\isacharunderscore}inverse{\isacharcolon}\ {\isachardoublequote}x\ {\isasymodot}\ x{\isasyminv}\ {\isacharequal}\ {\isacharparenleft}{\isasymunit}{\isasymColon}{\isacharprime}a{\isasymColon}group{\isacharparenright}{\isachardoublequote}\isanewline
|
11964
|
104 |
\isamarkupfalse%
|
9665
|
105 |
\isacommand{proof}\ {\isacharminus}\isanewline
|
11964
|
106 |
\ \ \isamarkupfalse%
|
|
107 |
\isacommand{have}\ {\isachardoublequote}x\ {\isasymodot}\ x{\isasyminv}\ {\isacharequal}\ {\isasymunit}\ {\isasymodot}\ {\isacharparenleft}x\ {\isasymodot}\ x{\isasyminv}{\isacharparenright}{\isachardoublequote}\isanewline
|
|
108 |
\ \ \ \ \isamarkupfalse%
|
|
109 |
\isacommand{by}\ {\isacharparenleft}simp\ only{\isacharcolon}\ group{\isachardot}left{\isacharunderscore}unit{\isacharparenright}\isanewline
|
|
110 |
\ \ \isamarkupfalse%
|
|
111 |
\isacommand{also}\ \isamarkupfalse%
|
|
112 |
\isacommand{have}\ {\isachardoublequote}{\isachardot}{\isachardot}{\isachardot}\ {\isacharequal}\ {\isasymunit}\ {\isasymodot}\ x\ {\isasymodot}\ x{\isasyminv}{\isachardoublequote}\isanewline
|
|
113 |
\ \ \ \ \isamarkupfalse%
|
|
114 |
\isacommand{by}\ {\isacharparenleft}simp\ only{\isacharcolon}\ semigroup{\isachardot}assoc{\isacharparenright}\isanewline
|
|
115 |
\ \ \isamarkupfalse%
|
|
116 |
\isacommand{also}\ \isamarkupfalse%
|
|
117 |
\isacommand{have}\ {\isachardoublequote}{\isachardot}{\isachardot}{\isachardot}\ {\isacharequal}\ {\isacharparenleft}x{\isasyminv}{\isacharparenright}{\isasyminv}\ {\isasymodot}\ x{\isasyminv}\ {\isasymodot}\ x\ {\isasymodot}\ x{\isasyminv}{\isachardoublequote}\isanewline
|
|
118 |
\ \ \ \ \isamarkupfalse%
|
|
119 |
\isacommand{by}\ {\isacharparenleft}simp\ only{\isacharcolon}\ group{\isachardot}left{\isacharunderscore}inverse{\isacharparenright}\isanewline
|
|
120 |
\ \ \isamarkupfalse%
|
|
121 |
\isacommand{also}\ \isamarkupfalse%
|
|
122 |
\isacommand{have}\ {\isachardoublequote}{\isachardot}{\isachardot}{\isachardot}\ {\isacharequal}\ {\isacharparenleft}x{\isasyminv}{\isacharparenright}{\isasyminv}\ {\isasymodot}\ {\isacharparenleft}x{\isasyminv}\ {\isasymodot}\ x{\isacharparenright}\ {\isasymodot}\ x{\isasyminv}{\isachardoublequote}\isanewline
|
|
123 |
\ \ \ \ \isamarkupfalse%
|
|
124 |
\isacommand{by}\ {\isacharparenleft}simp\ only{\isacharcolon}\ semigroup{\isachardot}assoc{\isacharparenright}\isanewline
|
|
125 |
\ \ \isamarkupfalse%
|
|
126 |
\isacommand{also}\ \isamarkupfalse%
|
|
127 |
\isacommand{have}\ {\isachardoublequote}{\isachardot}{\isachardot}{\isachardot}\ {\isacharequal}\ {\isacharparenleft}x{\isasyminv}{\isacharparenright}{\isasyminv}\ {\isasymodot}\ {\isasymunit}\ {\isasymodot}\ x{\isasyminv}{\isachardoublequote}\isanewline
|
|
128 |
\ \ \ \ \isamarkupfalse%
|
|
129 |
\isacommand{by}\ {\isacharparenleft}simp\ only{\isacharcolon}\ group{\isachardot}left{\isacharunderscore}inverse{\isacharparenright}\isanewline
|
|
130 |
\ \ \isamarkupfalse%
|
|
131 |
\isacommand{also}\ \isamarkupfalse%
|
|
132 |
\isacommand{have}\ {\isachardoublequote}{\isachardot}{\isachardot}{\isachardot}\ {\isacharequal}\ {\isacharparenleft}x{\isasyminv}{\isacharparenright}{\isasyminv}\ {\isasymodot}\ {\isacharparenleft}{\isasymunit}\ {\isasymodot}\ x{\isasyminv}{\isacharparenright}{\isachardoublequote}\isanewline
|
|
133 |
\ \ \ \ \isamarkupfalse%
|
|
134 |
\isacommand{by}\ {\isacharparenleft}simp\ only{\isacharcolon}\ semigroup{\isachardot}assoc{\isacharparenright}\isanewline
|
|
135 |
\ \ \isamarkupfalse%
|
|
136 |
\isacommand{also}\ \isamarkupfalse%
|
|
137 |
\isacommand{have}\ {\isachardoublequote}{\isachardot}{\isachardot}{\isachardot}\ {\isacharequal}\ {\isacharparenleft}x{\isasyminv}{\isacharparenright}{\isasyminv}\ {\isasymodot}\ x{\isasyminv}{\isachardoublequote}\isanewline
|
|
138 |
\ \ \ \ \isamarkupfalse%
|
|
139 |
\isacommand{by}\ {\isacharparenleft}simp\ only{\isacharcolon}\ group{\isachardot}left{\isacharunderscore}unit{\isacharparenright}\isanewline
|
|
140 |
\ \ \isamarkupfalse%
|
|
141 |
\isacommand{also}\ \isamarkupfalse%
|
|
142 |
\isacommand{have}\ {\isachardoublequote}{\isachardot}{\isachardot}{\isachardot}\ {\isacharequal}\ {\isasymunit}{\isachardoublequote}\isanewline
|
|
143 |
\ \ \ \ \isamarkupfalse%
|
|
144 |
\isacommand{by}\ {\isacharparenleft}simp\ only{\isacharcolon}\ group{\isachardot}left{\isacharunderscore}inverse{\isacharparenright}\isanewline
|
|
145 |
\ \ \isamarkupfalse%
|
|
146 |
\isacommand{finally}\ \isamarkupfalse%
|
|
147 |
\isacommand{show}\ {\isacharquery}thesis\ \isamarkupfalse%
|
|
148 |
\isacommand{{\isachardot}}\isanewline
|
|
149 |
\isamarkupfalse%
|
|
150 |
\isacommand{qed}\isamarkupfalse%
|
|
151 |
%
|
8890
|
152 |
\begin{isamarkuptext}%
|
10140
|
153 |
\noindent With \isa{group{\isacharunderscore}right{\isacharunderscore}inverse} already available, \isa{group{\isacharunderscore}right{\isacharunderscore}unit}\label{thm:group-right-unit} is now established much
|
|
154 |
easier.%
|
8890
|
155 |
\end{isamarkuptext}%
|
11964
|
156 |
\isamarkuptrue%
|
10140
|
157 |
\isacommand{theorem}\ group{\isacharunderscore}right{\isacharunderscore}unit{\isacharcolon}\ {\isachardoublequote}x\ {\isasymodot}\ {\isasymunit}\ {\isacharequal}\ {\isacharparenleft}x{\isasymColon}{\isacharprime}a{\isasymColon}group{\isacharparenright}{\isachardoublequote}\isanewline
|
11964
|
158 |
\isamarkupfalse%
|
9665
|
159 |
\isacommand{proof}\ {\isacharminus}\isanewline
|
11964
|
160 |
\ \ \isamarkupfalse%
|
|
161 |
\isacommand{have}\ {\isachardoublequote}x\ {\isasymodot}\ {\isasymunit}\ {\isacharequal}\ x\ {\isasymodot}\ {\isacharparenleft}x{\isasyminv}\ {\isasymodot}\ x{\isacharparenright}{\isachardoublequote}\isanewline
|
|
162 |
\ \ \ \ \isamarkupfalse%
|
|
163 |
\isacommand{by}\ {\isacharparenleft}simp\ only{\isacharcolon}\ group{\isachardot}left{\isacharunderscore}inverse{\isacharparenright}\isanewline
|
|
164 |
\ \ \isamarkupfalse%
|
|
165 |
\isacommand{also}\ \isamarkupfalse%
|
|
166 |
\isacommand{have}\ {\isachardoublequote}{\isachardot}{\isachardot}{\isachardot}\ {\isacharequal}\ x\ {\isasymodot}\ x{\isasyminv}\ {\isasymodot}\ x{\isachardoublequote}\isanewline
|
|
167 |
\ \ \ \ \isamarkupfalse%
|
|
168 |
\isacommand{by}\ {\isacharparenleft}simp\ only{\isacharcolon}\ semigroup{\isachardot}assoc{\isacharparenright}\isanewline
|
|
169 |
\ \ \isamarkupfalse%
|
|
170 |
\isacommand{also}\ \isamarkupfalse%
|
|
171 |
\isacommand{have}\ {\isachardoublequote}{\isachardot}{\isachardot}{\isachardot}\ {\isacharequal}\ {\isasymunit}\ {\isasymodot}\ x{\isachardoublequote}\isanewline
|
|
172 |
\ \ \ \ \isamarkupfalse%
|
|
173 |
\isacommand{by}\ {\isacharparenleft}simp\ only{\isacharcolon}\ group{\isacharunderscore}right{\isacharunderscore}inverse{\isacharparenright}\isanewline
|
|
174 |
\ \ \isamarkupfalse%
|
|
175 |
\isacommand{also}\ \isamarkupfalse%
|
|
176 |
\isacommand{have}\ {\isachardoublequote}{\isachardot}{\isachardot}{\isachardot}\ {\isacharequal}\ x{\isachardoublequote}\isanewline
|
|
177 |
\ \ \ \ \isamarkupfalse%
|
|
178 |
\isacommand{by}\ {\isacharparenleft}simp\ only{\isacharcolon}\ group{\isachardot}left{\isacharunderscore}unit{\isacharparenright}\isanewline
|
|
179 |
\ \ \isamarkupfalse%
|
|
180 |
\isacommand{finally}\ \isamarkupfalse%
|
|
181 |
\isacommand{show}\ {\isacharquery}thesis\ \isamarkupfalse%
|
|
182 |
\isacommand{{\isachardot}}\isanewline
|
|
183 |
\isamarkupfalse%
|
|
184 |
\isacommand{qed}\isamarkupfalse%
|
|
185 |
%
|
8903
|
186 |
\begin{isamarkuptext}%
|
|
187 |
\medskip Abstract theorems may be instantiated to only those types
|
10140
|
188 |
\isa{{\isasymtau}} where the appropriate class membership \isa{{\isasymtau}\ {\isasymColon}\ c} is
|
|
189 |
known at Isabelle's type signature level. Since we have \isa{agroup\ {\isasymsubseteq}\ group\ {\isasymsubseteq}\ semigroup} by definition, all theorems of \isa{semigroup} and \isa{group} are automatically inherited by \isa{group} and \isa{agroup}.%
|
8903
|
190 |
\end{isamarkuptext}%
|
11964
|
191 |
\isamarkuptrue%
|
8903
|
192 |
%
|
10395
|
193 |
\isamarkupsubsection{Abstract instantiation%
|
|
194 |
}
|
11964
|
195 |
\isamarkuptrue%
|
8903
|
196 |
%
|
|
197 |
\begin{isamarkuptext}%
|
10140
|
198 |
From the definition, the \isa{monoid} and \isa{group} classes
|
|
199 |
have been independent. Note that for monoids, \isa{right{\isacharunderscore}unit} had
|
|
200 |
to be included as an axiom, but for groups both \isa{right{\isacharunderscore}unit}
|
|
201 |
and \isa{right{\isacharunderscore}inverse} are derivable from the other axioms. With
|
|
202 |
\isa{group{\isacharunderscore}right{\isacharunderscore}unit} derived as a theorem of group theory (see
|
|
203 |
page~\pageref{thm:group-right-unit}), we may now instantiate \isa{monoid\ {\isasymsubseteq}\ semigroup} and \isa{group\ {\isasymsubseteq}\ monoid} properly as
|
|
204 |
follows (cf.\ \figref{fig:monoid-group}).
|
8903
|
205 |
|
|
206 |
\begin{figure}[htbp]
|
|
207 |
\begin{center}
|
|
208 |
\small
|
|
209 |
\unitlength 0.6mm
|
|
210 |
\begin{picture}(65,90)(0,-10)
|
|
211 |
\put(15,10){\line(0,1){10}} \put(15,30){\line(0,1){10}}
|
|
212 |
\put(15,50){\line(1,1){10}} \put(35,60){\line(1,-1){10}}
|
10140
|
213 |
\put(15,5){\makebox(0,0){\isa{agroup}}}
|
|
214 |
\put(15,25){\makebox(0,0){\isa{group}}}
|
|
215 |
\put(15,45){\makebox(0,0){\isa{semigroup}}}
|
|
216 |
\put(30,65){\makebox(0,0){\isa{term}}} \put(50,45){\makebox(0,0){\isa{monoid}}}
|
8903
|
217 |
\end{picture}
|
|
218 |
\hspace{4em}
|
|
219 |
\begin{picture}(30,90)(0,0)
|
|
220 |
\put(15,10){\line(0,1){10}} \put(15,30){\line(0,1){10}}
|
|
221 |
\put(15,50){\line(0,1){10}} \put(15,70){\line(0,1){10}}
|
10140
|
222 |
\put(15,5){\makebox(0,0){\isa{agroup}}}
|
|
223 |
\put(15,25){\makebox(0,0){\isa{group}}}
|
|
224 |
\put(15,45){\makebox(0,0){\isa{monoid}}}
|
|
225 |
\put(15,65){\makebox(0,0){\isa{semigroup}}}
|
|
226 |
\put(15,85){\makebox(0,0){\isa{term}}}
|
8903
|
227 |
\end{picture}
|
|
228 |
\caption{Monoids and groups: according to definition, and by proof}
|
|
229 |
\label{fig:monoid-group}
|
|
230 |
\end{center}
|
8907
|
231 |
\end{figure}%
|
8903
|
232 |
\end{isamarkuptext}%
|
11964
|
233 |
\isamarkuptrue%
|
11099
|
234 |
\isacommand{instance}\ monoid\ {\isasymsubseteq}\ semigroup\isanewline
|
11964
|
235 |
\isamarkupfalse%
|
10310
|
236 |
\isacommand{proof}\isanewline
|
11964
|
237 |
\ \ \isamarkupfalse%
|
|
238 |
\isacommand{fix}\ x\ y\ z\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a{\isasymColon}monoid{\isachardoublequote}\isanewline
|
|
239 |
\ \ \isamarkupfalse%
|
|
240 |
\isacommand{show}\ {\isachardoublequote}x\ {\isasymodot}\ y\ {\isasymodot}\ z\ {\isacharequal}\ x\ {\isasymodot}\ {\isacharparenleft}y\ {\isasymodot}\ z{\isacharparenright}{\isachardoublequote}\isanewline
|
|
241 |
\ \ \ \ \isamarkupfalse%
|
|
242 |
\isacommand{by}\ {\isacharparenleft}rule\ monoid{\isachardot}assoc{\isacharparenright}\isanewline
|
|
243 |
\isamarkupfalse%
|
8890
|
244 |
\isacommand{qed}\isanewline
|
|
245 |
\isanewline
|
11964
|
246 |
\isamarkupfalse%
|
11099
|
247 |
\isacommand{instance}\ group\ {\isasymsubseteq}\ monoid\isanewline
|
11964
|
248 |
\isamarkupfalse%
|
10310
|
249 |
\isacommand{proof}\isanewline
|
11964
|
250 |
\ \ \isamarkupfalse%
|
|
251 |
\isacommand{fix}\ x\ y\ z\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a{\isasymColon}group{\isachardoublequote}\isanewline
|
|
252 |
\ \ \isamarkupfalse%
|
|
253 |
\isacommand{show}\ {\isachardoublequote}x\ {\isasymodot}\ y\ {\isasymodot}\ z\ {\isacharequal}\ x\ {\isasymodot}\ {\isacharparenleft}y\ {\isasymodot}\ z{\isacharparenright}{\isachardoublequote}\isanewline
|
|
254 |
\ \ \ \ \isamarkupfalse%
|
|
255 |
\isacommand{by}\ {\isacharparenleft}rule\ semigroup{\isachardot}assoc{\isacharparenright}\isanewline
|
|
256 |
\ \ \isamarkupfalse%
|
|
257 |
\isacommand{show}\ {\isachardoublequote}{\isasymunit}\ {\isasymodot}\ x\ {\isacharequal}\ x{\isachardoublequote}\isanewline
|
|
258 |
\ \ \ \ \isamarkupfalse%
|
|
259 |
\isacommand{by}\ {\isacharparenleft}rule\ group{\isachardot}left{\isacharunderscore}unit{\isacharparenright}\isanewline
|
|
260 |
\ \ \isamarkupfalse%
|
|
261 |
\isacommand{show}\ {\isachardoublequote}x\ {\isasymodot}\ {\isasymunit}\ {\isacharequal}\ x{\isachardoublequote}\isanewline
|
|
262 |
\ \ \ \ \isamarkupfalse%
|
|
263 |
\isacommand{by}\ {\isacharparenleft}rule\ group{\isacharunderscore}right{\isacharunderscore}unit{\isacharparenright}\isanewline
|
|
264 |
\isamarkupfalse%
|
|
265 |
\isacommand{qed}\isamarkupfalse%
|
|
266 |
%
|
8903
|
267 |
\begin{isamarkuptext}%
|
10223
|
268 |
\medskip The $\INSTANCE$ command sets up an appropriate goal that
|
|
269 |
represents the class inclusion (or type arity, see
|
10140
|
270 |
\secref{sec:inst-arity}) to be proven (see also
|
10310
|
271 |
\cite{isabelle-isar-ref}). The initial proof step causes
|
|
272 |
back-chaining of class membership statements wrt.\ the hierarchy of
|
|
273 |
any classes defined in the current theory; the effect is to reduce to
|
|
274 |
the initial statement to a number of goals that directly correspond
|
|
275 |
to any class axioms encountered on the path upwards through the class
|
|
276 |
hierarchy.%
|
8903
|
277 |
\end{isamarkuptext}%
|
11964
|
278 |
\isamarkuptrue%
|
8903
|
279 |
%
|
10395
|
280 |
\isamarkupsubsection{Concrete instantiation \label{sec:inst-arity}%
|
|
281 |
}
|
11964
|
282 |
\isamarkuptrue%
|
8903
|
283 |
%
|
|
284 |
\begin{isamarkuptext}%
|
11099
|
285 |
So far we have covered the case of the form $\INSTANCE$~\isa{c\isactrlsub {\isadigit{1}}\ {\isasymsubseteq}\ c\isactrlsub {\isadigit{2}}}, namely \emph{abstract instantiation} ---
|
10223
|
286 |
$c@1$ is more special than \isa{c\isactrlsub {\isadigit{1}}} and thus an instance
|
|
287 |
of \isa{c\isactrlsub {\isadigit{2}}}. Even more interesting for practical
|
|
288 |
applications are \emph{concrete instantiations} of axiomatic type
|
11071
|
289 |
classes. That is, certain simple schemes \isa{{\isacharparenleft}{\isasymalpha}\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlsub n{\isacharparenright}\ t\ {\isasymColon}\ c} of class membership may be established at the
|
|
290 |
logical level and then transferred to Isabelle's type signature
|
|
291 |
level.
|
8903
|
292 |
|
10140
|
293 |
\medskip As a typical example, we show that type \isa{bool} with
|
|
294 |
exclusive-or as \isa{{\isasymodot}} operation, identity as \isa{{\isasyminv}}, and
|
|
295 |
\isa{False} as \isa{{\isasymunit}} forms an Abelian group.%
|
8903
|
296 |
\end{isamarkuptext}%
|
11964
|
297 |
\isamarkuptrue%
|
9665
|
298 |
\isacommand{defs}\ {\isacharparenleft}\isakeyword{overloaded}{\isacharparenright}\isanewline
|
10140
|
299 |
\ \ times{\isacharunderscore}bool{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequote}x\ {\isasymodot}\ y\ {\isasymequiv}\ x\ {\isasymnoteq}\ {\isacharparenleft}y{\isasymColon}bool{\isacharparenright}{\isachardoublequote}\isanewline
|
9672
|
300 |
\ \ inverse{\isacharunderscore}bool{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequote}x{\isasyminv}\ {\isasymequiv}\ x{\isasymColon}bool{\isachardoublequote}\isanewline
|
11964
|
301 |
\ \ unit{\isacharunderscore}bool{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequote}{\isasymunit}\ {\isasymequiv}\ False{\isachardoublequote}\isamarkupfalse%
|
|
302 |
%
|
8903
|
303 |
\begin{isamarkuptext}%
|
|
304 |
\medskip It is important to note that above $\DEFS$ are just
|
8907
|
305 |
overloaded meta-level constant definitions, where type classes are
|
|
306 |
not yet involved at all. This form of constant definition with
|
|
307 |
overloading (and optional recursion over the syntactic structure of
|
|
308 |
simple types) are admissible as definitional extensions of plain HOL
|
|
309 |
\cite{Wenzel:1997:TPHOL}. The Haskell-style type system is not
|
|
310 |
required for overloading. Nevertheless, overloaded definitions are
|
8903
|
311 |
best applied in the context of type classes.
|
|
312 |
|
|
313 |
\medskip Since we have chosen above $\DEFS$ of the generic group
|
10140
|
314 |
operations on type \isa{bool} appropriately, the class membership
|
|
315 |
\isa{bool\ {\isasymColon}\ agroup} may be now derived as follows.%
|
8903
|
316 |
\end{isamarkuptext}%
|
11964
|
317 |
\isamarkuptrue%
|
9672
|
318 |
\isacommand{instance}\ bool\ {\isacharcolon}{\isacharcolon}\ agroup\isanewline
|
11964
|
319 |
\isamarkupfalse%
|
9672
|
320 |
\isacommand{proof}\ {\isacharparenleft}intro{\isacharunderscore}classes{\isacharcomma}\isanewline
|
9665
|
321 |
\ \ \ \ unfold\ times{\isacharunderscore}bool{\isacharunderscore}def\ inverse{\isacharunderscore}bool{\isacharunderscore}def\ unit{\isacharunderscore}bool{\isacharunderscore}def{\isacharparenright}\isanewline
|
11964
|
322 |
\ \ \isamarkupfalse%
|
|
323 |
\isacommand{fix}\ x\ y\ z\isanewline
|
|
324 |
\ \ \isamarkupfalse%
|
|
325 |
\isacommand{show}\ {\isachardoublequote}{\isacharparenleft}{\isacharparenleft}x\ {\isasymnoteq}\ y{\isacharparenright}\ {\isasymnoteq}\ z{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}x\ {\isasymnoteq}\ {\isacharparenleft}y\ {\isasymnoteq}\ z{\isacharparenright}{\isacharparenright}{\isachardoublequote}\ \isamarkupfalse%
|
|
326 |
\isacommand{by}\ blast\isanewline
|
|
327 |
\ \ \isamarkupfalse%
|
|
328 |
\isacommand{show}\ {\isachardoublequote}{\isacharparenleft}False\ {\isasymnoteq}\ x{\isacharparenright}\ {\isacharequal}\ x{\isachardoublequote}\ \isamarkupfalse%
|
|
329 |
\isacommand{by}\ blast\isanewline
|
|
330 |
\ \ \isamarkupfalse%
|
|
331 |
\isacommand{show}\ {\isachardoublequote}{\isacharparenleft}x\ {\isasymnoteq}\ x{\isacharparenright}\ {\isacharequal}\ False{\isachardoublequote}\ \isamarkupfalse%
|
|
332 |
\isacommand{by}\ blast\isanewline
|
|
333 |
\ \ \isamarkupfalse%
|
|
334 |
\isacommand{show}\ {\isachardoublequote}{\isacharparenleft}x\ {\isasymnoteq}\ y{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}y\ {\isasymnoteq}\ x{\isacharparenright}{\isachardoublequote}\ \isamarkupfalse%
|
|
335 |
\isacommand{by}\ blast\isanewline
|
|
336 |
\isamarkupfalse%
|
|
337 |
\isacommand{qed}\isamarkupfalse%
|
|
338 |
%
|
8903
|
339 |
\begin{isamarkuptext}%
|
10223
|
340 |
The result of an $\INSTANCE$ statement is both expressed as a theorem
|
|
341 |
of Isabelle's meta-logic, and as a type arity of the type signature.
|
|
342 |
The latter enables type-inference system to take care of this new
|
|
343 |
instance automatically.
|
8903
|
344 |
|
8907
|
345 |
\medskip We could now also instantiate our group theory classes to
|
10140
|
346 |
many other concrete types. For example, \isa{int\ {\isasymColon}\ agroup}
|
|
347 |
(e.g.\ by defining \isa{{\isasymodot}} as addition, \isa{{\isasyminv}} as negation
|
|
348 |
and \isa{{\isasymunit}} as zero) or \isa{list\ {\isasymColon}\ {\isacharparenleft}term{\isacharparenright}\ semigroup}
|
|
349 |
(e.g.\ if \isa{{\isasymodot}} is defined as list append). Thus, the
|
|
350 |
characteristic constants \isa{{\isasymodot}}, \isa{{\isasyminv}}, \isa{{\isasymunit}}
|
|
351 |
really become overloaded, i.e.\ have different meanings on different
|
|
352 |
types.%
|
8903
|
353 |
\end{isamarkuptext}%
|
11964
|
354 |
\isamarkuptrue%
|
8903
|
355 |
%
|
10395
|
356 |
\isamarkupsubsection{Lifting and Functors%
|
|
357 |
}
|
11964
|
358 |
\isamarkuptrue%
|
8903
|
359 |
%
|
|
360 |
\begin{isamarkuptext}%
|
|
361 |
As already mentioned above, overloading in the simply-typed HOL
|
|
362 |
systems may include recursion over the syntactic structure of types.
|
10223
|
363 |
That is, definitional equations \isa{c\isactrlsup {\isasymtau}\ {\isasymequiv}\ t} may also
|
|
364 |
contain constants of name \isa{c} on the right-hand side --- if
|
|
365 |
these have types that are structurally simpler than \isa{{\isasymtau}}.
|
8903
|
366 |
|
|
367 |
This feature enables us to \emph{lift operations}, say to Cartesian
|
|
368 |
products, direct sums or function spaces. Subsequently we lift
|
10140
|
369 |
\isa{{\isasymodot}} component-wise to binary products \isa{{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}b}.%
|
8903
|
370 |
\end{isamarkuptext}%
|
11964
|
371 |
\isamarkuptrue%
|
9665
|
372 |
\isacommand{defs}\ {\isacharparenleft}\isakeyword{overloaded}{\isacharparenright}\isanewline
|
11964
|
373 |
\ \ times{\isacharunderscore}prod{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequote}p\ {\isasymodot}\ q\ {\isasymequiv}\ {\isacharparenleft}fst\ p\ {\isasymodot}\ fst\ q{\isacharcomma}\ snd\ p\ {\isasymodot}\ snd\ q{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
|
|
374 |
%
|
8903
|
375 |
\begin{isamarkuptext}%
|
10140
|
376 |
It is very easy to see that associativity of \isa{{\isasymodot}} on \isa{{\isacharprime}a}
|
11071
|
377 |
and \isa{{\isasymodot}} on \isa{{\isacharprime}b} transfers to \isa{{\isasymodot}} on \isa{{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}b}. Hence the binary type constructor \isa{{\isasymodot}} maps semigroups to
|
10140
|
378 |
semigroups. This may be established formally as follows.%
|
8903
|
379 |
\end{isamarkuptext}%
|
11964
|
380 |
\isamarkuptrue%
|
9672
|
381 |
\isacommand{instance}\ {\isacharasterisk}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}semigroup{\isacharcomma}\ semigroup{\isacharparenright}\ semigroup\isanewline
|
11964
|
382 |
\isamarkupfalse%
|
9672
|
383 |
\isacommand{proof}\ {\isacharparenleft}intro{\isacharunderscore}classes{\isacharcomma}\ unfold\ times{\isacharunderscore}prod{\isacharunderscore}def{\isacharparenright}\isanewline
|
11964
|
384 |
\ \ \isamarkupfalse%
|
|
385 |
\isacommand{fix}\ p\ q\ r\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a{\isasymColon}semigroup\ {\isasymtimes}\ {\isacharprime}b{\isasymColon}semigroup{\isachardoublequote}\isanewline
|
|
386 |
\ \ \isamarkupfalse%
|
|
387 |
\isacommand{show}\isanewline
|
10140
|
388 |
\ \ \ \ {\isachardoublequote}{\isacharparenleft}fst\ {\isacharparenleft}fst\ p\ {\isasymodot}\ fst\ q{\isacharcomma}\ snd\ p\ {\isasymodot}\ snd\ q{\isacharparenright}\ {\isasymodot}\ fst\ r{\isacharcomma}\isanewline
|
|
389 |
\ \ \ \ \ \ snd\ {\isacharparenleft}fst\ p\ {\isasymodot}\ fst\ q{\isacharcomma}\ snd\ p\ {\isasymodot}\ snd\ q{\isacharparenright}\ {\isasymodot}\ snd\ r{\isacharparenright}\ {\isacharequal}\isanewline
|
|
390 |
\ \ \ \ \ \ \ {\isacharparenleft}fst\ p\ {\isasymodot}\ fst\ {\isacharparenleft}fst\ q\ {\isasymodot}\ fst\ r{\isacharcomma}\ snd\ q\ {\isasymodot}\ snd\ r{\isacharparenright}{\isacharcomma}\isanewline
|
|
391 |
\ \ \ \ \ \ \ \ snd\ p\ {\isasymodot}\ snd\ {\isacharparenleft}fst\ q\ {\isasymodot}\ fst\ r{\isacharcomma}\ snd\ q\ {\isasymodot}\ snd\ r{\isacharparenright}{\isacharparenright}{\isachardoublequote}\isanewline
|
11964
|
392 |
\ \ \ \ \isamarkupfalse%
|
|
393 |
\isacommand{by}\ {\isacharparenleft}simp\ add{\isacharcolon}\ semigroup{\isachardot}assoc{\isacharparenright}\isanewline
|
|
394 |
\isamarkupfalse%
|
|
395 |
\isacommand{qed}\isamarkupfalse%
|
|
396 |
%
|
8903
|
397 |
\begin{isamarkuptext}%
|
|
398 |
Thus, if we view class instances as ``structures'', then overloaded
|
8907
|
399 |
constant definitions with recursion over types indirectly provide
|
|
400 |
some kind of ``functors'' --- i.e.\ mappings between abstract
|
8903
|
401 |
theories.%
|
|
402 |
\end{isamarkuptext}%
|
11964
|
403 |
\isamarkuptrue%
|
|
404 |
\isacommand{end}\isamarkupfalse%
|
|
405 |
\end{isabellebody}%
|
9145
|
406 |
%%% Local Variables:
|
|
407 |
%%% mode: latex
|
|
408 |
%%% TeX-master: "root"
|
|
409 |
%%% End:
|