doc-src/TutorialI/Recdef/document/Induction.tex
author nipkow
Tue, 29 Aug 2000 15:43:29 +0200
changeset 9722 a5f86aed785b
parent 9721 7e51c9f3d5a0
child 9723 a977245dfc8a
permissions -rw-r--r--
*** empty log message ***
nipkow@9722
     1
%
nipkow@9722
     2
\begin{isabellebody}%
nipkow@8749
     3
%
nipkow@8749
     4
\begin{isamarkuptext}%
nipkow@8749
     5
Assuming we have defined our function such that Isabelle could prove
nipkow@8749
     6
termination and that the recursion equations (or some suitable derived
nipkow@8749
     7
equations) are simplification rules, we might like to prove something about
nipkow@8749
     8
our function. Since the function is recursive, the natural proof principle is
nipkow@8749
     9
again induction. But this time the structural form of induction that comes
nipkow@8749
    10
with datatypes is unlikely to work well---otherwise we could have defined the
nipkow@8749
    11
function by \isacommand{primrec}. Therefore \isacommand{recdef} automatically
nipkow@8749
    12
proves a suitable induction rule $f$\isa{.induct} that follows the
nipkow@8749
    13
recursion pattern of the particular function $f$. We call this
nipkow@8749
    14
\textbf{recursion induction}. Roughly speaking, it
nipkow@8749
    15
requires you to prove for each \isacommand{recdef} equation that the property
nipkow@8749
    16
you are trying to establish holds for the left-hand side provided it holds
nipkow@8771
    17
for all recursive calls on the right-hand side. Here is a simple example%
nipkow@8749
    18
\end{isamarkuptext}%
wenzelm@9674
    19
\isacommand{lemma}\ {\isachardoublequote}map\ f\ {\isacharparenleft}sep{\isacharparenleft}x{\isacharcomma}xs{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ sep{\isacharparenleft}f\ x{\isacharcomma}\ map\ f\ xs{\isacharparenright}{\isachardoublequote}%
nipkow@8749
    20
\begin{isamarkuptxt}%
nipkow@8749
    21
\noindent
nipkow@8749
    22
involving the predefined \isa{map} functional on lists: \isa{map f xs}
nipkow@8749
    23
is the result of applying \isa{f} to all elements of \isa{xs}. We prove
nipkow@8749
    24
this lemma by recursion induction w.r.t. \isa{sep}:%
nipkow@8749
    25
\end{isamarkuptxt}%
wenzelm@9674
    26
\isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ x\ xs\ rule{\isacharcolon}\ sep{\isachardot}induct{\isacharparenright}%
nipkow@8749
    27
\begin{isamarkuptxt}%
nipkow@8749
    28
\noindent
nipkow@8749
    29
The resulting proof state has three subgoals corresponding to the three
nipkow@8749
    30
clauses for \isa{sep}:
nipkow@8749
    31
\begin{isabellepar}%
nipkow@8749
    32
~1.~{\isasymAnd}a.~map~f~(sep~(a,~[]))~=~sep~(f~a,~map~f~[])\isanewline
nipkow@8749
    33
~2.~{\isasymAnd}a~x.~map~f~(sep~(a,~[x]))~=~sep~(f~a,~map~f~[x])\isanewline
nipkow@8749
    34
~3.~{\isasymAnd}a~x~y~zs.\isanewline
nipkow@8749
    35
~~~~~~~map~f~(sep~(a,~y~\#~zs))~=~sep~(f~a,~map~f~(y~\#~zs))~{\isasymLongrightarrow}\isanewline
nipkow@8749
    36
~~~~~~~map~f~(sep~(a,~x~\#~y~\#~zs))~=~sep~(f~a,~map~f~(x~\#~y~\#~zs))%
nipkow@8749
    37
\end{isabellepar}%
nipkow@8749
    38
The rest is pure simplification:%
nipkow@8749
    39
\end{isamarkuptxt}%
wenzelm@9698
    40
\isacommand{by}\ simp{\isacharunderscore}all%
nipkow@8749
    41
\begin{isamarkuptext}%
nipkow@8749
    42
Try proving the above lemma by structural induction, and you find that you
nipkow@8749
    43
need an additional case distinction. What is worse, the names of variables
nipkow@8749
    44
are invented by Isabelle and have nothing to do with the names in the
nipkow@8749
    45
definition of \isa{sep}.
nipkow@8749
    46
nipkow@8749
    47
In general, the format of invoking recursion induction is
nipkow@8749
    48
\begin{ttbox}
nipkow@8749
    49
apply(induct_tac \(x@1 \dots x@n\) rule: \(f\).induct)
nipkow@8749
    50
\end{ttbox}\index{*induct_tac}%
nipkow@8749
    51
where $x@1~\dots~x@n$ is a list of free variables in the subgoal and $f$ the
nipkow@8749
    52
name of a function that takes an $n$-tuple. Usually the subgoal will
nipkow@8749
    53
contain the term $f~x@1~\dots~x@n$ but this need not be the case. The
nipkow@8749
    54
induction rules do not mention $f$ at all. For example \isa{sep.induct}
nipkow@8749
    55
\begin{isabellepar}%
nipkow@9689
    56
{\isasymlbrakk}~{\isasymAnd}a.~P~a~[];\isanewline
nipkow@9689
    57
~~{\isasymAnd}a~x.~P~a~[x];\isanewline
nipkow@9689
    58
~~{\isasymAnd}a~x~y~zs.~P~a~(y~\#~zs)~{\isasymLongrightarrow}~P~a~(x~\#~y~\#~zs){\isasymrbrakk}\isanewline
nipkow@9689
    59
{\isasymLongrightarrow}~P~u~v%
nipkow@8749
    60
\end{isabellepar}%
nipkow@9689
    61
merely says that in order to prove a property \isa{P} of \isa{u} and
nipkow@9689
    62
\isa{v} you need to prove it for the three cases where \isa{v} is the
nipkow@8749
    63
empty list, the singleton list, and the list with at least two elements
nipkow@8749
    64
(in which case you may assume it holds for the tail of that list).%
nipkow@8749
    65
\end{isamarkuptext}%
nipkow@9722
    66
\end{isabellebody}%
wenzelm@9145
    67
%%% Local Variables:
wenzelm@9145
    68
%%% mode: latex
wenzelm@9145
    69
%%% TeX-master: "root"
wenzelm@9145
    70
%%% End: