9645
|
1 |
(*<*)
|
9689
|
2 |
theory Nested1 = Nested0:;
|
9645
|
3 |
(*>*)
|
9689
|
4 |
consts trev :: "('a,'b)term => ('a,'b)term";
|
9645
|
5 |
|
|
6 |
text{*\noindent
|
|
7 |
Although the definition of @{term"trev"} is quite natural, we will have
|
|
8 |
overcome a minor difficulty in convincing Isabelle of is termination.
|
|
9 |
It is precisely this difficulty that is the \textit{rasion d'\^etre} of
|
|
10 |
this subsection.
|
|
11 |
|
|
12 |
Defining @{term"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}:
|
9689
|
15 |
*};
|
9645
|
16 |
|
|
17 |
recdef trev "measure size"
|
|
18 |
"trev (Var x) = Var x"
|
|
19 |
"trev (App f ts) = App f (rev(map trev ts))";
|
9689
|
20 |
|
9645
|
21 |
text{*
|
|
22 |
FIXME: recdef should complain and generate unprovable termination condition!
|
9689
|
23 |
moveto todo
|
9645
|
24 |
|
9689
|
25 |
Remember that function @{term"size"} is defined for each \isacommand{datatype}.
|
|
26 |
However, the definition does not succeed. Isabelle complains about an unproved termination
|
|
27 |
condition
|
9645
|
28 |
\begin{quote}
|
9689
|
29 |
@{term[display]"t : set ts --> size t < Suc (term_size ts)"}
|
9645
|
30 |
\end{quote}
|
9689
|
31 |
where @{term"set"} returns the set of elements of a list---no special knowledge of sets is
|
|
32 |
required in the following.
|
|
33 |
First we have to understand why the recursive call of @{term"trev"} underneath @{term"map"} leads
|
|
34 |
to the above condition. The reason is that \isacommand{recdef} ``knows'' that @{term"map"} will
|
|
35 |
apply @{term"trev"} only to elements of @{term"ts"}. Thus the above condition expresses that
|
|
36 |
the size of the argument @{term"t : set ts"} of any recursive call of @{term"trev"} is strictly
|
|
37 |
less than @{term"size(App f ts) = Suc(term_size ts)"}.
|
|
38 |
We will now prove the termination condition and continue with our definition.
|
|
39 |
Below we return to the question of how \isacommand{recdef} ``knows'' about @{term"map"}.
|
|
40 |
*};
|
9645
|
41 |
|
|
42 |
(*<*)
|
9689
|
43 |
end;
|
|
44 |
(*>*) |