| 9722 |      1 | %
 | 
|  |      2 | \begin{isabellebody}%
 | 
| 9924 |      3 | \def\isabellecontext{Induction}%
 | 
| 11866 |      4 | \isamarkupfalse%
 | 
| 8749 |      5 | %
 | 
|  |      6 | \begin{isamarkuptext}%
 | 
|  |      7 | Assuming we have defined our function such that Isabelle could prove
 | 
|  |      8 | termination and that the recursion equations (or some suitable derived
 | 
|  |      9 | equations) are simplification rules, we might like to prove something about
 | 
|  |     10 | our function. Since the function is recursive, the natural proof principle is
 | 
|  |     11 | again induction. But this time the structural form of induction that comes
 | 
| 10971 |     12 | with datatypes is unlikely to work well --- otherwise we could have defined the
 | 
| 8749 |     13 | function by \isacommand{primrec}. Therefore \isacommand{recdef} automatically
 | 
| 9792 |     14 | proves a suitable induction rule $f$\isa{{\isachardot}induct} that follows the
 | 
| 8749 |     15 | recursion pattern of the particular function $f$. We call this
 | 
|  |     16 | \textbf{recursion induction}. Roughly speaking, it
 | 
|  |     17 | requires you to prove for each \isacommand{recdef} equation that the property
 | 
|  |     18 | you are trying to establish holds for the left-hand side provided it holds
 | 
| 10795 |     19 | for all recursive calls on the right-hand side. Here is a simple example
 | 
|  |     20 | involving the predefined \isa{map} functional on lists:%
 | 
| 8749 |     21 | \end{isamarkuptext}%
 | 
| 11866 |     22 | \isamarkuptrue%
 | 
|  |     23 | \isacommand{lemma}\ {\isachardoublequote}map\ f\ {\isacharparenleft}sep{\isacharparenleft}x{\isacharcomma}xs{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ sep{\isacharparenleft}f\ x{\isacharcomma}\ map\ f\ xs{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
 | 
|  |     24 | %
 | 
| 8749 |     25 | \begin{isamarkuptxt}%
 | 
|  |     26 | \noindent
 | 
| 10795 |     27 | Note that \isa{map\ f\ xs}
 | 
| 8749 |     28 | is the result of applying \isa{f} to all elements of \isa{xs}. We prove
 | 
| 10795 |     29 | this lemma by recursion induction over \isa{sep}:%
 | 
| 8749 |     30 | \end{isamarkuptxt}%
 | 
| 11866 |     31 | \isamarkuptrue%
 | 
|  |     32 | \isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ x\ xs\ rule{\isacharcolon}\ sep{\isachardot}induct{\isacharparenright}\isamarkupfalse%
 | 
|  |     33 | %
 | 
| 8749 |     34 | \begin{isamarkuptxt}%
 | 
|  |     35 | \noindent
 | 
|  |     36 | The resulting proof state has three subgoals corresponding to the three
 | 
|  |     37 | clauses for \isa{sep}:
 | 
| 10362 |     38 | \begin{isabelle}%
 | 
|  |     39 | \ {\isadigit{1}}{\isachardot}\ {\isasymAnd}a{\isachardot}\ map\ f\ {\isacharparenleft}sep\ {\isacharparenleft}a{\isacharcomma}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ sep\ {\isacharparenleft}f\ a{\isacharcomma}\ map\ f\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\isanewline
 | 
|  |     40 | \ {\isadigit{2}}{\isachardot}\ {\isasymAnd}a\ x{\isachardot}\ map\ f\ {\isacharparenleft}sep\ {\isacharparenleft}a{\isacharcomma}\ {\isacharbrackleft}x{\isacharbrackright}{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ sep\ {\isacharparenleft}f\ a{\isacharcomma}\ map\ f\ {\isacharbrackleft}x{\isacharbrackright}{\isacharparenright}\isanewline
 | 
|  |     41 | \ {\isadigit{3}}{\isachardot}\ {\isasymAnd}a\ x\ y\ zs{\isachardot}\isanewline
 | 
| 10950 |     42 | \isaindent{\ {\isadigit{3}}{\isachardot}\ \ \ \ }map\ f\ {\isacharparenleft}sep\ {\isacharparenleft}a{\isacharcomma}\ y\ {\isacharhash}\ zs{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ sep\ {\isacharparenleft}f\ a{\isacharcomma}\ map\ f\ {\isacharparenleft}y\ {\isacharhash}\ zs{\isacharparenright}{\isacharparenright}\ {\isasymLongrightarrow}\isanewline
 | 
|  |     43 | \isaindent{\ {\isadigit{3}}{\isachardot}\ \ \ \ }map\ f\ {\isacharparenleft}sep\ {\isacharparenleft}a{\isacharcomma}\ x\ {\isacharhash}\ y\ {\isacharhash}\ zs{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ sep\ {\isacharparenleft}f\ a{\isacharcomma}\ map\ f\ {\isacharparenleft}x\ {\isacharhash}\ y\ {\isacharhash}\ zs{\isacharparenright}{\isacharparenright}%
 | 
| 9723 |     44 | \end{isabelle}
 | 
| 8749 |     45 | The rest is pure simplification:%
 | 
|  |     46 | \end{isamarkuptxt}%
 | 
| 11866 |     47 | \isamarkuptrue%
 | 
| 10171 |     48 | \isacommand{apply}\ simp{\isacharunderscore}all\isanewline
 | 
| 11866 |     49 | \isamarkupfalse%
 | 
|  |     50 | \isacommand{done}\isamarkupfalse%
 | 
|  |     51 | %
 | 
| 8749 |     52 | \begin{isamarkuptext}%
 | 
|  |     53 | Try proving the above lemma by structural induction, and you find that you
 | 
|  |     54 | need an additional case distinction. What is worse, the names of variables
 | 
|  |     55 | are invented by Isabelle and have nothing to do with the names in the
 | 
|  |     56 | definition of \isa{sep}.
 | 
|  |     57 | 
 | 
|  |     58 | In general, the format of invoking recursion induction is
 | 
| 9792 |     59 | \begin{quote}
 | 
| 11159 |     60 | \isacommand{apply}\isa{{\isacharparenleft}induct{\isacharunderscore}tac} $x@1 \dots x@n$ \isa{rule{\isacharcolon}} $f$\isa{{\isachardot}induct{\isacharparenright}}
 | 
| 11428 |     61 | \end{quote}\index{*induct_tac (method)}%
 | 
| 8749 |     62 | where $x@1~\dots~x@n$ is a list of free variables in the subgoal and $f$ the
 | 
|  |     63 | name of a function that takes an $n$-tuple. Usually the subgoal will
 | 
| 10971 |     64 | contain the term $f(x@1,\dots,x@n)$ but this need not be the case. The
 | 
| 11458 |     65 | induction rules do not mention $f$ at all. Here is \isa{sep{\isachardot}induct}:
 | 
| 9723 |     66 | \begin{isabelle}
 | 
| 9689 |     67 | {\isasymlbrakk}~{\isasymAnd}a.~P~a~[];\isanewline
 | 
|  |     68 | ~~{\isasymAnd}a~x.~P~a~[x];\isanewline
 | 
|  |     69 | ~~{\isasymAnd}a~x~y~zs.~P~a~(y~\#~zs)~{\isasymLongrightarrow}~P~a~(x~\#~y~\#~zs){\isasymrbrakk}\isanewline
 | 
|  |     70 | {\isasymLongrightarrow}~P~u~v%
 | 
| 9723 |     71 | \end{isabelle}
 | 
| 11458 |     72 | It merely says that in order to prove a property \isa{P} of \isa{u} and
 | 
| 9689 |     73 | \isa{v} you need to prove it for the three cases where \isa{v} is the
 | 
| 11458 |     74 | empty list, the singleton list, and the list with at least two elements.
 | 
|  |     75 | The final case has an induction hypothesis:  you may assume that \isa{P}
 | 
|  |     76 | holds for the tail of that list.%
 | 
| 8749 |     77 | \end{isamarkuptext}%
 | 
| 11866 |     78 | \isamarkuptrue%
 | 
|  |     79 | \isamarkupfalse%
 | 
| 9722 |     80 | \end{isabellebody}%
 | 
| 9145 |     81 | %%% Local Variables:
 | 
|  |     82 | %%% mode: latex
 | 
|  |     83 | %%% TeX-master: "root"
 | 
|  |     84 | %%% End:
 |