11 |
11 |
12 Defining \isa{trev} by \isacommand{recdef} rather than \isacommand{primrec} |
12 Defining \isa{trev} by \isacommand{recdef} rather than \isacommand{primrec} |
13 simplifies matters because we are now free to use the recursion equation |
13 simplifies matters because we are now free to use the recursion equation |
14 suggested at the end of \S\ref{sec:nested-datatype}:% |
14 suggested at the end of \S\ref{sec:nested-datatype}:% |
15 \end{isamarkuptext}% |
15 \end{isamarkuptext}% |
16 \isacommand{recdef}\ \end{isabellebody}% |
16 \isacommand{recdef}\ trev\ {\isachardoublequote}measure\ size{\isachardoublequote}\isanewline |
|
17 \ {\isachardoublequote}trev\ {\isacharparenleft}Var\ x{\isacharparenright}\ \ \ \ {\isacharequal}\ Var\ x{\isachardoublequote}\isanewline |
|
18 \ {\isachardoublequote}trev\ {\isacharparenleft}App\ f\ ts{\isacharparenright}\ {\isacharequal}\ App\ f\ {\isacharparenleft}rev{\isacharparenleft}map\ trev\ ts{\isacharparenright}{\isacharparenright}{\isachardoublequote}% |
|
19 \begin{isamarkuptext}% |
|
20 \noindent |
|
21 Remember that function \isa{size} is defined for each \isacommand{datatype}. |
|
22 However, the definition does not succeed. Isabelle complains about an |
|
23 unproved termination condition |
|
24 \begin{isabelle}% |
|
25 \ \ \ \ \ t\ {\isasymin}\ set\ ts\ {\isasymlongrightarrow}\ size\ t\ {\isacharless}\ Suc\ {\isacharparenleft}term{\isacharunderscore}list{\isacharunderscore}size\ ts{\isacharparenright}% |
|
26 \end{isabelle} |
|
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 |
|
30 (while processing the declaration of \isa{term}). Why does the |
|
31 recursive call of \isa{trev} lead to this |
|
32 condition? Because \isacommand{recdef} knows that \isa{map} |
|
33 will apply \isa{trev} only to elements of \isa{ts}. Thus the |
|
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}}, |
|
36 which equals \isa{Suc\ {\isacharparenleft}term{\isacharunderscore}list{\isacharunderscore}size\ ts{\isacharparenright}}. We will now prove the termination condition and |
|
37 continue with our definition. Below we return to the question of how |
|
38 \isacommand{recdef} knows about \isa{map}.% |
|
39 \end{isamarkuptext}% |
|
40 \end{isabellebody}% |
17 %%% Local Variables: |
41 %%% Local Variables: |
18 %%% mode: latex |
42 %%% mode: latex |
19 %%% TeX-master: "root" |
43 %%% TeX-master: "root" |
20 %%% End: |
44 %%% End: |