# Why isn't coNP = NP? [duplicate]

This question already has an answer here:

I am having trouble understanding the class $coNP$. We defined

$$coNP = \left\{ \overline{A} : A \in NP \right\}$$

As far as I know, a language $A$ is in $NP$ if, and only if, a non-deterministic turing machine $M$ exists, which outputs $1$ if $w \in A$ and $0$ if $w \notin A$. But if this is true, then a turing machine $M'$ must exist which simulates $M$ and inverts the output:

$$M' = \begin{cases}0 \text{ if } M = 1\\1 \text{ if } M = 0\end{cases}$$

Therefore, $w \in A \implies w \notin L(M')$ and $w \notin A \implies w \in L(M')$, meaning that $L(M') = \overline{L(M)}$.

As $M'$ works in non-deterministic polynomial time, $L(M') \in NP$, and as $L(M') = \overline{L(M)}$, $\overline{L(M)} \in NP$, but $\overline{L(M)} \in coNP$ as well. As this holds true for all languages in $NP$, why isn't $coNP = NP$?

## marked as duplicate by David Richerby, Yuval Filmus, cody, Raphael♦Jun 5 '17 at 14:44

• take a problem from NP and check your arguments. – miracle173 Jun 5 '17 at 11:15
• @miracle173 Let's look at $CLIQUE$. $\overline{CLIQUE}$ is the set of all tuples $(G,n)$ for which no clique exists within $G$ with at least $n$ nodes. $M$ exists and outputs $1$ if such a clique exists, $0$ otherwise. Let $M'$ be a non-deterministic turing machine which outputs $0$ if such a clique exists, $1$ otherwise. $M'$ works in polynomial time and decides the language $\overline{CLIQUE}$, so $\overline{CLIQUE} \in NP$, right? – just.kidding Jun 5 '17 at 11:27
• You have to be more careful with your use of the definition of NP. – Raphael Jun 5 '17 at 14:45
• sorry, I was offline. Can you state this NP problem (the clique problem)? Can you describe the nondeterministic algorithm that solves this NP problem? – miracle173 Jun 5 '17 at 18:58

A problem in NP can be solved quickly if the answer is YES. Your inverted Turing machine finds the answer quickly if the answer to the original question is YES and the answer to the inverted question is NO. You need an answer quickly if the answer to the inverted question is YES and to the original is NO, and you don't have that.

Edit: Take for example the "Travelling Salesman" problem. I give you a list of cities to visit and ask you "is there a tour to visit them all that is at most 957 miles"? If the answer is YES then there is such a tour, so all your nondeterministic TM has to do is take such a tour and verify in polynomial time that it is indeed 957 miles or shorter. You only need to check one tour (the right one) to prove the answer is YES. If the answer is NO then you have to check all possible tours and see that none is short enough. Proving the answer is NO is a lot, lot harder.

• Oh, so polynomial time only corresponds to the output of YES? If $w \notin A$, then $M$ can take exponential time even though $A \in NP$? – just.kidding Jun 5 '17 at 13:43
• I think this is quite misleading. "A problem is NP can be solved quickly is the answer is YES" -- this seem to imply the existence of a deterministic algorithm, which can output YES quickly on the instances of our problem, and require more time for NO. This is wrong -- if we had that, we could easily leverage the time bound for YES and turn it into a polynomial decider, where the OP's argument would apply. From the OP's comment above, they have been indeed mislead into this wrong interpretation. – chi Jun 6 '17 at 8:43
• But isn't there a NTM which runs in polynomial time and finds the shortest path through all nodes of the graph by always taking the correct path? – just.kidding Jun 6 '17 at 9:08