author | wenzelm |
Mon, 11 Sep 2023 19:30:48 +0200 | |
changeset 78659 | b5f3d1051b13 |
parent 76649 | 9a6cb5ecc183 |
permissions | -rw-r--r-- |
23004 | 1 |
\section{Introduction} |
2 |
||
27026 | 3 |
Starting from Isabelle 2007, new facilities for recursive |
26851 | 4 |
function definitions~\cite{krauss2006} are available. They provide |
23805 | 5 |
better support for general recursive definitions than previous |
26851 | 6 |
packages. But despite all tool support, function definitions can |
23805 | 7 |
sometimes be a difficult thing. |
23004 | 8 |
|
23188 | 9 |
This tutorial is an example-guided introduction to the practical use |
23805 | 10 |
of the package and related tools. It should help you get started with |
11 |
defining functions quickly. For the more difficult definitions we will |
|
12 |
discuss what problems can arise, and how they can be solved. |
|
13 |
||
27026 | 14 |
We assume that you have mastered the fundamentals of Isabelle/HOL |
23805 | 15 |
and are able to write basic specifications and proofs. To start out |
16 |
with Isabelle in general, consult the Isabelle/HOL tutorial |
|
17 |
\cite{isa-tutorial}. |
|
18 |
||
19 |
||
23004 | 20 |
|
23805 | 21 |
\paragraph{Structure of this tutorial.} |
22 |
Section 2 introduces the syntax and basic operation of the \cmd{fun} |
|
23 |
command, which provides full automation with reasonable default |
|
27026 | 24 |
behavior. The impatient reader can stop after that |
23805 | 25 |
section, and consult the remaining sections only when needed. |
26 |
Section 3 introduces the more verbose \cmd{function} command which |
|
27026 | 27 |
gives fine-grained control. This form should be used |
23805 | 28 |
whenever the short form fails. |
27026 | 29 |
After that we discuss more specialized issues: |
30 |
termination, mutual, nested and higher-order recursion, partiality, pattern matching |
|
23805 | 31 |
and others. |
23004 | 32 |
|
23805 | 33 |
|
34 |
\paragraph{Some background.} |
|
23004 | 35 |
Following the LCF tradition, the package is realized as a definitional |
36 |
extension: Recursive definitions are internally transformed into a |
|
37 |
non-recursive form, such that the function can be defined using |
|
38 |
standard definition facilities. Then the recursive specification is |
|
39 |
derived from the primitive definition. This is a complex task, but it |
|
40 |
is fully automated and mostly transparent to the user. Definitional |
|
41 |
extensions are valuable because they are conservative by construction: |
|
23805 | 42 |
The \qt{new} concept of general wellfounded recursion is completely reduced |
23004 | 43 |
to existing principles. |
44 |
||
45 |
||
27026 | 46 |
The new \cmd{function} command, and its short form \cmd{fun} have mostly |
47 |
replaced the traditional \cmd{recdef} command \cite{slind-tfl}. They solve |
|
48 |
a few of technical issues around \cmd{recdef}, and allow definitions |
|
23004 | 49 |
which were not previously possible. |
50 |
||
57502 | 51 |
In addition there is also the \cmd{partial\_function} command |
52 |
(see \cite{isabelle-isar-ref}) that supports the definition of partial |
|
76649
9a6cb5ecc183
Added section about code generation for partial functions
nipkow
parents:
57502
diff
changeset
|
53 |
and tail recursive functions. This command is particulary relevant if one wants to |
9a6cb5ecc183
Added section about code generation for partial functions
nipkow
parents:
57502
diff
changeset
|
54 |
generate executable code. This is covered in detail in the Code Generation |
9a6cb5ecc183
Added section about code generation for partial functions
nipkow
parents:
57502
diff
changeset
|
55 |
tutorial~\cite{Haftmann-codegen}. |
9a6cb5ecc183
Added section about code generation for partial functions
nipkow
parents:
57502
diff
changeset
|
56 |
The approach to partial function presented in Section~\ref{sec:partiality} |
9a6cb5ecc183
Added section about code generation for partial functions
nipkow
parents:
57502
diff
changeset
|
57 |
of this tutorial does not support code generation. |
23004 | 58 |
|
59 |