9722
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
9924
|
3 |
\def\isabellecontext{ToyList}%
|
11866
|
4 |
\isacommand{theory}\ ToyList\ {\isacharequal}\ PreList{\isacharcolon}\isamarkupfalse%
|
|
5 |
%
|
8749
|
6 |
\begin{isamarkuptext}%
|
|
7 |
\noindent
|
8771
|
8 |
HOL already has a predefined theory of lists called \isa{List} ---
|
|
9 |
\isa{ToyList} is merely a small fragment of it chosen as an example. In
|
8749
|
10 |
contrast to what is recommended in \S\ref{sec:Basic:Theories},
|
8771
|
11 |
\isa{ToyList} is not based on \isa{Main} but on \isa{PreList}, a
|
8749
|
12 |
theory that contains pretty much everything but lists, thus avoiding
|
|
13 |
ambiguities caused by defining lists twice.%
|
|
14 |
\end{isamarkuptext}%
|
11866
|
15 |
\isamarkuptrue%
|
9674
|
16 |
\isacommand{datatype}\ {\isacharprime}a\ list\ {\isacharequal}\ Nil\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharparenleft}{\isachardoublequote}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequote}{\isacharparenright}\isanewline
|
11866
|
17 |
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ Cons\ {\isacharprime}a\ {\isachardoublequote}{\isacharprime}a\ list{\isachardoublequote}\ \ \ \ \ \ \ \ \ \ \ \ {\isacharparenleft}\isakeyword{infixr}\ {\isachardoublequote}{\isacharhash}{\isachardoublequote}\ {\isadigit{6}}{\isadigit{5}}{\isacharparenright}\isamarkupfalse%
|
|
18 |
%
|
8749
|
19 |
\begin{isamarkuptext}%
|
|
20 |
\noindent
|
11428
|
21 |
\index{datatype@\isacommand {datatype} (command)}
|
|
22 |
The datatype \tydx{list} introduces two
|
|
23 |
constructors \cdx{Nil} and \cdx{Cons}, the
|
9541
|
24 |
empty~list and the operator that adds an element to the front of a list. For
|
9792
|
25 |
example, the term \isa{Cons True (Cons False Nil)} is a value of
|
|
26 |
type \isa{bool\ list}, namely the list with the elements \isa{True} and
|
11450
|
27 |
\isa{False}. Because this notation quickly becomes unwieldy, the
|
8749
|
28 |
datatype declaration is annotated with an alternative syntax: instead of
|
9541
|
29 |
\isa{Nil} and \isa{Cons x xs} we can write
|
9792
|
30 |
\isa{{\isacharbrackleft}{\isacharbrackright}}\index{$HOL2list@\texttt{[]}|bold} and
|
|
31 |
\isa{x\ {\isacharhash}\ xs}\index{$HOL2list@\texttt{\#}|bold}. In fact, this
|
11450
|
32 |
alternative syntax is the familiar one. Thus the list \isa{Cons True
|
9674
|
33 |
(Cons False Nil)} becomes \isa{True\ {\isacharhash}\ False\ {\isacharhash}\ {\isacharbrackleft}{\isacharbrackright}}. The annotation
|
11428
|
34 |
\isacommand{infixr}\index{infixr@\isacommand{infixr} (annotation)}
|
|
35 |
means that \isa{{\isacharhash}} associates to
|
11450
|
36 |
the right: the term \isa{x\ {\isacharhash}\ y\ {\isacharhash}\ z} is read as \isa{x\ {\isacharhash}\ {\isacharparenleft}y\ {\isacharhash}\ z{\isacharparenright}}
|
9792
|
37 |
and not as \isa{{\isacharparenleft}x\ {\isacharhash}\ y{\isacharparenright}\ {\isacharhash}\ z}.
|
10971
|
38 |
The \isa{{\isadigit{6}}{\isadigit{5}}} is the priority of the infix \isa{{\isacharhash}}.
|
8749
|
39 |
|
|
40 |
\begin{warn}
|
11456
|
41 |
Syntax annotations are can be powerful, but they are difficult to master and
|
|
42 |
are never necessary. You
|
8771
|
43 |
could drop them from theory \isa{ToyList} and go back to the identifiers
|
10795
|
44 |
\isa{Nil} and \isa{Cons}.
|
11456
|
45 |
Novices should avoid using
|
10795
|
46 |
syntax annotations in their own theories.
|
8749
|
47 |
\end{warn}
|
11428
|
48 |
Next, two functions \isa{app} and \cdx{rev} are declared:%
|
8749
|
49 |
\end{isamarkuptext}%
|
11866
|
50 |
\isamarkuptrue%
|
10187
|
51 |
\isacommand{consts}\ app\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list{\isachardoublequote}\ \ \ {\isacharparenleft}\isakeyword{infixr}\ {\isachardoublequote}{\isacharat}{\isachardoublequote}\ {\isadigit{6}}{\isadigit{5}}{\isacharparenright}\isanewline
|
11866
|
52 |
\ \ \ \ \ \ \ rev\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list{\isachardoublequote}\isamarkupfalse%
|
|
53 |
%
|
8749
|
54 |
\begin{isamarkuptext}%
|
|
55 |
\noindent
|
10971
|
56 |
In contrast to many functional programming languages,
|
|
57 |
Isabelle insists on explicit declarations of all functions
|
11456
|
58 |
(keyword \commdx{consts}). Apart from the declaration-before-use
|
10971
|
59 |
restriction, the order of items in a theory file is unconstrained. Function
|
10790
|
60 |
\isa{app} is annotated with concrete syntax too. Instead of the
|
|
61 |
prefix syntax \isa{app\ xs\ ys} the infix
|
9792
|
62 |
\isa{xs\ {\isacharat}\ ys}\index{$HOL2list@\texttt{\at}|bold} becomes the preferred
|
8749
|
63 |
form. Both functions are defined recursively:%
|
|
64 |
\end{isamarkuptext}%
|
11866
|
65 |
\isamarkuptrue%
|
8749
|
66 |
\isacommand{primrec}\isanewline
|
9674
|
67 |
{\isachardoublequote}{\isacharbrackleft}{\isacharbrackright}\ {\isacharat}\ ys\ \ \ \ \ \ \ {\isacharequal}\ ys{\isachardoublequote}\isanewline
|
|
68 |
{\isachardoublequote}{\isacharparenleft}x\ {\isacharhash}\ xs{\isacharparenright}\ {\isacharat}\ ys\ {\isacharequal}\ x\ {\isacharhash}\ {\isacharparenleft}xs\ {\isacharat}\ ys{\isacharparenright}{\isachardoublequote}\isanewline
|
8749
|
69 |
\isanewline
|
11866
|
70 |
\isamarkupfalse%
|
8749
|
71 |
\isacommand{primrec}\isanewline
|
9674
|
72 |
{\isachardoublequote}rev\ {\isacharbrackleft}{\isacharbrackright}\ \ \ \ \ \ \ \ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequote}\isanewline
|
11866
|
73 |
{\isachardoublequote}rev\ {\isacharparenleft}x\ {\isacharhash}\ xs{\isacharparenright}\ \ {\isacharequal}\ {\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharat}\ {\isacharparenleft}x\ {\isacharhash}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
|
|
74 |
%
|
8749
|
75 |
\begin{isamarkuptext}%
|
11456
|
76 |
\noindent\index{*rev (constant)|(}\index{append function|(}
|
10790
|
77 |
The equations for \isa{app} and \isa{rev} hardly need comments:
|
|
78 |
\isa{app} appends two lists and \isa{rev} reverses a list. The
|
11428
|
79 |
keyword \commdx{primrec} indicates that the recursion is
|
10790
|
80 |
of a particularly primitive kind where each recursive call peels off a datatype
|
8771
|
81 |
constructor from one of the arguments. Thus the
|
10654
|
82 |
recursion always terminates, i.e.\ the function is \textbf{total}.
|
11428
|
83 |
\index{functions!total}
|
8749
|
84 |
|
|
85 |
The termination requirement is absolutely essential in HOL, a logic of total
|
|
86 |
functions. If we were to drop it, inconsistencies would quickly arise: the
|
|
87 |
``definition'' $f(n) = f(n)+1$ immediately leads to $0 = 1$ by subtracting
|
|
88 |
$f(n)$ on both sides.
|
|
89 |
% However, this is a subtle issue that we cannot discuss here further.
|
|
90 |
|
|
91 |
\begin{warn}
|
11456
|
92 |
As we have indicated, the requirement for total functions is an essential characteristic of HOL\@. It is only
|
8749
|
93 |
because of totality that reasoning in HOL is comparatively easy. More
|
11456
|
94 |
generally, the philosophy in HOL is to refrain from asserting arbitrary axioms (such as
|
8749
|
95 |
function definitions whose totality has not been proved) because they
|
|
96 |
quickly lead to inconsistencies. Instead, fixed constructs for introducing
|
|
97 |
types and functions are offered (such as \isacommand{datatype} and
|
|
98 |
\isacommand{primrec}) which are guaranteed to preserve consistency.
|
|
99 |
\end{warn}
|
|
100 |
|
11456
|
101 |
\index{syntax}%
|
8749
|
102 |
A remark about syntax. The textual definition of a theory follows a fixed
|
10971
|
103 |
syntax with keywords like \isacommand{datatype} and \isacommand{end}.
|
|
104 |
% (see Fig.~\ref{fig:keywords} in Appendix~\ref{sec:Appendix} for a full list).
|
8749
|
105 |
Embedded in this syntax are the types and formulae of HOL, whose syntax is
|
10971
|
106 |
extensible (see \S\ref{sec:syntax-anno}), e.g.\ by new user-defined infix operators.
|
|
107 |
To distinguish the two levels, everything
|
8749
|
108 |
HOL-specific (terms and types) should be enclosed in
|
|
109 |
\texttt{"}\dots\texttt{"}.
|
|
110 |
To lessen this burden, quotation marks around a single identifier can be
|
|
111 |
dropped, unless the identifier happens to be a keyword, as in%
|
|
112 |
\end{isamarkuptext}%
|
11866
|
113 |
\isamarkuptrue%
|
|
114 |
\isacommand{consts}\ {\isachardoublequote}end{\isachardoublequote}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequote}\isamarkupfalse%
|
|
115 |
%
|
8749
|
116 |
\begin{isamarkuptext}%
|
|
117 |
\noindent
|
|
118 |
When Isabelle prints a syntax error message, it refers to the HOL syntax as
|
11456
|
119 |
the \textbf{inner syntax} and the enclosing theory language as the \textbf{outer syntax}.
|
8749
|
120 |
|
|
121 |
|
10878
|
122 |
\section{An Introductory Proof}
|
8749
|
123 |
\label{sec:intro-proof}
|
|
124 |
|
|
125 |
Assuming you have input the declarations and definitions of \texttt{ToyList}
|
|
126 |
presented so far, we are ready to prove a few simple theorems. This will
|
|
127 |
illustrate not just the basic proof commands but also the typical proof
|
|
128 |
process.
|
|
129 |
|
11457
|
130 |
\subsubsection*{Main Goal.}
|
8749
|
131 |
|
|
132 |
Our goal is to show that reversing a list twice produces the original
|
11456
|
133 |
list.%
|
8749
|
134 |
\end{isamarkuptext}%
|
11866
|
135 |
\isamarkuptrue%
|
|
136 |
\isacommand{theorem}\ rev{\isacharunderscore}rev\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}rev{\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharequal}\ xs{\isachardoublequote}\isamarkupfalse%
|
|
137 |
%
|
8749
|
138 |
\begin{isamarkuptxt}%
|
11428
|
139 |
\index{theorem@\isacommand {theorem} (command)|bold}%
|
10795
|
140 |
\noindent
|
11456
|
141 |
This \isacommand{theorem} command does several things:
|
8749
|
142 |
\begin{itemize}
|
|
143 |
\item
|
11456
|
144 |
It establishes a new theorem to be proved, namely \isa{rev\ {\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharequal}\ xs}.
|
8749
|
145 |
\item
|
11456
|
146 |
It gives that theorem the name \isa{rev{\isacharunderscore}rev}, for later reference.
|
9792
|
147 |
\item
|
11456
|
148 |
It tells Isabelle (via the bracketed attribute \attrdx{simp}) to take the eventual theorem as a simplification rule: future proofs involving
|
9792
|
149 |
simplification will replace occurrences of \isa{rev\ {\isacharparenleft}rev\ xs{\isacharparenright}} by
|
8749
|
150 |
\isa{xs}.
|
11457
|
151 |
\end{itemize}
|
8749
|
152 |
The name and the simplification attribute are optional.
|
|
153 |
Isabelle's response is to print
|
9723
|
154 |
\begin{isabelle}
|
8749
|
155 |
proof(prove):~step~0\isanewline
|
|
156 |
\isanewline
|
|
157 |
goal~(theorem~rev\_rev):\isanewline
|
|
158 |
rev~(rev~xs)~=~xs\isanewline
|
|
159 |
~1.~rev~(rev~xs)~=~xs
|
9723
|
160 |
\end{isabelle}
|
8749
|
161 |
The first three lines tell us that we are 0 steps into the proof of
|
9792
|
162 |
theorem \isa{rev{\isacharunderscore}rev}; for compactness reasons we rarely show these
|
8749
|
163 |
initial lines in this tutorial. The remaining lines display the current
|
11456
|
164 |
\rmindex{proof state}.
|
8749
|
165 |
Until we have finished a proof, the proof state always looks like this:
|
9723
|
166 |
\begin{isabelle}
|
8749
|
167 |
$G$\isanewline
|
|
168 |
~1.~$G\sb{1}$\isanewline
|
|
169 |
~~\vdots~~\isanewline
|
|
170 |
~$n$.~$G\sb{n}$
|
9723
|
171 |
\end{isabelle}
|
8749
|
172 |
where $G$
|
|
173 |
is the overall goal that we are trying to prove, and the numbered lines
|
|
174 |
contain the subgoals $G\sb{1}$, \dots, $G\sb{n}$ that we need to prove to
|
11456
|
175 |
establish $G$.\index{subgoals}
|
|
176 |
At \isa{step\ {\isadigit{0}}} there is only one subgoal, which is
|
8749
|
177 |
identical with the overall goal. Normally $G$ is constant and only serves as
|
|
178 |
a reminder. Hence we rarely show it in this tutorial.
|
|
179 |
|
9792
|
180 |
Let us now get back to \isa{rev\ {\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharequal}\ xs}. Properties of recursively
|
8749
|
181 |
defined functions are best established by induction. In this case there is
|
11428
|
182 |
nothing obvious except induction on \isa{xs}:%
|
8749
|
183 |
\end{isamarkuptxt}%
|
11866
|
184 |
\isamarkuptrue%
|
|
185 |
\isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ xs{\isacharparenright}\isamarkupfalse%
|
|
186 |
%
|
8749
|
187 |
\begin{isamarkuptxt}%
|
11428
|
188 |
\noindent\index{*induct_tac (method)}%
|
8749
|
189 |
This tells Isabelle to perform induction on variable \isa{xs}. The suffix
|
11428
|
190 |
\isa{tac} stands for \textbf{tactic},\index{tactics}
|
|
191 |
a synonym for ``theorem proving function''.
|
8749
|
192 |
By default, induction acts on the first subgoal. The new proof state contains
|
|
193 |
two subgoals, namely the base case (\isa{Nil}) and the induction step
|
|
194 |
(\isa{Cons}):
|
10971
|
195 |
\begin{isabelle}%
|
|
196 |
\ {\isadigit{1}}{\isachardot}\ rev\ {\isacharparenleft}rev\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\isanewline
|
|
197 |
\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}a\ list{\isachardot}\isanewline
|
|
198 |
\isaindent{\ {\isadigit{2}}{\isachardot}\ \ \ \ }rev\ {\isacharparenleft}rev\ list{\isacharparenright}\ {\isacharequal}\ list\ {\isasymLongrightarrow}\ rev\ {\isacharparenleft}rev\ {\isacharparenleft}a\ {\isacharhash}\ list{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ a\ {\isacharhash}\ list%
|
9723
|
199 |
\end{isabelle}
|
8749
|
200 |
|
11456
|
201 |
The induction step is an example of the general format of a subgoal:\index{subgoals}
|
9723
|
202 |
\begin{isabelle}
|
10328
|
203 |
~$i$.~{\isasymAnd}$x\sb{1}$~\dots~$x\sb{n}$.~{\it assumptions}~{\isasymLongrightarrow}~{\it conclusion}
|
|
204 |
\end{isabelle}\index{$IsaAnd@\isasymAnd|bold}
|
8749
|
205 |
The prefix of bound variables \isasymAnd$x\sb{1}$~\dots~$x\sb{n}$ can be
|
|
206 |
ignored most of the time, or simply treated as a list of variables local to
|
10299
|
207 |
this subgoal. Their deeper significance is explained in Chapter~\ref{chap:rules}.
|
11456
|
208 |
The {\it assumptions}\index{assumptions!of subgoal}
|
|
209 |
are the local assumptions for this subgoal and {\it
|
|
210 |
conclusion}\index{conclusion!of subgoal} is the actual proposition to be proved.
|
|
211 |
Typical proof steps
|
|
212 |
that add new assumptions are induction and case distinction. In our example
|
9792
|
213 |
the only assumption is the induction hypothesis \isa{rev\ {\isacharparenleft}rev\ list{\isacharparenright}\ {\isacharequal}\ list}, where \isa{list} is a variable name chosen by Isabelle. If there
|
8749
|
214 |
are multiple assumptions, they are enclosed in the bracket pair
|
|
215 |
\indexboldpos{\isasymlbrakk}{$Isabrl} and
|
|
216 |
\indexboldpos{\isasymrbrakk}{$Isabrr} and separated by semicolons.
|
|
217 |
|
|
218 |
Let us try to solve both goals automatically:%
|
|
219 |
\end{isamarkuptxt}%
|
11866
|
220 |
\isamarkuptrue%
|
|
221 |
\isacommand{apply}{\isacharparenleft}auto{\isacharparenright}\isamarkupfalse%
|
|
222 |
%
|
8749
|
223 |
\begin{isamarkuptxt}%
|
|
224 |
\noindent
|
|
225 |
This command tells Isabelle to apply a proof strategy called
|
|
226 |
\isa{auto} to all subgoals. Essentially, \isa{auto} tries to
|
10978
|
227 |
simplify the subgoals. In our case, subgoal~1 is solved completely (thanks
|
9792
|
228 |
to the equation \isa{rev\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}}) and disappears; the simplified version
|
8749
|
229 |
of subgoal~2 becomes the new subgoal~1:
|
10971
|
230 |
\begin{isabelle}%
|
|
231 |
\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}a\ list{\isachardot}\isanewline
|
|
232 |
\isaindent{\ {\isadigit{1}}{\isachardot}\ \ \ \ }rev\ {\isacharparenleft}rev\ list{\isacharparenright}\ {\isacharequal}\ list\ {\isasymLongrightarrow}\ rev\ {\isacharparenleft}rev\ list\ {\isacharat}\ a\ {\isacharhash}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\ a\ {\isacharhash}\ list%
|
9723
|
233 |
\end{isabelle}
|
8749
|
234 |
In order to simplify this subgoal further, a lemma suggests itself.%
|
|
235 |
\end{isamarkuptxt}%
|
11866
|
236 |
\isamarkuptrue%
|
|
237 |
\isamarkupfalse%
|
8749
|
238 |
%
|
11428
|
239 |
\isamarkupsubsubsection{First Lemma%
|
10395
|
240 |
}
|
11866
|
241 |
\isamarkuptrue%
|
9723
|
242 |
%
|
8749
|
243 |
\begin{isamarkuptext}%
|
11428
|
244 |
\indexbold{abandoning a proof}\indexbold{proofs!abandoning}
|
|
245 |
After abandoning the above proof attempt (at the shell level type
|
|
246 |
\commdx{oops}) we start a new proof:%
|
8749
|
247 |
\end{isamarkuptext}%
|
11866
|
248 |
\isamarkuptrue%
|
|
249 |
\isacommand{lemma}\ rev{\isacharunderscore}app\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}rev{\isacharparenleft}xs\ {\isacharat}\ ys{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}rev\ ys{\isacharparenright}\ {\isacharat}\ {\isacharparenleft}rev\ xs{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
|
|
250 |
%
|
8749
|
251 |
\begin{isamarkuptxt}%
|
11428
|
252 |
\noindent The keywords \commdx{theorem} and
|
|
253 |
\commdx{lemma} are interchangeable and merely indicate
|
10971
|
254 |
the importance we attach to a proposition. Therefore we use the words
|
11428
|
255 |
\emph{theorem} and \emph{lemma} pretty much interchangeably, too.
|
8749
|
256 |
|
|
257 |
There are two variables that we could induct on: \isa{xs} and
|
9792
|
258 |
\isa{ys}. Because \isa{{\isacharat}} is defined by recursion on
|
8749
|
259 |
the first argument, \isa{xs} is the correct one:%
|
|
260 |
\end{isamarkuptxt}%
|
11866
|
261 |
\isamarkuptrue%
|
|
262 |
\isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ xs{\isacharparenright}\isamarkupfalse%
|
|
263 |
%
|
8749
|
264 |
\begin{isamarkuptxt}%
|
|
265 |
\noindent
|
|
266 |
This time not even the base case is solved automatically:%
|
|
267 |
\end{isamarkuptxt}%
|
11866
|
268 |
\isamarkuptrue%
|
|
269 |
\isacommand{apply}{\isacharparenleft}auto{\isacharparenright}\isamarkupfalse%
|
|
270 |
%
|
8749
|
271 |
\begin{isamarkuptxt}%
|
10362
|
272 |
\begin{isabelle}%
|
|
273 |
\ {\isadigit{1}}{\isachardot}\ rev\ ys\ {\isacharequal}\ rev\ ys\ {\isacharat}\ {\isacharbrackleft}{\isacharbrackright}%
|
9723
|
274 |
\end{isabelle}
|
10362
|
275 |
Again, we need to abandon this proof attempt and prove another simple lemma
|
|
276 |
first. In the future the step of abandoning an incomplete proof before
|
|
277 |
embarking on the proof of a lemma usually remains implicit.%
|
8749
|
278 |
\end{isamarkuptxt}%
|
11866
|
279 |
\isamarkuptrue%
|
|
280 |
\isamarkupfalse%
|
8749
|
281 |
%
|
11428
|
282 |
\isamarkupsubsubsection{Second Lemma%
|
10395
|
283 |
}
|
11866
|
284 |
\isamarkuptrue%
|
9723
|
285 |
%
|
8749
|
286 |
\begin{isamarkuptext}%
|
11456
|
287 |
We again try the canonical proof procedure:%
|
8749
|
288 |
\end{isamarkuptext}%
|
11866
|
289 |
\isamarkuptrue%
|
10187
|
290 |
\isacommand{lemma}\ app{\isacharunderscore}Nil{\isadigit{2}}\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}xs\ {\isacharat}\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ xs{\isachardoublequote}\isanewline
|
11866
|
291 |
\isamarkupfalse%
|
9674
|
292 |
\isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ xs{\isacharparenright}\isanewline
|
11866
|
293 |
\isamarkupfalse%
|
|
294 |
\isacommand{apply}{\isacharparenleft}auto{\isacharparenright}\isamarkupfalse%
|
|
295 |
%
|
8749
|
296 |
\begin{isamarkuptxt}%
|
|
297 |
\noindent
|
11456
|
298 |
It works, yielding the desired message \isa{No\ subgoals{\isacharbang}}:
|
10362
|
299 |
\begin{isabelle}%
|
|
300 |
xs\ {\isacharat}\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ xs\isanewline
|
|
301 |
No\ subgoals{\isacharbang}%
|
9723
|
302 |
\end{isabelle}
|
8749
|
303 |
We still need to confirm that the proof is now finished:%
|
|
304 |
\end{isamarkuptxt}%
|
11866
|
305 |
\isamarkuptrue%
|
|
306 |
\isacommand{done}\isamarkupfalse%
|
|
307 |
%
|
8749
|
308 |
\begin{isamarkuptext}%
|
11428
|
309 |
\noindent
|
|
310 |
As a result of that final \commdx{done}, Isabelle associates the lemma just proved
|
10171
|
311 |
with its name. In this tutorial, we sometimes omit to show that final \isacommand{done}
|
|
312 |
if it is obvious from the context that the proof is finished.
|
|
313 |
|
|
314 |
% Instead of \isacommand{apply} followed by a dot, you can simply write
|
|
315 |
% \isacommand{by}\indexbold{by}, which we do most of the time.
|
10971
|
316 |
Notice that in lemma \isa{app{\isacharunderscore}Nil{\isadigit{2}}},
|
|
317 |
as printed out after the final \isacommand{done}, the free variable \isa{xs} has been
|
9792
|
318 |
replaced by the unknown \isa{{\isacharquery}xs}, just as explained in
|
|
319 |
\S\ref{sec:variables}.
|
8749
|
320 |
|
|
321 |
Going back to the proof of the first lemma%
|
|
322 |
\end{isamarkuptext}%
|
11866
|
323 |
\isamarkuptrue%
|
9674
|
324 |
\isacommand{lemma}\ rev{\isacharunderscore}app\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}rev{\isacharparenleft}xs\ {\isacharat}\ ys{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}rev\ ys{\isacharparenright}\ {\isacharat}\ {\isacharparenleft}rev\ xs{\isacharparenright}{\isachardoublequote}\isanewline
|
11866
|
325 |
\isamarkupfalse%
|
9674
|
326 |
\isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ xs{\isacharparenright}\isanewline
|
11866
|
327 |
\isamarkupfalse%
|
|
328 |
\isacommand{apply}{\isacharparenleft}auto{\isacharparenright}\isamarkupfalse%
|
|
329 |
%
|
8749
|
330 |
\begin{isamarkuptxt}%
|
|
331 |
\noindent
|
|
332 |
we find that this time \isa{auto} solves the base case, but the
|
|
333 |
induction step merely simplifies to
|
10362
|
334 |
\begin{isabelle}%
|
|
335 |
\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}a\ list{\isachardot}\isanewline
|
10950
|
336 |
\isaindent{\ {\isadigit{1}}{\isachardot}\ \ \ \ }rev\ {\isacharparenleft}list\ {\isacharat}\ ys{\isacharparenright}\ {\isacharequal}\ rev\ ys\ {\isacharat}\ rev\ list\ {\isasymLongrightarrow}\isanewline
|
|
337 |
\isaindent{\ {\isadigit{1}}{\isachardot}\ \ \ \ }{\isacharparenleft}rev\ ys\ {\isacharat}\ rev\ list{\isacharparenright}\ {\isacharat}\ a\ {\isacharhash}\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ rev\ ys\ {\isacharat}\ rev\ list\ {\isacharat}\ a\ {\isacharhash}\ {\isacharbrackleft}{\isacharbrackright}%
|
9723
|
338 |
\end{isabelle}
|
9792
|
339 |
Now we need to remember that \isa{{\isacharat}} associates to the right, and that
|
10187
|
340 |
\isa{{\isacharhash}} and \isa{{\isacharat}} have the same priority (namely the \isa{{\isadigit{6}}{\isadigit{5}}}
|
8749
|
341 |
in their \isacommand{infixr} annotation). Thus the conclusion really is
|
9723
|
342 |
\begin{isabelle}
|
9792
|
343 |
~~~~~(rev~ys~@~rev~list)~@~(a~\#~[])~=~rev~ys~@~(rev~list~@~(a~\#~[]))
|
9723
|
344 |
\end{isabelle}
|
9792
|
345 |
and the missing lemma is associativity of \isa{{\isacharat}}.%
|
8749
|
346 |
\end{isamarkuptxt}%
|
11866
|
347 |
\isamarkuptrue%
|
|
348 |
\isamarkupfalse%
|
8749
|
349 |
%
|
11456
|
350 |
\isamarkupsubsubsection{Third Lemma%
|
10395
|
351 |
}
|
11866
|
352 |
\isamarkuptrue%
|
9723
|
353 |
%
|
|
354 |
\begin{isamarkuptext}%
|
11456
|
355 |
Abandoning the previous attempt, the canonical proof procedure
|
|
356 |
succeeds without further ado.%
|
9723
|
357 |
\end{isamarkuptext}%
|
11866
|
358 |
\isamarkuptrue%
|
9674
|
359 |
\isacommand{lemma}\ app{\isacharunderscore}assoc\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}xs\ {\isacharat}\ ys{\isacharparenright}\ {\isacharat}\ zs\ {\isacharequal}\ xs\ {\isacharat}\ {\isacharparenleft}ys\ {\isacharat}\ zs{\isacharparenright}{\isachardoublequote}\isanewline
|
11866
|
360 |
\isamarkupfalse%
|
9674
|
361 |
\isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ xs{\isacharparenright}\isanewline
|
11866
|
362 |
\isamarkupfalse%
|
10171
|
363 |
\isacommand{apply}{\isacharparenleft}auto{\isacharparenright}\isanewline
|
11866
|
364 |
\isamarkupfalse%
|
|
365 |
\isacommand{done}\isamarkupfalse%
|
|
366 |
%
|
8749
|
367 |
\begin{isamarkuptext}%
|
|
368 |
\noindent
|
11456
|
369 |
Now we can prove the first lemma:%
|
8749
|
370 |
\end{isamarkuptext}%
|
11866
|
371 |
\isamarkuptrue%
|
9674
|
372 |
\isacommand{lemma}\ rev{\isacharunderscore}app\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}rev{\isacharparenleft}xs\ {\isacharat}\ ys{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}rev\ ys{\isacharparenright}\ {\isacharat}\ {\isacharparenleft}rev\ xs{\isacharparenright}{\isachardoublequote}\isanewline
|
11866
|
373 |
\isamarkupfalse%
|
9674
|
374 |
\isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ xs{\isacharparenright}\isanewline
|
11866
|
375 |
\isamarkupfalse%
|
10171
|
376 |
\isacommand{apply}{\isacharparenleft}auto{\isacharparenright}\isanewline
|
11866
|
377 |
\isamarkupfalse%
|
|
378 |
\isacommand{done}\isamarkupfalse%
|
|
379 |
%
|
8749
|
380 |
\begin{isamarkuptext}%
|
|
381 |
\noindent
|
11456
|
382 |
Finally, we prove our main theorem:%
|
8749
|
383 |
\end{isamarkuptext}%
|
11866
|
384 |
\isamarkuptrue%
|
9674
|
385 |
\isacommand{theorem}\ rev{\isacharunderscore}rev\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}rev{\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharequal}\ xs{\isachardoublequote}\isanewline
|
11866
|
386 |
\isamarkupfalse%
|
9674
|
387 |
\isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ xs{\isacharparenright}\isanewline
|
11866
|
388 |
\isamarkupfalse%
|
10171
|
389 |
\isacommand{apply}{\isacharparenleft}auto{\isacharparenright}\isanewline
|
11866
|
390 |
\isamarkupfalse%
|
|
391 |
\isacommand{done}\isamarkupfalse%
|
|
392 |
%
|
8749
|
393 |
\begin{isamarkuptext}%
|
|
394 |
\noindent
|
11456
|
395 |
The final \commdx{end} tells Isabelle to close the current theory because
|
8749
|
396 |
we are finished with its development:%
|
11456
|
397 |
\index{*rev (constant)|)}\index{append function|)}%
|
8749
|
398 |
\end{isamarkuptext}%
|
11866
|
399 |
\isamarkuptrue%
|
8749
|
400 |
\isacommand{end}\isanewline
|
11866
|
401 |
\isamarkupfalse%
|
9722
|
402 |
\end{isabellebody}%
|
9145
|
403 |
%%% Local Variables:
|
|
404 |
%%% mode: latex
|
|
405 |
%%% TeX-master: "root"
|
|
406 |
%%% End:
|