Documentation

CslibFrontier.Logics.Propositional.MaxSAT

Weighted partial MaxSAT and propositional translations #

A weighted partial MaxSAT instance (Cslib.Logic.PL.MaxSAT) pairs hard clauses hard : CNF V with weighted soft clauses soft : List (Clause V × ℕ) (repeated soft clauses are counted with their multiplicity). An assignment is feasible when it satisfies hard, and its cost is the sum of weights of falsified soft clauses. The optimum (MaxSAT.optimum) is the least cost of a feasible assignment in WithTop ℕ, or ⊤ when the hard clauses are unsatisfiable. Equivalently, MaxSAT.maxSatisfiedWeight gives the maximum weight of simultaneously satisfied soft clauses in WithBot ℕ.

For arbitrary propositions (Cslib.Logic.PL.PropMaxSAT), the Tseitin translation (PropMaxSAT.toTseitin) and positive-polarity Plaisted–Greenbaum translation (PropMaxSAT.toPlaistedGreenbaum) produce clausal weighted partial MaxSAT instances with linearly many clauses, clause width at most three, and the same optimum cost:

Main definitions #

Main results #

References #

Shared minimum-cost and branch-and-enumerate helpers #

def Cslib.Logic.PL.branchMinCost {α : Type u_1} [DecidableEq α] (feas : (α → Bool) → Bool) (cost : (α → Bool) → ℕ) :
List α → (α → Bool) → WithTop ℕ

Branch-and-enumerate minimum cost over a finite variable list vs, starting from base assignment σ.

Clausal weighted partial MaxSAT #

structure Cslib.Logic.PL.MaxSAT (V : Type u_1) :
Type u_1

A weighted partial MaxSAT instance over variable type V. Repeated soft clauses are counted with multiplicity.

  • hard : CNF V

    Clauses that must be satisfied by every feasible assignment.

  • soft : List (Clause V × ℕ)

    Soft clauses paired with non-negative integer weights.

theorem Cslib.Logic.PL.MaxSAT.ext_iff {V : Type u_1} {x y : MaxSAT V} :
x = y ↔ x.hard = y.hard ∧ x.soft = y.soft
theorem Cslib.Logic.PL.MaxSAT.ext {V : Type u_1} {x y : MaxSAT V} (hard : x.hard = y.hard) (soft : x.soft = y.soft) :
x = y
def Cslib.Logic.PL.MaxSAT.feasible {V : Type u_1} (φ : MaxSAT V) (σ : V → Bool) :

An assignment is feasible when it satisfies every hard clause.

def Cslib.Logic.PL.MaxSAT.cost {V : Type u_1} (φ : MaxSAT V) (σ : V → Bool) :

Total weight of soft clauses falsified by σ.

Total weight of all soft clauses in φ.

def Cslib.Logic.PL.MaxSAT.satisfiedWeight {V : Type u_1} (φ : MaxSAT V) (σ : V → Bool) :

Total weight of soft clauses satisfied by σ.

The underlying soft clauses as a CNF list.

def Cslib.Logic.PL.MaxSAT.vars {V : Type u_1} (φ : MaxSAT V) :

All variable occurrences appearing in the hard or soft clauses of φ.

theorem Cslib.Logic.PL.MaxSAT.cost_le_totalWeight {V : Type u_1} (φ : MaxSAT V) (σ : V → Bool) :
theorem Cslib.Logic.PL.MaxSAT.feasible_congr {V : Type u_1} {φ : MaxSAT V} {σ τ : V → Bool} (h : ∀ v ∈ φ.vars, σ v = τ v) :
φ.feasible σ ↔ φ.feasible τ
theorem Cslib.Logic.PL.MaxSAT.cost_congr {V : Type u_1} {φ : MaxSAT V} {σ τ : V → Bool} (h : ∀ v ∈ φ.vars, σ v = τ v) :
φ.cost σ = φ.cost τ
theorem Cslib.Logic.PL.MaxSAT.satisfiedWeight_congr {V : Type u_1} {φ : MaxSAT V} {σ τ : V → Bool} (h : ∀ v ∈ φ.vars, σ v = τ v) :
noncomputable def Cslib.Logic.PL.MaxSAT.optimum {V : Type u_1} (φ : MaxSAT V) :

Minimum cost among feasible assignments of φ, or ⊤ when φ.hard is unsatisfiable.

theorem Cslib.Logic.PL.MaxSAT.exists_feasible_cost_eq_optimum {V : Type u_1} {φ : MaxSAT V} (h : φ.hard.Satisfiable) :
∃ (σ : V → Bool), φ.feasible σ ∧ ↑(φ.cost σ) = φ.optimum

Attainment of the minimum: every satisfiable MaxSAT instance has a feasible assignment achieving φ.optimum.

theorem Cslib.Logic.PL.MaxSAT.exists_feasible_cost_eq_optimum_support {V : Type u_1} {φ : MaxSAT V} (h : φ.hard.Satisfiable) :
∃ (σ : V → Bool), (∀ v ∉ φ.vars, σ v = false) ∧ φ.feasible σ ∧ ↑(φ.cost σ) = φ.optimum

Finite-support attainment: when φ.hard is satisfiable, the minimum cost is achieved by an assignment that takes false on every variable outside φ.vars.

theorem Cslib.Logic.PL.MaxSAT.optimum_le_cost {V : Type u_1} {φ : MaxSAT V} {σ : V → Bool} (hσ : φ.feasible σ) :
φ.optimum ≤ ↑(φ.cost σ)
theorem Cslib.Logic.PL.MaxSAT.le_optimum_iff {V : Type u_1} {φ : MaxSAT V} {k : ℕ} :
↑k ≤ φ.optimum ↔ ∀ (σ : V → Bool), φ.feasible σ → k ≤ φ.cost σ
theorem Cslib.Logic.PL.MaxSAT.optimum_le_iff {V : Type u_1} {φ : MaxSAT V} {k : ℕ} :
φ.optimum ≤ ↑k ↔ ∃ (σ : V → Bool), φ.feasible σ ∧ φ.cost σ ≤ k
theorem Cslib.Logic.PL.MaxSAT.optimum_eq_coe_iff {V : Type u_1} {φ : MaxSAT V} {k : ℕ} :
φ.optimum = ↑k ↔ (∃ (σ : V → Bool), φ.feasible σ ∧ φ.cost σ = k) ∧ ∀ (σ : V → Bool), φ.feasible σ → k ≤ φ.cost σ
theorem Cslib.Logic.PL.MaxSAT.optimum_le_optimum_of_forall {V : Type u_1} {W : Type u_2} {φ : MaxSAT V} {ψ : MaxSAT W} (h : ∀ (τ : W → Bool), ψ.feasible τ → ∃ (σ : V → Bool), φ.feasible σ ∧ φ.cost σ ≤ ψ.cost τ) :

Decision version and maximum satisfied weight #

The cost decision problem: φ admits a feasible assignment of cost at most k.

The satisfied-weight decision problem: φ admits a feasible assignment satisfying weight at least t.

noncomputable def Cslib.Logic.PL.MaxSAT.maxSatisfiedWeight {V : Type u_1} (φ : MaxSAT V) :

Maximum weight of soft clauses simultaneously satisfied by a feasible assignment, or ⊥ when φ.hard is unsatisfiable.

theorem Cslib.Logic.PL.MaxSAT.maxSatisfiedWeight_eq_coe_iff {V : Type u_1} {φ : MaxSAT V} {t : ℕ} :
φ.maxSatisfiedWeight = ↑t ↔ (∃ (σ : V → Bool), φ.feasible σ ∧ φ.satisfiedWeight σ = t) ∧ ∀ (σ : V → Bool), φ.feasible σ → φ.satisfiedWeight σ ≤ t
theorem Cslib.Logic.PL.MaxSAT.optimum_add_maxSatisfiedWeight {V : Type u_1} {φ : MaxSAT V} (h : φ.hard.Satisfiable) :
∃ (opt : ℕ) (maxSat : ℕ), φ.optimum = ↑opt ∧ φ.maxSatisfiedWeight = ↑maxSat ∧ opt + maxSat = φ.totalWeight

Computable solver over finite variable lists #

Computable optimum for instances with decidable variable equality, suitable for decide.

Basic theory: empty soft, unweighted, relabelling, and monotonicity #

Unweighted MaxSAT view of a CNF formula: no hard clauses, each clause given unit weight.

@[simp]
theorem Cslib.Logic.PL.MaxSAT.feasible_unweighted {V : Type u_1} (φ : CNF V) (σ : V → Bool) :
theorem Cslib.Logic.PL.MaxSAT.cost_unweighted {V : Type u_1} (φ : CNF V) (σ : V → Bool) :
def Cslib.Logic.PL.MaxSAT.relabel {V : Type u_1} {W : Type u_2} (f : V → W) (φ : MaxSAT V) :

Rename all variables of a MaxSAT instance along f : V → W, reusing CNF.relabel.

@[simp]
theorem Cslib.Logic.PL.MaxSAT.feasible_relabel {V : Type u_1} {W : Type u_2} (f : V → W) (φ : MaxSAT V) (τ : W → Bool) :
(relabel f φ).feasible τ ↔ φ.feasible (τ ∘ f)
@[simp]
theorem Cslib.Logic.PL.MaxSAT.cost_relabel {V : Type u_1} {W : Type u_2} (f : V → W) (φ : MaxSAT V) (τ : W → Bool) :
(relabel f φ).cost τ = φ.cost (τ ∘ f)
@[simp]
theorem Cslib.Logic.PL.MaxSAT.satisfiedWeight_relabel {V : Type u_1} {W : Type u_2} (f : V → W) (φ : MaxSAT V) (τ : W → Bool) :
theorem Cslib.Logic.PL.MaxSAT.optimum_le_optimum_relabel {V : Type u_1} {W : Type u_2} (f : V → W) (φ : MaxSAT V) :
theorem Cslib.Logic.PL.MaxSAT.optimum_relabel {V : Type u_1} {W : Type u_2} {f : V → W} (hf : Function.Injective f) (φ : MaxSAT V) :

Relabelling along an injective variable map preserves the MaxSAT optimum.

theorem Cslib.Logic.PL.MaxSAT.cost_le_of_sublist {V : Type u_1} {φ ψ : MaxSAT V} (hs : φ.soft.Sublist ψ.soft) (σ : V → Bool) :
φ.cost σ ≤ ψ.cost σ
theorem Cslib.Logic.PL.MaxSAT.optimum_le_of_sublist {V : Type u_1} {φ ψ : MaxSAT V} (hh : ∀ c ∈ φ.hard, c ∈ ψ.hard) (hs : φ.soft.Sublist ψ.soft) :

Adding hard clauses or additional soft clauses can only increase or leave unchanged the optimum cost.

theorem Cslib.Logic.PL.MaxSAT.optimum_le_append_hard {V : Type u_1} (φ : MaxSAT V) (h' : CNF V) :
φ.optimum ≤ { hard := φ.hard ++ h', soft := φ.soft }.optimum
theorem Cslib.Logic.PL.MaxSAT.optimum_le_append_soft {V : Type u_1} (φ : MaxSAT V) (s' : List (Clause V × ℕ)) :
φ.optimum ≤ { hard := φ.hard, soft := φ.soft ++ s' }.optimum

Propositional weighted partial MaxSAT and Tseitin / Plaisted–Greenbaum translations #

structure Cslib.Logic.PL.PropMaxSAT (Atom : Type u_1) :
Type u_1

A weighted partial MaxSAT instance over arbitrary propositions.

  • hard : List (Proposition Atom)

    Propositions that must evaluate to true under every feasible assignment.

  • soft : List (Proposition Atom × ℕ)

    Soft propositions paired with non-negative integer weights.

theorem Cslib.Logic.PL.PropMaxSAT.ext {Atom : Type u_1} {x y : PropMaxSAT Atom} (hard : x.hard = y.hard) (soft : x.soft = y.soft) :
x = y
theorem Cslib.Logic.PL.PropMaxSAT.ext_iff {Atom : Type u_1} {x y : PropMaxSAT Atom} :
x = y ↔ x.hard = y.hard ∧ x.soft = y.soft

All hard and soft propositions of ψ.

Sum of syntactic sizes of all hard and soft propositions of ψ.

def Cslib.Logic.PL.PropMaxSAT.atoms {Atom : Type u_1} (ψ : PropMaxSAT Atom) :
List Atom

All atom occurrences appearing in ψ.

def Cslib.Logic.PL.PropMaxSAT.feasible {Atom : Type u_1} (ψ : PropMaxSAT Atom) (v : Atom → Bool) :

An atom valuation is feasible when every hard proposition holds.

def Cslib.Logic.PL.PropMaxSAT.cost {Atom : Type u_1} (ψ : PropMaxSAT Atom) (v : Atom → Bool) :

Total weight of soft propositions falsified by v.

Total weight of all soft propositions in ψ.

def Cslib.Logic.PL.PropMaxSAT.satisfiedWeight {Atom : Type u_1} (ψ : PropMaxSAT Atom) (v : Atom → Bool) :

Total weight of soft propositions satisfied by v.

theorem Cslib.Logic.PL.PropMaxSAT.feasible_congr {Atom : Type u_1} {ψ : PropMaxSAT Atom} {v w : Atom → Bool} (h : ∀ x ∈ ψ.atoms, v x = w x) :
theorem Cslib.Logic.PL.PropMaxSAT.cost_congr {Atom : Type u_1} {ψ : PropMaxSAT Atom} {v w : Atom → Bool} (h : ∀ x ∈ ψ.atoms, v x = w x) :
ψ.cost v = ψ.cost w
noncomputable def Cslib.Logic.PL.PropMaxSAT.optimum {Atom : Type u_1} (ψ : PropMaxSAT Atom) :

Minimum cost among feasible atom valuations of ψ, or ⊤ when ψ.hard is unsatisfiable.

theorem Cslib.Logic.PL.PropMaxSAT.optimum_eq_top_iff {Atom : Type u_1} (ψ : PropMaxSAT Atom) :
ψ.optimum = ⊤ ↔ ¬∃ (v : Atom → Bool), ψ.feasible v
theorem Cslib.Logic.PL.PropMaxSAT.optimum_ne_top_iff {Atom : Type u_1} (ψ : PropMaxSAT Atom) :
ψ.optimum ≠ ⊤ ↔ ∃ (v : Atom → Bool), ψ.feasible v
theorem Cslib.Logic.PL.PropMaxSAT.exists_feasible_cost_eq_optimum {Atom : Type u_1} {ψ : PropMaxSAT Atom} (h : ∃ (v : Atom → Bool), ψ.feasible v) :
∃ (v : Atom → Bool), ψ.feasible v ∧ ↑(ψ.cost v) = ψ.optimum
theorem Cslib.Logic.PL.PropMaxSAT.optimum_le_cost {Atom : Type u_1} {ψ : PropMaxSAT Atom} {v : Atom → Bool} (hv : ψ.feasible v) :
ψ.optimum ≤ ↑(ψ.cost v)
theorem Cslib.Logic.PL.PropMaxSAT.le_optimum_iff {Atom : Type u_1} {ψ : PropMaxSAT Atom} {k : ℕ} :
↑k ≤ ψ.optimum ↔ ∀ (v : Atom → Bool), ψ.feasible v → k ≤ ψ.cost v

Computable optimum for propositional MaxSAT instances over atoms with decidable equality.

Tseitin translation #

def Cslib.Logic.PL.PropMaxSAT.toTseitin {Atom : Type u_1} (ψ : PropMaxSAT Atom) :
MaxSAT (Atom ⊕ Proposition Atom)

The Tseitin translation of ψ into a clausal weighted partial MaxSAT instance: hard definitional clauses for every hard and soft proposition, unit hard clauses for ψ.hard, and unit soft clauses for ψ.soft preserving weights.

theorem Cslib.Logic.PL.PropMaxSAT.feasible_of_feasible_toTseitin {Atom : Type u_1} {ψ : PropMaxSAT Atom} {σ : Atom ⊕ Proposition Atom → Bool} (hσ : ψ.toTseitin.feasible σ) :
theorem Cslib.Logic.PL.PropMaxSAT.cost_toTseitin_eq {Atom : Type u_1} {ψ : PropMaxSAT Atom} {σ : Atom ⊕ Proposition Atom → Bool} (hσ : ψ.toTseitin.feasible σ) :
ψ.toTseitin.cost σ = ψ.cost (σ ∘ Sum.inl)
theorem Cslib.Logic.PL.PropMaxSAT.eq_tseitinExtend_of_feasible_toTseitin {Atom : Type u_1} {ψ : PropMaxSAT Atom} {σ : Atom ⊕ Proposition Atom → Bool} (hσ : ψ.toTseitin.feasible σ) {y : Atom ⊕ Proposition Atom} (hy : y ∈ ψ.toTseitin.vars) :

Under a feasible assignment for ψ.toTseitin, every variable appearing in ψ.toTseitin carries the value assigned by Proposition.tseitinExtend to its atom restriction.

theorem Cslib.Logic.PL.PropMaxSAT.eq_of_feasible_toTseitin {Atom : Type u_1} {ψ : PropMaxSAT Atom} {σ τ : Atom ⊕ Proposition Atom → Bool} (hσ : ψ.toTseitin.feasible σ) (hτ : ψ.toTseitin.feasible τ) (hatoms : σ ∘ Sum.inl = τ ∘ Sum.inl) {y : Atom ⊕ Proposition Atom} (hy : y ∈ ψ.toTseitin.vars) :
σ y = τ y

Feasible assignments for ψ.toTseitin are uniquely determined on the variables of ψ.toTseitin by their restriction to the atoms.

The Tseitin translation preserves the MaxSAT optimum.

Plaisted–Greenbaum translation #

The positive-polarity Plaisted–Greenbaum translation of ψ into a clausal weighted partial MaxSAT instance.

Under a feasible assignment for ψ.toPlaistedGreenbaum, the cost of its atom restriction never exceeds the cost of the translated assignment.

The Plaisted–Greenbaum translation preserves the MaxSAT optimum.

theorem Cslib.Logic.PL.PropMaxSAT.not_forall_eq_of_feasible_toPlaistedGreenbaum {Atom : Type u_1} [Nonempty Atom] :
¬∀ (ψ : PropMaxSAT Atom) (σ τ : Atom ⊕ Proposition Atom → Bool), ψ.toPlaistedGreenbaum.feasible σ → ψ.toPlaistedGreenbaum.feasible τ → σ ∘ Sum.inl = τ ∘ Sum.inl → ∀ y ∈ ψ.toPlaistedGreenbaum.vars, σ y = τ y

Unlike PropMaxSAT.toTseitin, feasible assignments for PropMaxSAT.toPlaistedGreenbaum are not uniquely determined by their restriction to atoms even on all variables of the translation.