What are practical guidelines for evaluating a language's “Turing Completeness”?

北城余情 提交于 2019-12-18 09:59:20

问题


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 build 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".


回答1:


You need some form of dynamic allocation construct (malloc ornew 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.




回答2:


'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.




回答3:


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.




回答4:


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...




回答5:


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.




回答6:


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.




回答7:


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)



回答8:


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.




回答9:


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.



回答10:


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...




回答11:


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.




回答12:


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

Yes, you need to have flow of control conditional on data: what is often expressed as if. For example a +-*/ pocket calculator is not Turing-complete, since there is no way to express conditionals.

You also need to be able to express a jump back to an earlier point in the program, on top of which you could implement a loop. For example BPF, which forbids backwards jumps to guarantee the program will terminate, is also not Turing complete.

You need some storage that is both readable and writable and arbitrarily large. For example, a language that has only two 32-bit variables is limited in what it can compute. You have many options for how the storage is structured: memory addressed by pointers, arrays, stacks, cons cells, pure data structures, etc.

On top of these you can build every other programming language: it may not be easy or fast, but it is enough.




回答13:


...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.



来源:https://stackoverflow.com/questions/449014/what-are-practical-guidelines-for-evaluating-a-languages-turing-completeness

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!