The P versus NP problem stands as the foundational open question in theoretical computer science, structural complexity theory, and mathematical logic. Proposed by Stephen Cook (1971) and Leonid Levin (1973), it queries whether every decision problem whose affirmative answers can be verified in polynomial time can also be solved in polynomial time:
This repository provides a theoretical reference framework paired with an empirical laboratory analyzing structural complexity foundations, non-relativizing proof barriers, and average-case phase transitions in random
Let
A DTM is defined as a 7-tuple
The complexity class P is defined as:
where
An NDTM replaces the transition function with a relation
The complexity class NP can be formulated via two equivalent definitions:
- Non-Deterministic Time:
-
Polynomial-Time Verifier:
A language
$L \in NP$ if and only if there exists a deterministic verifier$V$ and a polynomial$p(n)$ such that:
where
+-------------------------------------------------------------+
| POLYNOMIAL HIERARCHY |
| |
| +-----------------------------------------------------+ |
| | PSPACE | |
| | +---------------------------------------------+ | |
| | | NP | | |
| | | +-------------------------------------+ | | |
| | | | P | | | |
| | | | [SAT in NP-C] | | | |
| | | +-------------------------------------+ | | |
| | +---------------------------------------------+ | |
| +-----------------------------------------------------+ |
+-------------------------------------------------------------+
A language $A \subseteq \Sigma^$ is Karp-reducible to $B \subseteq \Sigma^$, denoted
A language
-
$B \in NP$ , and -
$\forall A \in NP, \quad A \le_p B$ (NP-hardness).
For any
Satisfiability of
Three major formal barrier theorems demonstrate why standard mathematical techniques fail to resolve
+-------------------------------------------------------------------------+
| THE THREE COMPLEXITY BARRIERS |
+-------------------------------------------------------------------------+
| 1. Relativization (Baker, Gill, Solovay 1975) |
| -> Oracle-independent diagonalization cannot resolve P vs NP. |
+-------------------------------------------------------------------------+
| 2. Natural Proofs (Razborov, Rudich 1997) |
| -> Circuit lower bounds using Constructivity + Largeness violate PRGs.|
+-------------------------------------------------------------------------+
| 3. Algebrization (Aaronson, Wigderson 2008) |
| -> Algebraic oracle extensions invalidate arithmetization proofs. |
+-------------------------------------------------------------------------+
Theorem (Baker, Gill, Solovay, 1975): There exist oracle sets
Implication: Techniques that relativize (remain invariant under oracle access) cannot resolve the problem. This rules out standard diagonalizations.
Theorem (Razborov & Rudich, 1997): Let
-
Largeness:
$|C_n| / |\mathcal{F}_n| \ge 2^{-c n}$ for constant$c \ge 0$ . -
Constructivity: Deciding
$f \in C_n$ is computable in$2^{O(n)}$ time.
Statement: If strong pseudorandom function generators exist, no Natural Property can prove super-polynomial circuit lower bounds for functions in NP.
Theorem (Aaronson & Wigderson, 2008): For low-degree polynomial extensions
Implication: Non-relativizing techniques based on arithmetization (e.g.,
Average-case hardness in random
Consider a random 3-CNF formula
In the limit
For 3-SAT, cavity method derivations and mathematical bounds fix the critical point at:
For general
As
-
Unclustered Phase (
$\alpha < 3.86$ ): Solutions form a single convex-like cluster. Search is linear$O(n)$ . -
Clustering / 1RSB Phase (
$3.86 \le \alpha < 4.267$ ): Solutions shatter into exponentially many isolated clusters. -
Rigidity / Frozen Phase (
$\alpha \approx 4.25$ ): Variables freeze into fixed truth values; search runtime scales exponentially$O(2^{\gamma n})$ . -
UNSAT Phase (
$\alpha > 4.267$ ): The solution space disappears.
Mulmuley and Sohoni (2001) reformulate algebraic separations (e.g.,
Conditional lower bounds rely on hypotheses like the Strong Exponential Time Hypothesis (SETH):
An empirical engine is provided to observe the node expansion spike and probability drop at the critical density
git clone https://github.com/your-username/p-vs-np-complexity-barriers.git
cd p-vs-np-complexity-barriers
python phase_transition.py --vars 50 --ratio-start 3.0 --ratio-end 5.5 --step 0.2import sys
import random
import time
import argparse
import json
class SATInstance:
def __init__(self, num_vars, clauses):
self.num_vars = num_vars
self.clauses = clauses
class DPLLSolver:
def __init__(self, instance):
self.num_vars = instance.num_vars
self.clauses = instance.clauses
self.node_count = 0
def solve(self):
return self._dpll(self.clauses, {}), self.node_count
def _unit_propagate(self, clauses, assignment):
updated = True
while updated:
updated = False
unit_clauses = [c for c in clauses if len(c) == 1]
if not unit_clauses:
break
for unit in unit_clauses:
lit = unit[0]
var = abs(lit)
val = lit > 0
if var in assignment:
if assignment[var] != val:
return None, None
else:
assignment[var] = val
updated = True
new_clauses = []
for c in clauses:
satisfied = False
new_c = []
for lit in c:
var = abs(lit)
val = lit > 0
if var in assignment:
if assignment[var] == val:
satisfied = True
break
else:
new_c.append(lit)
if not satisfied:
if not new_c:
return None, None
new_clauses.append(new_c)
clauses = new_clauses
return clauses, assignment
def _dpll(self, clauses, assignment):
self.node_count += 1
clauses, assignment = self._unit_propagate(clauses, assignment)
if clauses is None:
return False
if not clauses:
return True
unassigned = [v for v in range(1, self.num_vars + 1) if v not in assignment]
if not unassigned:
return True
var = unassigned[0]
assign_t = assignment.copy()
assign_t[var] = True
if self._dpll(clauses + [[var]], assign_t):
return True
assign_f = assignment.copy()
assign_f[var] = False
return self._dpll(clauses + [[-var]], assign_f)
def generate_random_3sat(num_vars, ratio):
num_clauses = int(round(num_vars * ratio))
clauses = []
vars_list = list(range(1, num_vars + 1))
for _ in range(num_clauses):
selected = random.sample(vars_list, 3)
clause = [v if random.random() < 0.5 else -v for v in selected]
clauses.append(clause)
return SATInstance(num_vars, clauses)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="3-SAT Phase Transition Lab")
parser.add_argument("--vars", type=int, default=40)
parser.add_argument("--ratio-start", type=float, default=3.0)
parser.add_argument("--ratio-end", type=float, default=5.5)
parser.add_argument("--step", type=float, default=0.25)
parser.add_argument("--trials", type=int, default=15)
args = parser.parse_args()
r = args.ratio_start
print(f"=== 3-SAT Phase Transition Lab (N={args.vars}) ===")
while r <= args.ratio_end:
sat_cnt, nodes_sum = 0, 0
for _ in range(args.trials):
inst = generate_random_3sat(args.vars, r)
solver = DPLLSolver(inst)
is_sat, nodes = solver.solve()
if is_sat: sat_cnt += 1
nodes_sum += nodes
print(f"Ratio: {r:.2f} | Pr[SAT]: {sat_cnt/args.trials:.2f} | Avg Nodes: {nodes_sum/args.trials:.1f}")
r += args.step- Cook, S. A. (1971). The complexity of theorem-proving procedures. STOC '71, pp. 151–158.
- Levin, L. A. (1973). Universal search problems. Problems of Information Transmission, 9(3), pp. 265–266.
- Karp, R. M. (1972). Reducibility among combinatorial problems. Complexity of Computer Computations, pp. 85–103.
- Baker, T., Gill, J., & Solovay, R. (1975). Relativizations of the P=?NP question. SIAM J. Comput., 4(4), pp. 431–442.
- Razborov, A. A., & Rudich, S. (1997). Natural proofs. JCSS, 55(1), pp. 24–35.
- Aaronson, S., & Wigderson, A. (2008). Algebrization: A new barrier in complexity theory. TOCT, 1(1), pp. 1–54.
- Ding, J., Sly, A., & Sun, N. (2015). Proof of the satisfiability conjecture for large k. STOC '15, pp. 59–68.
- Mulmuley, K. D., & Sohoni, M. (2001). Geometric complexity theory I. SIAM J. Comput., 31(2), pp. 496–526.
"If P = NP, then we would live in a world where every beautiful poem could be written by a machine as easily as it is read by a person." — Scott Aaronson
Released under the MIT License.