views:

880

answers:

13

I've read "what-is-turing-complete" and the wikipedia page, but I'm less interested in a formal proof than in the practical implications of being Turing Complete.

What I'm actually trying to decide is if the toy language I've just designed could be used as a general-purpose language. I know I can prove it is if I can write a Turing machine with it. But I don't want to go through that exercise until I'm fairly certain of success.

Is there a minimum set of features without which Turing Completeness is impossible? Is there a set of features which virtually guarantees completeness?

(My guess is that conditional branching and a readable/writeable memory store will get me most of the way there)


EDIT:

I think I've gone off on a tangent by saying "Turing Complete". I'm trying to guess with reasonable confidence that a newly invented language with a certain feature set (or alternately, a VM with a certain instruction set) would be able to compute anything worth computing. I know proving you can building a Turing machine with it is one way, but not the only way.

What I was hoping for was a set of guidelines like: "if it can do X,Y,and Z, it can probably do anything".

A: 

That will get you all the way there assuming you can branch on reading values from memory. And probably more than one memory location.

MSN

MSN
+4  A: 

I'm not sure if there's a "minimum set of features", but to prove that a language is Turing complete, you only have to prove that it can emulate another Turing complete system (not necessarily a Turing machine), as long as the other system is known to be Turing complete. http://en.wikipedia.org/wiki/Turing_complete#Examples has a whole list of Turing complete systems. Some of them are simpler than Turing machines.

Nate879
A: 

...than in the practical implications of being Turing Complete.

I doubt there are any practical implications of being Turing complete.

If you look at some of the examples of Turing complete machines, e.g., the original Turing machine, you'll see that the are so far from being useful for real computations that the concept must only be of theoretical interest.

David Norman
I recommend studying this topic a bit further. Turing completeness does have some very real practical implications. If you have a language that is not Turing complete then it is very weird and you will not be able to solve problems that the vast majority of other programming languages can.
BobbyShaftoe
I certainly think that it's important for a language to be Turing complete. I just isn't practical, since any language that is designed to be useful for real work will end up Turing complete.
David Norman
this answer should be _the_ answer to this question, not voted down. the impracticality of non-turing-complete languages does not make turing-complete languages inherently practical!
hop
I didn't vote it down, but it's not _the_ answer to _my_ question. I should have said "the implications Turing completeness has on the required feature set of a language". And I guess I could have substituted "ability to act as universal machine" for "Turing completeness".
AShelly
Turing completeness is a sign that the language is on par with other languages when it comes to expressiveness. Of course it doesn't imply much practically as a language "useful for real work" will probably be turing complete. However, the answer doesn't relate to the question, it got my down vote.
DeletedAccount
turing completeness has _nothing_ to do whatsoever with expressiveness. what are you people smoking?
hop
Shader languages and regular expressions are both examples of languages that are not Turing complete. Both are very expressive and highly practical.
Jasper Bekkers
@Jasper, that's exactly right. Though I believe modern shader languages actually are Turing-complete, though older ones weren't. http://en.wikipedia.org/wiki/Shading_language
poolie
+8  A: 

'Turing Completeness' describes the property of being able to express any arbitrary algorithmic computation, which was the point of Turing's Machine in the first place. A language or logical system can be described as 'Turing Complete' if it has this property. From a practical perspective all general purpose programming languages - and a surprisingly large number of special purpose ones - can do this for a suitably loose definition (see below).

However, a strict definition of Turing Completeness implies infinite storage capacity, which is of course not physically possible. Given this, no physical machine can possibly be Turing Complete, but this constraint is usually relaxed (at least informally) when ascribing Turing Completeness to a programming language. One trivial test of Turing Completeness for a language is whether the language can be used to implement a Turing Machine simulator.

An example of a widespread system that is not Turing Complete is Relational Algebra, the theoretical basis behind SQL as described in Codd's paper A relational model for large shared data banks. Relational Algebra has the property of Godel Completeness, which means that it can express any computation that can be defined in terms of first-order predicate calculus (i.e. ordinary logical expressions). However, it is not Turing-Complete as it cannot express an arbitrary algorithmic computation.

Note that most if not all all practical SQL dialects extend the pure relational model with procedural constructs to the extent that they are Turing Complete by the definition as normally applied to programming languages. However, an individual SQL query by and large is not.

Some more egregious examples of Turing Complete domain-specific languages are TeX and sendmail.cf,. In the latter case there is actually a famous-ish example of someone using sendmail.cf to implement a universal Turing Machine simulator.

ConcernedOfTunbridgeWells
Lots of good information here. Don't know why your answer was at -1 when I came to it.
harms
+15  A: 

You need some form of dynamic allocation construct (malloc or cons will do) and either recursive functions or some other way of writing an infinite loop. If you have those and can do anything at all interesting, you're almost certainly Turing-complete.

The lambda calculus is equivalent in power to a Turing machine, and if you implement lambda calculus it is actually pretty fun writing lambda calculus programs. Way more fun than writing program for a Turing machine!

The only practical implication of Turing-completeness I'm aware of is that you can write programs that don't terminate. I've used a couple of special-purpose languages that guarantee termination and therefore are not Turing-complete. Sometimes it is useful to give up the extra expressive power in exchange for guaranteed termination.

Norman Ramsey
This is really not true about needing dynamic allocation. The definitive thought-experiment Turing machine just has an array of bits. One sufficiently large indexable array is enough. Obviously on top of that you can write dynamic allocation within the language if you want.
poolie
@poolie - technically the array needs to be infinite for the true definition of 'Turing Completeness'. Ability to dynamically allocate storage sort of approximates this property.
ConcernedOfTunbridgeWells
@concerned, If you're going to insist on "infinite", then you need the ability to malloc infinite memory too, and no practical system actually allows that. But we still say that they are, for practical purposes, Turing-complete, as long as there is enough space to do the computation. That's why I said "sufficiently large".
poolie
A: 

If you can implement a Turing machine (as far as they can be implemented, as they're mathematical constructs with unlimited memory [the tape size is infinte]) then you can be sure it's Turing complete.

Some indications:

  • You can check memory and manipulate it based on the current value as well as using it to control program flow.
  • That memory can be allocated memory, strings which you're able to append to, a stack which you can allocate memory on through recursion etc.
  • Program flow can be through iteration or through selection based recursion.
DeletedAccount
+2  A: 

I cannot remember seeing anything like minimum features for Turing Completeness. However, if your language supports loops and conditional branches, the chances that it is Turing complete is good. However, the only way to prove it is still to similate a Turing Machine or another Turing Complete language.

PolyThinker
+1  A: 

I'd like to add one caveat to what Norman Ramsey said: a Turing machine has infinite memory and hence programming languages that are considered to be Turing complete are only so under the assumption that memory is also infinite.

Christian Lindig
+3  A: 

Examples of languages that are not Turing-complete frequently have bounded loops, like:

for i=1 to N {...}

but lack unbounded loops which check a more general condition, like:

while bool_expr {...}

If all possible looping constructs are bounded, your program is guaranteed to terminate. And, although an unconditional termination guarantee is potentially useful, it is also an indication that the language is not Turing-complete.

Note also that nailing down all possible looping constructs can be difficult; e.g., I'm pretty sure C++ templates were not intended to be Turing-complete...

comingstorm
+2  A: 

If you can write a Brainf$&# interpreter in your language, it is Turing-complete. LOLCODE was proved to be Turing-complete in exactly this way.

Pourquoi Litytestdata
Citation: http://forum.lolcode.com/viewtopic.php?id=51
Thomas
+1  A: 

Brainfuck is Turing complete, and has only loop structures and memory incrementation/decrementation so this is enough.

On the other hand there is no way to modify any value in the lambda calculus, but it is Turing complete, so it it is clearly possible to do it without mutable memory.

Most likely you program has nothing to do with the lambda calculus though, so for a practical answer the minimum must be

  1. A way to write to a variable
  2. A way to read to a variable
  3. A form of conditional goto (if statement, while loop, etc)
tomjen
+1  A: 

Any language capable of non-termination is pretty much Turing Complete. You can make a language non-terminating capable by giving it unbounded looping structures (Like While loops or a Goto that can reach itself again), or by giving it general recursion (by letting a function call itself without restriction.)

Once you are turing complete, you can do things like interpret other Turing Complete languages, including your own.

The real question is "what good is it?" If your language is going to be used in a specific domain to solve specific problems, it may be better to find a way to phrase the solutions in a language that is not Turing Complete, and thus guaranteed to give an answer.

You can always add Turing Completeness by writing "Do this, that, or whatever; but do it with the result provided by X" in any other Turing Complete language, where X is provided by a non-Turing complete language.

Of course, if you want to only use one language, it had probably better be Turing Complete...

Retra
A: 

You can try emulating an OISC (One Instruction-Set Computer). If you can emulate one of the instructions there, then since those single instruction can be used to compose a Turing Complete machine, then you have proven that your language must be Turing Complete as well.

Lie Ryan