doc-src/IsarImplementation/Thy/document/Tactic.tex
changeset 46259 6fab37137dcb
parent 46258 89ee3bc580a8
child 46260 9be4ff2dd91e
equal deleted inserted replaced
46258:89ee3bc580a8 46259:6fab37137dcb
   570 %
   570 %
   571 \isadelimmlref
   571 \isadelimmlref
   572 %
   572 %
   573 \endisadelimmlref
   573 \endisadelimmlref
   574 %
   574 %
       
   575 \isamarkupsubsection{Repetition tacticals%
       
   576 }
       
   577 \isamarkuptrue%
       
   578 %
       
   579 \begin{isamarkuptext}%
       
   580 These tacticals provide further control over repetition of
       
   581   tactics, beyond the stylized forms of ``\verb|?|''  and
       
   582   ``\verb|+|'' in Isar method expressions.%
       
   583 \end{isamarkuptext}%
       
   584 \isamarkuptrue%
       
   585 %
       
   586 \isadelimmlref
       
   587 %
       
   588 \endisadelimmlref
       
   589 %
       
   590 \isatagmlref
       
   591 %
       
   592 \begin{isamarkuptext}%
       
   593 \begin{mldecls}
       
   594   \indexdef{}{ML}{TRY}\verb|TRY: tactic -> tactic| \\
       
   595   \indexdef{}{ML}{REPEAT\_DETERM}\verb|REPEAT_DETERM: tactic -> tactic| \\
       
   596   \indexdef{}{ML}{REPEAT\_DETERM\_N}\verb|REPEAT_DETERM_N: int -> tactic -> tactic| \\
       
   597   \indexdef{}{ML}{REPEAT}\verb|REPEAT: tactic -> tactic| \\
       
   598   \indexdef{}{ML}{REPEAT1}\verb|REPEAT1: tactic -> tactic| \\
       
   599   \indexdef{}{ML}{DETERM\_UNTIL}\verb|DETERM_UNTIL: (thm -> bool) -> tactic -> tactic| \\
       
   600   \end{mldecls}
       
   601 
       
   602   \begin{description}
       
   603 
       
   604   \item \verb|TRY|~\isa{tac} applies \isa{tac} to the proof
       
   605   state and returns the resulting sequence, if non-empty; otherwise it
       
   606   returns the original state.  Thus, it applies \isa{tac} at most
       
   607   once.
       
   608 
       
   609   \item \verb|REPEAT_DETERM|~\isa{tac} applies \isa{tac} to the
       
   610   proof state and, recursively, to the head of the resulting sequence.
       
   611   It returns the first state to make \isa{tac} fail.  It is
       
   612   deterministic, discarding alternative outcomes.
       
   613 
       
   614   \item \verb|REPEAT_DETERM_N|~\isa{n\ tac} is like \verb|REPEAT_DETERM|~\isa{tac} but the number of repetitions is bound
       
   615   by \isa{n} (where \verb|~1| means \isa{{\isaliteral{5C3C696E66696E6974793E}{\isasyminfinity}}}).
       
   616 
       
   617   \item \verb|REPEAT|~\isa{tac} applies \isa{tac} to the proof
       
   618   state and, recursively, to each element of the resulting sequence.
       
   619   The resulting sequence consists of those states that make \isa{tac} fail.  Thus, it applies \isa{tac} as many times as
       
   620   possible (including zero times), and allows backtracking over each
       
   621   invocation of \isa{tac}.  \verb|REPEAT| is more general than \verb|REPEAT_DETERM|, but requires more space.
       
   622 
       
   623   \item \verb|REPEAT1|~\isa{tac} is like \verb|REPEAT|~\isa{tac}
       
   624   but it always applies \isa{tac} at least once, failing if this
       
   625   is impossible.
       
   626 
       
   627   \item \verb|DETERM_UNTIL|~\isa{P\ tac} applies \isa{tac} to
       
   628   the proof state and, recursively, to the head of the resulting
       
   629   sequence, until the predicate \isa{P} (applied on the proof
       
   630   state) yields \verb|true|. It fails if \isa{tac} fails on any of
       
   631   the intermediate states. It is deterministic, discarding alternative
       
   632   outcomes.
       
   633 
       
   634   \end{description}%
       
   635 \end{isamarkuptext}%
       
   636 \isamarkuptrue%
       
   637 %
       
   638 \endisatagmlref
       
   639 {\isafoldmlref}%
       
   640 %
       
   641 \isadelimmlref
       
   642 %
       
   643 \endisadelimmlref
       
   644 %
       
   645 \isamarkupsubsection{Identities for tacticals%
       
   646 }
       
   647 \isamarkuptrue%
       
   648 %
       
   649 \isadelimmlref
       
   650 %
       
   651 \endisadelimmlref
       
   652 %
       
   653 \isatagmlref
       
   654 %
       
   655 \begin{isamarkuptext}%
       
   656 \begin{mldecls}
       
   657   \indexdef{}{ML}{all\_tac}\verb|all_tac: tactic| \\
       
   658   \indexdef{}{ML}{no\_tac}\verb|no_tac: tactic| \\
       
   659   \end{mldecls}
       
   660 
       
   661   \begin{description}
       
   662 
       
   663   \item \verb|all_tac| maps any proof state to the one-element sequence
       
   664   containing that state.  Thus, it succeeds for all states.  It is the
       
   665   identity element of the tactical \verb|op THEN|.
       
   666 
       
   667   \item \verb|no_tac| maps any proof state to the empty sequence.  Thus
       
   668   it succeeds for no state.  It is the identity element of
       
   669   \verb|op ORELSE| and \verb|op APPEND|.  Also, it is a zero element
       
   670   for \verb|op THEN|, which means that \isa{tac\ THEN}~\verb|no_tac| is equivalent to \verb|no_tac|.
       
   671 
       
   672   \end{description}%
       
   673 \end{isamarkuptext}%
       
   674 \isamarkuptrue%
       
   675 %
       
   676 \endisatagmlref
       
   677 {\isafoldmlref}%
       
   678 %
       
   679 \isadelimmlref
       
   680 %
       
   681 \endisadelimmlref
       
   682 %
       
   683 \isadelimmlex
       
   684 %
       
   685 \endisadelimmlex
       
   686 %
       
   687 \isatagmlex
       
   688 %
       
   689 \begin{isamarkuptext}%
       
   690 The following examples illustrate how these primitive
       
   691   tactics can be used to imitate existing combinators like \verb|TRY|
       
   692   or \verb|REPEAT| (ignoring some further implementation tricks):%
       
   693 \end{isamarkuptext}%
       
   694 \isamarkuptrue%
       
   695 %
       
   696 \endisatagmlex
       
   697 {\isafoldmlex}%
       
   698 %
       
   699 \isadelimmlex
       
   700 %
       
   701 \endisadelimmlex
       
   702 %
       
   703 \isadelimML
       
   704 %
       
   705 \endisadelimML
       
   706 %
       
   707 \isatagML
       
   708 \isacommand{ML}\isamarkupfalse%
       
   709 \ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline
       
   710 \ \ fun\ TRY\ tac\ {\isaliteral{3D}{\isacharequal}}\ tac\ ORELSE\ all{\isaliteral{5F}{\isacharunderscore}}tac{\isaliteral{3B}{\isacharsemicolon}}\isanewline
       
   711 \ \ fun\ REPEAT\ tac\ st\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{28}{\isacharparenleft}}tac\ THEN\ REPEAT\ tac{\isaliteral{29}{\isacharparenright}}\ ORELSE\ all{\isaliteral{5F}{\isacharunderscore}}tac{\isaliteral{29}{\isacharparenright}}\ st{\isaliteral{3B}{\isacharsemicolon}}\isanewline
       
   712 {\isaliteral{2A7D}{\isacharverbatimclose}}%
       
   713 \endisatagML
       
   714 {\isafoldML}%
       
   715 %
       
   716 \isadelimML
       
   717 %
       
   718 \endisadelimML
       
   719 %
       
   720 \begin{isamarkuptext}%
       
   721 If \isa{tac} can return multiple outcomes then so can \verb|REPEAT|~\isa{tac}.  \verb|REPEAT| uses \verb|op ORELSE| and not
       
   722   \verb|op APPEND|, it applies \isa{tac} as many times as
       
   723   possible in each outcome.
       
   724 
       
   725   \begin{warn}
       
   726   Note \verb|REPEAT|'s explicit abstraction over the proof state.
       
   727   Recursive tacticals must be coded in this awkward fashion to avoid
       
   728   infinite recursion.  With the following definition, \verb|REPEAT|~\isa{tac} would loop due to the eager evaluation
       
   729   strategy of ML:
       
   730   \end{warn}%
       
   731 \end{isamarkuptext}%
       
   732 \isamarkuptrue%
       
   733 %
       
   734 \isadelimML
       
   735 %
       
   736 \endisadelimML
       
   737 %
       
   738 \isatagML
       
   739 \isacommand{ML}\isamarkupfalse%
       
   740 \ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline
       
   741 \ \ fun\ REPEAT\ tac\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}tac\ THEN\ REPEAT\ tac{\isaliteral{29}{\isacharparenright}}\ ORELSE\ all{\isaliteral{5F}{\isacharunderscore}}tac{\isaliteral{3B}{\isacharsemicolon}}\ \ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{2A}{\isacharasterisk}}BAD{\isaliteral{21}{\isacharbang}}{\isaliteral{2A}{\isacharasterisk}}{\isaliteral{29}{\isacharparenright}}\isanewline
       
   742 {\isaliteral{2A7D}{\isacharverbatimclose}}%
       
   743 \endisatagML
       
   744 {\isafoldML}%
       
   745 %
       
   746 \isadelimML
       
   747 %
       
   748 \endisadelimML
       
   749 \isanewline
       
   750 %
   575 \isadelimtheory
   751 \isadelimtheory
       
   752 \isanewline
   576 %
   753 %
   577 \endisadelimtheory
   754 \endisadelimtheory
   578 %
   755 %
   579 \isatagtheory
   756 \isatagtheory
   580 \isacommand{end}\isamarkupfalse%
   757 \isacommand{end}\isamarkupfalse%