1 % |
1 % |
2 \begin{isabellebody}% |
2 \begin{isabellebody}% |
3 \def\isabellecontext{Axioms}% |
3 \def\isabellecontext{Axioms}% |
4 % |
4 % |
5 \isamarkupsubsection{Axioms% |
5 \isamarkupsubsection{Axioms} |
6 } |
|
7 % |
6 % |
8 \begin{isamarkuptext}% |
7 \begin{isamarkuptext}% |
9 Now we want to attach axioms to our classes. Then we can reason on the |
8 Now we want to attach axioms to our classes. Then we can reason on the |
10 level of classes and the results will be applicable to all types in a class, |
9 level of classes and the results will be applicable to all types in a class, |
11 just as in axiomatic mathematics. These ideas are demonstrated by means of |
10 just as in axiomatic mathematics. These ideas are demonstrated by means of |
12 our above ordering relations.% |
11 our above ordering relations.% |
13 \end{isamarkuptext}% |
12 \end{isamarkuptext}% |
14 % |
13 % |
15 \isamarkupsubsubsection{Partial orders% |
14 \isamarkupsubsubsection{Partial orders} |
16 } |
|
17 % |
15 % |
18 \begin{isamarkuptext}% |
16 \begin{isamarkuptext}% |
19 A \emph{partial order} is a subclass of \isa{ordrel} |
17 A \emph{partial order} is a subclass of \isa{ordrel} |
20 where certain axioms need to hold:% |
18 where certain axioms need to hold:% |
21 \end{isamarkuptext}% |
19 \end{isamarkuptext}% |
137 \isacommand{apply}{\isacharparenleft}simp{\isacharunderscore}all\ {\isacharparenleft}no{\isacharunderscore}asm{\isacharunderscore}use{\isacharparenright}\ add{\isacharcolon}less{\isacharunderscore}le{\isacharparenright}\isanewline |
133 \isacommand{apply}{\isacharparenleft}simp{\isacharunderscore}all\ {\isacharparenleft}no{\isacharunderscore}asm{\isacharunderscore}use{\isacharparenright}\ add{\isacharcolon}less{\isacharunderscore}le{\isacharparenright}\isanewline |
138 \ \ \isacommand{apply}{\isacharparenleft}blast\ intro{\isacharcolon}\ trans\ antisym{\isacharparenright}\isanewline |
134 \ \ \isacommand{apply}{\isacharparenleft}blast\ intro{\isacharcolon}\ trans\ antisym{\isacharparenright}\isanewline |
139 \ \isacommand{apply}{\isacharparenleft}blast\ intro{\isacharcolon}\ refl{\isacharparenright}\isanewline |
135 \ \isacommand{apply}{\isacharparenleft}blast\ intro{\isacharcolon}\ refl{\isacharparenright}\isanewline |
140 \isacommand{done}% |
136 \isacommand{done}% |
141 \begin{isamarkuptext}% |
137 \begin{isamarkuptext}% |
142 \noindent |
138 The subclass relation must always be acyclic. Therefore Isabelle will |
143 The result is the following subclass diagram: |
139 complain if you also prove the relationship \isa{strord\ {\isacharless}\ parord}.% |
|
140 \end{isamarkuptext}% |
|
141 % |
|
142 \isamarkupsubsubsection{Multiple inheritance and sorts} |
|
143 % |
|
144 \begin{isamarkuptext}% |
|
145 A class may inherit from more than one direct superclass. This is called |
|
146 multiple inheritance and is certainly permitted. For example we could define |
|
147 the classes of well-founded orderings and well-orderings:% |
|
148 \end{isamarkuptext}% |
|
149 \isacommand{axclass}\ wford\ {\isacharless}\ parord\isanewline |
|
150 wford{\isacharcolon}\ {\isachardoublequote}wf\ {\isacharbraceleft}{\isacharparenleft}y{\isacharcomma}x{\isacharparenright}{\isachardot}\ y\ {\isacharless}{\isacharless}\ x{\isacharbraceright}{\isachardoublequote}\isanewline |
|
151 \isanewline |
|
152 \isacommand{axclass}\ wellord\ {\isacharless}\ linord{\isacharcomma}\ wford% |
|
153 \begin{isamarkuptext}% |
|
154 \noindent |
|
155 The last line expresses the usual definition: a well-ordering is a linear |
|
156 well-founded ordering. The result is the subclass diagram in |
|
157 Figure~\ref{fig:subclass}. |
|
158 |
|
159 \begin{figure}[htbp] |
144 \[ |
160 \[ |
145 \begin{array}{c} |
161 \begin{array}{r@ {}r@ {}c@ {}l@ {}l} |
146 \isa{term}\\ |
162 & & \isa{term}\\ |
147 |\\ |
163 & & |\\ |
148 \isa{ordrel}\\ |
164 & & \isa{ordrel}\\ |
149 |\\ |
165 & & |\\ |
150 \isa{strord}\\ |
166 & & \isa{strord}\\ |
151 |\\ |
167 & & |\\ |
152 \isa{parord} |
168 & & \isa{parord} \\ |
|
169 & / & & \backslash \\ |
|
170 \isa{linord} & & & & \isa{wford} \\ |
|
171 & \backslash & & / \\ |
|
172 & & \isa{wellord} |
153 \end{array} |
173 \end{array} |
154 \] |
174 \] |
155 |
175 \caption{Subclass diagramm} |
156 In general, the subclass diagram must be acyclic. Therefore Isabelle will |
176 \label{fig:subclass} |
157 complain if you also prove the relationship \isa{strord\ {\isacharless}\ parord}. |
177 \end{figure} |
158 Multiple inheritance is however permitted. |
178 |
159 |
179 Since class \isa{wellord} does not introduce any new axioms, it can simply |
160 This finishes our demonstration of type classes based on orderings. We |
180 be viewed as the intersection of the two classes \isa{linord} and \isa{wford}. Such intersections need not be given a new name but can be created on |
161 remind our readers that \isa{Main} contains a much more developed theory of |
181 the fly: the expression $\{C@1,\dots,C@n\}$, where the $C@i$ are classes, |
|
182 represents the intersection of the $C@i$. Such an expression is called a |
|
183 \bfindex{sort}, and sorts can appear in most places where we have only shown |
|
184 classes so far, for example in type constraints: \isa{{\isacharprime}a{\isacharcolon}{\isacharcolon}{\isacharbraceleft}linord{\isacharcomma}wford{\isacharbraceright}}. |
|
185 In fact, \isa{{\isacharprime}a{\isacharcolon}{\isacharcolon}ord} is short for \isa{{\isacharprime}a{\isacharcolon}{\isacharcolon}{\isacharbraceleft}ord{\isacharbraceright}}. |
|
186 However, we do not pursue this rarefied concept further. |
|
187 |
|
188 This concludes our demonstration of type classes based on orderings. We |
|
189 remind our readers that \isa{Main} contains a theory of |
162 orderings phrased in terms of the usual \isa{{\isasymle}} and \isa{{\isacharless}}. |
190 orderings phrased in terms of the usual \isa{{\isasymle}} and \isa{{\isacharless}}. |
163 It is recommended that, if possible, |
191 It is recommended that, if possible, |
164 you base your own ordering relations on this theory.% |
192 you base your own ordering relations on this theory.% |
165 \end{isamarkuptext}% |
193 \end{isamarkuptext}% |
166 % |
194 % |
167 \isamarkupsubsubsection{Inconsistencies% |
195 \isamarkupsubsubsection{Inconsistencies} |
168 } |
|
169 % |
196 % |
170 \begin{isamarkuptext}% |
197 \begin{isamarkuptext}% |
171 The reader may be wondering what happens if we, maybe accidentally, |
198 The reader may be wondering what happens if we, maybe accidentally, |
172 attach an inconsistent set of axioms to a class. So far we have always |
199 attach an inconsistent set of axioms to a class. So far we have always |
173 avoided to add new axioms to HOL for fear of inconsistencies and suddenly it |
200 avoided to add new axioms to HOL for fear of inconsistencies and suddenly it |