ChatGPT解决这个技术问题 Extra ChatGPT

What is Turing Complete?

What does the expression "Turing Complete" mean?

Can you give a simple explanation, without going into too many theoretical details?

Some very nice links at this SO question.
...and what is not TC. Cheers~

M
Mark Harrison

Here's the briefest explanation:

A Turing Complete system means a system in which a program can be written that will find an answer (although with no guarantees regarding runtime or memory).

So, if somebody says "my new thing is Turing Complete" that means in principle (although often not in practice) it could be used to solve any computation problem.

Sometimes it's a joke... a guy wrote a Turing Machine simulator in vi, so it's possible to say that vi is the only computational engine ever needed in the world.


For further reading, see The Annotated Turing. Very approachable. amazon.com/Annotated-Turing-Through-Historic-Computability/dp/…
"often not in practice" is incorrect. No system is ever Turing-complete in practice, because no realizable system has an infinite tape. What we really mean is that some systems have the ability to approximate Turing-completeness up to the limits of their available memory.
But Vi is the only computational engine ever needed in the world... ;-)
Is Emacs a Turning Machine too? XD
Someone recently showed that PowerPoint is Turing Complete too.
P
Prithvi Boinpally

Here is the simplest explanation

Alan Turing created a machine that can take a program, run that program, and show some result. But then he had to create different machines for different programs. So he created "Universal Turing Machine" that can take ANY program and run it.

Programming languages are similar to those machines (although virtual). They take programs and run them. Now, a programing language is called "Turing complete", if it can run any program (irrespective of the language) that a Turing machine can run given enough time and memory.

For example: Let's say there is a program that takes 10 numbers and adds them. A Turing machine can easily run this program. But now imagine that for some reason your programming language can't perform the same addition. This would make it "Turing incomplete" (so to speak). On the other hand, if it can run any program that the universal Turing machine can run, then it's Turing complete.

Most modern programming languages (e.g. Java, JavaScript, Perl, etc.) are all Turing complete because they each implement all the features required to run programs like addition, multiplication, if-else condition, return statements, ways to store/retrieve/erase data and so on.

Update: You can learn more on my blog post: "JavaScript Is Turing Complete" — Explained


The idea that there would even be a term for this kind of machine makes a lot more sense when I remember Turing and other early computer scientists would build a specific machine each time they wanted to solve a specific problem. We’re used to one machine that can be forever reprogrammed. Thank you for the context, Raja.
How JavaScript can be Turing Complete? It lacks file system , proper multithreading API . It has tons of limitations, mainly due to its browser security sandbox nature. It's hardly can be called ' a programming language ' .See how many variants of scripting abstraction exist (react, typescript ..you name it) ,all that to compensate what JS doesn't have. (asm.js should be mentioned here) . Java ,Python or C++ are true 'Turing Complete ' examples. But js? I don't think so.
@MichaelIV The touring machine did not have a file system/threads either. JS is absolutely touring complete.
@MichaelIV To add to Bax's response, one could consider a modern computer to consist of several Turing machines that work together to allow for all of those nice things that you mention. E.g. the CPU produces "tape" for the GPU to read so that it can write "tape" for the monitor so that the monitor can write "tape" to the user. Likewise, the CPU could produce "tape" for the hard drives, NICs, sound cards, etc.
JS is absolutely Turing complete - but Turing completeness is a lower bar than you might be imagining. It doesn't mean it's optimal for any computation. For example: A language doesn't need to be able to multiply numbers to be turing complete if it can add numbers, loop and perform conditional statements. It's turing complete because you could write a function to multiply numbers with that other functionality.
G
Gordon Gustafson

Informal Definition

A Turing complete language is one that can perform any computation. The Church-Turing Thesis states that any performable computation can be done by a Turing machine. A Turing machine is a machine with infinite random access memory and a finite 'program' that dictates when it should read, write, and move across that memory, when it should terminate with a certain result, and what it should do next. The input to a Turing machine is put in its memory before it starts.

Things that can make a language NOT Turing complete

A Turing machine can make decisions based on what it sees in memory - The 'language' that only supports +, -, *, and / on integers is not Turing complete because it can't make a choice based on its input, but a Turing machine can.

A Turing machine can run forever - If we took Java, Javascript, or Python and removed the ability to do any sort of loop, GOTO, or function call, it wouldn't be Turing complete because it can't perform an arbitrary computation that never finishes. Coq is a theorem prover that can't express programs that don't terminate, so it's not Turing complete.

A Turing machine can use infinite memory - A language that was exactly like Java but would terminate once it used more than 4 Gigabytes of memory wouldn't be Turing complete, because a Turing machine can use infinite memory. This is why we can't actually build a Turing machine, but Java is still a Turing complete language because the Java language has no restriction preventing it from using infinite memory. This is one reason regular expressions aren't Turing complete.

A Turing machine has random access memory - A language that only lets you work with memory through push and pop operations to a stack wouldn't be Turing complete. If I have a 'language' that reads a string once and can only use memory by pushing and popping from a stack, it can tell me whether every ( in the string has its own ) later on by pushing when it sees ( and popping when it sees ). However, it can't tell me if every ( has its own ) later on and every [ has its own ] later on (note that ([)] meets this criteria but ([]] does not). A Turing machine can use its random access memory to track ()'s and []'s separately, but this language with only a stack cannot.

A Turing machine can simulate any other Turing machine - A Turing machine, when given an appropriate 'program', can take another Turing machine's 'program' and simulate it on arbitrary input. If you had a language that was forbidden from implementing a Python interpreter, it wouldn't be Turing complete.

Examples of Turing complete languages

If your language has infinite random access memory, conditional execution, and some form of repeated execution, it's probably Turing complete. There are more exotic systems that can still achieve everything a Turing machine can, which makes them Turing complete too:

Untyped lambda calculus

Conway's game of life

C++ Templates

Prolog


SQL is most definitely turing-complete. It has scripting capabilities that allow for any computation.
No, you are confusing SQL with extensions such as T-SQL / PL-SQL. ANSI SQL is not turing-complete. But TSQL / PLSQL - is.
Apparently SQL is turing-complete: stackoverflow.com/questions/900055/…
According to turing completeness - system is Turing complete if it can be used to simulate any single-taped Turing machine. But in example above as I understood devs constructed particular cyclic tag system and not universal cyclic tag system. Hence - article doesn't proves SQL turing completeness. (Or I misunderstood something)
There is no realizable implementation of a Turing-complete language, because there are no infinite tapes. What we really mean is that some languages have the ability to approximate Turing-completeness up to the limits of the available memory of the host machine.
R
Ran Biron

From wikipedia:

Turing completeness, named after Alan Turing, is significant in that every plausible design for a computing device so far advanced can be emulated by a universal Turing machine — an observation that has become known as the Church-Turing thesis. Thus, a machine that can act as a universal Turing machine can, in principle, perform any calculation that any other programmable computer is capable of. However, this has nothing to do with the effort required to write a program for the machine, the time it may take for the machine to perform the calculation, or any abilities the machine may possess that are unrelated to computation. While truly Turing-complete machines are very likely physically impossible, as they require unlimited storage, Turing completeness is often loosely attributed to physical machines or programming languages that would be universal if they had unlimited storage. All modern computers are Turing-complete in this sense.

I don't know how you can be more non-technical than that except by saying "turing complete means 'able to answer computable problem given enough time and space'".


In this context, what is a "computing device"?
As with most Wikipedia articles, although this quote is technically correct, it provides no value to a person who has no knowledge on the subject and is trying to understand it. Being able to explain things properly is a science of its own :)
C
Community

Fundamentally, Turing-completeness is one concise requirement, unbounded recursion.

Not even bounded by memory.

I thought of this independently, but here is some discussion of the assertion. My definition of LSP provides more context.

The other answers here don't directly define the fundamental essence of Turing-completeness.


Finite state automata are allowed to have unbounded recursion. Case in point: a*.
@Rhymoid FSMs have limited memory—the finite # of states)—but unbounded recursion without tail optimization must have unlimited memory. I didn't restrict my definition to the subset of unbounded recursion only with tail optimization. Kindly remove your downvote.
you kept the definition of unbounded recursion foggy. Do you mean 'recursion' in the 'primitive recursion' sense, and 'unbounded' by making it 'partial' (or 'general', or 'mu-')? Then you may be right. But your current formulation is way too close to the statements criticized in David Harel's "On Folk Theorems". It's important to be rigorous in mathematics, and by leaving precise definitions out, you're ignoring that. By the way: FSMs can be generalized to model interaction; what sets them apart from TMs is that the latter's environment is also modeled (as the tape).
@Rhymoid enumeration is the antithesis of precision, e.g. enumerate the maximum precision of the fractions of an inch. Unbounded recursion means every possible form of recursion, which is impossible without an infinite tape. Fully generalized recursion (not just general within the model) is always Turing-complete. I am stating equivalence between generalized recursion and the ability to perform any possible computation. That is an important equivalence to note.
"Unbounded recursion means every possible form of recursion" That's your reading. To most SO users, 'unbounded recursion' means while (p) { /* ... */ }. "I am stating equivalence between generalized recursion and the ability to perform any possible computation." Church's thesis is a very different matter and should really be discussed separately.
W
Waylon Flinn

Turing Complete means that it is at least as powerful as a Turing Machine. This means anything that can be computed by a Turing Machine can be computed by a Turing Complete system.

No one has yet found a system more powerful than a Turing Machine. So, for the time being, saying a system is Turing Complete is the same as saying the system is as powerful as any known computing system (see Church-Turing Thesis).


Note that all this disregards wall time. It just says "it can be done".
@ThorbjørnRavnAndersen actually, it disregards physical computability altogether. Not only could it take longer than the age of the universe, but it might also use more memory than can be constructed with all the fermions and bosons in the universe.
There is, quitte possibly, no limit to the amount of bosons and fermions in the universe. We don't know, and will probably never know, it's size. Every time you read about the number of X in 'the universe', people are actually talking about the observable universe. Though interesting, it is not an actual physical limit.
Usually by powerfull one understand "compute fast" (a concept to put beside complexity (complexity theory)), a TM is complete if it finishes (computable (computability theory)). This answer is misleading if not wrong due to the approximate or wrong wording.
S
Shelby Moore III

In the simplest terms, a Turing-complete system can solve any possible computational problem.

One of the key requirements is the scratchpad size be unbounded and that is possible to rewind to access prior writes to the scratchpad.

Thus in practice no system is Turing-complete.

Rather some systems approximate Turing-completeness by modeling unbounded memory and performing any possible computation that can fit within the system's memory.


a
alex

I think the importance of the concept "Turing Complete" is in the the ability to identify a computing machine (not necessarily a mechanical/electrical "computer") that can have its processes be deconstructed into "simple" instructions, composed of simpler and simpler instructions, that a Universal machine could interpret and then execute.

I highly recommend The Annotated Turing

@Mark i think what you are explaining is a mix between the description of the Universal Turing Machine and Turing Complete.

Something that is Turing Complete, in a practical sense, would be a machine/process/computation able to be written and represented as a program, to be executed by a Universal Machine (a desktop computer). Though it doesn't take consideration for time or storage, as mentioned by others.


G
Glenn Mohammad

Super-brief summary from what Professor Brasilford explains in this video.

Turing Complete ≅ do anything that a Turing Machine can do.

It has conditional branching (i.e. "if statement"). Also, implies "go to" and thus permitting loop. It gets arbitrary amount of memory (e.g. long enough tape) that the program needs.


K
Keith Douglas

In practical language terms familiar to most programmers, the usual way to detect Turing completeness is if the language allows or allows the simulation of nested unbounded while statements (as opposed to Pascal-style for statements, with fixed upper bounds).


A single unbounded while loop is enough to simulate a Turing machine.
2
2 revs, 2 users 97%

A Turing Machine requires that any program can perform condition testing. That is fundamental.

Consider a player piano roll. The player piano can play a highly complicated piece of music, but there is never any conditional logic in the music. It is not Turing Complete.

Conditional logic is both the power and the danger of a machine that is Turing Complete.

The piano roll is guaranteed to halt every time. There is no such guarantee for a TM. This is called the “halting problem.”


P
Patrick87

We call a language Turing-complete if and only if (1) it is decidable by a Turing machine but (2) not by anything less capable than a Turing machine. For instance, the language of palindromes over the alphabet {a, b} is decidable by Turing machines, but also by pushdown automata; so, this language is not Turing-complete. Truly Turing-complete languages - ones that require the full computing power of Turing machines - are pretty rare. Perhaps the language of strings x.y.z where x is a number, y is a Turing-machine and z is an initial tape configuration, and y halts on z in fewer than x! steps - perhaps that qualifies (though it would need to be shown!)

A common imprecise usage confuses Turing-completeness with Turing-equivalence. Turing-equivalence refers to the property of a computational system which can simulate, and which can be simulated by, Turing machines. We might say Java is a Turing-equivalent programming language, for instance, because you can write a Turing-machine simulator in Java, and because you could define a Turing machine that simulates execution of Java programs. According to the Church-Turing thesis, Turing machines can perform any effective computation, so Turing-equivalence means a system is as capable as possible (if the Church-Turing thesis is true!)

Turing equivalence is a much more mainstream concern that true Turing completeness; this and the fact that "complete" is shorter than "equivalent" may explain why "Turing-complete" is so often misused to mean Turing-equivalent, but I digress.


C
Community

As Waylon Flinn said:

Turing Complete means that it is at least as powerful as a Turing Machine.

I believe this is incorrect, a system is Turing complete if it's exactly as powerful as the Turing Machine, i.e. every computation done by the machine can be done by the system, but also every computation done by the system can be done by the Turing machine.


I think you're assuming that the Church-Turing thesis is true to arrive at this conclusion. It has yet to be proven. The property you're describing is called 'Turing Equivalent'.
@WaylonFlinn No, he's right. "Completeness" means both that it is at least as strong as a thing, but also no stronger. Compare with "NP-Complete".
@DevinJeanpierre I don't want to start a flame war here but I'm almost certain the computational class you're describing is called "Turing Equivalent". Turing Complete does bear a similar relation to NP-Complete though. NP-Complete is equal to NP if and only if P=NP. In the same way Turing Complete is equal to Turing Equivalent if and only if the Church-Turing thesis is correct.
@Waylon Source? Nothing I read agrees with that (e.g. en.wikipedia.org/wiki/Turing_completeness )
@DevinJeanpierre It says it right there in the wikipedia article you link to. Quoting the Formal definitions section: "A computational system that can compute every Turing-computable function is called Turing complete", "A Turing-complete system is called Turing equivalent if every function it can compute is also Turing computable"
A
Akshay Jain

Can a relational database input latitudes and longitudes of places and roads, and compute the shortest path between them - no. This is one problem that shows SQL is not Turing complete.

But C++ can do it, and can do any problem. Thus it is.


Being able to compute the shortest path between points is not the definition of Turing complete. There is so much more to it than just that one example.