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