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