Documentation

CslibFrontier.Logics.Propositional.CNF.Johnson

Johnson's algorithm for MAX-SAT #

Johnson's algorithm [Joh74] sets the variables of a CNF formula one at a time; this file formalizes it in the form obtained by derandomizing a uniformly random assignment with the method of conditional expectations Williamson and Shmoys, Sections 5.1–5.2. A clause with j distinct literals, none of them yet set, is falsified by a uniformly random assignment with probability 2 ^ -j, so the weight Σ_c 2 ^ (L - |c|) (Cslib.Logic.PL.CNF.johnsonWeight) is 2 ^ L times the expected number of falsified clauses when no clause contains a complementary pair. Setting a variable v to b drops the clauses satisfied by the literal (v, b) and deletes (v, !b) from the others; this is the restriction Cslib.Logic.PL.CNF.restrict used for resolution. The weights after setting v to true and to false sum to at most twice the current weight (Cslib.Logic.PL.CNF.johnsonWeight_restrict_add_le), with equality when no clause contains both (v, true) and (v, false). Setting each variable to the value of smaller weight is therefore the method of conditional expectations with the weight as a pessimistic estimator (Cslib.PessimisticEstimator.greedy_spec_of_add_le).

The algorithm (Cslib.Logic.PL.johnson) first removes repeated literals from each clause, then sets the variables in order of first occurrence. When no variable is left, every remaining clause is empty and contributes 2 ^ L to the weight, so 2 ^ L times the number of clauses falsified by the output is at most the initial weight (Cslib.Logic.PL.two_pow_mul_countUnsat_johnsonAssignment_le). If every clause has at least k distinct literals, the output falsifies at most 2 ^ -k of the clauses (Cslib.Logic.PL.two_pow_mul_countUnsat_johnsonAssignment_le_length). This gives the 7 / 8 guarantee for clauses with three distinct variables (Cslib.Logic.PL.CNF.IsExactThreeDistinct.eight_mul_countUnsat_johnsonAssignment_le), a constructive form of Cslib.Logic.PL.CNF.IsExactThreeDistinct.exists_countUnsat_le_div_eight, and the 1 / 2 guarantee for formulas without empty clauses (Cslib.Logic.PL.two_mul_countUnsat_johnsonAssignment_le).

The polynomial running time is proved in CslibFrontier.Logics.Propositional.CNF.Johnson.PolyTime.

Main definitions #

Main results #

References #

Repeated literals #

Remove repeated literals from a clause, keeping first occurrences.

Remove repeated literals from every clause of a formula.

Removing repeated literals leaves no repeated literals.

@[simp]

Removing repeated literals keeps every literal.

Removing repeated literals does not lengthen a clause.

After removing repeated literals, the length of a clause is its number of distinct literals.

@[simp]
theorem Cslib.Logic.PL.Clause.eval_eraseDupLits {V : Type u_1} [DecidableEq V] (σ : V → Bool) (c : Clause V) :

Removing repeated literals does not change the value of a clause.

@[simp]
theorem Cslib.Logic.PL.CNF.countUnsat_eraseDupLits {V : Type u_1} [DecidableEq V] (σ : V → Bool) (φ : CNF V) :

Removing repeated literals does not change the number of falsified clauses.

Setting a variable #

theorem Cslib.Logic.PL.CNF.restrict_cons {V : Type u_1} [DecidableEq V] (v : V) (b : Bool) (c : Clause V) (ψ : CNF V) :
restrict (c :: ψ) v b = if (v, b) ∈ c then ψ.restrict v b else List.filter (fun (x : Literal V) => decide (x ≠ (v, !b))) c :: ψ.restrict v b

Setting a variable with CNF.restrict, one clause at a time.

theorem Cslib.Logic.PL.CNF.countUnsat_restrict {V : Type u_1} [DecidableEq V] {σ : V → Bool} {v : V} {b : Bool} (hσ : σ v = b) (ψ : CNF V) :
countUnsat σ (ψ.restrict v b) = countUnsat σ ψ

Under an assignment that sets v to b, setting v to b in the formula does not change the number of falsified clauses.

Johnson's weight #

def Cslib.Logic.PL.CNF.johnsonWeight {V : Type u_1} (L : ℕ) (ψ : CNF V) :

Johnson's weight Σ_c 2 ^ (L - |c|). For clauses of length at most L without repeated literals and without complementary pairs, this is 2 ^ L times the expected number of clauses falsified by a uniformly random assignment.

@[simp]

The empty formula has weight 0.

@[simp]
theorem Cslib.Logic.PL.CNF.johnsonWeight_cons {V : Type u_1} (L : ℕ) (c : Clause V) (ψ : CNF V) :
johnsonWeight L (c :: ψ) = 2 ^ (L - List.length c) + johnsonWeight L ψ

The weight of a formula, one clause at a time.

theorem Cslib.Logic.PL.CNF.johnsonWeight_restrict_add_le {V : Type u_1} [DecidableEq V] {L : ℕ} (v : V) {ψ : CNF V} (hψ : ∀ c ∈ ψ, List.Nodup c ∧ List.length c ≤ L) :

Averaging: on clauses without repeated literals and of length at most L, setting a variable to true and to false gives weights summing to at most twice the weight.

theorem Cslib.Logic.PL.CNF.johnsonWeight_of_vars_eq_nil {V : Type u_1} {L : ℕ} {ψ : CNF V} (hψ : ∀ (v : V), v ∉ ψ.vars) (σ : V → Bool) :
johnsonWeight L ψ = 2 ^ L * countUnsat σ ψ

A formula without variables has weight 2 ^ L per clause, all of them falsified.

Johnson's algorithm #

def Cslib.Logic.PL.johnsonBranch {V : Type u_1} [DecidableEq V] (v : V) (b : Bool) (s : CNF V × List V) :
CNF V × List V

Fix v to b, recording v among the variables set to true when b is true.

def Cslib.Logic.PL.johnsonState {V : Type u_1} [DecidableEq V] (φ : CNF V) :
CNF V × List V

The final state of Johnson's algorithm: the variables of φ are fixed in order of first occurrence, each to the value giving the smaller weight.

def Cslib.Logic.PL.johnson {V : Type u_1} [DecidableEq V] (φ : CNF V) :

Johnson's algorithm: the variables set to true.

def Cslib.Logic.PL.johnsonAssignment {V : Type u_1} [DecidableEq V] (φ : CNF V) :
V → Bool

The assignment computed by Johnson's algorithm.

Correctness of Johnson's algorithm: with L the number of variable occurrences, 2 ^ L times the number of clauses that the output falsifies is at most the initial weight.

Corollaries #

theorem Cslib.Logic.PL.CNF.johnsonWeight_eraseDupLits {V : Type u_1} [DecidableEq V] (L : ℕ) (φ : CNF V) :
johnsonWeight L φ.eraseDupLits = (List.map (fun (c : Clause V) => 2 ^ (L - (List.toFinset c).card)) φ).sum

After removing repeated literals, the weight counts the distinct literals of each clause.

Johnson's bound: the output of Johnson's algorithm falsifies at most Σ_c 2 ^ -|c| clauses, where |c| is the number of distinct literals of c. This is the expected number of clauses falsified by a uniformly random assignment when no clause contains a complementary pair, and an upper bound for it otherwise.

Johnson's bound: if every clause has at least k distinct literals, Johnson's algorithm falsifies at most 2 ^ -k of the clauses.

The 7 / 8 guarantee: on an exact 3-CNF formula with three distinct variables per clause, Johnson's algorithm falsifies at most 1 / 8 of the clauses.

The 1 / 2 guarantee: on a formula without empty clauses, Johnson's algorithm falsifies at most half of the clauses.

Approximation ratios #

theorem Cslib.Logic.PL.one_sub_inv_two_pow_mul_le_johnsonAssignment {V : Type u_1} [DecidableEq V] {k : ℕ} {φ : CNF V} (hk : ∀ c ∈ φ, k ≤ (List.toFinset c).card) :
(1 - 2⁻¹ ^ k) * (1 - φ.unsatVal) ≤ 1 - ↑(CNF.countUnsat (johnsonAssignment φ) φ) / ↑(List.length φ)

Approximation ratio: if every clause has at least k distinct literals, the proportion of the clauses that Johnson's algorithm satisfies is at least 1 - 2 ^ -k times the largest proportion that an assignment satisfies, 1 - φ.unsatVal.

The 7 / 8 approximation ratio for MAX-E3SAT with three distinct variables per clause.

theorem Cslib.Logic.PL.one_div_two_mul_le_johnsonAssignment {V : Type u_1} [DecidableEq V] {φ : CNF V} (hφ : ∀ c ∈ φ, c ≠ []) :
1 / 2 * (1 - φ.unsatVal) ≤ 1 - ↑(CNF.countUnsat (johnsonAssignment φ) φ) / ↑(List.length φ)

The 1 / 2 approximation ratio for MAX-SAT on formulas without empty clauses.