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

前端 未结 13 2038
礼貌的吻别
礼貌的吻别 2020-12-22 19:22

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.

<
相关标签:
13条回答
  • 2020-12-22 19:43

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

    0 讨论(0)
  • 2020-12-22 19:43

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

    0 讨论(0)
  • 2020-12-22 19:44

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

    0 讨论(0)
  • 2020-12-22 19:45

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

    0 讨论(0)
  • 2020-12-22 19:47

    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.
    0 讨论(0)
  • 2020-12-22 19:48

    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)
    0 讨论(0)
提交回复
热议问题