## Given the encoding of a specific Turing machine, can it be decided if it will halt on a specific input? - turing-machines

### Universal Turing Machine Problems

```If I have a machine, call it machine 1, that is able to solve a problem: it's just a machine, not per se a Turing machine. It can solve one specific problem.
If this exact same problem can be solved on a Universal Turing Machine, then is my original machine, 1, a Universal Turing Machine too?
This does not hold for all problems, which is already ansered. Are there any problems which have this described property at all? If it is absolutely not true, then why?
Can someone give an example of a problem to be solved. If this problem is solved by my original machine, 1, definately makes this a Universal Turning Machine? Or does such a problem not exists? If it doesn't exists, why?
I'm very interested, but can't figure it out... Thanks.
Edit: made the question more clear.
```
```The point of the Universal Turning Machine (UTM) is that for any Turing Machine (TM) you could take that TM and create an encoding for it that describes the operation of the TM and have that encoding run on another TM.
The UTM is a TM which has an definition sufficiently powerful such that any other TM definition could be rewritten in it.
Think of the UTM as an interpreter. The TM is a specific task.
Unless the TM is also in the class of interpreters then it is not a UTM as well. (Because a UTM is also a specifically tasked TM).
So to answer your second question: if you can show that the UTM and TM are equivalent then you have shown that TM is also a UTM. To do this you need to be able to show how an encoded program for the UTM can be changed into an equivalent program for the TM.
```
```A Universal Turing Machine can solve any of a huge class of problems.
If your machine(1) can solve 1+1, that doesn't mean it can solve any of the huge class. So it may not be a Universal Turing Machine.
```
```The logicians differentiate between "sufficient" and "neccessary" conditions. Take, for example, the sentence
The sky is blue.
(let's just assume that's always true). What you know now is this:
When you look at the sky, you see the color blue.
What you don't know is this:
When you see the color blue, you're looking at the sky.
-- you might as well be looking at your neighbour's car.
In logical terms, the color blue is neccessary for the sky, but it's not sufficient.
The same is true for your case: Machine (1) does solve your problem, so it's indeed a solvable problem. Hence, being able to solve the problem is a neccessary condition for a UTM, but not a sufficient one, because a UTM must be able to solve any problem (that's solvable at all), not just this single one.
```
```A universal turing machine can solve any code that any specific turing machine can solve.
So your universal turing machine (2) can solve the problem that your original turing machine (1) was designed to solve.
Your original turing machine (1) however can solve only that exact problem and can't solve any other problem (including the "problem" of being a universal turing machine).
So no, your original turing machine is not a universal turing machine according to your description. (It might be if the you define it to, but that's kind of cheating).
```
```Can someone give an example of a problem to be solved.
Sure: Given encoded turning machine and data, what is the result :) If your machine can solve this problem, it is surely UTM.
Do you know the line of reasoning why those different problems are in NP? Like 'can i solve the 3-sat problem when I have a machine that solves the Hamiltonian problem?' You can surely use the same to answer your question.
```
```Proving the Turing completeness of a particular system is not trivial, unless you can easily show that it's equivalent/isomorphic to another system that is know to be Turing complete. So short answer: there is no simple test that you can put your machine through to check whether it is Turing complete. You have to analyze and show properties of the system as a whole.
```
```Imagine a UTM as if how would you proceed if you have to write a code(High level) for simulating the turing machine.You will require the following:
1.Array to hold the input symbols and the stuff that yiu would do on it.
2.An array(possible 2-d) to hold the transition function that you will prompt the user.
3.An algorithm that read user's inputs of transition functions and simulates it on array 1.
4.Few variables that your program will need to track its own state.
If you think in this way,if you end up getting a perfectly working code you end up with a perfect UTM.
However the catch is no matter how efficiently you code you can't stop the user from entering transition functions that can cause your code to run forever.So there will be certain problems for which UTM will fail,and then we say that for those problems we can't develop a membership testing machine.(though notice a membership verification machine is always possible)```

### How to convert a CFG to a Turing Machine

```How do I convert a CFG to a TM? I have a basic idea of how to convert a DFA to a TM, but I can't think of a way to do this one properly.
Can I get some general implementation steps on this?
```
```Construct a pushdown automata (PDA) using a standard algorithm. I won't go into details of any particular construction (a separate question would be a better place to cover that) but you can search "convert cfg to pda" and get results. One example is here.
Construct a two-tape Turing Machine from the PDA as follows:
The Turing machine reads the input tape (tape #1) left to right
The Turing machine uses the second tape as the stack, moving right when pushing and left when popping.
Construct a vanilla one-tape Turing Machine from the two-tape machine using a standard construction. The proof that one-tape and two-tape TMs are equivalent is a constructive proof and you can follow the implied algorithm to show construct a single-tape TM for the language of your CFG.
```
`Every produced word of the CFG can be written as a parse tree. If you get a string produced by the CFG these are the leafs of your parse tree. To determine whether the string is produced by the CFG you simply go from the leaves to inner nodes till the root. So the general idea is to turn around the production rules. If you can reach the root, then the string is part of the grammar. If you are at a point, where no turned production rule fits, then the word is not produced by the CFG. Note that if there are more than one possibilities you need to try all possibilities and if one works, the string is produced by the CFG. If none works, it is not.`

### Can Turing machines halt and implicitly accept strings that the Turing machine cannot handle?

```so I came across a problem that I was unsure about. For curiosity's sake, I wanted to ask:
I am pretty sure that Turing machines can implicitly reject strings that it cannot handle, but can it do the complement of that? In other words, can it implicitly accept an input that it cannot handle? I apologize if this is a stupid question, I cannot seem to find an answer to this.
```
```That's not a stupid question! I believe what is meant by "strings that it cannot handle" is actually, "strings which are not in a valid format", which I take to mean "strings that contain symbols that we don't know." (I'm going off of slide 14 of this presentation, which I found by just googling Turing 'implicitly reject').
So, if we do use that definition, then we need to simply create a Turing machine that accepts an input if it contains a symbol not in our valid set.
Yes, there are other possible interpretations of "strings that it cannot handle", but I'm fairly sure it means this. It obviously could not be a definition without constraints, or else we could define "strings that it cannot handle" as, say, "strings representing programs that halt", and we'd have solved the halting problem! (Or if you're not familiar with the halting problem, you could substitute in any NP-complete problem, really).
I think the reason that the idea of rejecting strings the Turing machine cannot handle was introduced in the first place is so that the machine can be well defined on all input. So, say, if you have a Turing machine that accepts a binary number if it's divisible by 3, but you pass in input that is not a bianry number (like, say, "apple sauce"), we can still reason about the output of the program.```

### Explanation of the Turing Machine Halting Problem

```I'm looking for a simple explanation of the halting problem for Turing machines. I know the basis of how TMs work, how they enumerate things, machine configurations, etc., but I don't have a good handle on the halting problem.
Can someone provide a good explanation of this topic?
```
```For a minute, let's ignore the world of Turing machines and just think about computer programs. This will make our reasoning less rigorous, but probably a heck of a lot easier to follow.
Consider the following task: write a program that, given a program P and an input to that program, determines whether the program will terminate when given that input. (For simplicity, we'll assume that the program doesn't ask for user input and doesn't involve randomness, so running the same program on the same input always does the same thing). Is it possible to write a program that meets this description? The answer is no. To show this, we'll use a proof by contradiction. We'll assume that, somehow, someone manages to write the program, and then show that something terrible would happen if this were the case.
Imagine that someone writes a function that looks like this:
function willHalt(program, input)
This function has the following properties:
It always returns a value.
If the function returns true, then the specified program eventually terminates (halts) when run on the specified input.
If the function returns false, then the specified program never terminates when run on the specified input (loops).
At this point we can start to be skeptical about whoever wrote this function.
Them: "Hey! I just wrote a program that can take in any program and and input, and it will tell you whether or not the program halts on that input!"
Us: "Oh really? It can take in any program? Any program at all?"
Them: "Yeah! That's what I said."
And then we give them this program:
function trickyTricky(input) {
/* Ask whether this program (named trickyTricky) is going to halt
* on its input.
*/
if (willHalt(trickyTricky, input)) {
/* If so, loop infinitely! */
while (true) { }
} else {
/* If not, do nothing and stop running! */
}
}
So let's think about what this program does.
First, imagine that this program, when given a particular input, eventually terminates when run on that input. Trace through the program carefully and see what happens then. First, it asks willHalt whether it's going to terminate, and the answer is "yes, yes it will." That means that the if statement evaluates to true... so the program then goes into an infinite loop! Oops - the program was supposed to halt, but instead it looped infinitely!
Second, imagine that this program, when given a particular input, goes into an infinite loop. Trace through the program carefully to see what happens then. First, it asks willHalt whether it's going to terminate. The answer is no, so it doesn't go into the if statement, and instead immediately finishes running. But that's not good - the program was supposed to loop infinitely, but instead it terminated!
So now we have a problem. If you really truly can write a function that tells you whether a program will halt on some input, then you can use that program to build a program that does the opposite of what it's supposed to do - and that's impossible!
The halting problem is just a mathematically rigorous way of formalizing the above idea. Instead of talking about programs, we talk about Turing machines and TM encodings. Really, though, the core idea behind the math is just what's shown above.
If you're interested, for a class I taught last year, I put together a guide to self-reference and undecidability that might give you a little bit more exposition on how this style of argument works.
```
```The halting problems asks that we determine whether or not a program, given an input, will halt (reach some final state). Turing proved that no algorithm exists that can determine this for any given program and input.
An algorithm could spend an arbitrarily long amount of time processing a program and its input, but for all programs and all inputs, the algorithm could never accurately determine whether or not the program would eventually halt. With each change of state, the next could be the last.
The halting problem is an early example of a decision problem.
Because no algorithm exists that can accurately answer 'yes, it will halt' or 'no, it will not halt' for the halting problem, it is undecidable.```

### Universal turing machine U should determine if M(x) stops

```so we have a universal turing machine U, that should determine if a turing machine M with input x will stop. The solution should be presented in pseudo code.
can someone help me a bit out, who should i solve it ?
```
```This sounds like the halting problem:
The halting problem can be stated as follows: "Given a description of an arbitrary computer program, decide whether the program finishes running or continues to run forever". This is equivalent to the problem of deciding, given a program and an input, whether the program will eventually halt when run with that input, or will run forever.
Alan Turing proved in 1936 that a general algorithm to solve the halting problem for all possible program-input pairs cannot exist. A key part of the proof was a mathematical definition of a computer and program, what became known as a Turing machine; the halting problem is undecidable over Turing machines.
So no, it's not possible.
If you want, you can probably run M on x for a while. If it stops, we know it stops. If it doesn't stop, we don't really know whether or not it stops.```