9722
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
10267
|
3 |
\def\isabellecontext{Nested{\isadigit{1}}}%
|
17056
|
4 |
%
|
|
5 |
\isadelimtheory
|
|
6 |
%
|
|
7 |
\endisadelimtheory
|
|
8 |
%
|
|
9 |
\isatagtheory
|
|
10 |
%
|
|
11 |
\endisatagtheory
|
|
12 |
{\isafoldtheory}%
|
|
13 |
%
|
|
14 |
\isadelimtheory
|
|
15 |
%
|
|
16 |
\endisadelimtheory
|
|
17 |
\isamarkuptrue%
|
10186
|
18 |
%
|
9698
|
19 |
\begin{isamarkuptext}%
|
|
20 |
\noindent
|
11277
|
21 |
Although the definition of \isa{trev} below is quite natural, we will have
|
10878
|
22 |
to overcome a minor difficulty in convincing Isabelle of its termination.
|
9754
|
23 |
It is precisely this difficulty that is the \textit{raison d'\^etre} of
|
9698
|
24 |
this subsection.
|
|
25 |
|
|
26 |
Defining \isa{trev} by \isacommand{recdef} rather than \isacommand{primrec}
|
|
27 |
simplifies matters because we are now free to use the recursion equation
|
|
28 |
suggested at the end of \S\ref{sec:nested-datatype}:%
|
|
29 |
\end{isamarkuptext}%
|
17056
|
30 |
\isamarkupfalse%
|
11636
|
31 |
\isacommand{recdef}\ trev\ {\isachardoublequote}measure\ size{\isachardoublequote}\isanewline
|
|
32 |
\ {\isachardoublequote}trev\ {\isacharparenleft}Var\ x{\isacharparenright}\ \ \ \ {\isacharequal}\ Var\ x{\isachardoublequote}\isanewline
|
17056
|
33 |
\ {\isachardoublequote}trev\ {\isacharparenleft}App\ f\ ts{\isacharparenright}\ {\isacharequal}\ App\ f\ {\isacharparenleft}rev{\isacharparenleft}map\ trev\ ts{\isacharparenright}{\isacharparenright}{\isachardoublequote}\isamarkuptrue%
|
11866
|
34 |
%
|
11636
|
35 |
\begin{isamarkuptext}%
|
|
36 |
\noindent
|
|
37 |
Remember that function \isa{size} is defined for each \isacommand{datatype}.
|
|
38 |
However, the definition does not succeed. Isabelle complains about an
|
|
39 |
unproved termination condition
|
|
40 |
\begin{isabelle}%
|
|
41 |
\ \ \ \ \ t\ {\isasymin}\ set\ ts\ {\isasymlongrightarrow}\ size\ t\ {\isacharless}\ Suc\ {\isacharparenleft}term{\isacharunderscore}list{\isacharunderscore}size\ ts{\isacharparenright}%
|
|
42 |
\end{isabelle}
|
|
43 |
where \isa{set} returns the set of elements of a list
|
|
44 |
and \isa{term{\isacharunderscore}list{\isacharunderscore}size\ {\isacharcolon}{\isacharcolon}\ term\ list\ {\isasymRightarrow}\ nat} is an auxiliary
|
|
45 |
function automatically defined by Isabelle
|
|
46 |
(while processing the declaration of \isa{term}). Why does the
|
|
47 |
recursive call of \isa{trev} lead to this
|
|
48 |
condition? Because \isacommand{recdef} knows that \isa{map}
|
|
49 |
will apply \isa{trev} only to elements of \isa{ts}. Thus the
|
|
50 |
condition expresses that the size of the argument \isa{t\ {\isasymin}\ set\ ts} of any
|
|
51 |
recursive call of \isa{trev} is strictly less than \isa{size\ {\isacharparenleft}App\ f\ ts{\isacharparenright}},
|
|
52 |
which equals \isa{Suc\ {\isacharparenleft}term{\isacharunderscore}list{\isacharunderscore}size\ ts{\isacharparenright}}. We will now prove the termination condition and
|
|
53 |
continue with our definition. Below we return to the question of how
|
12491
|
54 |
\isacommand{recdef} knows about \isa{map}.
|
|
55 |
|
|
56 |
The termination condition is easily proved by induction:%
|
11636
|
57 |
\end{isamarkuptext}%
|
17056
|
58 |
%
|
|
59 |
\isadelimtheory
|
|
60 |
%
|
|
61 |
\endisadelimtheory
|
|
62 |
%
|
|
63 |
\isatagtheory
|
|
64 |
%
|
|
65 |
\endisatagtheory
|
|
66 |
{\isafoldtheory}%
|
|
67 |
%
|
|
68 |
\isadelimtheory
|
|
69 |
%
|
|
70 |
\endisadelimtheory
|
11636
|
71 |
\end{isabellebody}%
|
9698
|
72 |
%%% Local Variables:
|
|
73 |
%%% mode: latex
|
|
74 |
%%% TeX-master: "root"
|
|
75 |
%%% End:
|