10187
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{WFrec}%
|
|
4 |
%
|
|
5 |
\begin{isamarkuptext}%
|
|
6 |
\noindent
|
11161
|
7 |
So far, all recursive definitions were shown to terminate via measure
|
11494
|
8 |
functions. Sometimes this can be inconvenient or
|
10187
|
9 |
impossible. Fortunately, \isacommand{recdef} supports much more
|
|
10 |
general definitions. For example, termination of Ackermann's function
|
10654
|
11 |
can be shown by means of the \rmindex{lexicographic product} \isa{{\isacharless}{\isacharasterisk}lex{\isacharasterisk}{\isachargreater}}:%
|
10187
|
12 |
\end{isamarkuptext}%
|
|
13 |
\isacommand{consts}\ ack\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}nat{\isasymtimes}nat\ {\isasymRightarrow}\ nat{\isachardoublequote}\isanewline
|
|
14 |
\isacommand{recdef}\ ack\ {\isachardoublequote}measure{\isacharparenleft}{\isasymlambda}m{\isachardot}\ m{\isacharparenright}\ {\isacharless}{\isacharasterisk}lex{\isacharasterisk}{\isachargreater}\ measure{\isacharparenleft}{\isasymlambda}n{\isachardot}\ n{\isacharparenright}{\isachardoublequote}\isanewline
|
|
15 |
\ \ {\isachardoublequote}ack{\isacharparenleft}{\isadigit{0}}{\isacharcomma}n{\isacharparenright}\ \ \ \ \ \ \ \ \ {\isacharequal}\ Suc\ n{\isachardoublequote}\isanewline
|
|
16 |
\ \ {\isachardoublequote}ack{\isacharparenleft}Suc\ m{\isacharcomma}{\isadigit{0}}{\isacharparenright}\ \ \ \ \ {\isacharequal}\ ack{\isacharparenleft}m{\isacharcomma}\ {\isadigit{1}}{\isacharparenright}{\isachardoublequote}\isanewline
|
|
17 |
\ \ {\isachardoublequote}ack{\isacharparenleft}Suc\ m{\isacharcomma}Suc\ n{\isacharparenright}\ {\isacharequal}\ ack{\isacharparenleft}m{\isacharcomma}ack{\isacharparenleft}Suc\ m{\isacharcomma}n{\isacharparenright}{\isacharparenright}{\isachardoublequote}%
|
|
18 |
\begin{isamarkuptext}%
|
|
19 |
\noindent
|
|
20 |
The lexicographic product decreases if either its first component
|
|
21 |
decreases (as in the second equation and in the outer call in the
|
|
22 |
third equation) or its first component stays the same and the second
|
|
23 |
component decreases (as in the inner call in the third equation).
|
|
24 |
|
|
25 |
In general, \isacommand{recdef} supports termination proofs based on
|
10396
|
26 |
arbitrary well-founded relations as introduced in \S\ref{sec:Well-founded}.
|
|
27 |
This is called \textbf{well-founded
|
11494
|
28 |
recursion}\indexbold{recursion!well-founded}. A function definition
|
|
29 |
is total if and only if the set of
|
|
30 |
all pairs $(r,l)$, where $l$ is the argument on the
|
10396
|
31 |
left-hand side of an equation and $r$ the argument of some recursive call on
|
|
32 |
the corresponding right-hand side, induces a well-founded relation. For a
|
|
33 |
systematic account of termination proofs via well-founded relations see, for
|
10878
|
34 |
example, Baader and Nipkow~\cite{Baader-Nipkow}.
|
10187
|
35 |
|
11494
|
36 |
Each \isacommand{recdef} definition should be accompanied (after the function's
|
|
37 |
name) by a well-founded relation on the function's argument type.
|
|
38 |
Isabelle/HOL formalizes some of the most important
|
10396
|
39 |
constructions of well-founded relations (see \S\ref{sec:Well-founded}). For
|
11494
|
40 |
example, \isa{measure\ f} is always well-founded. The lexicographic
|
10396
|
41 |
product of two well-founded relations is again well-founded, which we relied
|
|
42 |
on when defining Ackermann's function above.
|
11308
|
43 |
Of course the lexicographic product can also be iterated:%
|
10189
|
44 |
\end{isamarkuptext}%
|
|
45 |
\isacommand{consts}\ contrived\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}nat\ {\isasymtimes}\ nat\ {\isasymtimes}\ nat\ {\isasymRightarrow}\ nat{\isachardoublequote}\isanewline
|
|
46 |
\isacommand{recdef}\ contrived\isanewline
|
|
47 |
\ \ {\isachardoublequote}measure{\isacharparenleft}{\isasymlambda}i{\isachardot}\ i{\isacharparenright}\ {\isacharless}{\isacharasterisk}lex{\isacharasterisk}{\isachargreater}\ measure{\isacharparenleft}{\isasymlambda}j{\isachardot}\ j{\isacharparenright}\ {\isacharless}{\isacharasterisk}lex{\isacharasterisk}{\isachargreater}\ measure{\isacharparenleft}{\isasymlambda}k{\isachardot}\ k{\isacharparenright}{\isachardoublequote}\isanewline
|
|
48 |
{\isachardoublequote}contrived{\isacharparenleft}i{\isacharcomma}j{\isacharcomma}Suc\ k{\isacharparenright}\ {\isacharequal}\ contrived{\isacharparenleft}i{\isacharcomma}j{\isacharcomma}k{\isacharparenright}{\isachardoublequote}\isanewline
|
|
49 |
{\isachardoublequote}contrived{\isacharparenleft}i{\isacharcomma}Suc\ j{\isacharcomma}{\isadigit{0}}{\isacharparenright}\ {\isacharequal}\ contrived{\isacharparenleft}i{\isacharcomma}j{\isacharcomma}j{\isacharparenright}{\isachardoublequote}\isanewline
|
|
50 |
{\isachardoublequote}contrived{\isacharparenleft}Suc\ i{\isacharcomma}{\isadigit{0}}{\isacharcomma}{\isadigit{0}}{\isacharparenright}\ {\isacharequal}\ contrived{\isacharparenleft}i{\isacharcomma}i{\isacharcomma}i{\isacharparenright}{\isachardoublequote}\isanewline
|
|
51 |
{\isachardoublequote}contrived{\isacharparenleft}{\isadigit{0}}{\isacharcomma}{\isadigit{0}}{\isacharcomma}{\isadigit{0}}{\isacharparenright}\ \ \ \ \ {\isacharequal}\ {\isadigit{0}}{\isachardoublequote}%
|
|
52 |
\begin{isamarkuptext}%
|
10396
|
53 |
Lexicographic products of measure functions already go a long
|
10878
|
54 |
way. Furthermore, you may embed a type in an
|
10396
|
55 |
existing well-founded relation via the inverse image construction \isa{inv{\isacharunderscore}image}. All these constructions are known to \isacommand{recdef}. Thus you
|
10241
|
56 |
will never have to prove well-foundedness of any relation composed
|
10189
|
57 |
solely of these building blocks. But of course the proof of
|
11494
|
58 |
termination of your function definition --- that the arguments
|
|
59 |
decrease with every recursive call --- may still require you to provide
|
10189
|
60 |
additional lemmas.
|
|
61 |
|
10842
|
62 |
It is also possible to use your own well-founded relations with
|
|
63 |
\isacommand{recdef}. For example, the greater-than relation can be made
|
|
64 |
well-founded by cutting it off at a certain point. Here is an example
|
|
65 |
of a recursive function that calls itself with increasing values up to ten:%
|
10187
|
66 |
\end{isamarkuptext}%
|
10189
|
67 |
\isacommand{consts}\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}nat\ {\isasymRightarrow}\ nat{\isachardoublequote}\isanewline
|
11627
|
68 |
\isacommand{recdef}\ \end{isabellebody}%
|
10187
|
69 |
%%% Local Variables:
|
|
70 |
%%% mode: latex
|
|
71 |
%%% TeX-master: "root"
|
|
72 |
%%% End:
|