3 \chapter{Theories, Terms and Types} \label{theories} |
3 \chapter{Theories, Terms and Types} \label{theories} |
4 \index{theories|(}\index{signatures|bold} |
4 \index{theories|(}\index{signatures|bold} |
5 \index{reading!axioms|see{{\tt extend_theory} and {\tt assume_ax}}} |
5 \index{reading!axioms|see{{\tt extend_theory} and {\tt assume_ax}}} |
6 Theories organize the syntax, declarations and axioms of a mathematical |
6 Theories organize the syntax, declarations and axioms of a mathematical |
7 development. They are built, starting from the Pure theory, by extending |
7 development. They are built, starting from the Pure theory, by extending |
8 and merging existing theories. They have the \ML\ type \ttindex{theory}. |
8 and merging existing theories. They have the \ML\ type \mltydx{theory}. |
9 Theory operations signal errors by raising exception \ttindex{THEORY}, |
9 Theory operations signal errors by raising exception \xdx{THEORY}, |
10 returning a message and a list of theories. |
10 returning a message and a list of theories. |
11 |
11 |
12 Signatures, which contain information about sorts, types, constants and |
12 Signatures, which contain information about sorts, types, constants and |
13 syntax, have the \ML\ type~\ttindexbold{Sign.sg}. For identification, |
13 syntax, have the \ML\ type~\mltydx{Sign.sg}. For identification, |
14 each signature carries a unique list of {\bf stamps}, which are \ML\ |
14 each signature carries a unique list of {\bf stamps}, which are \ML\ |
15 references (to strings). The strings serve as human-readable names; the |
15 references to strings. The strings serve as human-readable names; the |
16 references serve as unique identifiers. Each primitive signature has a |
16 references serve as unique identifiers. Each primitive signature has a |
17 single stamp. When two signatures are merged, their lists of stamps are |
17 single stamp. When two signatures are merged, their lists of stamps are |
18 also merged. Every theory carries a unique signature. |
18 also merged. Every theory carries a unique signature. |
19 |
19 |
20 Terms and types are the underlying representation of logical syntax. Their |
20 Terms and types are the underlying representation of logical syntax. Their |
21 \ML\ definitions are irrelevant to naive Isabelle users. Programmers who |
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 |
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 |
23 that looks for subgoals of a particular form. Terms and types may be |
24 `certified' to be well-formed with respect to a given signature. |
24 `certified' to be well-formed with respect to a given signature. |
25 |
25 |
26 \section{Defining Theories}\label{DefiningTheories} |
26 |
|
27 \section{Defining theories}\label{sec:ref-defining-theories} |
27 |
28 |
28 Theories can be defined either using concrete syntax or by calling certain |
29 Theories can be defined either using concrete syntax or by calling certain |
29 \ML{} functions (see \S\ref{BuildingATheory}). Appendix~\ref{app:TheorySyntax} |
30 \ML{} functions (see \S\ref{BuildingATheory}). Appendix~\ref{app:TheorySyntax} |
30 presents the concrete syntax for theories. A theory definition consists of |
31 presents the concrete syntax for theories; here is an explanation of the |
31 several different parts: |
32 constituent parts: |
32 \begin{description} |
33 \begin{description} |
33 \item[{\it theoryDef}] A theory has a name $id$ and is an extension of the |
34 \item[{\it theoryDef}] |
34 union of theories with name {\it name}, the {\bf parent |
35 is the full definition. The new theory is called $id$. It is the union |
35 theories}\indexbold{theories!parent}, with new classes, types, constants, |
36 of the named {\bf parent theories}\indexbold{theories!parent}, possibly |
36 syntax and axioms. The basic theory, which contains only the meta-logic, |
37 extended with new classes, etc. The basic theory, which contains only |
37 is called {\tt Pure}. |
38 the meta-logic, is called \thydx{Pure}. |
38 |
39 |
39 Normally each {\it name\/} is an identifier, the precise name of the parent |
40 Normally each {\it name\/} is an identifier, the name of the parent |
40 theory. Strings can be used to document additional dependencies; see |
41 theory. Strings can be used to document additional dependencies; see |
41 \S\ref{LoadingTheories} for details. |
42 \S\ref{LoadingTheories} for details. |
42 \item[$classes$] {\tt$id$ < $id@1$ \dots\ $id@n$} declares $id$ as a subclass |
43 |
43 of existing classes $id@1\dots id@n$. This rules out cyclic class |
44 \item[$classes$] |
44 structures. Isabelle automatically computes the transitive closure of |
45 is a series of class declarations. Declaring {\tt$id$ < $id@1$ \dots\ |
45 subclass hierarchies. Hence it is not necessary to declare {\tt c < e} in |
46 $id@n$} makes $id$ a subclass of the existing classes $id@1\dots |
46 addition to {\tt c < d} and {\tt d < e}. |
47 id@n$. This rules out cyclic class structures. Isabelle automatically |
47 \item[$default$] introduces $sort$ as the new default sort for type |
48 computes the transitive closure of subclass hierarchies; it is not |
48 variables. Unconstrained type variables in an input string are |
49 necessary to declare {\tt c < e} in addition to {\tt c < d} and {\tt d < |
49 automatically constrained by $sort$; this does not apply to type variables |
50 e}. |
50 created internally during type inference. If omitted, the default sort is |
51 |
51 the union of the default sorts of the parent theories. |
52 \item[$default$] |
52 \item[$sort$] is a finite set of classes; a single class $id$ abbreviates the |
53 introduces $sort$ as the new default sort for type variables. This |
53 singleton set {\tt\{}$id${\tt\}}. |
54 applies to unconstrained type variables in an input string but not to |
54 \item[$type$] is either the declaration of a new type (constructor) or type |
55 type variables created internally. If omitted, the default sort is the |
55 synonym $name$. Only binary type constructors can have infix status and |
56 union of the default sorts of the parent theories. |
56 symbolic names, e.g.\ {\tt ('a,'b)"*"}. Type constructors of $n$ arguments |
57 |
57 are declared by $(\alpha@1,\dots,\alpha@n)name$. A {\bf type |
58 \item[$sort$] |
58 synonym}\indexbold{types!synonyms} is simply an abbreviation |
59 is a finite set of classes. A single class $id$ abbreviates the singleton |
59 $(\alpha@1,\dots,\alpha@n)name = \mbox{\tt"}\tau\mbox{\tt"}$ and follows |
60 set {\tt\{}$id${\tt\}}. |
60 the same rules as in \ML, except that $name$ can be a string and $\tau$ |
61 |
61 must be enclosed in quotation marks. |
62 \item[$types$] |
62 \item[$infix$] declares a type or constant to be an infix operator of |
63 is a series of type declarations. Each declares a new type constructor |
63 priority $nat$ associating to the left ({\tt infixl}) or right ({\tt |
64 or type synonym. An $n$-place type constructor is specified by |
64 infixr}). |
65 $(\alpha@1,\dots,\alpha@n)name$, where the type variables serve only to |
65 \item[$arities$] Each $name$ must be an existing type constructor which is |
66 indicate the number~$n$. |
|
67 |
|
68 Only 2-place type constructors can have infix status and symbolic names; |
|
69 an example is {\tt ('a,'b)"*"}, which expresses binary product types. |
|
70 |
|
71 A {\bf type synonym}\indexbold{types!synonyms} is an abbreviation |
|
72 $(\alpha@1,\dots,\alpha@n)name = \mbox{\tt"}\tau\mbox{\tt"}$, where |
|
73 $name$ can be a string and $\tau$ must be enclosed in quotation marks. |
|
74 |
|
75 \item[$infix$] |
|
76 declares a type or constant to be an infix operator of priority $nat$ |
|
77 associating to the left ({\tt infixl}) or right ({\tt infixr}). |
|
78 |
|
79 \item[$arities$] |
|
80 is a series of arity declarations. Each assigns arities to type |
|
81 constructors. The $name$ must be an existing type constructor, which is |
66 given the additional arity $arity$. |
82 given the additional arity $arity$. |
67 \item[$constDecl$] Each new constant $name$ is declared to be of type |
83 |
68 $string$. For display purposes $mixfix$ annotations can be attached. |
84 \item[$constDecl$] |
69 \item[$mixfix$] There are three forms of syntactic annotations: |
85 is a series of constant declarations. Each new constant $name$ is given |
|
86 the type specified by the $string$. The optional $mixfix$ annotations |
|
87 may attach concrete syntax to the constant. |
|
88 |
|
89 \item[$mixfix$] \index{mixfix declarations} |
|
90 annotations can take three forms: |
70 \begin{itemize} |
91 \begin{itemize} |
71 \item A mixfix template given as a $string$ of the form |
92 \item A mixfix template given as a $string$ of the form |
72 {\tt"}\dots{\tt\_}\dots{\tt\_}\dots{\tt"} where the $i$-th underscore |
93 {\tt"}\dots{\tt\_}\dots{\tt\_}\dots{\tt"} where the $i$-th underscore |
73 indicates the position where the $i$-th argument should go. The minimal |
94 indicates the position where the $i$-th argument should go. The list |
74 priority of each argument is given by a list of natural numbers, the |
95 of numbers gives the priority of each argument. The final number gives |
75 priority of the whole construct by the following natural number; |
96 the priority of the whole construct. |
76 priorities are optional. |
97 |
77 |
98 \item A constant $f$ of type $\tau@1\To(\tau@2\To\tau)$ can be given {\bf |
78 \item Binary constants can be given infix status. |
99 infix} status. |
79 |
100 |
80 \item A constant $f$ {\tt::} $(\tau@1\To\tau@2)\To\tau@3$ can be given {\bf |
101 \item A constant $f$ of type $(\tau@1\To\tau@2)\To\tau$ can be given {\bf |
81 binder} status: the declaration {\tt binder} $\cal Q$ $p$ causes |
102 binder} status. The declaration {\tt binder} $\cal Q$ $p$ causes |
82 ${\cal Q}\,x.F(x)$ to be treated |
103 ${\cal Q}\,x.F(x)$ to be treated |
83 like $f(F)$, where $p$ is the priority. |
104 like $f(F)$, where $p$ is the priority. |
84 \end{itemize} |
105 \end{itemize} |
85 \item[$trans$] Specifies syntactic translation rules, that is parse |
106 |
86 rules ({\tt =>}), print rules ({\tt <=}), or both ({\tt ==}). |
107 \item[$trans$] |
87 \item[$rule$] A rule consists of a name $id$ and a formula $string$. Rule |
108 specifies syntactic translation rules. There are three forms: parse |
88 names must be distinct. |
109 rules ({\tt =>}), print rules ({\tt <=}), and parse/print rules ({\tt ==}). |
89 \item[$ml$] This final part of a theory consists of \ML\ code, |
110 |
90 typically for parse and print translations. |
111 \item[$rule$] |
|
112 is a series of rule declarations. Each has a name $id$ and the |
|
113 formula is given by the $string$. Rule names must be distinct. |
|
114 |
|
115 \item[$ml$] \index{*ML section} |
|
116 consists of \ML\ code, typically for parse and print translations. |
91 \end{description} |
117 \end{description} |
92 The $mixfix$, $trans$ and $ml$ sections are explained in more detail in |
118 % |
93 the {\it Defining Logics} chapter of {\it Isabelle's Object Logics}. |
119 Chapter~\ref{chap:syntax} explains mixfix declarations, translation rules |
|
120 and the {\tt ML} section in more detail. |
94 |
121 |
95 |
122 |
96 \subsection{*Classes and arities} |
123 \subsection{*Classes and arities} |
97 \index{*classes!context conditions}\index{*arities!context conditions} |
124 \index{classes!context conditions}\index{arities!context conditions} |
98 |
125 |
99 In order to guarantee principal types~\cite{nipkow-prehofer}, |
126 In order to guarantee principal types~\cite{nipkow-prehofer}, |
100 classes and arities must obey two conditions: |
127 arity declarations must obey two conditions: |
101 \begin{itemize} |
128 \begin{itemize} |
102 \item There must be no two declarations $ty :: (\vec{r})c$ and $ty :: |
129 \item There must be no two declarations $ty :: (\vec{r})c$ and $ty :: |
103 (\vec{s})c$ with $\vec{r} \neq \vec{s}$. For example, the following is |
130 (\vec{s})c$ with $\vec{r} \neq \vec{s}$. For example, the following is |
104 forbidden: |
131 forbidden: |
105 \begin{ttbox} |
132 \begin{ttbox} |
144 \item[\ttindexbold{loadpath}] |
170 \item[\ttindexbold{loadpath}] |
145 contains a list of directories to search when locating the files that |
171 contains a list of directories to search when locating the files that |
146 define a theory. This list is only used if the theory name in {\tt |
172 define a theory. This list is only used if the theory name in {\tt |
147 use_thy} does not specify the path explicitly. |
173 use_thy} does not specify the path explicitly. |
148 |
174 |
149 \item[\ttindexbold{delete_tmpfiles} \tt:= false;] |
175 \item[\ttindexbold{delete_tmpfiles} := false;] |
150 suppresses the deletion of temporary files. |
176 suppresses the deletion of temporary files. |
151 \end{description} |
177 \end{ttdescription} |
152 % |
178 % |
153 Each theory definition must reside in a separate file. Let the file {\it |
179 Each theory definition must reside in a separate file. Let the file {\it |
154 tf}{\tt.thy} contain the definition of a theory called $TF$ with parent |
180 tf}{\tt.thy} contain the definition of a theory called $TF$ with parent |
155 theories $TB@1$ \dots $TB@n$. Calling \ttindexbold{use_thy}~{\tt"}{\it |
181 theories $TB@1$ \dots $TB@n$. Calling \ttindexbold{use_thy}~{\tt"}{\it |
156 TF\/}{\tt"} reads file {\it tf}{\tt.thy}, writes an intermediate \ML{} |
182 TF\/}{\tt"} reads file {\it tf}{\tt.thy}, writes a temporary \ML{} |
157 file {\tt.}{\it tf}{\tt.thy.ML}, and reads the latter file. Recursive {\tt |
183 file {\tt.}{\it tf}{\tt.thy.ML}, and reads the latter file. Recursive {\tt |
158 use_thy} calls load those parent theories that have not been loaded |
184 use_thy} calls load those parent theories that have not been loaded |
159 previously; the recursion may continue to any depth. One {\tt use_thy} |
185 previously; the recursion may continue to any depth. One {\tt use_thy} |
160 call can read an entire logic if all theories are linked appropriately. |
186 call can read an entire logic if all theories are linked appropriately. |
161 |
187 |
162 The result is an \ML\ structure~$TF$ containing a component {\tt thy} for |
188 The result is an \ML\ structure~$TF$ containing a component {\tt thy} for |
163 the new theory and components $r@1$ \dots $r@n$ for the rules. The |
189 the new theory and components $r@1$ \dots $r@n$ for the rules. The |
164 structure also contains the definitions of the {\tt ML} section, if |
190 structure also contains the definitions of the {\tt ML} section, if |
165 present. The file {\tt.}{\it tf}{\tt.thy.ML} is then deleted if |
191 present. The file {\tt.}{\it tf}{\tt.thy.ML} is then deleted if |
166 \ttindexbold{delete_tmpfiles} is set to {\tt true} and no errors occurred. |
192 {\tt delete_tmpfiles} is set to {\tt true} and no errors occurred. |
167 |
193 |
168 Finally the file {\it tf}{\tt.ML} is read, if it exists. This file |
194 Finally the file {\it tf}{\tt.ML} is read, if it exists. This file |
169 normally contains proofs involving the new theory. It is also possible to |
195 normally contains proofs involving the new theory. It is also possible to |
170 provide only a {\tt.ML} file, with no {\tt.thy} file. In this case the |
196 provide only a {\tt.ML} file, with no {\tt.thy} file. In this case the |
171 {\tt.ML} file must declare an \ML\ structure having the theory's name. If |
197 {\tt.ML} file must declare an \ML\ structure having the theory's name. If |
201 descended from it. However, {\tt use_thy} reads only one theory, even if |
234 descended from it. However, {\tt use_thy} reads only one theory, even if |
202 some of the parent theories are out of date. In this case you should |
235 some of the parent theories are out of date. In this case you should |
203 call {\tt update()}. |
236 call {\tt update()}. |
204 \end{warn} |
237 \end{warn} |
205 |
238 |
206 \begin{description} |
239 \begin{ttdescription} |
207 \item[\ttindexbold{update} ()] |
240 \item[\ttindexbold{update} ()] |
208 reloads all modified theories and their descendants in the correct order. |
241 reloads all modified theories and their descendants in the correct order. |
209 |
242 |
210 \item[\ttindexbold{unlink_thy} $thyname$]\indexbold{theories!removing} |
243 \item[\ttindexbold{unlink_thy} $thyname$]\indexbold{theories!removing} |
211 informs Isabelle that theory $thyname$ no longer exists. If you delete the |
244 informs Isabelle that theory $thyname$ no longer exists. If you delete the |
212 theory files for $thyname$ then you must execute {\tt unlink_thy}; |
245 theory files for $thyname$ then you must execute {\tt unlink_thy}; |
213 otherwise {\tt update} will complain about a missing file. |
246 otherwise {\tt update} will complain about a missing file. |
214 \end{description} |
247 \end{ttdescription} |
215 |
248 |
216 |
249 |
217 \subsection{Important note for Poly/ML users}\index{Poly/\ML} |
250 \subsection{Important note for Poly/ML users}\index{Poly/{\ML} compiler} |
218 The theory mechanism depends upon reference variables. At the end of a |
251 The theory mechanism depends upon reference variables. At the end of a |
219 Poly/\ML{} session, the contents of references are lost unless they are |
252 Poly/\ML{} session, the contents of references are lost unless they are |
220 declared in the current database. Assignments to references in the {\tt |
253 declared in the current database. Assignments to references in the {\tt |
221 Pure} database are lost, including all information about loaded theories. |
254 Pure} database are lost, including all information about loaded theories. |
222 |
255 |
223 To avoid losing such information (assuming you have loaded some theories) |
256 To avoid losing such information you must declare a new {\tt Readthy} |
224 you must declare a new {\tt Readthy} structure in the child database: |
257 structure in the child database: |
225 \begin{ttbox} |
258 \begin{ttbox} |
226 structure Readthy = ReadthyFUN (structure ThySyn = ThySyn); |
259 structure Readthy = ReadthyFUN (structure ThySyn = ThySyn); |
227 Readthy.loaded_thys := !loaded_thys; |
260 Readthy.loaded_thys := !loaded_thys; |
228 open Readthy; |
261 open Readthy; |
229 \end{ttbox} |
262 \end{ttbox} |
230 This copies into the new reference \verb$loaded_thys$ the contents of the |
263 The assignment copies into the new reference \verb$loaded_thys$ the |
231 original reference, which is the list of already loaded theories. |
264 contents of the original reference, which is the list of already loaded |
|
265 theories. You should not omit the declarations even if the parent database |
|
266 has no loaded theories, since they allocate new references. |
232 |
267 |
233 |
268 |
234 \subsection{*Pseudo theories}\indexbold{theories!pseudo} |
269 \subsection{*Pseudo theories}\indexbold{theories!pseudo} |
235 Any automatic reloading facility requires complete knowledge of all |
270 Any automatic reloading facility requires complete knowledge of all |
236 dependencies. Sometimes theories depend on objects created in \ML{} files |
271 dependencies. Sometimes theories depend on objects created in \ML{} files |
237 with no associated {\tt.thy} file. Unless such dependencies are documented, |
272 with no associated {\tt.thy} file. Unless such dependencies are documented, |
238 {\tt update} fails to reload these \ML{} files and the system is left in a |
273 {\tt update} fails to reload these \ML{} files and the system is left in a |
239 state where some objects, e.g.\ theorems, still refer to old versions of |
274 state where some objects, such as theorems, still refer to old versions of |
240 theories. This may lead to the error |
275 theories. This may lead to the error |
241 \begin{ttbox} |
276 \begin{ttbox} |
242 Attempt to merge different versions of theory: \(T\) |
277 Attempt to merge different versions of theory: \(T\) |
243 \end{ttbox} |
278 \end{ttbox} |
244 Therefore there is a way to link theories and {\em orphaned\/} \ML{} files --- |
279 Therefore there is a way to link theories and {\bf orphaned} \ML{} files --- |
245 those without associated {\tt.thy} file. |
280 those without associated {\tt.thy} file. |
246 |
281 |
247 Let us assume we have an orphaned \ML{} file named {\tt orphan.ML} and a theory |
282 Let us assume we have an orphaned \ML{} file named {\tt orphan.ML} and a |
248 $B$ which depends on {\tt orphan.ML} (for example, {\tt b.ML} uses theorems |
283 theory~$B$ that depends on {\tt orphan.ML} --- for example, {\tt b.ML} uses |
249 that are proved in {\tt orphan.ML}). Then {\tt b.thy} should mention this |
284 theorems proved in {\tt orphan.ML}. Then {\tt b.thy} should |
250 dependence: |
285 mention this dependence by means of a string: |
251 \begin{ttbox} |
286 \begin{ttbox} |
252 B = ... + "orphan" + ... |
287 B = ... + "orphan" + ... |
253 \end{ttbox} |
288 \end{ttbox} |
254 Although {\tt orphan} is {\em not\/} used in building the base of theory $B$ |
289 Strings stand for \ML{} files rather than {\tt.thy} files, and merely |
255 (strings stand for \ML{} files rather than {\tt.thy} files and merely document |
290 document additional dependencies. Thus {\tt orphan} is not a theory and is |
256 additional dependencies), {\tt orphan.ML} is loaded automatically when $B$ is |
291 not used in building the base of theory~$B$, but {\tt orphan.ML} is loaded |
257 (re)built. |
292 automatically whenever~$B$ is (re)built. |
258 |
293 |
259 If {\tt orphan.ML} depends on theories $A@1\dots A@n$, this should be recorded |
294 The orphaned file may have its own dependencies. If {\tt orphan.ML} |
260 by creating a {\bf pseudo theory} in the file {\tt orphan.thy}: |
295 depends on theories $A@1$, \ldots, $A@n$, record this by creating a {\bf |
|
296 pseudo theory} in the file {\tt orphan.thy}: |
261 \begin{ttbox} |
297 \begin{ttbox} |
262 orphan = A1 + \(...\) + An |
298 orphan = A1 + \(...\) + An |
263 \end{ttbox} |
299 \end{ttbox} |
264 The resulting theory is a dummy, but it ensures that {\tt update} reloads |
300 The resulting theory is a dummy, but it ensures that {\tt update} reloads |
265 theory {\it orphan} whenever it reloads one of the $A@i$. |
301 theory {\it orphan} whenever it reloads one of the $A@i$. |
266 |
302 |
267 For an extensive example of how this technique can be used to link over 30 |
303 For an extensive example of how this technique can be used to link over 30 |
268 files and load them by just two {\tt use_thy} calls, consult the ZF source |
304 theory files and load them by just two {\tt use_thy} calls, consult the |
269 files. |
305 source files of {\tt ZF} set theory. |
270 |
|
271 \index{*update|)} |
|
272 |
306 |
273 |
307 |
274 |
308 |
275 \section{Basic operations on theories} |
309 \section{Basic operations on theories} |
276 \subsection{Extracting an axiom from a theory} |
310 \subsection{Extracting an axiom from a theory} |
277 \index{theories!extracting axioms|bold}\index{axioms} |
311 \index{theories!axioms of}\index{axioms!extracting} |
278 \begin{ttbox} |
312 \begin{ttbox} |
279 get_axiom: theory -> string -> thm |
313 get_axiom: theory -> string -> thm |
280 assume_ax: theory -> string -> thm |
314 assume_ax: theory -> string -> thm |
281 \end{ttbox} |
315 \end{ttbox} |
282 \begin{description} |
316 \begin{ttdescription} |
283 \item[\ttindexbold{get_axiom} $thy$ $name$] |
317 \item[\ttindexbold{get_axiom} $thy$ $name$] |
284 returns an axiom with the given $name$ from $thy$, raising exception |
318 returns an axiom with the given $name$ from $thy$, raising exception |
285 \ttindex{THEORY} if none exists. Merging theories can cause several axioms |
319 \xdx{THEORY} if none exists. Merging theories can cause several axioms |
286 to have the same name; {\tt get_axiom} returns an arbitrary one. |
320 to have the same name; {\tt get_axiom} returns an arbitrary one. |
287 |
321 |
288 \item[\ttindexbold{assume_ax} $thy$ $formula$] |
322 \item[\ttindexbold{assume_ax} $thy$ $formula$] |
289 reads the {\it formula} using the syntax of $thy$, following the same |
323 reads the {\it formula} using the syntax of $thy$, following the same |
290 conventions as axioms in a theory definition. You can thus pretend that |
324 conventions as axioms in a theory definition. You can thus pretend that |
405 | Var of indexname * typ |
434 | Var of indexname * typ |
406 | Bound of int |
435 | Bound of int |
407 | Abs of string * typ * term |
436 | Abs of string * typ * term |
408 | op $ of term * term; |
437 | op $ of term * term; |
409 \end{ttbox} |
438 \end{ttbox} |
410 \begin{description} |
439 \begin{ttdescription} |
411 \item[\ttindexbold{Const}($a$, $T$)] |
440 \item[\ttindexbold{Const}($a$, $T$)] \index{constants|bold} |
412 is the {\bf constant} with name~$a$ and type~$T$. Constants include |
441 is the {\bf constant} with name~$a$ and type~$T$. Constants include |
413 connectives like $\land$ and $\forall$ as well as constants like~0 |
442 connectives like $\land$ and $\forall$ as well as constants like~0 |
414 and~$Suc$. Other constants may be required to define a logic's concrete |
443 and~$Suc$. Other constants may be required to define a logic's concrete |
415 syntax. |
444 syntax. |
416 |
445 |
417 \item[\ttindexbold{Free}($a$, $T$)] |
446 \item[\ttindexbold{Free}($a$, $T$)] \index{variables!free|bold} |
418 is the {\bf free variable} with name~$a$ and type~$T$. |
447 is the {\bf free variable} with name~$a$ and type~$T$. |
419 |
448 |
420 \item[\ttindexbold{Var}($v$, $T$)] |
449 \item[\ttindexbold{Var}($v$, $T$)] \index{unknowns|bold} |
421 is the {\bf scheme variable} with indexname~$v$ and type~$T$. An |
450 is the {\bf scheme variable} with indexname~$v$ and type~$T$. An |
422 \ttindexbold{indexname} is a string paired with a non-negative index, or |
451 \mltydx{indexname} is a string paired with a non-negative index, or |
423 subscript; a term's scheme variables can be systematically renamed by |
452 subscript; a term's scheme variables can be systematically renamed by |
424 incrementing their subscripts. Scheme variables are essentially free |
453 incrementing their subscripts. Scheme variables are essentially free |
425 variables, but may be instantiated during unification. |
454 variables, but may be instantiated during unification. |
426 |
455 |
427 \item[\ttindexbold{Bound} $i$] |
456 \item[\ttindexbold{Bound} $i$] \index{variables!bound|bold} |
428 is the {\bf bound variable} with de Bruijn index~$i$, which counts the |
457 is the {\bf bound variable} with de Bruijn index~$i$, which counts the |
429 number of lambdas, starting from zero, between a variable's occurrence and |
458 number of lambdas, starting from zero, between a variable's occurrence |
430 its binding. The representation prevents capture of variables. For more |
459 and its binding. The representation prevents capture of variables. For |
431 information see de Bruijn \cite{debruijn72} or |
460 more information see de Bruijn \cite{debruijn72} or |
432 Paulson~\cite[page~336]{paulson91}. |
461 Paulson~\cite[page~336]{paulson91}. |
433 |
462 |
434 \item[\ttindexbold{Abs}($a$, $T$, $u$)] |
463 \item[\ttindexbold{Abs}($a$, $T$, $u$)] |
435 is the {\bf abstraction} with body~$u$, and whose bound variable has |
464 \index{lambda abs@$\lambda$-abstractions|bold} |
436 name~$a$ and type~$T$. The name is used only for parsing and printing; it |
465 is the $\lambda$-{\bf abstraction} with body~$u$, and whose bound |
437 has no logical significance. |
466 variable has name~$a$ and type~$T$. The name is used only for parsing |
438 |
467 and printing; it has no logical significance. |
439 \item[\tt $t$ \$ $u$] \index{$@{\tt\$}|bold} |
468 |
|
469 \item[$t$ \$ $u$] \index{$@{\tt\$}|bold} \index{function applications|bold} |
440 is the {\bf application} of~$t$ to~$u$. |
470 is the {\bf application} of~$t$ to~$u$. |
441 \end{description} |
471 \end{ttdescription} |
442 Application is written as an infix operator to aid readability. |
472 Application is written as an infix operator to aid readability. |
443 Here is an \ML\ pattern to recognize first-order formula of |
473 Here is an \ML\ pattern to recognize first-order formulae of |
444 the form~$A\imp B$, binding the subformulae to~$A$ and~$B$: |
474 the form~$A\imp B$, binding the subformulae to~$A$ and~$B$: |
445 \begin{ttbox} |
475 \begin{ttbox} |
446 Const("Trueprop",_) $ (Const("op -->",_) $ A $ B) |
476 Const("Trueprop",_) $ (Const("op -->",_) $ A $ B) |
447 \end{ttbox} |
477 \end{ttbox} |
448 |
478 |
449 |
479 |
450 \section{Terms and variable binding} |
480 \section{Variable binding} |
451 \begin{ttbox} |
481 \begin{ttbox} |
452 loose_bnos : term -> int list |
482 loose_bnos : term -> int list |
453 incr_boundvars : int -> term -> term |
483 incr_boundvars : int -> term -> term |
454 abstract_over : term*term -> term |
484 abstract_over : term*term -> term |
455 variant_abs : string * typ * term -> string * term |
485 variant_abs : string * typ * term -> string * term |
456 aconv : term*term -> bool\hfill{\bf infix} |
486 aconv : term*term -> bool\hfill{\bf infix} |
457 \end{ttbox} |
487 \end{ttbox} |
458 These functions are all concerned with the de Bruijn representation of |
488 These functions are all concerned with the de Bruijn representation of |
459 bound variables. |
489 bound variables. |
460 \begin{description} |
490 \begin{ttdescription} |
461 \item[\ttindexbold{loose_bnos} $t$] |
491 \item[\ttindexbold{loose_bnos} $t$] |
462 returns the list of all dangling bound variable references. In |
492 returns the list of all dangling bound variable references. In |
463 particular, {\tt Bound~0} is loose unless it is enclosed in an |
493 particular, {\tt Bound~0} is loose unless it is enclosed in an |
464 abstraction. Similarly {\tt Bound~1} is loose unless it is enclosed in |
494 abstraction. Similarly {\tt Bound~1} is loose unless it is enclosed in |
465 at least two abstractions; if enclosed in just one, the list will contain |
495 at least two abstractions; if enclosed in just one, the list will contain |
501 \item |
531 \item |
502 Two applications are \(\alpha\)-convertible |
532 Two applications are \(\alpha\)-convertible |
503 if the corresponding subterms are. |
533 if the corresponding subterms are. |
504 \end{itemize} |
534 \end{itemize} |
505 |
535 |
506 \end{description} |
536 \end{ttdescription} |
507 |
537 |
508 \section{Certified terms}\index{terms!certified|bold}\index{signatures} |
538 \section{Certified terms}\index{terms!certified|bold}\index{signatures} |
509 A term $t$ can be {\bf certified} under a signature to ensure that every |
539 A term $t$ can be {\bf certified} under a signature to ensure that every |
510 type in~$t$ is declared in the signature and every constant in~$t$ is |
540 type in~$t$ is declared in the signature and every constant in~$t$ is |
511 declared as a constant of the same type in the signature. It must be |
541 declared as a constant of the same type in the signature. It must be |
512 well-typed and its use of bound variables must be well-formed. Meta-rules |
542 well-typed and its use of bound variables must be well-formed. Meta-rules |
513 such as {\tt forall_elim} take certified terms as arguments. |
543 such as {\tt forall_elim} take certified terms as arguments. |
514 |
544 |
515 Certified terms belong to the abstract type \ttindexbold{cterm}. |
545 Certified terms belong to the abstract type \mltydx{cterm}. |
516 Elements of the type can only be created through the certification process. |
546 Elements of the type can only be created through the certification process. |
517 In case of error, Isabelle raises exception~\ttindex{TERM}\@. |
547 In case of error, Isabelle raises exception~\ttindex{TERM}\@. |
518 |
548 |
519 \subsection{Printing terms} |
549 \subsection{Printing terms} |
520 \index{printing!terms|bold} |
550 \index{terms!printing of} |
521 \begin{ttbox} |
551 \begin{ttbox} |
522 string_of_cterm : cterm -> string |
552 string_of_cterm : cterm -> string |
523 Sign.string_of_term : Sign.sg -> term -> string |
553 Sign.string_of_term : Sign.sg -> term -> string |
524 \end{ttbox} |
554 \end{ttbox} |
525 \begin{description} |
555 \begin{ttdescription} |
526 \item[\ttindexbold{string_of_cterm} $ct$] |
556 \item[\ttindexbold{string_of_cterm} $ct$] |
527 displays $ct$ as a string. |
557 displays $ct$ as a string. |
528 |
558 |
529 \item[\ttindexbold{Sign.string_of_term} $sign$ $t$] |
559 \item[\ttindexbold{Sign.string_of_term} $sign$ $t$] |
530 displays $t$ as a string, using the syntax of~$sign$. |
560 displays $t$ as a string, using the syntax of~$sign$. |
531 \end{description} |
561 \end{ttdescription} |
532 |
562 |
533 \subsection{Making and inspecting certified terms} |
563 \subsection{Making and inspecting certified terms} |
534 \begin{ttbox} |
564 \begin{ttbox} |
535 cterm_of : Sign.sg -> term -> cterm |
565 cterm_of : Sign.sg -> term -> cterm |
536 read_cterm : Sign.sg -> string * typ -> cterm |
566 read_cterm : Sign.sg -> string * typ -> cterm |
537 rep_cterm : cterm -> \{T:typ, t:term, sign:Sign.sg, maxidx:int\} |
567 rep_cterm : cterm -> \{T:typ, t:term, sign:Sign.sg, maxidx:int\} |
538 \end{ttbox} |
568 \end{ttbox} |
539 \begin{description} |
569 \begin{ttdescription} |
540 \item[\ttindexbold{cterm_of} $sign$ $t$] \index{signatures} |
570 \item[\ttindexbold{cterm_of} $sign$ $t$] \index{signatures} |
541 certifies $t$ with respect to signature~$sign$. |
571 certifies $t$ with respect to signature~$sign$. |
542 |
572 |
543 \item[\ttindexbold{read_cterm} $sign$ ($s$, $T$)] |
573 \item[\ttindexbold{read_cterm} $sign$ ($s$, $T$)] |
544 reads the string~$s$ using the syntax of~$sign$, creating a certified term. |
574 reads the string~$s$ using the syntax of~$sign$, creating a certified term. |
567 | TVar of indexname * sort; |
597 | TVar of indexname * sort; |
568 |
598 |
569 infixr 5 -->; |
599 infixr 5 -->; |
570 fun S --> T = Type("fun",[S,T]); |
600 fun S --> T = Type("fun",[S,T]); |
571 \end{ttbox} |
601 \end{ttbox} |
572 \begin{description} |
602 \begin{ttdescription} |
573 \item[\ttindexbold{Type}($a$, $Ts$)] |
603 \item[\ttindexbold{Type}($a$, $Ts$)] \index{type constructors|bold} |
574 applies the {\bf type constructor} named~$a$ to the type operands~$Ts$. |
604 applies the {\bf type constructor} named~$a$ to the type operands~$Ts$. |
575 Type constructors include~\ttindexbold{fun}, the binary function space |
605 Type constructors include~\tydx{fun}, the binary function space |
576 constructor, as well as nullary type constructors such |
606 constructor, as well as nullary type constructors such as~\tydx{prop}. |
577 as~\ttindexbold{prop}. Other type constructors may be introduced. In |
607 Other type constructors may be introduced. In expressions, but not in |
578 expressions, but not in patterns, \hbox{\tt$S$-->$T$} is a convenient |
608 patterns, \hbox{\tt$S$-->$T$} is a convenient shorthand for function |
579 shorthand for function types. |
609 types. |
580 |
610 |
581 \item[\ttindexbold{TFree}($a$, $s$)] |
611 \item[\ttindexbold{TFree}($a$, $s$)] \index{type variables|bold} |
582 is the {\bf free type variable} with name~$a$ and sort~$s$. |
612 is the {\bf type variable} with name~$a$ and sort~$s$. |
583 |
613 |
584 \item[\ttindexbold{TVar}($v$, $s$)] |
614 \item[\ttindexbold{TVar}($v$, $s$)] \index{type unknowns|bold} |
585 is the {\bf scheme type variable} with indexname~$v$ and sort~$s$. Scheme |
615 is the {\bf type unknown} with indexname~$v$ and sort~$s$. |
586 type variables are essentially free type variables, but may be instantiated |
616 Type unknowns are essentially free type variables, but may be |
587 during unification. |
617 instantiated during unification. |
588 \end{description} |
618 \end{ttdescription} |
589 |
619 |
590 |
620 |
591 \section{Certified types} |
621 \section{Certified types} |
592 \index{types!certified|bold} |
622 \index{types!certified|bold} |
593 Certified types, which are analogous to certified terms, have type |
623 Certified types, which are analogous to certified terms, have type |
594 \ttindexbold{ctyp}. |
624 \ttindexbold{ctyp}. |
595 |
625 |
596 \subsection{Printing types} |
626 \subsection{Printing types} |
597 \index{printing!types|bold} |
627 \index{types!printing of} |
598 \begin{ttbox} |
628 \begin{ttbox} |
599 string_of_ctyp : ctyp -> string |
629 string_of_ctyp : ctyp -> string |
600 Sign.string_of_typ : Sign.sg -> typ -> string |
630 Sign.string_of_typ : Sign.sg -> typ -> string |
601 \end{ttbox} |
631 \end{ttbox} |
602 \begin{description} |
632 \begin{ttdescription} |
603 \item[\ttindexbold{string_of_ctyp} $cT$] |
633 \item[\ttindexbold{string_of_ctyp} $cT$] |
604 displays $cT$ as a string. |
634 displays $cT$ as a string. |
605 |
635 |
606 \item[\ttindexbold{Sign.string_of_typ} $sign$ $T$] |
636 \item[\ttindexbold{Sign.string_of_typ} $sign$ $T$] |
607 displays $T$ as a string, using the syntax of~$sign$. |
637 displays $T$ as a string, using the syntax of~$sign$. |
608 \end{description} |
638 \end{ttdescription} |
609 |
639 |
610 |
640 |
611 \subsection{Making and inspecting certified types} |
641 \subsection{Making and inspecting certified types} |
612 \begin{ttbox} |
642 \begin{ttbox} |
613 ctyp_of : Sign.sg -> typ -> ctyp |
643 ctyp_of : Sign.sg -> typ -> ctyp |
614 rep_ctyp : ctyp -> \{T: typ, sign: Sign.sg\} |
644 rep_ctyp : ctyp -> \{T: typ, sign: Sign.sg\} |
615 \end{ttbox} |
645 \end{ttbox} |
616 \begin{description} |
646 \begin{ttdescription} |
617 \item[\ttindexbold{ctyp_of} $sign$ $T$] \index{signatures} |
647 \item[\ttindexbold{ctyp_of} $sign$ $T$] \index{signatures} |
618 certifies $T$ with respect to signature~$sign$. |
648 certifies $T$ with respect to signature~$sign$. |
619 |
649 |
620 \item[\ttindexbold{rep_ctyp} $cT$] |
650 \item[\ttindexbold{rep_ctyp} $cT$] |
621 decomposes $cT$ as a record containing the type itself and its signature. |
651 decomposes $cT$ as a record containing the type itself and its signature. |
622 \end{description} |
652 \end{ttdescription} |
623 |
653 |
624 \index{theories|)} |
654 \index{theories|)} |