Documentation

CslibFrontier.Computability.Complexity.FineGrained.PPZ

The satisfiability coding lemma and PPZ for k-SAT #

The PPZ algorithm of Paturi, Pudlák and Zane processes the variables of a CNF formula in a uniformly random order. A variable is forced if, after substituting the values already chosen, some clause becomes a unit clause on it; the algorithm then sets the variable to satisfy that clause. Otherwise it chooses the value uniformly (Cslib.Complexity.PPZ.round) Paturi, Pudlák, Zane.

Let σ be the only satisfying assignment of the formula. Along a run that agrees with σ, forced values are correct (forced_eq), so the run produces σ with probability 2^{-u}, where u is the number of unforced variables (run_apply_restrict). Flipping a variable x of σ falsifies some clause; in this critical clause the literal on x is the only one true under σ (exists_critical). If x comes after the other variables of its critical clause, then x is forced. In a uniformly random order this happens with probability 1 / m for a clause on m variables (card_isLast_mul), so for clauses of at most k literals at most (1 - 1/k) n variables are unforced on average. By the arithmetic–geometric mean inequality, one round finds σ with probability at least 2^{-(1 - 1/k) n} (round_success).

The run is defined for any oracle that proposes values for variables (runWith); PPZ uses unit clauses and PPSZ (Cslib.Complexity.PPSZ.round) uses bounded implication. The run analysis (runWith_apply_restrict, roundWith_apply_eq) and the averaging step (roundWith_apply_ge) are proved once for every oracle whose values agree with σ along runs that agree with σ.

Without uniqueness, the same argument applies to the variables I(σ) whose flips falsify the formula, and one round outputs σ with probability at least 2^{-(n - |I(σ)| / k)} (round_apply_ge). Since ∑_σ 2^{|I(σ)|} ≥ 2^n over the satisfying assignments (Cslib.BitString.two_pow_le_sum_two_pow_isolation), one round finds some satisfying assignment with probability at least 2^{-(1 - 1/k) n} (round_success_of_satisfiable).

Main definitions #

Main results #

References #

The algorithm #

def Cslib.Complexity.PPZ.IsUnitOn {n : ℕ} (τ : Fin n → Option Bool) (x : Fin n) (b : Bool) (c : Logic.PL.Clause (Fin n)) :

The clause c is a unit clause on x with polarity b under the partial assignment τ: it has a literal (x, b), every literal on x has polarity b, and τ falsifies every other literal.

Instances For
    @[instance_reducible]
    instance Cslib.Complexity.PPZ.instDecidableIsUnitOn {n : ℕ} (τ : Fin n → Option Bool) (x : Fin n) (b : Bool) (c : Logic.PL.Clause (Fin n)) :
    Decidable (IsUnitOn τ x b c)
    def Cslib.Complexity.PPZ.forced {n : ℕ} (φ : Logic.PL.CNF (Fin n)) (τ : Fin n → Option Bool) (x : Fin n) :

    The value forced on x under τ by a unit clause of φ, if any.

    noncomputable def Cslib.Complexity.PPZ.stepWith {n : ℕ} (O : (Fin n → Option Bool) → Fin n → Option Bool) (τ : Fin n → Option Bool) (x : Fin n) :

    One step on x with the oracle O: the value O τ x if there is one, and a uniform bit otherwise. PPZ uses unit clauses as the oracle (step); PPSZ uses bounded implication (Cslib.Complexity.PPSZ.step).

    noncomputable def Cslib.Complexity.PPZ.runWith {n : ℕ} (O : (Fin n → Option Bool) → Fin n → Option Bool) (π : Equiv.Perm (Fin n)) :
    ℕ → PMF (Fin n → Option Bool)

    The first i steps of a round with the oracle O in the order π: the variable π j is processed at step j.

    noncomputable def Cslib.Complexity.PPZ.roundWith {n : ℕ} (O : (Fin n → Option Bool) → Fin n → Option Bool) :
    PMF (Fin n → Option Bool)

    One round with the oracle O: process all variables in a uniformly random order.

    noncomputable def Cslib.Complexity.PPZ.step {n : ℕ} (φ : Logic.PL.CNF (Fin n)) (τ : Fin n → Option Bool) (x : Fin n) :

    One step of PPZ on x: the forced value if there is one, and a uniform bit otherwise.

    noncomputable def Cslib.Complexity.PPZ.run {n : ℕ} (φ : Logic.PL.CNF (Fin n)) (π : Equiv.Perm (Fin n)) :
    ℕ → PMF (Fin n → Option Bool)

    The first i steps of a PPZ round in the order π: the variable π j is processed at step j.

    noncomputable def Cslib.Complexity.PPZ.round {n : ℕ} (φ : Logic.PL.CNF (Fin n)) :
    PMF (Fin n → Option Bool)

    One round of PPZ: process all variables in a uniformly random order.

    theorem Cslib.Complexity.PPZ.stepWith_of_eq_some {n : ℕ} {O : (Fin n → Option Bool) → Fin n → Option Bool} {τ : Fin n → Option Bool} {x : Fin n} {b : Bool} (h : O τ x = some b) :

    A step on a variable with an oracle value sets it to that value.

    theorem Cslib.Complexity.PPZ.stepWith_of_eq_none {n : ℕ} {O : (Fin n → Option Bool) → Fin n → Option Bool} {τ : Fin n → Option Bool} {x : Fin n} (h : O τ x = none) :

    A step on a variable without an oracle value chooses a uniform bit.

    theorem Cslib.Complexity.PPZ.runWith_zero {n : ℕ} (O : (Fin n → Option Bool) → Fin n → Option Bool) (π : Equiv.Perm (Fin n)) :
    runWith O π 0 = PMF.pure fun (x : Fin n) => none

    A run of no steps assigns nothing.

    theorem Cslib.Complexity.PPZ.runWith_succ {n : ℕ} (O : (Fin n → Option Bool) → Fin n → Option Bool) (π : Equiv.Perm (Fin n)) {i : ℕ} (h : i < n) :
    runWith O π (i + 1) = (runWith O π i).bind fun (τ : Fin n → Option Bool) => PMF.map (fun (b : Bool) => Function.update τ (π ⟨i, h⟩) (some b)) (stepWith O τ (π ⟨i, h⟩))

    Step i of a run processes the variable π i.

    theorem Cslib.Complexity.PPZ.runWith_succ_of_le {n : ℕ} (O : (Fin n → Option Bool) → Fin n → Option Bool) (π : Equiv.Perm (Fin n)) {i : ℕ} (h : n ≤ i) :
    runWith O π (i + 1) = runWith O π i

    A run stops after all n variables are processed.

    Runs that agree with the solution #

    The variables processed in the first i steps of the order π.

    def Cslib.Complexity.PPZ.restrict {n : ℕ} (σ : Fin n → Bool) (D : Finset (Fin n)) :

    The restriction of σ to D.

    theorem Cslib.Complexity.PPZ.forced_eq {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {σ : Fin n → Bool} (hσ : Logic.PL.CNF.eval σ φ = true) {τ : Fin n → Option Bool} (hτ : ∀ (y : Fin n) (b : Bool), τ y = some b → σ y = b) {x : Fin n} {b : Bool} (h : forced φ τ x = some b) :
    σ x = b

    Forced values are correct. If σ satisfies φ and τ agrees with σ where defined, every value forced under τ is the value of σ.

    theorem Cslib.Complexity.PPZ.mem_prefixSet {n : ℕ} {π : Equiv.Perm (Fin n)} {i : ℕ} {x : Fin n} :
    x ∈ prefixSet π i ↔ ↑((Equiv.symm π) x) < i
    theorem Cslib.Complexity.PPZ.eq_of_restrict_eq_some {n : ℕ} {σ : Fin n → Bool} {D : Finset (Fin n)} {y : Fin n} {b : Bool} (h : restrict σ D y = some b) :
    σ y = b

    A restriction of σ agrees with σ where it is defined.

    theorem Cslib.Complexity.PPZ.restrict_prefixSet_self {n : ℕ} (σ : Fin n → Bool) (π : Equiv.Perm (Fin n)) :
    restrict σ (prefixSet π n) = fun (x : Fin n) => some (σ x)

    Once all n variables are processed, the restriction of σ is all of σ.

    theorem Cslib.Complexity.PPZ.restrict_insert {n : ℕ} (σ : Fin n → Bool) (D : Finset (Fin n)) (x : Fin n) :
    restrict σ (insert x D) = Function.update (restrict σ D) x (some (σ x))

    Restricting σ to one more variable x sets x to σ x.

    Prefixes of an order #

    theorem Cslib.Complexity.PPZ.mem_prefixSet_iff_exists {n : ℕ} {π : Equiv.Perm (Fin n)} {i : ℕ} {x : Fin n} :
    x ∈ prefixSet π i ↔ ∃ (j : Fin n), ↑j < i ∧ π j = x

    The variables processed in the first i steps are those at positions below i.

    No variable is processed in zero steps.

    All variables are processed in n steps.

    theorem Cslib.Complexity.PPZ.apply_notMem_prefixSet_self {n : ℕ} (π : Equiv.Perm (Fin n)) {i : ℕ} (hi : i < n) :
    π ⟨i, hi⟩ ∉ prefixSet π i

    The variable at position i is not processed in the first i steps.

    theorem Cslib.Complexity.PPZ.prefixSet_succ {n : ℕ} (π : Equiv.Perm (Fin n)) {i : ℕ} (hi : i < n) :
    prefixSet π (i + 1) = insert (π ⟨i, hi⟩) (prefixSet π i)

    Step i adds the variable at position i.

    theorem Cslib.Complexity.PPZ.card_prefixSet {n : ℕ} (π : Equiv.Perm (Fin n)) {i : ℕ} :
    i ≤ n → (prefixSet π i).card = i

    The first i ≤ n steps process i variables.

    def Cslib.Complexity.PPZ.EqOnPrefix {n : ℕ} (π π₀ : Equiv.Perm (Fin n)) (i : ℕ) :

    The order π agrees with π₀ on the first i positions.

    Instances For
      @[instance_reducible]
      instance Cslib.Complexity.PPZ.instDecidableEqOnPrefix {n : ℕ} (π π₀ : Equiv.Perm (Fin n)) (i : ℕ) :
      Decidable (EqOnPrefix π π₀ i)

      Agreement on a prefix is decidable.

      theorem Cslib.Complexity.PPZ.EqOnPrefix.prefixSet_eq {n : ℕ} {π π₀ : Equiv.Perm (Fin n)} {i : ℕ} (h : EqOnPrefix π π₀ i) :
      prefixSet π i = prefixSet π₀ i

      Orders that agree on the first i positions process the same variables in the first i steps.

      theorem Cslib.Complexity.PPZ.EqOnPrefix.apply_notMem_prefixSet {n : ℕ} {π π₀ : Equiv.Perm (Fin n)} {i : ℕ} (h : EqOnPrefix π π₀ i) (hi : i < n) :
      π ⟨i, hi⟩ ∉ prefixSet π₀ i

      An order that agrees with π₀ on the first i positions has at position i a variable that π₀ does not process in its first i steps.

      theorem Cslib.Complexity.PPZ.eqOnPrefix_swap_iff {n : ℕ} {π π₀ : Equiv.Perm (Fin n)} {i : ℕ} (hi : i < n) {y : Fin n} (hy : y ∉ prefixSet π₀ i) :
      EqOnPrefix π (Equiv.swap (π₀ ⟨i, hi⟩) y * π₀) (i + 1) ↔ EqOnPrefix π π₀ i ∧ π ⟨i, hi⟩ = y

      The orders that agree with π₀ on the first i positions and have y at position i are those that agree on the first i + 1 positions with π₀ followed by the swap of y with the variable of π₀ at position i.

      theorem Cslib.Complexity.PPZ.prefixSet_swap {n : ℕ} {π₀ : Equiv.Perm (Fin n)} {i : ℕ} (hi : i < n) {y : Fin n} (hy : y ∉ prefixSet π₀ i) :
      prefixSet (Equiv.swap (π₀ ⟨i, hi⟩) y * π₀) (i + 1) = insert y (prefixSet π₀ i)

      The first i + 1 steps of π₀ followed by the swap of y with the variable at position i process the first i variables of π₀ and y.

      Runs in a fixed order #

      theorem Cslib.Complexity.PPZ.eq_none_of_mem_support_runWith {n : ℕ} {O : (Fin n → Option Bool) → Fin n → Option Bool} {π : Equiv.Perm (Fin n)} {i : ℕ} {τ : Fin n → Option Bool} (hτ : τ ∈ (runWith O π i).support) {y : Fin n} (hy : y ∉ prefixSet π i) :
      τ y = none

      A run only assigns the variables it has processed.

      theorem Cslib.Complexity.PPZ.eq_none_of_mem_support_run {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {π : Equiv.Perm (Fin n)} {i : ℕ} {τ : Fin n → Option Bool} (hτ : τ ∈ (run φ π i).support) {y : Fin n} (hy : y ∉ prefixSet π i) :
      τ y = none

      A run of PPZ only assigns the variables it has processed.

      def Cslib.Complexity.PPZ.unforcedCountWith {n : ℕ} (O : (Fin n → Option Bool) → Fin n → Option Bool) (σ : Fin n → Bool) (π : Equiv.Perm (Fin n)) (i : ℕ) :

      The number of variables without an oracle value among the first i steps of the run with the oracle O that agrees with σ: at these steps the run chooses a uniform bit.

      def Cslib.Complexity.PPZ.unforcedCount {n : ℕ} (φ : Logic.PL.CNF (Fin n)) (σ : Fin n → Bool) (π : Equiv.Perm (Fin n)) (i : ℕ) :

      The number of unforced variables among the first i steps of a run that agrees with σ.

      theorem Cslib.Complexity.PPZ.unforcedCountWith_succ {n : ℕ} (O : (Fin n → Option Bool) → Fin n → Option Bool) (σ : Fin n → Bool) (π : Equiv.Perm (Fin n)) {i : ℕ} (h : i < n) :
      unforcedCountWith O σ π (i + 1) = unforcedCountWith O σ π i + if O (restrict σ (prefixSet π i)) (π ⟨i, h⟩) = none then 1 else 0

      Step i adds one to the count if the oracle has no value for the variable at position i.

      theorem Cslib.Complexity.PPZ.runWith_apply_restrict {n : ℕ} {O : (Fin n → Option Bool) → Fin n → Option Bool} {σ : Fin n → Bool} (hO : ∀ (τ : Fin n → Option Bool), (∀ (y : Fin n) (b : Bool), τ y = some b → σ y = b) → ∀ (x : Fin n) (b : Bool), O τ x = some b → σ x = b) (π : Equiv.Perm (Fin n)) {i : ℕ} :
      (runWith O π i) (restrict σ (prefixSet π i)) = 2⁻¹ ^ unforcedCountWith O σ π i

      A run in a fixed order produces the solution with probability 2^{-u}, after Paturi, Pudlák, Saks, Zane, Lemma 1, where u counts the variables without an oracle value along the run that agrees with σ. The oracle must be sound along σ: under every partial assignment that agrees with σ, its values are those of σ. The source draws the random bits up front and characterises the bit strings that lead to σ; here the bits are drawn during the run, and the probability is computed directly.

      theorem Cslib.Complexity.PPZ.run_apply_restrict {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {σ : Fin n → Bool} (hσ : Logic.PL.CNF.eval σ φ = true) (π : Equiv.Perm (Fin n)) {i : ℕ} :
      (run φ π i) (restrict σ (prefixSet π i)) = 2⁻¹ ^ unforcedCount φ σ π i

      A PPZ run in a fixed order produces the solution with probability 2^{-u}, where u counts the unforced variables along the run that agrees with σ.

      Averaging over the orders #

      theorem Cslib.Complexity.PPZ.roundWith_apply_eq {n : ℕ} {O : (Fin n → Option Bool) → Fin n → Option Bool} {σ : Fin n → Bool} (hO : ∀ (τ : Fin n → Option Bool), (∀ (y : Fin n) (b : Bool), τ y = some b → σ y = b) → ∀ (x : Fin n) (b : Bool), O τ x = some b → σ x = b) :
      ((roundWith O) fun (x : Fin n) => some (σ x)).toReal = ∑ π : Equiv.Perm (Fin n), (↑n.factorial)⁻¹ * (1 / 2) ^ unforcedCountWith O σ π n

      The success probability is an average over the orders, after Paturi, Pudlák, Saks, Zane, Lemma 2: for an oracle that is sound along σ, one round outputs σ with probability (1/n!) ∑_π 2^{-u(π)}, where u(π) counts the variables without an oracle value in the order π.

      theorem Cslib.Complexity.PPZ.unforcedCountWith_eq_card {n : ℕ} (O : (Fin n → Option Bool) → Fin n → Option Bool) (σ : Fin n → Bool) (π : Equiv.Perm (Fin n)) :
      unforcedCountWith O σ π n = {x : Fin n | O (restrict σ (prefixSet π ↑((Equiv.symm π) x))) x = none}.card

      The variables without an oracle value along a whole run are those whose predecessors in the order, set as in σ, give them no oracle value.

      theorem Cslib.Complexity.PPZ.roundWith_apply_ge {n : ℕ} {O : (Fin n → Option Bool) → Fin n → Option Bool} {σ : Fin n → Bool} (hO : ∀ (τ : Fin n → Option Bool), (∀ (y : Fin n) (b : Bool), τ y = some b → σ y = b) → ∀ (x : Fin n) (b : Bool), O τ x = some b → σ x = b) :
      2 ^ (-↑n + ∑ x : Fin n, ↑{π : Equiv.Perm (Fin n) | O (restrict σ (prefixSet π ↑((Equiv.symm π) x))) x ≠ none}.card / ↑n.factorial) ≤ ((roundWith O) fun (x : Fin n) => some (σ x)).toReal

      The success probability in terms of forcing probabilities, after Paturi, Pudlák, Saks, Zane, Lemma 3: for an oracle that is sound along σ, one round outputs σ with probability at least 2^{-n + ∑ₓ Pr_π[x forced]}, where Pr_π[x forced] is the fraction of the n! orders in which the values of σ on the variables before x give x an oracle value. The proof applies the arithmetic–geometric mean inequality to roundWith_apply_eq.

      Critical clauses #

      The variables of a clause.

      def Cslib.Complexity.PPZ.IsCritical {n : ℕ} (σ : Fin n → Bool) (x : Fin n) (c : Logic.PL.Clause (Fin n)) :

      c is a critical clause of x for σ: it contains x, the literals on x are true under σ, and every other literal is false under σ.

      theorem Cslib.Complexity.PPZ.exists_critical_of_flip {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {σ : Fin n → Bool} (hσ : Logic.PL.CNF.eval σ φ = true) {x : Fin n} (hflip : Logic.PL.CNF.eval (Function.update σ x !σ x) φ ≠ true) :
      ∃ c ∈ φ, IsCritical σ x c

      Critical clauses exist for every variable whose flip falsifies φ.

      theorem Cslib.Complexity.PPZ.exists_critical {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {σ : Fin n → Bool} (hσ : Logic.PL.CNF.eval σ φ = true) (huniq : ∀ (τ : Fin n → Bool), Logic.PL.CNF.eval τ φ = true → τ = σ) (x : Fin n) :
      ∃ c ∈ φ, IsCritical σ x c

      Critical clauses exist for every variable of the unique satisfying assignment: flipping the variable falsifies some clause.

      def Cslib.Complexity.PPZ.IsLast {n : ℕ} (π : Equiv.Perm (Fin n)) (S : Finset (Fin n)) (x : Fin n) :

      x comes after every other variable of S in the order π.

      Instances For
        @[instance_reducible]
        instance Cslib.Complexity.PPZ.instDecidableIsLast {n : ℕ} (π : Equiv.Perm (Fin n)) (S : Finset (Fin n)) (x : Fin n) :
        Decidable (IsLast π S x)
        theorem Cslib.Complexity.PPZ.forced_ne_none_of_isLast {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {σ : Fin n → Bool} {x : Fin n} {c : Logic.PL.Clause (Fin n)} (hc : c ∈ φ) (hcrit : IsCritical σ x c) {π : Equiv.Perm (Fin n)} (hlast : IsLast π (vars c) x) :
        forced φ (restrict σ (prefixSet π ↑((Equiv.symm π) x))) x ≠ none

        A variable that comes last in its critical clause is forced.

        Random orders #

        theorem Cslib.Complexity.PPZ.card_isLast_mul {n : ℕ} {S : Finset (Fin n)} {x : Fin n} (hx : x ∈ S) :
        {π : Equiv.Perm (Fin n) | IsLast π S x}.card * S.card = n.factorial

        Each variable of S comes last in a 1 / |S| fraction of the orders.

        The success probability #

        theorem Cslib.Complexity.PPZ.unforcedCount_le {n : ℕ} {φ : Logic.PL.CNF (Fin n)} {σ : Fin n → Bool} {I : Finset (Fin n)} {C : Fin n → Logic.PL.Clause (Fin n)} (hC : ∀ x ∈ I, C x ∈ φ ∧ IsCritical σ x (C x)) (π : Equiv.Perm (Fin n)) :
        unforcedCount φ σ π n ≤ {x : Fin n | ¬(x ∈ I ∧ IsLast π (vars (C x)) x)}.card

        With critical clauses C for the variables of I, the unforced variables of a run that agrees with σ are among the variables that are not in I or do not come last in their critical clause.

        theorem Cslib.Complexity.PPZ.round_apply_ge {n k : ℕ} (hk : 1 ≤ k) {φ : Logic.PL.CNF (Fin n)} {σ : Fin n → Bool} (hσ : Logic.PL.CNF.eval σ φ = true) {I : Finset (Fin n)} (hI : ∀ x ∈ I, Logic.PL.CNF.eval (Function.update σ x !σ x) φ ≠ true) (hlen : ∀ c ∈ φ, List.length c ≤ k) :
        2 ^ (-(↑n - ↑I.card / ↑k)) ≤ ((round φ) fun (x : Fin n) => some (σ x)).toReal

        One satisfying assignment. Let σ satisfy a CNF formula on n variables whose clauses have at most k ≥ 1 literals, and let I be a set of variables whose flips falsify the formula. Then one round of PPZ outputs σ with probability at least 2^{-(n - |I| / k)}: each variable of I comes last in its critical clause, and is then forced, in at least a 1 / k fraction of the orders.

        theorem Cslib.Complexity.PPZ.round_success {n k : ℕ} (hk : 1 ≤ k) {φ : Logic.PL.CNF (Fin n)} {σ : Fin n → Bool} (hσ : Logic.PL.CNF.eval σ φ = true) (huniq : ∀ (τ : Fin n → Bool), Logic.PL.CNF.eval τ φ = true → τ = σ) (hlen : ∀ c ∈ φ, List.length c ≤ k) :
        2 ^ (-((1 - 1 / ↑k) * ↑n)) ≤ ((round φ) fun (x : Fin n) => some (σ x)).toReal

        The PPZ algorithm for unique k-SAT Paturi, Pudlák, Zane: if σ is the only satisfying assignment of a CNF formula on n variables whose clauses have at most k ≥ 1 literals, one round of PPZ outputs σ with probability at least 2^{-(1 - 1/k) n}.

        theorem Cslib.Complexity.PPZ.round_success_of_satisfiable {n k : ℕ} (hk : 1 ≤ k) {φ : Logic.PL.CNF (Fin n)} (hsat : φ.Satisfiable) (hlen : ∀ c ∈ φ, List.length c ≤ k) :
        2 ^ (-((1 - 1 / ↑k) * ↑n)) ≤ ((round φ).toOuterMeasure {τ : Fin n → Option Bool | ∃ (σ : Fin n → Bool), Logic.PL.CNF.eval σ φ = true ∧ τ = fun (x : Fin n) => some (σ x)}).toReal

        The PPZ algorithm for k-SAT Paturi, Pudlák, Zane: for every satisfiable CNF formula on n variables whose clauses have at most k ≥ 1 literals, one round of PPZ outputs a satisfying assignment with probability at least 2^{-(1 - 1/k) n}. Each satisfying assignment σ is output with probability at least 2^{-(n - I(σ)/k)}, where I(σ) counts the variables whose flips falsify the formula, and ∑_σ 2^{I(σ) - n} ≥ 1 (Cslib.BitString.two_pow_le_sum_two_pow_isolation).