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