author | clasohm |
Tue, 04 Oct 1994 13:02:16 +0100 | |
changeset 624 | 33b9b5da3e6f |
parent 478 | 838bd766d536 |
child 864 | d63b111b917a |
permissions | -rw-r--r-- |
104 | 1 |
%% $Id$ |
145 | 2 |
|
104 | 3 |
\chapter{Theories, Terms and Types} \label{theories} |
4 |
\index{theories|(}\index{signatures|bold} |
|
478 | 5 |
\index{reading!axioms|see{{\tt assume_ax}}} |
104 | 6 |
Theories organize the syntax, declarations and axioms of a mathematical |
7 |
development. They are built, starting from the Pure theory, by extending |
|
324 | 8 |
and merging existing theories. They have the \ML\ type \mltydx{theory}. |
9 |
Theory operations signal errors by raising exception \xdx{THEORY}, |
|
104 | 10 |
returning a message and a list of theories. |
11 |
||
12 |
Signatures, which contain information about sorts, types, constants and |
|
332 | 13 |
syntax, have the \ML\ type~\mltydx{Sign.sg}. For identification, each |
14 |
signature carries a unique list of \bfindex{stamps}, which are \ML\ |
|
324 | 15 |
references to strings. The strings serve as human-readable names; the |
104 | 16 |
references serve as unique identifiers. Each primitive signature has a |
17 |
single stamp. When two signatures are merged, their lists of stamps are |
|
18 |
also merged. Every theory carries a unique signature. |
|
19 |
||
20 |
Terms and types are the underlying representation of logical syntax. Their |
|
275 | 21 |
\ML\ definitions are irrelevant to naive Isabelle users. Programmers who |
22 |
wish to extend Isabelle may need to know such details, say to code a tactic |
|
23 |
that looks for subgoals of a particular form. Terms and types may be |
|
104 | 24 |
`certified' to be well-formed with respect to a given signature. |
25 |
||
324 | 26 |
|
27 |
\section{Defining theories}\label{sec:ref-defining-theories} |
|
104 | 28 |
|
29 |
Theories can be defined either using concrete syntax or by calling certain |
|
286 | 30 |
\ML{} functions (see \S\ref{BuildingATheory}). Appendix~\ref{app:TheorySyntax} |
324 | 31 |
presents the concrete syntax for theories; here is an explanation of the |
32 |
constituent parts: |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
33 |
\begin{description} |
324 | 34 |
\item[{\it theoryDef}] |
35 |
is the full definition. The new theory is called $id$. It is the union |
|
36 |
of the named {\bf parent theories}\indexbold{theories!parent}, possibly |
|
37 |
extended with new classes, etc. The basic theory, which contains only |
|
38 |
the meta-logic, is called \thydx{Pure}. |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
39 |
|
324 | 40 |
Normally each {\it name\/} is an identifier, the name of the parent |
41 |
theory. Strings can be used to document additional dependencies; see |
|
275 | 42 |
\S\ref{LoadingTheories} for details. |
324 | 43 |
|
44 |
\item[$classes$] |
|
45 |
is a series of class declarations. Declaring {\tt$id$ < $id@1$ \dots\ |
|
46 |
$id@n$} makes $id$ a subclass of the existing classes $id@1\dots |
|
47 |
id@n$. This rules out cyclic class structures. Isabelle automatically |
|
48 |
computes the transitive closure of subclass hierarchies; it is not |
|
49 |
necessary to declare {\tt c < e} in addition to {\tt c < d} and {\tt d < |
|
50 |
e}. |
|
51 |
||
52 |
\item[$default$] |
|
53 |
introduces $sort$ as the new default sort for type variables. This |
|
54 |
applies to unconstrained type variables in an input string but not to |
|
55 |
type variables created internally. If omitted, the default sort is the |
|
56 |
union of the default sorts of the parent theories. |
|
57 |
||
58 |
\item[$sort$] |
|
59 |
is a finite set of classes. A single class $id$ abbreviates the singleton |
|
60 |
set {\tt\{}$id${\tt\}}. |
|
61 |
||
62 |
\item[$types$] |
|
63 |
is a series of type declarations. Each declares a new type constructor |
|
64 |
or type synonym. An $n$-place type constructor is specified by |
|
65 |
$(\alpha@1,\dots,\alpha@n)name$, where the type variables serve only to |
|
66 |
indicate the number~$n$. |
|
67 |
||
68 |
Only 2-place type constructors can have infix status and symbolic names; |
|
69 |
an example is {\tt ('a,'b)"*"}, which expresses binary product types. |
|
70 |
||
332 | 71 |
A {\bf type synonym}\indexbold{type synonyms} is an abbreviation |
324 | 72 |
$(\alpha@1,\dots,\alpha@n)name = \mbox{\tt"}\tau\mbox{\tt"}$, where |
73 |
$name$ can be a string and $\tau$ must be enclosed in quotation marks. |
|
74 |
||
75 |
\item[$infix$] |
|
76 |
declares a type or constant to be an infix operator of priority $nat$ |
|
77 |
associating to the left ({\tt infixl}) or right ({\tt infixr}). |
|
78 |
||
79 |
\item[$arities$] |
|
80 |
is a series of arity declarations. Each assigns arities to type |
|
81 |
constructors. The $name$ must be an existing type constructor, which is |
|
273 | 82 |
given the additional arity $arity$. |
324 | 83 |
|
84 |
\item[$constDecl$] |
|
85 |
is a series of constant declarations. Each new constant $name$ is given |
|
86 |
the type specified by the $string$. The optional $mixfix$ annotations |
|
87 |
may attach concrete syntax to the constant. |
|
88 |
||
89 |
\item[$mixfix$] \index{mixfix declarations} |
|
90 |
annotations can take three forms: |
|
273 | 91 |
\begin{itemize} |
92 |
\item A mixfix template given as a $string$ of the form |
|
93 |
{\tt"}\dots{\tt\_}\dots{\tt\_}\dots{\tt"} where the $i$-th underscore |
|
324 | 94 |
indicates the position where the $i$-th argument should go. The list |
95 |
of numbers gives the priority of each argument. The final number gives |
|
96 |
the priority of the whole construct. |
|
104 | 97 |
|
324 | 98 |
\item A constant $f$ of type $\tau@1\To(\tau@2\To\tau)$ can be given {\bf |
99 |
infix} status. |
|
104 | 100 |
|
324 | 101 |
\item A constant $f$ of type $(\tau@1\To\tau@2)\To\tau$ can be given {\bf |
102 |
binder} status. The declaration {\tt binder} $\cal Q$ $p$ causes |
|
286 | 103 |
${\cal Q}\,x.F(x)$ to be treated |
104 |
like $f(F)$, where $p$ is the priority. |
|
273 | 105 |
\end{itemize} |
324 | 106 |
|
107 |
\item[$trans$] |
|
108 |
specifies syntactic translation rules. There are three forms: parse |
|
109 |
rules ({\tt =>}), print rules ({\tt <=}), and parse/print rules ({\tt ==}). |
|
110 |
||
111 |
\item[$rule$] |
|
112 |
is a series of rule declarations. Each has a name $id$ and the |
|
113 |
formula is given by the $string$. Rule names must be distinct. |
|
114 |
||
115 |
\item[$ml$] \index{*ML section} |
|
116 |
consists of \ML\ code, typically for parse and print translations. |
|
104 | 117 |
\end{description} |
324 | 118 |
% |
119 |
Chapter~\ref{chap:syntax} explains mixfix declarations, translation rules |
|
120 |
and the {\tt ML} section in more detail. |
|
145 | 121 |
|
122 |
||
275 | 123 |
\subsection{*Classes and arities} |
324 | 124 |
\index{classes!context conditions}\index{arities!context conditions} |
145 | 125 |
|
286 | 126 |
In order to guarantee principal types~\cite{nipkow-prehofer}, |
324 | 127 |
arity declarations must obey two conditions: |
145 | 128 |
\begin{itemize} |
286 | 129 |
\item There must be no two declarations $ty :: (\vec{r})c$ and $ty :: |
130 |
(\vec{s})c$ with $\vec{r} \neq \vec{s}$. For example, the following is |
|
131 |
forbidden: |
|
145 | 132 |
\begin{ttbox} |
275 | 133 |
types 'a ty |
145 | 134 |
arities ty :: ({\ttlbrace}logic{\ttrbrace}) logic |
135 |
ty :: ({\ttlbrace}{\ttrbrace})logic |
|
136 |
\end{ttbox} |
|
286 | 137 |
|
145 | 138 |
\item If there are two declarations $ty :: (s@1,\dots,s@n)c$ and $ty :: |
139 |
(s@1',\dots,s@n')c'$ such that $c' < c$ then $s@i' \preceq s@i$ must hold |
|
140 |
for $i=1,\dots,n$. The relationship $\preceq$, defined as |
|
141 |
\[ s' \preceq s \iff \forall c\in s. \exists c'\in s'.~ c'\le c, \] |
|
142 |
expresses that the set of types represented by $s'$ is a subset of the set of |
|
286 | 143 |
types represented by $s$. For example, the following is forbidden: |
145 | 144 |
\begin{ttbox} |
145 |
classes term < logic |
|
275 | 146 |
types 'a ty |
145 | 147 |
arities ty :: ({\ttlbrace}logic{\ttrbrace})logic |
148 |
ty :: ({\ttlbrace}{\ttrbrace})term |
|
149 |
\end{ttbox} |
|
286 | 150 |
|
145 | 151 |
\end{itemize} |
152 |
||
104 | 153 |
|
324 | 154 |
\section{Loading a new theory}\label{LoadingTheories} |
155 |
\index{theories!loading}\index{files!reading} |
|
286 | 156 |
\begin{ttbox} |
157 |
use_thy : string -> unit |
|
158 |
time_use_thy : string -> unit |
|
159 |
loadpath : string list ref \hfill{\bf initially {\tt["."]}} |
|
160 |
delete_tmpfiles : bool ref \hfill{\bf initially true} |
|
161 |
\end{ttbox} |
|
162 |
||
324 | 163 |
\begin{ttdescription} |
286 | 164 |
\item[\ttindexbold{use_thy} $thyname$] |
165 |
reads the theory $thyname$ and creates an \ML{} structure as described below. |
|
275 | 166 |
|
286 | 167 |
\item[\ttindexbold{time_use_thy} $thyname$] |
168 |
calls {\tt use_thy} $thyname$ and reports the time taken. |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
169 |
|
286 | 170 |
\item[\ttindexbold{loadpath}] |
171 |
contains a list of directories to search when locating the files that |
|
172 |
define a theory. This list is only used if the theory name in {\tt |
|
173 |
use_thy} does not specify the path explicitly. |
|
174 |
||
324 | 175 |
\item[\ttindexbold{delete_tmpfiles} := false;] |
286 | 176 |
suppresses the deletion of temporary files. |
324 | 177 |
\end{ttdescription} |
286 | 178 |
% |
104 | 179 |
Each theory definition must reside in a separate file. Let the file {\it |
332 | 180 |
T}{\tt.thy} contain the definition of a theory called~$T$, whose parent |
181 |
theories are $TB@1$ \dots $TB@n$. Calling \ttindexbold{use_thy}~{\tt"{\it |
|
182 |
T\/}"} reads the file {\it T}{\tt.thy}, writes a temporary \ML{} |
|
183 |
file {\tt.{\it T}.thy.ML}, and reads the latter file. Recursive {\tt |
|
286 | 184 |
use_thy} calls load those parent theories that have not been loaded |
332 | 185 |
previously; the recursive calls may continue to any depth. One {\tt use_thy} |
186 |
call can read an entire logic provided all theories are linked appropriately. |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
187 |
|
332 | 188 |
The result is an \ML\ structure~$T$ containing a component {\tt thy} for |
189 |
the new theory and components for each of the rules. The structure also |
|
190 |
contains the definitions of the {\tt ML} section, if present. The file |
|
191 |
{\tt.{\it T}.thy.ML} is then deleted if {\tt delete_tmpfiles} is set |
|
192 |
to {\tt true} and no errors occurred. |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
193 |
|
332 | 194 |
Finally the file {\it T}{\tt.ML} is read, if it exists. This file normally |
195 |
begins with the declaration {\tt open~$T$} and contains proofs involving |
|
196 |
the new theory. |
|
197 |
||
198 |
Special applications, such as \ZF's inductive definition package, construct |
|
478 | 199 |
theories directly by calling \ML\ functions. In this situation there is no |
200 |
{\tt.thy} file, only an {\tt.ML} file. The {\tt.ML} file must declare an |
|
201 |
\ML\ structure having the theory's name. See the file {\tt ZF/ex/LList.ML} |
|
202 |
for an example. Section~\ref{sec:pseudo-theories} below describes a way of |
|
203 |
linking such theories to their parents. |
|
324 | 204 |
|
205 |
\begin{warn} |
|
332 | 206 |
Temporary files are written to the current directory, which therefore must |
207 |
be writable. Isabelle inherits the current directory from the operating |
|
208 |
system; you can change it within Isabelle by typing \hbox{\tt\ \ |
|
209 |
\ttindex{cd} "{\it dir}";\ \ }. |
|
273 | 210 |
\end{warn} |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
211 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
212 |
|
324 | 213 |
\section{Reloading modified theories}\label{sec:reloading-theories} |
214 |
\indexbold{theories!reloading} |
|
286 | 215 |
\begin{ttbox} |
216 |
update : unit -> unit |
|
217 |
unlink_thy : string -> unit |
|
218 |
\end{ttbox} |
|
332 | 219 |
Changing a theory on disk often makes it necessary to reload all theories |
220 |
descended from it. However, {\tt use_thy} reads only one theory, even if |
|
221 |
some of the parent theories are out of date. In this case you should call |
|
222 |
{\tt update()}. |
|
223 |
||
286 | 224 |
Isabelle keeps track of all loaded theories and their files. If |
225 |
\ttindex{use_thy} finds that the theory to be loaded has been read before, |
|
226 |
it determines whether to reload the theory as follows. First it looks for |
|
227 |
the theory's files in their previous location. If it finds them, it |
|
228 |
compares their modification times to the internal data and stops if they |
|
229 |
are equal. If the files have been moved, {\tt use_thy} searches for them |
|
230 |
as it would for a new theory. After {\tt use_thy} reloads a theory, it |
|
231 |
marks the children as out-of-date. |
|
232 |
||
324 | 233 |
\begin{ttdescription} |
332 | 234 |
\item[\ttindexbold{update}()] |
286 | 235 |
reloads all modified theories and their descendants in the correct order. |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
236 |
|
286 | 237 |
\item[\ttindexbold{unlink_thy} $thyname$]\indexbold{theories!removing} |
238 |
informs Isabelle that theory $thyname$ no longer exists. If you delete the |
|
239 |
theory files for $thyname$ then you must execute {\tt unlink_thy}; |
|
240 |
otherwise {\tt update} will complain about a missing file. |
|
324 | 241 |
\end{ttdescription} |
286 | 242 |
|
243 |
||
332 | 244 |
\goodbreak |
324 | 245 |
\subsection{Important note for Poly/ML users}\index{Poly/{\ML} compiler} |
286 | 246 |
The theory mechanism depends upon reference variables. At the end of a |
247 |
Poly/\ML{} session, the contents of references are lost unless they are |
|
248 |
declared in the current database. Assignments to references in the {\tt |
|
249 |
Pure} database are lost, including all information about loaded theories. |
|
478 | 250 |
To avoid losing this information simply call |
286 | 251 |
\begin{ttbox} |
478 | 252 |
init_thy_reader(); |
286 | 253 |
\end{ttbox} |
478 | 254 |
when building the new database. |
286 | 255 |
|
256 |
||
332 | 257 |
\subsection{*Pseudo theories}\label{sec:pseudo-theories} |
258 |
\indexbold{theories!pseudo}% |
|
275 | 259 |
Any automatic reloading facility requires complete knowledge of all |
286 | 260 |
dependencies. Sometimes theories depend on objects created in \ML{} files |
332 | 261 |
with no associated {\tt.thy} file. These objects may be theories but they |
262 |
could also be theorems, proof procedures, etc. |
|
263 |
||
264 |
Unless such dependencies are documented, {\tt update} fails to reload these |
|
265 |
\ML{} files and the system is left in a state where some objects, such as |
|
266 |
theorems, still refer to old versions of theories. This may lead to the |
|
267 |
error |
|
275 | 268 |
\begin{ttbox} |
269 |
Attempt to merge different versions of theory: \(T\) |
|
270 |
\end{ttbox} |
|
324 | 271 |
Therefore there is a way to link theories and {\bf orphaned} \ML{} files --- |
286 | 272 |
those without associated {\tt.thy} file. |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
273 |
|
324 | 274 |
Let us assume we have an orphaned \ML{} file named {\tt orphan.ML} and a |
332 | 275 |
theory~$B$ that depends on {\tt orphan.ML} --- for example, {\tt B.ML} uses |
276 |
theorems proved in {\tt orphan.ML}. Then {\tt B.thy} should |
|
324 | 277 |
mention this dependence by means of a string: |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
278 |
\begin{ttbox} |
275 | 279 |
B = ... + "orphan" + ... |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
280 |
\end{ttbox} |
324 | 281 |
Strings stand for \ML{} files rather than {\tt.thy} files, and merely |
282 |
document additional dependencies. Thus {\tt orphan} is not a theory and is |
|
283 |
not used in building the base of theory~$B$, but {\tt orphan.ML} is loaded |
|
284 |
automatically whenever~$B$ is (re)built. |
|
275 | 285 |
|
324 | 286 |
The orphaned file may have its own dependencies. If {\tt orphan.ML} |
287 |
depends on theories $A@1$, \ldots, $A@n$, record this by creating a {\bf |
|
288 |
pseudo theory} in the file {\tt orphan.thy}: |
|
275 | 289 |
\begin{ttbox} |
290 |
orphan = A1 + \(...\) + An |
|
291 |
\end{ttbox} |
|
286 | 292 |
The resulting theory is a dummy, but it ensures that {\tt update} reloads |
275 | 293 |
theory {\it orphan} whenever it reloads one of the $A@i$. |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
294 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
295 |
For an extensive example of how this technique can be used to link over 30 |
324 | 296 |
theory files and load them by just two {\tt use_thy} calls, consult the |
297 |
source files of {\tt ZF} set theory. |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
298 |
|
104 | 299 |
|
300 |
||
301 |
\section{Basic operations on theories} |
|
302 |
\subsection{Extracting an axiom from a theory} |
|
324 | 303 |
\index{theories!axioms of}\index{axioms!extracting} |
104 | 304 |
\begin{ttbox} |
305 |
get_axiom: theory -> string -> thm |
|
306 |
assume_ax: theory -> string -> thm |
|
307 |
\end{ttbox} |
|
324 | 308 |
\begin{ttdescription} |
104 | 309 |
\item[\ttindexbold{get_axiom} $thy$ $name$] |
310 |
returns an axiom with the given $name$ from $thy$, raising exception |
|
324 | 311 |
\xdx{THEORY} if none exists. Merging theories can cause several axioms |
104 | 312 |
to have the same name; {\tt get_axiom} returns an arbitrary one. |
313 |
||
314 |
\item[\ttindexbold{assume_ax} $thy$ $formula$] |
|
286 | 315 |
reads the {\it formula} using the syntax of $thy$, following the same |
316 |
conventions as axioms in a theory definition. You can thus pretend that |
|
317 |
{\it formula} is an axiom and use the resulting theorem like an axiom. |
|
318 |
Actually {\tt assume_ax} returns an assumption; \ttindex{result} |
|
319 |
complains about additional assumptions, but \ttindex{uresult} does not. |
|
104 | 320 |
|
321 |
For example, if {\it formula} is |
|
332 | 322 |
\hbox{\tt a=b ==> b=a} then the resulting theorem has the form |
323 |
\hbox{\verb'?a=?b ==> ?b=?a [!!a b. a=b ==> b=a]'} |
|
324 | 324 |
\end{ttdescription} |
104 | 325 |
|
286 | 326 |
\subsection{Building a theory} |
327 |
\label{BuildingATheory} |
|
328 |
\index{theories!constructing|bold} |
|
329 |
\begin{ttbox} |
|
332 | 330 |
pure_thy : theory |
331 |
merge_theories : theory * theory -> theory |
|
286 | 332 |
\end{ttbox} |
324 | 333 |
\begin{ttdescription} |
286 | 334 |
\item[\ttindexbold{pure_thy}] contains just the types, constants, and syntax |
335 |
of the meta-logic. There are no axioms: meta-level inferences are carried |
|
336 |
out by \ML\ functions. |
|
337 |
\item[\ttindexbold{merge_theories} ($thy@1$, $thy@2$)] merges the two |
|
338 |
theories $thy@1$ and $thy@2$. The resulting theory contains all types, |
|
339 |
constants and axioms of the constituent theories; its default sort is the |
|
340 |
union of the default sorts of the constituent theories. |
|
478 | 341 |
%\item [\ttindexbold{extend_theory} $thy$ {\tt"}$T${\tt"} $\cdots$] extends |
342 |
% the theory $thy$ with new types, constants, etc. $T$ identifies the theory |
|
343 |
% internally. When a theory is redeclared, say to change an incorrect axiom, |
|
344 |
% bindings to the old axiom may persist. Isabelle ensures that the old and |
|
345 |
% new theories are not involved in the same proof. Attempting to combine |
|
346 |
% different theories having the same name $T$ yields the fatal error |
|
347 |
%extend_theory : theory -> string -> \(\cdots\) -> theory |
|
286 | 348 |
\begin{ttbox} |
349 |
Attempt to merge different versions of theory: \(T\) |
|
350 |
\end{ttbox} |
|
324 | 351 |
\end{ttdescription} |
286 | 352 |
|
275 | 353 |
%\item [\ttindexbold{extend_theory} $thy$ {\tt"}$T${\tt"} |
354 |
% ($classes$, $default$, $types$, $arities$, $consts$, $sextopt$) $rules$] |
|
355 |
%\hfill\break %%% include if line is just too short |
|
286 | 356 |
%is the \ML{} equivalent of the following theory definition: |
275 | 357 |
%\begin{ttbox} |
358 |
%\(T\) = \(thy\) + |
|
359 |
%classes \(c\) < \(c@1\),\(\dots\),\(c@m\) |
|
360 |
% \dots |
|
361 |
%default {\(d@1,\dots,d@r\)} |
|
362 |
%types \(tycon@1\),\dots,\(tycon@i\) \(n\) |
|
363 |
% \dots |
|
364 |
%arities \(tycon@1'\),\dots,\(tycon@j'\) :: (\(s@1\),\dots,\(s@n\))\(c\) |
|
365 |
% \dots |
|
366 |
%consts \(b@1\),\dots,\(b@k\) :: \(\tau\) |
|
367 |
% \dots |
|
368 |
%rules \(name\) \(rule\) |
|
369 |
% \dots |
|
370 |
%end |
|
371 |
%\end{ttbox} |
|
372 |
%where |
|
373 |
%\begin{tabular}[t]{l@{~=~}l} |
|
374 |
%$classes$ & \tt[("$c$",["$c@1$",\dots,"$c@m$"]),\dots] \\ |
|
375 |
%$default$ & \tt["$d@1$",\dots,"$d@r$"]\\ |
|
376 |
%$types$ & \tt[([$tycon@1$,\dots,$tycon@i$], $n$),\dots] \\ |
|
377 |
%$arities$ & \tt[([$tycon'@1$,\dots,$tycon'@j$], ([$s@1$,\dots,$s@n$],$c$)),\dots] |
|
378 |
%\\ |
|
379 |
%$consts$ & \tt[([$b@1$,\dots,$b@k$],$\tau$),\dots] \\ |
|
380 |
%$rules$ & \tt[("$name$",$rule$),\dots] |
|
381 |
%\end{tabular} |
|
104 | 382 |
|
383 |
||
384 |
\subsection{Inspecting a theory} |
|
385 |
\index{theories!inspecting|bold} |
|
386 |
\begin{ttbox} |
|
387 |
print_theory : theory -> unit |
|
388 |
axioms_of : theory -> (string*thm)list |
|
389 |
parents_of : theory -> theory list |
|
390 |
sign_of : theory -> Sign.sg |
|
391 |
stamps_of_thy : theory -> string ref list |
|
392 |
\end{ttbox} |
|
393 |
These provide a simple means of viewing a theory's components. |
|
394 |
Unfortunately, there is no direct connection between a theorem and its |
|
395 |
theory. |
|
324 | 396 |
\begin{ttdescription} |
104 | 397 |
\item[\ttindexbold{print_theory} {\it thy}] |
398 |
prints the theory {\it thy\/} at the terminal as a set of identifiers. |
|
399 |
||
400 |
\item[\ttindexbold{axioms_of} $thy$] |
|
401 |
returns the axioms of~$thy$ and its ancestors. |
|
402 |
||
403 |
\item[\ttindexbold{parents_of} $thy$] |
|
478 | 404 |
returns the complete list of ancestors of~$thy$. |
104 | 405 |
|
406 |
\item[\ttindexbold{stamps_of_thy} $thy$]\index{signatures} |
|
332 | 407 |
returns the \rmindex{stamps} of the signature associated with~$thy$. |
104 | 408 |
|
409 |
\item[\ttindexbold{sign_of} $thy$] |
|
410 |
returns the signature associated with~$thy$. It is useful with functions |
|
411 |
like {\tt read_instantiate_sg}, which take a signature as an argument. |
|
324 | 412 |
\end{ttdescription} |
104 | 413 |
|
414 |
||
415 |
\section{Terms} |
|
416 |
\index{terms|bold} |
|
324 | 417 |
Terms belong to the \ML\ type \mltydx{term}, which is a concrete datatype |
104 | 418 |
with six constructors: there are six kinds of term. |
419 |
\begin{ttbox} |
|
420 |
type indexname = string * int; |
|
421 |
infix 9 $; |
|
422 |
datatype term = Const of string * typ |
|
423 |
| Free of string * typ |
|
424 |
| Var of indexname * typ |
|
425 |
| Bound of int |
|
426 |
| Abs of string * typ * term |
|
427 |
| op $ of term * term; |
|
428 |
\end{ttbox} |
|
324 | 429 |
\begin{ttdescription} |
430 |
\item[\ttindexbold{Const}($a$, $T$)] \index{constants|bold} |
|
286 | 431 |
is the {\bf constant} with name~$a$ and type~$T$. Constants include |
432 |
connectives like $\land$ and $\forall$ as well as constants like~0 |
|
433 |
and~$Suc$. Other constants may be required to define a logic's concrete |
|
434 |
syntax. |
|
104 | 435 |
|
324 | 436 |
\item[\ttindexbold{Free}($a$, $T$)] \index{variables!free|bold} |
437 |
is the {\bf free variable} with name~$a$ and type~$T$. |
|
104 | 438 |
|
324 | 439 |
\item[\ttindexbold{Var}($v$, $T$)] \index{unknowns|bold} |
440 |
is the {\bf scheme variable} with indexname~$v$ and type~$T$. An |
|
441 |
\mltydx{indexname} is a string paired with a non-negative index, or |
|
442 |
subscript; a term's scheme variables can be systematically renamed by |
|
443 |
incrementing their subscripts. Scheme variables are essentially free |
|
444 |
variables, but may be instantiated during unification. |
|
104 | 445 |
|
324 | 446 |
\item[\ttindexbold{Bound} $i$] \index{variables!bound|bold} |
447 |
is the {\bf bound variable} with de Bruijn index~$i$, which counts the |
|
448 |
number of lambdas, starting from zero, between a variable's occurrence |
|
449 |
and its binding. The representation prevents capture of variables. For |
|
450 |
more information see de Bruijn \cite{debruijn72} or |
|
451 |
Paulson~\cite[page~336]{paulson91}. |
|
104 | 452 |
|
324 | 453 |
\item[\ttindexbold{Abs}($a$, $T$, $u$)] |
454 |
\index{lambda abs@$\lambda$-abstractions|bold} |
|
455 |
is the $\lambda$-{\bf abstraction} with body~$u$, and whose bound |
|
456 |
variable has name~$a$ and type~$T$. The name is used only for parsing |
|
457 |
and printing; it has no logical significance. |
|
104 | 458 |
|
324 | 459 |
\item[$t$ \$ $u$] \index{$@{\tt\$}|bold} \index{function applications|bold} |
104 | 460 |
is the {\bf application} of~$t$ to~$u$. |
324 | 461 |
\end{ttdescription} |
286 | 462 |
Application is written as an infix operator to aid readability. |
332 | 463 |
Here is an \ML\ pattern to recognize \FOL{} formulae of |
104 | 464 |
the form~$A\imp B$, binding the subformulae to~$A$ and~$B$: |
465 |
\begin{ttbox} |
|
466 |
Const("Trueprop",_) $ (Const("op -->",_) $ A $ B) |
|
467 |
\end{ttbox} |
|
468 |
||
469 |
||
324 | 470 |
\section{Variable binding} |
286 | 471 |
\begin{ttbox} |
472 |
loose_bnos : term -> int list |
|
473 |
incr_boundvars : int -> term -> term |
|
474 |
abstract_over : term*term -> term |
|
475 |
variant_abs : string * typ * term -> string * term |
|
476 |
aconv : term*term -> bool\hfill{\bf infix} |
|
477 |
\end{ttbox} |
|
478 |
These functions are all concerned with the de Bruijn representation of |
|
479 |
bound variables. |
|
324 | 480 |
\begin{ttdescription} |
286 | 481 |
\item[\ttindexbold{loose_bnos} $t$] |
482 |
returns the list of all dangling bound variable references. In |
|
483 |
particular, {\tt Bound~0} is loose unless it is enclosed in an |
|
484 |
abstraction. Similarly {\tt Bound~1} is loose unless it is enclosed in |
|
485 |
at least two abstractions; if enclosed in just one, the list will contain |
|
486 |
the number 0. A well-formed term does not contain any loose variables. |
|
487 |
||
488 |
\item[\ttindexbold{incr_boundvars} $j$] |
|
332 | 489 |
increases a term's dangling bound variables by the offset~$j$. This is |
286 | 490 |
required when moving a subterm into a context where it is enclosed by a |
491 |
different number of abstractions. Bound variables with a matching |
|
492 |
abstraction are unaffected. |
|
493 |
||
494 |
\item[\ttindexbold{abstract_over} $(v,t)$] |
|
495 |
forms the abstraction of~$t$ over~$v$, which may be any well-formed term. |
|
496 |
It replaces every occurrence of \(v\) by a {\tt Bound} variable with the |
|
497 |
correct index. |
|
498 |
||
499 |
\item[\ttindexbold{variant_abs} $(a,T,u)$] |
|
500 |
substitutes into $u$, which should be the body of an abstraction. |
|
501 |
It replaces each occurrence of the outermost bound variable by a free |
|
502 |
variable. The free variable has type~$T$ and its name is a variant |
|
332 | 503 |
of~$a$ chosen to be distinct from all constants and from all variables |
286 | 504 |
free in~$u$. |
505 |
||
506 |
\item[$t$ \ttindexbold{aconv} $u$] |
|
507 |
tests whether terms~$t$ and~$u$ are \(\alpha\)-convertible: identical up |
|
508 |
to renaming of bound variables. |
|
509 |
\begin{itemize} |
|
510 |
\item |
|
511 |
Two constants, {\tt Free}s, or {\tt Var}s are \(\alpha\)-convertible |
|
512 |
if their names and types are equal. |
|
513 |
(Variables having the same name but different types are thus distinct. |
|
514 |
This confusing situation should be avoided!) |
|
515 |
\item |
|
516 |
Two bound variables are \(\alpha\)-convertible |
|
517 |
if they have the same number. |
|
518 |
\item |
|
519 |
Two abstractions are \(\alpha\)-convertible |
|
520 |
if their bodies are, and their bound variables have the same type. |
|
521 |
\item |
|
522 |
Two applications are \(\alpha\)-convertible |
|
523 |
if the corresponding subterms are. |
|
524 |
\end{itemize} |
|
525 |
||
324 | 526 |
\end{ttdescription} |
286 | 527 |
|
528 |
\section{Certified terms}\index{terms!certified|bold}\index{signatures} |
|
104 | 529 |
A term $t$ can be {\bf certified} under a signature to ensure that every |
530 |
type in~$t$ is declared in the signature and every constant in~$t$ is |
|
531 |
declared as a constant of the same type in the signature. It must be |
|
286 | 532 |
well-typed and its use of bound variables must be well-formed. Meta-rules |
533 |
such as {\tt forall_elim} take certified terms as arguments. |
|
104 | 534 |
|
324 | 535 |
Certified terms belong to the abstract type \mltydx{cterm}. |
104 | 536 |
Elements of the type can only be created through the certification process. |
537 |
In case of error, Isabelle raises exception~\ttindex{TERM}\@. |
|
538 |
||
539 |
\subsection{Printing terms} |
|
324 | 540 |
\index{terms!printing of} |
104 | 541 |
\begin{ttbox} |
275 | 542 |
string_of_cterm : cterm -> string |
104 | 543 |
Sign.string_of_term : Sign.sg -> term -> string |
544 |
\end{ttbox} |
|
324 | 545 |
\begin{ttdescription} |
275 | 546 |
\item[\ttindexbold{string_of_cterm} $ct$] |
104 | 547 |
displays $ct$ as a string. |
548 |
||
549 |
\item[\ttindexbold{Sign.string_of_term} $sign$ $t$] |
|
550 |
displays $t$ as a string, using the syntax of~$sign$. |
|
324 | 551 |
\end{ttdescription} |
104 | 552 |
|
553 |
\subsection{Making and inspecting certified terms} |
|
554 |
\begin{ttbox} |
|
275 | 555 |
cterm_of : Sign.sg -> term -> cterm |
556 |
read_cterm : Sign.sg -> string * typ -> cterm |
|
557 |
rep_cterm : cterm -> \{T:typ, t:term, sign:Sign.sg, maxidx:int\} |
|
104 | 558 |
\end{ttbox} |
324 | 559 |
\begin{ttdescription} |
275 | 560 |
\item[\ttindexbold{cterm_of} $sign$ $t$] \index{signatures} |
104 | 561 |
certifies $t$ with respect to signature~$sign$. |
562 |
||
275 | 563 |
\item[\ttindexbold{read_cterm} $sign$ ($s$, $T$)] |
104 | 564 |
reads the string~$s$ using the syntax of~$sign$, creating a certified term. |
565 |
The term is checked to have type~$T$; this type also tells the parser what |
|
566 |
kind of phrase to parse. |
|
567 |
||
275 | 568 |
\item[\ttindexbold{rep_cterm} $ct$] |
104 | 569 |
decomposes $ct$ as a record containing its type, the term itself, its |
570 |
signature, and the maximum subscript of its unknowns. The type and maximum |
|
571 |
subscript are computed during certification. |
|
324 | 572 |
\end{ttdescription} |
104 | 573 |
|
574 |
||
286 | 575 |
\section{Types}\index{types|bold} |
324 | 576 |
Types belong to the \ML\ type \mltydx{typ}, which is a concrete |
286 | 577 |
datatype with three constructor functions. These correspond to type |
578 |
constructors, free type variables and schematic type variables. Types are |
|
579 |
classified by sorts, which are lists of classes. A class is represented by |
|
580 |
a string. |
|
104 | 581 |
\begin{ttbox} |
582 |
type class = string; |
|
583 |
type sort = class list; |
|
584 |
||
585 |
datatype typ = Type of string * typ list |
|
586 |
| TFree of string * sort |
|
587 |
| TVar of indexname * sort; |
|
588 |
||
589 |
infixr 5 -->; |
|
590 |
fun S --> T = Type("fun",[S,T]); |
|
591 |
\end{ttbox} |
|
324 | 592 |
\begin{ttdescription} |
593 |
\item[\ttindexbold{Type}($a$, $Ts$)] \index{type constructors|bold} |
|
594 |
applies the {\bf type constructor} named~$a$ to the type operands~$Ts$. |
|
595 |
Type constructors include~\tydx{fun}, the binary function space |
|
596 |
constructor, as well as nullary type constructors such as~\tydx{prop}. |
|
597 |
Other type constructors may be introduced. In expressions, but not in |
|
598 |
patterns, \hbox{\tt$S$-->$T$} is a convenient shorthand for function |
|
599 |
types. |
|
104 | 600 |
|
324 | 601 |
\item[\ttindexbold{TFree}($a$, $s$)] \index{type variables|bold} |
602 |
is the {\bf type variable} with name~$a$ and sort~$s$. |
|
104 | 603 |
|
324 | 604 |
\item[\ttindexbold{TVar}($v$, $s$)] \index{type unknowns|bold} |
605 |
is the {\bf type unknown} with indexname~$v$ and sort~$s$. |
|
606 |
Type unknowns are essentially free type variables, but may be |
|
607 |
instantiated during unification. |
|
608 |
\end{ttdescription} |
|
104 | 609 |
|
610 |
||
611 |
\section{Certified types} |
|
612 |
\index{types!certified|bold} |
|
613 |
Certified types, which are analogous to certified terms, have type |
|
275 | 614 |
\ttindexbold{ctyp}. |
104 | 615 |
|
616 |
\subsection{Printing types} |
|
324 | 617 |
\index{types!printing of} |
104 | 618 |
\begin{ttbox} |
275 | 619 |
string_of_ctyp : ctyp -> string |
104 | 620 |
Sign.string_of_typ : Sign.sg -> typ -> string |
621 |
\end{ttbox} |
|
324 | 622 |
\begin{ttdescription} |
275 | 623 |
\item[\ttindexbold{string_of_ctyp} $cT$] |
104 | 624 |
displays $cT$ as a string. |
625 |
||
626 |
\item[\ttindexbold{Sign.string_of_typ} $sign$ $T$] |
|
627 |
displays $T$ as a string, using the syntax of~$sign$. |
|
324 | 628 |
\end{ttdescription} |
104 | 629 |
|
630 |
||
631 |
\subsection{Making and inspecting certified types} |
|
632 |
\begin{ttbox} |
|
275 | 633 |
ctyp_of : Sign.sg -> typ -> ctyp |
634 |
rep_ctyp : ctyp -> \{T: typ, sign: Sign.sg\} |
|
104 | 635 |
\end{ttbox} |
324 | 636 |
\begin{ttdescription} |
275 | 637 |
\item[\ttindexbold{ctyp_of} $sign$ $T$] \index{signatures} |
104 | 638 |
certifies $T$ with respect to signature~$sign$. |
639 |
||
275 | 640 |
\item[\ttindexbold{rep_ctyp} $cT$] |
104 | 641 |
decomposes $cT$ as a record containing the type itself and its signature. |
324 | 642 |
\end{ttdescription} |
104 | 643 |
|
644 |
\index{theories|)} |