diff -r 619531d87ce4 -r 4e2ee88276d2 doc-src/TutorialI/document/AdvancedInd.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc-src/TutorialI/document/AdvancedInd.tex Thu Jul 26 19:59:06 2012 +0200 @@ -0,0 +1,436 @@ +% +\begin{isabellebody}% +\def\isabellecontext{AdvancedInd}% +% +\isadelimtheory +% +\endisadelimtheory +% +\isatagtheory +% +\endisatagtheory +{\isafoldtheory}% +% +\isadelimtheory +% +\endisadelimtheory +% +\begin{isamarkuptext}% +\noindent +Now that we have learned about rules and logic, we take another look at the +finer points of induction. We consider two questions: what to do if the +proposition to be proved is not directly amenable to induction +(\S\ref{sec:ind-var-in-prems}), and how to utilize (\S\ref{sec:complete-ind}) +and even derive (\S\ref{sec:derive-ind}) new induction schemas. We conclude +with an extended example of induction (\S\ref{sec:CTL-revisited}).% +\end{isamarkuptext}% +\isamarkuptrue% +% +\isamarkupsubsection{Massaging the Proposition% +} +\isamarkuptrue% +% +\begin{isamarkuptext}% +\label{sec:ind-var-in-prems} +Often we have assumed that the theorem to be proved is already in a form +that is amenable to induction, but sometimes it isn't. +Here is an example. +Since \isa{hd} and \isa{last} return the first and last element of a +non-empty list, this lemma looks easy to prove:% +\end{isamarkuptext}% +\isamarkuptrue% +\isacommand{lemma}\isamarkupfalse% +\ {\isaliteral{22}{\isachardoublequoteopen}}xs\ {\isaliteral{5C3C6E6F7465713E}{\isasymnoteq}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ hd{\isaliteral{28}{\isacharparenleft}}rev\ xs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ last\ xs{\isaliteral{22}{\isachardoublequoteclose}}\isanewline +% +\isadelimproof +% +\endisadelimproof +% +\isatagproof +\isacommand{apply}\isamarkupfalse% +{\isaliteral{28}{\isacharparenleft}}induct{\isaliteral{5F}{\isacharunderscore}}tac\ xs{\isaliteral{29}{\isacharparenright}}% +\begin{isamarkuptxt}% +\noindent +But induction produces the warning +\begin{quote}\tt +Induction variable occurs also among premises! +\end{quote} +and leads to the base case +\begin{isabelle}% +\ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ xs\ {\isaliteral{5C3C6E6F7465713E}{\isasymnoteq}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}\ hd\ {\isaliteral{28}{\isacharparenleft}}rev\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ last\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}% +\end{isabelle} +Simplification reduces the base case to this: +\begin{isabelle} +\ 1.\ xs\ {\isasymnoteq}\ []\ {\isasymLongrightarrow}\ hd\ []\ =\ last\ [] +\end{isabelle} +We cannot prove this equality because we do not know what \isa{hd} and +\isa{last} return when applied to \isa{{\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}}. + +We should not have ignored the warning. Because the induction +formula is only the conclusion, induction does not affect the occurrence of \isa{xs} in the premises. +Thus the case that should have been trivial +becomes unprovable. Fortunately, the solution is easy:\footnote{A similar +heuristic applies to rule inductions; see \S\ref{sec:rtc}.} +\begin{quote} +\emph{Pull all occurrences of the induction variable into the conclusion +using \isa{{\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}}.} +\end{quote} +Thus we should state the lemma as an ordinary +implication~(\isa{{\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}}), letting +\attrdx{rule_format} (\S\ref{sec:forward}) convert the +result to the usual \isa{{\isaliteral{5C3C4C6F6E6772696768746172726F773E}{\isasymLongrightarrow}}} form:% +\end{isamarkuptxt}% +\isamarkuptrue% +% +\endisatagproof +{\isafoldproof}% +% +\isadelimproof +% +\endisadelimproof +\isacommand{lemma}\isamarkupfalse% +\ hd{\isaliteral{5F}{\isacharunderscore}}rev\ {\isaliteral{5B}{\isacharbrackleft}}rule{\isaliteral{5F}{\isacharunderscore}}format{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}xs\ {\isaliteral{5C3C6E6F7465713E}{\isasymnoteq}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ hd{\isaliteral{28}{\isacharparenleft}}rev\ xs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ last\ xs{\isaliteral{22}{\isachardoublequoteclose}}% +\isadelimproof +% +\endisadelimproof +% +\isatagproof +% +\begin{isamarkuptxt}% +\noindent +This time, induction leaves us with a trivial base case: +\begin{isabelle}% +\ {\isadigit{1}}{\isaliteral{2E}{\isachardot}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{5C3C6E6F7465713E}{\isasymnoteq}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}\ hd\ {\isaliteral{28}{\isacharparenleft}}rev\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ last\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}% +\end{isabelle} +And \isa{auto} completes the proof. + +If there are multiple premises $A@1$, \dots, $A@n$ containing the +induction variable, you should turn the conclusion $C$ into +\[ A@1 \longrightarrow \cdots A@n \longrightarrow C. \] +Additionally, you may also have to universally quantify some other variables, +which can yield a fairly complex conclusion. However, \isa{rule{\isaliteral{5F}{\isacharunderscore}}format} +can remove any number of occurrences of \isa{{\isaliteral{5C3C666F72616C6C3E}{\isasymforall}}} and +\isa{{\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}}. + +\index{induction!on a term}% +A second reason why your proposition may not be amenable to induction is that +you want to induct on a complex term, rather than a variable. In +general, induction on a term~$t$ requires rephrasing the conclusion~$C$ +as +\begin{equation}\label{eqn:ind-over-term} +\forall y@1 \dots y@n.~ x = t \longrightarrow C. +\end{equation} +where $y@1 \dots y@n$ are the free variables in $t$ and $x$ is a new variable. +Now you can perform induction on~$x$. An example appears in +\S\ref{sec:complete-ind} below. + +The very same problem may occur in connection with rule induction. Remember +that it requires a premise of the form $(x@1,\dots,x@k) \in R$, where $R$ is +some inductively defined set and the $x@i$ are variables. If instead we have +a premise $t \in R$, where $t$ is not just an $n$-tuple of variables, we +replace it with $(x@1,\dots,x@k) \in R$, and rephrase the conclusion $C$ as +\[ \forall y@1 \dots y@n.~ (x@1,\dots,x@k) = t \longrightarrow C. \] +For an example see \S\ref{sec:CTL-revisited} below. + +Of course, all premises that share free variables with $t$ need to be pulled into +the conclusion as well, under the \isa{{\isaliteral{5C3C666F72616C6C3E}{\isasymforall}}}, again using \isa{{\isaliteral{5C3C6C6F6E6772696768746172726F773E}{\isasymlongrightarrow}}} as shown above. + +Readers who are puzzled by the form of statement +(\ref{eqn:ind-over-term}) above should remember that the +transformation is only performed to permit induction. Once induction +has been applied, the statement can be transformed back into something quite +intuitive. For example, applying wellfounded induction on $x$ (w.r.t.\ +$\prec$) to (\ref{eqn:ind-over-term}) and transforming the result a +little leads to the goal +\[ \bigwedge\overline{y}.\ + \forall \overline{z}.\ t\,\overline{z} \prec t\,\overline{y}\ \longrightarrow\ C\,\overline{z} + \ \Longrightarrow\ C\,\overline{y} \] +where $\overline{y}$ stands for $y@1 \dots y@n$ and the dependence of $t$ and +$C$ on the free variables of $t$ has been made explicit. +Unfortunately, this induction schema cannot be expressed as a +single theorem because it depends on the number of free variables in $t$ --- +the notation $\overline{y}$ is merely an informal device.% +\end{isamarkuptxt}% +\isamarkuptrue% +% +\endisatagproof +{\isafoldproof}% +% +\isadelimproof +% +\endisadelimproof +% +\isamarkupsubsection{Beyond Structural and Recursion Induction% +} +\isamarkuptrue% +% +\begin{isamarkuptext}% +\label{sec:complete-ind} +So far, inductive proofs were by structural induction for +primitive recursive functions and recursion induction for total recursive +functions. But sometimes structural induction is awkward and there is no +recursive function that could furnish a more appropriate +induction schema. In such cases a general-purpose induction schema can +be helpful. We show how to apply such induction schemas by an example. + +Structural induction on \isa{nat} is +usually known as mathematical induction. There is also \textbf{complete} +\index{induction!complete}% +induction, where you prove $P(n)$ under the assumption that $P(m)$ +holds for all $m