author | nipkow |
Mon, 22 Nov 1993 18:26:46 +0100 | |
changeset 139 | 4f83c0a0c3f4 |
parent 138 | 9ba8bff1addc |
child 141 | a133921366cb |
permissions | -rw-r--r-- |
104 | 1 |
%% $Id$ |
2 |
\chapter{Theories, Terms and Types} \label{theories} |
|
3 |
\index{theories|(}\index{signatures|bold} |
|
4 |
\index{reading!axioms|see{{\tt extend_theory} and {\tt assume_ax}}} |
|
5 |
Theories organize the syntax, declarations and axioms of a mathematical |
|
6 |
development. They are built, starting from the Pure theory, by extending |
|
7 |
and merging existing theories. They have the \ML{} type \ttindex{theory}. |
|
8 |
Theory operations signal errors by raising exception \ttindex{THEORY}, |
|
9 |
returning a message and a list of theories. |
|
10 |
||
11 |
Signatures, which contain information about sorts, types, constants and |
|
12 |
syntax, have the \ML{} type~\ttindexbold{Sign.sg}. For identification, |
|
13 |
each signature carries a unique list of {\bf stamps}, which are~\ML{} |
|
14 |
references (to strings). The strings serve as human-readable names; the |
|
15 |
references serve as unique identifiers. Each primitive signature has a |
|
16 |
single stamp. When two signatures are merged, their lists of stamps are |
|
17 |
also merged. Every theory carries a unique signature. |
|
18 |
||
19 |
Terms and types are the underlying representation of logical syntax. Their |
|
20 |
\ML{} definitions are irrelevant to naive Isabelle users. Programmers who wish |
|
21 |
to extend Isabelle may need to know such details, say to code a tactic that |
|
22 |
looks for subgoals of a particular form. Terms and types may be |
|
23 |
`certified' to be well-formed with respect to a given signature. |
|
24 |
||
25 |
\section{Defining Theories} |
|
26 |
\label{DefiningTheories} |
|
27 |
||
28 |
Theories can be defined either using concrete syntax or by calling certain |
|
29 |
\ML-functions (see \S\ref{BuildingATheory}). Figure~\ref{TheorySyntax} |
|
30 |
presents the concrete syntax for theories. This grammar employs the |
|
31 |
following conventions: |
|
32 |
\begin{itemize} |
|
33 |
\item Identifiers such as $theoryDef$ denote nonterminal symbols. |
|
34 |
\item Text in {\tt typewriter font} denotes terminal symbols. |
|
35 |
\item \ldots{} indicates repetition of a phrase. |
|
36 |
\item A vertical bar~($|$) separates alternative phrases. |
|
37 |
\item Square [brackets] enclose optional phrases. |
|
38 |
\item $id$ stands for an Isabelle identifier. |
|
39 |
\item $string$ stands for an ML string, with its quotation marks. |
|
40 |
\item $k$ stands for a natural number. |
|
41 |
\item $text$ stands for arbitrary ML text. |
|
42 |
\end{itemize} |
|
43 |
||
44 |
\begin{figure}[hp] |
|
45 |
\begin{center} |
|
46 |
\begin{tabular}{rclc} |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
47 |
$theoryDef$ &=& $id$ {\tt=} $name@1$ {\tt+} \dots {\tt+} $name@n$ |
104 | 48 |
[{\tt+} $extension$]\\\\ |
49 |
$extension$ &=& [$classes$] [$default$] [$types$] [$arities$] [$consts$] |
|
50 |
[$rules$] {\tt end} [$ml$]\\\\ |
|
51 |
$classes$ &=& \ttindex{classes} $class$ \dots $class$ \\\\ |
|
52 |
$class$ &=& $id$ [{\tt<} $id@1${\tt,} \dots{\tt,} $id@n$] \\\\ |
|
53 |
$default$ &=& \ttindex{default} $sort$ \\\\ |
|
54 |
$sort$ &=& $id$ ~~$|$~~ {\tt\{} $id@1${\tt,} \dots{\tt,} $id@n$ {\tt\}} \\\\ |
|
55 |
$name$ &=& $id$ ~~$|$~~ $string$ \\\\ |
|
56 |
$types$ &=& \ttindex{types} $typeDecl$ \dots $typeDecl$ \\\\ |
|
57 |
$typeDecl$ &=& $name${\tt,} \dots{\tt,} $name$ $k$ |
|
58 |
[{\tt(} $infix$ {\tt)}] \\\\ |
|
59 |
$infix$ &=& \ttindex{infixl} $k$ ~~$|$~~ \ttindex{infixr} $k$ \\\\ |
|
60 |
$arities$ &=& \ttindex{arities} $arityDecl$ \dots $arityDecl$ \\\\ |
|
61 |
$arityDecl$ &=& $name${\tt,} \dots{\tt,} $name$ {\tt::} $arity$ \\\\ |
|
62 |
$arity$ &=& [{\tt(} $sort${\tt,} \dots{\tt,} $sort$ {\tt)}] $id$ \\\\ |
|
63 |
$consts$ &=& \ttindex{consts} $constDecl$ \dots $constDecl$ \\\\ |
|
64 |
$constDecl$ &=& $name@1${\tt,} \dots{\tt,} $name@n$ {\tt::} $string$ |
|
65 |
[{\tt(} $mixfix$ {\tt)}] \\\\ |
|
66 |
$mixfix$ &=& $string$ |
|
67 |
[ [\quad{\tt[} $k@1${\tt,} \dots{\tt,} $k@n$ {\tt]}\quad] $k$]\\ |
|
68 |
&$|$& $infix$ \\ |
|
69 |
&$|$& \ttindex{binder} $string$ $k$\\\\ |
|
70 |
$rules$ &=& \ttindex{rules} $rule$ \dots $rule$ \\\\ |
|
71 |
$rule$ &=& $id$ $string$ \\\\ |
|
72 |
$ml$ &=& \ttindex{ML} $text$ |
|
73 |
\end{tabular} |
|
74 |
\end{center} |
|
75 |
\caption{Theory Syntax} |
|
76 |
\label{TheorySyntax} |
|
77 |
\end{figure} |
|
78 |
||
79 |
The different parts of a theory definition are interpreted as follows: |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
80 |
\begin{description} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
81 |
\item[$theoryDef$] A theory has a name $id$ and is an |
139 | 82 |
extension of the union of theories $name@1$ \dots $name@n$ with new |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
83 |
classes, types, constants, syntax and axioms. The basic theory, which |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
84 |
contains only the meta-logic, is called {\tt Pure}. |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
85 |
|
139 | 86 |
If $name@i$ is a string, then theory $name@i$ is {\em not} used in building |
87 |
the base of theory $id$. Strings stand for ML-files rather than |
|
88 |
theory-files and document the dependence if $id$ on additional files. This |
|
89 |
is required because $name@1$ \dots $name@n$ are loaded automatically when |
|
90 |
theory $id$ is (re)built. See Chapter~\ref{LoadingTheories} for details. |
|
104 | 91 |
\item[$class$] The new class $id$ is declared as a subclass of existing |
92 |
classes $id@1$ \dots $id@n$. This rules out cyclic class structures. |
|
93 |
Isabelle automatically computes the transitive closure of subclass |
|
94 |
hierarchies. Hence it is not necessary to declare $c@1 < c@3$ in addition |
|
95 |
to $c@1 < c@2$ and $c@2 < c@3$. |
|
96 |
\item[$default$] introduces $sort$ as the new default sort for type |
|
97 |
variables. Unconstrained type variables in an input string are |
|
98 |
automatically constrained by $sort$; this does not apply to type variables |
|
99 |
created internally during type inference. If omitted, |
|
100 |
the default sort is the same as in the parent theory. |
|
101 |
\item[$sort$] is a finite set $id@1$ \dots $id@n$ of classes; a single class |
|
102 |
$id$ abbreviates the singleton set {\tt\{}$id${\tt\}}. |
|
103 |
\item[$name$] is either an alphanumeric identifier or an arbitrary string. |
|
104 |
\item[$typeDecl$] Each $name$ is declared as a new type constructor with |
|
105 |
$k$ arguments. Only binary type constructors can have infix status and |
|
106 |
symbolic names ($string$). |
|
107 |
\item[$infix$] declares a type or constant to be an infix operator of |
|
108 |
precedence $k$ associating to the left ({\tt infixl}) or right ({\tt |
|
109 |
infixr}). |
|
110 |
\item[$arityDecl$] Each existing type constructor $name@1$ \dots $name@n$ |
|
111 |
is given the additional arity $arity$. |
|
112 |
\item[$constDecl$] The new constants $name@1$ \dots $name@n$ are declared to |
|
113 |
be of type $string$. For display purposes they can be annotated with |
|
114 |
$mixfix$ declarations. |
|
115 |
\item[$mixfix$] $string$ is a mixfix template of the form {\tt"}\dots{\tt\_} |
|
116 |
\dots{\tt\_} \dots{\tt"} where the $i$-th underscore indicates the position |
|
117 |
where the $i$-th argument should go, $k@i$ is the minimum precedence of |
|
118 |
the $i$-th argument, and $k$ the precedence of the construct. The list |
|
119 |
\hbox{\tt[$k@1$, \dots, $k@n$]} is optional. |
|
120 |
||
121 |
Binary constants can be given infix status. |
|
122 |
||
123 |
A constant $f$ {\tt::} $(\tau@1\To\tau@2)\To\tau@3$ can be given {\em |
|
124 |
binder} status: {\tt binder} $Q$ $p$ causes $Q\,x.F(x)$ to be treated |
|
125 |
like $f(F)$; $p$ is the precedence of the construct. |
|
126 |
\item[$rule$] A rule consists of a name $id$ and a formula $string$. Rule |
|
127 |
names must be distinct. |
|
128 |
\item[$ml$] This final part of a theory consists of ML code, |
|
129 |
typically for parse and print translations. |
|
130 |
\end{description} |
|
131 |
The $mixfix$ and $ml$ sections are explained in more detail in the {\it |
|
132 |
Defining Logics} chapter of the {\it Logics} manual. |
|
133 |
||
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
134 |
\section{Loading Theories} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
135 |
\label{LoadingTheories} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
136 |
\subsection{Reading a new theory} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
137 |
|
104 | 138 |
\begin{ttbox} |
139 |
use_thy: string -> unit |
|
140 |
\end{ttbox} |
|
141 |
Each theory definition must reside in a separate file. Let the file {\it |
|
139 | 142 |
tf}{\tt.thy} contain the definition of a theory called $TF$ with parent |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
143 |
theories $TB@1$ \dots $TB@n$. Calling \ttindexbold{use_thy}~{\tt"}{\it |
139 | 144 |
TF\/}{\tt"} reads file {\it tf}{\tt.thy}, writes an intermediate {\ML}-file |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
145 |
{\tt.}{\it tf}{\tt.thy.ML}, and reads the latter file. Any of the parent |
139 | 146 |
theories that have not been loaded yet are read now by recursive {\tt |
147 |
use_thy} calls until either an already loaded theory or {\tt Pure} is |
|
148 |
reached. Therefore one can read a complete logic by just one {\tt use_thy} |
|
149 |
call if all theories are linked appropriatly. Afterwards an {\ML} |
|
150 |
structure~$TF$ containing a component {\tt thy} for the new theory and |
|
151 |
components $r@1$ \dots $r@n$ for the rules is declared; it also contains the |
|
152 |
definitions of the {\tt ML} section if any. Unless |
|
153 |
\ttindexbold{delete_tmpfiles} is set to {\tt false}, {\tt.}{\it |
|
154 |
tf}{\tt.thy.ML} is deleted if no errors occured. Finally the file {\it |
|
155 |
tf}{\tt.ML} is read, if it exists; this file normally contains proofs |
|
156 |
involving the new theory. |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
157 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
158 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
159 |
\subsection{Filenames and paths} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
160 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
161 |
The files the theory definition resides in must have the lower case name of |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
162 |
the theory with ".thy" or ".ML" appended. On the other hand {\tt use_thy}'s |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
163 |
parameter has to be the exact theory name. Optionally the name can be |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
164 |
preceeded by a path to specify the directory where the files can be found. If |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
165 |
no path is provided the reference variable {\tt loadpath} is used which |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
166 |
contains a list of paths that are searched in the given order. After the |
139 | 167 |
".thy"-file for a theory has been found, the same path is used to locate the |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
168 |
(optional) ".ML"-file. (You might note that it is also possible to only |
139 | 169 |
provide a ".ML"- but no ".thy"-file. In this case an \ML{} structure with the |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
170 |
theory's name has to be created in the ".ML" file. If both the ".thy"-file |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
171 |
and a structure declaration in the ".ML"-file exist the declaration in the |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
172 |
latter file is used. See {\tt ZF/ex/llist.ML} for an example.) |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
173 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
174 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
175 |
\subsection{Reloading a theory} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
176 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
177 |
{\tt use_thy} keeps track of all loaded theories and stores information about |
139 | 178 |
their files. If it finds that the theory to be loaded was already read |
179 |
before, the following happens: First the theory's files are searched at the |
|
180 |
place they were located the last time they were read. If they are found, |
|
181 |
their time of last modification is compared to the internal data and {\tt |
|
182 |
use_thy} stops if they are equal. In case the files have been moved, {\tt |
|
183 |
use_thy} searches them the same way a new theory would be searched for. |
|
184 |
After all these tests have been passed, the theory is reloaded and all |
|
185 |
theories that depend on it (i.e. that have its name in their $theoryDef$) are |
|
186 |
marked as out-of-date. |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
187 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
188 |
As changing a theory often makes it necessary to reload all theories that |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
189 |
(indirectly) depend on it, {\tt update} should be used instead of {\tt |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
190 |
use_thy} to read a modified theory. This function reloads all changed |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
191 |
theories and their descendants in the correct order. |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
192 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
193 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
194 |
\subsection{Pseudo theories} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
195 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
196 |
There is a problem with {\tt update}: objects created in \ML-files that do not |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
197 |
belong to a theory (see explanation of $theoryDef$ in \ref{DefiningTheories}). |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
198 |
These files are read manually between {\tt use_thy} calls and define objects |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
199 |
used in different theories. As {\tt update} only knows about the |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
200 |
theories there still exist objects with references to the old theory version |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
201 |
after the new one has been read. This (most probably) will produce the fatal |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
202 |
error |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
203 |
\begin{center} \tt |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
204 |
Attempt to merge different versions of theory: $T$ |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
205 |
\end{center} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
206 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
207 |
Therefore there is a way to link theories and the $orphaned$ \ML-files. The |
139 | 208 |
link from a theory to an \ML-file has been mentioned in |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
209 |
Chapter~\ref{DefiningTheories} (strings in $theoryDef$). But to make this |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
210 |
work and to establish a link in the opposite direction we need to create a |
139 | 211 |
{\it pseudo theory}. Let's assume we have an \ML-file named {\tt orphan.ML} |
212 |
that depends on theory $A$ and is itself used in theory $B$. To link the |
|
213 |
three we have to create the file {\tt orphan.thy} containing the line |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
214 |
\begin{ttbox} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
215 |
orphan = A |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
216 |
\end{ttbox} |
139 | 217 |
and add {\tt "orphan"} to the list of $B$'s parents. Creating {\tt |
218 |
orphan.thy} is necessary because of two reasons: First it enables automatic |
|
219 |
loading of $orphan$'s parents and second it creates the \ML{}-object {\tt |
|
220 |
orphan} that is needed by {\tt use_thy} (though it is not added to the base |
|
221 |
of theory $B$). If {\tt orphan.ML} depended on no theory then {\tt Pure} |
|
222 |
would have been used instead of {\tt A}. |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
223 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
224 |
For an extensive example of how this technique can be used to link over 30 |
139 | 225 |
files and read them by just two {\tt use_thy} calls have a look at the ZF |
226 |
logic. |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
227 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
228 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
229 |
\subsection{Removing a theory} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
230 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
231 |
If a previously read file is removed the {\tt update} function will keep |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
232 |
on complaining about a missing file. The theory is not automatically removed |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
233 |
from the internal list to preserve the links to other theories in case one |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
234 |
forgot to adjust the {\tt loadpath} after moving a file. To manually remove a |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
235 |
theory use {\tt unlink_thy}. |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
236 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
237 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
238 |
\subsection{Using Poly/\ML} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
239 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
240 |
As the functions for reading theories depend on reference variables one has to |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
241 |
take into consideration the way Poly/\ML{} handles them. They are only saved |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
242 |
together with the state if they were declared in the current database. E.g. |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
243 |
changes made to a reference variable declared in the $Pure$ database are $not$ |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
244 |
saved if made while using a child database. Therefore a new {\tt Readthy} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
245 |
structure has to be declared by |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
246 |
\begin{ttbox} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
247 |
structure Readthy = ReadthyFUN (structure ThySyn = ThySyn); |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
248 |
open Readthy; |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
249 |
\end{ttbox} |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
250 |
in every newly created database. This is not necessary if the database is |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
251 |
created by copying an existent one. |
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
252 |
|
139 | 253 |
%The above declarations are contained in the $Pure$ database, so one could |
254 |
%simply use e.g. {\tt use_thy} if saving of the reference variables is not |
|
255 |
%needed. Standard ML of New Jersey does not have this behaviour. |
|
104 | 256 |
|
257 |
||
258 |
\section{Basic operations on theories} |
|
259 |
\subsection{Extracting an axiom from a theory} |
|
260 |
\index{theories!extracting axioms|bold}\index{axioms} |
|
261 |
\begin{ttbox} |
|
262 |
get_axiom: theory -> string -> thm |
|
263 |
assume_ax: theory -> string -> thm |
|
264 |
\end{ttbox} |
|
265 |
\begin{description} |
|
266 |
\item[\ttindexbold{get_axiom} $thy$ $name$] |
|
267 |
returns an axiom with the given $name$ from $thy$, raising exception |
|
268 |
\ttindex{THEORY} if none exists. Merging theories can cause several axioms |
|
269 |
to have the same name; {\tt get_axiom} returns an arbitrary one. |
|
270 |
||
271 |
\item[\ttindexbold{assume_ax} $thy$ $formula$] |
|
272 |
reads the {\it formula} using the syntax of $thy$, following the same |
|
273 |
conventions as axioms in a theory definition. You can thus pretend that |
|
274 |
{\it formula} is an axiom; in fact, {\tt assume_ax} returns an assumption. |
|
275 |
You can use the resulting theorem like an axiom. Note that |
|
276 |
\ttindex{result} complains about additional assumptions, but |
|
277 |
\ttindex{uresult} does not. |
|
278 |
||
279 |
For example, if {\it formula} is |
|
280 |
\hbox{\tt a=b ==> b=a} then the resulting theorem might have the form |
|
281 |
\hbox{\tt\frenchspacing ?a=?b ==> ?b=?a [!!a b. a=b ==> b=a]} |
|
282 |
\end{description} |
|
283 |
||
284 |
\subsection{Building a theory} |
|
285 |
\label{BuildingATheory} |
|
286 |
\index{theories!constructing|bold} |
|
287 |
\begin{ttbox} |
|
288 |
pure_thy: theory |
|
289 |
merge_theories: theory * theory -> theory |
|
290 |
extend_theory: theory -> string |
|
291 |
-> (class * class list) list |
|
292 |
* sort |
|
293 |
* (string list * int)list |
|
294 |
* (string list * (sort list * class))list |
|
295 |
* (string list * string)list * sext option |
|
296 |
-> (string*string)list -> theory |
|
297 |
\end{ttbox} |
|
298 |
Type \ttindex{class} is a synonym for {\tt string}; type \ttindex{sort} is |
|
299 |
a synonym for \hbox{\tt class list}. |
|
300 |
\begin{description} |
|
301 |
\item[\ttindexbold{pure_thy}] contains just the types, constants, and syntax |
|
302 |
of the meta-logic. There are no axioms: meta-level inferences are carried |
|
303 |
out by \ML\ functions. |
|
304 |
\item[\ttindexbold{merge_theories} ($thy@1$, $thy@2$)] merges the two |
|
305 |
theories $thy@1$ and $thy@2$. The resulting theory contains all types, |
|
306 |
constants and axioms of the constituent theories; its default sort is the |
|
307 |
union of the default sorts of the constituent theories. |
|
308 |
\item [\ttindexbold{extend_theory} $thy$ {\tt"}$T${\tt"} |
|
309 |
($classes$, $default$, $types$, $arities$, $consts$, $sextopt$) $rules$] |
|
310 |
\hfill\break %%% include if line is just too short |
|
311 |
is the \ML-equivalent of the following theory definition: |
|
312 |
\begin{ttbox} |
|
313 |
\(T\) = \(thy\) + |
|
314 |
classes \(c\) < \(c@1\),\(\dots\),\(c@m\) |
|
315 |
\dots |
|
316 |
default {\(d@1,\dots,d@r\)} |
|
317 |
types \(tycon@1\),\dots,\(tycon@i\) \(n\) |
|
318 |
\dots |
|
319 |
arities \(tycon@1'\),\dots,\(tycon@j'\) :: (\(s@1\),\dots,\(s@n\))\(c\) |
|
320 |
\dots |
|
321 |
consts \(b@1\),\dots,\(b@k\) :: \(\tau\) |
|
322 |
\dots |
|
323 |
rules \(name\) \(rule\) |
|
324 |
\dots |
|
325 |
end |
|
326 |
\end{ttbox} |
|
327 |
where |
|
328 |
\begin{tabular}[t]{l@{~=~}l} |
|
329 |
$classes$ & \tt[("$c$",["$c@1$",\dots,"$c@m$"]),\dots] \\ |
|
330 |
$default$ & \tt["$d@1$",\dots,"$d@r$"]\\ |
|
331 |
$types$ & \tt[([$tycon@1$,\dots,$tycon@i$], $n$),\dots] \\ |
|
332 |
$arities$ & \tt[([$tycon'@1$,\dots,$tycon'@j$], ([$s@1$,\dots,$s@n$],$c$)),\dots] |
|
333 |
\\ |
|
334 |
$consts$ & \tt[([$b@1$,\dots,$b@k$],$\tau$),\dots] \\ |
|
335 |
$rules$ & \tt[("$name$",$rule$),\dots] |
|
336 |
\end{tabular} |
|
337 |
||
338 |
If theories are defined as in \S\ref{DefiningTheories}, new syntax is added |
|
339 |
as mixfix annotations to constants. Using {\tt extend_theory}, new syntax can |
|
340 |
be added via $sextopt$ which is either {\tt None}, or {\tt Some($sext$)}. The |
|
341 |
latter case is not documented. |
|
342 |
||
343 |
$T$ identifies the theory internally. When a theory is redeclared, say to |
|
344 |
change an incorrect axiom, bindings to the old axiom may persist. Isabelle |
|
345 |
ensures that the old and new theories are not involved in the same proof. |
|
346 |
Attempting to combine different theories having the same name $T$ yields the |
|
347 |
fatal error |
|
348 |
\begin{center} \tt |
|
349 |
Attempt to merge different versions of theory: $T$ |
|
350 |
\end{center} |
|
351 |
\end{description} |
|
352 |
||
353 |
||
354 |
\subsection{Inspecting a theory} |
|
355 |
\index{theories!inspecting|bold} |
|
356 |
\begin{ttbox} |
|
357 |
print_theory : theory -> unit |
|
358 |
axioms_of : theory -> (string*thm)list |
|
359 |
parents_of : theory -> theory list |
|
360 |
sign_of : theory -> Sign.sg |
|
361 |
stamps_of_thy : theory -> string ref list |
|
362 |
\end{ttbox} |
|
363 |
These provide a simple means of viewing a theory's components. |
|
364 |
Unfortunately, there is no direct connection between a theorem and its |
|
365 |
theory. |
|
366 |
\begin{description} |
|
367 |
\item[\ttindexbold{print_theory} {\it thy}] |
|
368 |
prints the theory {\it thy\/} at the terminal as a set of identifiers. |
|
369 |
||
370 |
\item[\ttindexbold{axioms_of} $thy$] |
|
371 |
returns the axioms of~$thy$ and its ancestors. |
|
372 |
||
373 |
\item[\ttindexbold{parents_of} $thy$] |
|
374 |
returns the parents of~$thy$. This list contains zero, one or two |
|
375 |
elements, depending upon whether $thy$ is {\tt pure_thy}, |
|
376 |
\hbox{\tt extend_theory $thy$} or \hbox{\tt merge_theories ($thy@1$, $thy@2$)}. |
|
377 |
||
378 |
\item[\ttindexbold{stamps_of_thy} $thy$]\index{signatures} |
|
379 |
returns the stamps of the signature associated with~$thy$. |
|
380 |
||
381 |
\item[\ttindexbold{sign_of} $thy$] |
|
382 |
returns the signature associated with~$thy$. It is useful with functions |
|
383 |
like {\tt read_instantiate_sg}, which take a signature as an argument. |
|
384 |
\end{description} |
|
385 |
||
386 |
||
387 |
\section{Terms} |
|
388 |
\index{terms|bold} |
|
389 |
Terms belong to the \ML{} type \ttindexbold{term}, which is a concrete datatype |
|
390 |
with six constructors: there are six kinds of term. |
|
391 |
\begin{ttbox} |
|
392 |
type indexname = string * int; |
|
393 |
infix 9 $; |
|
394 |
datatype term = Const of string * typ |
|
395 |
| Free of string * typ |
|
396 |
| Var of indexname * typ |
|
397 |
| Bound of int |
|
398 |
| Abs of string * typ * term |
|
399 |
| op $ of term * term; |
|
400 |
\end{ttbox} |
|
401 |
\begin{description} |
|
402 |
\item[\ttindexbold{Const}($a$, $T$)] |
|
403 |
is the {\bf constant} with name~$a$ and type~$T$. Constants include |
|
404 |
connectives like $\land$ and $\forall$ (logical constants), as well as |
|
405 |
constants like~0 and~$Suc$. Other constants may be required to define the |
|
406 |
concrete syntax of a logic. |
|
407 |
||
408 |
\item[\ttindexbold{Free}($a$, $T$)] |
|
409 |
is the {\bf free variable} with name~$a$ and type~$T$. |
|
410 |
||
411 |
\item[\ttindexbold{Var}($v$, $T$)] |
|
412 |
is the {\bf scheme variable} with indexname~$v$ and type~$T$. An |
|
413 |
\ttindexbold{indexname} is a string paired with a non-negative index, or |
|
414 |
subscript; a term's scheme variables can be systematically renamed by |
|
415 |
incrementing their subscripts. Scheme variables are essentially free |
|
416 |
variables, but may be instantiated during unification. |
|
417 |
||
418 |
\item[\ttindexbold{Bound} $i$] |
|
419 |
is the {\bf bound variable} with de Bruijn index~$i$, which counts the |
|
420 |
number of lambdas, starting from zero, between a variable's occurrence and |
|
421 |
its binding. The representation prevents capture of variables. For more |
|
422 |
information see de Bruijn \cite{debruijn72} or |
|
423 |
Paulson~\cite[page~336]{paulson91}. |
|
424 |
||
425 |
\item[\ttindexbold{Abs}($a$, $T$, $u$)] |
|
426 |
is the {\bf abstraction} with body~$u$, and whose bound variable has |
|
427 |
name~$a$ and type~$T$. The name is used only for parsing and printing; it |
|
428 |
has no logical significance. |
|
429 |
||
430 |
\item[\tt $t$ \$ $u$] \index{$@{\tt\$}|bold} |
|
431 |
is the {\bf application} of~$t$ to~$u$. |
|
432 |
\end{description} |
|
433 |
Application is written as an infix operator in order to aid readability. |
|
434 |
For example, here is an \ML{} pattern to recognize first-order formula of |
|
435 |
the form~$A\imp B$, binding the subformulae to~$A$ and~$B$: |
|
436 |
\begin{ttbox} |
|
437 |
Const("Trueprop",_) $ (Const("op -->",_) $ A $ B) |
|
438 |
\end{ttbox} |
|
439 |
||
440 |
||
441 |
\section{Certified terms} |
|
442 |
\index{terms!certified|bold}\index{signatures} |
|
443 |
A term $t$ can be {\bf certified} under a signature to ensure that every |
|
444 |
type in~$t$ is declared in the signature and every constant in~$t$ is |
|
445 |
declared as a constant of the same type in the signature. It must be |
|
446 |
well-typed and must not have any `loose' bound variable |
|
447 |
references.\footnote{This concerns the internal representation of variable |
|
448 |
binding using de Bruijn indexes.} Meta-rules such as {\tt forall_elim} take |
|
449 |
certified terms as arguments. |
|
450 |
||
451 |
Certified terms belong to the abstract type \ttindexbold{Sign.cterm}. |
|
452 |
Elements of the type can only be created through the certification process. |
|
453 |
In case of error, Isabelle raises exception~\ttindex{TERM}\@. |
|
454 |
||
455 |
\subsection{Printing terms} |
|
456 |
\index{printing!terms|bold} |
|
457 |
\begin{ttbox} |
|
458 |
Sign.string_of_cterm : Sign.cterm -> string |
|
459 |
Sign.string_of_term : Sign.sg -> term -> string |
|
460 |
\end{ttbox} |
|
461 |
\begin{description} |
|
462 |
\item[\ttindexbold{Sign.string_of_cterm} $ct$] |
|
463 |
displays $ct$ as a string. |
|
464 |
||
465 |
\item[\ttindexbold{Sign.string_of_term} $sign$ $t$] |
|
466 |
displays $t$ as a string, using the syntax of~$sign$. |
|
467 |
\end{description} |
|
468 |
||
469 |
\subsection{Making and inspecting certified terms} |
|
470 |
\begin{ttbox} |
|
471 |
Sign.cterm_of : Sign.sg -> term -> Sign.cterm |
|
472 |
Sign.read_cterm : Sign.sg -> string * typ -> Sign.cterm |
|
473 |
Sign.rep_cterm : Sign.cterm -> \{T:typ, t:term, |
|
474 |
sign: Sign.sg, maxidx:int\} |
|
475 |
\end{ttbox} |
|
476 |
\begin{description} |
|
477 |
\item[\ttindexbold{Sign.cterm_of} $sign$ $t$] \index{signatures} |
|
478 |
certifies $t$ with respect to signature~$sign$. |
|
479 |
||
480 |
\item[\ttindexbold{Sign.read_cterm} $sign$ ($s$, $T$)] |
|
481 |
reads the string~$s$ using the syntax of~$sign$, creating a certified term. |
|
482 |
The term is checked to have type~$T$; this type also tells the parser what |
|
483 |
kind of phrase to parse. |
|
484 |
||
485 |
\item[\ttindexbold{Sign.rep_cterm} $ct$] |
|
486 |
decomposes $ct$ as a record containing its type, the term itself, its |
|
487 |
signature, and the maximum subscript of its unknowns. The type and maximum |
|
488 |
subscript are computed during certification. |
|
489 |
\end{description} |
|
490 |
||
491 |
||
492 |
\section{Types} |
|
493 |
\index{types|bold} |
|
494 |
Types belong to the \ML{} type \ttindexbold{typ}, which is a concrete |
|
495 |
datatype with three constructors. Types are classified by sorts, which are |
|
496 |
lists of classes. A class is represented by a string. |
|
497 |
\begin{ttbox} |
|
498 |
type class = string; |
|
499 |
type sort = class list; |
|
500 |
||
501 |
datatype typ = Type of string * typ list |
|
502 |
| TFree of string * sort |
|
503 |
| TVar of indexname * sort; |
|
504 |
||
505 |
infixr 5 -->; |
|
506 |
fun S --> T = Type("fun",[S,T]); |
|
507 |
\end{ttbox} |
|
508 |
\begin{description} |
|
509 |
\item[\ttindexbold{Type}($a$, $Ts$)] |
|
510 |
applies the {\bf type constructor} named~$a$ to the type operands~$Ts$. |
|
511 |
Type constructors include~\ttindexbold{fun}, the binary function space |
|
512 |
constructor, as well as nullary type constructors such |
|
513 |
as~\ttindexbold{prop}. Other type constructors may be introduced. In |
|
514 |
expressions, but not in patterns, \hbox{\tt$S$-->$T$} is a convenient |
|
515 |
shorthand for function types. |
|
516 |
||
517 |
\item[\ttindexbold{TFree}($a$, $s$)] |
|
518 |
is the {\bf free type variable} with name~$a$ and sort~$s$. |
|
519 |
||
520 |
\item[\ttindexbold{TVar}($v$, $s$)] |
|
521 |
is the {\bf scheme type variable} with indexname~$v$ and sort~$s$. Scheme |
|
522 |
type variables are essentially free type variables, but may be instantiated |
|
523 |
during unification. |
|
524 |
\end{description} |
|
525 |
||
526 |
||
527 |
\section{Certified types} |
|
528 |
\index{types!certified|bold} |
|
529 |
Certified types, which are analogous to certified terms, have type |
|
530 |
\ttindexbold{Sign.ctyp}. |
|
531 |
||
532 |
\subsection{Printing types} |
|
533 |
\index{printing!types|bold} |
|
534 |
\begin{ttbox} |
|
535 |
Sign.string_of_ctyp : Sign.ctyp -> string |
|
536 |
Sign.string_of_typ : Sign.sg -> typ -> string |
|
537 |
\end{ttbox} |
|
538 |
\begin{description} |
|
539 |
\item[\ttindexbold{Sign.string_of_ctyp} $cT$] |
|
540 |
displays $cT$ as a string. |
|
541 |
||
542 |
\item[\ttindexbold{Sign.string_of_typ} $sign$ $T$] |
|
543 |
displays $T$ as a string, using the syntax of~$sign$. |
|
544 |
\end{description} |
|
545 |
||
546 |
||
547 |
\subsection{Making and inspecting certified types} |
|
548 |
\begin{ttbox} |
|
549 |
Sign.ctyp_of : Sign.sg -> typ -> Sign.ctyp |
|
550 |
Sign.rep_ctyp : Sign.ctyp -> \{T: typ, sign: Sign.sg\} |
|
551 |
\end{ttbox} |
|
552 |
\begin{description} |
|
553 |
\item[\ttindexbold{Sign.ctyp_of} $sign$ $T$] \index{signatures} |
|
554 |
certifies $T$ with respect to signature~$sign$. |
|
555 |
||
556 |
\item[\ttindexbold{Sign.rep_ctyp} $cT$] |
|
557 |
decomposes $cT$ as a record containing the type itself and its signature. |
|
558 |
\end{description} |
|
559 |
||
560 |
\index{theories|)} |