9722
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
9698
|
3 |
\isacommand{consts}\ trev\ \ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}b{\isacharparenright}term\ {\isacharequal}{\isachargreater}\ {\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}b{\isacharparenright}term{\isachardoublequote}%
|
|
4 |
\begin{isamarkuptext}%
|
|
5 |
\noindent
|
|
6 |
Although the definition of \isa{trev} is quite natural, we will have
|
|
7 |
overcome a minor difficulty in convincing Isabelle of is termination.
|
|
8 |
It is precisely this difficulty that is the \textit{rasion d'\^etre} of
|
|
9 |
this subsection.
|
|
10 |
|
|
11 |
Defining \isa{trev} by \isacommand{recdef} rather than \isacommand{primrec}
|
|
12 |
simplifies matters because we are now free to use the recursion equation
|
|
13 |
suggested at the end of \S\ref{sec:nested-datatype}:%
|
|
14 |
\end{isamarkuptext}%
|
|
15 |
\isacommand{recdef}\ trev\ {\isachardoublequote}measure\ size{\isachardoublequote}\isanewline
|
|
16 |
\ {\isachardoublequote}trev\ {\isacharparenleft}Var\ x{\isacharparenright}\ {\isacharequal}\ Var\ x{\isachardoublequote}\isanewline
|
|
17 |
\ {\isachardoublequote}trev\ {\isacharparenleft}App\ f\ ts{\isacharparenright}\ {\isacharequal}\ App\ f\ {\isacharparenleft}rev{\isacharparenleft}map\ trev\ ts{\isacharparenright}{\isacharparenright}{\isachardoublequote}%
|
|
18 |
\begin{isamarkuptext}%
|
|
19 |
FIXME: recdef should complain and generate unprovable termination condition!
|
|
20 |
moveto todo
|
|
21 |
|
|
22 |
Remember that function \isa{size} is defined for each \isacommand{datatype}.
|
|
23 |
However, the definition does not succeed. Isabelle complains about an unproved termination
|
|
24 |
condition
|
|
25 |
\begin{quote}
|
|
26 |
|
|
27 |
\begin{isabelle}%
|
|
28 |
\mbox{t}\ {\isasymin}\ set\ \mbox{ts}\ {\isasymlongrightarrow}\ size\ \mbox{t}\ {\isacharless}\ Suc\ {\isacharparenleft}term{\isacharunderscore}size\ \mbox{ts}{\isacharparenright}
|
|
29 |
\end{isabelle}%
|
|
30 |
|
|
31 |
\end{quote}
|
|
32 |
where \isa{set} returns the set of elements of a list---no special knowledge of sets is
|
|
33 |
required in the following.
|
|
34 |
First we have to understand why the recursive call of \isa{trev} underneath \isa{map} leads
|
|
35 |
to the above condition. The reason is that \isacommand{recdef} ``knows'' that \isa{map} will
|
|
36 |
apply \isa{trev} only to elements of \isa{\mbox{ts}}. Thus the above condition expresses that
|
|
37 |
the size of the argument \isa{\mbox{t}\ {\isasymin}\ set\ \mbox{ts}} of any recursive call of \isa{trev} is strictly
|
|
38 |
less than \isa{size\ {\isacharparenleft}App\ \mbox{f}\ \mbox{ts}{\isacharparenright}\ {\isacharequal}\ Suc\ {\isacharparenleft}term{\isacharunderscore}size\ \mbox{ts}{\isacharparenright}}.
|
|
39 |
We will now prove the termination condition and continue with our definition.
|
|
40 |
Below we return to the question of how \isacommand{recdef} ``knows'' about \isa{map}.%
|
|
41 |
\end{isamarkuptext}%
|
9722
|
42 |
\end{isabellebody}%
|
9698
|
43 |
%%% Local Variables:
|
|
44 |
%%% mode: latex
|
|
45 |
%%% TeX-master: "root"
|
|
46 |
%%% End:
|