Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

#P, parsimonious polynomial-time reductions, #P-hardness and #P-completeness on the CookLevin machine model

Definition
NQueensComp_NPC_SharpP

by mikedeng1 · Oct 24, 2026 · Mathlib 0df444a (Lean v4.33.1)

counting-complexityp2o-batch-pfp2ap2o-gran-per-chapterp2o-plan-paperp2o-v1parsimonious-reductionsharp-p

This module adds a counting layer on top of the published CookLevin framework (multi-tape Turing machines, step-bounded polynomial time, NP verifiers).

  1. A function fff from binary strings to N\mathbb NN is in #P if there are a polynomial-time NP verifier VVV (in the sense of CookLevin.IsNPVerifier: decided by a machine within a polynomial number of steps, and accepting only certificates of length at most a polynomial in ∣x∣|x|∣x∣) such that for every input xxx
f(x)=#{w∈{0,1}∗:V(x,w)=true}.f(x)=\#\{w\in\{0,1\}^* : V(x,w)=\mathrm{true}\}.f(x)=#{w∈{0,1}∗:V(x,w)=true}.
  1. A parsimonious reduction from fff to ggg is a map RRR on binary strings, computable in polynomial time (CookLevin.IsPolyTimeComputable), with f(x)=g(R(x))f(x)=g(R(x))f(x)=g(R(x)) for every xxx.
  2. ggg is #P-hard if every f∈#Pf\in\#\mathrm Pf∈#P parsimoniously reduces to ggg, and #P-complete if moreover g∈#Pg\in\#\mathrm Pg∈#P.

The paper (p. 819) proves #P-completeness through "a sequence of parsimonious reductions as described by Papadimitriou (1994, Chapter 18)": maps that preserve the number of solutions exactly and are computable in polynomial time. These definitions make that notion precise; hardness under parsimonious reductions implies hardness under polynomial-time Turing reductions.

Formalization Note Because the verifier's certificates have bounded length, the set of accepted certificates is finite and Set.ncard is its true size. The reduction must be polynomial-time computable; without that requirement every counting function would reduce to any counting function that is onto N\mathbb NN.

Definition code
import Mathlib
import Definitions.Def_CookLevin_Complexity

namespace NQueensComp.NPC

/-- `f ∈ #P` (Valiant; Papadimitriou 1994, Ch. 18): `f` counts the accepted certificates of a
polynomial-time NP verifier on the published CookLevin machine model.  `IsNPVerifier` bounds the
length of every accepted certificate by a polynomial in `|x|`, so the set below is finite and its
`ncard` is the true number of accepted certificates. -/
def InSharpP (f : List Bool → ℕ) : Prop :=
  ∃ (V : List Bool → List Bool → Bool) (c d : ℕ),
    CookLevin.IsNPVerifier c d V ∧
      ∀ x : List Bool, f x = _root_.Set.ncard {w : List Bool | V x w = true}

/-- A parsimonious reduction from the counting function `f` to the counting function `g`: a map
`R` computable in polynomial time (on the CookLevin model) with `f x = g (R x)` for every input
string `x`, i.e. the number of solutions is exactly preserved (p. 819). -/
def ParsimoniousReducible (f g : List Bool → ℕ) : Prop :=
  ∃ R : List Bool → List Bool, CookLevin.IsPolyTimeComputable R ∧ ∀ x : List Bool, f x = g (R x)

/-- `g` is #P-hard: every function in #P parsimoniously reduces to it. -/
def SharpPHard (g : List Bool → ℕ) : Prop :=
  ∀ f : List Bool → ℕ, InSharpP f → ParsimoniousReducible f g

/-- `g` is #P-complete: it is in #P and #P-hard under parsimonious polynomial-time reductions. -/
def SharpPComplete (g : List Bool → ℕ) : Prop :=
  InSharpP g ∧ SharpPHard g

end NQueensComp.NPC
Source
Gent, Jefferson & Nightingale, Complexity of n-Queens Completion, J. Artif. Intell. Res. 59 (2017), p. 819, §3 (parsimonious reductions, after Papadimitriou 1994, Ch. 18)
Human review
  • Endorsed by Shuze Chen · Nov 8, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Nov 8, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me