author | wenzelm |
Wed, 27 Apr 2011 23:04:28 +0200 | |
changeset 42498 | 9e1a77ad7ca3 |
parent 39838 | eb47307ab930 |
child 42840 | e87888b4152f |
permissions | -rw-r--r-- |
145 | 1 |
|
104 | 2 |
\chapter{Theories, Terms and Types} \label{theories} |
30184
37969710e61f
removed parts of the manual that are clearly obsolete, or covered by
wenzelm
parents:
19627
diff
changeset
|
3 |
\index{theories|(} |
104 | 4 |
|
6568 | 5 |
\section{The theory loader}\label{sec:more-theories} |
6 |
\index{theories!reading}\index{files!reading} |
|
7 |
||
8 |
Isabelle's theory loader manages dependencies of the internal graph of theory |
|
9 |
nodes (the \emph{theory database}) and the external view of the file system. |
|
138
9ba8bff1addc
added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents:
104
diff
changeset
|
10 |
|
6568 | 11 |
\medskip Theory and {\ML} files are located by skimming through the |
12 |
directories listed in Isabelle's internal load path, which merely contains the |
|
13 |
current directory ``\texttt{.}'' by default. The load path may be accessed by |
|
14 |
the following operations. |
|
332 | 15 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
16 |
\begin{ttbox} |
6568 | 17 |
show_path: unit -> string list |
18 |
add_path: string -> unit |
|
19 |
del_path: string -> unit |
|
20 |
reset_path: unit -> unit |
|
7440 | 21 |
with_path: string -> ('a -> 'b) -> 'a -> 'b |
11052 | 22 |
no_document: ('a -> 'b) -> 'a -> 'b |
286 | 23 |
\end{ttbox} |
24 |
||
324 | 25 |
\begin{ttdescription} |
6568 | 26 |
\item[\ttindexbold{show_path}();] displays the load path components in |
6571 | 27 |
canonical string representation (which is always according to Unix rules). |
6568 | 28 |
|
6569 | 29 |
\item[\ttindexbold{add_path} "$dir$";] adds component $dir$ to the beginning |
30 |
of the load path. |
|
6568 | 31 |
|
6569 | 32 |
\item[\ttindexbold{del_path} "$dir$";] removes any occurrences of component |
6568 | 33 |
$dir$ from the load path. |
34 |
||
35 |
\item[\ttindexbold{reset_path}();] resets the load path to ``\texttt{.}'' |
|
36 |
(current directory) only. |
|
7440 | 37 |
|
38 |
\item[\ttindexbold{with_path} "$dir$" $f$ $x$;] temporarily adds component |
|
11052 | 39 |
$dir$ to the beginning of the load path while executing $(f~x)$. |
40 |
||
41 |
\item[\ttindexbold{no_document} $f$ $x$;] temporarily disables {\LaTeX} |
|
42 |
document generation while executing $(f~x)$. |
|
7440 | 43 |
|
324 | 44 |
\end{ttdescription} |
286 | 45 |
|
7440 | 46 |
Furthermore, in operations referring indirectly to some file (e.g.\ |
47 |
\texttt{use_dir}) the argument may be prefixed by a directory that will be |
|
48 |
temporarily appended to the load path, too. |
|
104 | 49 |
|
50 |
||
866
2d3d020eef11
added documentation of bind_thm, qed, qed_goal, get_thm, thms_of
clasohm
parents:
864
diff
changeset
|
51 |
\section{Basic operations on theories}\label{BasicOperationsOnTheories} |
4384 | 52 |
|
53 |
\subsection{*Theory inclusion} |
|
54 |
\begin{ttbox} |
|
55 |
transfer : theory -> thm -> thm |
|
56 |
\end{ttbox} |
|
57 |
||
39838 | 58 |
Transferring theorems to super theories has no logical significance, |
59 |
but may affect some operations in subtle ways (e.g.\ implicit merges |
|
60 |
of signatures when applying rules, or pretty printing of theorems). |
|
4384 | 61 |
|
62 |
\begin{ttdescription} |
|
63 |
||
64 |
\item[\ttindexbold{transfer} $thy$ $thm$] transfers theorem $thm$ to |
|
65 |
theory $thy$, provided the latter includes the theory of $thm$. |
|
66 |
||
324 | 67 |
\end{ttdescription} |
104 | 68 |
|
1369 | 69 |
|
11623 | 70 |
\section{Terms}\label{sec:terms} |
104 | 71 |
\index{terms|bold} |
324 | 72 |
Terms belong to the \ML\ type \mltydx{term}, which is a concrete datatype |
3108 | 73 |
with six constructors: |
104 | 74 |
\begin{ttbox} |
75 |
type indexname = string * int; |
|
76 |
infix 9 $; |
|
77 |
datatype term = Const of string * typ |
|
78 |
| Free of string * typ |
|
79 |
| Var of indexname * typ |
|
80 |
| Bound of int |
|
81 |
| Abs of string * typ * term |
|
82 |
| op $ of term * term; |
|
83 |
\end{ttbox} |
|
324 | 84 |
\begin{ttdescription} |
4317 | 85 |
\item[\ttindexbold{Const} ($a$, $T$)] \index{constants|bold} |
8136 | 86 |
is the \textbf{constant} with name~$a$ and type~$T$. Constants include |
286 | 87 |
connectives like $\land$ and $\forall$ as well as constants like~0 |
88 |
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
|
89 |
syntax. |
104 | 90 |
|
4317 | 91 |
\item[\ttindexbold{Free} ($a$, $T$)] \index{variables!free|bold} |
8136 | 92 |
is the \textbf{free variable} with name~$a$ and type~$T$. |
104 | 93 |
|
4317 | 94 |
\item[\ttindexbold{Var} ($v$, $T$)] \index{unknowns|bold} |
8136 | 95 |
is the \textbf{scheme variable} with indexname~$v$ and type~$T$. An |
324 | 96 |
\mltydx{indexname} is a string paired with a non-negative index, or |
97 |
subscript; a term's scheme variables can be systematically renamed by |
|
98 |
incrementing their subscripts. Scheme variables are essentially free |
|
99 |
variables, but may be instantiated during unification. |
|
104 | 100 |
|
324 | 101 |
\item[\ttindexbold{Bound} $i$] \index{variables!bound|bold} |
8136 | 102 |
is the \textbf{bound variable} with de Bruijn index~$i$, which counts the |
324 | 103 |
number of lambdas, starting from zero, between a variable's occurrence |
104 |
and its binding. The representation prevents capture of variables. For |
|
105 |
more information see de Bruijn \cite{debruijn72} or |
|
6592 | 106 |
Paulson~\cite[page~376]{paulson-ml2}. |
104 | 107 |
|
4317 | 108 |
\item[\ttindexbold{Abs} ($a$, $T$, $u$)] |
324 | 109 |
\index{lambda abs@$\lambda$-abstractions|bold} |
8136 | 110 |
is the $\lambda$-\textbf{abstraction} with body~$u$, and whose bound |
324 | 111 |
variable has name~$a$ and type~$T$. The name is used only for parsing |
112 |
and printing; it has no logical significance. |
|
104 | 113 |
|
324 | 114 |
\item[$t$ \$ $u$] \index{$@{\tt\$}|bold} \index{function applications|bold} |
8136 | 115 |
is the \textbf{application} of~$t$ to~$u$. |
324 | 116 |
\end{ttdescription} |
9695 | 117 |
Application is written as an infix operator to aid readability. Here is an |
118 |
\ML\ pattern to recognize FOL formulae of the form~$A\imp B$, binding the |
|
119 |
subformulae to~$A$ and~$B$: |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
120 |
\begin{ttbox} |
104 | 121 |
Const("Trueprop",_) $ (Const("op -->",_) $ A $ B) |
122 |
\end{ttbox} |
|
123 |
||
124 |
||
4317 | 125 |
\section{*Variable binding} |
286 | 126 |
\begin{ttbox} |
127 |
loose_bnos : term -> int list |
|
128 |
incr_boundvars : int -> term -> term |
|
129 |
abstract_over : term*term -> term |
|
130 |
variant_abs : string * typ * term -> string * term |
|
8136 | 131 |
aconv : term * term -> bool\hfill\textbf{infix} |
286 | 132 |
\end{ttbox} |
133 |
These functions are all concerned with the de Bruijn representation of |
|
134 |
bound variables. |
|
324 | 135 |
\begin{ttdescription} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
136 |
\item[\ttindexbold{loose_bnos} $t$] |
286 | 137 |
returns the list of all dangling bound variable references. In |
6669 | 138 |
particular, \texttt{Bound~0} is loose unless it is enclosed in an |
139 |
abstraction. Similarly \texttt{Bound~1} is loose unless it is enclosed in |
|
286 | 140 |
at least two abstractions; if enclosed in just one, the list will contain |
141 |
the number 0. A well-formed term does not contain any loose variables. |
|
142 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
143 |
\item[\ttindexbold{incr_boundvars} $j$] |
332 | 144 |
increases a term's dangling bound variables by the offset~$j$. This is |
286 | 145 |
required when moving a subterm into a context where it is enclosed by a |
146 |
different number of abstractions. Bound variables with a matching |
|
147 |
abstraction are unaffected. |
|
148 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
149 |
\item[\ttindexbold{abstract_over} $(v,t)$] |
286 | 150 |
forms the abstraction of~$t$ over~$v$, which may be any well-formed term. |
6669 | 151 |
It replaces every occurrence of \(v\) by a \texttt{Bound} variable with the |
286 | 152 |
correct index. |
153 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
154 |
\item[\ttindexbold{variant_abs} $(a,T,u)$] |
286 | 155 |
substitutes into $u$, which should be the body of an abstraction. |
156 |
It replaces each occurrence of the outermost bound variable by a free |
|
157 |
variable. The free variable has type~$T$ and its name is a variant |
|
332 | 158 |
of~$a$ chosen to be distinct from all constants and from all variables |
286 | 159 |
free in~$u$. |
160 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
161 |
\item[$t$ \ttindexbold{aconv} $u$] |
286 | 162 |
tests whether terms~$t$ and~$u$ are \(\alpha\)-convertible: identical up |
163 |
to renaming of bound variables. |
|
164 |
\begin{itemize} |
|
165 |
\item |
|
6669 | 166 |
Two constants, \texttt{Free}s, or \texttt{Var}s are \(\alpha\)-convertible |
286 | 167 |
if their names and types are equal. |
168 |
(Variables having the same name but different types are thus distinct. |
|
169 |
This confusing situation should be avoided!) |
|
170 |
\item |
|
171 |
Two bound variables are \(\alpha\)-convertible |
|
172 |
if they have the same number. |
|
173 |
\item |
|
174 |
Two abstractions are \(\alpha\)-convertible |
|
175 |
if their bodies are, and their bound variables have the same type. |
|
176 |
\item |
|
177 |
Two applications are \(\alpha\)-convertible |
|
178 |
if the corresponding subterms are. |
|
179 |
\end{itemize} |
|
180 |
||
324 | 181 |
\end{ttdescription} |
286 | 182 |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
183 |
\section{Certified terms}\index{terms!certified|bold}\index{signatures} |
8136 | 184 |
A term $t$ can be \textbf{certified} under a signature to ensure that every type |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
185 |
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
|
186 |
constant declared in the signature. The term must be well-typed and its use |
6669 | 187 |
of bound variables must be well-formed. Meta-rules such as \texttt{forall_elim} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
188 |
take certified terms as arguments. |
104 | 189 |
|
324 | 190 |
Certified terms belong to the abstract type \mltydx{cterm}. |
104 | 191 |
Elements of the type can only be created through the certification process. |
192 |
In case of error, Isabelle raises exception~\ttindex{TERM}\@. |
|
193 |
||
194 |
\subsection{Printing terms} |
|
324 | 195 |
\index{terms!printing of} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
196 |
\begin{ttbox} |
275 | 197 |
string_of_cterm : cterm -> string |
104 | 198 |
Sign.string_of_term : Sign.sg -> term -> string |
199 |
\end{ttbox} |
|
324 | 200 |
\begin{ttdescription} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
201 |
\item[\ttindexbold{string_of_cterm} $ct$] |
104 | 202 |
displays $ct$ as a string. |
203 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
204 |
\item[\ttindexbold{Sign.string_of_term} $sign$ $t$] |
104 | 205 |
displays $t$ as a string, using the syntax of~$sign$. |
324 | 206 |
\end{ttdescription} |
104 | 207 |
|
208 |
\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
|
209 |
\begin{ttbox} |
8136 | 210 |
cterm_of : Sign.sg -> term -> cterm |
211 |
read_cterm : Sign.sg -> string * typ -> cterm |
|
212 |
cert_axm : Sign.sg -> string * term -> string * term |
|
213 |
read_axm : Sign.sg -> string * string -> string * term |
|
214 |
rep_cterm : cterm -> \{T:typ, t:term, sign:Sign.sg, maxidx:int\} |
|
4543 | 215 |
Sign.certify_term : Sign.sg -> term -> term * typ * int |
104 | 216 |
\end{ttbox} |
324 | 217 |
\begin{ttdescription} |
4543 | 218 |
|
219 |
\item[\ttindexbold{cterm_of} $sign$ $t$] \index{signatures} certifies |
|
220 |
$t$ with respect to signature~$sign$. |
|
221 |
||
222 |
\item[\ttindexbold{read_cterm} $sign$ ($s$, $T$)] reads the string~$s$ |
|
223 |
using the syntax of~$sign$, creating a certified term. The term is |
|
224 |
checked to have type~$T$; this type also tells the parser what kind |
|
225 |
of phrase to parse. |
|
226 |
||
227 |
\item[\ttindexbold{cert_axm} $sign$ ($name$, $t$)] certifies $t$ with |
|
228 |
respect to $sign$ as a meta-proposition and converts all exceptions |
|
229 |
to an error, including the final message |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
230 |
\begin{ttbox} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
231 |
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
|
232 |
\end{ttbox} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
233 |
|
4543 | 234 |
\item[\ttindexbold{read_axm} $sign$ ($name$, $s$)] similar to {\tt |
235 |
cert_axm}, but first reads the string $s$ using the syntax of |
|
236 |
$sign$. |
|
237 |
||
238 |
\item[\ttindexbold{rep_cterm} $ct$] decomposes $ct$ as a record |
|
239 |
containing its type, the term itself, its signature, and the maximum |
|
240 |
subscript of its unknowns. The type and maximum subscript are |
|
241 |
computed during certification. |
|
242 |
||
243 |
\item[\ttindexbold{Sign.certify_term}] is a more primitive version of |
|
244 |
\texttt{cterm_of}, returning the internal representation instead of |
|
245 |
an abstract \texttt{cterm}. |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
246 |
|
324 | 247 |
\end{ttdescription} |
104 | 248 |
|
249 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
250 |
\section{Types}\index{types|bold} |
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
represented by a string. |
104 | 256 |
\begin{ttbox} |
257 |
type class = string; |
|
258 |
type sort = class list; |
|
259 |
||
260 |
datatype typ = Type of string * typ list |
|
261 |
| TFree of string * sort |
|
262 |
| TVar of indexname * sort; |
|
263 |
||
264 |
infixr 5 -->; |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
265 |
fun S --> T = Type ("fun", [S, T]); |
104 | 266 |
\end{ttbox} |
324 | 267 |
\begin{ttdescription} |
4317 | 268 |
\item[\ttindexbold{Type} ($a$, $Ts$)] \index{type constructors|bold} |
8136 | 269 |
applies the \textbf{type constructor} named~$a$ to the type operand list~$Ts$. |
324 | 270 |
Type constructors include~\tydx{fun}, the binary function space |
271 |
constructor, as well as nullary type constructors such as~\tydx{prop}. |
|
272 |
Other type constructors may be introduced. In expressions, but not in |
|
273 |
patterns, \hbox{\tt$S$-->$T$} is a convenient shorthand for function |
|
274 |
types. |
|
104 | 275 |
|
4317 | 276 |
\item[\ttindexbold{TFree} ($a$, $s$)] \index{type variables|bold} |
8136 | 277 |
is the \textbf{type variable} with name~$a$ and sort~$s$. |
104 | 278 |
|
4317 | 279 |
\item[\ttindexbold{TVar} ($v$, $s$)] \index{type unknowns|bold} |
8136 | 280 |
is the \textbf{type unknown} with indexname~$v$ and sort~$s$. |
324 | 281 |
Type unknowns are essentially free type variables, but may be |
282 |
instantiated during unification. |
|
283 |
\end{ttdescription} |
|
104 | 284 |
|
285 |
||
286 |
\section{Certified types} |
|
287 |
\index{types!certified|bold} |
|
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
288 |
Certified types, which are analogous to certified terms, have type |
275 | 289 |
\ttindexbold{ctyp}. |
104 | 290 |
|
291 |
\subsection{Printing types} |
|
324 | 292 |
\index{types!printing of} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
293 |
\begin{ttbox} |
275 | 294 |
string_of_ctyp : ctyp -> string |
104 | 295 |
Sign.string_of_typ : Sign.sg -> typ -> string |
296 |
\end{ttbox} |
|
324 | 297 |
\begin{ttdescription} |
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
298 |
\item[\ttindexbold{string_of_ctyp} $cT$] |
104 | 299 |
displays $cT$ as a string. |
300 |
||
864
d63b111b917a
quite a lot of minor and major revisions (inspecting theories, read_axm,
wenzelm
parents:
478
diff
changeset
|
301 |
\item[\ttindexbold{Sign.string_of_typ} $sign$ $T$] |
104 | 302 |
displays $T$ as a string, using the syntax of~$sign$. |
324 | 303 |
\end{ttdescription} |
104 | 304 |
|
305 |
||
306 |
\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
|
307 |
\begin{ttbox} |
4543 | 308 |
ctyp_of : Sign.sg -> typ -> ctyp |
8136 | 309 |
rep_ctyp : ctyp -> \{T: typ, sign: Sign.sg\} |
4543 | 310 |
Sign.certify_typ : Sign.sg -> typ -> typ |
104 | 311 |
\end{ttbox} |
324 | 312 |
\begin{ttdescription} |
4543 | 313 |
|
314 |
\item[\ttindexbold{ctyp_of} $sign$ $T$] \index{signatures} certifies |
|
315 |
$T$ with respect to signature~$sign$. |
|
316 |
||
317 |
\item[\ttindexbold{rep_ctyp} $cT$] decomposes $cT$ as a record |
|
318 |
containing the type itself and its signature. |
|
319 |
||
320 |
\item[\ttindexbold{Sign.certify_typ}] is a more primitive version of |
|
321 |
\texttt{ctyp_of}, returning the internal representation instead of |
|
322 |
an abstract \texttt{ctyp}. |
|
104 | 323 |
|
324 | 324 |
\end{ttdescription} |
104 | 325 |
|
1846 | 326 |
|
104 | 327 |
\index{theories|)} |
5369 | 328 |
|
329 |
||
330 |
%%% Local Variables: |
|
331 |
%%% mode: latex |
|
332 |
%%% TeX-master: "ref" |
|
333 |
%%% End: |