author | paulson |
Thu, 11 Jul 1996 15:00:38 +0200 | |
changeset 1846 | 763f08fb194f |
parent 1650 | a4ed2655b08c |
child 1880 | 78c4b3ddba6c |
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 |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
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 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
29 |
Theories are usually defined using theory definition files (which have a name |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
30 |
suffix {\tt .thy}). There is also a low level interface provided by certain |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
31 |
\ML{} functions (see \S\ref{BuildingATheory}). |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
32 |
Appendix~\ref{app:TheorySyntax} presents the concrete syntax for theory |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
33 |
definitions; here is an explanation of the constituent parts: |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
34 |
\begin{description} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
35 |
\item[{\it theoryDef}] |
324 | 36 |
is the full definition. The new theory is called $id$. It is the union |
37 |
of the named {\bf parent theories}\indexbold{theories!parent}, possibly |
|
38 |
extended with new classes, etc. The basic theory, which contains only |
|
39 |
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
|
40 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
41 |
Normally each {\it name\/} is an identifier, the name of the parent theory. |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
42 |
Quoted strings can be used to document additional file dependencies; see |
275 | 43 |
\S\ref{LoadingTheories} for details. |
324 | 44 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
45 |
\item[$classes$] |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
46 |
is a series of class declarations. Declaring {\tt$id$ < $id@1$ \dots\ |
324 | 47 |
$id@n$} makes $id$ a subclass of the existing classes $id@1\dots |
48 |
id@n$. This rules out cyclic class structures. Isabelle automatically |
|
49 |
computes the transitive closure of subclass hierarchies; it is not |
|
50 |
necessary to declare {\tt c < e} in addition to {\tt c < d} and {\tt d < |
|
51 |
e}. |
|
52 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
53 |
\item[$default$] |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
54 |
introduces $sort$ as the new default sort for type variables. This applies |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
55 |
to unconstrained type variables in an input string but not to type |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
56 |
variables created internally. If omitted, the default sort is the listwise |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
57 |
union of the default sorts of the parent theories (i.e.\ their logical |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
58 |
intersection). |
324 | 59 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
60 |
\item[$sort$] |
324 | 61 |
is a finite set of classes. A single class $id$ abbreviates the singleton |
62 |
set {\tt\{}$id${\tt\}}. |
|
63 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
64 |
\item[$types$] |
324 | 65 |
is a series of type declarations. Each declares a new type constructor |
66 |
or type synonym. An $n$-place type constructor is specified by |
|
67 |
$(\alpha@1,\dots,\alpha@n)name$, where the type variables serve only to |
|
68 |
indicate the number~$n$. |
|
69 |
||
332 | 70 |
A {\bf type synonym}\indexbold{type synonyms} is an abbreviation |
1387 | 71 |
$(\alpha@1,\dots,\alpha@n)name = \tau$, where $name$ and $\tau$ can |
72 |
be strings. |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
73 |
|
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
74 |
\item[$infix$] |
324 | 75 |
declares a type or constant to be an infix operator of priority $nat$ |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
76 |
associating to the left ({\tt infixl}) or right ({\tt infixr}). Only |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
77 |
2-place type constructors can have infix status; an example is {\tt |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
78 |
('a,'b)~"*"~(infixr~20)}, which expresses binary product types. |
324 | 79 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
80 |
\item[$arities$] |
324 | 81 |
is a series of arity declarations. Each assigns arities to type |
82 |
constructors. The $name$ must be an existing type constructor, which is |
|
273 | 83 |
given the additional arity $arity$. |
324 | 84 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
85 |
\item[$constDecl$] |
324 | 86 |
is a series of constant declarations. Each new constant $name$ is given |
1380 | 87 |
the specified type. The optional $mixfix$ annotations may |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
88 |
attach concrete syntax to the constant. A variant of {\tt consts} is the |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
89 |
{\tt syntax} section\index{*syntax section}, which adds just syntax without |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
90 |
declaring logical constants. |
324 | 91 |
|
92 |
\item[$mixfix$] \index{mixfix declarations} |
|
93 |
annotations can take three forms: |
|
273 | 94 |
\begin{itemize} |
95 |
\item A mixfix template given as a $string$ of the form |
|
96 |
{\tt"}\dots{\tt\_}\dots{\tt\_}\dots{\tt"} where the $i$-th underscore |
|
324 | 97 |
indicates the position where the $i$-th argument should go. The list |
98 |
of numbers gives the priority of each argument. The final number gives |
|
99 |
the priority of the whole construct. |
|
104 | 100 |
|
324 | 101 |
\item A constant $f$ of type $\tau@1\To(\tau@2\To\tau)$ can be given {\bf |
102 |
infix} status. |
|
104 | 103 |
|
324 | 104 |
\item A constant $f$ of type $(\tau@1\To\tau@2)\To\tau$ can be given {\bf |
105 |
binder} status. The declaration {\tt binder} $\cal Q$ $p$ causes |
|
286 | 106 |
${\cal Q}\,x.F(x)$ to be treated |
107 |
like $f(F)$, where $p$ is the priority. |
|
273 | 108 |
\end{itemize} |
324 | 109 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
110 |
\item[$trans$] |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
111 |
specifies syntactic translation rules (macros). There are three forms: |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
112 |
parse rules ({\tt =>}), print rules ({\tt <=}), and parse/print rules ({\tt |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
113 |
==}). |
324 | 114 |
|
1650 | 115 |
\item[$rules$] |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
116 |
is a series of rule declarations. Each has a name $id$ and the formula is |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
117 |
given by the $string$. Rule names must be distinct within any single |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
118 |
theory file. |
324 | 119 |
|
1650 | 120 |
\item[$defs$] |
121 |
is a series of definitions. Just like $rules$, except that every $string$ |
|
122 |
must be a definition. |
|
123 |
||
124 |
\item[$constdefs$] combines the declaration of constants and their |
|
125 |
definition. The first $string$ is the type, the second the definition. |
|
126 |
||
1846 | 127 |
\item[$oracle$] links the theory to a trusted external reasoner. It is |
128 |
allowed to create theorems, but each theorem carries a proof object |
|
129 |
describing the oracle invocation. See \S\ref{sec:oracles} for details. |
|
130 |
||
324 | 131 |
\item[$ml$] \index{*ML section} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
132 |
consists of \ML\ code, typically for parse and print translation functions. |
104 | 133 |
\end{description} |
324 | 134 |
% |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
135 |
Chapters~\ref{Defining-Logics} and \ref{chap:syntax} explain mixfix |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
136 |
declarations, translation rules and the {\tt ML} section in more detail. |
145 | 137 |
|
138 |
||
275 | 139 |
\subsection{*Classes and arities} |
324 | 140 |
\index{classes!context conditions}\index{arities!context conditions} |
145 | 141 |
|
286 | 142 |
In order to guarantee principal types~\cite{nipkow-prehofer}, |
324 | 143 |
arity declarations must obey two conditions: |
145 | 144 |
\begin{itemize} |
286 | 145 |
\item There must be no two declarations $ty :: (\vec{r})c$ and $ty :: |
146 |
(\vec{s})c$ with $\vec{r} \neq \vec{s}$. For example, the following is |
|
147 |
forbidden: |
|
145 | 148 |
\begin{ttbox} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
149 |
types |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
150 |
'a ty |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
151 |
arities |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
152 |
ty :: ({\ttlbrace}logic{\ttrbrace}) logic |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
153 |
ty :: ({\ttlbrace}{\ttrbrace})logic |
145 | 154 |
\end{ttbox} |
286 | 155 |
|
145 | 156 |
\item If there are two declarations $ty :: (s@1,\dots,s@n)c$ and $ty :: |
157 |
(s@1',\dots,s@n')c'$ such that $c' < c$ then $s@i' \preceq s@i$ must hold |
|
158 |
for $i=1,\dots,n$. The relationship $\preceq$, defined as |
|
159 |
\[ s' \preceq s \iff \forall c\in s. \exists c'\in s'.~ c'\le c, \] |
|
160 |
expresses that the set of types represented by $s'$ is a subset of the set of |
|
286 | 161 |
types represented by $s$. For example, the following is forbidden: |
145 | 162 |
\begin{ttbox} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
163 |
classes |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
164 |
term < logic |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
165 |
types |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
166 |
'a ty |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
167 |
arities |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
168 |
ty :: ({\ttlbrace}logic{\ttrbrace})logic |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
169 |
ty :: ({\ttlbrace}{\ttrbrace})term |
145 | 170 |
\end{ttbox} |
286 | 171 |
|
145 | 172 |
\end{itemize} |
173 |
||
104 | 174 |
|
324 | 175 |
\section{Loading a new theory}\label{LoadingTheories} |
176 |
\index{theories!loading}\index{files!reading} |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
177 |
\begin{ttbox} |
286 | 178 |
use_thy : string -> unit |
179 |
time_use_thy : string -> unit |
|
180 |
loadpath : string list ref \hfill{\bf initially {\tt["."]}} |
|
181 |
delete_tmpfiles : bool ref \hfill{\bf initially true} |
|
182 |
\end{ttbox} |
|
183 |
||
324 | 184 |
\begin{ttdescription} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
185 |
\item[\ttindexbold{use_thy} $thyname$] |
286 | 186 |
reads the theory $thyname$ and creates an \ML{} structure as described below. |
275 | 187 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
188 |
\item[\ttindexbold{time_use_thy} $thyname$] |
286 | 189 |
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
|
190 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
191 |
\item[\ttindexbold{loadpath}] |
286 | 192 |
contains a list of directories to search when locating the files that |
193 |
define a theory. This list is only used if the theory name in {\tt |
|
194 |
use_thy} does not specify the path explicitly. |
|
195 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
196 |
\item[\ttindexbold{delete_tmpfiles} := false;] |
286 | 197 |
suppresses the deletion of temporary files. |
324 | 198 |
\end{ttdescription} |
286 | 199 |
% |
104 | 200 |
Each theory definition must reside in a separate file. Let the file {\it |
332 | 201 |
T}{\tt.thy} contain the definition of a theory called~$T$, whose parent |
202 |
theories are $TB@1$ \dots $TB@n$. Calling \ttindexbold{use_thy}~{\tt"{\it |
|
203 |
T\/}"} reads the file {\it T}{\tt.thy}, writes a temporary \ML{} |
|
204 |
file {\tt.{\it T}.thy.ML}, and reads the latter file. Recursive {\tt |
|
286 | 205 |
use_thy} calls load those parent theories that have not been loaded |
332 | 206 |
previously; the recursive calls may continue to any depth. One {\tt use_thy} |
207 |
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
|
208 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
209 |
The result is an \ML\ structure~$T$ containing at least a component {\tt thy} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
210 |
for the new theory and components for each of the rules. The structure also |
332 | 211 |
contains the definitions of the {\tt ML} section, if present. The file |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
212 |
{\tt.{\it T}.thy.ML} is then deleted if {\tt delete_tmpfiles} is set to {\tt |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
213 |
true} and no errors occurred. |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
214 |
|
332 | 215 |
Finally the file {\it T}{\tt.ML} is read, if it exists. This file normally |
216 |
begins with the declaration {\tt open~$T$} and contains proofs involving |
|
217 |
the new theory. |
|
218 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
219 |
Some applications construct theories directly by calling \ML\ functions. In |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
220 |
this situation there is no {\tt.thy} file, only an {\tt.ML} file. The |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
221 |
{\tt.ML} file must declare an \ML\ structure having the theory's name and a |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
222 |
component {\tt thy} containing the new theory object. |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
223 |
Section~\ref{sec:pseudo-theories} below describes a way of linking such |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
224 |
theories to their parents. |
324 | 225 |
|
226 |
\begin{warn} |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
227 |
Temporary files are written to the current directory, so this must be |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
228 |
writable. Isabelle inherits the current directory from the operating |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
229 |
system; you can change it within Isabelle by typing {\tt |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
230 |
cd"$dir$"}\index{*cd}. |
273 | 231 |
\end{warn} |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
232 |
|
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
233 |
|
324 | 234 |
\section{Reloading modified theories}\label{sec:reloading-theories} |
235 |
\indexbold{theories!reloading} |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
236 |
\begin{ttbox} |
286 | 237 |
update : unit -> unit |
238 |
unlink_thy : string -> unit |
|
239 |
\end{ttbox} |
|
332 | 240 |
Changing a theory on disk often makes it necessary to reload all theories |
241 |
descended from it. However, {\tt use_thy} reads only one theory, even if |
|
242 |
some of the parent theories are out of date. In this case you should call |
|
243 |
{\tt update()}. |
|
244 |
||
286 | 245 |
Isabelle keeps track of all loaded theories and their files. If |
246 |
\ttindex{use_thy} finds that the theory to be loaded has been read before, |
|
247 |
it determines whether to reload the theory as follows. First it looks for |
|
248 |
the theory's files in their previous location. If it finds them, it |
|
249 |
compares their modification times to the internal data and stops if they |
|
250 |
are equal. If the files have been moved, {\tt use_thy} searches for them |
|
251 |
as it would for a new theory. After {\tt use_thy} reloads a theory, it |
|
252 |
marks the children as out-of-date. |
|
253 |
||
324 | 254 |
\begin{ttdescription} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
255 |
\item[\ttindexbold{update}()] |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
256 |
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
|
257 |
|
286 | 258 |
\item[\ttindexbold{unlink_thy} $thyname$]\indexbold{theories!removing} |
259 |
informs Isabelle that theory $thyname$ no longer exists. If you delete the |
|
260 |
theory files for $thyname$ then you must execute {\tt unlink_thy}; |
|
261 |
otherwise {\tt update} will complain about a missing file. |
|
324 | 262 |
\end{ttdescription} |
286 | 263 |
|
264 |
||
332 | 265 |
\goodbreak |
324 | 266 |
\subsection{Important note for Poly/ML users}\index{Poly/{\ML} compiler} |
286 | 267 |
The theory mechanism depends upon reference variables. At the end of a |
268 |
Poly/\ML{} session, the contents of references are lost unless they are |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
269 |
declared in the current database. In particular, assignments to references |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
270 |
of the {\tt Pure} database are lost, including all information about loaded |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
271 |
theories. To avoid losing this information simply call |
286 | 272 |
\begin{ttbox} |
478 | 273 |
init_thy_reader(); |
286 | 274 |
\end{ttbox} |
478 | 275 |
when building the new database. |
286 | 276 |
|
277 |
||
332 | 278 |
\subsection{*Pseudo theories}\label{sec:pseudo-theories} |
279 |
\indexbold{theories!pseudo}% |
|
275 | 280 |
Any automatic reloading facility requires complete knowledge of all |
286 | 281 |
dependencies. Sometimes theories depend on objects created in \ML{} files |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
282 |
with no associated theory definition file. These objects may be theories but |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
283 |
they could also be theorems, proof procedures, etc. |
332 | 284 |
|
285 |
Unless such dependencies are documented, {\tt update} fails to reload these |
|
286 |
\ML{} files and the system is left in a state where some objects, such as |
|
287 |
theorems, still refer to old versions of theories. This may lead to the |
|
288 |
error |
|
275 | 289 |
\begin{ttbox} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
290 |
Attempt to merge different versions of theories: \dots |
275 | 291 |
\end{ttbox} |
324 | 292 |
Therefore there is a way to link theories and {\bf orphaned} \ML{} files --- |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
293 |
those not associated with a theory definition. |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
294 |
|
324 | 295 |
Let us assume we have an orphaned \ML{} file named {\tt orphan.ML} and a |
332 | 296 |
theory~$B$ that depends on {\tt orphan.ML} --- for example, {\tt B.ML} uses |
297 |
theorems proved in {\tt orphan.ML}. Then {\tt B.thy} should |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
298 |
mention this dependency as follows: |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
299 |
\begin{ttbox} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
300 |
B = \(\ldots\) + "orphan" + \(\ldots\) |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
301 |
\end{ttbox} |
1369 | 302 |
Quoted strings stand for theories which have to be loaded before the |
303 |
current theory is read but which are not used in building the base of |
|
304 |
theory~$B$. Whenever {\tt orphan} changes and is reloaded, Isabelle |
|
305 |
knows that $B$ has to be updated, too. |
|
275 | 306 |
|
1369 | 307 |
Note that it's necessary for {\tt orphan} to declare a special ML |
308 |
object of type {\tt theory} which is present in all theories. This is |
|
309 |
normally achieved by adding the file {\tt orphan.thy} to make {\tt |
|
310 |
orphan} a {\bf pseudo theory}. A minimum version of {\tt orphan.thy} |
|
311 |
would be |
|
312 |
||
313 |
\begin{ttbox} |
|
314 |
orphan = Pure |
|
315 |
\end{ttbox} |
|
316 |
||
317 |
which uses {\tt Pure} to make a dummy theory. Normally though the |
|
318 |
orphaned file has its own dependencies. If {\tt orphan.ML} depends on |
|
319 |
theories or files $A@1$, \ldots, $A@n$, record this by creating the |
|
320 |
pseudo theory in the following way: |
|
275 | 321 |
\begin{ttbox} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
322 |
orphan = \(A@1\) + \(\ldots\) + \(A@n\) |
275 | 323 |
\end{ttbox} |
1369 | 324 |
The resulting theory ensures that {\tt update} reloads {\tt orphan} |
325 |
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
|
326 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
327 |
For an extensive example of how this technique can be used to link lots of |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
328 |
theory files and load them by just a few {\tt use_thy} calls, consult the |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
329 |
sources of \ZF{} set theory. |
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
330 |
|
104 | 331 |
|
332 |
||
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
864
diff
changeset
|
333 |
\section{Basic operations on theories}\label{BasicOperationsOnTheories} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
334 |
\subsection{Extracting an axiom or theorem from a theory} |
324 | 335 |
\index{theories!axioms of}\index{axioms!extracting} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
336 |
\index{theories!theorems of}\index{theorems!extracting} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
337 |
\begin{ttbox} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
338 |
get_axiom : theory -> string -> thm |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
339 |
get_thm : theory -> string -> thm |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
340 |
assume_ax : theory -> string -> thm |
104 | 341 |
\end{ttbox} |
324 | 342 |
\begin{ttdescription} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
343 |
\item[\ttindexbold{get_axiom} $thy$ $name$] |
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
864
diff
changeset
|
344 |
returns an axiom with the given $name$ from $thy$, raising exception |
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
864
diff
changeset
|
345 |
\xdx{THEORY} if none exists. Merging theories can cause several axioms |
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
864
diff
changeset
|
346 |
to have the same name; {\tt get_axiom} returns an arbitrary one. |
104 | 347 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
348 |
\item[\ttindexbold{get_thm} $thy$ $name$] |
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
864
diff
changeset
|
349 |
is analogous to {\tt get_axiom}, but looks for a stored theorem. Like |
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
864
diff
changeset
|
350 |
{\tt get_axiom} it searches all parents of a theory if the theorem |
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
864
diff
changeset
|
351 |
is not associated with $thy$. |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
352 |
|
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
353 |
\item[\ttindexbold{assume_ax} $thy$ $formula$] |
286 | 354 |
reads the {\it formula} using the syntax of $thy$, following the same |
355 |
conventions as axioms in a theory definition. You can thus pretend that |
|
356 |
{\it formula} is an axiom and use the resulting theorem like an axiom. |
|
357 |
Actually {\tt assume_ax} returns an assumption; \ttindex{result} |
|
358 |
complains about additional assumptions, but \ttindex{uresult} does not. |
|
104 | 359 |
|
360 |
For example, if {\it formula} is |
|
332 | 361 |
\hbox{\tt a=b ==> b=a} then the resulting theorem has the form |
362 |
\hbox{\verb'?a=?b ==> ?b=?a [!!a b. a=b ==> b=a]'} |
|
324 | 363 |
\end{ttdescription} |
104 | 364 |
|
286 | 365 |
\subsection{Building a theory} |
366 |
\label{BuildingATheory} |
|
367 |
\index{theories!constructing|bold} |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
368 |
\begin{ttbox} |
332 | 369 |
pure_thy : theory |
370 |
merge_theories : theory * theory -> theory |
|
286 | 371 |
\end{ttbox} |
324 | 372 |
\begin{ttdescription} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
373 |
\item[\ttindexbold{pure_thy}] contains just the syntax and signature |
286 | 374 |
of the meta-logic. There are no axioms: meta-level inferences are carried |
375 |
out by \ML\ functions. |
|
376 |
\item[\ttindexbold{merge_theories} ($thy@1$, $thy@2$)] merges the two |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
377 |
theories $thy@1$ and $thy@2$. The resulting theory contains all of the |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
378 |
syntax, signature and axioms of the constituent theories. Merging theories |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
379 |
that contain different identification stamps of the same name fails with |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
380 |
the following message |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
381 |
\begin{ttbox} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
382 |
Attempt to merge different versions of theories: "\(T@1\)", \(\ldots\), "\(T@n\)" |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
383 |
\end{ttbox} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
384 |
This error may especially occur when a theory is redeclared --- say to |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
385 |
change an incorrect axiom --- and bindings to old versions persist. |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
386 |
Isabelle ensures that old and new theories of the same name are not |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
387 |
involved in a proof. |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
388 |
|
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
389 |
%% FIXME |
478 | 390 |
%\item [\ttindexbold{extend_theory} $thy$ {\tt"}$T${\tt"} $\cdots$] extends |
391 |
% the theory $thy$ with new types, constants, etc. $T$ identifies the theory |
|
392 |
% internally. When a theory is redeclared, say to change an incorrect axiom, |
|
393 |
% bindings to the old axiom may persist. Isabelle ensures that the old and |
|
394 |
% new theories are not involved in the same proof. Attempting to combine |
|
395 |
% different theories having the same name $T$ yields the fatal error |
|
396 |
%extend_theory : theory -> string -> \(\cdots\) -> theory |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
397 |
%\begin{ttbox} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
398 |
%Attempt to merge different versions of theory: \(T\) |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
399 |
%\end{ttbox} |
324 | 400 |
\end{ttdescription} |
286 | 401 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
402 |
%% FIXME |
275 | 403 |
%\item [\ttindexbold{extend_theory} $thy$ {\tt"}$T${\tt"} |
404 |
% ($classes$, $default$, $types$, $arities$, $consts$, $sextopt$) $rules$] |
|
405 |
%\hfill\break %%% include if line is just too short |
|
286 | 406 |
%is the \ML{} equivalent of the following theory definition: |
275 | 407 |
%\begin{ttbox} |
408 |
%\(T\) = \(thy\) + |
|
409 |
%classes \(c\) < \(c@1\),\(\dots\),\(c@m\) |
|
410 |
% \dots |
|
411 |
%default {\(d@1,\dots,d@r\)} |
|
412 |
%types \(tycon@1\),\dots,\(tycon@i\) \(n\) |
|
413 |
% \dots |
|
414 |
%arities \(tycon@1'\),\dots,\(tycon@j'\) :: (\(s@1\),\dots,\(s@n\))\(c\) |
|
415 |
% \dots |
|
416 |
%consts \(b@1\),\dots,\(b@k\) :: \(\tau\) |
|
417 |
% \dots |
|
418 |
%rules \(name\) \(rule\) |
|
419 |
% \dots |
|
420 |
%end |
|
421 |
%\end{ttbox} |
|
422 |
%where |
|
423 |
%\begin{tabular}[t]{l@{~=~}l} |
|
424 |
%$classes$ & \tt[("$c$",["$c@1$",\dots,"$c@m$"]),\dots] \\ |
|
425 |
%$default$ & \tt["$d@1$",\dots,"$d@r$"]\\ |
|
426 |
%$types$ & \tt[([$tycon@1$,\dots,$tycon@i$], $n$),\dots] \\ |
|
427 |
%$arities$ & \tt[([$tycon'@1$,\dots,$tycon'@j$], ([$s@1$,\dots,$s@n$],$c$)),\dots] |
|
428 |
%\\ |
|
429 |
%$consts$ & \tt[([$b@1$,\dots,$b@k$],$\tau$),\dots] \\ |
|
430 |
%$rules$ & \tt[("$name$",$rule$),\dots] |
|
431 |
%\end{tabular} |
|
104 | 432 |
|
433 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
434 |
\subsection{Inspecting a theory}\label{sec:inspct-thy} |
104 | 435 |
\index{theories!inspecting|bold} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
436 |
\begin{ttbox} |
104 | 437 |
print_theory : theory -> unit |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
438 |
axioms_of : theory -> (string * thm) list |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
439 |
thms_of : theory -> (string * thm) list |
104 | 440 |
parents_of : theory -> theory list |
441 |
sign_of : theory -> Sign.sg |
|
442 |
stamps_of_thy : theory -> string ref list |
|
443 |
\end{ttbox} |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
444 |
These provide means of viewing a theory's components. |
324 | 445 |
\begin{ttdescription} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
446 |
\item[\ttindexbold{print_theory} $thy$] |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
447 |
prints the contents of $thy$ excluding the syntax related parts (which are |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
448 |
shown by {\tt print_syntax}). The output is quite verbose. |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
449 |
|
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
450 |
\item[\ttindexbold{axioms_of} $thy$] |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
451 |
returns the additional axioms of the most recent extend node of~$thy$. |
104 | 452 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
453 |
\item[\ttindexbold{thms_of} $thy$] |
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
864
diff
changeset
|
454 |
returns all theorems that are associated with $thy$. |
104 | 455 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
456 |
\item[\ttindexbold{parents_of} $thy$] |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
457 |
returns the direct ancestors of~$thy$. |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
458 |
|
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
459 |
\item[\ttindexbold{sign_of} $thy$] |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
460 |
returns the signature associated with~$thy$. It is useful with functions |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
461 |
like {\tt read_instantiate_sg}, which take a signature as an argument. |
104 | 462 |
|
463 |
\item[\ttindexbold{stamps_of_thy} $thy$]\index{signatures} |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
464 |
returns the identification \rmindex{stamps} of the signature associated |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
465 |
with~$thy$. |
324 | 466 |
\end{ttdescription} |
104 | 467 |
|
468 |
||
1380 | 469 |
\section{Generating HTML documents} |
1369 | 470 |
\index{HTML|bold} |
471 |
||
472 |
Isabelle is able to make HTML documents that show a theory's |
|
473 |
definition, the theorems proved in its ML file and the relationship |
|
474 |
with its ancestors and descendants. HTML stands for Hypertext Markup |
|
475 |
Language and is used in the World Wide Web to represent text |
|
1380 | 476 |
containing images and links to other documents. Web browsers like |
477 |
{\tt xmosaic} or {\tt netscape} are used to view these documents. |
|
1369 | 478 |
|
479 |
Besides the three HTML files that are made for every theory |
|
480 |
(definition and theorems, ancestors, descendants), Isabelle stores |
|
481 |
links to all theories in an index file. These indexes are themself |
|
1380 | 482 |
linked with other indexes to represent the hierarchic structure of |
483 |
Isabelle's logics. |
|
1369 | 484 |
|
485 |
To make HTML files for logics that are part of the Isabelle |
|
1380 | 486 |
distribution, simply set the shell environment variable {\tt |
487 |
MAKE_HTML} before compiling a logic. This works for single logics as |
|
488 |
well as for the shell script {\tt make-all} (see |
|
489 |
\ref{sec:shell-scripts}). To make HTML files for {\tt FOL} using a |
|
490 |
{\tt csh} style shell, the following commands can be used: |
|
491 |
||
492 |
\begin{ttbox} |
|
493 |
cd FOL |
|
494 |
setenv MAKE_HTML |
|
495 |
make |
|
496 |
\end{ttbox} |
|
497 |
||
1497 | 498 |
The databases made this way do not differ from the ones made with an |
499 |
unset {\tt MAKE_HTML}; in particular no HTML files are written if the |
|
500 |
database is used to manually load a theory. |
|
501 |
||
502 |
As you will see below, the HTML generation is controlled by a boolean |
|
503 |
reference variable. If you want to make databases which define this |
|
504 |
variable's value as {\tt true} and where therefore HTML files are |
|
505 |
written each time {\tt use_thy} is invoked, you have to set {\tt |
|
506 |
MAKE_HTML} to ``{\tt true}'': |
|
507 |
||
508 |
\begin{ttbox} |
|
509 |
cd FOL |
|
510 |
setenv MAKE_HTML true |
|
511 |
make |
|
512 |
\end{ttbox} |
|
513 |
||
514 |
All theories loaded from within the {\tt FOL} database and all |
|
515 |
databases derived from it will now cause HTML files to be written. |
|
516 |
This behaviour can be changed by assigning a value of {\tt false} to |
|
517 |
the boolean reference variable {\tt make_html}. Be careful when making |
|
1520
5fee0fef5019
removed note about "IO exceptions" during HTML generation
clasohm
parents:
1497
diff
changeset
|
518 |
such databases publicly available since it means that your users will |
5fee0fef5019
removed note about "IO exceptions" during HTML generation
clasohm
parents:
1497
diff
changeset
|
519 |
generate HTML files though they might not intend to do so. |
1452
ee54d2c15d66
added warning for databases made with set MAKE_HTML
clasohm
parents:
1409
diff
changeset
|
520 |
|
1380 | 521 |
As some of Isabelle's logics are based on others (e.g. {\tt ZF} on |
522 |
{\tt FOL}) and because the HTML files list a theory's ancestors, you |
|
523 |
should not make HTML files for a logic if the HTML files for the base |
|
524 |
logic do not exist. Otherwise some of the hypertext links might point |
|
525 |
to non-existing documents. |
|
526 |
||
527 |
The entry point to all logics is the {\tt index.html} file located in |
|
528 |
Isabelle's main directory. You can also access a HTML version of the |
|
529 |
distribution package at |
|
1369 | 530 |
|
531 |
\begin{ttbox} |
|
532 |
http://www4.informatik.tu-muenchen.de/~nipkow/isabelle |
|
533 |
\end{ttbox} |
|
534 |
||
1380 | 535 |
|
536 |
\subsection*{Manual HTML generation} |
|
537 |
||
1551 | 538 |
To manually control the generation of HTML files the following |
539 |
commands and reference variables are used: |
|
1369 | 540 |
|
541 |
\begin{ttbox} |
|
542 |
init_html : unit -> unit |
|
543 |
make_html : bool ref |
|
544 |
finish_html : unit -> unit |
|
545 |
\end{ttbox} |
|
546 |
||
547 |
\begin{ttdescription} |
|
548 |
\item[\ttindexbold{init_html}] |
|
549 |
activates the HTML facility. It stores the current working directory |
|
1380 | 550 |
as the place where the {\tt index.html} file for all theories loaded |
551 |
afterwards will be stored. |
|
1369 | 552 |
|
553 |
\item[\ttindexbold{make_html}] |
|
1380 | 554 |
is a boolean reference variable read by {\tt use_thy} and other |
555 |
functions to decide whether HTML files should be made. After you have |
|
556 |
used {\tt init_html} you can manually change {\tt make_html}'s value |
|
557 |
to temporarily disable HTML generation. |
|
1369 | 558 |
|
559 |
\item[\ttindexbold{finish_html}] |
|
560 |
has to be called after all theories have been read that should be |
|
1380 | 561 |
listed in the current {\tt index.html} file. It reads a temporary |
1369 | 562 |
file with information about the theories read since the last use of |
563 |
{\tt init_html} and makes the {\tt index.html} file. If {\tt |
|
564 |
make_html} is {\tt false} nothing is done. |
|
565 |
||
566 |
The indexes made by this function also contain a link to the {\tt |
|
1497 | 567 |
README} file if there exists one in the directory where the index is |
1380 | 568 |
stored. If there's a {\tt README.html} file it is used instead of |
569 |
{\tt README}. |
|
1369 | 570 |
|
571 |
\end{ttdescription} |
|
572 |
||
1380 | 573 |
The above functions could be used in the following way: |
574 |
||
575 |
\begin{ttbox} |
|
576 |
init_html(); |
|
1497 | 577 |
{\out Setting path for index.html to "/home/clasohm/isabelle/HOL"} |
1380 | 578 |
use_thy "List"; |
579 |
\dots |
|
580 |
finish_html(); |
|
581 |
\end{ttbox} |
|
1369 | 582 |
|
1380 | 583 |
Please note that HTML files are made only for those theories that are |
584 |
read while {\tt make_html} is {\tt true}. These files may contain |
|
585 |
links to theories that were read with a {\tt false} {\tt make_html} |
|
586 |
and therefore point to non-existing files. |
|
587 |
||
588 |
||
589 |
\subsection*{Extending or adding a logic} |
|
590 |
||
591 |
If you add a new subdirectory to Isabelle's logics (or add a completly |
|
592 |
new logic), you would have to call {\tt init_html} at the start of every |
|
1369 | 593 |
directory's {\tt ROOT.ML} file and {\tt finish_html} at the end of |
594 |
it. This is automatically done if you use |
|
595 |
||
1380 | 596 |
\begin{ttbox}\index{use_dir} |
1369 | 597 |
use_dir : string -> unit |
598 |
\end{ttbox} |
|
599 |
||
600 |
This function takes a path as its parameter, changes the working |
|
601 |
directory, calls {\tt init_html} if {\tt make_html} is {\tt true}, |
|
602 |
executes {\tt ROOT.ML}, and calls {\tt finish_html}. The {\tt |
|
603 |
index.html} file written in this directory will be automatically |
|
604 |
linked to the first index found in the (recursively searched) |
|
605 |
superdirectories. |
|
606 |
||
1380 | 607 |
Instead of adding something like |
608 |
||
609 |
\begin{ttbox} |
|
610 |
use"ex/ROOT.ML"; |
|
611 |
\end{ttbox} |
|
612 |
||
613 |
to the logic's makefile you have to use this: |
|
614 |
||
615 |
\begin{ttbox} |
|
616 |
use_dir"ex"; |
|
617 |
\end{ttbox} |
|
618 |
||
619 |
Since {\tt use_dir} calls {\tt init_html} only if {\tt make_html} is |
|
620 |
{\tt true} the generation of HTML files depends on the value this |
|
621 |
reference variable has. It can either be inherited from the used \ML{} |
|
622 |
database or set in the makefile before {\tt use_dir} is invoked, |
|
623 |
e.g. to set it's value according to the environment variable {\tt |
|
624 |
MAKE_HTML}. |
|
625 |
||
626 |
The generated HTML files contain all theorems that were proved in the |
|
627 |
theory's \ML{} file with {\tt qed}, {\tt qed_goal} and {\tt qed_goalw}, |
|
628 |
or stored with {\tt bind_thm} and {\tt store_thm}. Additionally there |
|
629 |
is a hypertext link to the whole \ML{} file. |
|
630 |
||
1551 | 631 |
You can add section headings to the list of theorems by using |
632 |
||
633 |
\begin{ttbox}\index{use_dir} |
|
634 |
section: string -> unit |
|
635 |
\end{ttbox} |
|
636 |
||
637 |
in a theory's ML file, which converts a plain string to a HTML |
|
638 |
heading and inserts it before the next theorem proved or stored with |
|
639 |
one of the above functions. If {\tt make_html} is {\tt false} nothing |
|
640 |
is done. |
|
641 |
||
1380 | 642 |
|
643 |
\subsection*{Using someone else's database} |
|
644 |
||
645 |
To make them independent from their storage place, the HTML files only |
|
646 |
contain relative paths which are derived from absolute ones like the |
|
647 |
current working directory, {\tt gif_path} or {\tt base_path}. The |
|
648 |
latter two are reference variables which are initialized at the time |
|
649 |
when the {\tt Pure} database is made. Because you need write access |
|
650 |
for the current directory to make HTML files and therefore (probably) |
|
651 |
generate them in your home directory, the absolute {\tt base_path} is |
|
652 |
not correct if you use someone else's database or a database derived |
|
653 |
from it. |
|
654 |
||
1409 | 655 |
In that case you first should set {\tt base_path} to the value of {\em |
656 |
your} Isabelle main directory, i.e. the directory that contains the |
|
657 |
subdirectories where standard logics like {\tt FOL} and {\tt HOL} or |
|
658 |
your own logics are stored. If you do not do this, the generated HTML |
|
659 |
files will still be usable but may contain incomplete titles and lack |
|
660 |
some hypertext links. |
|
1380 | 661 |
|
662 |
It's also a good idea to set {\tt gif_path} which points to the |
|
663 |
directory containing two GIF images used in the HTML |
|
664 |
documents. Normally this is the {\tt Tools} subdirectory of Isabelle's |
|
665 |
main directory. While its value in general is still valid, your HTML |
|
666 |
files would depend on files not owned by you. This prevents you from |
|
667 |
changing the location of the HTML files (as they contain relative |
|
668 |
paths) and also causes trouble if the database's maker (re)moves the |
|
669 |
GIFs. |
|
670 |
||
1409 | 671 |
Here's what you should do before invoking {\tt init_html} using |
1380 | 672 |
someone else's \ML{} database: |
673 |
||
674 |
\begin{ttbox} |
|
675 |
base_path := "/home/smith/isabelle"; |
|
676 |
gif_path := "/home/smith/isabelle/Tools"; |
|
677 |
init_html(); |
|
678 |
\dots |
|
679 |
\end{ttbox} |
|
1369 | 680 |
|
104 | 681 |
\section{Terms} |
682 |
\index{terms|bold} |
|
324 | 683 |
Terms belong to the \ML\ type \mltydx{term}, which is a concrete datatype |
104 | 684 |
with six constructors: there are six kinds of term. |
685 |
\begin{ttbox} |
|
686 |
type indexname = string * int; |
|
687 |
infix 9 $; |
|
688 |
datatype term = Const of string * typ |
|
689 |
| Free of string * typ |
|
690 |
| Var of indexname * typ |
|
691 |
| Bound of int |
|
692 |
| Abs of string * typ * term |
|
693 |
| op $ of term * term; |
|
694 |
\end{ttbox} |
|
324 | 695 |
\begin{ttdescription} |
696 |
\item[\ttindexbold{Const}($a$, $T$)] \index{constants|bold} |
|
286 | 697 |
is the {\bf constant} with name~$a$ and type~$T$. Constants include |
698 |
connectives like $\land$ and $\forall$ as well as constants like~0 |
|
699 |
and~$Suc$. Other constants may be required to define a logic's concrete |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
700 |
syntax. |
104 | 701 |
|
324 | 702 |
\item[\ttindexbold{Free}($a$, $T$)] \index{variables!free|bold} |
703 |
is the {\bf free variable} with name~$a$ and type~$T$. |
|
104 | 704 |
|
324 | 705 |
\item[\ttindexbold{Var}($v$, $T$)] \index{unknowns|bold} |
706 |
is the {\bf scheme variable} with indexname~$v$ and type~$T$. An |
|
707 |
\mltydx{indexname} is a string paired with a non-negative index, or |
|
708 |
subscript; a term's scheme variables can be systematically renamed by |
|
709 |
incrementing their subscripts. Scheme variables are essentially free |
|
710 |
variables, but may be instantiated during unification. |
|
104 | 711 |
|
324 | 712 |
\item[\ttindexbold{Bound} $i$] \index{variables!bound|bold} |
713 |
is the {\bf bound variable} with de Bruijn index~$i$, which counts the |
|
714 |
number of lambdas, starting from zero, between a variable's occurrence |
|
715 |
and its binding. The representation prevents capture of variables. For |
|
716 |
more information see de Bruijn \cite{debruijn72} or |
|
717 |
Paulson~\cite[page~336]{paulson91}. |
|
104 | 718 |
|
324 | 719 |
\item[\ttindexbold{Abs}($a$, $T$, $u$)] |
720 |
\index{lambda abs@$\lambda$-abstractions|bold} |
|
721 |
is the $\lambda$-{\bf abstraction} with body~$u$, and whose bound |
|
722 |
variable has name~$a$ and type~$T$. The name is used only for parsing |
|
723 |
and printing; it has no logical significance. |
|
104 | 724 |
|
324 | 725 |
\item[$t$ \$ $u$] \index{$@{\tt\$}|bold} \index{function applications|bold} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
726 |
is the {\bf application} of~$t$ to~$u$. |
324 | 727 |
\end{ttdescription} |
286 | 728 |
Application is written as an infix operator to aid readability. |
332 | 729 |
Here is an \ML\ pattern to recognize \FOL{} formulae of |
104 | 730 |
the form~$A\imp B$, binding the subformulae to~$A$ and~$B$: |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
731 |
\begin{ttbox} |
104 | 732 |
Const("Trueprop",_) $ (Const("op -->",_) $ A $ B) |
733 |
\end{ttbox} |
|
734 |
||
735 |
||
324 | 736 |
\section{Variable binding} |
286 | 737 |
\begin{ttbox} |
738 |
loose_bnos : term -> int list |
|
739 |
incr_boundvars : int -> term -> term |
|
740 |
abstract_over : term*term -> term |
|
741 |
variant_abs : string * typ * term -> string * term |
|
742 |
aconv : term*term -> bool\hfill{\bf infix} |
|
743 |
\end{ttbox} |
|
744 |
These functions are all concerned with the de Bruijn representation of |
|
745 |
bound variables. |
|
324 | 746 |
\begin{ttdescription} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
747 |
\item[\ttindexbold{loose_bnos} $t$] |
286 | 748 |
returns the list of all dangling bound variable references. In |
749 |
particular, {\tt Bound~0} is loose unless it is enclosed in an |
|
750 |
abstraction. Similarly {\tt Bound~1} is loose unless it is enclosed in |
|
751 |
at least two abstractions; if enclosed in just one, the list will contain |
|
752 |
the number 0. A well-formed term does not contain any loose variables. |
|
753 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
754 |
\item[\ttindexbold{incr_boundvars} $j$] |
332 | 755 |
increases a term's dangling bound variables by the offset~$j$. This is |
286 | 756 |
required when moving a subterm into a context where it is enclosed by a |
757 |
different number of abstractions. Bound variables with a matching |
|
758 |
abstraction are unaffected. |
|
759 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
760 |
\item[\ttindexbold{abstract_over} $(v,t)$] |
286 | 761 |
forms the abstraction of~$t$ over~$v$, which may be any well-formed term. |
762 |
It replaces every occurrence of \(v\) by a {\tt Bound} variable with the |
|
763 |
correct index. |
|
764 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
765 |
\item[\ttindexbold{variant_abs} $(a,T,u)$] |
286 | 766 |
substitutes into $u$, which should be the body of an abstraction. |
767 |
It replaces each occurrence of the outermost bound variable by a free |
|
768 |
variable. The free variable has type~$T$ and its name is a variant |
|
332 | 769 |
of~$a$ chosen to be distinct from all constants and from all variables |
286 | 770 |
free in~$u$. |
771 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
772 |
\item[$t$ \ttindexbold{aconv} $u$] |
286 | 773 |
tests whether terms~$t$ and~$u$ are \(\alpha\)-convertible: identical up |
774 |
to renaming of bound variables. |
|
775 |
\begin{itemize} |
|
776 |
\item |
|
777 |
Two constants, {\tt Free}s, or {\tt Var}s are \(\alpha\)-convertible |
|
778 |
if their names and types are equal. |
|
779 |
(Variables having the same name but different types are thus distinct. |
|
780 |
This confusing situation should be avoided!) |
|
781 |
\item |
|
782 |
Two bound variables are \(\alpha\)-convertible |
|
783 |
if they have the same number. |
|
784 |
\item |
|
785 |
Two abstractions are \(\alpha\)-convertible |
|
786 |
if their bodies are, and their bound variables have the same type. |
|
787 |
\item |
|
788 |
Two applications are \(\alpha\)-convertible |
|
789 |
if the corresponding subterms are. |
|
790 |
\end{itemize} |
|
791 |
||
324 | 792 |
\end{ttdescription} |
286 | 793 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
794 |
\section{Certified terms}\index{terms!certified|bold}\index{signatures} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
795 |
A term $t$ can be {\bf certified} under a signature to ensure that every type |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
796 |
in~$t$ is well-formed and every constant in~$t$ is a type instance of a |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
797 |
constant declared in the signature. The term must be well-typed and its use |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
798 |
of bound variables must be well-formed. Meta-rules such as {\tt forall_elim} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
799 |
take certified terms as arguments. |
104 | 800 |
|
324 | 801 |
Certified terms belong to the abstract type \mltydx{cterm}. |
104 | 802 |
Elements of the type can only be created through the certification process. |
803 |
In case of error, Isabelle raises exception~\ttindex{TERM}\@. |
|
804 |
||
805 |
\subsection{Printing terms} |
|
324 | 806 |
\index{terms!printing of} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
807 |
\begin{ttbox} |
275 | 808 |
string_of_cterm : cterm -> string |
104 | 809 |
Sign.string_of_term : Sign.sg -> term -> string |
810 |
\end{ttbox} |
|
324 | 811 |
\begin{ttdescription} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
812 |
\item[\ttindexbold{string_of_cterm} $ct$] |
104 | 813 |
displays $ct$ as a string. |
814 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
815 |
\item[\ttindexbold{Sign.string_of_term} $sign$ $t$] |
104 | 816 |
displays $t$ as a string, using the syntax of~$sign$. |
324 | 817 |
\end{ttdescription} |
104 | 818 |
|
819 |
\subsection{Making and inspecting certified terms} |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
820 |
\begin{ttbox} |
275 | 821 |
cterm_of : Sign.sg -> term -> cterm |
822 |
read_cterm : Sign.sg -> string * typ -> cterm |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
823 |
cert_axm : Sign.sg -> string * term -> string * term |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
824 |
read_axm : Sign.sg -> string * string -> string * term |
275 | 825 |
rep_cterm : cterm -> \{T:typ, t:term, sign:Sign.sg, maxidx:int\} |
104 | 826 |
\end{ttbox} |
324 | 827 |
\begin{ttdescription} |
275 | 828 |
\item[\ttindexbold{cterm_of} $sign$ $t$] \index{signatures} |
104 | 829 |
certifies $t$ with respect to signature~$sign$. |
830 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
831 |
\item[\ttindexbold{read_cterm} $sign$ ($s$, $T$)] |
104 | 832 |
reads the string~$s$ using the syntax of~$sign$, creating a certified term. |
833 |
The term is checked to have type~$T$; this type also tells the parser what |
|
834 |
kind of phrase to parse. |
|
835 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
836 |
\item[\ttindexbold{cert_axm} $sign$ ($name$, $t$)] |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
837 |
certifies $t$ with respect to $sign$ as a meta-proposition and converts all |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
838 |
exceptions to an error, including the final message |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
839 |
\begin{ttbox} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
840 |
The error(s) above occurred in axiom "\(name\)" |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
841 |
\end{ttbox} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
842 |
|
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
843 |
\item[\ttindexbold{read_axm} $sign$ ($name$, $s$)] |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
844 |
similar to {\tt cert_axm}, but first reads the string $s$ using the syntax of |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
845 |
$sign$. |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
846 |
|
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
847 |
\item[\ttindexbold{rep_cterm} $ct$] |
104 | 848 |
decomposes $ct$ as a record containing its type, the term itself, its |
849 |
signature, and the maximum subscript of its unknowns. The type and maximum |
|
850 |
subscript are computed during certification. |
|
324 | 851 |
\end{ttdescription} |
104 | 852 |
|
853 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
854 |
\section{Types}\index{types|bold} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
855 |
Types belong to the \ML\ type \mltydx{typ}, which is a concrete datatype with |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
856 |
three constructor functions. These correspond to type constructors, free |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
857 |
type variables and schematic type variables. Types are classified by sorts, |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
858 |
which are lists of classes (representing an intersection). A class is |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
859 |
represented by a string. |
104 | 860 |
\begin{ttbox} |
861 |
type class = string; |
|
862 |
type sort = class list; |
|
863 |
||
864 |
datatype typ = Type of string * typ list |
|
865 |
| TFree of string * sort |
|
866 |
| TVar of indexname * sort; |
|
867 |
||
868 |
infixr 5 -->; |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
869 |
fun S --> T = Type ("fun", [S, T]); |
104 | 870 |
\end{ttbox} |
324 | 871 |
\begin{ttdescription} |
872 |
\item[\ttindexbold{Type}($a$, $Ts$)] \index{type constructors|bold} |
|
873 |
applies the {\bf type constructor} named~$a$ to the type operands~$Ts$. |
|
874 |
Type constructors include~\tydx{fun}, the binary function space |
|
875 |
constructor, as well as nullary type constructors such as~\tydx{prop}. |
|
876 |
Other type constructors may be introduced. In expressions, but not in |
|
877 |
patterns, \hbox{\tt$S$-->$T$} is a convenient shorthand for function |
|
878 |
types. |
|
104 | 879 |
|
324 | 880 |
\item[\ttindexbold{TFree}($a$, $s$)] \index{type variables|bold} |
881 |
is the {\bf type variable} with name~$a$ and sort~$s$. |
|
104 | 882 |
|
324 | 883 |
\item[\ttindexbold{TVar}($v$, $s$)] \index{type unknowns|bold} |
884 |
is the {\bf type unknown} with indexname~$v$ and sort~$s$. |
|
885 |
Type unknowns are essentially free type variables, but may be |
|
886 |
instantiated during unification. |
|
887 |
\end{ttdescription} |
|
104 | 888 |
|
889 |
||
890 |
\section{Certified types} |
|
891 |
\index{types!certified|bold} |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
892 |
Certified types, which are analogous to certified terms, have type |
275 | 893 |
\ttindexbold{ctyp}. |
104 | 894 |
|
895 |
\subsection{Printing types} |
|
324 | 896 |
\index{types!printing of} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
897 |
\begin{ttbox} |
275 | 898 |
string_of_ctyp : ctyp -> string |
104 | 899 |
Sign.string_of_typ : Sign.sg -> typ -> string |
900 |
\end{ttbox} |
|
324 | 901 |
\begin{ttdescription} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
902 |
\item[\ttindexbold{string_of_ctyp} $cT$] |
104 | 903 |
displays $cT$ as a string. |
904 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
905 |
\item[\ttindexbold{Sign.string_of_typ} $sign$ $T$] |
104 | 906 |
displays $T$ as a string, using the syntax of~$sign$. |
324 | 907 |
\end{ttdescription} |
104 | 908 |
|
909 |
||
910 |
\subsection{Making and inspecting certified types} |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
911 |
\begin{ttbox} |
275 | 912 |
ctyp_of : Sign.sg -> typ -> ctyp |
913 |
rep_ctyp : ctyp -> \{T: typ, sign: Sign.sg\} |
|
104 | 914 |
\end{ttbox} |
324 | 915 |
\begin{ttdescription} |
275 | 916 |
\item[\ttindexbold{ctyp_of} $sign$ $T$] \index{signatures} |
104 | 917 |
certifies $T$ with respect to signature~$sign$. |
918 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
919 |
\item[\ttindexbold{rep_ctyp} $cT$] |
104 | 920 |
decomposes $cT$ as a record containing the type itself and its signature. |
324 | 921 |
\end{ttdescription} |
104 | 922 |
|
1846 | 923 |
|
924 |
\section{Oracles: calling external reasoners } |
|
925 |
\label{sec:oracles} |
|
926 |
\index{oracles|(} |
|
927 |
||
928 |
Oracles allow Isabelle to take advantage of external reasoners such as |
|
929 |
arithmetic decision procedures, model checkers, fast tautology checkers or |
|
930 |
computer algebra systems. Invoked as an oracle, an external reasoner can |
|
931 |
create arbitrary Isabelle theorems. It is your responsibility to ensure that |
|
932 |
the external reasoner is as trustworthy as your application requires. |
|
933 |
Isabelle's proof objects~(\S\ref{sec:proofObjects}) record how each theorem |
|
934 |
depends upon oracle calls. |
|
935 |
||
936 |
\begin{ttbox} |
|
937 |
invoke_oracle : theory * Sign.sg * exn -> thm |
|
938 |
set_oracle : Sign.sg -> typ -> string |
|
939 |
\end{ttbox} |
|
940 |
\begin{ttdescription} |
|
941 |
\item[\ttindexbold{invoke_oracle} ($thy$, $sign$, $exn$)] invokes the oracle |
|
942 |
of theory $thy$ passing the information contained in the exception value |
|
943 |
$exn$ and creating a theorem having signature $sign$. Errors arise if $thy$ |
|
944 |
does not have an oracle, if the oracle rejects its arguments or if its |
|
945 |
result is ill-typed. |
|
946 |
||
947 |
\item[\ttindexbold{set_oracle} $fn$ $thy$] sets the oracle of theory $thy$ to |
|
948 |
be $fn$. It is seldom called explicitly, as there is syntax for oracles in |
|
949 |
theory files. A theory can have at most one oracle. |
|
950 |
\end{ttdescription} |
|
951 |
||
952 |
A curious feature of {\ML} exceptions is that they are ordinary constructors. |
|
953 |
The {\ML} type {\tt exn} is a datatype that can be extended at any time. (See |
|
954 |
my {\em {ML} for the Working Programmer}~\cite{paulson-ml2}, especially |
|
955 |
page~136.) The oracle mechanism takes advantage of this to allow an oracle to |
|
956 |
take any information whatever. |
|
957 |
||
958 |
There must be some way of invoking the external reasoner from \ML, either |
|
959 |
because it is coded in {\ML} or via an operating system interface. Isabelle |
|
960 |
expects the {\ML} function to take two arguments: a signature and an |
|
961 |
exception. |
|
962 |
\begin{itemize} |
|
963 |
\item The signature will typically be that of a desendant of the theory |
|
964 |
declaring the oracle. The oracle will use it to distinguish constants from |
|
965 |
variables, etc., and it will be attached to the generated theorems. |
|
966 |
||
967 |
\item The exception is used to pass arbitrary information to the oracle. This |
|
968 |
information must contain a full description of the problem to be solved by |
|
969 |
the external reasoner, including any additional information that might be |
|
970 |
required. The oracle may raise the exception to indicate that it cannot |
|
971 |
solve the specified problem. |
|
972 |
\end{itemize} |
|
973 |
||
974 |
A trivial example is provided on directory {\tt FOL/ex}. This oracle |
|
975 |
generates tautologies of the form $P\bimp\cdots\bimp P$, with an even number |
|
976 |
of $P$s. |
|
977 |
||
978 |
File {\tt declIffOracle.ML} begins by declaring a new exception constructor |
|
979 |
for the oracle the information it requires: here, just an integer. It |
|
980 |
contains some code (suppressed below) for creating the tautologies, and |
|
981 |
finally declares the oracle function itself: |
|
982 |
\begin{ttbox} |
|
983 |
exception IffOracleExn of int; |
|
984 |
\(\vdots\) |
|
985 |
fun mk_iff_oracle (sign, IffOracleExn n) = |
|
986 |
if n>0 andalso n mod 2 = 0 |
|
987 |
then Trueprop $ mk_iff n |
|
988 |
else raise IffOracleExn n; |
|
989 |
\end{ttbox} |
|
990 |
Observe the function two arguments, the signature {\tt sign} and the exception |
|
991 |
given as a pattern. The function checks its argument for validity. If $n$ is |
|
992 |
positive and even then it creates a tautology containing $n$ occurrences |
|
993 |
of~$P$. Otherwise it signals error by raising its own exception. Errors may |
|
994 |
be signalled by other means, such as returning the theorem {\tt True}. |
|
995 |
Please ensure that the oracle's result is correctly typed; Isabelle will |
|
996 |
reject ill-typed theorems by raising a cryptic exception at top level. |
|
997 |
||
998 |
The theory file {\tt IffOracle.thy} packages up the function above as an |
|
999 |
oracle. The first line indicates that the new theory depends upon the file |
|
1000 |
{\tt declIffOracle.ML} (which declares the {\ML} code) as well as on \FOL. |
|
1001 |
The second line informs Isabelle that this theory has an oracle given by the |
|
1002 |
function {\tt mk_iff_oracle}. |
|
1003 |
\begin{ttbox} |
|
1004 |
IffOracle = "declIffOracle" + FOL + |
|
1005 |
oracle mk_iff_oracle |
|
1006 |
end |
|
1007 |
\end{ttbox} |
|
1008 |
Because a theory can have at most one oracle, the theory itself serves to |
|
1009 |
identify the oracle. |
|
1010 |
||
1011 |
Here are some examples of invoking the oracle. An argument of 10 is allowed, |
|
1012 |
but one of 5 is forbidden: |
|
1013 |
\begin{ttbox} |
|
1014 |
invoke_oracle (IffOracle.thy, sign_of IffOracle.thy, IffOracleExn 10); |
|
1015 |
{\out "P <-> P <-> P <-> P <-> P <-> P <-> P <-> P <-> P <-> P" : thm} |
|
1016 |
invoke_oracle (IffOracle.thy, sign_of IffOracle.thy, IffOracleExn 5); |
|
1017 |
{\out Exception- IffOracleExn 5 raised} |
|
1018 |
\end{ttbox} |
|
1019 |
||
1020 |
\index{oracles|)} |
|
104 | 1021 |
\index{theories|)} |