10328
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{Axioms}%
|
17056
|
4 |
%
|
|
5 |
\isadelimtheory
|
|
6 |
%
|
|
7 |
\endisadelimtheory
|
|
8 |
%
|
|
9 |
\isatagtheory
|
|
10 |
%
|
|
11 |
\endisatagtheory
|
|
12 |
{\isafoldtheory}%
|
|
13 |
%
|
|
14 |
\isadelimtheory
|
|
15 |
%
|
|
16 |
\endisadelimtheory
|
10328
|
17 |
%
|
10397
|
18 |
\isamarkupsubsection{Axioms%
|
|
19 |
}
|
11866
|
20 |
\isamarkuptrue%
|
10328
|
21 |
%
|
|
22 |
\begin{isamarkuptext}%
|
31678
|
23 |
Attaching axioms to our classes lets us reason on the level of
|
|
24 |
classes. The results will be applicable to all types in a class, just
|
|
25 |
as in axiomatic mathematics.
|
|
26 |
|
|
27 |
\begin{warn}
|
|
28 |
Proofs in this section use structured \emph{Isar} proofs, which are not
|
|
29 |
covered in this tutorial; but see \cite{Nipkow-TYPES02}.%
|
|
30 |
\end{warn}%
|
10328
|
31 |
\end{isamarkuptext}%
|
11866
|
32 |
\isamarkuptrue%
|
10328
|
33 |
%
|
31678
|
34 |
\isamarkupsubsubsection{Semigroups%
|
10397
|
35 |
}
|
11866
|
36 |
\isamarkuptrue%
|
10328
|
37 |
%
|
|
38 |
\begin{isamarkuptext}%
|
31682
|
39 |
We specify \emph{semigroups} as subclass of \isa{plus}:%
|
10328
|
40 |
\end{isamarkuptext}%
|
17175
|
41 |
\isamarkuptrue%
|
31678
|
42 |
\isacommand{class}\isamarkupfalse%
|
|
43 |
\ semigroup\ {\isacharequal}\ plus\ {\isacharplus}\isanewline
|
|
44 |
\ \ \isakeyword{assumes}\ assoc{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}x\ {\isasymoplus}\ y{\isacharparenright}\ {\isasymoplus}\ z\ {\isacharequal}\ x\ {\isasymoplus}\ {\isacharparenleft}y\ {\isasymoplus}\ z{\isacharparenright}{\isachardoublequoteclose}%
|
10328
|
45 |
\begin{isamarkuptext}%
|
31678
|
46 |
\noindent This \hyperlink{command.class}{\mbox{\isa{\isacommand{class}}}} specification requires that
|
|
47 |
all instances of \isa{semigroup} obey \hyperlink{fact.assoc:}{\mbox{\isa{assoc{\isacharcolon}}}}~\isa{{\isachardoublequote}{\isasymAnd}x\ y\ z\ {\isasymColon}\ {\isacharprime}a{\isasymColon}semigroup{\isachardot}\ {\isacharparenleft}x\ {\isasymoplus}\ y{\isacharparenright}\ {\isasymoplus}\ z\ {\isacharequal}\ x\ {\isasymoplus}\ {\isacharparenleft}y\ {\isasymoplus}\ z{\isacharparenright}{\isachardoublequote}}.
|
10328
|
48 |
|
31678
|
49 |
We can use this class axiom to derive further abstract theorems
|
|
50 |
relative to class \isa{semigroup}:%
|
10328
|
51 |
\end{isamarkuptext}%
|
17175
|
52 |
\isamarkuptrue%
|
|
53 |
\isacommand{lemma}\isamarkupfalse%
|
31678
|
54 |
\ assoc{\isacharunderscore}left{\isacharcolon}\isanewline
|
|
55 |
\ \ \isakeyword{fixes}\ x\ y\ z\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a{\isasymColon}semigroup{\isachardoublequoteclose}\isanewline
|
|
56 |
\ \ \isakeyword{shows}\ {\isachardoublequoteopen}x\ {\isasymoplus}\ {\isacharparenleft}y\ {\isasymoplus}\ z{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}x\ {\isasymoplus}\ y{\isacharparenright}\ {\isasymoplus}\ z{\isachardoublequoteclose}\isanewline
|
|
57 |
%
|
17056
|
58 |
\isadelimproof
|
31678
|
59 |
\ \ %
|
17056
|
60 |
\endisadelimproof
|
|
61 |
%
|
|
62 |
\isatagproof
|
31678
|
63 |
\isacommand{using}\isamarkupfalse%
|
|
64 |
\ assoc\ \isacommand{by}\isamarkupfalse%
|
|
65 |
\ {\isacharparenleft}rule\ sym{\isacharparenright}%
|
17056
|
66 |
\endisatagproof
|
|
67 |
{\isafoldproof}%
|
|
68 |
%
|
|
69 |
\isadelimproof
|
|
70 |
%
|
|
71 |
\endisadelimproof
|
11866
|
72 |
%
|
10328
|
73 |
\begin{isamarkuptext}%
|
31678
|
74 |
\noindent The \isa{semigroup} constraint on type \isa{{\isacharprime}a} restricts instantiations of \isa{{\isacharprime}a} to types of class
|
|
75 |
\isa{semigroup} and during the proof enables us to use the fact
|
|
76 |
\hyperlink{fact.assoc}{\mbox{\isa{assoc}}} whose type parameter is itself constrained to class
|
31682
|
77 |
\isa{semigroup}. The main advantage of classes is that theorems
|
|
78 |
can be proved in the abstract and freely reused for each instance.
|
31678
|
79 |
|
|
80 |
On instantiation, we have to give a proof that the given operations
|
|
81 |
obey the class axioms:%
|
10328
|
82 |
\end{isamarkuptext}%
|
17175
|
83 |
\isamarkuptrue%
|
31678
|
84 |
\isacommand{instantiation}\isamarkupfalse%
|
|
85 |
\ nat\ {\isacharcolon}{\isacharcolon}\ semigroup\isanewline
|
|
86 |
\isakeyword{begin}\isanewline
|
|
87 |
\isanewline
|
17175
|
88 |
\isacommand{instance}\isamarkupfalse%
|
31678
|
89 |
%
|
|
90 |
\isadelimproof
|
|
91 |
\ %
|
|
92 |
\endisadelimproof
|
|
93 |
%
|
|
94 |
\isatagproof
|
|
95 |
\isacommand{proof}\isamarkupfalse%
|
|
96 |
%
|
|
97 |
\begin{isamarkuptxt}%
|
|
98 |
\noindent The proof opens with a default proof step, which for
|
|
99 |
instance judgements invokes method \hyperlink{method.intro-classes}{\mbox{\isa{intro{\isacharunderscore}classes}}}.%
|
|
100 |
\end{isamarkuptxt}%
|
|
101 |
\isamarkuptrue%
|
|
102 |
\ \ \isacommand{fix}\isamarkupfalse%
|
|
103 |
\ m\ n\ q\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
|
|
104 |
\ \ \isacommand{show}\isamarkupfalse%
|
|
105 |
\ {\isachardoublequoteopen}{\isacharparenleft}m\ {\isasymoplus}\ n{\isacharparenright}\ {\isasymoplus}\ q\ {\isacharequal}\ m\ {\isasymoplus}\ {\isacharparenleft}n\ {\isasymoplus}\ q{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
|
106 |
\ \ \ \ \isacommand{by}\isamarkupfalse%
|
|
107 |
\ {\isacharparenleft}induct\ m{\isacharparenright}\ simp{\isacharunderscore}all\isanewline
|
|
108 |
\isacommand{qed}\isamarkupfalse%
|
|
109 |
%
|
|
110 |
\endisatagproof
|
|
111 |
{\isafoldproof}%
|
17056
|
112 |
%
|
|
113 |
\isadelimproof
|
|
114 |
%
|
|
115 |
\endisadelimproof
|
31678
|
116 |
\isanewline
|
|
117 |
\isanewline
|
|
118 |
\isacommand{end}\isamarkupfalse%
|
|
119 |
%
|
|
120 |
\begin{isamarkuptext}%
|
|
121 |
\noindent Again, the interesting things enter the stage with
|
|
122 |
parametric types:%
|
|
123 |
\end{isamarkuptext}%
|
|
124 |
\isamarkuptrue%
|
|
125 |
\isacommand{instantiation}\isamarkupfalse%
|
38325
|
126 |
\ prod\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}semigroup{\isacharcomma}\ semigroup{\isacharparenright}\ semigroup\isanewline
|
31678
|
127 |
\isakeyword{begin}\isanewline
|
|
128 |
\isanewline
|
|
129 |
\isacommand{instance}\isamarkupfalse%
|
|
130 |
%
|
|
131 |
\isadelimproof
|
|
132 |
\ %
|
|
133 |
\endisadelimproof
|
17056
|
134 |
%
|
|
135 |
\isatagproof
|
31678
|
136 |
\isacommand{proof}\isamarkupfalse%
|
|
137 |
\isanewline
|
|
138 |
\ \ \isacommand{fix}\isamarkupfalse%
|
|
139 |
\ p\isactrlisub {\isadigit{1}}\ p\isactrlisub {\isadigit{2}}\ p\isactrlisub {\isadigit{3}}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a{\isasymColon}semigroup\ {\isasymtimes}\ {\isacharprime}b{\isasymColon}semigroup{\isachardoublequoteclose}\isanewline
|
|
140 |
\ \ \isacommand{show}\isamarkupfalse%
|
|
141 |
\ {\isachardoublequoteopen}p\isactrlisub {\isadigit{1}}\ {\isasymoplus}\ p\isactrlisub {\isadigit{2}}\ {\isasymoplus}\ p\isactrlisub {\isadigit{3}}\ {\isacharequal}\ p\isactrlisub {\isadigit{1}}\ {\isasymoplus}\ {\isacharparenleft}p\isactrlisub {\isadigit{2}}\ {\isasymoplus}\ p\isactrlisub {\isadigit{3}}{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
|
142 |
\ \ \ \ \isacommand{by}\isamarkupfalse%
|
|
143 |
\ {\isacharparenleft}cases\ p\isactrlisub {\isadigit{1}}{\isacharcomma}\ cases\ p\isactrlisub {\isadigit{2}}{\isacharcomma}\ cases\ p\isactrlisub {\isadigit{3}}{\isacharparenright}\ {\isacharparenleft}simp\ add{\isacharcolon}\ assoc{\isacharparenright}%
|
16353
|
144 |
\begin{isamarkuptxt}%
|
31678
|
145 |
\noindent Associativity of product semigroups is established
|
|
146 |
using the hypothetical associativity \hyperlink{fact.assoc}{\mbox{\isa{assoc}}} of the type
|
|
147 |
components, which holds due to the \isa{semigroup} constraints
|
|
148 |
imposed on the type components by the \hyperlink{command.instance}{\mbox{\isa{\isacommand{instance}}}} proposition.
|
|
149 |
Indeed, this pattern often occurs with parametric types and type
|
|
150 |
classes.%
|
16353
|
151 |
\end{isamarkuptxt}%
|
17175
|
152 |
\isamarkuptrue%
|
31678
|
153 |
\isacommand{qed}\isamarkupfalse%
|
|
154 |
%
|
17056
|
155 |
\endisatagproof
|
|
156 |
{\isafoldproof}%
|
|
157 |
%
|
|
158 |
\isadelimproof
|
|
159 |
%
|
|
160 |
\endisadelimproof
|
31678
|
161 |
\isanewline
|
|
162 |
\isanewline
|
|
163 |
\isacommand{end}\isamarkupfalse%
|
|
164 |
%
|
|
165 |
\isamarkupsubsubsection{Monoids%
|
|
166 |
}
|
|
167 |
\isamarkuptrue%
|
11866
|
168 |
%
|
10328
|
169 |
\begin{isamarkuptext}%
|
31678
|
170 |
We define a subclass \isa{monoidl} (a semigroup with a
|
|
171 |
left-hand neutral) by extending \isa{semigroup} with one additional
|
|
172 |
parameter \isa{neutral} together with its property:%
|
10328
|
173 |
\end{isamarkuptext}%
|
17175
|
174 |
\isamarkuptrue%
|
31678
|
175 |
\isacommand{class}\isamarkupfalse%
|
|
176 |
\ monoidl\ {\isacharequal}\ semigroup\ {\isacharplus}\isanewline
|
|
177 |
\ \ \isakeyword{fixes}\ neutral\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a{\isachardoublequoteclose}\ {\isacharparenleft}{\isachardoublequoteopen}{\isasymzero}{\isachardoublequoteclose}{\isacharparenright}\isanewline
|
|
178 |
\ \ \isakeyword{assumes}\ neutl{\isacharcolon}\ {\isachardoublequoteopen}{\isasymzero}\ {\isasymoplus}\ x\ {\isacharequal}\ x{\isachardoublequoteclose}%
|
|
179 |
\begin{isamarkuptext}%
|
|
180 |
\noindent Again, we prove some instances, by providing
|
|
181 |
suitable parameter definitions and proofs for the additional
|
|
182 |
specifications.%
|
|
183 |
\end{isamarkuptext}%
|
|
184 |
\isamarkuptrue%
|
|
185 |
\isacommand{instantiation}\isamarkupfalse%
|
|
186 |
\ nat\ {\isacharcolon}{\isacharcolon}\ monoidl\isanewline
|
|
187 |
\isakeyword{begin}\isanewline
|
|
188 |
\isanewline
|
|
189 |
\isacommand{definition}\isamarkupfalse%
|
|
190 |
\isanewline
|
|
191 |
\ \ neutral{\isacharunderscore}nat{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymzero}\ {\isacharequal}\ {\isacharparenleft}{\isadigit{0}}{\isasymColon}nat{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
|
192 |
\isanewline
|
|
193 |
\isacommand{instance}\isamarkupfalse%
|
17056
|
194 |
%
|
|
195 |
\isadelimproof
|
31678
|
196 |
\ %
|
17056
|
197 |
\endisadelimproof
|
|
198 |
%
|
|
199 |
\isatagproof
|
31678
|
200 |
\isacommand{proof}\isamarkupfalse%
|
|
201 |
\isanewline
|
|
202 |
\ \ \isacommand{fix}\isamarkupfalse%
|
|
203 |
\ n\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
|
|
204 |
\ \ \isacommand{show}\isamarkupfalse%
|
|
205 |
\ {\isachardoublequoteopen}{\isasymzero}\ {\isasymoplus}\ n\ {\isacharequal}\ n{\isachardoublequoteclose}\isanewline
|
|
206 |
\ \ \ \ \isacommand{unfolding}\isamarkupfalse%
|
|
207 |
\ neutral{\isacharunderscore}nat{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
|
|
208 |
\ simp\isanewline
|
|
209 |
\isacommand{qed}\isamarkupfalse%
|
|
210 |
%
|
17056
|
211 |
\endisatagproof
|
|
212 |
{\isafoldproof}%
|
|
213 |
%
|
|
214 |
\isadelimproof
|
|
215 |
%
|
|
216 |
\endisadelimproof
|
31678
|
217 |
\isanewline
|
|
218 |
\isanewline
|
|
219 |
\isacommand{end}\isamarkupfalse%
|
11866
|
220 |
%
|
10328
|
221 |
\begin{isamarkuptext}%
|
31682
|
222 |
\noindent In contrast to the examples above, we here have both
|
31678
|
223 |
specification of class operations and a non-trivial instance proof.
|
|
224 |
|
|
225 |
This covers products as well:%
|
|
226 |
\end{isamarkuptext}%
|
|
227 |
\isamarkuptrue%
|
|
228 |
\isacommand{instantiation}\isamarkupfalse%
|
38325
|
229 |
\ prod\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}monoidl{\isacharcomma}\ monoidl{\isacharparenright}\ monoidl\isanewline
|
31678
|
230 |
\isakeyword{begin}\isanewline
|
|
231 |
\isanewline
|
|
232 |
\isacommand{definition}\isamarkupfalse%
|
|
233 |
\isanewline
|
|
234 |
\ \ neutral{\isacharunderscore}prod{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymzero}\ {\isacharequal}\ {\isacharparenleft}{\isasymzero}{\isacharcomma}\ {\isasymzero}{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
|
235 |
\isanewline
|
|
236 |
\isacommand{instance}\isamarkupfalse%
|
|
237 |
%
|
|
238 |
\isadelimproof
|
|
239 |
\ %
|
|
240 |
\endisadelimproof
|
|
241 |
%
|
|
242 |
\isatagproof
|
|
243 |
\isacommand{proof}\isamarkupfalse%
|
|
244 |
\isanewline
|
|
245 |
\ \ \isacommand{fix}\isamarkupfalse%
|
|
246 |
\ p\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a{\isasymColon}monoidl\ {\isasymtimes}\ {\isacharprime}b{\isasymColon}monoidl{\isachardoublequoteclose}\isanewline
|
|
247 |
\ \ \isacommand{show}\isamarkupfalse%
|
|
248 |
\ {\isachardoublequoteopen}{\isasymzero}\ {\isasymoplus}\ p\ {\isacharequal}\ p{\isachardoublequoteclose}\isanewline
|
|
249 |
\ \ \ \ \isacommand{by}\isamarkupfalse%
|
|
250 |
\ {\isacharparenleft}cases\ p{\isacharparenright}\ {\isacharparenleft}simp\ add{\isacharcolon}\ neutral{\isacharunderscore}prod{\isacharunderscore}def\ neutl{\isacharparenright}\isanewline
|
|
251 |
\isacommand{qed}\isamarkupfalse%
|
|
252 |
%
|
|
253 |
\endisatagproof
|
|
254 |
{\isafoldproof}%
|
|
255 |
%
|
|
256 |
\isadelimproof
|
|
257 |
%
|
|
258 |
\endisadelimproof
|
|
259 |
\isanewline
|
|
260 |
\isanewline
|
|
261 |
\isacommand{end}\isamarkupfalse%
|
|
262 |
%
|
|
263 |
\begin{isamarkuptext}%
|
|
264 |
\noindent Fully-fledged monoids are modelled by another
|
|
265 |
subclass which does not add new parameters but tightens the
|
|
266 |
specification:%
|
|
267 |
\end{isamarkuptext}%
|
|
268 |
\isamarkuptrue%
|
|
269 |
\isacommand{class}\isamarkupfalse%
|
|
270 |
\ monoid\ {\isacharequal}\ monoidl\ {\isacharplus}\isanewline
|
|
271 |
\ \ \isakeyword{assumes}\ neutr{\isacharcolon}\ {\isachardoublequoteopen}x\ {\isasymoplus}\ {\isasymzero}\ {\isacharequal}\ x{\isachardoublequoteclose}%
|
|
272 |
\begin{isamarkuptext}%
|
|
273 |
\noindent Corresponding instances for \isa{nat} and products
|
|
274 |
are left as an exercise to the reader.%
|
10328
|
275 |
\end{isamarkuptext}%
|
11866
|
276 |
\isamarkuptrue%
|
10328
|
277 |
%
|
31678
|
278 |
\isamarkupsubsubsection{Groups%
|
10397
|
279 |
}
|
11866
|
280 |
\isamarkuptrue%
|
10328
|
281 |
%
|
|
282 |
\begin{isamarkuptext}%
|
31678
|
283 |
\noindent To finish our small algebra example, we add a \isa{group} class:%
|
10328
|
284 |
\end{isamarkuptext}%
|
17175
|
285 |
\isamarkuptrue%
|
31678
|
286 |
\isacommand{class}\isamarkupfalse%
|
|
287 |
\ group\ {\isacharequal}\ monoidl\ {\isacharplus}\isanewline
|
|
288 |
\ \ \isakeyword{fixes}\ inv\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\ {\isacharparenleft}{\isachardoublequoteopen}{\isasymdiv}\ {\isacharunderscore}{\isachardoublequoteclose}\ {\isacharbrackleft}{\isadigit{8}}{\isadigit{1}}{\isacharbrackright}\ {\isadigit{8}}{\isadigit{0}}{\isacharparenright}\isanewline
|
|
289 |
\ \ \isakeyword{assumes}\ invl{\isacharcolon}\ {\isachardoublequoteopen}{\isasymdiv}\ x\ {\isasymoplus}\ x\ {\isacharequal}\ {\isasymzero}{\isachardoublequoteclose}%
|
10328
|
290 |
\begin{isamarkuptext}%
|
31678
|
291 |
\noindent We continue with a further example for abstract
|
|
292 |
proofs relative to type classes:%
|
10328
|
293 |
\end{isamarkuptext}%
|
17175
|
294 |
\isamarkuptrue%
|
|
295 |
\isacommand{lemma}\isamarkupfalse%
|
31678
|
296 |
\ left{\isacharunderscore}cancel{\isacharcolon}\isanewline
|
|
297 |
\ \ \isakeyword{fixes}\ x\ y\ z\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a{\isasymColon}group{\isachardoublequoteclose}\isanewline
|
|
298 |
\ \ \isakeyword{shows}\ {\isachardoublequoteopen}x\ {\isasymoplus}\ y\ {\isacharequal}\ x\ {\isasymoplus}\ z\ {\isasymlongleftrightarrow}\ y\ {\isacharequal}\ z{\isachardoublequoteclose}\isanewline
|
17056
|
299 |
%
|
|
300 |
\isadelimproof
|
|
301 |
%
|
|
302 |
\endisadelimproof
|
|
303 |
%
|
|
304 |
\isatagproof
|
31678
|
305 |
\isacommand{proof}\isamarkupfalse%
|
|
306 |
\isanewline
|
|
307 |
\ \ \isacommand{assume}\isamarkupfalse%
|
|
308 |
\ {\isachardoublequoteopen}x\ {\isasymoplus}\ y\ {\isacharequal}\ x\ {\isasymoplus}\ z{\isachardoublequoteclose}\isanewline
|
|
309 |
\ \ \isacommand{then}\isamarkupfalse%
|
|
310 |
\ \isacommand{have}\isamarkupfalse%
|
|
311 |
\ {\isachardoublequoteopen}{\isasymdiv}\ x\ {\isasymoplus}\ {\isacharparenleft}x\ {\isasymoplus}\ y{\isacharparenright}\ {\isacharequal}\ {\isasymdiv}\ x\ {\isasymoplus}\ {\isacharparenleft}x\ {\isasymoplus}\ z{\isacharparenright}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
|
|
312 |
\ simp\isanewline
|
|
313 |
\ \ \isacommand{then}\isamarkupfalse%
|
|
314 |
\ \isacommand{have}\isamarkupfalse%
|
|
315 |
\ {\isachardoublequoteopen}{\isacharparenleft}{\isasymdiv}\ x\ {\isasymoplus}\ x{\isacharparenright}\ {\isasymoplus}\ y\ {\isacharequal}\ {\isacharparenleft}{\isasymdiv}\ x\ {\isasymoplus}\ x{\isacharparenright}\ {\isasymoplus}\ z{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
|
|
316 |
\ {\isacharparenleft}simp\ add{\isacharcolon}\ assoc{\isacharparenright}\isanewline
|
|
317 |
\ \ \isacommand{then}\isamarkupfalse%
|
|
318 |
\ \isacommand{show}\isamarkupfalse%
|
|
319 |
\ {\isachardoublequoteopen}y\ {\isacharequal}\ z{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
|
|
320 |
\ {\isacharparenleft}simp\ add{\isacharcolon}\ invl\ neutl{\isacharparenright}\isanewline
|
|
321 |
\isacommand{next}\isamarkupfalse%
|
|
322 |
\isanewline
|
|
323 |
\ \ \isacommand{assume}\isamarkupfalse%
|
|
324 |
\ {\isachardoublequoteopen}y\ {\isacharequal}\ z{\isachardoublequoteclose}\isanewline
|
|
325 |
\ \ \isacommand{then}\isamarkupfalse%
|
|
326 |
\ \isacommand{show}\isamarkupfalse%
|
|
327 |
\ {\isachardoublequoteopen}x\ {\isasymoplus}\ y\ {\isacharequal}\ x\ {\isasymoplus}\ z{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
|
|
328 |
\ simp\isanewline
|
|
329 |
\isacommand{qed}\isamarkupfalse%
|
17175
|
330 |
%
|
17056
|
331 |
\endisatagproof
|
|
332 |
{\isafoldproof}%
|
|
333 |
%
|
|
334 |
\isadelimproof
|
|
335 |
%
|
|
336 |
\endisadelimproof
|
11866
|
337 |
%
|
10328
|
338 |
\begin{isamarkuptext}%
|
31678
|
339 |
\noindent Any \isa{group} is also a \isa{monoid}; this
|
|
340 |
can be made explicit by claiming an additional subclass relation,
|
|
341 |
together with a proof of the logical difference:%
|
10328
|
342 |
\end{isamarkuptext}%
|
17175
|
343 |
\isamarkuptrue%
|
|
344 |
\isacommand{instance}\isamarkupfalse%
|
31678
|
345 |
\ group\ {\isasymsubseteq}\ monoid\isanewline
|
17056
|
346 |
%
|
|
347 |
\isadelimproof
|
|
348 |
%
|
|
349 |
\endisadelimproof
|
|
350 |
%
|
|
351 |
\isatagproof
|
31678
|
352 |
\isacommand{proof}\isamarkupfalse%
|
|
353 |
\isanewline
|
|
354 |
\ \ \isacommand{fix}\isamarkupfalse%
|
|
355 |
\ x\isanewline
|
|
356 |
\ \ \isacommand{from}\isamarkupfalse%
|
|
357 |
\ invl\ \isacommand{have}\isamarkupfalse%
|
|
358 |
\ {\isachardoublequoteopen}{\isasymdiv}\ x\ {\isasymoplus}\ x\ {\isacharequal}\ {\isasymzero}{\isachardoublequoteclose}\ \isacommand{{\isachardot}}\isamarkupfalse%
|
|
359 |
\isanewline
|
|
360 |
\ \ \isacommand{then}\isamarkupfalse%
|
|
361 |
\ \isacommand{have}\isamarkupfalse%
|
|
362 |
\ {\isachardoublequoteopen}{\isasymdiv}\ x\ {\isasymoplus}\ {\isacharparenleft}x\ {\isasymoplus}\ {\isasymzero}{\isacharparenright}\ {\isacharequal}\ {\isasymdiv}\ x\ {\isasymoplus}\ x{\isachardoublequoteclose}\isanewline
|
|
363 |
\ \ \ \ \isacommand{by}\isamarkupfalse%
|
|
364 |
\ {\isacharparenleft}simp\ add{\isacharcolon}\ neutl\ invl\ assoc\ {\isacharbrackleft}symmetric{\isacharbrackright}{\isacharparenright}\isanewline
|
|
365 |
\ \ \isacommand{then}\isamarkupfalse%
|
|
366 |
\ \isacommand{show}\isamarkupfalse%
|
|
367 |
\ {\isachardoublequoteopen}x\ {\isasymoplus}\ {\isasymzero}\ {\isacharequal}\ x{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
|
|
368 |
\ {\isacharparenleft}simp\ add{\isacharcolon}\ left{\isacharunderscore}cancel{\isacharparenright}\isanewline
|
|
369 |
\isacommand{qed}\isamarkupfalse%
|
17175
|
370 |
%
|
17056
|
371 |
\endisatagproof
|
|
372 |
{\isafoldproof}%
|
|
373 |
%
|
|
374 |
\isadelimproof
|
|
375 |
%
|
|
376 |
\endisadelimproof
|
11866
|
377 |
%
|
10328
|
378 |
\begin{isamarkuptext}%
|
31678
|
379 |
\noindent The proof result is propagated to the type system,
|
|
380 |
making \isa{group} an instance of \isa{monoid} by adding an
|
|
381 |
additional edge to the graph of subclass relation; see also
|
10396
|
382 |
Figure~\ref{fig:subclass}.
|
|
383 |
|
|
384 |
\begin{figure}[htbp]
|
31678
|
385 |
\begin{center}
|
|
386 |
\small
|
|
387 |
\unitlength 0.6mm
|
|
388 |
\begin{picture}(40,60)(0,0)
|
|
389 |
\put(20,60){\makebox(0,0){\isa{semigroup}}}
|
|
390 |
\put(20,40){\makebox(0,0){\isa{monoidl}}}
|
|
391 |
\put(00,20){\makebox(0,0){\isa{monoid}}}
|
|
392 |
\put(40,00){\makebox(0,0){\isa{group}}}
|
|
393 |
\put(20,55){\vector(0,-1){10}}
|
|
394 |
\put(15,35){\vector(-1,-1){10}}
|
|
395 |
\put(25,35){\vector(1,-3){10}}
|
|
396 |
\end{picture}
|
|
397 |
\hspace{8em}
|
|
398 |
\begin{picture}(40,60)(0,0)
|
|
399 |
\put(20,60){\makebox(0,0){\isa{semigroup}}}
|
|
400 |
\put(20,40){\makebox(0,0){\isa{monoidl}}}
|
|
401 |
\put(00,20){\makebox(0,0){\isa{monoid}}}
|
|
402 |
\put(40,00){\makebox(0,0){\isa{group}}}
|
|
403 |
\put(20,55){\vector(0,-1){10}}
|
|
404 |
\put(15,35){\vector(-1,-1){10}}
|
|
405 |
\put(05,15){\vector(3,-1){30}}
|
|
406 |
\end{picture}
|
|
407 |
\caption{Subclass relationship of monoids and groups:
|
|
408 |
before and after establishing the relationship
|
|
409 |
\isa{group\ {\isasymsubseteq}\ monoid}; transitive edges are left out.}
|
|
410 |
\label{fig:subclass}
|
|
411 |
\end{center}
|
|
412 |
\end{figure}%
|
10328
|
413 |
\end{isamarkuptext}%
|
11866
|
414 |
\isamarkuptrue%
|
10328
|
415 |
%
|
10397
|
416 |
\isamarkupsubsubsection{Inconsistencies%
|
|
417 |
}
|
11866
|
418 |
\isamarkuptrue%
|
10328
|
419 |
%
|
|
420 |
\begin{isamarkuptext}%
|
31678
|
421 |
The reader may be wondering what happens if we attach an
|
|
422 |
inconsistent set of axioms to a class. So far we have always avoided
|
|
423 |
to add new axioms to HOL for fear of inconsistencies and suddenly it
|
10328
|
424 |
seems that we are throwing all caution to the wind. So why is there no
|
|
425 |
problem?
|
|
426 |
|
31678
|
427 |
The point is that by construction, all type variables in the axioms of
|
|
428 |
a \isacommand{class} are automatically constrained with the class
|
|
429 |
being defined (as shown for axiom \isa{refl} above). These
|
|
430 |
constraints are always carried around and Isabelle takes care that
|
|
431 |
they are never lost, unless the type variable is instantiated with a
|
|
432 |
type that has been shown to belong to that class. Thus you may be able
|
|
433 |
to prove \isa{False} from your axioms, but Isabelle will remind you
|
|
434 |
that this theorem has the hidden hypothesis that the class is
|
|
435 |
non-empty.
|
12332
|
436 |
|
31678
|
437 |
Even if each individual class is consistent, intersections of
|
|
438 |
(unrelated) classes readily become inconsistent in practice. Now we
|
|
439 |
know this need not worry us.%
|
|
440 |
\end{isamarkuptext}%
|
|
441 |
\isamarkuptrue%
|
|
442 |
%
|
|
443 |
\isamarkupsubsubsection{Syntactic Classes and Predefined Overloading%
|
|
444 |
}
|
|
445 |
\isamarkuptrue%
|
|
446 |
%
|
|
447 |
\begin{isamarkuptext}%
|
|
448 |
In our algebra example, we have started with a \emph{syntactic
|
|
449 |
class} \isa{plus} which only specifies operations but no axioms; it
|
|
450 |
would have been also possible to start immediately with class \isa{semigroup}, specifying the \isa{{\isasymoplus}} operation and associativity at
|
|
451 |
the same time.
|
|
452 |
|
|
453 |
Which approach is more appropriate depends. Usually it is more
|
|
454 |
convenient to introduce operations and axioms in the same class: then
|
|
455 |
the type checker will automatically insert the corresponding class
|
|
456 |
constraints whenever the operations occur, reducing the need of manual
|
|
457 |
annotations. However, when operations are decorated with popular
|
|
458 |
syntax, syntactic classes can be an option to re-use the syntax in
|
|
459 |
different contexts; this is indeed the way most overloaded constants
|
|
460 |
in HOL are introduced, of which the most important are listed in
|
|
461 |
Table~\ref{tab:overloading} in the appendix. Section
|
|
462 |
\ref{sec:numeric-classes} covers a range of corresponding classes
|
|
463 |
\emph{with} axioms.
|
|
464 |
|
|
465 |
Further note that classes may contain axioms but \emph{no} operations.
|
|
466 |
An example is class \isa{finite} from theory \hyperlink{theory.Finite-Set}{\mbox{\isa{Finite{\isacharunderscore}Set}}}
|
|
467 |
which specifies a type to be finite: \isa{{\isachardoublequote}finite\ {\isacharparenleft}UNIV\ {\isasymColon}\ {\isacharprime}a{\isasymColon}finite\ set{\isacharparenright}{\isachardoublequote}}.%
|
10328
|
468 |
\end{isamarkuptext}%
|
17175
|
469 |
\isamarkuptrue%
|
17056
|
470 |
%
|
|
471 |
\isadelimtheory
|
|
472 |
%
|
|
473 |
\endisadelimtheory
|
|
474 |
%
|
|
475 |
\isatagtheory
|
|
476 |
%
|
|
477 |
\endisatagtheory
|
|
478 |
{\isafoldtheory}%
|
|
479 |
%
|
|
480 |
\isadelimtheory
|
|
481 |
%
|
|
482 |
\endisadelimtheory
|
10328
|
483 |
\end{isabellebody}%
|
|
484 |
%%% Local Variables:
|
|
485 |
%%% mode: latex
|
|
486 |
%%% TeX-master: "root"
|
|
487 |
%%% End:
|