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