9722
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
9924
|
3 |
\def\isabellecontext{AdvancedInd}%
|
11866
|
4 |
\isamarkupfalse%
|
9670
|
5 |
%
|
|
6 |
\begin{isamarkuptext}%
|
|
7 |
\noindent
|
|
8 |
Now that we have learned about rules and logic, we take another look at the
|
11494
|
9 |
finer points of induction. We consider two questions: what to do if the
|
10396
|
10 |
proposition to be proved is not directly amenable to induction
|
|
11 |
(\S\ref{sec:ind-var-in-prems}), and how to utilize (\S\ref{sec:complete-ind})
|
|
12 |
and even derive (\S\ref{sec:derive-ind}) new induction schemas. We conclude
|
|
13 |
with an extended example of induction (\S\ref{sec:CTL-revisited}).%
|
9670
|
14 |
\end{isamarkuptext}%
|
11866
|
15 |
\isamarkuptrue%
|
9670
|
16 |
%
|
10878
|
17 |
\isamarkupsubsection{Massaging the Proposition%
|
10397
|
18 |
}
|
11866
|
19 |
\isamarkuptrue%
|
9670
|
20 |
%
|
|
21 |
\begin{isamarkuptext}%
|
10217
|
22 |
\label{sec:ind-var-in-prems}
|
11494
|
23 |
Often we have assumed that the theorem to be proved is already in a form
|
10878
|
24 |
that is amenable to induction, but sometimes it isn't.
|
|
25 |
Here is an example.
|
|
26 |
Since \isa{hd} and \isa{last} return the first and last element of a
|
|
27 |
non-empty list, this lemma looks easy to prove:%
|
9670
|
28 |
\end{isamarkuptext}%
|
11866
|
29 |
\isamarkuptrue%
|
9673
|
30 |
\isacommand{lemma}\ {\isachardoublequote}xs\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymLongrightarrow}\ hd{\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharequal}\ last\ xs{\isachardoublequote}\isanewline
|
11866
|
31 |
\isamarkupfalse%
|
15481
|
32 |
\isamarkupfalse%
|
11866
|
33 |
\isamarkuptrue%
|
|
34 |
\isamarkupfalse%
|
13791
|
35 |
\isacommand{lemma}\ hd{\isacharunderscore}rev\ {\isacharbrackleft}rule{\isacharunderscore}format{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}xs\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymlongrightarrow}\ hd{\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharequal}\ last\ xs{\isachardoublequote}\isamarkupfalse%
|
11866
|
36 |
\isamarkupfalse%
|
|
37 |
\isamarkuptrue%
|
12492
|
38 |
\isamarkupfalse%
|
9670
|
39 |
%
|
10878
|
40 |
\isamarkupsubsection{Beyond Structural and Recursion Induction%
|
10397
|
41 |
}
|
11866
|
42 |
\isamarkuptrue%
|
9670
|
43 |
%
|
|
44 |
\begin{isamarkuptext}%
|
10217
|
45 |
\label{sec:complete-ind}
|
10878
|
46 |
So far, inductive proofs were by structural induction for
|
9670
|
47 |
primitive recursive functions and recursion induction for total recursive
|
|
48 |
functions. But sometimes structural induction is awkward and there is no
|
10878
|
49 |
recursive function that could furnish a more appropriate
|
|
50 |
induction schema. In such cases a general-purpose induction schema can
|
9670
|
51 |
be helpful. We show how to apply such induction schemas by an example.
|
|
52 |
|
|
53 |
Structural induction on \isa{nat} is
|
11494
|
54 |
usually known as mathematical induction. There is also \textbf{complete}
|
|
55 |
\index{induction!complete}%
|
|
56 |
induction, where you prove $P(n)$ under the assumption that $P(m)$
|
|
57 |
holds for all $m<n$. In Isabelle, this is the theorem \tdx{nat_less_induct}:
|
9670
|
58 |
\begin{isabelle}%
|
14379
|
59 |
\ \ \ \ \ {\isacharparenleft}{\isasymAnd}n{\isachardot}\ {\isasymforall}m{\isacharless}n{\isachardot}\ P\ m\ {\isasymLongrightarrow}\ P\ n{\isacharparenright}\ {\isasymLongrightarrow}\ P\ n%
|
9924
|
60 |
\end{isabelle}
|
11494
|
61 |
As an application, we prove a property of the following
|
11278
|
62 |
function:%
|
9670
|
63 |
\end{isamarkuptext}%
|
11866
|
64 |
\isamarkuptrue%
|
10281
|
65 |
\isacommand{consts}\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}nat\ {\isasymRightarrow}\ nat{\isachardoublequote}\isanewline
|
11866
|
66 |
\isamarkupfalse%
|
|
67 |
\isacommand{axioms}\ f{\isacharunderscore}ax{\isacharcolon}\ {\isachardoublequote}f{\isacharparenleft}f{\isacharparenleft}n{\isacharparenright}{\isacharparenright}\ {\isacharless}\ f{\isacharparenleft}Suc{\isacharparenleft}n{\isacharparenright}{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
|
|
68 |
%
|
9670
|
69 |
\begin{isamarkuptext}%
|
11256
|
70 |
\begin{warn}
|
|
71 |
We discourage the use of axioms because of the danger of
|
|
72 |
inconsistencies. Axiom \isa{f{\isacharunderscore}ax} does
|
|
73 |
not introduce an inconsistency because, for example, the identity function
|
|
74 |
satisfies it. Axioms can be useful in exploratory developments, say when
|
|
75 |
you assume some well-known theorems so that you can quickly demonstrate some
|
|
76 |
point about methodology. If your example turns into a substantial proof
|
|
77 |
development, you should replace axioms by theorems.
|
|
78 |
\end{warn}\noindent
|
10878
|
79 |
The axiom for \isa{f} implies \isa{n\ {\isasymle}\ f\ n}, which can
|
11196
|
80 |
be proved by induction on \mbox{\isa{f\ n}}. Following the recipe outlined
|
9670
|
81 |
above, we have to phrase the proposition as follows to allow induction:%
|
|
82 |
\end{isamarkuptext}%
|
11866
|
83 |
\isamarkuptrue%
|
|
84 |
\isacommand{lemma}\ f{\isacharunderscore}incr{\isacharunderscore}lem{\isacharcolon}\ {\isachardoublequote}{\isasymforall}i{\isachardot}\ k\ {\isacharequal}\ f\ i\ {\isasymlongrightarrow}\ i\ {\isasymle}\ f\ i{\isachardoublequote}\isamarkupfalse%
|
15481
|
85 |
\isamarkuptrue%
|
|
86 |
\isamarkupfalse%
|
11866
|
87 |
\isamarkuptrue%
|
15481
|
88 |
\isamarkupfalse%
|
|
89 |
\isamarkupfalse%
|
|
90 |
\isamarkupfalse%
|
11866
|
91 |
\isamarkuptrue%
|
|
92 |
\isamarkupfalse%
|
|
93 |
%
|
9670
|
94 |
\begin{isamarkuptext}%
|
|
95 |
\noindent
|
11196
|
96 |
If you find the last step puzzling, here are the two lemmas it employs:
|
10878
|
97 |
\begin{isabelle}
|
|
98 |
\isa{m\ {\isacharless}\ n\ {\isasymLongrightarrow}\ Suc\ m\ {\isasymle}\ n}
|
|
99 |
\rulename{Suc_leI}\isanewline
|
|
100 |
\isa{{\isasymlbrakk}i\ {\isasymle}\ j{\isacharsemicolon}\ j\ {\isacharless}\ k{\isasymrbrakk}\ {\isasymLongrightarrow}\ i\ {\isacharless}\ k}
|
|
101 |
\rulename{le_less_trans}
|
|
102 |
\end{isabelle}
|
|
103 |
%
|
9670
|
104 |
The proof goes like this (writing \isa{j} instead of \isa{nat}).
|
9792
|
105 |
Since \isa{i\ {\isacharequal}\ Suc\ j} it suffices to show
|
10878
|
106 |
\hbox{\isa{j\ {\isacharless}\ f\ {\isacharparenleft}Suc\ j{\isacharparenright}}},
|
|
107 |
by \isa{Suc{\isacharunderscore}leI}\@. This is
|
9792
|
108 |
proved as follows. From \isa{f{\isacharunderscore}ax} we have \isa{f\ {\isacharparenleft}f\ j{\isacharparenright}\ {\isacharless}\ f\ {\isacharparenleft}Suc\ j{\isacharparenright}}
|
10878
|
109 |
(1) which implies \isa{f\ j\ {\isasymle}\ f\ {\isacharparenleft}f\ j{\isacharparenright}} by the induction hypothesis.
|
|
110 |
Using (1) once more we obtain \isa{f\ j\ {\isacharless}\ f\ {\isacharparenleft}Suc\ j{\isacharparenright}} (2) by the transitivity
|
|
111 |
rule \isa{le{\isacharunderscore}less{\isacharunderscore}trans}.
|
9792
|
112 |
Using the induction hypothesis once more we obtain \isa{j\ {\isasymle}\ f\ j}
|
|
113 |
which, together with (2) yields \isa{j\ {\isacharless}\ f\ {\isacharparenleft}Suc\ j{\isacharparenright}} (again by
|
|
114 |
\isa{le{\isacharunderscore}less{\isacharunderscore}trans}).
|
9670
|
115 |
|
11494
|
116 |
This last step shows both the power and the danger of automatic proofs. They
|
|
117 |
will usually not tell you how the proof goes, because it can be hard to
|
|
118 |
translate the internal proof into a human-readable format. Automatic
|
|
119 |
proofs are easy to write but hard to read and understand.
|
9670
|
120 |
|
11494
|
121 |
The desired result, \isa{i\ {\isasymle}\ f\ i}, follows from \isa{f{\isacharunderscore}incr{\isacharunderscore}lem}:%
|
9670
|
122 |
\end{isamarkuptext}%
|
11866
|
123 |
\isamarkuptrue%
|
|
124 |
\isacommand{lemmas}\ f{\isacharunderscore}incr\ {\isacharequal}\ f{\isacharunderscore}incr{\isacharunderscore}lem{\isacharbrackleft}rule{\isacharunderscore}format{\isacharcomma}\ OF\ refl{\isacharbrackright}\isamarkupfalse%
|
|
125 |
%
|
9670
|
126 |
\begin{isamarkuptext}%
|
9698
|
127 |
\noindent
|
10878
|
128 |
The final \isa{refl} gets rid of the premise \isa{{\isacharquery}k\ {\isacharequal}\ f\ {\isacharquery}i}.
|
|
129 |
We could have included this derivation in the original statement of the lemma:%
|
9670
|
130 |
\end{isamarkuptext}%
|
11866
|
131 |
\isamarkuptrue%
|
13791
|
132 |
\isacommand{lemma}\ f{\isacharunderscore}incr{\isacharbrackleft}rule{\isacharunderscore}format{\isacharcomma}\ OF\ refl{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isasymforall}i{\isachardot}\ k\ {\isacharequal}\ f\ i\ {\isasymlongrightarrow}\ i\ {\isasymle}\ f\ i{\isachardoublequote}\isamarkupfalse%
|
11866
|
133 |
\isamarkupfalse%
|
|
134 |
%
|
9670
|
135 |
\begin{isamarkuptext}%
|
11256
|
136 |
\begin{exercise}
|
|
137 |
From the axiom and lemma for \isa{f}, show that \isa{f} is the
|
|
138 |
identity function.
|
|
139 |
\end{exercise}
|
9670
|
140 |
|
11428
|
141 |
Method \methdx{induct_tac} can be applied with any rule $r$
|
9792
|
142 |
whose conclusion is of the form ${?}P~?x@1 \dots ?x@n$, in which case the
|
9670
|
143 |
format is
|
9792
|
144 |
\begin{quote}
|
|
145 |
\isacommand{apply}\isa{{\isacharparenleft}induct{\isacharunderscore}tac} $y@1 \dots y@n$ \isa{rule{\isacharcolon}} $r$\isa{{\isacharparenright}}
|
11428
|
146 |
\end{quote}
|
9792
|
147 |
where $y@1, \dots, y@n$ are variables in the first subgoal.
|
11256
|
148 |
The conclusion of $r$ can even be an (iterated) conjunction of formulae of
|
|
149 |
the above form in which case the application is
|
9792
|
150 |
\begin{quote}
|
|
151 |
\isacommand{apply}\isa{{\isacharparenleft}induct{\isacharunderscore}tac} $y@1 \dots y@n$ \isa{and} \dots\ \isa{and} $z@1 \dots z@m$ \isa{rule{\isacharcolon}} $r$\isa{{\isacharparenright}}
|
10878
|
152 |
\end{quote}
|
|
153 |
|
11256
|
154 |
A further useful induction rule is \isa{length{\isacharunderscore}induct},
|
|
155 |
induction on the length of a list\indexbold{*length_induct}
|
|
156 |
\begin{isabelle}%
|
|
157 |
\ \ \ \ \ {\isacharparenleft}{\isasymAnd}xs{\isachardot}\ {\isasymforall}ys{\isachardot}\ length\ ys\ {\isacharless}\ length\ xs\ {\isasymlongrightarrow}\ P\ ys\ {\isasymLongrightarrow}\ P\ xs{\isacharparenright}\ {\isasymLongrightarrow}\ P\ xs%
|
|
158 |
\end{isabelle}
|
|
159 |
which is a special case of \isa{measure{\isacharunderscore}induct}
|
|
160 |
\begin{isabelle}%
|
|
161 |
\ \ \ \ \ {\isacharparenleft}{\isasymAnd}x{\isachardot}\ {\isasymforall}y{\isachardot}\ f\ y\ {\isacharless}\ f\ x\ {\isasymlongrightarrow}\ P\ y\ {\isasymLongrightarrow}\ P\ x{\isacharparenright}\ {\isasymLongrightarrow}\ P\ a%
|
|
162 |
\end{isabelle}
|
|
163 |
where \isa{f} may be any function into type \isa{nat}.%
|
9698
|
164 |
\end{isamarkuptext}%
|
11866
|
165 |
\isamarkuptrue%
|
9698
|
166 |
%
|
10878
|
167 |
\isamarkupsubsection{Derivation of New Induction Schemas%
|
10397
|
168 |
}
|
11866
|
169 |
\isamarkuptrue%
|
9698
|
170 |
%
|
|
171 |
\begin{isamarkuptext}%
|
|
172 |
\label{sec:derive-ind}
|
11494
|
173 |
\index{induction!deriving new schemas}%
|
9698
|
174 |
Induction schemas are ordinary theorems and you can derive new ones
|
11494
|
175 |
whenever you wish. This section shows you how, using the example
|
9924
|
176 |
of \isa{nat{\isacharunderscore}less{\isacharunderscore}induct}. Assume we only have structural induction
|
11494
|
177 |
available for \isa{nat} and want to derive complete induction. We
|
|
178 |
must generalize the statement as shown:%
|
9698
|
179 |
\end{isamarkuptext}%
|
11866
|
180 |
\isamarkuptrue%
|
9792
|
181 |
\isacommand{lemma}\ induct{\isacharunderscore}lem{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isasymAnd}n{\isacharcolon}{\isacharcolon}nat{\isachardot}\ {\isasymforall}m{\isacharless}n{\isachardot}\ P\ m\ {\isasymLongrightarrow}\ P\ n{\isacharparenright}\ {\isasymLongrightarrow}\ {\isasymforall}m{\isacharless}n{\isachardot}\ P\ m{\isachardoublequote}\isanewline
|
11866
|
182 |
\isamarkupfalse%
|
|
183 |
\isamarkupfalse%
|
15481
|
184 |
\isamarkuptrue%
|
|
185 |
\isamarkupfalse%
|
|
186 |
\isamarkupfalse%
|
11866
|
187 |
%
|
9698
|
188 |
\begin{isamarkuptext}%
|
|
189 |
\noindent
|
11196
|
190 |
The elimination rule \isa{less{\isacharunderscore}SucE} expresses the case distinction:
|
9698
|
191 |
\begin{isabelle}%
|
10696
|
192 |
\ \ \ \ \ {\isasymlbrakk}m\ {\isacharless}\ Suc\ n{\isacharsemicolon}\ m\ {\isacharless}\ n\ {\isasymLongrightarrow}\ P{\isacharsemicolon}\ m\ {\isacharequal}\ n\ {\isasymLongrightarrow}\ P{\isasymrbrakk}\ {\isasymLongrightarrow}\ P%
|
9924
|
193 |
\end{isabelle}
|
9698
|
194 |
|
|
195 |
Now it is straightforward to derive the original version of
|
11256
|
196 |
\isa{nat{\isacharunderscore}less{\isacharunderscore}induct} by manipulating the conclusion of the above
|
|
197 |
lemma: instantiate \isa{n} by \isa{Suc\ n} and \isa{m} by \isa{n}
|
|
198 |
and remove the trivial condition \isa{n\ {\isacharless}\ Suc\ n}. Fortunately, this
|
9698
|
199 |
happens automatically when we add the lemma as a new premise to the
|
|
200 |
desired goal:%
|
|
201 |
\end{isamarkuptext}%
|
11866
|
202 |
\isamarkuptrue%
|
9924
|
203 |
\isacommand{theorem}\ nat{\isacharunderscore}less{\isacharunderscore}induct{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isasymAnd}n{\isacharcolon}{\isacharcolon}nat{\isachardot}\ {\isasymforall}m{\isacharless}n{\isachardot}\ P\ m\ {\isasymLongrightarrow}\ P\ n{\isacharparenright}\ {\isasymLongrightarrow}\ P\ n{\isachardoublequote}\isanewline
|
11866
|
204 |
\isamarkupfalse%
|
15481
|
205 |
\isamarkupfalse%
|
11866
|
206 |
%
|
9698
|
207 |
\begin{isamarkuptext}%
|
11494
|
208 |
HOL already provides the mother of
|
10396
|
209 |
all inductions, well-founded induction (see \S\ref{sec:Well-founded}). For
|
10878
|
210 |
example theorem \isa{nat{\isacharunderscore}less{\isacharunderscore}induct} is
|
10396
|
211 |
a special case of \isa{wf{\isacharunderscore}induct} where \isa{r} is \isa{{\isacharless}} on
|
10878
|
212 |
\isa{nat}. The details can be found in theory \isa{Wellfounded_Recursion}.%
|
9670
|
213 |
\end{isamarkuptext}%
|
11866
|
214 |
\isamarkuptrue%
|
|
215 |
\isamarkupfalse%
|
9722
|
216 |
\end{isabellebody}%
|
9670
|
217 |
%%% Local Variables:
|
|
218 |
%%% mode: latex
|
|
219 |
%%% TeX-master: "root"
|
|
220 |
%%% End:
|