doc-src/TutorialI/Recdef/document/Induction.tex
author wenzelm
Sun, 21 Oct 2001 19:49:29 +0200
changeset 11866 fbd097aec213
parent 11458 09a6c44a48ea
child 13758 ee898d32de21
permissions -rw-r--r--
updated;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9722
a5f86aed785b *** empty log message ***
nipkow
parents: 9721
diff changeset
     1
%
a5f86aed785b *** empty log message ***
nipkow
parents: 9721
diff changeset
     2
\begin{isabellebody}%
9924
3370f6aa3200 updated;
wenzelm
parents: 9792
diff changeset
     3
\def\isabellecontext{Induction}%
11866
fbd097aec213 updated;
wenzelm
parents: 11458
diff changeset
     4
\isamarkupfalse%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
     5
%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
     6
\begin{isamarkuptext}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
     7
Assuming we have defined our function such that Isabelle could prove
2665170f104a Adding generated files
nipkow
parents:
diff changeset
     8
termination and that the recursion equations (or some suitable derived
2665170f104a Adding generated files
nipkow
parents:
diff changeset
     9
equations) are simplification rules, we might like to prove something about
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    10
our function. Since the function is recursive, the natural proof principle is
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    11
again induction. But this time the structural form of induction that comes
10971
6852682eaf16 *** empty log message ***
nipkow
parents: 10950
diff changeset
    12
with datatypes is unlikely to work well --- otherwise we could have defined the
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    13
function by \isacommand{primrec}. Therefore \isacommand{recdef} automatically
9792
bbefb6ce5cb2 *** empty log message ***
nipkow
parents: 9723
diff changeset
    14
proves a suitable induction rule $f$\isa{{\isachardot}induct} that follows the
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    15
recursion pattern of the particular function $f$. We call this
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    16
\textbf{recursion induction}. Roughly speaking, it
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    17
requires you to prove for each \isacommand{recdef} equation that the property
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    18
you are trying to establish holds for the left-hand side provided it holds
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10362
diff changeset
    19
for all recursive calls on the right-hand side. Here is a simple example
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10362
diff changeset
    20
involving the predefined \isa{map} functional on lists:%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    21
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11458
diff changeset
    22
\isamarkuptrue%
fbd097aec213 updated;
wenzelm
parents: 11458
diff changeset
    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%
fbd097aec213 updated;
wenzelm
parents: 11458
diff changeset
    24
%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    25
\begin{isamarkuptxt}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    26
\noindent
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10362
diff changeset
    27
Note that \isa{map\ f\ xs}
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    28
is the result of applying \isa{f} to all elements of \isa{xs}. We prove
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10362
diff changeset
    29
this lemma by recursion induction over \isa{sep}:%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    30
\end{isamarkuptxt}%
11866
fbd097aec213 updated;
wenzelm
parents: 11458
diff changeset
    31
\isamarkuptrue%
fbd097aec213 updated;
wenzelm
parents: 11458
diff changeset
    32
\isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ x\ xs\ rule{\isacharcolon}\ sep{\isachardot}induct{\isacharparenright}\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11458
diff changeset
    33
%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    34
\begin{isamarkuptxt}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    35
\noindent
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    36
The resulting proof state has three subgoals corresponding to the three
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    37
clauses for \isa{sep}:
10362
c6b197ccf1f1 *** empty log message ***
nipkow
parents: 10171
diff changeset
    38
\begin{isabelle}%
c6b197ccf1f1 *** empty log message ***
nipkow
parents: 10171
diff changeset
    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
c6b197ccf1f1 *** empty log message ***
nipkow
parents: 10171
diff changeset
    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
c6b197ccf1f1 *** empty log message ***
nipkow
parents: 10171
diff changeset
    41
\ {\isadigit{3}}{\isachardot}\ {\isasymAnd}a\ x\ y\ zs{\isachardot}\isanewline
10950
aa788fcb75a5 updated;
wenzelm
parents: 10795
diff changeset
    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
aa788fcb75a5 updated;
wenzelm
parents: 10795
diff changeset
    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
a977245dfc8a *** empty log message ***
nipkow
parents: 9722
diff changeset
    44
\end{isabelle}
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    45
The rest is pure simplification:%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    46
\end{isamarkuptxt}%
11866
fbd097aec213 updated;
wenzelm
parents: 11458
diff changeset
    47
\isamarkuptrue%
10171
59d6633835fa *** empty log message ***
nipkow
parents: 9924
diff changeset
    48
\isacommand{apply}\ simp{\isacharunderscore}all\isanewline
11866
fbd097aec213 updated;
wenzelm
parents: 11458
diff changeset
    49
\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11458
diff changeset
    50
\isacommand{done}\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11458
diff changeset
    51
%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    52
\begin{isamarkuptext}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    53
Try proving the above lemma by structural induction, and you find that you
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    54
need an additional case distinction. What is worse, the names of variables
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    55
are invented by Isabelle and have nothing to do with the names in the
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    56
definition of \isa{sep}.
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    57
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    58
In general, the format of invoking recursion induction is
9792
bbefb6ce5cb2 *** empty log message ***
nipkow
parents: 9723
diff changeset
    59
\begin{quote}
11159
07b13770c4d6 *** empty log message ***
nipkow
parents: 11023
diff changeset
    60
\isacommand{apply}\isa{{\isacharparenleft}induct{\isacharunderscore}tac} $x@1 \dots x@n$ \isa{rule{\isacharcolon}} $f$\isa{{\isachardot}induct{\isacharparenright}}
11428
332347b9b942 tidying the index
paulson
parents: 11159
diff changeset
    61
\end{quote}\index{*induct_tac (method)}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    62
where $x@1~\dots~x@n$ is a list of free variables in the subgoal and $f$ the
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    63
name of a function that takes an $n$-tuple. Usually the subgoal will
10971
6852682eaf16 *** empty log message ***
nipkow
parents: 10950
diff changeset
    64
contain the term $f(x@1,\dots,x@n)$ but this need not be the case. The
11458
09a6c44a48ea numerous stylistic changes and indexing
paulson
parents: 11428
diff changeset
    65
induction rules do not mention $f$ at all. Here is \isa{sep{\isachardot}induct}:
9723
a977245dfc8a *** empty log message ***
nipkow
parents: 9722
diff changeset
    66
\begin{isabelle}
9689
751fde5307e4 *** empty log message ***
nipkow
parents: 9674
diff changeset
    67
{\isasymlbrakk}~{\isasymAnd}a.~P~a~[];\isanewline
751fde5307e4 *** empty log message ***
nipkow
parents: 9674
diff changeset
    68
~~{\isasymAnd}a~x.~P~a~[x];\isanewline
751fde5307e4 *** empty log message ***
nipkow
parents: 9674
diff changeset
    69
~~{\isasymAnd}a~x~y~zs.~P~a~(y~\#~zs)~{\isasymLongrightarrow}~P~a~(x~\#~y~\#~zs){\isasymrbrakk}\isanewline
751fde5307e4 *** empty log message ***
nipkow
parents: 9674
diff changeset
    70
{\isasymLongrightarrow}~P~u~v%
9723
a977245dfc8a *** empty log message ***
nipkow
parents: 9722
diff changeset
    71
\end{isabelle}
11458
09a6c44a48ea numerous stylistic changes and indexing
paulson
parents: 11428
diff changeset
    72
It merely says that in order to prove a property \isa{P} of \isa{u} and
9689
751fde5307e4 *** empty log message ***
nipkow
parents: 9674
diff changeset
    73
\isa{v} you need to prove it for the three cases where \isa{v} is the
11458
09a6c44a48ea numerous stylistic changes and indexing
paulson
parents: 11428
diff changeset
    74
empty list, the singleton list, and the list with at least two elements.
09a6c44a48ea numerous stylistic changes and indexing
paulson
parents: 11428
diff changeset
    75
The final case has an induction hypothesis:  you may assume that \isa{P}
09a6c44a48ea numerous stylistic changes and indexing
paulson
parents: 11428
diff changeset
    76
holds for the tail of that list.%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    77
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11458
diff changeset
    78
\isamarkuptrue%
fbd097aec213 updated;
wenzelm
parents: 11458
diff changeset
    79
\isamarkupfalse%
9722
a5f86aed785b *** empty log message ***
nipkow
parents: 9721
diff changeset
    80
\end{isabellebody}%
9145
9f7b8de5bfaf updated;
wenzelm
parents: 8771
diff changeset
    81
%%% Local Variables:
9f7b8de5bfaf updated;
wenzelm
parents: 8771
diff changeset
    82
%%% mode: latex
9f7b8de5bfaf updated;
wenzelm
parents: 8771
diff changeset
    83
%%% TeX-master: "root"
9f7b8de5bfaf updated;
wenzelm
parents: 8771
diff changeset
    84
%%% End: