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