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