doc-src/TutorialI/Misc/document/simp.tex
author nipkow
Mon, 09 Oct 2000 10:18:21 +0200
changeset 10171 59d6633835fa
parent 9933 9feb1e0c4cb3
child 10187 0376cccd9118
permissions -rw-r--r--
*** empty log message ***
     1 %
     2 \begin{isabellebody}%
     3 \def\isabellecontext{simp}%
     4 %
     5 \isamarkupsubsubsection{Simplification rules}
     6 %
     7 \begin{isamarkuptext}%
     8 \indexbold{simplification rule}
     9 To facilitate simplification, theorems can be declared to be simplification
    10 rules (with the help of the attribute \isa{{\isacharbrackleft}simp{\isacharbrackright}}\index{*simp
    11   (attribute)}), in which case proofs by simplification make use of these
    12 rules automatically. In addition the constructs \isacommand{datatype} and
    13 \isacommand{primrec} (and a few others) invisibly declare useful
    14 simplification rules. Explicit definitions are \emph{not} declared
    15 simplification rules automatically!
    16 
    17 Not merely equations but pretty much any theorem can become a simplification
    18 rule. The simplifier will try to make sense of it.  For example, a theorem
    19 \isa{{\isasymnot}\ P} is automatically turned into \isa{P\ {\isacharequal}\ False}. The details
    20 are explained in \S\ref{sec:SimpHow}.
    21 
    22 The simplification attribute of theorems can be turned on and off as follows:
    23 \begin{quote}
    24 \isacommand{declare} \textit{theorem-name}\isa{{\isacharbrackleft}simp{\isacharbrackright}}\\
    25 \isacommand{declare} \textit{theorem-name}\isa{{\isacharbrackleft}simp\ del{\isacharbrackright}}
    26 \end{quote}
    27 As a rule of thumb, equations that really simplify (like \isa{rev\ {\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharequal}\ xs} and \isa{xs\ {\isacharat}\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ xs}) should be made simplification
    28 rules.  Those of a more specific nature (e.g.\ distributivity laws, which
    29 alter the structure of terms considerably) should only be used selectively,
    30 i.e.\ they should not be default simplification rules.  Conversely, it may
    31 also happen that a simplification rule needs to be disabled in certain
    32 proofs.  Frequent changes in the simplification status of a theorem may
    33 indicate a badly designed theory.
    34 \begin{warn}
    35   Simplification may not terminate, for example if both $f(x) = g(x)$ and
    36   $g(x) = f(x)$ are simplification rules. It is the user's responsibility not
    37   to include simplification rules that can lead to nontermination, either on
    38   their own or in combination with other simplification rules.
    39 \end{warn}%
    40 \end{isamarkuptext}%
    41 %
    42 \isamarkupsubsubsection{The simplification method}
    43 %
    44 \begin{isamarkuptext}%
    45 \index{*simp (method)|bold}
    46 The general format of the simplification method is
    47 \begin{quote}
    48 \isa{simp} \textit{list of modifiers}
    49 \end{quote}
    50 where the list of \emph{modifiers} helps to fine tune the behaviour and may
    51 be empty. Most if not all of the proofs seen so far could have been performed
    52 with \isa{simp} instead of \isa{auto}, except that \isa{simp} attacks
    53 only the first subgoal and may thus need to be repeated---use
    54 \isaindex{simp_all} to simplify all subgoals.
    55 Note that \isa{simp} fails if nothing changes.%
    56 \end{isamarkuptext}%
    57 %
    58 \isamarkupsubsubsection{Adding and deleting simplification rules}
    59 %
    60 \begin{isamarkuptext}%
    61 If a certain theorem is merely needed in a few proofs by simplification,
    62 we do not need to make it a global simplification rule. Instead we can modify
    63 the set of simplification rules used in a simplification step by adding rules
    64 to it and/or deleting rules from it. The two modifiers for this are
    65 \begin{quote}
    66 \isa{add{\isacharcolon}} \textit{list of theorem names}\\
    67 \isa{del{\isacharcolon}} \textit{list of theorem names}
    68 \end{quote}
    69 In case you want to use only a specific list of theorems and ignore all
    70 others:
    71 \begin{quote}
    72 \isa{only{\isacharcolon}} \textit{list of theorem names}
    73 \end{quote}%
    74 \end{isamarkuptext}%
    75 %
    76 \isamarkupsubsubsection{Assumptions}
    77 %
    78 \begin{isamarkuptext}%
    79 \index{simplification!with/of assumptions}
    80 By default, assumptions are part of the simplification process: they are used
    81 as simplification rules and are simplified themselves. For example:%
    82 \end{isamarkuptext}%
    83 \isacommand{lemma}\ {\isachardoublequote}{\isasymlbrakk}\ xs\ {\isacharat}\ zs\ {\isacharequal}\ ys\ {\isacharat}\ xs{\isacharsemicolon}\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharat}\ xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharat}\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ ys\ {\isacharequal}\ zs{\isachardoublequote}\isanewline
    84 \isacommand{apply}\ simp\isanewline
    85 \isacommand{done}%
    86 \begin{isamarkuptext}%
    87 \noindent
    88 The second assumption simplifies to \isa{xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}}, which in turn
    89 simplifies the first assumption to \isa{zs\ {\isacharequal}\ ys}, thus reducing the
    90 conclusion to \isa{ys\ {\isacharequal}\ ys} and hence to \isa{True}.
    91 
    92 In some cases this may be too much of a good thing and may lead to
    93 nontermination:%
    94 \end{isamarkuptext}%
    95 \isacommand{lemma}\ {\isachardoublequote}{\isasymforall}x{\isachardot}\ f\ x\ {\isacharequal}\ g\ {\isacharparenleft}f\ {\isacharparenleft}g\ x{\isacharparenright}{\isacharparenright}\ {\isasymLongrightarrow}\ f\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ f\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharat}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequote}%
    96 \begin{isamarkuptxt}%
    97 \noindent
    98 cannot be solved by an unmodified application of \isa{simp} because the
    99 simplification rule \isa{f\ x\ {\isacharequal}\ g\ {\isacharparenleft}f\ {\isacharparenleft}g\ x{\isacharparenright}{\isacharparenright}} extracted from the assumption
   100 does not terminate. Isabelle notices certain simple forms of
   101 nontermination but not this one. The problem can be circumvented by
   102 explicitly telling the simplifier to ignore the assumptions:%
   103 \end{isamarkuptxt}%
   104 \isacommand{apply}{\isacharparenleft}simp\ {\isacharparenleft}no{\isacharunderscore}asm{\isacharparenright}{\isacharparenright}\isanewline
   105 \isacommand{done}%
   106 \begin{isamarkuptext}%
   107 \noindent
   108 There are three options that influence the treatment of assumptions:
   109 \begin{description}
   110 \item[\isa{{\isacharparenleft}no{\isacharunderscore}asm{\isacharparenright}}]\indexbold{*no_asm}
   111  means that assumptions are completely ignored.
   112 \item[\isa{{\isacharparenleft}no{\isacharunderscore}asm{\isacharunderscore}simp{\isacharparenright}}]\indexbold{*no_asm_simp}
   113  means that the assumptions are not simplified but
   114   are used in the simplification of the conclusion.
   115 \item[\isa{{\isacharparenleft}no{\isacharunderscore}asm{\isacharunderscore}use{\isacharparenright}}]\indexbold{*no_asm_use}
   116  means that the assumptions are simplified but are not
   117   used in the simplification of each other or the conclusion.
   118 \end{description}
   119 Neither \isa{{\isacharparenleft}no{\isacharunderscore}asm{\isacharunderscore}simp{\isacharparenright}} nor \isa{{\isacharparenleft}no{\isacharunderscore}asm{\isacharunderscore}use{\isacharparenright}} allow to simplify
   120 the above problematic subgoal.
   121 
   122 Note that only one of the above options is allowed, and it must precede all
   123 other arguments.%
   124 \end{isamarkuptext}%
   125 %
   126 \isamarkupsubsubsection{Rewriting with definitions}
   127 %
   128 \begin{isamarkuptext}%
   129 \index{simplification!with definitions}
   130 Constant definitions (\S\ref{sec:ConstDefinitions}) can
   131 be used as simplification rules, but by default they are not.  Hence the
   132 simplifier does not expand them automatically, just as it should be:
   133 definitions are introduced for the purpose of abbreviating complex
   134 concepts. Of course we need to expand the definitions initially to derive
   135 enough lemmas that characterize the concept sufficiently for us to forget the
   136 original definition. For example, given%
   137 \end{isamarkuptext}%
   138 \isacommand{constdefs}\ exor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequote}\isanewline
   139 \ \ \ \ \ \ \ \ \ {\isachardoublequote}exor\ A\ B\ {\isasymequiv}\ {\isacharparenleft}A\ {\isasymand}\ {\isasymnot}B{\isacharparenright}\ {\isasymor}\ {\isacharparenleft}{\isasymnot}A\ {\isasymand}\ B{\isacharparenright}{\isachardoublequote}%
   140 \begin{isamarkuptext}%
   141 \noindent
   142 we may want to prove%
   143 \end{isamarkuptext}%
   144 \isacommand{lemma}\ {\isachardoublequote}exor\ A\ {\isacharparenleft}{\isasymnot}A{\isacharparenright}{\isachardoublequote}%
   145 \begin{isamarkuptxt}%
   146 \noindent
   147 Typically, the opening move consists in \emph{unfolding} the definition(s), which we need to
   148 get started, but nothing else:\indexbold{*unfold}\indexbold{definition!unfolding}%
   149 \end{isamarkuptxt}%
   150 \isacommand{apply}{\isacharparenleft}simp\ only{\isacharcolon}exor{\isacharunderscore}def{\isacharparenright}%
   151 \begin{isamarkuptxt}%
   152 \noindent
   153 In this particular case, the resulting goal
   154 \begin{isabelle}
   155 ~1.~A~{\isasymand}~{\isasymnot}~{\isasymnot}~A~{\isasymor}~{\isasymnot}~A~{\isasymand}~{\isasymnot}~A%
   156 \end{isabelle}
   157 can be proved by simplification. Thus we could have proved the lemma outright by%
   158 \end{isamarkuptxt}%
   159 \isacommand{apply}{\isacharparenleft}simp\ add{\isacharcolon}\ exor{\isacharunderscore}def{\isacharparenright}%
   160 \begin{isamarkuptext}%
   161 \noindent
   162 Of course we can also unfold definitions in the middle of a proof.
   163 
   164 You should normally not turn a definition permanently into a simplification
   165 rule because this defeats the whole purpose of an abbreviation.
   166 
   167 \begin{warn}
   168   If you have defined $f\,x\,y~\isasymequiv~t$ then you can only expand
   169   occurrences of $f$ with at least two arguments. Thus it is safer to define
   170   $f$~\isasymequiv~\isasymlambda$x\,y.\;t$.
   171 \end{warn}%
   172 \end{isamarkuptext}%
   173 %
   174 \isamarkupsubsubsection{Simplifying let-expressions}
   175 %
   176 \begin{isamarkuptext}%
   177 \index{simplification!of let-expressions}
   178 Proving a goal containing \isaindex{let}-expressions almost invariably
   179 requires the \isa{let}-con\-structs to be expanded at some point. Since
   180 \isa{let}-\isa{in} is just syntactic sugar for a predefined constant
   181 (called \isa{Let}), expanding \isa{let}-constructs means rewriting with
   182 \isa{Let{\isacharunderscore}def}:%
   183 \end{isamarkuptext}%
   184 \isacommand{lemma}\ {\isachardoublequote}{\isacharparenleft}let\ xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ in\ xs{\isacharat}ys{\isacharat}xs{\isacharparenright}\ {\isacharequal}\ ys{\isachardoublequote}\isanewline
   185 \isacommand{apply}{\isacharparenleft}simp\ add{\isacharcolon}\ Let{\isacharunderscore}def{\isacharparenright}\isanewline
   186 \isacommand{done}%
   187 \begin{isamarkuptext}%
   188 If, in a particular context, there is no danger of a combinatorial explosion
   189 of nested \isa{let}s one could even simlify with \isa{Let{\isacharunderscore}def} by
   190 default:%
   191 \end{isamarkuptext}%
   192 \isacommand{declare}\ Let{\isacharunderscore}def\ {\isacharbrackleft}simp{\isacharbrackright}%
   193 \isamarkupsubsubsection{Conditional equations}
   194 %
   195 \begin{isamarkuptext}%
   196 So far all examples of rewrite rules were equations. The simplifier also
   197 accepts \emph{conditional} equations, for example%
   198 \end{isamarkuptext}%
   199 \isacommand{lemma}\ hd{\isacharunderscore}Cons{\isacharunderscore}tl{\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}xs\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}\ \ {\isasymLongrightarrow}\ \ hd\ xs\ {\isacharhash}\ tl\ xs\ {\isacharequal}\ xs{\isachardoublequote}\isanewline
   200 \isacommand{apply}{\isacharparenleft}case{\isacharunderscore}tac\ xs{\isacharcomma}\ simp{\isacharcomma}\ simp{\isacharparenright}\isanewline
   201 \isacommand{done}%
   202 \begin{isamarkuptext}%
   203 \noindent
   204 Note the use of ``\ttindexboldpos{,}{$Isar}'' to string together a
   205 sequence of methods. Assuming that the simplification rule
   206 \isa{{\isacharparenleft}rev\ xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}}
   207 is present as well,%
   208 \end{isamarkuptext}%
   209 \isacommand{lemma}\ {\isachardoublequote}xs\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymLongrightarrow}\ hd{\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharhash}\ tl{\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharequal}\ rev\ xs{\isachardoublequote}%
   210 \begin{isamarkuptext}%
   211 \noindent
   212 is proved by plain simplification:
   213 the conditional equation \isa{hd{\isacharunderscore}Cons{\isacharunderscore}tl} above
   214 can simplify \isa{hd\ {\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharhash}\ tl\ {\isacharparenleft}rev\ xs{\isacharparenright}} to \isa{rev\ xs}
   215 because the corresponding precondition \isa{rev\ xs\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}}
   216 simplifies to \isa{xs\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}}, which is exactly the local
   217 assumption of the subgoal.%
   218 \end{isamarkuptext}%
   219 %
   220 \isamarkupsubsubsection{Automatic case splits}
   221 %
   222 \begin{isamarkuptext}%
   223 \indexbold{case splits}\index{*split|(}
   224 Goals containing \isa{if}-expressions are usually proved by case
   225 distinction on the condition of the \isa{if}. For example the goal%
   226 \end{isamarkuptext}%
   227 \isacommand{lemma}\ {\isachardoublequote}{\isasymforall}xs{\isachardot}\ if\ xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ then\ rev\ xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ else\ rev\ xs\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequote}%
   228 \begin{isamarkuptxt}%
   229 \noindent
   230 can be split into
   231 \begin{isabelle}
   232 ~1.~{\isasymforall}xs.~(xs~=~[]~{\isasymlongrightarrow}~rev~xs~=~[])~{\isasymand}~(xs~{\isasymnoteq}~[]~{\isasymlongrightarrow}~rev~xs~{\isasymnoteq}~[])
   233 \end{isabelle}
   234 by a degenerate form of simplification%
   235 \end{isamarkuptxt}%
   236 \isacommand{apply}{\isacharparenleft}simp\ only{\isacharcolon}\ split{\isacharcolon}\ split{\isacharunderscore}if{\isacharparenright}%
   237 \begin{isamarkuptext}%
   238 \noindent
   239 where no simplification rules are included (\isa{only{\isacharcolon}} is followed by the
   240 empty list of theorems) but the rule \isaindexbold{split_if} for
   241 splitting \isa{if}s is added (via the modifier \isa{split{\isacharcolon}}). Because
   242 case-splitting on \isa{if}s is almost always the right proof strategy, the
   243 simplifier performs it automatically. Try \isacommand{apply}\isa{{\isacharparenleft}simp{\isacharparenright}}
   244 on the initial goal above.
   245 
   246 This splitting idea generalizes from \isa{if} to \isaindex{case}:%
   247 \end{isamarkuptext}%
   248 \isacommand{lemma}\ {\isachardoublequote}{\isacharparenleft}case\ xs\ of\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymRightarrow}\ zs\ {\isacharbar}\ y{\isacharhash}ys\ {\isasymRightarrow}\ y{\isacharhash}{\isacharparenleft}ys{\isacharat}zs{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ xs{\isacharat}zs{\isachardoublequote}%
   249 \begin{isamarkuptxt}%
   250 \noindent
   251 becomes
   252 \begin{isabelle}\makeatother
   253 ~1.~(xs~=~[]~{\isasymlongrightarrow}~zs~=~xs~@~zs)~{\isasymand}\isanewline
   254 ~~~~({\isasymforall}a~list.~xs~=~a~\#~list~{\isasymlongrightarrow}~a~\#~list~@~zs~=~xs~@~zs)
   255 \end{isabelle}
   256 by typing%
   257 \end{isamarkuptxt}%
   258 \isacommand{apply}{\isacharparenleft}simp\ only{\isacharcolon}\ split{\isacharcolon}\ list{\isachardot}split{\isacharparenright}%
   259 \begin{isamarkuptext}%
   260 \noindent
   261 In contrast to \isa{if}-expressions, the simplifier does not split
   262 \isa{case}-expressions by default because this can lead to nontermination
   263 in case of recursive datatypes. Again, if the \isa{only{\isacharcolon}} modifier is
   264 dropped, the above goal is solved,%
   265 \end{isamarkuptext}%
   266 \isacommand{apply}{\isacharparenleft}simp\ split{\isacharcolon}\ list{\isachardot}split{\isacharparenright}%
   267 \begin{isamarkuptext}%
   268 \noindent%
   269 which \isacommand{apply}\isa{{\isacharparenleft}simp{\isacharparenright}} alone will not do.
   270 
   271 In general, every datatype $t$ comes with a theorem
   272 $t$\isa{{\isachardot}split} which can be declared to be a \bfindex{split rule} either
   273 locally as above, or by giving it the \isa{split} attribute globally:%
   274 \end{isamarkuptext}%
   275 \isacommand{declare}\ list{\isachardot}split\ {\isacharbrackleft}split{\isacharbrackright}%
   276 \begin{isamarkuptext}%
   277 \noindent
   278 The \isa{split} attribute can be removed with the \isa{del} modifier,
   279 either locally%
   280 \end{isamarkuptext}%
   281 \isacommand{apply}{\isacharparenleft}simp\ split\ del{\isacharcolon}\ split{\isacharunderscore}if{\isacharparenright}%
   282 \begin{isamarkuptext}%
   283 \noindent
   284 or globally:%
   285 \end{isamarkuptext}%
   286 \isacommand{declare}\ list{\isachardot}split\ {\isacharbrackleft}split\ del{\isacharbrackright}%
   287 \begin{isamarkuptext}%
   288 The above split rules intentionally only affect the conclusion of a
   289 subgoal.  If you want to split an \isa{if} or \isa{case}-expression in
   290 the assumptions, you have to apply \isa{split{\isacharunderscore}if{\isacharunderscore}asm} or
   291 $t$\isa{{\isachardot}split{\isacharunderscore}asm}:%
   292 \end{isamarkuptext}%
   293 \isacommand{lemma}\ {\isachardoublequote}if\ xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ then\ ys\ {\isachartilde}{\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ else\ ys\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}{\isacharequal}{\isachargreater}\ xs\ {\isacharat}\ ys\ {\isachartilde}{\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequote}\isanewline
   294 \isacommand{apply}{\isacharparenleft}simp\ only{\isacharcolon}\ split{\isacharcolon}\ split{\isacharunderscore}if{\isacharunderscore}asm{\isacharparenright}%
   295 \begin{isamarkuptext}%
   296 \noindent
   297 In contrast to splitting the conclusion, this actually creates two
   298 separate subgoals (which are solved by \isa{simp{\isacharunderscore}all}):
   299 \begin{isabelle}
   300 \ \isadigit{1}{\isachardot}\ {\isasymlbrakk}\mbox{xs}\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isacharsemicolon}\ \mbox{ys}\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharat}\ \mbox{ys}\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}\isanewline
   301 \ \isadigit{2}{\isachardot}\ {\isasymlbrakk}\mbox{xs}\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}{\isacharsemicolon}\ \mbox{ys}\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isasymrbrakk}\ {\isasymLongrightarrow}\ \mbox{xs}\ {\isacharat}\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}
   302 \end{isabelle}
   303 If you need to split both in the assumptions and the conclusion,
   304 use $t$\isa{{\isachardot}splits} which subsumes $t$\isa{{\isachardot}split} and
   305 $t$\isa{{\isachardot}split{\isacharunderscore}asm}. Analogously, there is \isa{if{\isacharunderscore}splits}.
   306 
   307 \begin{warn}
   308   The simplifier merely simplifies the condition of an \isa{if} but not the
   309   \isa{then} or \isa{else} parts. The latter are simplified only after the
   310   condition reduces to \isa{True} or \isa{False}, or after splitting. The
   311   same is true for \isaindex{case}-expressions: only the selector is
   312   simplified at first, until either the expression reduces to one of the
   313   cases or it is split.
   314 \end{warn}
   315 
   316 \index{*split|)}%
   317 \end{isamarkuptext}%
   318 %
   319 \isamarkupsubsubsection{Arithmetic}
   320 %
   321 \begin{isamarkuptext}%
   322 \index{arithmetic}
   323 The simplifier routinely solves a small class of linear arithmetic formulae
   324 (over type \isa{nat} and other numeric types): it only takes into account
   325 assumptions and conclusions that are (possibly negated) (in)equalities
   326 (\isa{{\isacharequal}}, \isasymle, \isa{{\isacharless}}) and it only knows about addition. Thus%
   327 \end{isamarkuptext}%
   328 \isacommand{lemma}\ {\isachardoublequote}{\isasymlbrakk}\ {\isasymnot}\ m\ {\isacharless}\ n{\isacharsemicolon}\ m\ {\isacharless}\ n{\isacharplus}\isadigit{1}\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ m\ {\isacharequal}\ n{\isachardoublequote}%
   329 \begin{isamarkuptext}%
   330 \noindent
   331 is proved by simplification, whereas the only slightly more complex%
   332 \end{isamarkuptext}%
   333 \isacommand{lemma}\ {\isachardoublequote}{\isasymnot}\ m\ {\isacharless}\ n\ {\isasymand}\ m\ {\isacharless}\ n{\isacharplus}\isadigit{1}\ {\isasymLongrightarrow}\ m\ {\isacharequal}\ n{\isachardoublequote}%
   334 \begin{isamarkuptext}%
   335 \noindent
   336 is not proved by simplification and requires \isa{arith}.%
   337 \end{isamarkuptext}%
   338 %
   339 \isamarkupsubsubsection{Tracing}
   340 %
   341 \begin{isamarkuptext}%
   342 \indexbold{tracing the simplifier}
   343 Using the simplifier effectively may take a bit of experimentation.  Set the
   344 \isaindexbold{trace_simp} \rmindex{flag} to get a better idea of what is going
   345 on:%
   346 \end{isamarkuptext}%
   347 \isacommand{ML}\ {\isachardoublequote}set\ trace{\isacharunderscore}simp{\isachardoublequote}\isanewline
   348 \isacommand{lemma}\ {\isachardoublequote}rev\ {\isacharbrackleft}a{\isacharbrackright}\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequote}\isanewline
   349 \isacommand{apply}{\isacharparenleft}simp{\isacharparenright}%
   350 \begin{isamarkuptext}%
   351 \noindent
   352 produces the trace
   353 
   354 \begin{ttbox}\makeatother
   355 Applying instance of rewrite rule:
   356 rev (?x1 \# ?xs1) == rev ?xs1 @ [?x1]
   357 Rewriting:
   358 rev [x] == rev [] @ [x]
   359 Applying instance of rewrite rule:
   360 rev [] == []
   361 Rewriting:
   362 rev [] == []
   363 Applying instance of rewrite rule:
   364 [] @ ?y == ?y
   365 Rewriting:
   366 [] @ [x] == [x]
   367 Applying instance of rewrite rule:
   368 ?x3 \# ?t3 = ?t3 == False
   369 Rewriting:
   370 [x] = [] == False
   371 \end{ttbox}
   372 
   373 In more complicated cases, the trace can be quite lenghty, especially since
   374 invocations of the simplifier are often nested (e.g.\ when solving conditions
   375 of rewrite rules). Thus it is advisable to reset it:%
   376 \end{isamarkuptext}%
   377 \isacommand{ML}\ {\isachardoublequote}reset\ trace{\isacharunderscore}simp{\isachardoublequote}\isanewline
   378 \end{isabellebody}%
   379 %%% Local Variables:
   380 %%% mode: latex
   381 %%% TeX-master: "root"
   382 %%% End: