Documentation

CslibFrontier.Logics.Propositional.CNF.Restrict

General CNF variable restriction and branching model counts #

This module develops the semantic, satisfiability, size, occurrence, and model-counting properties of single-variable restriction (Cslib.Logic.PL.CNF.restrict from Resolution.lean), list-ordered partial-assignment restriction (Cslib.Logic.PL.CNF.restrictList), and partial-map restriction (Cslib.Logic.PL.CNF.restrictBy).

Main definitions #

Main results #

Single-variable clause and formula restriction #

theorem Cslib.Logic.PL.Clause.eval_filter_ne_neg {V : Type u_1} [DecidableEq V] (σ : V → Bool) {c : Clause V} {v : V} {b : Bool} (hc : (v, b) ∉ c) :
eval σ (List.filter (fun (x : Literal V) => decide (x ≠ (v, !b))) c) = eval (Function.update σ v b) c

Filtering (v, !b) out of a clause that does not contain (v, b) computes evaluation under Function.update σ v b.

@[simp]
theorem Cslib.Logic.PL.CNF.eval_restrict {V : Type u_1} [DecidableEq V] (φ : CNF V) (v : V) (b : Bool) (σ : V → Bool) :
eval σ (φ.restrict v b) = eval (Function.update σ v b) φ

Evaluating a single-variable restriction φ.restrict v b at σ equals evaluating φ at Function.update σ v b.

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

When σ v = b, evaluating φ.restrict v b at σ agrees with evaluating φ at σ.

theorem Cslib.Logic.PL.CNF.restrict_eq_self_of_notMem_vars {V : Type u_1} [DecidableEq V] {φ : CNF V} {v : V} {b : Bool} (hv : v ∉ φ.vars) :
φ.restrict v b = φ

Restricting on a variable that does not occur in φ leaves φ unchanged.

theorem Cslib.Logic.PL.CNF.notMem_vars_restrict {V : Type u_1} [DecidableEq V] (φ : CNF V) (v : V) (b : Bool) :
v ∉ (φ.restrict v b).vars

The restricted variable does not occur in φ.restrict v b.

theorem Cslib.Logic.PL.CNF.numVars_restrict_le {V : Type u_1} [DecidableEq V] (φ : CNF V) (v : V) (b : Bool) :

Restricting a variable never increases the number of distinct occurring variables.

theorem Cslib.Logic.PL.CNF.numVars_restrict_lt {V : Type u_1} [DecidableEq V] {φ : CNF V} {v : V} {b : Bool} (hv : v ∈ φ.vars) :

Restricting an occurring variable strictly reduces CNF.numVars.

theorem Cslib.Logic.PL.CNF.exists_clause_subset_of_mem_restrict {V : Type u_1} [DecidableEq V] {φ : CNF V} {v : V} {b : Bool} {c' : Clause V} (hc' : c' ∈ φ.restrict v b) :
∃ c ∈ φ, (∀ l ∈ c', l ∈ c) ∧ List.toFinset c' ⊆ List.toFinset c ∧ List.length c' ≤ List.length c

Every clause of φ.restrict v b is a sublist-literal subset of some clause of φ of at most the same length.

theorem Cslib.Logic.PL.CNF.length_restrict_le {V : Type u_1} [DecidableEq V] (φ : CNF V) (v : V) (b : Bool) :

Restricting never increases the number of clauses.

theorem Cslib.Logic.PL.CNF.length_restrict_lt {V : Type u_1} [DecidableEq V] {φ : CNF V} {v : V} {b : Bool} {c : Clause V} (hc : c ∈ φ) (hl : (v, b) ∈ c) :

If some clause of φ contains (v, b), restricting v to b strictly decreases the number of clauses.

@[simp]
theorem Cslib.Logic.PL.CNF.occurrences_restrict_self {V : Type u_1} [DecidableEq V] (φ : CNF V) (v : V) (b : Bool) :
(φ.restrict v b).occurrences v = 0

Restricting on v removes all occurrences of v.

theorem Cslib.Logic.PL.CNF.occurrences_restrict_le {V : Type u_1} [DecidableEq V] (φ : CNF V) (v u : V) (b : Bool) :

Restricting on v does not increase the number of clauses mentioning any variable u.

Satisfiability and assignment bijections #

theorem Cslib.Logic.PL.CNF.satisfiable_restrict_iff {V : Type u_1} [DecidableEq V] (φ : CNF V) (v : V) (b : Bool) :
(φ.restrict v b).Satisfiable ↔ ∃ (σ : V → Bool), σ v = b ∧ eval σ φ = true

φ.restrict v b is satisfiable iff φ has a satisfying assignment mapping v to b.

Binary branching characterization of CNF satisfiability.

def Cslib.Logic.PL.CNF.restrictModelsEquiv {V : Type u_1} [DecidableEq V] (φ : CNF V) (declared : Finset V) {v : V} (hv : v ∈ declared) (b : Bool) :
{ σ : ↥(declared.erase v) → Bool // eval (fun (u : V) => if h : u ∈ declared.erase v then σ ⟨u, h⟩ else false) (φ.restrict v b) = true } ≃ { τ : ↥declared → Bool // eval (fun (u : V) => if h : u ∈ declared then τ ⟨u, h⟩ else false) φ = true ∧ τ ⟨v, hv⟩ = b }

Explicit bijection between satisfying assignments of φ.restrict v b on declared.erase v and satisfying assignments of φ on declared that map v to b.

def Cslib.Logic.PL.CNF.modelsSplitEquiv {V : Type u_1} [DecidableEq V] (φ : CNF V) (declared : Finset V) {v : V} (hv : v ∈ declared) :
{ σ : ↥(declared.erase v) → Bool // eval (fun (u : V) => if h : u ∈ declared.erase v then σ ⟨u, h⟩ else false) (φ.restrict v false) = true } ⊕ { σ : ↥(declared.erase v) → Bool // eval (fun (u : V) => if h : u ∈ declared.erase v then σ ⟨u, h⟩ else false) (φ.restrict v true) = true } ≃ { τ : ↥declared → Bool // eval (fun (u : V) => if h : u ∈ declared then τ ⟨u, h⟩ else false) φ = true }

Explicit disjoint sum equivalence splitting declared models of φ into those extending φ.restrict v false and those extending φ.restrict v true.

theorem Cslib.Logic.PL.CNF.restrictModelsEquiv_apply_val {V : Type u_1} [DecidableEq V] (φ : CNF V) (declared : Finset V) {v : V} (hv : v ∈ declared) (b : Bool) (σ : { σ : ↥(declared.erase v) → Bool // eval (fun (u : V) => if h : u ∈ declared.erase v then σ ⟨u, h⟩ else false) (φ.restrict v b) = true }) (u : ↥declared) :
↑((φ.restrictModelsEquiv declared hv b) σ) u = if h : ↑u = v then b else ↑σ ⟨↑u, ⋯⟩

Forward action of restrictModelsEquiv extends σ at v by b.

@[simp]
theorem Cslib.Logic.PL.CNF.restrictModelsEquiv_apply_self {V : Type u_1} [DecidableEq V] (φ : CNF V) (declared : Finset V) {v : V} (hv : v ∈ declared) (b : Bool) (σ : { σ : ↥(declared.erase v) → Bool // eval (fun (u : V) => if h : u ∈ declared.erase v then σ ⟨u, h⟩ else false) (φ.restrict v b) = true }) :
↑((φ.restrictModelsEquiv declared hv b) σ) ⟨v, hv⟩ = b

At the restricted variable v, restrictModelsEquiv yields b.

@[simp]
theorem Cslib.Logic.PL.CNF.restrictModelsEquiv_apply_ne {V : Type u_1} [DecidableEq V] (φ : CNF V) (declared : Finset V) {v : V} (hv : v ∈ declared) (b : Bool) (σ : { σ : ↥(declared.erase v) → Bool // eval (fun (u : V) => if h : u ∈ declared.erase v then σ ⟨u, h⟩ else false) (φ.restrict v b) = true }) {u : ↥declared} (hu : ↑u ≠ v) :
↑((φ.restrictModelsEquiv declared hv b) σ) u = ↑σ ⟨↑u, ⋯⟩

Off the restricted variable v, restrictModelsEquiv agrees with σ.

@[simp]
theorem Cslib.Logic.PL.CNF.restrictModelsEquiv_symm_apply_val {V : Type u_1} [DecidableEq V] (φ : CNF V) (declared : Finset V) {v : V} (hv : v ∈ declared) (b : Bool) (τ : { τ : ↥declared → Bool // eval (fun (u : V) => if h : u ∈ declared then τ ⟨u, h⟩ else false) φ = true ∧ τ ⟨v, hv⟩ = b }) (u : ↥(declared.erase v)) :
↑((φ.restrictModelsEquiv declared hv b).symm τ) u = ↑τ ⟨↑u, ⋯⟩

Inverse of restrictModelsEquiv restricts τ to declared.erase v.

@[simp]
theorem Cslib.Logic.PL.CNF.modelsSplitEquiv_inl_val {V : Type u_1} [DecidableEq V] (φ : CNF V) (declared : Finset V) {v : V} (hv : v ∈ declared) (σ : { σ : ↥(declared.erase v) → Bool // eval (fun (u : V) => if h : u ∈ declared.erase v then σ ⟨u, h⟩ else false) (φ.restrict v false) = true }) :
↑((φ.modelsSplitEquiv declared hv) (Sum.inl σ)) = ↑((φ.restrictModelsEquiv declared hv false) σ)

Left branch of modelsSplitEquiv agrees with restrictModelsEquiv ... false.

@[simp]
theorem Cslib.Logic.PL.CNF.modelsSplitEquiv_inr_val {V : Type u_1} [DecidableEq V] (φ : CNF V) (declared : Finset V) {v : V} (hv : v ∈ declared) (σ : { σ : ↥(declared.erase v) → Bool // eval (fun (u : V) => if h : u ∈ declared.erase v then σ ⟨u, h⟩ else false) (φ.restrict v true) = true }) :
↑((φ.modelsSplitEquiv declared hv) (Sum.inr σ)) = ↑((φ.restrictModelsEquiv declared hv true) σ)

Right branch of modelsSplitEquiv agrees with restrictModelsEquiv ... true.

theorem Cslib.Logic.PL.CNF.modelsSplitEquiv_symm_of_eq_false {V : Type u_1} [DecidableEq V] (φ : CNF V) (declared : Finset V) {v : V} (hv : v ∈ declared) (τ : { τ : ↥declared → Bool // eval (fun (u : V) => if h : u ∈ declared then τ ⟨u, h⟩ else false) φ = true }) (h : ↑τ ⟨v, hv⟩ = false) :
(φ.modelsSplitEquiv declared hv).symm τ = Sum.inl ((φ.restrictModelsEquiv declared hv false).symm ⟨↑τ, ⋯⟩)

Inverse of modelsSplitEquiv on an assignment setting v ↦ false.

theorem Cslib.Logic.PL.CNF.modelsSplitEquiv_symm_of_eq_true {V : Type u_1} [DecidableEq V] (φ : CNF V) (declared : Finset V) {v : V} (hv : v ∈ declared) (τ : { τ : ↥declared → Bool // eval (fun (u : V) => if h : u ∈ declared then τ ⟨u, h⟩ else false) φ = true }) (h : ↑τ ⟨v, hv⟩ = true) :
(φ.modelsSplitEquiv declared hv).symm τ = Sum.inr ((φ.restrictModelsEquiv declared hv true).symm ⟨↑τ, ⋯⟩)

Inverse of modelsSplitEquiv on an assignment setting v ↦ true.

Branching additivity for model counts #

theorem Cslib.Logic.PL.CNF.modelCountOn_eq_add_restrict {V : Type u_1} [DecidableEq V] (φ : CNF V) (declared : Finset V) {v : V} (hv : v ∈ declared) :
φ.modelCountOn declared = (φ.restrict v false).modelCountOn (declared.erase v) + (φ.restrict v true).modelCountOn (declared.erase v)

Branching additivity for declared-universe model counting: restricting v ∈ declared splits modelCountOn into the sum of false and true branches over declared.erase v.

theorem Cslib.Logic.PL.CNF.modelCountOn_eq_restrict_of_forall {V : Type u_1} [DecidableEq V] {φ : CNF V} {declared : Finset V} {v : V} (hv : v ∈ declared) {b : Bool} (hforce : ∀ (σ : V → Bool), eval σ φ = true → σ v = b) :
φ.modelCountOn declared = (φ.restrict v b).modelCountOn (declared.erase v)

When every satisfying assignment of φ maps v ∈ declared to b, restricting v ↦ b conserves modelCountOn onto declared.erase v.

theorem Cslib.Logic.PL.CNF.modelCountOn_restrict_of_notMem {V : Type u_1} [DecidableEq V] (φ : CNF V) (declared : Finset V) {v : V} (hv : v ∉ declared) :
(φ.restrict v false).modelCountOn declared = φ.modelCountOn declared

When v ∉ declared, modelCountOn fixes v ↦ false, so restricting v ↦ false leaves modelCountOn unchanged.

Branching additivity for occurring-variable CNF.modelCount on an occurring variable v, explicitly accounting for any other variables eliminated along each branch.

theorem Cslib.Logic.PL.CNF.modelCount_restrict_of_notMem_vars {V : Type u_1} [DecidableEq V] (φ : CNF V) {v : V} (hv : v ∉ φ.vars) (b : Bool) :

Restricting a non-occurring variable leaves CNF.modelCount unchanged.

Iterated list restriction and partial-map restriction #

def Cslib.Logic.PL.CNF.restrictList {V : Type u_1} [DecidableEq V] (φ : CNF V) (assign : List (Literal V)) :
CNF V

Restrict a formula sequentially along a list of literals (v, b).

@[simp]
@[simp]
theorem Cslib.Logic.PL.CNF.restrictList_cons {V : Type u_1} [DecidableEq V] (φ : CNF V) (l : Literal V) (ls : List (Literal V)) :
φ.restrictList (l :: ls) = (φ.restrict l.1 l.2).restrictList ls
def Cslib.Logic.PL.CNF.applyAssignList {V : Type u_1} [DecidableEq V] (assign : List (Literal V)) (σ : V → Bool) :
V → Bool

Update an assignment by applying a list of literals in list order (earlier entries override later ones, matching CNF.restrictList).

@[simp]
@[simp]
theorem Cslib.Logic.PL.CNF.applyAssignList_cons {V : Type u_1} [DecidableEq V] (l : Literal V) (ls : List (Literal V)) (σ : V → Bool) :
theorem Cslib.Logic.PL.CNF.eval_restrictList {V : Type u_1} [DecidableEq V] (φ : CNF V) (assign : List (Literal V)) (σ : V → Bool) :
eval σ (φ.restrictList assign) = eval (applyAssignList assign σ) φ

Evaluation of φ.restrictList assign at σ equals evaluation of φ at applyAssignList assign σ.

theorem Cslib.Logic.PL.CNF.vars_restrictList_subset {V : Type u_1} [DecidableEq V] (φ : CNF V) (assign : List (Literal V)) :

Variables remaining in φ.restrictList assign occur in φ and not in assign.

Iterated restriction does not increase the number of clauses.

theorem Cslib.Logic.PL.CNF.occurrences_restrictList_le {V : Type u_1} [DecidableEq V] (φ : CNF V) (assign : List (Literal V)) (u : V) :

Iterated restriction does not increase occurrences of any variable.

theorem Cslib.Logic.PL.CNF.occurrences_restrictList_eq_zero {V : Type u_1} [DecidableEq V] (φ : CNF V) (assign : List (Literal V)) {u : V} (hu : u ∈ List.map Prod.fst assign) :
(φ.restrictList assign).occurrences u = 0

Any variable mentioned in assign has zero occurrences in φ.restrictList assign.

theorem Cslib.Logic.PL.CNF.applyAssignList_eq_of_nodup {V : Type u_1} [DecidableEq V] {assign : List (Literal V)} (hnd : (List.map Prod.fst assign).Nodup) (σ : V → Bool) {l : Literal V} (hl : l ∈ assign) :
applyAssignList assign σ l.1 = l.2

If every assigned literal holds in assign (no conflicting assignments to the same variable), applyAssignList fixes each variable to its assigned Boolean value.

theorem Cslib.Logic.PL.CNF.satisfiable_restrictList_iff {V : Type u_1} [DecidableEq V] (φ : CNF V) {assign : List (Literal V)} (hnd : (List.map Prod.fst assign).Nodup) :
(φ.restrictList assign).Satisfiable ↔ ∃ (σ : V → Bool), (∀ l ∈ assign, σ l.1 = l.2) ∧ eval σ φ = true

Under a variable-disjoint literal list assign, satisfiability of φ.restrictList assign is equivalent to satisfiability of φ extending assign.

theorem Cslib.Logic.PL.CNF.vars_restrictBy_subset {V : Type u_1} (φ : CNF V) (ρ : V → Option Bool) (v : V) :
v ∈ (φ.restrictBy ρ).vars → v ∈ φ.vars ∧ ρ v = none

Variables remaining after CNF.restrictBy ρ belong to φ and are not fixed by ρ.

Partial-map restriction CNF.restrictBy does not increase clause count.

theorem Cslib.Logic.PL.CNF.occurrences_restrictBy_eq_zero {V : Type u_1} [DecidableEq V] (φ : CNF V) (ρ : V → Option Bool) {v : V} (hv : ρ v ≠ none) :

CNF.restrictBy ρ eliminates all occurrences of variables fixed by ρ.

theorem Cslib.Logic.PL.CNF.satisfiable_restrictBy_iff {V : Type u_1} (φ : CNF V) (ρ : V → Option Bool) :
(φ.restrictBy ρ).Satisfiable ↔ ∃ (σ : V → Bool), (∀ (v : V) (b : Bool), ρ v = some b → σ v = b) ∧ eval σ φ = true

CNF.restrictBy ρ is satisfiable iff φ has a satisfying assignment extending ρ.