doc-src/TutorialI/Inductive/document/Star.tex
author paulson
Tue, 01 Feb 2005 18:01:57 +0100
changeset 15481 fc075ae929e4
parent 14379 ea10a8c3e9cf
child 15614 b098158a3f39
permissions -rw-r--r--
the new subst tactic, by Lucas Dixon
nipkow@10225
     1
%
nipkow@10225
     2
\begin{isabellebody}%
nipkow@10225
     3
\def\isabellecontext{Star}%
wenzelm@11866
     4
\isamarkupfalse%
nipkow@10225
     5
%
paulson@10878
     6
\isamarkupsection{The Reflexive Transitive Closure%
wenzelm@10395
     7
}
wenzelm@11866
     8
\isamarkuptrue%
nipkow@10225
     9
%
nipkow@10225
    10
\begin{isamarkuptext}%
nipkow@10242
    11
\label{sec:rtc}
paulson@11494
    12
\index{reflexive transitive closure!defining inductively|(}%
paulson@10878
    13
An inductive definition may accept parameters, so it can express 
paulson@10878
    14
functions that yield sets.
paulson@10878
    15
Relations too can be defined inductively, since they are just sets of pairs.
paulson@10878
    16
A perfect example is the function that maps a relation to its
paulson@10878
    17
reflexive transitive closure.  This concept was already
nipkow@11147
    18
introduced in \S\ref{sec:Relations}, where the operator \isa{\isactrlsup {\isacharasterisk}} was
nipkow@10520
    19
defined as a least fixed point because inductive definitions were not yet
nipkow@10520
    20
available. But now they are:%
nipkow@10225
    21
\end{isamarkuptext}%
wenzelm@11866
    22
\isamarkuptrue%
nipkow@10242
    23
\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
wenzelm@11866
    24
\isamarkupfalse%
nipkow@10225
    25
\isacommand{inductive}\ {\isachardoublequote}r{\isacharasterisk}{\isachardoublequote}\isanewline
nipkow@10225
    26
\isakeyword{intros}\isanewline
nipkow@10242
    27
rtc{\isacharunderscore}refl{\isacharbrackleft}iff{\isacharbrackright}{\isacharcolon}\ \ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}x{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\isanewline
wenzelm@11866
    28
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}\isamarkupfalse%
wenzelm@11866
    29
%
nipkow@10242
    30
\begin{isamarkuptext}%
nipkow@10242
    31
\noindent
nipkow@10242
    32
The function \isa{rtc} is annotated with concrete syntax: instead of
paulson@11494
    33
\isa{rtc\ r} we can write \isa{r{\isacharasterisk}}. The actual definition
nipkow@10520
    34
consists of two rules. Reflexivity is obvious and is immediately given the
nipkow@10520
    35
\isa{iff} attribute to increase automation. The
nipkow@10363
    36
second rule, \isa{rtc{\isacharunderscore}step}, says that we can always add one more
nipkow@10363
    37
\isa{r}-step to the left. Although we could make \isa{rtc{\isacharunderscore}step} an
nipkow@10520
    38
introduction rule, this is dangerous: the recursion in the second premise
nipkow@10520
    39
slows down and may even kill the automatic tactics.
nipkow@10242
    40
nipkow@10242
    41
The above definition of the concept of reflexive transitive closure may
nipkow@10242
    42
be sufficiently intuitive but it is certainly not the only possible one:
paulson@10878
    43
for a start, it does not even mention transitivity.
nipkow@10242
    44
The rest of this section is devoted to proving that it is equivalent to
paulson@10878
    45
the standard definition. We start with a simple lemma:%
nipkow@10242
    46
\end{isamarkuptext}%
wenzelm@11866
    47
\isamarkuptrue%
nipkow@11308
    48
\isacommand{lemma}\ {\isacharbrackleft}intro{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\isanewline
wenzelm@11866
    49
\isamarkupfalse%
paulson@15481
    50
\isamarkupfalse%
wenzelm@11866
    51
%
nipkow@10242
    52
\begin{isamarkuptext}%
nipkow@10242
    53
\noindent
nipkow@10242
    54
Although the lemma itself is an unremarkable consequence of the basic rules,
nipkow@10242
    55
it has the advantage that it can be declared an introduction rule without the
nipkow@10242
    56
danger of killing the automatic tactics because \isa{r{\isacharasterisk}} occurs only in
nipkow@10242
    57
the conclusion and not in the premise. Thus some proofs that would otherwise
nipkow@10242
    58
need \isa{rtc{\isacharunderscore}step} can now be found automatically. The proof also
paulson@10878
    59
shows that \isa{blast} is able to handle \isa{rtc{\isacharunderscore}step}. But
nipkow@10242
    60
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
    61
nipkow@10520
    62
To prove transitivity, we need rule induction, i.e.\ theorem
nipkow@10520
    63
\isa{rtc{\isachardot}induct}:
nipkow@10520
    64
\begin{isabelle}%
nipkow@10696
    65
\ \ \ \ \ {\isasymlbrakk}{\isacharparenleft}{\isacharquery}xb{\isacharcomma}\ {\isacharquery}xa{\isacharparenright}\ {\isasymin}\ {\isacharquery}r{\isacharasterisk}{\isacharsemicolon}\ {\isasymAnd}x{\isachardot}\ {\isacharquery}P\ x\ x{\isacharsemicolon}\isanewline
paulson@14379
    66
\isaindent{\ \ \ \ \ \ }{\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
wenzelm@10950
    67
\isaindent{\ \ \ \ \ }{\isasymLongrightarrow}\ {\isacharquery}P\ {\isacharquery}xb\ {\isacharquery}xa%
nipkow@10520
    68
\end{isabelle}
nipkow@10520
    69
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,
nipkow@10520
    70
i.e.\ if \isa{{\isacharquery}P} holds for the conclusion provided it holds for the
nipkow@10520
    71
premises. In general, rule induction for an $n$-ary inductive relation $R$
nipkow@10520
    72
expects a premise of the form $(x@1,\dots,x@n) \in R$.
nipkow@10520
    73
nipkow@10520
    74
Now we turn to the inductive proof of transitivity:%
nipkow@10242
    75
\end{isamarkuptext}%
wenzelm@11866
    76
\isamarkuptrue%
nipkow@10520
    77
\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
wenzelm@11866
    78
\isamarkupfalse%
paulson@15481
    79
\isamarkupfalse%
wenzelm@11866
    80
\isamarkuptrue%
wenzelm@11866
    81
\isamarkupfalse%
nipkow@10242
    82
\isacommand{lemma}\ rtc{\isacharunderscore}trans{\isacharbrackleft}rule{\isacharunderscore}format{\isacharbrackright}{\isacharcolon}\isanewline
wenzelm@11866
    83
\ \ {\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}\isamarkupfalse%
wenzelm@11866
    84
\isamarkuptrue%
wenzelm@11866
    85
\isamarkupfalse%
paulson@15481
    86
\isamarkuptrue%
wenzelm@11866
    87
\isamarkupfalse%
paulson@15481
    88
\isamarkupfalse%
paulson@15481
    89
\isamarkupfalse%
wenzelm@11866
    90
%
nipkow@10242
    91
\begin{isamarkuptext}%
nipkow@10242
    92
Let us now prove that \isa{r{\isacharasterisk}} is really the reflexive transitive closure
nipkow@10242
    93
of \isa{r}, i.e.\ the least reflexive and transitive
nipkow@10242
    94
relation containing \isa{r}. The latter is easily formalized%
nipkow@10242
    95
\end{isamarkuptext}%
wenzelm@11866
    96
\isamarkuptrue%
nipkow@10237
    97
\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
wenzelm@11866
    98
\isamarkupfalse%
nipkow@10237
    99
\isacommand{inductive}\ {\isachardoublequote}rtc{\isadigit{2}}\ r{\isachardoublequote}\isanewline
nipkow@10225
   100
\isakeyword{intros}\isanewline
nipkow@10237
   101
{\isachardoublequote}{\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ rtc{\isadigit{2}}\ r{\isachardoublequote}\isanewline
nipkow@10237
   102
{\isachardoublequote}{\isacharparenleft}x{\isacharcomma}x{\isacharparenright}\ {\isasymin}\ rtc{\isadigit{2}}\ r{\isachardoublequote}\isanewline
wenzelm@11866
   103
{\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}\isamarkupfalse%
wenzelm@11866
   104
%
nipkow@10237
   105
\begin{isamarkuptext}%
nipkow@10242
   106
\noindent
nipkow@10242
   107
and the equivalence of the two definitions is easily shown by the obvious rule
nipkow@10237
   108
inductions:%
nipkow@10237
   109
\end{isamarkuptext}%
wenzelm@11866
   110
\isamarkuptrue%
nipkow@10237
   111
\isacommand{lemma}\ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ rtc{\isadigit{2}}\ r\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\isanewline
wenzelm@11866
   112
\isamarkupfalse%
wenzelm@11866
   113
\isamarkupfalse%
wenzelm@11866
   114
\isamarkupfalse%
paulson@15481
   115
\isamarkupfalse%
paulson@15481
   116
\isamarkupfalse%
paulson@15481
   117
\isanewline
nipkow@10225
   118
\isanewline
wenzelm@11866
   119
\isamarkupfalse%
nipkow@10237
   120
\isacommand{lemma}\ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ rtc{\isadigit{2}}\ r{\isachardoublequote}\isanewline
wenzelm@11866
   121
\isamarkupfalse%
wenzelm@11866
   122
\isamarkupfalse%
wenzelm@11866
   123
\isamarkupfalse%
paulson@15481
   124
\isamarkupfalse%
paulson@15481
   125
\isamarkupfalse%
wenzelm@11866
   126
%
nipkow@10242
   127
\begin{isamarkuptext}%
nipkow@10242
   128
So why did we start with the first definition? Because it is simpler. It
nipkow@10242
   129
contains only two rules, and the single step rule is simpler than
nipkow@10242
   130
transitivity.  As a consequence, \isa{rtc{\isachardot}induct} is simpler than
paulson@10878
   131
\isa{rtc{\isadigit{2}}{\isachardot}induct}. Since inductive proofs are hard enough
nipkow@11147
   132
anyway, we should always pick the simplest induction schema available.
nipkow@10242
   133
Hence \isa{rtc} is the definition of choice.
paulson@11494
   134
\index{reflexive transitive closure!defining inductively|)}
nipkow@10242
   135
nipkow@10520
   136
\begin{exercise}\label{ex:converse-rtc-step}
nipkow@10242
   137
Show that the converse of \isa{rtc{\isacharunderscore}step} also holds:
nipkow@10242
   138
\begin{isabelle}%
nipkow@10696
   139
\ \ \ \ \ {\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
   140
\end{isabelle}
nipkow@10520
   141
\end{exercise}
nipkow@10520
   142
\begin{exercise}
nipkow@10520
   143
Repeat the development of this section, but starting with a definition of
nipkow@10520
   144
\isa{rtc} where \isa{rtc{\isacharunderscore}step} is replaced by its converse as shown
nipkow@10520
   145
in exercise~\ref{ex:converse-rtc-step}.
nipkow@10242
   146
\end{exercise}%
nipkow@10242
   147
\end{isamarkuptext}%
wenzelm@11866
   148
\isamarkuptrue%
wenzelm@11866
   149
\isamarkupfalse%
wenzelm@11866
   150
\isamarkupfalse%
wenzelm@11866
   151
\isamarkupfalse%
wenzelm@11866
   152
\isamarkupfalse%
wenzelm@11866
   153
\isamarkupfalse%
wenzelm@11866
   154
\isamarkupfalse%
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: