doc-src/Ref/tactic.tex
author lcp
Fri, 15 Apr 1994 17:16:23 +0200
changeset 323 361a71713176
parent 286 e7efbf03562b
child 332 01b87a921967
permissions -rw-r--r--
penultimate Springer draft
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     1
%% $Id$
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     2
\chapter{Tactics} \label{tactics}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     3
\index{tactics|(}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
     4
Tactics have type \mltydx{tactic}.  They are essentially
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     5
functions from theorems to theorem sequences, where the theorems represent
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     6
states of a backward proof.  Tactics seldom need to be coded from scratch,
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
     7
as functions; instead they are expressed using basic tactics and tacticals.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     8
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
     9
\section{Resolution and assumption tactics}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    10
{\bf Resolution} is Isabelle's basic mechanism for refining a subgoal using
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    11
a rule.  {\bf Elim-resolution} is particularly suited for elimination
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    12
rules, while {\bf destruct-resolution} is particularly suited for
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    13
destruction rules.  The {\tt r}, {\tt e}, {\tt d} naming convention is
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    14
maintained for several different kinds of resolution tactics, as well as
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    15
the shortcuts in the subgoal module.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    16
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    17
All the tactics in this section act on a subgoal designated by a positive
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    18
integer~$i$.  They fail (by returning the empty sequence) if~$i$ is out of
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    19
range.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    20
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    21
\subsection{Resolution tactics}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    22
\index{resolution!tactics}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    23
\index{tactics!resolution|bold}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    24
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    25
resolve_tac  : thm list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    26
eresolve_tac : thm list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    27
dresolve_tac : thm list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    28
forward_tac  : thm list -> int -> tactic 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    29
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    30
These perform resolution on a list of theorems, $thms$, representing a list
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    31
of object-rules.  When generating next states, they take each of the rules
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    32
in the order given.  Each rule may yield several next states, or none:
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    33
higher-order resolution may yield multiple resolvents.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    34
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    35
\item[\ttindexbold{resolve_tac} {\it thms} {\it i}] 
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    36
  refines the proof state using the rules, which should normally be
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    37
  introduction rules.  It resolves a rule's conclusion with
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    38
  subgoal~$i$ of the proof state.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    39
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    40
\item[\ttindexbold{eresolve_tac} {\it thms} {\it i}] 
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    41
  \index{elim-resolution}
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    42
  performs elim-resolution with the rules, which should normally be
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    43
  elimination rules.  It resolves with a rule, solves its first premise by
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    44
  assumption, and finally {\em deletes\/} that assumption from any new
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    45
  subgoals.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    46
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    47
\item[\ttindexbold{dresolve_tac} {\it thms} {\it i}] 
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    48
  \index{forward proof}\index{destruct-resolution}
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    49
  performs destruct-resolution with the rules, which normally should
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    50
  be destruction rules.  This replaces an assumption by the result of
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    51
  applying one of the rules.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    52
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    53
\item[\ttindexbold{forward_tac}]\index{forward proof}
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    54
  is like {\tt dresolve_tac} except that the selected assumption is not
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    55
  deleted.  It applies a rule to an assumption, adding the result as a new
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    56
  assumption.
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    57
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    58
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    59
\subsection{Assumption tactics}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    60
\index{tactics!assumption|bold}\index{assumptions!tactics for}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    61
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    62
assume_tac    : int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    63
eq_assume_tac : int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    64
\end{ttbox} 
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    65
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    66
\item[\ttindexbold{assume_tac} {\it i}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    67
attempts to solve subgoal~$i$ by assumption.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    68
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    69
\item[\ttindexbold{eq_assume_tac}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    70
is like {\tt assume_tac} but does not use unification.  It succeeds (with a
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    71
{\em unique\/} next state) if one of the assumptions is identical to the
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    72
subgoal's conclusion.  Since it does not instantiate variables, it cannot
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    73
make other subgoals unprovable.  It is intended to be called from proof
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    74
strategies, not interactively.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    75
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    76
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    77
\subsection{Matching tactics} \label{match_tac}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    78
\index{tactics!matching}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    79
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    80
match_tac  : thm list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    81
ematch_tac : thm list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    82
dmatch_tac : thm list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    83
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    84
These are just like the resolution tactics except that they never
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    85
instantiate unknowns in the proof state.  Flexible subgoals are not updated
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    86
willy-nilly, but are left alone.  Matching --- strictly speaking --- means
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    87
treating the unknowns in the proof state as constants; these tactics merely
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    88
discard unifiers that would update the proof state.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    89
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    90
\item[\ttindexbold{match_tac} {\it thms} {\it i}] 
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    91
refines the proof state using the rules, matching a rule's
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    92
conclusion with subgoal~$i$ of the proof state.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    93
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    94
\item[\ttindexbold{ematch_tac}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    95
is like {\tt match_tac}, but performs elim-resolution.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    96
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    97
\item[\ttindexbold{dmatch_tac}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
    98
is like {\tt match_tac}, but performs destruct-resolution.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
    99
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   100
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   101
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   102
\subsection{Resolution with instantiation} \label{res_inst_tac}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   103
\index{tactics!instantiation}\index{instantiation}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   104
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   105
res_inst_tac  : (string*string)list -> thm -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   106
eres_inst_tac : (string*string)list -> thm -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   107
dres_inst_tac : (string*string)list -> thm -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   108
forw_inst_tac : (string*string)list -> thm -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   109
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   110
These tactics are designed for applying rules such as substitution and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   111
induction, which cause difficulties for higher-order unification.  The
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   112
tactics accept explicit instantiations for schematic variables in the rule
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   113
--- typically, in the rule's conclusion.  Each instantiation is a pair
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   114
{\tt($v$,$e$)}, where $v$ can be a type variable or ordinary variable:
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   115
\begin{itemize}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   116
\item If $v$ is the {\bf type variable} {\tt'a}, then
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   117
the rule must contain a schematic type variable \verb$?'a$ of some
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   118
sort~$s$, and $e$ should be a type of sort $s$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   119
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   120
\item If $v$ is the {\bf variable} {\tt P}, then
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   121
the rule must contain a schematic variable \verb$?P$ of some type~$\tau$,
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   122
and $e$ should be a term of some type~$\sigma$ such that $\tau$ and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   123
$\sigma$ are unifiable.  If the unification of $\tau$ and $\sigma$
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   124
instantiates any schematic type variables in $\tau$, these instantiations
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   125
are recorded for application to the rule.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   126
\end{itemize}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   127
Types are instantiated before terms.  Because type instantiations are
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   128
inferred from term instantiations, explicit type instantiations are seldom
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   129
necessary --- if \verb$?t$ has type \verb$?'a$, then the instantiation list
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   130
\verb$[("'a","bool"),("t","True")]$ may be simplified to
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   131
\verb$[("t","True")]$.  Type unknowns in the proof state may cause
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   132
failure because the tactics cannot instantiate them.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   133
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   134
The instantiation tactics act on a given subgoal.  Terms in the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   135
instantiations are type-checked in the context of that subgoal --- in
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   136
particular, they may refer to that subgoal's parameters.  Any unknowns in
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   137
the terms receive subscripts and are lifted over the parameters; thus, you
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   138
may not refer to unknowns in the subgoal.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   139
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   140
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   141
\item[\ttindexbold{res_inst_tac} {\it insts} {\it thm} {\it i}]
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   142
instantiates the rule {\it thm} with the instantiations {\it insts}, as
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   143
described above, and then performs resolution on subgoal~$i$.  Resolution
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   144
typically causes further instantiations; you need not give explicit
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   145
instantiations for every variable in the rule.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   146
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   147
\item[\ttindexbold{eres_inst_tac}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   148
is like {\tt res_inst_tac}, but performs elim-resolution.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   149
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   150
\item[\ttindexbold{dres_inst_tac}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   151
is like {\tt res_inst_tac}, but performs destruct-resolution.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   152
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   153
\item[\ttindexbold{forw_inst_tac}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   154
is like {\tt dres_inst_tac} except that the selected assumption is not
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   155
deleted.  It applies the instantiated rule to an assumption, adding the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   156
result as a new assumption.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   157
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   158
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   159
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   160
\section{Other basic tactics}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   161
\subsection{Definitions and meta-level rewriting}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   162
\index{tactics!meta-rewriting|bold}\index{meta-rewriting|bold}
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   163
\index{definitions}
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   164
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   165
Definitions in Isabelle have the form $t\equiv u$, where typically $t$ is a
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   166
constant or a constant applied to a list of variables, for example $\it
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   167
sqr(n)\equiv n\times n$.  (Conditional definitions, $\phi\Imp t\equiv u$,
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   168
are not supported.)  {\bf Unfolding} the definition $t\equiv u$ means using
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   169
it as a rewrite rule, replacing~$t$ by~$u$ throughout a theorem.  {\bf
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   170
Folding} $t\equiv u$ means replacing~$u$ by~$t$.  Rewriting continues until
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   171
no rewrites are applicable to any subterm.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   172
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   173
There are rules for unfolding and folding definitions; Isabelle does not do
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   174
this automatically.  The corresponding tactics rewrite the proof state,
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   175
yielding a unique result.  See also the {\tt goalw} command, which is the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   176
easiest way of handling definitions.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   177
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   178
rewrite_goals_tac : thm list -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   179
rewrite_tac       : thm list -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   180
fold_goals_tac    : thm list -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   181
fold_tac          : thm list -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   182
\end{ttbox}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   183
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   184
\item[\ttindexbold{rewrite_goals_tac} {\it defs}]  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   185
unfolds the {\it defs} throughout the subgoals of the proof state, while
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   186
leaving the main goal unchanged.  Use \ttindex{SELECT_GOAL} to restrict it to a
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   187
particular subgoal.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   188
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   189
\item[\ttindexbold{rewrite_tac} {\it defs}]  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   190
unfolds the {\it defs} throughout the proof state, including the main goal
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   191
--- not normally desirable!
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   192
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   193
\item[\ttindexbold{fold_goals_tac} {\it defs}]  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   194
folds the {\it defs} throughout the subgoals of the proof state, while
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   195
leaving the main goal unchanged.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   196
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   197
\item[\ttindexbold{fold_tac} {\it defs}]  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   198
folds the {\it defs} throughout the proof state.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   199
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   200
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   201
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   202
\subsection{Tactic shortcuts}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   203
\index{shortcuts!for tactics}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   204
\index{tactics!resolution}\index{tactics!assumption}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   205
\index{tactics!meta-rewriting}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   206
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   207
rtac     : thm -> int ->tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   208
etac     : thm -> int ->tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   209
dtac     : thm -> int ->tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   210
atac     : int ->tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   211
ares_tac : thm list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   212
rewtac   : thm -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   213
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   214
These abbreviate common uses of tactics.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   215
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   216
\item[\ttindexbold{rtac} {\it thm} {\it i}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   217
abbreviates \hbox{\tt resolve_tac [{\it thm}] {\it i}}, doing resolution.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   218
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   219
\item[\ttindexbold{etac} {\it thm} {\it i}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   220
abbreviates \hbox{\tt eresolve_tac [{\it thm}] {\it i}}, doing elim-resolution.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   221
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   222
\item[\ttindexbold{dtac} {\it thm} {\it i}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   223
abbreviates \hbox{\tt dresolve_tac [{\it thm}] {\it i}}, doing
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   224
destruct-resolution.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   225
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   226
\item[\ttindexbold{atac} {\it i}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   227
is a synonym for \hbox{\tt assume_tac {\it i}}, doing proof by assumption.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   228
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   229
\item[\ttindexbold{ares_tac} {\it thms} {\it i}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   230
tries proof by assumption and resolution; it abbreviates
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   231
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   232
assume_tac {\it i} ORELSE resolve_tac {\it thms} {\it i}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   233
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   234
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   235
\item[\ttindexbold{rewtac} {\it def}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   236
abbreviates \hbox{\tt rewrite_goals_tac [{\it def}]}, unfolding a definition.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   237
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   238
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   239
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   240
\subsection{Inserting premises and facts}\label{cut_facts_tac}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   241
\index{tactics!for inserting facts}\index{assumptions!inserting}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   242
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   243
cut_facts_tac : thm list -> int -> tactic
286
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   244
cut_inst_tac  : (string*string)list -> thm -> int -> tactic
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   245
subgoal_tac   : string -> int -> tactic
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   246
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   247
These tactics add assumptions --- which must be proved, sooner or later ---
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   248
to a given subgoal.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   249
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   250
\item[\ttindexbold{cut_facts_tac} {\it thms} {\it i}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   251
  adds the {\it thms} as new assumptions to subgoal~$i$.  Once they have
286
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   252
  been inserted as assumptions, they become subject to tactics such as {\tt
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   253
    eresolve_tac} and {\tt rewrite_goals_tac}.  Only rules with no premises
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   254
  are inserted: Isabelle cannot use assumptions that contain $\Imp$
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   255
  or~$\Forall$.  Sometimes the theorems are premises of a rule being
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   256
  derived, returned by~{\tt goal}; instead of calling this tactic, you
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   257
  could state the goal with an outermost meta-quantifier.
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   258
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   259
\item[\ttindexbold{cut_inst_tac} {\it insts} {\it thm} {\it i}]
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   260
  instantiates the {\it thm} with the instantiations {\it insts}, as
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   261
  described in \S\ref{res_inst_tac}.  It adds the resulting theorem as a
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   262
  new assumption to subgoal~$i$. 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   263
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   264
\item[\ttindexbold{subgoal_tac} {\it formula} {\it i}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   265
adds the {\it formula} as a assumption to subgoal~$i$, and inserts the same
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   266
{\it formula} as a new subgoal, $i+1$.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   267
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   268
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   269
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   270
\subsection{Theorems useful with tactics}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   271
\index{theorems!of pure theory}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   272
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   273
asm_rl: thm 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   274
cut_rl: thm 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   275
\end{ttbox}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   276
\begin{ttdescription}
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   277
\item[\tdx{asm_rl}] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   278
is $\psi\Imp\psi$.  Under elim-resolution it does proof by assumption, and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   279
\hbox{\tt eresolve_tac (asm_rl::{\it thms}) {\it i}} is equivalent to
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   280
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   281
assume_tac {\it i}  ORELSE  eresolve_tac {\it thms} {\it i}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   282
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   283
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   284
\item[\tdx{cut_rl}] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   285
is $\List{\psi\Imp\theta,\psi}\Imp\theta$.  It is useful for inserting
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   286
assumptions; it underlies {\tt forward_tac}, {\tt cut_facts_tac}
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   287
and {\tt subgoal_tac}.
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   288
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   289
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   290
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   291
\section{Obscure tactics}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   292
\subsection{Tidying the proof state}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   293
\index{parameters!removing unused}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   294
\index{flex-flex constraints}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   295
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   296
prune_params_tac : tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   297
flexflex_tac     : tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   298
\end{ttbox}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   299
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   300
\item[\ttindexbold{prune_params_tac}]  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   301
  removes unused parameters from all subgoals of the proof state.  It works
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   302
  by rewriting with the theorem $(\Forall x. V)\equiv V$.  This tactic can
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   303
  make the proof state more readable.  It is used with
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   304
  \ttindex{rule_by_tactic} to simplify the resulting theorem.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   305
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   306
\item[\ttindexbold{flexflex_tac}]  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   307
  removes all flex-flex pairs from the proof state by applying the trivial
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   308
  unifier.  This drastic step loses information, and should only be done as
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   309
  the last step of a proof.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   310
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   311
  Flex-flex constraints arise from difficult cases of higher-order
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   312
  unification.  To prevent this, use \ttindex{res_inst_tac} to instantiate
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   313
  some variables in a rule~(\S\ref{res_inst_tac}).  Normally flex-flex
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   314
  constraints can be ignored; they often disappear as unknowns get
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   315
  instantiated.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   316
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   317
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   318
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   319
\subsection{Renaming parameters in a goal} \index{parameters!renaming}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   320
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   321
rename_tac        : string -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   322
rename_last_tac   : string -> string list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   323
Logic.set_rename_prefix : string -> unit
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   324
Logic.auto_rename       : bool ref      \hfill{\bf initially false}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   325
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   326
When creating a parameter, Isabelle chooses its name by matching variable
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   327
names via the object-rule.  Given the rule $(\forall I)$ formalized as
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   328
$\left(\Forall x. P(x)\right) \Imp \forall x.P(x)$, Isabelle will note that
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   329
the $\Forall$-bound variable in the premise has the same name as the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   330
$\forall$-bound variable in the conclusion.  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   331
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   332
Sometimes there is insufficient information and Isabelle chooses an
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   333
arbitrary name.  The renaming tactics let you override Isabelle's choice.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   334
Because renaming parameters has no logical effect on the proof state, the
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   335
{\tt by} command prints the message {\tt Warning:\ same as previous
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   336
level}.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   337
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   338
Alternatively, you can suppress the naming mechanism described above and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   339
have Isabelle generate uniform names for parameters.  These names have the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   340
form $p${\tt a}, $p${\tt b}, $p${\tt c},~\ldots, where $p$ is any desired
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   341
prefix.  They are ugly but predictable.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   342
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   343
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   344
\item[\ttindexbold{rename_tac} {\it str} {\it i}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   345
interprets the string {\it str} as a series of blank-separated variable
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   346
names, and uses them to rename the parameters of subgoal~$i$.  The names
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   347
must be distinct.  If there are fewer names than parameters, then the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   348
tactic renames the innermost parameters and may modify the remaining ones
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   349
to ensure that all the parameters are distinct.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   350
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   351
\item[\ttindexbold{rename_last_tac} {\it prefix} {\it suffixes} {\it i}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   352
generates a list of names by attaching each of the {\it suffixes\/} to the 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   353
{\it prefix}.  It is intended for coding structural induction tactics,
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   354
where several of the new parameters should have related names.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   355
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   356
\item[\ttindexbold{Logic.set_rename_prefix} {\it prefix};] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   357
sets the prefix for uniform renaming to~{\it prefix}.  The default prefix
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   358
is {\tt"k"}.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   359
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   360
\item[\ttindexbold{Logic.auto_rename} := true;] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   361
makes Isabelle generate uniform names for parameters. 
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   362
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   363
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   364
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   365
\subsection{Composition: resolution without lifting}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   366
\index{tactics!for composition}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   367
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   368
compose_tac: (bool * thm * int) -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   369
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   370
{\bf Composing} two rules means to resolve them without prior lifting or
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   371
renaming of unknowns.  This low-level operation, which underlies the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   372
resolution tactics, may occasionally be useful for special effects.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   373
A typical application is \ttindex{res_inst_tac}, which lifts and instantiates a
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   374
rule, then passes the result to {\tt compose_tac}.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   375
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   376
\item[\ttindexbold{compose_tac} ($flag$, $rule$, $m$) $i$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   377
refines subgoal~$i$ using $rule$, without lifting.  The $rule$ is taken to
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   378
have the form $\List{\psi@1; \ldots; \psi@m} \Imp \psi$, where $\psi$ need
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   379
not be atomic; thus $m$ determines the number of new subgoals.  If
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   380
$flag$ is {\tt true} then it performs elim-resolution --- it solves the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   381
first premise of~$rule$ by assumption and deletes that assumption.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   382
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   383
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   384
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   385
\section{Managing lots of rules}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   386
These operations are not intended for interactive use.  They are concerned
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   387
with the processing of large numbers of rules in automatic proof
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   388
strategies.  Higher-order resolution involving a long list of rules is
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   389
slow.  Filtering techniques can shorten the list of rules given to
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   390
resolution, and can also detect whether a given subgoal is too flexible,
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   391
with too many rules applicable.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   392
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   393
\subsection{Combined resolution and elim-resolution} \label{biresolve_tac}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   394
\index{tactics!resolution}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   395
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   396
biresolve_tac   : (bool*thm)list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   397
bimatch_tac     : (bool*thm)list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   398
subgoals_of_brl : bool*thm -> int
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   399
lessb           : (bool*thm) * (bool*thm) -> bool
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   400
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   401
{\bf Bi-resolution} takes a list of $\it (flag,rule)$ pairs.  For each
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   402
pair, it applies resolution if the flag is~{\tt false} and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   403
elim-resolution if the flag is~{\tt true}.  A single tactic call handles a
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   404
mixture of introduction and elimination rules.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   405
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   406
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   407
\item[\ttindexbold{biresolve_tac} {\it brls} {\it i}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   408
refines the proof state by resolution or elim-resolution on each rule, as
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   409
indicated by its flag.  It affects subgoal~$i$ of the proof state.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   410
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   411
\item[\ttindexbold{bimatch_tac}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   412
is like {\tt biresolve_tac}, but performs matching: unknowns in the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   413
proof state are never updated (see~\S\ref{match_tac}).
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   414
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   415
\item[\ttindexbold{subgoals_of_brl}({\it flag},{\it rule})] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   416
returns the number of new subgoals that bi-resolution would yield for the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   417
pair (if applied to a suitable subgoal).  This is $n$ if the flag is
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   418
{\tt false} and $n-1$ if the flag is {\tt true}, where $n$ is the number
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   419
of premises of the rule.  Elim-resolution yields one fewer subgoal than
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   420
ordinary resolution because it solves the major premise by assumption.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   421
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   422
\item[\ttindexbold{lessb} ({\it brl1},{\it brl2})] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   423
returns the result of 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   424
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   425
subgoals_of_brl {\it brl1} < subgoals_of_brl {\it brl2}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   426
\end{ttbox}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   427
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   428
Note that \hbox{\tt sort lessb {\it brls}} sorts a list of $\it
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   429
(flag,rule)$ pairs by the number of new subgoals they will yield.  Thus,
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   430
those that yield the fewest subgoals should be tried first.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   431
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   432
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   433
\subsection{Discrimination nets for fast resolution}\label{filt_resolve_tac}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   434
\index{discrimination nets|bold}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   435
\index{tactics!resolution}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   436
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   437
net_resolve_tac  : thm list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   438
net_match_tac    : thm list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   439
net_biresolve_tac: (bool*thm) list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   440
net_bimatch_tac  : (bool*thm) list -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   441
filt_resolve_tac : thm list -> int -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   442
could_unify      : term*term->bool
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   443
filter_thms      : (term*term->bool) -> int*term*thm list -> thm list
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   444
\end{ttbox}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   445
The module {\tt Net} implements a discrimination net data structure for
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   446
fast selection of rules \cite[Chapter 14]{charniak80}.  A term is
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   447
classified by the symbol list obtained by flattening it in preorder.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   448
The flattening takes account of function applications, constants, and free
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   449
and bound variables; it identifies all unknowns and also regards
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   450
\index{lambda abs@$\lambda$-abstractions}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   451
$\lambda$-abstractions as unknowns, since they could $\eta$-contract to
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   452
anything.  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   453
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   454
A discrimination net serves as a polymorphic dictionary indexed by terms.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   455
The module provides various functions for inserting and removing items from
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   456
nets.  It provides functions for returning all items whose term could match
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   457
or unify with a target term.  The matching and unification tests are
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   458
overly lax (due to the identifications mentioned above) but they serve as
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   459
useful filters.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   460
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   461
A net can store introduction rules indexed by their conclusion, and
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   462
elimination rules indexed by their major premise.  Isabelle provides
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   463
several functions for `compiling' long lists of rules into fast
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   464
resolution tactics.  When supplied with a list of theorems, these functions
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   465
build a discrimination net; the net is used when the tactic is applied to a
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   466
goal.  To avoid repreatedly constructing the nets, use currying: bind the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   467
resulting tactics to \ML{} identifiers.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   468
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   469
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   470
\item[\ttindexbold{net_resolve_tac} {\it thms}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   471
builds a discrimination net to obtain the effect of a similar call to {\tt
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   472
resolve_tac}.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   473
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   474
\item[\ttindexbold{net_match_tac} {\it thms}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   475
builds a discrimination net to obtain the effect of a similar call to {\tt
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   476
match_tac}.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   477
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   478
\item[\ttindexbold{net_biresolve_tac} {\it brls}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   479
builds a discrimination net to obtain the effect of a similar call to {\tt
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   480
biresolve_tac}.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   481
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   482
\item[\ttindexbold{net_bimatch_tac} {\it brls}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   483
builds a discrimination net to obtain the effect of a similar call to {\tt
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   484
bimatch_tac}.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   485
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   486
\item[\ttindexbold{filt_resolve_tac} {\it thms} {\it maxr} {\it i}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   487
uses discrimination nets to extract the {\it thms} that are applicable to
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   488
subgoal~$i$.  If more than {\it maxr\/} theorems are applicable then the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   489
tactic fails.  Otherwise it calls {\tt resolve_tac}.  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   490
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   491
This tactic helps avoid runaway instantiation of unknowns, for example in
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   492
type inference.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   493
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   494
\item[\ttindexbold{could_unify} ({\it t},{\it u})] 
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   495
returns {\tt false} if~$t$ and~$u$ are `obviously' non-unifiable, and
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   496
otherwise returns~{\tt true}.  It assumes all variables are distinct,
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   497
reporting that {\tt ?a=?a} may unify with {\tt 0=1}.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   498
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   499
\item[\ttindexbold{filter_thms} $could\; (limit,prem,thms)$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   500
returns the list of potentially resolvable rules (in {\it thms\/}) for the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   501
subgoal {\it prem}, using the predicate {\it could\/} to compare the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   502
conclusion of the subgoal with the conclusion of each rule.  The resulting list
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   503
is no longer than {\it limit}.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   504
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   505
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   506
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   507
\section{Programming tools for proof strategies}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   508
Do not consider using the primitives discussed in this section unless you
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   509
really need to code tactics from scratch.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   510
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   511
\subsection{Operations on type {\tt tactic}}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   512
\index{tactics!primitives for coding}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   513
A tactic maps theorems to theorem sequences (lazy lists).  The type
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   514
constructor for sequences is called \mltydx{Sequence.seq}.  To simplify the
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   515
types of tactics and tacticals, Isabelle defines a type of tactics:
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   516
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   517
datatype tactic = Tactic of thm -> thm Sequence.seq
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   518
\end{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   519
{\tt Tactic} and {\tt tapply} convert between tactics and functions.  The
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   520
other operations provide means for coding tactics in a clean style.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   521
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   522
tapply    : tactic * thm -> thm Sequence.seq
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   523
Tactic    :     (thm -> thm Sequence.seq) -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   524
PRIMITIVE :                  (thm -> thm) -> tactic  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   525
STATE     :               (thm -> tactic) -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   526
SUBGOAL   : ((term*int) -> tactic) -> int -> tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   527
\end{ttbox} 
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   528
\begin{ttdescription}
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   529
\item[\ttindexbold{tapply}({\it tac}, {\it thm})]  
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   530
returns the result of applying the tactic, as a function, to {\it thm}.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   531
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   532
\item[\ttindexbold{Tactic} {\it f}]  
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   533
packages {\it f} as a tactic.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   534
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   535
\item[\ttindexbold{PRIMITIVE} $f$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   536
applies $f$ to the proof state and returns the result as a
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   537
one-element sequence.  This packages the meta-rule~$f$ as a tactic.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   538
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   539
\item[\ttindexbold{STATE} $f$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   540
applies $f$ to the proof state and then applies the resulting tactic to the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   541
same state.  It supports the following style, where the tactic body is
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   542
expressed using tactics and tacticals, but may peek at the proof state:
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   543
\begin{ttbox} 
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   544
STATE (fn state => {\it tactic-valued expression})
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   545
\end{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   546
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   547
\item[\ttindexbold{SUBGOAL} $f$ $i$] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   548
extracts subgoal~$i$ from the proof state as a term~$t$, and computes a
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   549
tactic by calling~$f(t,i)$.  It applies the resulting tactic to the same
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   550
state.  The tactic body is expressed using tactics and tacticals, but may
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   551
peek at a particular subgoal:
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   552
\begin{ttbox} 
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   553
SUBGOAL (fn (t,i) => {\it tactic-valued expression})
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   554
\end{ttbox} 
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   555
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   556
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   557
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   558
\subsection{Tracing}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   559
\index{tactics!tracing}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   560
\index{tracing!of tactics}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   561
\begin{ttbox} 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   562
pause_tac: tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   563
print_tac: tactic
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   564
\end{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   565
These violate the functional behaviour of tactics by printing information
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   566
when they are applied to a proof state.  Their output may be difficult to
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   567
interpret.  Note that certain of the searching tacticals, such as {\tt
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   568
REPEAT}, have built-in tracing options.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   569
\begin{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   570
\item[\ttindexbold{pause_tac}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   571
prints {\tt** Press RETURN to continue:} and then reads a line from the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   572
terminal.  If this line is blank then it returns the proof state unchanged;
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   573
otherwise it fails (which may terminate a repetition).
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   574
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   575
\item[\ttindexbold{print_tac}] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   576
returns the proof state unchanged, with the side effect of printing it at
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   577
the terminal.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   578
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   579
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   580
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   581
\section{Sequences}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   582
\index{sequences (lazy lists)|bold}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   583
The module {\tt Sequence} declares a type of lazy lists.  It uses
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   584
Isabelle's type \mltydx{option} to represent the possible presence
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   585
(\ttindexbold{Some}) or absence (\ttindexbold{None}) of
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   586
a value:
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   587
\begin{ttbox}
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   588
datatype 'a option = None  |  Some of 'a;
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   589
\end{ttbox}
286
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   590
For clarity, the module name {\tt Sequence} is omitted from the signature
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   591
specifications below; for instance, {\tt null} appears instead of {\tt
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   592
  Sequence.null}.
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   593
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   594
\subsection{Basic operations on sequences}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   595
\begin{ttbox} 
286
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   596
null   : 'a seq
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   597
seqof  : (unit -> ('a * 'a seq) option) -> 'a seq
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   598
single : 'a -> 'a seq
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   599
pull   : 'a seq -> ('a * 'a seq) option
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   600
\end{ttbox}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   601
\begin{ttdescription}
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   602
\item[Sequence.null] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   603
is the empty sequence.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   604
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   605
\item[\tt Sequence.seqof (fn()=> Some($x$,$s$))] 
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   606
constructs the sequence with head~$x$ and tail~$s$, neither of which is
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   607
evaluated.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   608
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   609
\item[Sequence.single $x$] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   610
constructs the sequence containing the single element~$x$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   611
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   612
\item[Sequence.pull $s$] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   613
returns {\tt None} if the sequence is empty and {\tt Some($x$,$s'$)} if the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   614
sequence has head~$x$ and tail~$s'$.  Warning: calling \hbox{Sequence.pull
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   615
$s$} again will {\bf recompute} the value of~$x$; it is not stored!
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   616
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   617
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   618
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   619
\subsection{Converting between sequences and lists}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   620
\begin{ttbox} 
286
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   621
chop      : int * 'a seq -> 'a list * 'a seq
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   622
list_of_s : 'a seq -> 'a list
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   623
s_of_list : 'a list -> 'a seq
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   624
\end{ttbox}
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   625
\begin{ttdescription}
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   626
\item[Sequence.chop ($n$, $s$)] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   627
returns the first~$n$ elements of~$s$ as a list, paired with the remaining
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   628
elements of~$s$.  If $s$ has fewer than~$n$ elements, then so will the
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   629
list.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   630
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   631
\item[Sequence.list_of_s $s$] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   632
returns the elements of~$s$, which must be finite, as a list.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   633
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   634
\item[Sequence.s_of_list $l$] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   635
creates a sequence containing the elements of~$l$.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   636
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   637
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   638
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   639
\subsection{Combining sequences}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   640
\begin{ttbox} 
286
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   641
append     : 'a seq * 'a seq -> 'a seq
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   642
interleave : 'a seq * 'a seq -> 'a seq
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   643
flats      : 'a seq seq -> 'a seq
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   644
maps       : ('a -> 'b) -> 'a seq -> 'b seq
e7efbf03562b first draft of Springer book
lcp
parents: 104
diff changeset
   645
filters    : ('a -> bool) -> 'a seq -> 'a seq
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   646
\end{ttbox} 
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   647
\begin{ttdescription}
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   648
\item[Sequence.append ($s@1$, $s@2$)] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   649
concatenates $s@1$ to $s@2$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   650
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   651
\item[Sequence.interleave ($s@1$, $s@2$)] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   652
joins $s@1$ with $s@2$ by interleaving their elements.  The result contains
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   653
all the elements of the sequences, even if both are infinite.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   654
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   655
\item[Sequence.flats $ss$] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   656
concatenates a sequence of sequences.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   657
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   658
\item[Sequence.maps $f$ $s$] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   659
applies $f$ to every element of~$s=x@1,x@2,\ldots$, yielding the sequence
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   660
$f(x@1),f(x@2),\ldots$.
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   661
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   662
\item[Sequence.filters $p$ $s$] 
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   663
returns the sequence consisting of all elements~$x$ of~$s$ such that $p(x)$
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   664
is {\tt true}.
323
361a71713176 penultimate Springer draft
lcp
parents: 286
diff changeset
   665
\end{ttdescription}
104
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   666
d8205bb279a7 Initial revision
lcp
parents:
diff changeset
   667
\index{tactics|)}