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