doc-src/TutorialI/Inductive/document/Star.tex
changeset 10520 bb9dfcc87951
parent 10396 5ab08609e6c8
child 10589 b2d1b393b750
     1.1 --- a/doc-src/TutorialI/Inductive/document/Star.tex	Fri Nov 24 16:49:27 2000 +0100
     1.2 +++ b/doc-src/TutorialI/Inductive/document/Star.tex	Sun Nov 26 10:48:38 2000 +0100
     1.3 @@ -7,14 +7,12 @@
     1.4  %
     1.5  \begin{isamarkuptext}%
     1.6  \label{sec:rtc}
     1.7 -{\bf Say something about inductive relations as opposed to sets? Or has that
     1.8 -been said already? If not, explain induction!}
     1.9 -
    1.10 -A perfect example of an inductive definition is the reflexive transitive
    1.11 -closure of a relation. This concept was already introduced in
    1.12 -\S\ref{sec:Relations}, where the operator \isa{{\isacharcircum}{\isacharasterisk}} was
    1.13 -defined as a least fixed point because
    1.14 -inductive definitions were not yet available. But now they are:%
    1.15 +Many inductive definitions define proper relations rather than merely set
    1.16 +like \isa{even}. A perfect example is the
    1.17 +reflexive transitive closure of a relation. This concept was already
    1.18 +introduced in \S\ref{sec:Relations}, where the operator \isa{{\isacharcircum}{\isacharasterisk}} was
    1.19 +defined as a least fixed point because inductive definitions were not yet
    1.20 +available. But now they are:%
    1.21  \end{isamarkuptext}%
    1.22  \isacommand{consts}\ rtc\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}a{\isacharparenright}set\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}a{\isacharparenright}set{\isachardoublequote}\ \ \ {\isacharparenleft}{\isachardoublequote}{\isacharunderscore}{\isacharasterisk}{\isachardoublequote}\ {\isacharbrackleft}{\isadigit{1}}{\isadigit{0}}{\isadigit{0}}{\isadigit{0}}{\isacharbrackright}\ {\isadigit{9}}{\isadigit{9}}{\isadigit{9}}{\isacharparenright}\isanewline
    1.23  \isacommand{inductive}\ {\isachardoublequote}r{\isacharasterisk}{\isachardoublequote}\isanewline
    1.24 @@ -24,13 +22,13 @@
    1.25  \begin{isamarkuptext}%
    1.26  \noindent
    1.27  The function \isa{rtc} is annotated with concrete syntax: instead of
    1.28 -\isa{rtc\ r} we can read and write {term"r*"}. The actual definition
    1.29 -consists of two rules. Reflexivity is obvious and is immediately declared an
    1.30 -equivalence rule.  Thus the automatic tools will apply it automatically. The
    1.31 +\isa{rtc\ r} we can read and write \isa{r{\isacharasterisk}}. The actual definition
    1.32 +consists of two rules. Reflexivity is obvious and is immediately given the
    1.33 +\isa{iff} attribute to increase automation. The
    1.34  second rule, \isa{rtc{\isacharunderscore}step}, says that we can always add one more
    1.35  \isa{r}-step to the left. Although we could make \isa{rtc{\isacharunderscore}step} an
    1.36 -introduction rule, this is dangerous: the recursion slows down and may
    1.37 -even kill the automatic tactics.
    1.38 +introduction rule, this is dangerous: the recursion in the second premise
    1.39 +slows down and may even kill the automatic tactics.
    1.40  
    1.41  The above definition of the concept of reflexive transitive closure may
    1.42  be sufficiently intuitive but it is certainly not the only possible one:
    1.43 @@ -50,34 +48,44 @@
    1.44  shows that \isa{blast} is quite able to handle \isa{rtc{\isacharunderscore}step}. But
    1.45  some of the other automatic tactics are more sensitive, and even \isa{blast} can be lead astray in the presence of large numbers of rules.
    1.46  
    1.47 -Let us now turn to transitivity. It should be a consequence of the definition.%
    1.48 +To prove transitivity, we need rule induction, i.e.\ theorem
    1.49 +\isa{rtc{\isachardot}induct}:
    1.50 +\begin{isabelle}%
    1.51 +\ \ \ \ \ {\isasymlbrakk}{\isacharparenleft}{\isacharquery}xb{\isacharcomma}\ {\isacharquery}xa{\isacharparenright}\ {\isasymin}\ {\isacharquery}r{\isacharasterisk}{\isacharsemicolon}\ {\isasymAnd}x{\isachardot}\ {\isacharquery}P\ x\ x{\isacharsemicolon}\isanewline
    1.52 +\ \ \ \ \ \ \ \ {\isasymAnd}x\ y\ z{\isachardot}\ {\isasymlbrakk}{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ {\isacharquery}r{\isacharsemicolon}\ {\isacharparenleft}y{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ {\isacharquery}r{\isacharasterisk}{\isacharsemicolon}\ {\isacharquery}P\ y\ z{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharquery}P\ x\ z{\isasymrbrakk}\isanewline
    1.53 +\ \ \ \ \ {\isasymLongrightarrow}\ {\isacharquery}P\ {\isacharquery}xb\ {\isacharquery}xa%
    1.54 +\end{isabelle}
    1.55 +It says that \isa{{\isacharquery}P} holds for an arbitrary pair \isa{{\isacharparenleft}{\isacharquery}xb{\isacharcomma}{\isacharquery}xa{\isacharparenright}\ {\isasymin}\ {\isacharquery}r{\isacharasterisk}} if \isa{{\isacharquery}P} is preserved by all rules of the inductive definition,
    1.56 +i.e.\ if \isa{{\isacharquery}P} holds for the conclusion provided it holds for the
    1.57 +premises. In general, rule induction for an $n$-ary inductive relation $R$
    1.58 +expects a premise of the form $(x@1,\dots,x@n) \in R$.
    1.59 +
    1.60 +Now we turn to the inductive proof of transitivity:%
    1.61  \end{isamarkuptext}%
    1.62 -\isacommand{lemma}\ rtc{\isacharunderscore}trans{\isacharcolon}\isanewline
    1.63 -\ \ {\isachardoublequote}{\isasymlbrakk}\ {\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isacharsemicolon}\ {\isacharparenleft}y{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}%
    1.64 -\begin{isamarkuptxt}%
    1.65 -\noindent
    1.66 -The proof starts canonically by rule induction:%
    1.67 -\end{isamarkuptxt}%
    1.68 +\isacommand{lemma}\ rtc{\isacharunderscore}trans{\isacharcolon}\ {\isachardoublequote}{\isasymlbrakk}\ {\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isacharsemicolon}\ {\isacharparenleft}y{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\isanewline
    1.69  \isacommand{apply}{\isacharparenleft}erule\ rtc{\isachardot}induct{\isacharparenright}%
    1.70  \begin{isamarkuptxt}%
    1.71  \noindent
    1.72 -However, even the resulting base case is a problem
    1.73 +Unfortunately, even the resulting base case is a problem
    1.74  \begin{isabelle}%
    1.75  \ {\isadigit{1}}{\isachardot}\ {\isasymAnd}x{\isachardot}\ {\isacharparenleft}y{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}%
    1.76  \end{isabelle}
    1.77  and maybe not what you had expected. We have to abandon this proof attempt.
    1.78 -To understand what is going on,
    1.79 -let us look at the induction rule \isa{rtc{\isachardot}induct}:
    1.80 -\[ \frac{(x,y) \in r^* \qquad \bigwedge x.~P~x~x \quad \dots}{P~x~y} \]
    1.81 -When applying this rule, $x$ becomes \isa{x}, $y$ becomes
    1.82 -\isa{y} and $P~x~y$ becomes \isa{{\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}}, thus
    1.83 +To understand what is going on, let us look again at \isa{rtc{\isachardot}induct}.
    1.84 +In the above application of \isa{erule}, the first premise of
    1.85 +\isa{rtc{\isachardot}induct} is unified with the first suitable assumption, which
    1.86 +is \isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}} rather than \isa{{\isacharparenleft}y{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}}. Although that
    1.87 +is what we want, it is merely due to the order in which the assumptions occur
    1.88 +in the subgoal, which it is not good practice to rely on. As a result,
    1.89 +\isa{{\isacharquery}xb} becomes \isa{x}, \isa{{\isacharquery}xa} becomes
    1.90 +\isa{y} and \isa{{\isacharquery}P} becomes \isa{{\isasymlambda}u\ v{\isachardot}\ {\isacharparenleft}u{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}}, thus
    1.91  yielding the above subgoal. So what went wrong?
    1.92  
    1.93 -When looking at the instantiation of $P~x~y$ we see
    1.94 -that $P$ does not depend on its second parameter at
    1.95 -all. The reason is that in our original goal, of the pair \isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}} only
    1.96 -\isa{x} appears also in the conclusion, but not \isa{y}. Thus our
    1.97 -induction statement is too weak. Fortunately, it can easily be strengthened:
    1.98 +When looking at the instantiation of \isa{{\isacharquery}P} we see that it does not
    1.99 +depend on its second parameter at all. The reason is that in our original
   1.100 +goal, of the pair \isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}} only \isa{x} appears also in the
   1.101 +conclusion, but not \isa{y}. Thus our induction statement is too
   1.102 +weak. Fortunately, it can easily be strengthened:
   1.103  transfer the additional premise \isa{{\isacharparenleft}y{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}} into the conclusion:%
   1.104  \end{isamarkuptxt}%
   1.105  \isacommand{lemma}\ rtc{\isacharunderscore}trans{\isacharbrackleft}rule{\isacharunderscore}format{\isacharbrackright}{\isacharcolon}\isanewline
   1.106 @@ -145,11 +153,16 @@
   1.107  certainly pick the simplest induction schema available for any concept.
   1.108  Hence \isa{rtc} is the definition of choice.
   1.109  
   1.110 -\begin{exercise}
   1.111 +\begin{exercise}\label{ex:converse-rtc-step}
   1.112  Show that the converse of \isa{rtc{\isacharunderscore}step} also holds:
   1.113  \begin{isabelle}%
   1.114  \ \ \ \ \ {\isasymlbrakk}{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isacharsemicolon}\ {\isacharparenleft}y{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}%
   1.115  \end{isabelle}
   1.116 +\end{exercise}
   1.117 +\begin{exercise}
   1.118 +Repeat the development of this section, but starting with a definition of
   1.119 +\isa{rtc} where \isa{rtc{\isacharunderscore}step} is replaced by its converse as shown
   1.120 +in exercise~\ref{ex:converse-rtc-step}.
   1.121  \end{exercise}%
   1.122  \end{isamarkuptext}%
   1.123  \end{isabellebody}%