4

I want to show that $Primes \in NP$ an I've seen multiple proofs that use facts from number theory, like this one.

But isn't it much easier to proof $$Composites=\{x\in \mathbb{N}\cup\{0\}:x=1 \vee\exists p,q>1: x=pq\} \in NP$$ first and then doing a polynomial reduction on $Primes$?

Because I can make a simple Turin-Machine Verifier that goes like this...

TM M on input $(n, (p,q))$

  • Check if $1<p,q<n$
  • Check if $n=1$ or $n=pq$
  • Check if $n\geq 1$
  • If all the checks above are true, then accept. Else decline.

All the number specifications are clearly polynomial, multiplication is also polynomial $\Rightarrow Composites \in NP$

Now I want to find a polynomial reduction i.e. $Primes \leq_p Composites$

Clearly, $\overline{Primes}=Composites$, so we have $n \in Primes \Leftrightarrow n\notin Composites$

I define the function (Turing-Machine) $N$ on input $n$ simply as: If $n\in Primes$, decline. Else accept. (This TM runs in constant time)

Then, $n \in Primes \Leftrightarrow N(n) \in Composites$

Since $Primes \leq_p Composites$ and $Composites\in NP$ $\Rightarrow Primes\in NP$

Quotenbanane
  • 167
  • 7

3 Answers3

4

As you have stated, $Composites\in NP$ and $\overline{Primes}=Composites$.

Hence, what you proved is that $Primes\in co-NP$.

There is no easy reduction $Primes\le_p Composites$, since you will have to do the following task: given a number $n$, return another number $n'$ such that $n$ is prime if and only if $n'$ is composite.

What you did wasn't a reduction, since it didn't return a new number $n'$, but rather tried to directly build a TM for the problem. But you have to be wary that in the non-deterministic realm, you can't simply say "if some (non-deterministic) machine $M$ rejects, then [...]", since $M$ only verifies that something is true - it doesn't verify when something isn't true.

nir shahar
  • 11,753
  • 3
  • 17
  • 35
3

Here is the definition of NP:

A language $L$ is in NP if there is a polytime machine $T$ and a polynomial $p$ such that:

  • If $x \in L$ then there exists $y$ of size at most $p(|x|)$ such that $T(x,y) = 1$.
  • If $x \notin L$ then for all $y$ of size at most $p(|x|)$, $T(x,y) = 0$.

We think of $y$ as a witness.

Composites is in NP since $y$ could be a nontrivial factorization of $x$, and $T$ just checks that $y$ is indeed a factorization of $x$. Let $p$ be a polynomial such that there is always a factorization of size at most $p(|x|)$.

You're suggesting to define $S(x,y) = 1 - T(x,y)$. Let's see what this $S$ satisfies:

  • If $x$ is prime then for all $y$ of size at most $p(|x|)$, $T(x,y) = 1$.
  • If $x$ is composite then there exists $y$ of size at most $p(|x|)$ such that $T(x,y) = 0$.

This is not quite what we want in the definition of NP. In fact, the language that $S$ accepts nondeterministically is probably $\Sigma^*$, since for every $x$ we can find a non-factorization $y$.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514
1

Your reduction was polynomial in the number N. To show that Primes is in NP, you need a reduction that is polynomial in the size of N, not in the number N itself. For example, one trillion stored in binary only takes 40 bits. So you are not allowed "polynomial in one trillion" but only "polynomial in 40" to show that a number around one trillion is a prime.

gnasher729
  • 32,238
  • 36
  • 56