Prove whether this language is decidable or undecidable - computation-theory

So I am reviewing my notes for this problem, and I cant seem to understand how this problem works. Say we have M, and M accepts an input that makes it visit every non-halting state.
I convinced myself that this problem is decidable, but I am having trouble proving so. A rough outline of my answer would be : Assume we have a TM T that has only one halting state, and if it wants to go through all the states it needs to pass through this halt state and we somehow need to show how they cycle through all the states as such.
Any help would be beneficial, thanks!

I think you'll find the answer is actually that it's undecidable. Why? Well this would let you solve the halting problem.
You are given a TM M and an input x and an oracle Q for the problem you describe. Can we solve the halting problem for M with input x using oracle Q?
First, we connect a new TM N to the front of M. Here's what N does:
- deletes the tape contents
- writes x onto the tape
M halts on x iff NM halts on all inputs. This should be easy to see since N leaves the tape exactly as M would have seen if the input had been x. We can design N in such a way that all states of N are visited.
Now, modify M into M' by adding a second tape. The second tape will be used to keep track of the highest-numbered state of M' we have visited. Add transitions to M' which read the nth state from the secondary tape and cause M' to transition to the (n+1)st state. The transition from the highest-numbered state of M' should return to the initial state of M' and write something like "finished" on the secondary tape. When M' sees "finished" on the secondary tape, it behaves just like M did and only considers the primary tape.
So M' does exactly what M' does, except that it first visits all the states of M and then resets after which it behaves just like M.
M' halts on x iff M halts on x. Also NM' halts iff M halts on x.
Finally we're ready for the proof. The oracle Q accepts NM' iff M halts on x. Q accepts NM' if NM' accepts an input y that causes NM' to visit all states. But:
- all inputs y cause NM' to visit all states (since all states of N are visited by construction, and all states of M' are visited by modification of M); so Q is really just answering the question "does NM' accept any strings?"
- NM' erases y from the input tape, writes x and hands it off to M'. So the input y doesn't matter; if NM' accepts any input, it accepts all of them. And it accepts all of them if M' accepts x.
- M' accepts the same language as M.
So Q applied to NM' does indeed tell us if M halts on x. Then Q solves the halting problem.

Related

How to demonstrate a set is decidible, semi-decidible or not semi-decidible?

I have been asked to prove if the following set is decidible, semi-decidible or not semi-decidible:
In other words, it is the set of inputs such that exists a Turing Machine encoded with the natural y with input p that returns its input.
Consider the set K as the set of naturals such that the Turing machine encoded with x and input x stops. This is demonstrated to be a non-decidible set.
I think that what I need is to find a reduction of K to L, but I don't know how to prove that L is decidible, semi-decidible or not semi-decidible.
L may not look decidable at first glance, because there is this nasty unbounded quantifier included, which seems to make necessary a possibly infinite search when you look for a y satisfying the condition for a specific p.
However, the answer is much simpler: There is a turing machine M which always returns its input, i.e. M(p) = p holds for all p in the considered language. Let y be a code of M. Then you can use this same y for all p, showing that L contains all words of the language. Hence L is of course decidable.
In fact, this is an example to demonstrate the principle of extensionality (if two sets have the same elements and one is decidable, then the other is decidable too, even if it doesn't look so).

Show that the language L = {w ∈ {0, 1} ∗ | Mw(x) ↓ for an input x} is partially decidable but not decidable

I am trying to prove that the language L = {w ∈ {0, 1} ∗ | Mw(x) ↓ for an input x} is partially decidable but not decidable. Mw is an encoding of M, thus the language L is such that all encodings of machine M halt on some input x.
I have two ideas:
reduce this to the halting problem using some decider TM
use Post's Theorem and somehow prove that the complement of L is undecidable but L is partially decidable
However, I'm having trouble deciding which of these two would actually be correct and how to write it with correct notation. Can anyone offer some hints?
This answer assumes that L is the language of all representations of Turing machines which halt on some input.
First, this language must be semi-decidable, or recursively enumerable, because we can enumerate Turing-machine encodings that halt on some input. To accomplish this, begin enumerating all binary strings. At each stage, begin a new TM which begins simulating execution of the machine encoded by the string just generated on all possible inputs. Continue on so that all possible TM encodings are being simulated on all possible inputs. Dovetail the executions of these machines so that each one gets its next time quantum within finite time so that every possible input is simulated on every possible TM in finite time. If any of the simulations ever halt, then we print out the encoding that halted on the input and we can stop simulating that encoding. This must eventually print out any encoding in the language, so the language is enumerated. This means we can answer the question, "is this TM in the language?" for any provided TM given that the answer is yes (since we will eventually encounter it).
Second, the language cannot be decidable, or recursive, because this gives us a clear method of deciding the halting problem: ask whether the TM in question in in the language, and get a yes or no answer back as to whether it halts on some input. We can always modify the TM of interest so that it can only possibly halt on whatever input is of interest and then feed it into our decider if we have a specific input in mind.
Third, these facts imply that the language is not co-recursively enumerable, since its being both recursively enumerable and co-recursively enumerable would imply it is recursive, which is not the case.

Why is co-P = P

More specifically why is there a TM that accepts and halts for any complement language in P?
I understand, that there is a TM that rejects a language L from P, but why must there be a TM that accepts the complement of L?
Simple solution: Let L be the original language with Turing Machine M that accepts the language L. To compute L-complement, create a new machine M' such that M' is the same as M, except we switch all transitions to the accept state of M to a "reject state", and all transitions to a reject state (or a "malformed transition") to the accept state.
The running time for M' is the same as the running time for M. It will accept/reject exactly when M rejects/accepts.
A commenter asked if I could provide intuition for why this does not work for NP vs co-NP. It helps here to start with the Cook-Levin definition of a language L being in NP, which allows a clear definition of a language L' being in co-NP. (Using the definition based on Non-deterministic Turing machines makes the definition of co-NP a bit harder)
In the Cook-Levin definition, a language L is in NP, if we have a "verifying" Turing Machine V such that for all strings S in L, there is a polynomially-length bounded certificate string C such that V accepts the pair (S, C) (think of V either as a two-tape input machine, or else think of it as accepting the encoding of the pair of inputs). In addition of course, we have the requirement that V complete the verification in polynomial time.
As an example, for the 3SAT language, the strings S would be 3SAT problem instance statements, and the certificate C would be the truth-assignments to the variables. The verifier V would look at the truth-assignments and check if each clause of the 3SAT problem instance is verified with that truth assignment.
So put succinctly for a language L in NP is described by its verifying Turing machine V, and we say that:
So to describe the complement language, L' we have:
If we wanted to 'try the same trick' for NP vs co-NP as we did for P vs co-P, the opportunity does not really present itself well. We either need to try this for a deterministic Turing machine that completely solves the language for every instance (and will probably not have a polynomial-time running bound), or we need to see if we can make it work by applying the trick to V. If we simply swap around the results for the verifying machine V, we still need to check every possible certificate C to see if a given string S is truly not accepted by V.

Prove that all P problems except {} and {a,b}* are complete

It is easy to say that {} and {a,b}* are not P complete because other problems in P can't be reduced to these because {} can't accept anything and {a,b}* cannot reject anything. So, proper mapping can't be done with a reduction function.
But I'm stuck with proving that every other problem in P is P-complete.
You have to be careful when talking about P-completeness because this means different things to different people based on what type of reductions you're allowing. I'm going to assume that you're talking about using polynomial-time reductions. In that case, choose any language L ∈ P other than ∅ or {a, b}*. Now pick any language M in P that you like. Here's a silly reduction from M to L:
Given an input string w, decide whether w in M in polynomial time (this is possible because M ∈ P.)
If w ∈ M, output any string w ∈ L that you'd like (at least one exists because L is nonempty.)
Otherwise, w ∉ M, so output any string w ∉ L that you'd like (at least one exists, because L isn't {a, b}*.
This reduction takes polynomial time because each step takes polynomial time, so it's a polynomial-time reduction from an arbitrary P language to L. Therefore, L is P-complete with respect to polynomial-time reductions.
Generally speaking, when you talk about notions of completeness, you have to make sure that your reductions are given fewer computational resources than the class of solvers that you're using, or you can do weird things like what's described here that make reductions essentially useless.

Part of the theorem: "A language is Turing-recognizable if and only if some enumerator enumerates it"

I need help to understand this proof.
"First we show that if we have an enumerator E that enumerates a
language A, a TM M recognizes A. The TM M works in the following way.
PROOF M = "On input w:
1.Run E. Every time that E outputs a string, compare it with w.
If w ever appears in the output of E, accept."
Clearly, M accepts those strings that appear on E's list. "
If w doesn't appear in the output of E it doesn't appear in the E's list.
What is he triyng to say?
You have to prove both parts since it includes "if and only if" phrase.
First, you should show that if there exists an enumerator E which enumerates all strings in the language L, we can construct a recognizer for this language L.
This recognizer works with an input w ( a string ) and runs the E inside. E is an enumerator which generates all strings in L one by one. If the input string is equal to one of these generated strings then ACCEPT. If this language is infinite, then the recognizer may not halt, which is not a problem for a recognizer since it is not a decider.
Second part is, if L is Turing recognizable then there must be a Turing Machine M that recognizes L. An enumerator can be constructed as follows;
for k=1,2,3...
Run M on w1,w2,w3... in parallelized for k steps
if M accepts any of the wi then print wi on the printer.
The reason why we run them in parallelized with limited steps is the same reason why we prefer depth-limited search over depth-first search. It can go through an infinite dead path on the search graph.
Your theorem has two directions: if the "if" and the "only if". The proof is for the "if" direction.
Assuming you have an enumerator E for a language L, can you construct a Turing machine M that recognizes L? Yes, you can. Just define a Turing machine M that, on input string w, checks to see if w is ever in the output of E (which may be infinite). If it is, accept. If it isn't reject.
Since E is an enumerator for L, for any w in L, E eventually outputs w before halting (if it ever halts). Thus, M halts for every string in L. If w is not in L, either M never halts, or M rejects w.
Also, for M to be a decider, not just a recognizer for L, M must always halt.

Resources