6
$\begingroup$

We know that Turing machines and Lambda Calculus are equivalent in power. And There are proofs for that, I'm sure.

But is there an algorithm, a systematic way for us to convert a Turing machine into a Lambda Calculus expression? Is it impossible to have such algorithm? (meaning does it go down to undecidability or NP-Completeness?) if not, are there any papers or algorithms for doing so?

$\endgroup$
9
$\begingroup$

Sure there is. I'm going to assume you can figure out how to convert Haskell into the lambda calculus; for a reference, look at the GHC implementation.

Now just to be clear: a Turing Machine is a (finite) map from (State, Token) pairs to (State, Token, Direction) triples. We'll represent the states as integers (this is okay by the finiteness of the map) and represent the tokens by the values True and False. The directions will be L and R.

The state of the machine is represented by a four-tuple (State, LeftTape, Head, RightTape), where LeftTape and RightTape are lists of tokens and Head is a token.

The initial state for input n is (1, [], True, replicate (n-1) True). The machine halts if it enters state 0. The result is the number of symbols on the tape.

Now it is easy to see that the following defines an interpreter:

data Direction = L | R
type Configuration = (Integer, [Bool], Bool, [Bool])
type TM = Map (Integer, Bool) (Integer, Bool, Direction)

tail' :: [Bool] -> [Bool]
tail' (_:xs) = xs
tail' [] = []

head' :: [Bool] -> Bool
head' (x:_) = x
head' [] = False

step :: TM -> Configuration -> Configuration
step tm (s, lt, h, rt) = (s', lt', h', rt')
     where (s', t, d) = tm ! (s, h)
           (lt', h', rt') = case d of
               L -> (tail' lt, head' lt, t:rt)
               R -> (t:lt, head' rt, tail' rt)

run :: TM -> Int -> Int
run tm n = go (1, [], True, replicate (n-1) True)
    where go (0, lt, h, rt) = length . filter id $ lt ++ [h] ++ rt
          go c = go (step tm c)

(This implementation may have bugs, but a correct implementation is not far.)

Now simply take your favourite Turing Machine, partially apply the run function to it, and convert the resulting Int -> Int term into the lambda calculus.

$\endgroup$
  • $\begingroup$ This is only half an answer. The other conversion is missing: how to simulate $\lambda$-calculus with Turing machines. $\endgroup$ – Andrej Bauer Oct 24 '15 at 8:57
  • 1
    $\begingroup$ @AndrejBauer: Indeed, I'm only answering the question in the title. The other direction is left as an exercise to the reader. $\endgroup$ – Anton Golov Oct 24 '15 at 9:40
  • $\begingroup$ @AndrejBauer actually I think the answer is complete here, since I did not ask for the proof of equivalency between turing machines and lambda calculus, but only the algorithm f converting turing machines into lambda calculus, and this answer successfully satisfies the latter. $\endgroup$ – Ashkan Kzme Oct 24 '15 at 11:55
  • $\begingroup$ You are correct. $\endgroup$ – Andrej Bauer Oct 26 '15 at 8:00
12
$\begingroup$

All proofs of the equivalence of these two models of computation are constructive, that is they describe an algorithm for converting a program from one model of computation to the other. However, I caution you that these proofs are probably rather informal, and may not satisfy you. You may get luckier if you consult original work by computing pioneers (Turing, Church, Post, Kleene and their ilk).

$\endgroup$
  • 2
    $\begingroup$ The answer to your original question is: Yes, there is an algorithms, a systematic way to convert a Turing machine into a $\lambda$ calculus expression. $\endgroup$ – Yuval Filmus Oct 23 '15 at 13:08
  • $\begingroup$ well, what is it? $\endgroup$ – Ashkan Kzme Oct 23 '15 at 13:32
  • $\begingroup$ I'm not going to spell it out. For me it's enough to know that it exists in principle. If you're interested, you might be able to find it in textbooks or early papers. $\endgroup$ – Yuval Filmus Oct 23 '15 at 13:34
  • 1
    $\begingroup$ Its not popular to try to "find" these models. If there exists one, then it is trivial to prove there are infinite algorithms (just add any number of unused predicates into the system, and you'll get a new algorithm). Thus, we'd have to pick one. Ideally we want the simplest one, but Turing machine/lambda calculus has never been about being the simplest. Thus, every variant and flavor of turing complete language will have a different "best" algorithm. Computer Scientists are generally content with proving that one must exist, because that is enough to do the kinds of proofs... $\endgroup$ – Cort Ammon Oct 23 '15 at 19:51
  • $\begingroup$ .. they typically want to do. I am reminded of when they proved Rule 110 was Turing complete using cyclic tag codes. It's not the same as proving two fundamental models are equivalent, but the result was still messy enough to make me glad I didn't have to actually find the algorithm myself. $\endgroup$ – Cort Ammon Oct 23 '15 at 19:53
10
$\begingroup$

Since you did not like Yuval's answer, you deserve this one:

The equivalence of Church's $\lambda$-calculus and Turing machines is proved in the Appendix of Alan Turing's 1937 paper On computable numbers, with an application to the Entscheidungsproblem.

$\endgroup$
  • 5
    $\begingroup$ I most respectfully suggest that we are unable nor entirely willing to satisfy your further demands. I can highly recommend the Google search engine through which I also found the above reference, although, being an expert in this area, I knew of course what to look for. $\endgroup$ – Andrej Bauer Oct 23 '15 at 13:42
  • $\begingroup$ @AshkanKzme, please don't use comments to promote other questions of yours. Comments should only be used to suggest clarifications or improvements to the post you are commenting on. See cs.stackexchange.com/help/privileges/comment for more details. Note that this is not a discussion forum, so please refrain from chatty or tangential comments. $\endgroup$ – D.W. Oct 23 '15 at 16:30
  • $\begingroup$ Point well taken. Which policy describes how to respond to people who treat us like we are their servants? Servilely? $\endgroup$ – Andrej Bauer Oct 24 '15 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.