4 % |
4 % |
5 \isamarkupsection{The reflexive transitive closure} |
5 \isamarkupsection{The reflexive transitive closure} |
6 % |
6 % |
7 \begin{isamarkuptext}% |
7 \begin{isamarkuptext}% |
8 \label{sec:rtc} |
8 \label{sec:rtc} |
9 |
|
10 {\bf Say something about inductive relations as opposed to sets? Or has that |
9 {\bf Say something about inductive relations as opposed to sets? Or has that |
11 been said already? If not, explain induction!} |
10 been said already? If not, explain induction!} |
12 |
11 |
13 A perfect example of an inductive definition is the reflexive transitive |
12 A perfect example of an inductive definition is the reflexive transitive |
14 closure of a relation. This concept was already introduced in |
13 closure of a relation. This concept was already introduced in |
15 \S\ref{sec:rtrancl}, but it was not shown how it is defined. In fact, |
14 \S\ref{sec:rtrancl}, but it was not shown how it is defined. In fact, |
16 the operator \isa{{\isacharcircum}{\isacharasterisk}} is not defined inductively but via a least |
15 the operator \isa{{\isacharcircum}{\isacharasterisk}} is not defined inductively but via a least |
17 fixpoint because at that point in the theory hierarchy |
16 fixed point because at that point in the theory hierarchy |
18 inductive definitions are not yet available. But now they are:% |
17 inductive definitions are not yet available. But now they are:% |
19 \end{isamarkuptext}% |
18 \end{isamarkuptext}% |
20 \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 |
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 |
21 \isacommand{inductive}\ {\isachardoublequote}r{\isacharasterisk}{\isachardoublequote}\isanewline |
20 \isacommand{inductive}\ {\isachardoublequote}r{\isacharasterisk}{\isachardoublequote}\isanewline |
22 \isakeyword{intros}\isanewline |
21 \isakeyword{intros}\isanewline |
25 \begin{isamarkuptext}% |
24 \begin{isamarkuptext}% |
26 \noindent |
25 \noindent |
27 The function \isa{rtc} is annotated with concrete syntax: instead of |
26 The function \isa{rtc} is annotated with concrete syntax: instead of |
28 \isa{rtc\ r} we can read and write {term"r*"}. The actual definition |
27 \isa{rtc\ r} we can read and write {term"r*"}. The actual definition |
29 consists of two rules. Reflexivity is obvious and is immediately declared an |
28 consists of two rules. Reflexivity is obvious and is immediately declared an |
30 equivalence. Thus the automatic tools will apply it automatically. The second |
29 equivalence rule. Thus the automatic tools will apply it automatically. The |
31 rule, \isa{rtc{\isacharunderscore}step}, says that we can always add one more \isa{r}-step to the left. Although we could make \isa{rtc{\isacharunderscore}step} an |
30 second rule, \isa{rtc{\isacharunderscore}step}, says that we can always add one more |
|
31 \isa{r}-step to the left. Although we could make \isa{rtc{\isacharunderscore}step} an |
32 introduction rule, this is dangerous: the recursion slows down and may |
32 introduction rule, this is dangerous: the recursion slows down and may |
33 even kill the automatic tactics. |
33 even kill the automatic tactics. |
34 |
34 |
35 The above definition of the concept of reflexive transitive closure may |
35 The above definition of the concept of reflexive transitive closure may |
36 be sufficiently intuitive but it is certainly not the only possible one: |
36 be sufficiently intuitive but it is certainly not the only possible one: |
57 \begin{isamarkuptxt}% |
57 \begin{isamarkuptxt}% |
58 \noindent |
58 \noindent |
59 The proof starts canonically by rule induction:% |
59 The proof starts canonically by rule induction:% |
60 \end{isamarkuptxt}% |
60 \end{isamarkuptxt}% |
61 \isacommand{apply}{\isacharparenleft}erule\ rtc{\isachardot}induct{\isacharparenright}% |
61 \isacommand{apply}{\isacharparenleft}erule\ rtc{\isachardot}induct{\isacharparenright}% |
62 \begin{isamarkuptext}% |
62 \begin{isamarkuptxt}% |
63 \noindent |
63 \noindent |
64 However, even the resulting base case is a problem |
64 However, even the resulting base case is a problem |
65 \begin{isabelle} |
65 \begin{isabelle}% |
66 \ {\isadigit{1}}{\isachardot}\ {\isasymAnd}x{\isachardot}\ {\isacharparenleft}y{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk} |
66 \ {\isadigit{1}}{\isachardot}\ {\isasymAnd}x{\isachardot}\ {\isacharparenleft}y{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}% |
67 \end{isabelle} |
67 \end{isabelle} |
68 and maybe not what you had expected. We have to abandon this proof attempt. |
68 and maybe not what you had expected. We have to abandon this proof attempt. |
69 To understand what is going on, |
69 To understand what is going on, |
70 let us look at the induction rule \isa{rtc{\isachardot}induct}: |
70 let us look at the induction rule \isa{rtc{\isachardot}induct}: |
71 \[ \frac{(x,y) \in r^* \qquad \bigwedge x.~P~x~x \quad \dots}{P~x~y} \] |
71 \[ \frac{(x,y) \in r^* \qquad \bigwedge x.~P~x~x \quad \dots}{P~x~y} \] |
77 that $P$ does not depend on its second parameter at |
77 that $P$ does not depend on its second parameter at |
78 all. The reason is that in our original goal, of the pair \isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}} only |
78 all. The reason is that in our original goal, of the pair \isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}} only |
79 \isa{x} appears also in the conclusion, but not \isa{y}. Thus our |
79 \isa{x} appears also in the conclusion, but not \isa{y}. Thus our |
80 induction statement is too weak. Fortunately, it can easily be strengthened: |
80 induction statement is too weak. Fortunately, it can easily be strengthened: |
81 transfer the additional premise \isa{{\isacharparenleft}y{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}} into the conclusion:% |
81 transfer the additional premise \isa{{\isacharparenleft}y{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}} into the conclusion:% |
82 \end{isamarkuptext}% |
82 \end{isamarkuptxt}% |
83 \isacommand{lemma}\ rtc{\isacharunderscore}trans{\isacharbrackleft}rule{\isacharunderscore}format{\isacharbrackright}{\isacharcolon}\isanewline |
83 \isacommand{lemma}\ rtc{\isacharunderscore}trans{\isacharbrackleft}rule{\isacharunderscore}format{\isacharbrackright}{\isacharcolon}\isanewline |
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}% |
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}% |
85 \begin{isamarkuptxt}% |
85 \begin{isamarkuptxt}% |
86 \noindent |
86 \noindent |
87 This is not an obscure trick but a generally applicable heuristic: |
87 This is not an obscure trick but a generally applicable heuristic: |
91 using $\longrightarrow$. |
91 using $\longrightarrow$. |
92 \end{quote} |
92 \end{quote} |
93 A similar heuristic for other kinds of inductions is formulated in |
93 A similar heuristic for other kinds of inductions is formulated in |
94 \S\ref{sec:ind-var-in-prems}. The \isa{rule{\isacharunderscore}format} directive turns |
94 \S\ref{sec:ind-var-in-prems}. The \isa{rule{\isacharunderscore}format} directive turns |
95 \isa{{\isasymlongrightarrow}} back into \isa{{\isasymLongrightarrow}}. Thus in the end we obtain the original |
95 \isa{{\isasymlongrightarrow}} back into \isa{{\isasymLongrightarrow}}. Thus in the end we obtain the original |
96 statement of our lemma. |
96 statement of our lemma.% |
97 |
97 \end{isamarkuptxt}% |
|
98 \isacommand{apply}{\isacharparenleft}erule\ rtc{\isachardot}induct{\isacharparenright}% |
|
99 \begin{isamarkuptxt}% |
|
100 \noindent |
98 Now induction produces two subgoals which are both proved automatically: |
101 Now induction produces two subgoals which are both proved automatically: |
99 \begin{isabelle} |
102 \begin{isabelle}% |
100 \ {\isadigit{1}}{\isachardot}\ {\isasymAnd}x{\isachardot}\ {\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymlongrightarrow}\ {\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\isanewline |
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 |
101 \ {\isadigit{2}}{\isachardot}\ {\isasymAnd}x\ y\ za{\isachardot}\isanewline |
104 \ {\isadigit{2}}{\isachardot}\ {\isasymAnd}x\ y\ za{\isachardot}\isanewline |
102 \ \ \ \ \ \ \ {\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 |
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 |
103 \ \ \ \ \ \ \ {\isasymLongrightarrow}\ {\isacharparenleft}za{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymlongrightarrow}\ {\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk} |
106 \ \ \ \ \ \ \ {\isasymLongrightarrow}\ {\isacharparenleft}za{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymlongrightarrow}\ {\isacharparenleft}x{\isacharcomma}\ z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}% |
104 \end{isabelle}% |
107 \end{isabelle}% |
105 \end{isamarkuptxt}% |
108 \end{isamarkuptxt}% |
106 \isacommand{apply}{\isacharparenleft}erule\ rtc{\isachardot}induct{\isacharparenright}\isanewline |
|
107 \ \isacommand{apply}{\isacharparenleft}blast{\isacharparenright}\isanewline |
109 \ \isacommand{apply}{\isacharparenleft}blast{\isacharparenright}\isanewline |
108 \isacommand{apply}{\isacharparenleft}blast\ intro{\isacharcolon}\ rtc{\isacharunderscore}step{\isacharparenright}\isanewline |
110 \isacommand{apply}{\isacharparenleft}blast\ intro{\isacharcolon}\ rtc{\isacharunderscore}step{\isacharparenright}\isanewline |
109 \isacommand{done}% |
111 \isacommand{done}% |
110 \begin{isamarkuptext}% |
112 \begin{isamarkuptext}% |
111 Let us now prove that \isa{r{\isacharasterisk}} is really the reflexive transitive closure |
113 Let us now prove that \isa{r{\isacharasterisk}} is really the reflexive transitive closure |