18

Is there a known, explicit example of an algorithm with the property such that if $P\neq NP$ then this algorithm doesn't run in polynomial time and if $P=NP$ then it does run in polynomial time?

jwodder
  • 103
  • 2
user2925716
  • 317
  • 1
  • 7
  • 9
    Sort of. If P = NP, Levin’s universal search algorithm runs in polynomial time on accepting instances https://en.wikipedia.org/wiki/P_versus_NP_problem#Polynomial-time_algorithms – Emil Jeřábek Oct 19 '18 at 16:29
  • @Emil: if P=NP then also P=coNP, so can't you simultaneously do Levin search on the complement of your language, thus giving a truly poly time algorithm on all instances? – Joshua Grochow Oct 21 '18 at 02:12
  • 3
    @JoshuaGrochow In order to express the language as coNP, I would need first to know the polytime algorithm for NP, defeating the whole purpose. – Emil Jeřábek Oct 21 '18 at 09:45

1 Answers1

17

If you assume that $P=^?NP$ is provable in PA (or ZFC), a trivial example is the following:

Input: N   (integer in binary format)
For I = 1 to N do
begin
  if I is a valid encoding of a proof of P = NP in PA (or ZFC)
    then halt and accept
End
Reject

Another - less trivial - example that relies on no assumption is the following:

Input: x   (boolean formula)
Find the minimum i such that
  1) |M_i| < log(log(|x|))  [ M_1,M_2,... is a standard fixed TM enumeration] 
  2) and  M_i solves SAT correctly 
       on all formulas |y| < log(log(|x|))
          halting in no more than |y|^|M_i| steps
          [ checkable in polynomial time w.r.t. |x| ]
  if such i exists simulate M_i on input x 
      until it stops and accept/reject according to its output
      or until it reaches 2^|x| steps and in this case reject;
  if such i doesn't exist loop for 2^|x| steps and reject.

If $P =NP$ the algorithm will soon or later - suppose on input $x_0$ - find the index of the polynomial time Turing machine (or a padded version of it) $M_{SAT}$ that solves SAT in $O( |x| ^ { |M_{SAT}| })$ and for all inputs greater than $x_0$ will continue to simulate it and halt in polynomial time (note that step 2 can also be checked in polynomial time). In other words if $P = NP$ the algorithm solves SAT in polynomial time on all but a finite number of instances.

If $P \neq NP$ the algorithm runs in exponential time.

Marzio De Biasi
  • 22,915
  • 2
  • 58
  • 127
  • How do I quicly decide if "I is a valid encoding of a proof of P = NP in PA (or ZFC)" ? – user2925716 Oct 19 '18 at 17:03
  • @user2925716 You can do it in polynomial time (imagine that $I$ is a string that represents the full proof in any reasonable deduction system). – Marzio De Biasi Oct 19 '18 at 18:00
  • 2
    Tall assumption. – Jirka Hanika Oct 19 '18 at 19:24
  • This runs in polynomial time in either case. – Joshua Oct 19 '18 at 19:51
  • @Joshua: why? If P<>NP the algorithm will never find a proof so it will loop between 1 and N on every input (notice that the input is in binary so it's length is $log_2(N)$) – Marzio De Biasi Oct 19 '18 at 19:56
  • Oh that makes it worse. It's O(1) if P=NP and O(2^N) otherwise, but we can trivially fix it to O(1) on either side if we assume P=?NP is not independent of axioms. – Joshua Oct 19 '18 at 20:05
  • 1
    If P≠NP, the runtime of the unconditional algorithm is superpolynomial (as requested), but if NP is only very slightly superpolynomial, not exponential. We can change the algorithm to make it i.o.-exponential, but provably making it exponential (as opposed to just i.o.-exponential) if P≠NP is likely as hard as solving P=NP. – Dmytro Taranovsky Oct 20 '18 at 03:42
  • Are there no "practical" examples, that is algorithms that may actually be used rather then ones deliberately contrived to show the point? – Nathaniel Bubis Oct 21 '18 at 06:57
  • @DmytroTaranovsky: a clarification, what is i.o.-exponential ? – Marzio De Biasi Oct 22 '18 at 10:24
  • The claim that the second algorithm runs in exponential time if $P\ne NP$ is unjustified, and most likely wrong. For example, assume that $P\ne NP$, but $NP\subseteq P/o(n)$. Then for any $n=|x|$, there exists a TM $M_i$ of length $|M_i|<\log\log|x|$ that computes SAT correctly on all inputs $|y|<\log\log|x|$, rejects all longer inputs, and does all this in time $(\log\log|x|)^c$ (independent of the length of its input). If this $M_i$ is the one picked up by the loop, the algorithm will halt (reject) in time $n+2^{O((\log\log n)^c)}=n+o(n)$ or so. Now, it is possible that the loop happens ... – Emil Jeřábek Oct 22 '18 at 13:01
  • ... to find another TM $M_j$ with $j<i$ that also works correctly on inputs $|y|<\log\log|x|$, and that happens to take an enormous time on input $x$. However, I see no guarantee for the latter behaviour, and as far as I can see, it is conceivable that the former behaviour will prevail for all or most $n$. – Emil Jeřábek Oct 22 '18 at 13:03
  • 1
    I used i.o.-exponential to mean exponential for infinitely many input sizes; i.o.-exponential can still oscillate between exponential and non-exponential as input size changes. Also, Emil Jeřábek's comment appears correct; a fix to provably get superpolynomial time (if P≠NP) is to always use at least $x^{|M_i|}$ time; and for i.o.-exponential -- at least $2^x$ each time we increase i. – Dmytro Taranovsky Oct 22 '18 at 15:19
  • @EmilJeřábek: we could check $|M_i| < \log \log \log |x|$ on $|y| < \log \log |x|$. – Marzio De Biasi Oct 22 '18 at 15:33
  • This rules out the specific scenario I brought up in my comment, but I don’t see how it would fix the actual problem. – Emil Jeřábek Oct 22 '18 at 16:58
  • Could you include in your answer your comment with correct mathjax from here? https://blog.computationalcomplexity.org/2018/10/if-pnp-then-we-have-alg-for-sat.html?showComment=1540820172336#c2698850165138217415 I haven't managed to understand it, and it's quite hard to continue the discussion on a moderated blog. – domotorp Nov 01 '18 at 15:07