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