doc-src/Ref/undocumented.tex
author Walther Neuper <neuper@ist.tugraz.at>
Thu, 12 Aug 2010 15:03:34 +0200
branchisac-from-Isabelle2009-2
changeset 37913 20e3616b2d9c
parent 4276 a770eae2cdb0
permissions -rw-r--r--
prepare reactivation of isac-update-Isa09-2
lcp@104
     1
%%%%Currently UNDOCUMENTED low-level functions!  from previous manual
lcp@104
     2
lcp@104
     3
%%%%Low level information about terms and module Logic.
lcp@104
     4
%%%%Mainly used for implementation of Pure.
lcp@104
     5
lcp@104
     6
%move to ML sources?
lcp@104
     7
lcp@104
     8
\subsection{Basic declarations}
lcp@104
     9
The implication symbol is {\tt implies}.
lcp@104
    10
lcp@104
    11
The term \verb|all T| is the universal quantifier for type {\tt T}\@.
lcp@104
    12
lcp@104
    13
The term \verb|equals T| is the equality predicate for type {\tt T}\@.
lcp@104
    14
lcp@104
    15
lcp@104
    16
There are a number of basic functions on terms and types.
lcp@104
    17
lcp@104
    18
\index{--->}
lcp@104
    19
\beginprog
lcp@104
    20
op ---> : typ list * typ -> typ
lcp@104
    21
\endprog
lcp@104
    22
Given types \([ \tau_1, \ldots, \tau_n]\) and \(\tau\), it
lcp@104
    23
forms the type \(\tau_1\to \cdots \to (\tau_n\to\tau)\).
lcp@104
    24
lcp@104
    25
Calling {\prog{}type_of \${t}}\index{type_of} computes the type of the
lcp@104
    26
term~$t$.  Raises exception {\tt TYPE} unless applications are well-typed.
lcp@104
    27
lcp@104
    28
lcp@104
    29
Calling \verb|subst_bounds|$([u_{n-1},\ldots,u_0],\,t)$\index{subst_bounds}
lcp@104
    30
substitutes the $u_i$ for loose bound variables in $t$.  This achieves
lcp@104
    31
\(\beta\)-reduction of \(u_{n-1} \cdots u_0\) into $t$, replacing {\tt
lcp@104
    32
Bound~i} with $u_i$.  For \((\lambda x y.t)(u,v)\), the bound variable
lcp@104
    33
indices in $t$ are $x:1$ and $y:0$.  The appropriate call is
lcp@104
    34
\verb|subst_bounds([v,u],t)|.  Loose bound variables $\geq n$ are reduced
lcp@104
    35
by $n$ to compensate for the disappearance of $n$ lambdas.
lcp@104
    36
lcp@104
    37
\index{maxidx_of_term}
lcp@104
    38
\beginprog
lcp@104
    39
maxidx_of_term: term -> int
lcp@104
    40
\endprog
lcp@104
    41
Computes the maximum index of all the {\tt Var}s in a term.
lcp@104
    42
If there are no {\tt Var}s, the result is \(-1\).
lcp@104
    43
lcp@104
    44
\index{term_match}
lcp@104
    45
\beginprog
lcp@104
    46
term_match: (term*term)list * term*term -> (term*term)list
lcp@104
    47
\endprog
lcp@104
    48
Calling \verb|term_match(vts,t,u)| instantiates {\tt Var}s in {\tt t} to
lcp@104
    49
match it with {\tt u}.  The resulting list of variable/term pairs extends
lcp@104
    50
{\tt vts}, which is typically empty.  First-order pattern matching is used
lcp@104
    51
to implement meta-level rewriting.
lcp@104
    52
lcp@104
    53
lcp@104
    54
\subsection{The representation of object-rules}
lcp@104
    55
The module {\tt Logic} contains operations concerned with inference ---
lcp@104
    56
especially, for constructing and destructing terms that represent
lcp@104
    57
object-rules.
lcp@104
    58
lcp@104
    59
\index{occs}
lcp@104
    60
\beginprog
lcp@104
    61
op occs: term*term -> bool
lcp@104
    62
\endprog
lcp@104
    63
Does one term occur in the other?
lcp@104
    64
(This is a reflexive relation.)
lcp@104
    65
lcp@104
    66
\index{add_term_vars}
lcp@104
    67
\beginprog
lcp@104
    68
add_term_vars: term*term list -> term list
lcp@104
    69
\endprog
lcp@104
    70
Accumulates the {\tt Var}s in the term, suppressing duplicates.
lcp@104
    71
The second argument should be the list of {\tt Var}s found so far.
lcp@104
    72
lcp@104
    73
\index{add_term_frees}
lcp@104
    74
\beginprog
lcp@104
    75
add_term_frees: term*term list -> term list
lcp@104
    76
\endprog
lcp@104
    77
Accumulates the {\tt Free}s in the term, suppressing duplicates.
lcp@104
    78
The second argument should be the list of {\tt Free}s found so far.
lcp@104
    79
lcp@104
    80
\index{mk_equals}
lcp@104
    81
\beginprog
lcp@104
    82
mk_equals: term*term -> term
lcp@104
    83
\endprog
lcp@104
    84
Given $t$ and $u$ makes the term $t\equiv u$.
lcp@104
    85
lcp@104
    86
\index{dest_equals}
lcp@104
    87
\beginprog
lcp@104
    88
dest_equals: term -> term*term
lcp@104
    89
\endprog
lcp@104
    90
Given $t\equiv u$ returns the pair $(t,u)$.
lcp@104
    91
lcp@104
    92
\index{list_implies:}
lcp@104
    93
\beginprog
lcp@104
    94
list_implies: term list * term -> term
lcp@104
    95
\endprog
lcp@104
    96
Given the pair $([\phi_1,\ldots, \phi_m], \phi)$
lcp@104
    97
makes the term \([\phi_1;\ldots; \phi_m] \Imp \phi\).
lcp@104
    98
lcp@104
    99
\index{strip_imp_prems}
lcp@104
   100
\beginprog
lcp@104
   101
strip_imp_prems: term -> term list
lcp@104
   102
\endprog
lcp@104
   103
Given \([\phi_1;\ldots; \phi_m] \Imp \phi\)
lcp@104
   104
returns the list \([\phi_1,\ldots, \phi_m]\). 
lcp@104
   105
lcp@104
   106
\index{strip_imp_concl}
lcp@104
   107
\beginprog
lcp@104
   108
strip_imp_concl: term -> term
lcp@104
   109
\endprog
lcp@104
   110
Given \([\phi_1;\ldots; \phi_m] \Imp \phi\)
lcp@104
   111
returns the term \(\phi\). 
lcp@104
   112
lcp@104
   113
\index{list_equals}
lcp@104
   114
\beginprog
lcp@104
   115
list_equals: (term*term)list * term -> term
lcp@104
   116
\endprog
lcp@104
   117
For adding flex-flex constraints to an object-rule. 
lcp@104
   118
Given $([(t_1,u_1),\ldots, (t_k,u_k)], \phi)$,
lcp@104
   119
makes the term \([t_1\equiv u_1;\ldots; t_k\equiv u_k]\Imp \phi\).
lcp@104
   120
lcp@104
   121
\index{strip_equals}
lcp@104
   122
\beginprog
lcp@104
   123
strip_equals: term -> (term*term) list * term
lcp@104
   124
\endprog
lcp@104
   125
Given \([t_1\equiv u_1;\ldots; t_k\equiv u_k]\Imp \phi\),
lcp@104
   126
returns $([(t_1,u_1),\ldots, (t_k,u_k)], \phi)$.
lcp@104
   127
lcp@104
   128
\index{rule_of}
lcp@104
   129
\beginprog
lcp@104
   130
rule_of: (term*term)list * term list * term -> term
lcp@104
   131
\endprog
lcp@104
   132
Makes an object-rule: given the triple
lcp@104
   133
\[ ([(t_1,u_1),\ldots, (t_k,u_k)], [\phi_1,\ldots, \phi_m], \phi) \]
lcp@104
   134
returns the term
lcp@104
   135
\([t_1\equiv u_1;\ldots; t_k\equiv u_k; \phi_1;\ldots; \phi_m]\Imp \phi\)
lcp@104
   136
lcp@104
   137
\index{strip_horn}
lcp@104
   138
\beginprog
lcp@104
   139
strip_horn: term -> (term*term)list * term list * term
lcp@104
   140
\endprog
lcp@104
   141
Breaks an object-rule into its parts: given
lcp@104
   142
\[ [t_1\equiv u_1;\ldots; t_k\equiv u_k; \phi_1;\ldots; \phi_m] \Imp \phi \]
lcp@104
   143
returns the triple
lcp@104
   144
\(([(t_k,u_k),\ldots, (t_1,u_1)], [\phi_1,\ldots, \phi_m], \phi).\)
lcp@104
   145
lcp@104
   146
\index{strip_assums}
lcp@104
   147
\beginprog
lcp@104
   148
strip_assums: term -> (term*int) list * (string*typ) list * term
lcp@104
   149
\endprog
lcp@104
   150
Strips premises of a rule allowing a more general form,
lcp@104
   151
where $\Forall$ and $\Imp$ may be intermixed.
lcp@104
   152
This is typical of assumptions of a subgoal in natural deduction.
lcp@104
   153
Returns additional information about the number, names,
lcp@104
   154
and types of quantified variables.
lcp@104
   155
lcp@104
   156
lcp@104
   157
\index{strip_prems}
lcp@104
   158
\beginprog
lcp@104
   159
strip_prems: int * term list * term -> term list * term
lcp@104
   160
\endprog
lcp@104
   161
For finding premise (or subgoal) $i$: given the triple
lcp@104
   162
\( (i, [], \phi_1;\ldots \phi_i\Imp \phi) \)
lcp@104
   163
it returns another triple,
lcp@104
   164
\((\phi_i, [\phi_{i-1},\ldots, \phi_1], \phi)\),
paulson@3485
   165
where $\phi$ need not be atomic.  Raises an exception if $i$ is out of
lcp@104
   166
range.
lcp@104
   167
lcp@104
   168
lcp@104
   169
\subsection{Environments}
lcp@104
   170
The module {\tt Envir} (which is normally closed)
lcp@104
   171
declares a type of environments.
lcp@104
   172
An environment holds variable assignments
lcp@104
   173
and the next index to use when generating a variable.
lcp@104
   174
\par\indent\vbox{\small \begin{verbatim}
lcp@104
   175
    datatype env = Envir of {asol: term xolist, maxidx: int}
lcp@104
   176
\end{verbatim}}
lcp@104
   177
The operations of lookup, update, and generation of variables
lcp@104
   178
are used during unification.
lcp@104
   179
lcp@104
   180
\beginprog
lcp@104
   181
empty: int->env
lcp@104
   182
\endprog
lcp@104
   183
Creates the environment with no assignments
lcp@104
   184
and the given index.
lcp@104
   185
lcp@104
   186
\beginprog
lcp@104
   187
lookup: env * indexname -> term option
lcp@104
   188
\endprog
lcp@104
   189
Looks up a variable, specified by its indexname,
lcp@104
   190
and returns {\tt None} or {\tt Some} as appropriate.
lcp@104
   191
lcp@104
   192
\beginprog
lcp@104
   193
update: (indexname * term) * env -> env
lcp@104
   194
\endprog
lcp@104
   195
Given a variable, term, and environment,
lcp@104
   196
produces {\em a new environment\/} where the variable has been updated.
lcp@104
   197
This has no side effect on the given environment.
lcp@104
   198
lcp@104
   199
\beginprog
lcp@104
   200
genvar: env * typ -> env * term
lcp@104
   201
\endprog
lcp@104
   202
Generates a variable of the given type and returns it,
lcp@104
   203
paired with a new environment (with incremented {\tt maxidx} field).
lcp@104
   204
lcp@104
   205
\beginprog
lcp@104
   206
alist_of: env -> (indexname * term) list
lcp@104
   207
\endprog
lcp@104
   208
Converts an environment into an association list
lcp@104
   209
containing the assignments.
lcp@104
   210
lcp@104
   211
\beginprog
lcp@104
   212
norm_term: env -> term -> term
lcp@104
   213
\endprog
lcp@104
   214
lcp@104
   215
Copies a term, 
lcp@104
   216
following assignments in the environment,
lcp@104
   217
and performing all possible \(\beta\)-reductions.
lcp@104
   218
lcp@104
   219
\beginprog
lcp@104
   220
rewrite: (env * (term*term)list) -> term -> term
lcp@104
   221
\endprog
lcp@104
   222
Rewrites a term using the given term pairs as rewrite rules.  Assignments
lcp@104
   223
are ignored; the environment is used only with {\tt genvar}, to generate
lcp@104
   224
unique {\tt Var}s as placeholders for bound variables.
lcp@104
   225
lcp@104
   226
lcp@104
   227
\subsection{The unification functions}
lcp@104
   228
lcp@104
   229
lcp@104
   230
\beginprog
wenzelm@4276
   231
unifiers: env * ((term*term)list) -> (env * (term*term)list) Seq.seq
lcp@104
   232
\endprog
lcp@104
   233
This is the main unification function.
lcp@104
   234
Given an environment and a list of disagreement pairs,
lcp@104
   235
it returns a sequence of outcomes.
lcp@104
   236
Each outcome consists of an updated environment and 
lcp@104
   237
a list of flex-flex pairs (these are discussed below).
lcp@104
   238
lcp@104
   239
\beginprog
wenzelm@4276
   240
smash_unifiers: env * (term*term)list -> env Seq.seq
lcp@104
   241
\endprog
lcp@104
   242
This unification function maps an environment and a list of disagreement
paulson@3485
   243
pairs to a sequence of updated environments.  The function obliterates
paulson@3485
   244
flex-flex pairs by choosing the obvious unifier.  It may be used to tidy up
lcp@104
   245
any flex-flex pairs remaining at the end of a proof.
lcp@104
   246
lcp@104
   247
lcp@104
   248
\subsubsection{Multiple unifiers}
lcp@104
   249
The unification procedure performs Huet's {\sc match} operation
lcp@104
   250
\cite{huet75} in big steps.
lcp@104
   251
It solves \(\Var{f}(t_1,\ldots,t_p) \equiv u\) for \(\Var{f}\) by finding
lcp@104
   252
all ways of copying \(u\), first trying projection on the arguments
lcp@104
   253
\(t_i\).  It never copies below any variable in \(u\); instead it returns a
lcp@104
   254
new variable, resulting in a flex-flex disagreement pair.  
lcp@104
   255
lcp@104
   256
lcp@104
   257
\beginprog
lcp@104
   258
type_assign: cterm -> cterm
lcp@104
   259
\endprog
lcp@104
   260
Produces a cterm by updating the signature of its argument
lcp@104
   261
to include all variable/type assignments.
lcp@104
   262
Type inference under the resulting signature will assume the
lcp@104
   263
same type assignments as in the argument.
lcp@104
   264
This is used in the goal package to give persistence to type assignments
lcp@104
   265
within each proof. 
lcp@104
   266
(Contrast with {\sc lcf}'s sticky types \cite[page 148]{paulson-book}.)
lcp@104
   267
lcp@104
   268