How to write an enumeration of all computable functions?

Motivation: I would like to be able to use functional programming of toys in languages ​​without first-order functions, using natural numbers instead of functions.

A universal function is a function f: N β†’ (N β†’ N), which is equivalent to f: N * N β†’ N, which lists all possible computable functions. In other words, there exists a number k such that f (k) is a quadratic function, there exists a number j such that f (j) is the nth simple function, etc.

To write such a function, you can take any language containing Turing (a programming language compiler, lambda calculus, Turing machines ...) and list all the programs. I would like to allow not only evaluation, but also operations on such functions as addition, composition, currying. For example, given the indices of the two functions f, g, I would like to know what is the index of the function f + g or f composed with g. This would allow "functional toy programming."

What is a good way to write such a code library? I am not looking for a minimalistic Turing Tering that will try to calculate factorial 10, and I don't want to write an advanced compiler. It should have some basic functions, such as adding and the ability to write a loop, but not much more.

Welcome to all high-level languages. Pseudocode, Haskell and Python are preferred. You can assume arbitrary arithmetic of accuracy. Use evalor the like is not permitted.

Explanation: The listed functions will consist of all partial recursive (computable) - this includes functions that do not stop at some inputs. A universal function will hang in these cases; Of course, this is inevitable. See Also: m-recursive functions - http://en.wikipedia.org/wiki/M-recursive_function .

+5
source share
7 answers

, , .

-, , , , 2 ^ 32 2 ^ 64 . , , - .

(), ? ​​ , . f1()+f2() - , ( f1), "+" ( f2). ...

, , - , , , ( ). , . , Halting, .

+8

- , , .

, ( , ) , .

+1

, , : .

N (, int) .

, , N. . N ( ) ( ).

, , World of Warcraft, Microsoft Office 17, Service Pack 6 Windows 9.

+1

. , , . .

... .

n +, -, *,/.
:

a + a
a + b
a - a
a - b
a * a
a * b
a/a
a/b

, , , , , , , , .

, .

- , , sin log ( ), .

? !

. , , , . , "function ↔ number", zip . , , :-) , , zip .

, , : -)

0

, , - , . , (, ..) . , , , . , , , , , .

, : 433,457,175,432,167,463, .

.

, +, -,: =, ==, <, if, then, endif, do, end_do_condition, enddo . 11 , , , , , . ( , .) , 4- . , 64- .

, , , .

, , . , .

0

​​, Turing ( , , ...)

, ... , . , , , , , ... .

Godelization ... Lisp, .

0

, . - . : . : , , . .

: "" ; . . .

0

All Articles