doc-src/Ref/theories.tex
author lcp
Mon, 21 Mar 1994 11:02:57 +0100
changeset 286 e7efbf03562b
parent 275 933ec96c522e
child 324 34bc15b546e6
permissions -rw-r--r--
first draft of Springer book
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     1
%% $Id$
145
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
     2
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     3
\chapter{Theories, Terms and Types} \label{theories}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     4
\index{theories|(}\index{signatures|bold}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     5
\index{reading!axioms|see{{\tt extend_theory} and {\tt assume_ax}}}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     6
Theories organize the syntax, declarations and axioms of a mathematical
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     7
development.  They are built, starting from the Pure theory, by extending
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
     8
and merging existing theories.  They have the \ML\ type \ttindex{theory}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     9
Theory operations signal errors by raising exception \ttindex{THEORY},
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    10
returning a message and a list of theories.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    11
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    12
Signatures, which contain information about sorts, types, constants and
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    13
syntax, have the \ML\ type~\ttindexbold{Sign.sg}.  For identification,
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    14
each signature carries a unique list of {\bf stamps}, which are \ML\
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    15
references (to strings).  The strings serve as human-readable names; the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    16
references serve as unique identifiers.  Each primitive signature has a
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    17
single stamp.  When two signatures are merged, their lists of stamps are
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    18
also merged.  Every theory carries a unique signature.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    19
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    20
Terms and types are the underlying representation of logical syntax.  Their
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    21
\ML\ definitions are irrelevant to naive Isabelle users.  Programmers who
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    22
wish to extend Isabelle may need to know such details, say to code a tactic
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    23
that looks for subgoals of a particular form.  Terms and types may be
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    24
`certified' to be well-formed with respect to a given signature.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    25
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    26
\section{Defining Theories}\label{DefiningTheories}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    27
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    28
Theories can be defined either using concrete syntax or by calling certain
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    29
\ML{} functions (see \S\ref{BuildingATheory}).  Appendix~\ref{app:TheorySyntax}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    30
presents the concrete syntax for theories.  A theory definition consists of
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    31
several different parts: 
138
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
    32
\begin{description} 
273
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    33
\item[{\it theoryDef}] A theory has a name $id$ and is an extension of the
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    34
  union of theories with name {\it name}, the {\bf parent
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    35
    theories}\indexbold{theories!parent}, with new classes, types, constants,
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    36
  syntax and axioms.  The basic theory, which contains only the meta-logic,
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    37
  is called {\tt Pure}.
138
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
    38
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    39
  Normally each {\it name\/} is an identifier, the precise name of the parent
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    40
  theory. Strings can be used to document additional dependencies; see
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    41
  \S\ref{LoadingTheories} for details.
273
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    42
\item[$classes$] {\tt$id$ < $id@1$ \dots\ $id@n$} declares $id$ as a subclass
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    43
  of existing classes $id@1\dots id@n$.  This rules out cyclic class
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    44
  structures.  Isabelle automatically computes the transitive closure of
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    45
  subclass hierarchies.  Hence it is not necessary to declare {\tt c < e} in
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    46
  addition to {\tt c < d} and {\tt d < e}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    47
\item[$default$] introduces $sort$ as the new default sort for type
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    48
  variables.  Unconstrained type variables in an input string are
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    49
  automatically constrained by $sort$; this does not apply to type variables
273
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    50
  created internally during type inference.  If omitted, the default sort is
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    51
  the union of the default sorts of the parent theories.
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    52
\item[$sort$] is a finite set of classes; a single class $id$ abbreviates the
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    53
  singleton set {\tt\{}$id${\tt\}}.
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    54
\item[$type$] is either the declaration of a new type (constructor) or type
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    55
  synonym $name$. Only binary type constructors can have infix status and
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    56
  symbolic names, e.g.\ {\tt ('a,'b)"*"}. Type constructors of $n$ arguments
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    57
  are declared by $(\alpha@1,\dots,\alpha@n)name$.  A {\bf type
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    58
    synonym}\indexbold{types!synonyms} is simply an abbreviation
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    59
  $(\alpha@1,\dots,\alpha@n)name = \mbox{\tt"}\tau\mbox{\tt"}$ and follows
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    60
  the same rules as in \ML, except that $name$ can be a string and $\tau$
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    61
  must be enclosed in quotation marks.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    62
\item[$infix$] declares a type or constant to be an infix operator of
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    63
  priority $nat$ associating to the left ({\tt infixl}) or right ({\tt
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    64
    infixr}).
273
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    65
\item[$arities$] Each $name$ must be an existing type constructor which is
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    66
  given the additional arity $arity$.
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    67
\item[$constDecl$] Each new constant $name$ is declared to be of type
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    68
  $string$.  For display purposes $mixfix$ annotations can be attached.
273
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    69
\item[$mixfix$] There are three forms of syntactic annotations:
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    70
  \begin{itemize}
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    71
  \item A mixfix template given as a $string$ of the form
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    72
    {\tt"}\dots{\tt\_}\dots{\tt\_}\dots{\tt"} where the $i$-th underscore
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    73
    indicates the position where the $i$-th argument should go. The minimal
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    74
    priority of each argument is given by a list of natural numbers, the
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    75
    priority of the whole construct by the following natural number;
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    76
    priorities are optional.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    77
273
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    78
  \item Binary constants can be given infix status.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    79
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    80
  \item A constant $f$ {\tt::} $(\tau@1\To\tau@2)\To\tau@3$ can be given {\bf
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    81
    binder} status: the declaration {\tt binder} $\cal Q$ $p$ causes
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    82
  ${\cal Q}\,x.F(x)$ to be treated
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    83
  like $f(F)$, where $p$ is the priority.
273
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    84
  \end{itemize}
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    85
\item[$trans$] Specifies syntactic translation rules, that is parse 
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    86
  rules ({\tt =>}), print rules ({\tt <=}), or both ({\tt ==}).
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    87
\item[$rule$] A rule consists of a name $id$ and a formula $string$.  Rule
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    88
  names must be distinct.
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    89
\item[$ml$] This final part of a theory consists of \ML\ code, 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    90
  typically for parse and print translations.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    91
\end{description}
273
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
    92
The $mixfix$, $trans$ and $ml$ sections are explained in more detail in 
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    93
the {\it Defining Logics} chapter of {\it Isabelle's Object Logics}.
145
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
    94
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
    95
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
    96
\subsection{*Classes and arities}
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    97
\index{*classes!context conditions}\index{*arities!context conditions}
145
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
    98
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
    99
In order to guarantee principal types~\cite{nipkow-prehofer},
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   100
classes and arities must obey two conditions:
145
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   101
\begin{itemize}
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   102
\item There must be no two declarations $ty :: (\vec{r})c$ and $ty ::
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   103
  (\vec{s})c$ with $\vec{r} \neq \vec{s}$.  For example, the following is
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   104
  forbidden:
145
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   105
\begin{ttbox}
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   106
types 'a ty
145
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   107
arities ty :: ({\ttlbrace}logic{\ttrbrace}) logic
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   108
        ty :: ({\ttlbrace}{\ttrbrace})logic
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   109
\end{ttbox}
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   110
145
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   111
\item If there are two declarations $ty :: (s@1,\dots,s@n)c$ and $ty ::
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   112
  (s@1',\dots,s@n')c'$ such that $c' < c$ then $s@i' \preceq s@i$ must hold
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   113
  for $i=1,\dots,n$.  The relationship $\preceq$, defined as
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   114
\[ s' \preceq s \iff \forall c\in s. \exists c'\in s'.~ c'\le c, \]
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   115
expresses that the set of types represented by $s'$ is a subset of the set of
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   116
types represented by $s$.  For example, the following is forbidden:
145
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   117
\begin{ttbox}
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   118
classes term < logic
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   119
types 'a ty
145
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   120
arities ty :: ({\ttlbrace}logic{\ttrbrace})logic
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   121
        ty :: ({\ttlbrace}{\ttrbrace})term
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   122
\end{ttbox}
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   123
145
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   124
\end{itemize}
422197c5a078 added subsection 'Classes and types';
wenzelm
parents: 141
diff changeset
   125
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   126
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   127
\section{Loading a new theory}
138
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
   128
\label{LoadingTheories}
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   129
\index{theories!loading}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   130
\begin{ttbox} 
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   131
use_thy         : string -> unit
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   132
time_use_thy    : string -> unit
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   133
loadpath        : string list ref \hfill{\bf initially {\tt["."]}}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   134
delete_tmpfiles : bool ref \hfill{\bf initially true}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   135
\end{ttbox}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   136
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   137
\begin{description}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   138
\item[\ttindexbold{use_thy} $thyname$] 
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   139
  reads the theory $thyname$ and creates an \ML{} structure as described below.
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   140
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   141
\item[\ttindexbold{time_use_thy} $thyname$] 
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   142
  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
   143
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   144
\item[\ttindexbold{loadpath}] 
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   145
  contains a list of directories to search when locating the files that
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   146
  define a theory.  This list is only used if the theory name in {\tt
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   147
    use_thy} does not specify the path explicitly.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   148
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   149
\item[\ttindexbold{delete_tmpfiles} \tt:= false;] 
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   150
suppresses the deletion of temporary files.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   151
\end{description}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   152
%
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   153
Each theory definition must reside in a separate file.  Let the file {\it
139
4f83c0a0c3f4 minor changes
nipkow
parents: 138
diff changeset
   154
  tf}{\tt.thy} contain the definition of a theory called $TF$ with parent
138
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
   155
theories $TB@1$ \dots $TB@n$.  Calling \ttindexbold{use_thy}~{\tt"}{\it
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   156
  TF\/}{\tt"} reads file {\it tf}{\tt.thy}, writes an intermediate \ML{}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   157
file {\tt.}{\it tf}{\tt.thy.ML}, and reads the latter file.  Recursive {\tt
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   158
  use_thy} calls load those parent theories that have not been loaded
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   159
previously; the recursion may continue to any depth.  One {\tt use_thy}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   160
call can read an entire logic if all theories are linked appropriately.
138
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
   161
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   162
The result is an \ML\ structure~$TF$ containing a component {\tt thy} for
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   163
the new theory and components $r@1$ \dots $r@n$ for the rules.  The
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   164
structure also contains the definitions of the {\tt ML} section, if
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   165
present.  The file {\tt.}{\it tf}{\tt.thy.ML} is then deleted if
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   166
\ttindexbold{delete_tmpfiles} is set to {\tt true} and no errors occurred.
138
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
   167
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   168
Finally the file {\it tf}{\tt.ML} is read, if it exists.  This file
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   169
normally contains proofs involving the new theory.  It is also possible to
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   170
provide only a {\tt.ML} file, with no {\tt.thy} file.  In this case the
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   171
{\tt.ML} file must declare an \ML\ structure having the theory's name.  If
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   172
both the {\tt.thy} file and a structure declaration in the {\tt.ML} file
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   173
exist, then the latter declaration is used.  See {\tt ZF/ex/llist.ML} for
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   174
an example.
138
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
   175
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   176
\indexbold{theories!names of}\indexbold{files!names of}
273
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
   177
\begin{warn}
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   178
  Case is significant.  The argument of \ttindex{use_thy} must be the exact
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   179
  theory name.  The corresponding filenames are derived by appending
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   180
  {\tt.thy} or {\tt.ML} to the theory's name {\it after conversion to lower
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   181
    case}. 
273
538db1a98ba3 *** empty log message ***
nipkow
parents: 185
diff changeset
   182
\end{warn}
138
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
   183
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
   184
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   185
\section{Reloading modified theories}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   186
\indexbold{theories!reloading}\index{*update|(}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   187
\begin{ttbox} 
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   188
update     : unit -> unit
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   189
unlink_thy : string -> unit
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   190
\end{ttbox}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   191
Isabelle keeps track of all loaded theories and their files.  If
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   192
\ttindex{use_thy} finds that the theory to be loaded has been read before,
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   193
it determines whether to reload the theory as follows.  First it looks for
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   194
the theory's files in their previous location.  If it finds them, it
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   195
compares their modification times to the internal data and stops if they
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   196
are equal.  If the files have been moved, {\tt use_thy} searches for them
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   197
as it would for a new theory.  After {\tt use_thy} reloads a theory, it
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   198
marks the children as out-of-date.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   199
\begin{warn}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   200
  Changing a theory on disk often makes it necessary to reload all theories
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   201
  descended from it.  However, {\tt use_thy} reads only one theory, even if
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   202
  some of the parent theories are out of date.  In this case you should
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   203
  call {\tt update()}.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   204
\end{warn}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   205
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   206
\begin{description}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   207
\item[\ttindexbold{update} ()] 
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   208
  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
   209
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   210
\item[\ttindexbold{unlink_thy} $thyname$]\indexbold{theories!removing}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   211
  informs Isabelle that theory $thyname$ no longer exists.  If you delete the
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   212
  theory files for $thyname$ then you must execute {\tt unlink_thy};
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   213
  otherwise {\tt update} will complain about a missing file.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   214
\end{description}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   215
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   216
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   217
\subsection{Important note for Poly/ML users}\index{Poly/\ML}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   218
The theory mechanism depends upon reference variables.  At the end of a
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   219
Poly/\ML{} session, the contents of references are lost unless they are
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   220
declared in the current database.  Assignments to references in the {\tt
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   221
  Pure} database are lost, including all information about loaded theories.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   222
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   223
To avoid losing such information (assuming you have loaded some theories)
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   224
you must declare a new {\tt Readthy} structure in the child database:
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   225
\begin{ttbox}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   226
structure Readthy = ReadthyFUN (structure ThySyn = ThySyn);
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   227
Readthy.loaded_thys := !loaded_thys;
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   228
open Readthy;
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   229
\end{ttbox}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   230
This copies into the new reference \verb$loaded_thys$ the contents of the
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   231
original reference, which is the list of already loaded theories.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   232
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   233
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   234
\subsection{*Pseudo theories}\indexbold{theories!pseudo}
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   235
Any automatic reloading facility requires complete knowledge of all
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   236
dependencies.  Sometimes theories depend on objects created in \ML{} files
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   237
with no associated {\tt.thy} file.  Unless such dependencies are documented,
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   238
{\tt update} fails to reload these \ML{} files and the system is left in a
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   239
state where some objects, e.g.\ theorems, still refer to old versions of
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   240
theories. This may lead to the error
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   241
\begin{ttbox}
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   242
Attempt to merge different versions of theory: \(T\)
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   243
\end{ttbox}
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   244
Therefore there is a way to link theories and {\em orphaned\/} \ML{} files ---
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   245
those without associated {\tt.thy} file.
138
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
   246
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   247
Let us assume we have an orphaned \ML{} file named {\tt orphan.ML} and a theory
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   248
$B$ which depends on {\tt orphan.ML} (for example, {\tt b.ML} uses theorems
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   249
that are proved in {\tt orphan.ML}). Then {\tt b.thy} should mention this
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   250
dependence:
138
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
   251
\begin{ttbox}
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   252
B = ... + "orphan" + ...
138
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
   253
\end{ttbox}
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   254
Although {\tt orphan} is {\em not\/} used in building the base of theory $B$
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   255
(strings stand for \ML{} files rather than {\tt.thy} files and merely document
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   256
additional dependencies), {\tt orphan.ML} is loaded automatically when $B$ is
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   257
(re)built.
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   258
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   259
If {\tt orphan.ML} depends on theories $A@1\dots A@n$, this should be recorded
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   260
by creating a {\bf pseudo theory} in the file {\tt orphan.thy}:
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   261
\begin{ttbox}
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   262
orphan = A1 + \(...\) + An
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   263
\end{ttbox}
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   264
The resulting theory is a dummy, but it ensures that {\tt update} reloads
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   265
theory {\it orphan} 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
   266
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
   267
For an extensive example of how this technique can be used to link over 30
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   268
files and load them by just two {\tt use_thy} calls, consult the ZF source
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   269
files.
138
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
   270
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   271
\index{*update|)}
138
9ba8bff1addc added chapter "Defining Theories" and made changes for new Readthy functions
clasohm
parents: 104
diff changeset
   272
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   273
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   274
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   275
\section{Basic operations on theories}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   276
\subsection{Extracting an axiom from a theory}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   277
\index{theories!extracting axioms|bold}\index{axioms}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   278
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   279
get_axiom: theory -> string -> thm
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   280
assume_ax: theory -> string -> thm
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   281
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   282
\begin{description}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   283
\item[\ttindexbold{get_axiom} $thy$ $name$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   284
returns an axiom with the given $name$ from $thy$, raising exception
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   285
\ttindex{THEORY} if none exists.  Merging theories can cause several axioms
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   286
to have the same name; {\tt get_axiom} returns an arbitrary one.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   287
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   288
\item[\ttindexbold{assume_ax} $thy$ $formula$] 
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   289
  reads the {\it formula} using the syntax of $thy$, following the same
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   290
  conventions as axioms in a theory definition.  You can thus pretend that
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   291
  {\it formula} is an axiom and use the resulting theorem like an axiom.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   292
  Actually {\tt assume_ax} returns an assumption;  \ttindex{result}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   293
  complains about additional assumptions, but \ttindex{uresult} does not.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   294
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   295
For example, if {\it formula} is
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   296
\hbox{\tt a=b ==> b=a} then the resulting theorem might have the form
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   297
\hbox{\tt\frenchspacing ?a=?b ==> ?b=?a  [!!a b. a=b ==> b=a]}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   298
\end{description}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   299
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   300
\subsection{Building a theory}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   301
\label{BuildingATheory}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   302
\index{theories!constructing|bold}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   303
\begin{ttbox} 
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   304
pure_thy: theory
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   305
merge_theories: theory * theory -> theory
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   306
extend_theory: theory -> string -> \(\cdots\) -> theory
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   307
\end{ttbox}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   308
\begin{description}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   309
\item[\ttindexbold{pure_thy}] contains just the types, constants, and syntax
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   310
  of the meta-logic.  There are no axioms: meta-level inferences are carried
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   311
  out by \ML\ functions.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   312
\item[\ttindexbold{merge_theories} ($thy@1$, $thy@2$)] merges the two
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   313
  theories $thy@1$ and $thy@2$.  The resulting theory contains all types,
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   314
  constants and axioms of the constituent theories; its default sort is the
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   315
  union of the default sorts of the constituent theories.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   316
\item [\ttindexbold{extend_theory} $thy$ {\tt"}$T${\tt"} $\cdots$] extends
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   317
  the theory $thy$ with new types, constants, etc.  $T$ identifies the theory
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   318
  internally.  When a theory is redeclared, say to change an incorrect axiom,
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   319
  bindings to the old axiom may persist.  Isabelle ensures that the old and
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   320
  new theories are not involved in the same proof.  Attempting to combine
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   321
  different theories having the same name $T$ yields the fatal error
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   322
\begin{ttbox}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   323
Attempt to merge different versions of theory: \(T\)
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   324
\end{ttbox}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   325
\end{description}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   326
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   327
%\item [\ttindexbold{extend_theory} $thy$ {\tt"}$T${\tt"}
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   328
%      ($classes$, $default$, $types$, $arities$, $consts$, $sextopt$) $rules$]
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   329
%\hfill\break   %%% include if line is just too short
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   330
%is the \ML{} equivalent of the following theory definition:
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   331
%\begin{ttbox}
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   332
%\(T\) = \(thy\) +
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   333
%classes \(c\) < \(c@1\),\(\dots\),\(c@m\)
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   334
%        \dots
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   335
%default {\(d@1,\dots,d@r\)}
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   336
%types   \(tycon@1\),\dots,\(tycon@i\) \(n\)
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   337
%        \dots
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   338
%arities \(tycon@1'\),\dots,\(tycon@j'\) :: (\(s@1\),\dots,\(s@n\))\(c\)
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   339
%        \dots
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   340
%consts  \(b@1\),\dots,\(b@k\) :: \(\tau\)
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   341
%        \dots
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   342
%rules   \(name\) \(rule\)
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   343
%        \dots
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   344
%end
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   345
%\end{ttbox}
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   346
%where
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   347
%\begin{tabular}[t]{l@{~=~}l}
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   348
%$classes$ & \tt[("$c$",["$c@1$",\dots,"$c@m$"]),\dots] \\
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   349
%$default$ & \tt["$d@1$",\dots,"$d@r$"]\\
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   350
%$types$   & \tt[([$tycon@1$,\dots,$tycon@i$], $n$),\dots] \\
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   351
%$arities$ & \tt[([$tycon'@1$,\dots,$tycon'@j$], ([$s@1$,\dots,$s@n$],$c$)),\dots]
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   352
%\\
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   353
%$consts$  & \tt[([$b@1$,\dots,$b@k$],$\tau$),\dots] \\
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   354
%$rules$   & \tt[("$name$",$rule$),\dots]
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   355
%\end{tabular}
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   356
%
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   357
%If theories are defined as in \S\ref{DefiningTheories}, new syntax is added
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   358
%as mixfix annotations to constants.  Using {\tt extend_theory}, new syntax can
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   359
%be added via $sextopt$ which is either {\tt None}, or {\tt Some($sext$)}.  The
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   360
%latter case is not documented.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   361
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   362
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   363
\subsection{Inspecting a theory}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   364
\index{theories!inspecting|bold}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   365
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   366
print_theory  : theory -> unit
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   367
axioms_of     : theory -> (string*thm)list
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   368
parents_of    : theory -> theory list
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   369
sign_of       : theory -> Sign.sg
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   370
stamps_of_thy : theory -> string ref list
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   371
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   372
These provide a simple means of viewing a theory's components.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   373
Unfortunately, there is no direct connection between a theorem and its
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   374
theory.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   375
\begin{description}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   376
\item[\ttindexbold{print_theory} {\it thy}]  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   377
prints the theory {\it thy\/} at the terminal as a set of identifiers.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   378
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   379
\item[\ttindexbold{axioms_of} $thy$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   380
returns the axioms of~$thy$ and its ancestors.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   381
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   382
\item[\ttindexbold{parents_of} $thy$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   383
returns the parents of~$thy$.  This list contains zero, one or two
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   384
elements, depending upon whether $thy$ is {\tt pure_thy}, 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   385
\hbox{\tt extend_theory $thy$} or \hbox{\tt merge_theories ($thy@1$, $thy@2$)}.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   386
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   387
\item[\ttindexbold{stamps_of_thy} $thy$]\index{signatures}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   388
returns the stamps of the signature associated with~$thy$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   389
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   390
\item[\ttindexbold{sign_of} $thy$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   391
returns the signature associated with~$thy$.  It is useful with functions
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   392
like {\tt read_instantiate_sg}, which take a signature as an argument.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   393
\end{description}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   394
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   395
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   396
\section{Terms}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   397
\index{terms|bold}
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   398
Terms belong to the \ML\ type \ttindexbold{term}, which is a concrete datatype
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   399
with six constructors: there are six kinds of term.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   400
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   401
type indexname = string * int;
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   402
infix 9 $;
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   403
datatype term = Const of string * typ
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   404
              | Free  of string * typ
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   405
              | Var   of indexname * typ
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   406
              | Bound of int
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   407
              | Abs   of string * typ * term
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   408
              | op $  of term * term;
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   409
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   410
\begin{description}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   411
\item[\ttindexbold{Const}($a$, $T$)] 
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   412
  is the {\bf constant} with name~$a$ and type~$T$.  Constants include
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   413
  connectives like $\land$ and $\forall$ as well as constants like~0
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   414
  and~$Suc$.  Other constants may be required to define a logic's concrete
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   415
  syntax. 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   416
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   417
\item[\ttindexbold{Free}($a$, $T$)] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   418
is the {\bf free variable} with name~$a$ and type~$T$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   419
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   420
\item[\ttindexbold{Var}($v$, $T$)] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   421
is the {\bf scheme variable} with indexname~$v$ and type~$T$.  An
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   422
\ttindexbold{indexname} is a string paired with a non-negative index, or
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   423
subscript; a term's scheme variables can be systematically renamed by
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   424
incrementing their subscripts.  Scheme variables are essentially free
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   425
variables, but may be instantiated during unification.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   426
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   427
\item[\ttindexbold{Bound} $i$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   428
is the {\bf bound variable} with de Bruijn index~$i$, which counts the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   429
number of lambdas, starting from zero, between a variable's occurrence and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   430
its binding.  The representation prevents capture of variables.  For more
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   431
information see de Bruijn \cite{debruijn72} or
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   432
Paulson~\cite[page~336]{paulson91}.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   433
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   434
\item[\ttindexbold{Abs}($a$, $T$, $u$)] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   435
is the {\bf abstraction} with body~$u$, and whose bound variable has
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   436
name~$a$ and type~$T$.  The name is used only for parsing and printing; it
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   437
has no logical significance.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   438
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   439
\item[\tt $t$ \$ $u$] \index{$@{\tt\$}|bold}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   440
is the {\bf application} of~$t$ to~$u$.  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   441
\end{description}
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   442
Application is written as an infix operator to aid readability.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   443
Here is an \ML\ pattern to recognize first-order formula of
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   444
the form~$A\imp B$, binding the subformulae to~$A$ and~$B$:
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   445
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   446
Const("Trueprop",_) $ (Const("op -->",_) $ A $ B)
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   447
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   448
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   449
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   450
\section{Terms and variable binding}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   451
\begin{ttbox}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   452
loose_bnos     : term -> int list
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   453
incr_boundvars : int -> term -> term
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   454
abstract_over  : term*term -> term
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   455
variant_abs    : string * typ * term -> string * term
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   456
aconv          : term*term -> bool\hfill{\bf infix}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   457
\end{ttbox}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   458
These functions are all concerned with the de Bruijn representation of
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   459
bound variables.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   460
\begin{description}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   461
\item[\ttindexbold{loose_bnos} $t$] 
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   462
  returns the list of all dangling bound variable references.  In
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   463
  particular, {\tt Bound~0} is loose unless it is enclosed in an
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   464
  abstraction.  Similarly {\tt Bound~1} is loose unless it is enclosed in
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   465
  at least two abstractions; if enclosed in just one, the list will contain
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   466
  the number 0.  A well-formed term does not contain any loose variables.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   467
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   468
\item[\ttindexbold{incr_boundvars} $j$] 
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   469
  increases a term's dangling bound variables by the offset~$j$.  This
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   470
  required when moving a subterm into a context where it is enclosed by a
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   471
  different number of abstractions.  Bound variables with a matching
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   472
  abstraction are unaffected.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   473
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   474
\item[\ttindexbold{abstract_over} $(v,t)$] 
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   475
  forms the abstraction of~$t$ over~$v$, which may be any well-formed term.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   476
  It replaces every occurrence of \(v\) by a {\tt Bound} variable with the
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   477
  correct index.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   478
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   479
\item[\ttindexbold{variant_abs} $(a,T,u)$] 
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   480
  substitutes into $u$, which should be the body of an abstraction.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   481
  It replaces each occurrence of the outermost bound variable by a free
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   482
  variable.  The free variable has type~$T$ and its name is a variant
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   483
  of~$a$ choosen to be distinct from all constants and from all variables
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   484
  free in~$u$.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   485
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   486
\item[$t$ \ttindexbold{aconv} $u$] 
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   487
  tests whether terms~$t$ and~$u$ are \(\alpha\)-convertible: identical up
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   488
  to renaming of bound variables.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   489
\begin{itemize}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   490
  \item
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   491
    Two constants, {\tt Free}s, or {\tt Var}s are \(\alpha\)-convertible
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   492
    if their names and types are equal.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   493
    (Variables having the same name but different types are thus distinct.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   494
    This confusing situation should be avoided!)
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   495
  \item
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   496
    Two bound variables are \(\alpha\)-convertible
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   497
    if they have the same number.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   498
  \item
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   499
    Two abstractions are \(\alpha\)-convertible
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   500
    if their bodies are, and their bound variables have the same type.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   501
  \item
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   502
    Two applications are \(\alpha\)-convertible
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   503
    if the corresponding subterms are.
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   504
\end{itemize}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   505
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   506
\end{description}
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   507
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   508
\section{Certified terms}\index{terms!certified|bold}\index{signatures} 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   509
A term $t$ can be {\bf certified} under a signature to ensure that every
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   510
type in~$t$ is declared in the signature and every constant in~$t$ is
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   511
declared as a constant of the same type in the signature.  It must be
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   512
well-typed and its use of bound variables must be well-formed.  Meta-rules
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   513
such as {\tt forall_elim} take certified terms as arguments.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   514
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   515
Certified terms belong to the abstract type \ttindexbold{cterm}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   516
Elements of the type can only be created through the certification process.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   517
In case of error, Isabelle raises exception~\ttindex{TERM}\@.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   518
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   519
\subsection{Printing terms}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   520
\index{printing!terms|bold}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   521
\begin{ttbox} 
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   522
     string_of_cterm :           cterm -> string
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   523
Sign.string_of_term  : Sign.sg -> term -> string
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   524
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   525
\begin{description}
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   526
\item[\ttindexbold{string_of_cterm} $ct$] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   527
displays $ct$ as a string.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   528
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   529
\item[\ttindexbold{Sign.string_of_term} $sign$ $t$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   530
displays $t$ as a string, using the syntax of~$sign$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   531
\end{description}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   532
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   533
\subsection{Making and inspecting certified terms}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   534
\begin{ttbox} 
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   535
cterm_of   : Sign.sg -> term -> cterm
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   536
read_cterm : Sign.sg -> string * typ -> cterm
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   537
rep_cterm  : cterm -> \{T:typ, t:term, sign:Sign.sg, maxidx:int\}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   538
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   539
\begin{description}
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   540
\item[\ttindexbold{cterm_of} $sign$ $t$] \index{signatures}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   541
certifies $t$ with respect to signature~$sign$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   542
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   543
\item[\ttindexbold{read_cterm} $sign$ ($s$, $T$)] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   544
reads the string~$s$ using the syntax of~$sign$, creating a certified term.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   545
The term is checked to have type~$T$; this type also tells the parser what
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   546
kind of phrase to parse.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   547
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   548
\item[\ttindexbold{rep_cterm} $ct$] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   549
decomposes $ct$ as a record containing its type, the term itself, its
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   550
signature, and the maximum subscript of its unknowns.  The type and maximum
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   551
subscript are computed during certification.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   552
\end{description}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   553
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   554
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   555
\section{Types}\index{types|bold} 
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   556
Types belong to the \ML\ type \ttindexbold{typ}, which is a concrete
286
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   557
datatype with three constructor functions.  These correspond to type
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   558
constructors, free type variables and schematic type variables.  Types are
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   559
classified by sorts, which are lists of classes.  A class is represented by
e7efbf03562b first draft of Springer book
lcp
parents: 275
diff changeset
   560
a string.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   561
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   562
type class = string;
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   563
type sort  = class list;
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   564
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   565
datatype typ = Type  of string * typ list
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   566
             | TFree of string * sort
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   567
             | TVar  of indexname * sort;
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   568
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   569
infixr 5 -->;
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   570
fun S --> T = Type("fun",[S,T]);
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   571
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   572
\begin{description}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   573
\item[\ttindexbold{Type}($a$, $Ts$)] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   574
applies the {\bf type constructor} named~$a$ to the type operands~$Ts$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   575
Type constructors include~\ttindexbold{fun}, the binary function space
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   576
constructor, as well as nullary type constructors such
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   577
as~\ttindexbold{prop}.  Other type constructors may be introduced.  In
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   578
expressions, but not in patterns, \hbox{\tt$S$-->$T$} is a convenient
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   579
shorthand for function types.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   580
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   581
\item[\ttindexbold{TFree}($a$, $s$)] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   582
is the {\bf free type variable} with name~$a$ and sort~$s$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   583
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   584
\item[\ttindexbold{TVar}($v$, $s$)] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   585
is the {\bf scheme type variable} with indexname~$v$ and sort~$s$.  Scheme
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   586
type variables are essentially free type variables, but may be instantiated
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   587
during unification.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   588
\end{description}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   589
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   590
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   591
\section{Certified types}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   592
\index{types!certified|bold}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   593
Certified types, which are analogous to certified terms, have type 
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   594
\ttindexbold{ctyp}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   595
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   596
\subsection{Printing types}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   597
\index{printing!types|bold}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   598
\begin{ttbox} 
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   599
     string_of_ctyp :           ctyp -> string
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   600
Sign.string_of_typ  : Sign.sg -> typ -> string
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   601
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   602
\begin{description}
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   603
\item[\ttindexbold{string_of_ctyp} $cT$] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   604
displays $cT$ as a string.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   605
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   606
\item[\ttindexbold{Sign.string_of_typ} $sign$ $T$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   607
displays $T$ as a string, using the syntax of~$sign$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   608
\end{description}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   609
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   610
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   611
\subsection{Making and inspecting certified types}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   612
\begin{ttbox} 
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   613
ctyp_of  : Sign.sg -> typ -> ctyp
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   614
rep_ctyp : ctyp -> \{T: typ, sign: Sign.sg\}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   615
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   616
\begin{description}
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   617
\item[\ttindexbold{ctyp_of} $sign$ $T$] \index{signatures}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   618
certifies $T$ with respect to signature~$sign$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   619
275
933ec96c522e update towards LNCS
nipkow
parents: 273
diff changeset
   620
\item[\ttindexbold{rep_ctyp} $cT$] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   621
decomposes $cT$ as a record containing the type itself and its signature.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   622
\end{description}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   623
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   624
\index{theories|)}