doc-src/TutorialI/Inductive/document/Star.tex
author nipkow
Mon, 06 Nov 2000 11:32:23 +0100
changeset 10396 5ab08609e6c8
parent 10395 7ef380745743
child 10520 bb9dfcc87951
permissions -rw-r--r--
*** empty log message ***
nipkow@10225
     1
%
nipkow@10225
     2
\begin{isabellebody}%
nipkow@10225
     3
\def\isabellecontext{Star}%
nipkow@10225
     4
%
wenzelm@10395
     5
\isamarkupsection{The reflexive transitive closure%
wenzelm@10395
     6
}
nipkow@10225
     7
%
nipkow@10225
     8
\begin{isamarkuptext}%
nipkow@10242
     9
\label{sec:rtc}
nipkow@10242
    10
{\bf Say something about inductive relations as opposed to sets? Or has that
nipkow@10242
    11
been said already? If not, explain induction!}
nipkow@10242
    12
nipkow@10237
    13
A perfect example of an inductive definition is the reflexive transitive
nipkow@10225
    14
closure of a relation. This concept was already introduced in
nipkow@10396
    15
\S\ref{sec:Relations}, where the operator \isa{{\isacharcircum}{\isacharasterisk}} was
nipkow@10396
    16
defined as a least fixed point because
nipkow@10396
    17
inductive definitions were not yet available. But now they are:%
nipkow@10225
    18
\end{isamarkuptext}%
nipkow@10242
    19
\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
nipkow@10225
    20
\isacommand{inductive}\ {\isachardoublequote}r{\isacharasterisk}{\isachardoublequote}\isanewline
nipkow@10225
    21
\isakeyword{intros}\isanewline
nipkow@10242
    22
rtc{\isacharunderscore}refl{\isacharbrackleft}iff{\isacharbrackright}{\isacharcolon}\ \ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}x{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\isanewline
nipkow@10242
    23
rtc{\isacharunderscore}step{\isacharcolon}\ \ \ \ \ \ \ {\isachardoublequote}{\isasymlbrakk}\ {\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r{\isacharsemicolon}\ {\isacharparenleft}y{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}%
nipkow@10242
    24
\begin{isamarkuptext}%
nipkow@10242
    25
\noindent
nipkow@10242
    26
The function \isa{rtc} is annotated with concrete syntax: instead of
nipkow@10242
    27
\isa{rtc\ r} we can read and write {term"r*"}. The actual definition
nipkow@10242
    28
consists of two rules. Reflexivity is obvious and is immediately declared an
nipkow@10363
    29
equivalence rule.  Thus the automatic tools will apply it automatically. The
nipkow@10363
    30
second rule, \isa{rtc{\isacharunderscore}step}, says that we can always add one more
nipkow@10363
    31
\isa{r}-step to the left. Although we could make \isa{rtc{\isacharunderscore}step} an
nipkow@10242
    32
introduction rule, this is dangerous: the recursion slows down and may
nipkow@10242
    33
even kill the automatic tactics.
nipkow@10242
    34
nipkow@10242
    35
The above definition of the concept of reflexive transitive closure may
nipkow@10242
    36
be sufficiently intuitive but it is certainly not the only possible one:
nipkow@10242
    37
for a start, it does not even mention transitivity explicitly.
nipkow@10242
    38
The rest of this section is devoted to proving that it is equivalent to
nipkow@10242
    39
the ``standard'' definition. We start with a simple lemma:%
nipkow@10242
    40
\end{isamarkuptext}%
nipkow@10225
    41
\isacommand{lemma}\ {\isacharbrackleft}intro{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isacharcolon}\ r\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\isanewline
nipkow@10242
    42
\isacommand{by}{\isacharparenleft}blast\ intro{\isacharcolon}\ rtc{\isacharunderscore}step{\isacharparenright}%
nipkow@10242
    43
\begin{isamarkuptext}%
nipkow@10242
    44
\noindent
nipkow@10242
    45
Although the lemma itself is an unremarkable consequence of the basic rules,
nipkow@10242
    46
it has the advantage that it can be declared an introduction rule without the
nipkow@10242
    47
danger of killing the automatic tactics because \isa{r{\isacharasterisk}} occurs only in
nipkow@10242
    48
the conclusion and not in the premise. Thus some proofs that would otherwise
nipkow@10242
    49
need \isa{rtc{\isacharunderscore}step} can now be found automatically. The proof also
nipkow@10242
    50
shows that \isa{blast} is quite able to handle \isa{rtc{\isacharunderscore}step}. But
nipkow@10242
    51
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.
nipkow@10242
    52
nipkow@10242
    53
Let us now turn to transitivity. It should be a consequence of the definition.%
nipkow@10242
    54
\end{isamarkuptext}%
nipkow@10242
    55
\isacommand{lemma}\ rtc{\isacharunderscore}trans{\isacharcolon}\isanewline
nipkow@10242
    56
\ \ {\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}%
nipkow@10242
    57
\begin{isamarkuptxt}%
nipkow@10242
    58
\noindent
nipkow@10242
    59
The proof starts canonically by rule induction:%
nipkow@10242
    60
\end{isamarkuptxt}%
nipkow@10242
    61
\isacommand{apply}{\isacharparenleft}erule\ rtc{\isachardot}induct{\isacharparenright}%
nipkow@10363
    62
\begin{isamarkuptxt}%
nipkow@10242
    63
\noindent
nipkow@10242
    64
However, even the resulting base case is a problem
nipkow@10363
    65
\begin{isabelle}%
nipkow@10363
    66
\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}x{\isachardot}\ {\isacharparenleft}y{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}%
nipkow@10242
    67
\end{isabelle}
nipkow@10242
    68
and maybe not what you had expected. We have to abandon this proof attempt.
nipkow@10242
    69
To understand what is going on,
nipkow@10242
    70
let us look at the induction rule \isa{rtc{\isachardot}induct}:
nipkow@10242
    71
\[ \frac{(x,y) \in r^* \qquad \bigwedge x.~P~x~x \quad \dots}{P~x~y} \]
nipkow@10242
    72
When applying this rule, $x$ becomes \isa{x}, $y$ becomes
nipkow@10242
    73
\isa{y} and $P~x~y$ becomes \isa{{\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}}, thus
nipkow@10242
    74
yielding the above subgoal. So what went wrong?
nipkow@10242
    75
nipkow@10242
    76
When looking at the instantiation of $P~x~y$ we see
nipkow@10242
    77
that $P$ does not depend on its second parameter at
nipkow@10242
    78
all. The reason is that in our original goal, of the pair \isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}} only
nipkow@10242
    79
\isa{x} appears also in the conclusion, but not \isa{y}. Thus our
nipkow@10242
    80
induction statement is too weak. Fortunately, it can easily be strengthened:
nipkow@10242
    81
transfer the additional premise \isa{{\isacharparenleft}y{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}} into the conclusion:%
nipkow@10363
    82
\end{isamarkuptxt}%
nipkow@10242
    83
\isacommand{lemma}\ rtc{\isacharunderscore}trans{\isacharbrackleft}rule{\isacharunderscore}format{\isacharbrackright}{\isacharcolon}\isanewline
nipkow@10242
    84
\ \ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymLongrightarrow}\ {\isacharparenleft}y{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymlongrightarrow}\ {\isacharparenleft}x{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}%
nipkow@10242
    85
\begin{isamarkuptxt}%
nipkow@10242
    86
\noindent
nipkow@10242
    87
This is not an obscure trick but a generally applicable heuristic:
nipkow@10242
    88
\begin{quote}\em
nipkow@10242
    89
Whe proving a statement by rule induction on $(x@1,\dots,x@n) \in R$,
nipkow@10242
    90
pull all other premises containing any of the $x@i$ into the conclusion
nipkow@10242
    91
using $\longrightarrow$.
nipkow@10242
    92
\end{quote}
nipkow@10242
    93
A similar heuristic for other kinds of inductions is formulated in
nipkow@10242
    94
\S\ref{sec:ind-var-in-prems}. The \isa{rule{\isacharunderscore}format} directive turns
nipkow@10242
    95
\isa{{\isasymlongrightarrow}} back into \isa{{\isasymLongrightarrow}}. Thus in the end we obtain the original
nipkow@10363
    96
statement of our lemma.%
nipkow@10363
    97
\end{isamarkuptxt}%
nipkow@10363
    98
\isacommand{apply}{\isacharparenleft}erule\ rtc{\isachardot}induct{\isacharparenright}%
nipkow@10363
    99
\begin{isamarkuptxt}%
nipkow@10363
   100
\noindent
nipkow@10242
   101
Now induction produces two subgoals which are both proved automatically:
nipkow@10363
   102
\begin{isabelle}%
nipkow@10242
   103
\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}x{\isachardot}\ {\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymlongrightarrow}\ {\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\isanewline
nipkow@10242
   104
\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}x\ y\ za{\isachardot}\isanewline
nipkow@10242
   105
\ \ \ \ \ \ \ {\isasymlbrakk}{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ r{\isacharsemicolon}\ {\isacharparenleft}y{\isacharcomma}\ za{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isacharsemicolon}\ {\isacharparenleft}za{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymlongrightarrow}\ {\isacharparenleft}y{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isasymrbrakk}\isanewline
nipkow@10363
   106
\ \ \ \ \ \ \ {\isasymLongrightarrow}\ {\isacharparenleft}za{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymlongrightarrow}\ {\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}%
nipkow@10242
   107
\end{isabelle}%
nipkow@10242
   108
\end{isamarkuptxt}%
nipkow@10225
   109
\ \isacommand{apply}{\isacharparenleft}blast{\isacharparenright}\isanewline
nipkow@10237
   110
\isacommand{apply}{\isacharparenleft}blast\ intro{\isacharcolon}\ rtc{\isacharunderscore}step{\isacharparenright}\isanewline
nipkow@10242
   111
\isacommand{done}%
nipkow@10242
   112
\begin{isamarkuptext}%
nipkow@10242
   113
Let us now prove that \isa{r{\isacharasterisk}} is really the reflexive transitive closure
nipkow@10242
   114
of \isa{r}, i.e.\ the least reflexive and transitive
nipkow@10242
   115
relation containing \isa{r}. The latter is easily formalized%
nipkow@10242
   116
\end{isamarkuptext}%
nipkow@10237
   117
\isacommand{consts}\ rtc{\isadigit{2}}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}a{\isacharparenright}set\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}a{\isacharparenright}set{\isachardoublequote}\isanewline
nipkow@10237
   118
\isacommand{inductive}\ {\isachardoublequote}rtc{\isadigit{2}}\ r{\isachardoublequote}\isanewline
nipkow@10225
   119
\isakeyword{intros}\isanewline
nipkow@10237
   120
{\isachardoublequote}{\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ rtc{\isadigit{2}}\ r{\isachardoublequote}\isanewline
nipkow@10237
   121
{\isachardoublequote}{\isacharparenleft}x{\isacharcomma}x{\isacharparenright}\ {\isasymin}\ rtc{\isadigit{2}}\ r{\isachardoublequote}\isanewline
nipkow@10237
   122
{\isachardoublequote}{\isasymlbrakk}\ {\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ rtc{\isadigit{2}}\ r{\isacharsemicolon}\ {\isacharparenleft}y{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ rtc{\isadigit{2}}\ r\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ rtc{\isadigit{2}}\ r{\isachardoublequote}%
nipkow@10237
   123
\begin{isamarkuptext}%
nipkow@10242
   124
\noindent
nipkow@10242
   125
and the equivalence of the two definitions is easily shown by the obvious rule
nipkow@10237
   126
inductions:%
nipkow@10237
   127
\end{isamarkuptext}%
nipkow@10237
   128
\isacommand{lemma}\ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ rtc{\isadigit{2}}\ r\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\isanewline
nipkow@10237
   129
\isacommand{apply}{\isacharparenleft}erule\ rtc{\isadigit{2}}{\isachardot}induct{\isacharparenright}\isanewline
nipkow@10237
   130
\ \ \isacommand{apply}{\isacharparenleft}blast{\isacharparenright}\isanewline
nipkow@10237
   131
\ \isacommand{apply}{\isacharparenleft}blast{\isacharparenright}\isanewline
nipkow@10237
   132
\isacommand{apply}{\isacharparenleft}blast\ intro{\isacharcolon}\ rtc{\isacharunderscore}trans{\isacharparenright}\isanewline
nipkow@10237
   133
\isacommand{done}\isanewline
nipkow@10225
   134
\isanewline
nipkow@10237
   135
\isacommand{lemma}\ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ rtc{\isadigit{2}}\ r{\isachardoublequote}\isanewline
nipkow@10237
   136
\isacommand{apply}{\isacharparenleft}erule\ rtc{\isachardot}induct{\isacharparenright}\isanewline
nipkow@10237
   137
\ \isacommand{apply}{\isacharparenleft}blast\ intro{\isacharcolon}\ rtc{\isadigit{2}}{\isachardot}intros{\isacharparenright}\isanewline
nipkow@10237
   138
\isacommand{apply}{\isacharparenleft}blast\ intro{\isacharcolon}\ rtc{\isadigit{2}}{\isachardot}intros{\isacharparenright}\isanewline
nipkow@10242
   139
\isacommand{done}%
nipkow@10242
   140
\begin{isamarkuptext}%
nipkow@10242
   141
So why did we start with the first definition? Because it is simpler. It
nipkow@10242
   142
contains only two rules, and the single step rule is simpler than
nipkow@10242
   143
transitivity.  As a consequence, \isa{rtc{\isachardot}induct} is simpler than
nipkow@10242
   144
\isa{rtc{\isadigit{2}}{\isachardot}induct}. Since inductive proofs are hard enough, we should
nipkow@10242
   145
certainly pick the simplest induction schema available for any concept.
nipkow@10242
   146
Hence \isa{rtc} is the definition of choice.
nipkow@10242
   147
nipkow@10242
   148
\begin{exercise}
nipkow@10242
   149
Show that the converse of \isa{rtc{\isacharunderscore}step} also holds:
nipkow@10242
   150
\begin{isabelle}%
nipkow@10242
   151
\ \ \ \ \ {\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}%
nipkow@10242
   152
\end{isabelle}
nipkow@10242
   153
\end{exercise}%
nipkow@10242
   154
\end{isamarkuptext}%
nipkow@10225
   155
\end{isabellebody}%
nipkow@10225
   156
%%% Local Variables:
nipkow@10225
   157
%%% mode: latex
nipkow@10225
   158
%%% TeX-master: "root"
nipkow@10225
   159
%%% End: