https://wiki.haskell.org/api.php?action=feedcontributions&user=Simon04&feedformat=atomHaskellWiki - User contributions [en]2024-03-28T19:56:24ZUser contributionsMediaWiki 1.35.5https://wiki.haskell.org/index.php?title=Recursive_function_theory&diff=44278Recursive function theory2012-01-29T13:13:52Z<p>Simon04: /* Implementations */ link to archive.org-archived version as the website is no longer available</p>
<hr />
<div>== Introduction ==<br />
<br />
* [http://planetmath.org/encyclopedia/RecursiveFunction.html PlanetMath article]<br />
* Dr Matt Fairtlough's [http://www.dcs.shef.ac.uk/~matt/teaching/04/com2030/lectures/tomlect13.pdf Introduction to recursive function theory] among his [http://www.dcs.shef.ac.uk/~matt/teaching/04/com2030/ lecture notes]<br />
<br />
== Designed languages ==<br />
* Dr Matt Fairtlough's [http://www.dcs.shef.ac.uk/~matt/teaching/04/com2030/lectures/tomlect16.pdf Minimal Programming Language (MIN)] is not exactly a recursive function theory language, but it is based on natural numbers, too and its equivalent power with partal recursive functions is shown in its description.<br />
<br />
== Implementations ==<br />
[http://web.archive.org/web/20060713051445/http://www.dcs.shef.ac.uk/~matt/teaching/04/com2030/lectures/Recursion.hs In Haskell], among other implementations (e.g. written in Java) in Dr Matt Fairtlough's [http://web.archive.org/web/20060713073121/http://www.dcs.shef.ac.uk/~matt/teaching/04/com2030/ lecture notes] (see the bottom of the page).<br />
<br />
== Motivations ==<br />
<br />
Well-known concepts are taken from [Mon:MathLog], but several new notations (only notations, not concepts) are introduced to reflect all concepts described in [Mon:MathLog], and some simplifications are made (by allowing zero-arity generalizations). These are plans to achieve formalizations that can allow us in the future to incarnate the main concepts of recursive function theory in a ''toy'' programming language, to play with it so that some interesting concepts can be taught in a funny way.<br />
<br />
The relatedness of this page to Haskell (and to functional programming) is very few. It seems to me that (programming in) recursive functional theory may be rather another world (e.g. currying is missing, too) -- although the lack of variables (even lack of formal parameters) can yield a feeling resembling to [[pointfree]] style programming, or even to [[combinatory logic]].<br />
<br />
But despite of its weak (direct) relatedness to functional programming, maybe this page can be useful for someone in the future<br />
* e.g. when writing on quines (self-printing programs or self-representing formulas) etc. David Madore's [http://www.madore.org/~david/computers/quine.html Quines (self-replicating programs)] page uses recursive function theory for explaining the theoretical roots of quines (e.g. [http://www.madore.org/~david/computers/quine.html#sec_fp fixed point theorem])<br />
* or when writing on other general concepts of [[computer science]].<br />
<br />
Other few relatedness of this topic to Haskell may appear by the fact that the Haskell implementation of the mentioned toy programming language may use<br />
* tricks with types, [[type arithmetic]]<br />
* or metaprogramming concepts, at worst preprocessing steps<br />
because type-safe implementations of <math>\underline\mathbf\dot K^m_n</math> and <math>\underline\mathbf K^m_n</math> does not look straightforward for me.<br />
<br />
== Notations ==<br />
<br />
;<math>\mathbb N</math><br />
:the set of natural numbers, incuding 0<br />
;''Type system''<br />
:I do not use this term in a precise way here: see the following items for explanation. Headlines ''Type system'' may suggest that the type system of the planned recursive function theory programming language implementation can prevent the user from applying a partial function to an out-of-domain value -- but I think that type safety in this sense cannot be achieved.<br />
;<math>f:A\to B</math><br />
:<math>f</math> is a total function from <math>A</math> to <math>B</math>. In an implemented recursion function theory language, it means a function that surely terminates.<br />
;<math>f:A\supset\!\to B</math><br />
:<math>f</math> is a partial function from <math>A</math> to <math>B</math> (it may be either a total function or a proper partial function). In an implemented recursion theory language, maybe this information (being partial) cannot be grasped by the type system. It may mean that proper partial functions simply fail to terminate, without reflecting this possibility in the type system in any way.<br />
;<math>A\times B</math><br />
:Descartes-product of sets is used here for stressing the fact that recursive function theory does not know the concept of ''currying'' (much more other concepts will be needed to achieve something similar to currying, see [http://en.wikipedia.org/wiki/S-m-n_theorem Kleene's <math>s^m_n</math> theorem]). So using <math>f:A\times B\to C</math> (instead of <math>f:A\to B\to C</math>) is intended to stress the lack of currying (at this level).<br />
<br />
== Primitive recursive functions ==<br />
<br />
=== Type system ===<br />
<br />
:<math>\left\lfloor0\right\rfloor = \mathbb N</math><br />
:<math>\begin{matrix}\left\lfloor n + 1\right\rfloor = \underbrace{\mathbb N\times\dots\times\mathbb N}\to\mathbb N\\\;\;\;\;\;\;\;\;n+1\end{matrix}</math><br />
<br />
=== Initial functions ===<br />
<br />
==== Constant ====<br />
<br />
:<math>\mathbf 0 : \left\lfloor0\right\rfloor</math><br />
:<math>\mathbf 0 = 0</math><br />
<br />
This allows us to deal with a concept of zero in recursive function theory.<br />
In the literature (in [Mon:MathLog], too) this aim is achieved in another way: a<br />
:<math>\mathbf{zero} : \left\lfloor1\right\rfloor</math><br />
:<math>\mathbf{zero}\;x = 0</math><br />
is defined instead. Is this approach superfluously overcomplicated? Can we avoid it and use the more simple and indirect looking<br />
:<math>\mathbf 0 : \left\lfloor0\right\rfloor</math><br />
:<math>\mathbf 0 = 0</math><br />
approach?<br />
<br />
Are these approaches equivalent? Is the latter (more simple looking) one as powerful as the former one? Could we define a <math>\mathbf{zero}</math> using the<br />
:<math>\mathbf 0 : \left\lfloor0\right\rfloor</math><br />
:<math>\mathbf 0 = 0</math><br />
approach?<br />
Let us try:<br />
:<math>\mathbf{zero} = \underline\mathbf K^0_1 \mathbf0</math> <br />
(see the definition of <math>\underline\mathbf K^m_n</math> somewhat below).<br />
This looks like working, but raises new questions: what about generalizing operations (here: composition) to deal with zero-arity cases in an appropriate way?<br />
E.g.<br />
:<math>\underline\mathbf\dot K^0_n c\left\langle\right\rangle</math><br />
:<math>\underline\mathbf K^0_n c</math><br />
where <math>c : \left\lfloor0\right\rfloor, n \in \mathbb N</math><br />
can be regarded as <math>n</math>-ary functions throwing all their <math>n</math> arguments away and returning <math>c</math>.<br />
<br />
Does it take a generalization to allow such cases, or can they be inferred?<br />
A practical approach to solve such questions: let us write a Haskell program which implements (at least partially) recursive function theory. Then we can see clearly which things have to be defined and things which are consequences. I think the <math>\underline\mathbf K^0_n c</math> construct is a rather straighforward thing.<br />
<br />
Why all this can be important: it may be exactly <math>\underline\mathbf K^0_n c</math> that saves us from defining the concept of zero in recursive function theory as<br />
:<math>\mathbf{zero} : \left\lfloor1\right\rfloor</math><br />
:<math>\mathbf{zero}\;x = 0</math><br />
-- it may be superfluous: if we need functions that throw away (some or all) of their arguments and return a constant, then we can combine them from <math>\underline\mathbf K^m_n</math>, <math>\mathbf s</math> and <math>\mathbf 0</math>, if we allow concepts like <math>\underline\mathbf K^0_m</math>.<br />
<br />
==== Successor function ====<br />
<br />
:<math>\mathbf s : \left\lfloor1\right\rfloor</math><br />
:<math>\mathbf s = \lambda x . x + 1</math><br />
<br />
==== Projection functions ====<br />
<br />
For all <math>0\leq i<m</math>:<br />
:<math>\mathbf U^m_i : \left\lfloor m\right\rfloor</math><br />
:<math>\mathbf U^m_i x_0\dots x_i \dots x_{m-1} = x_i</math><br />
<br />
=== Operations ===<br />
<br />
==== Composition ====<br />
<br />
:<math>\underline\mathbf\dot K^m_n : \left\lfloor m\right\rfloor \times \left\lfloor n\right\rfloor^m \to \left\lfloor n\right\rfloor</math><br />
:<math>\underline\mathbf\dot K^m_n f \left\langle g_0,\dots, g_{m-1}\right\rangle x_0 \dots x_{n-1} = f \left(g_0 x_0 \dots x_{n-1}\right) \dots \left(g_{m-1} x_0 \dots x_{n-1}\right)</math><br />
This resembles to the <math>\mathbf\Phi^n_m</math> combinator of [[Combinatory logic]] (as described in <nowiki>[HasFeyCr:CombLog1, 171]</nowiki>).<br />
If we prefer avoiding the notion of the nested tuple, and use a more homogenous style (somewhat resembling to currying):<br />
:<math>\begin{matrix}\underline\mathbf K^m_n : \left\lfloor m\right\rfloor \times \underbrace{\left\lfloor n\right\rfloor\times\dots\times\left\lfloor n\right\rfloor} \to \left\lfloor n\right\rfloor\\\;\;\;\;\;\;\;\;\;\;m\end{matrix}</math><br />
Let underbrace not mislead us -- it does not mean any bracing.<br />
:<math>\underline\mathbf K^m_n f g_0\dots g_{m-1} x_0 \dots x_{n-1} = f \left(g_0 x_0 \dots x_{n-1}\right) \dots \left(g_{m-1} x_0 \dots x_{n-1}\right)</math><br />
remembering us to<br />
:<math>\underline\mathbf K^m_n f g_0\dots g_{m-1} x_0 \dots x_{n-1} = \mathbf \Phi^n_m f g_0 \dots g_{m-1} x_0 \dots x_{n-1}</math><br />
<br />
==== Primitive recursion ====<br />
<br />
:<math>\underline\mathbf R^m : \left\lfloor m\right\rfloor \times \left\lfloor m+2\right\rfloor \to \left\lfloor m+1\right\rfloor</math><br />
:<math>\underline\mathbf R^m f h = g\;\mathrm{where}</math><br />
::<math>g x_0 \dots x_{m-1} 0 = f x_0 \dots x_{m-1}</math><br />
::<math>g x_0 \dots x_{m-1} \left(\mathbf s y\right) = h x_0 \dots x_{m-1} y \left(g x_0\dots x_{m-1} y\right)</math><br />
The last equation resembles to the <math>\mathbf S_n</math> combinator of [[Combinatory logic]] (as described in <nowiki>[HasFeyCr:CombLog1, 169]</nowiki>):<br />
:<math>g x_0 \dots x_{m-1} \left(\mathbf s y\right) = \mathbf S_{m+1} h g x_0 \dots x_{m-1} y</math><br />
<br />
== General recursive functions ==<br />
<br />
Everything seen above, and the new concepts:<br />
<br />
=== Type system ===<br />
<br />
:<math> \widehat{\,m\,} = \left\{ f : \left\lfloor m+1\right\rfloor\;\vert\;f \mathrm{\ is\ special}\right\}</math><br />
<br />
See the definition of being ''special'' <nowiki>[Mon:MathLog, 45]</nowiki>. This property ensures, that minimalization does not lead us out of the world of total functions. Its definition is the rather straightforward formalization of this expectation.<br />
:<math>\mathbf{special}^m f \equiv \forall x_0, \dots, x_{m-1} \in \mathbb N\;\;\exists y \in \mathbb N\;\;f x_0 \dots x_{m-1} y = 0</math><br />
It resembles to the concept of inverse -- more exactly, to the existence part.<br />
<br />
<br />
=== Operations ===<br />
<br />
==== Minimalization ====<br />
<br />
:<math>\underline\mu^m : \widehat m \to \left\lfloor m\right\rfloor</math><br />
:<math>\underline\mu^m f x_0 \dots x_{m-1} = \min \left\{y\in\mathbb N\;\vert\;f x_0 \dots x_{m-1} y = 0\right\}</math><br />
Minimalization does not lead us out of the word of total functions, if we use it only for ''special'' functions -- the property of being ''special'' is defined exactly for this purpose [Mon:MatLog, 45].<br />
As we can see, minimalization is a concept resembling somehow to the concept of ''inverse''.<br />
<br />
Existence of the required minimum value of the set -- a sufficient and satisfactory condition for this is that the set is never empty. And this is equivalent to the statement<br />
:<math>\forall x_0, \dots, x_{m-1} \in \mathbb N\;\;\exists y \in \mathbb N\;\;f x_0 \dots x_{m-1} y = 0</math><br />
<br />
== Partial recursive functions ==<br />
<br />
Everything seen above, but new constructs are provided, too.<br />
<br />
=== Type system ===<br />
<br />
:<math>\begin{matrix}\left\lceil n + 1\right\rceil = \underbrace{\mathbb N\times\dots\times\mathbb N}\supset\!\to\mathbb N\\\;\;\;\;\;\;n+1\end{matrix}</math><br />
<br />
Question: is there any sense to define<br />
<math>\left\lceil0\right\rceil</math> in another way than simply <math>\left\lceil0\right\rceil = \left\lfloor0\right\rfloor = \mathbb N</math>? Partial constant?<br />
Is<br />
:<math>\left\lceil0\right\rceil = \mathbb N</math> <br />
<br />
or<br />
:<math>\left\lceil0\right\rceil = \mathbb N\;\cup\;\left\{\bot\right\}</math>? <br />
=== Operations ===<br />
<br />
:<math>\overline\mathbf\dot K^m_n : \left\lceil m\right\rceil \times \left\lceil n\right\rceil^m \to \left\lceil n\right\rceil</math><br />
:<math>\begin{matrix}\overline\mathbf K^m_n : \left\lceil m\right\rceil \times \underbrace{\left\lceil n\right\rceil\times\dots\times\left\lceil n\right\rceil} \to \left\lceil n\right\rceil\\\;\;\;\;\;\;\;\;\;\;m\end{matrix}</math><br />
<br />
:<math>\overline\mathbf R^m : \left\lceil m\right\rceil \times \left\lceil m+2\right\rceil \to \left\lceil m+1\right\rceil</math> <br />
:<math>\overline\mu^m : \left\lceil m+1\right\rceil \to \left\lceil m\right\rceil</math><br />
<br />
Their definitions are straightforward extension of the corresponding total function based definitions.<br />
<br />
Remark: these operations take partial functions as arguments, but they are total operations themselves in the sense that they always yield a result -- at worst an empty function (as an ultimate partial function).<br />
<br />
== Bibliography ==<br />
<br />
;<nowiki>[HasFeyCr:CombLog1]</nowiki><br />
:Curry, Haskell B; Feys, Robert; Craig, William: Combinatory Logic. Volume I. North-Holland Publishing Company, Amsterdam, 1958.<br />
;<nowiki>[Mon:MathLog]</nowiki><br />
:Monk, J. Donald: Mathematical Logic. Springer-Verlag, New York * Heidelberg * Berlin, 1976.<br />
<br />
[[Category:Theoretical foundations]]</div>Simon04