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 |
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. |
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 |
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 |
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|)} |