10328
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{Axioms}%
|
|
4 |
%
|
10397
|
5 |
\isamarkupsubsection{Axioms%
|
|
6 |
}
|
10328
|
7 |
%
|
|
8 |
\begin{isamarkuptext}%
|
|
9 |
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,
|
|
11 |
just as in axiomatic mathematics. These ideas are demonstrated by means of
|
|
12 |
our above ordering relations.%
|
|
13 |
\end{isamarkuptext}%
|
|
14 |
%
|
10397
|
15 |
\isamarkupsubsubsection{Partial orders%
|
|
16 |
}
|
10328
|
17 |
%
|
|
18 |
\begin{isamarkuptext}%
|
|
19 |
A \emph{partial order} is a subclass of \isa{ordrel}
|
|
20 |
where certain axioms need to hold:%
|
|
21 |
\end{isamarkuptext}%
|
|
22 |
\isacommand{axclass}\ parord\ {\isacharless}\ ordrel\isanewline
|
|
23 |
refl{\isacharcolon}\ \ \ \ {\isachardoublequote}x\ {\isacharless}{\isacharless}{\isacharequal}\ x{\isachardoublequote}\isanewline
|
|
24 |
trans{\isacharcolon}\ \ \ {\isachardoublequote}{\isasymlbrakk}\ x\ {\isacharless}{\isacharless}{\isacharequal}\ y{\isacharsemicolon}\ y\ {\isacharless}{\isacharless}{\isacharequal}\ z\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ x\ {\isacharless}{\isacharless}{\isacharequal}\ z{\isachardoublequote}\isanewline
|
|
25 |
antisym{\isacharcolon}\ {\isachardoublequote}{\isasymlbrakk}\ x\ {\isacharless}{\isacharless}{\isacharequal}\ y{\isacharsemicolon}\ y\ {\isacharless}{\isacharless}{\isacharequal}\ x\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ x\ {\isacharequal}\ y{\isachardoublequote}\isanewline
|
|
26 |
less{\isacharunderscore}le{\isacharcolon}\ {\isachardoublequote}x\ {\isacharless}{\isacharless}\ y\ {\isacharequal}\ {\isacharparenleft}x\ {\isacharless}{\isacharless}{\isacharequal}\ y\ {\isasymand}\ x\ {\isasymnoteq}\ y{\isacharparenright}{\isachardoublequote}%
|
|
27 |
\begin{isamarkuptext}%
|
|
28 |
\noindent
|
|
29 |
The first three axioms are the familiar ones, and the final one
|
|
30 |
requires that \isa{{\isacharless}{\isacharless}} and \isa{{\isacharless}{\isacharless}{\isacharequal}} are related as expected.
|
|
31 |
Note that behind the scenes, Isabelle has restricted the axioms to class
|
|
32 |
\isa{parord}. For example, this is what \isa{refl} really looks like:
|
|
33 |
\isa{{\isacharparenleft}{\isacharquery}x{\isasymColon}{\isacharquery}{\isacharprime}a{\isacharparenright}\ {\isacharless}{\isacharless}{\isacharequal}\ {\isacharquery}x}.
|
|
34 |
|
|
35 |
We can now prove simple theorems in this abstract setting, for example
|
|
36 |
that \isa{{\isacharless}{\isacharless}} is not symmetric:%
|
|
37 |
\end{isamarkuptext}%
|
|
38 |
\isacommand{lemma}\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}x{\isacharcolon}{\isacharcolon}{\isacharprime}a{\isacharcolon}{\isacharcolon}parord{\isacharparenright}\ {\isacharless}{\isacharless}\ y\ {\isasymLongrightarrow}\ {\isacharparenleft}{\isasymnot}\ y\ {\isacharless}{\isacharless}\ x{\isacharparenright}\ {\isacharequal}\ True{\isachardoublequote}%
|
|
39 |
\begin{isamarkuptxt}%
|
|
40 |
\noindent
|
|
41 |
The conclusion is not simply \isa{{\isasymnot}\ y\ {\isacharless}{\isacharless}\ x} because the preprocessor
|
|
42 |
of the simplifier would turn this into \isa{{\isacharparenleft}y\ {\isacharless}{\isacharless}\ x{\isacharparenright}\ {\isacharequal}\ False}, thus yielding
|
|
43 |
a nonterminating rewrite rule. In the above form it is a generally useful
|
|
44 |
rule.
|
|
45 |
The type constraint is necessary because otherwise Isabelle would only assume
|
|
46 |
\isa{{\isacharprime}a{\isacharcolon}{\isacharcolon}ordrel} (as required in the type of \isa{{\isacharless}{\isacharless}}), in
|
|
47 |
which case the proposition is not a theorem. The proof is easy:%
|
|
48 |
\end{isamarkuptxt}%
|
|
49 |
\isacommand{by}{\isacharparenleft}simp\ add{\isacharcolon}less{\isacharunderscore}le\ antisym{\isacharparenright}%
|
|
50 |
\begin{isamarkuptext}%
|
|
51 |
We could now continue in this vein and develop a whole theory of
|
|
52 |
results about partial orders. Eventually we will want to apply these results
|
|
53 |
to concrete types, namely the instances of the class. Thus we first need to
|
|
54 |
prove that the types in question, for example \isa{bool}, are indeed
|
|
55 |
instances of \isa{parord}:%
|
|
56 |
\end{isamarkuptext}%
|
|
57 |
\isacommand{instance}\ bool\ {\isacharcolon}{\isacharcolon}\ parord\isanewline
|
|
58 |
\isacommand{apply}\ intro{\isacharunderscore}classes%
|
|
59 |
\begin{isamarkuptxt}%
|
|
60 |
\noindent
|
|
61 |
This time \isa{intro{\isacharunderscore}classes} leaves us with the four axioms,
|
|
62 |
specialized to type \isa{bool}, as subgoals:
|
|
63 |
\begin{isabelle}%
|
|
64 |
\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}x{\isasymColon}bool{\isachardot}\ x\ {\isacharless}{\isacharless}{\isacharequal}\ x\isanewline
|
|
65 |
\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}{\isacharparenleft}x{\isasymColon}bool{\isacharparenright}\ {\isacharparenleft}y{\isasymColon}bool{\isacharparenright}\ z{\isasymColon}bool{\isachardot}\ {\isasymlbrakk}x\ {\isacharless}{\isacharless}{\isacharequal}\ y{\isacharsemicolon}\ y\ {\isacharless}{\isacharless}{\isacharequal}\ z{\isasymrbrakk}\ {\isasymLongrightarrow}\ x\ {\isacharless}{\isacharless}{\isacharequal}\ z\isanewline
|
|
66 |
\ {\isadigit{3}}{\isachardot}\ {\isasymAnd}{\isacharparenleft}x{\isasymColon}bool{\isacharparenright}\ y{\isasymColon}bool{\isachardot}\ {\isasymlbrakk}x\ {\isacharless}{\isacharless}{\isacharequal}\ y{\isacharsemicolon}\ y\ {\isacharless}{\isacharless}{\isacharequal}\ x{\isasymrbrakk}\ {\isasymLongrightarrow}\ x\ {\isacharequal}\ y\isanewline
|
|
67 |
\ {\isadigit{4}}{\isachardot}\ {\isasymAnd}{\isacharparenleft}x{\isasymColon}bool{\isacharparenright}\ y{\isasymColon}bool{\isachardot}\ {\isacharparenleft}x\ {\isacharless}{\isacharless}\ y{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}x\ {\isacharless}{\isacharless}{\isacharequal}\ y\ {\isasymand}\ x\ {\isasymnoteq}\ y{\isacharparenright}%
|
|
68 |
\end{isabelle}
|
|
69 |
Fortunately, the proof is easy for blast, once we have unfolded the definitions
|
|
70 |
of \isa{{\isacharless}{\isacharless}} and \isa{{\isacharless}{\isacharless}{\isacharequal}} at \isa{bool}:%
|
|
71 |
\end{isamarkuptxt}%
|
|
72 |
\isacommand{apply}{\isacharparenleft}simp{\isacharunderscore}all\ {\isacharparenleft}no{\isacharunderscore}asm{\isacharunderscore}use{\isacharparenright}\ only{\isacharcolon}\ le{\isacharunderscore}bool{\isacharunderscore}def\ less{\isacharunderscore}bool{\isacharunderscore}def{\isacharparenright}\isanewline
|
|
73 |
\isacommand{by}{\isacharparenleft}blast{\isacharcomma}\ blast{\isacharcomma}\ blast{\isacharcomma}\ blast{\isacharparenright}%
|
|
74 |
\begin{isamarkuptext}%
|
|
75 |
\noindent
|
|
76 |
Can you figure out why we have to include \isa{{\isacharparenleft}no{\isacharunderscore}asm{\isacharunderscore}use{\isacharparenright}}?
|
|
77 |
|
|
78 |
We can now apply our single lemma above in the context of booleans:%
|
|
79 |
\end{isamarkuptext}%
|
|
80 |
\isacommand{lemma}\ {\isachardoublequote}{\isacharparenleft}P{\isacharcolon}{\isacharcolon}bool{\isacharparenright}\ {\isacharless}{\isacharless}\ Q\ {\isasymLongrightarrow}\ {\isasymnot}{\isacharparenleft}Q\ {\isacharless}{\isacharless}\ P{\isacharparenright}{\isachardoublequote}\isanewline
|
|
81 |
\isacommand{by}\ simp%
|
|
82 |
\begin{isamarkuptext}%
|
|
83 |
\noindent
|
|
84 |
The effect is not stunning but demonstrates the principle. It also shows
|
|
85 |
that tools like the simplifier can deal with generic rules as well. Moreover,
|
|
86 |
it should be clear that the main advantage of the axiomatic method is that
|
|
87 |
theorems can be proved in the abstract and one does not need to repeat the
|
|
88 |
proof for each instance.%
|
|
89 |
\end{isamarkuptext}%
|
|
90 |
%
|
10397
|
91 |
\isamarkupsubsubsection{Linear orders%
|
|
92 |
}
|
10328
|
93 |
%
|
|
94 |
\begin{isamarkuptext}%
|
|
95 |
If any two elements of a partial order are comparable it is a
|
|
96 |
\emph{linear} or \emph{total} order:%
|
|
97 |
\end{isamarkuptext}%
|
|
98 |
\isacommand{axclass}\ linord\ {\isacharless}\ parord\isanewline
|
|
99 |
total{\isacharcolon}\ {\isachardoublequote}x\ {\isacharless}{\isacharless}{\isacharequal}\ y\ {\isasymor}\ y\ {\isacharless}{\isacharless}{\isacharequal}\ x{\isachardoublequote}%
|
|
100 |
\begin{isamarkuptext}%
|
|
101 |
\noindent
|
|
102 |
By construction, \isa{linord} inherits all axioms from \isa{parord}.
|
|
103 |
Therefore we can show that totality can be expressed in terms of \isa{{\isacharless}{\isacharless}}
|
|
104 |
as follows:%
|
|
105 |
\end{isamarkuptext}%
|
|
106 |
\isacommand{lemma}\ {\isachardoublequote}{\isasymAnd}x{\isacharcolon}{\isacharcolon}{\isacharprime}a{\isacharcolon}{\isacharcolon}linord{\isachardot}\ x{\isacharless}{\isacharless}y\ {\isasymor}\ x{\isacharequal}y\ {\isasymor}\ y{\isacharless}{\isacharless}x{\isachardoublequote}\isanewline
|
|
107 |
\isacommand{apply}{\isacharparenleft}simp\ add{\isacharcolon}\ less{\isacharunderscore}le{\isacharparenright}\isanewline
|
|
108 |
\isacommand{apply}{\isacharparenleft}insert\ total{\isacharparenright}\isanewline
|
|
109 |
\isacommand{apply}\ blast\isanewline
|
|
110 |
\isacommand{done}%
|
|
111 |
\begin{isamarkuptext}%
|
|
112 |
Linear orders are an example of subclassing by construction, which is the most
|
|
113 |
common case. It is also possible to prove additional subclass relationships
|
|
114 |
later on, i.e.\ subclassing by proof. This is the topic of the following
|
|
115 |
section.%
|
|
116 |
\end{isamarkuptext}%
|
|
117 |
%
|
10397
|
118 |
\isamarkupsubsubsection{Strict orders%
|
|
119 |
}
|
10328
|
120 |
%
|
|
121 |
\begin{isamarkuptext}%
|
|
122 |
An alternative axiomatization of partial orders takes \isa{{\isacharless}{\isacharless}} rather than
|
|
123 |
\isa{{\isacharless}{\isacharless}{\isacharequal}} as the primary concept. The result is a \emph{strict} order:%
|
|
124 |
\end{isamarkuptext}%
|
|
125 |
\isacommand{axclass}\ strord\ {\isacharless}\ ordrel\isanewline
|
|
126 |
irrefl{\isacharcolon}\ \ \ \ \ {\isachardoublequote}{\isasymnot}\ x\ {\isacharless}{\isacharless}\ x{\isachardoublequote}\isanewline
|
|
127 |
less{\isacharunderscore}trans{\isacharcolon}\ {\isachardoublequote}{\isasymlbrakk}\ x\ {\isacharless}{\isacharless}\ y{\isacharsemicolon}\ y\ {\isacharless}{\isacharless}\ z\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ x\ {\isacharless}{\isacharless}\ z{\isachardoublequote}\isanewline
|
|
128 |
le{\isacharunderscore}less{\isacharcolon}\ \ \ \ {\isachardoublequote}x\ {\isacharless}{\isacharless}{\isacharequal}\ y\ {\isacharequal}\ {\isacharparenleft}x\ {\isacharless}{\isacharless}\ y\ {\isasymor}\ x\ {\isacharequal}\ y{\isacharparenright}{\isachardoublequote}%
|
|
129 |
\begin{isamarkuptext}%
|
|
130 |
\noindent
|
|
131 |
It is well known that partial orders are the same as strict orders. Let us
|
|
132 |
prove one direction, namely that partial orders are a subclass of strict
|
|
133 |
orders. The proof follows the ususal pattern:%
|
|
134 |
\end{isamarkuptext}%
|
|
135 |
\isacommand{instance}\ parord\ {\isacharless}\ strord\isanewline
|
|
136 |
\isacommand{apply}\ intro{\isacharunderscore}classes\isanewline
|
|
137 |
\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
|
|
139 |
\ \isacommand{apply}{\isacharparenleft}blast\ intro{\isacharcolon}\ refl{\isacharparenright}\isanewline
|
|
140 |
\isacommand{done}%
|
|
141 |
\begin{isamarkuptext}%
|
10396
|
142 |
The subclass relation must always be acyclic. Therefore Isabelle will
|
|
143 |
complain if you also prove the relationship \isa{strord\ {\isacharless}\ parord}.%
|
|
144 |
\end{isamarkuptext}%
|
|
145 |
%
|
10397
|
146 |
\isamarkupsubsubsection{Multiple inheritance and sorts%
|
|
147 |
}
|
10396
|
148 |
%
|
|
149 |
\begin{isamarkuptext}%
|
|
150 |
A class may inherit from more than one direct superclass. This is called
|
|
151 |
multiple inheritance and is certainly permitted. For example we could define
|
|
152 |
the classes of well-founded orderings and well-orderings:%
|
|
153 |
\end{isamarkuptext}%
|
|
154 |
\isacommand{axclass}\ wford\ {\isacharless}\ parord\isanewline
|
|
155 |
wford{\isacharcolon}\ {\isachardoublequote}wf\ {\isacharbraceleft}{\isacharparenleft}y{\isacharcomma}x{\isacharparenright}{\isachardot}\ y\ {\isacharless}{\isacharless}\ x{\isacharbraceright}{\isachardoublequote}\isanewline
|
|
156 |
\isanewline
|
|
157 |
\isacommand{axclass}\ wellord\ {\isacharless}\ linord{\isacharcomma}\ wford%
|
|
158 |
\begin{isamarkuptext}%
|
10328
|
159 |
\noindent
|
10396
|
160 |
The last line expresses the usual definition: a well-ordering is a linear
|
|
161 |
well-founded ordering. The result is the subclass diagram in
|
|
162 |
Figure~\ref{fig:subclass}.
|
|
163 |
|
|
164 |
\begin{figure}[htbp]
|
10328
|
165 |
\[
|
10396
|
166 |
\begin{array}{r@ {}r@ {}c@ {}l@ {}l}
|
|
167 |
& & \isa{term}\\
|
|
168 |
& & |\\
|
|
169 |
& & \isa{ordrel}\\
|
|
170 |
& & |\\
|
|
171 |
& & \isa{strord}\\
|
|
172 |
& & |\\
|
|
173 |
& & \isa{parord} \\
|
|
174 |
& / & & \backslash \\
|
|
175 |
\isa{linord} & & & & \isa{wford} \\
|
|
176 |
& \backslash & & / \\
|
|
177 |
& & \isa{wellord}
|
10328
|
178 |
\end{array}
|
|
179 |
\]
|
10396
|
180 |
\caption{Subclass diagramm}
|
|
181 |
\label{fig:subclass}
|
|
182 |
\end{figure}
|
10328
|
183 |
|
10396
|
184 |
Since class \isa{wellord} does not introduce any new axioms, it can simply
|
|
185 |
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
|
|
186 |
the fly: the expression $\{C@1,\dots,C@n\}$, where the $C@i$ are classes,
|
|
187 |
represents the intersection of the $C@i$. Such an expression is called a
|
|
188 |
\bfindex{sort}, and sorts can appear in most places where we have only shown
|
|
189 |
classes so far, for example in type constraints: \isa{{\isacharprime}a{\isacharcolon}{\isacharcolon}{\isacharbraceleft}linord{\isacharcomma}wford{\isacharbraceright}}.
|
|
190 |
In fact, \isa{{\isacharprime}a{\isacharcolon}{\isacharcolon}ord} is short for \isa{{\isacharprime}a{\isacharcolon}{\isacharcolon}{\isacharbraceleft}ord{\isacharbraceright}}.
|
|
191 |
However, we do not pursue this rarefied concept further.
|
10328
|
192 |
|
10396
|
193 |
This concludes our demonstration of type classes based on orderings. We
|
|
194 |
remind our readers that \isa{Main} contains a theory of
|
10328
|
195 |
orderings phrased in terms of the usual \isa{{\isasymle}} and \isa{{\isacharless}}.
|
|
196 |
It is recommended that, if possible,
|
|
197 |
you base your own ordering relations on this theory.%
|
|
198 |
\end{isamarkuptext}%
|
|
199 |
%
|
10397
|
200 |
\isamarkupsubsubsection{Inconsistencies%
|
|
201 |
}
|
10328
|
202 |
%
|
|
203 |
\begin{isamarkuptext}%
|
|
204 |
The reader may be wondering what happens if we, maybe accidentally,
|
|
205 |
attach an inconsistent set of axioms to a class. So far we have always
|
|
206 |
avoided to add new axioms to HOL for fear of inconsistencies and suddenly it
|
|
207 |
seems that we are throwing all caution to the wind. So why is there no
|
|
208 |
problem?
|
|
209 |
|
|
210 |
The point is that by construction, all type variables in the axioms of an
|
|
211 |
\isacommand{axclass} are automatically constrained with the class being
|
|
212 |
defined (as shown for axiom \isa{refl} above). These constraints are
|
|
213 |
always carried around and Isabelle takes care that they are never lost,
|
|
214 |
unless the type variable is instantiated with a type that has been shown to
|
|
215 |
belong to that class. Thus you may be able to prove \isa{False}
|
|
216 |
from your axioms, but Isabelle will remind you that this
|
|
217 |
theorem has the hidden hypothesis that the class is non-empty.%
|
|
218 |
\end{isamarkuptext}%
|
|
219 |
\end{isabellebody}%
|
|
220 |
%%% Local Variables:
|
|
221 |
%%% mode: latex
|
|
222 |
%%% TeX-master: "root"
|
|
223 |
%%% End:
|