Documentation

CslibFrontier.Logics.Propositional.CSP.PartitionFunction.Properties

Algebraic laws and separator conditioning for weighted CSP partition functions #

This module extends Cslib.Logic.PL.CSP.partitionFunction over finite domains and arbitrary semirings with the algebraic identities needed by variable-elimination and separator-based algorithms:

Main definitions #

Main results #

theorem Cslib.Logic.PL.CSP.weight_congr {Rel : Type u_1} {V : Type u_2} {D : Type u_4} {R : Type u_5} [Monoid R] {wt : Rel → List D → R} {F : CSP Rel V} {σ τ : V → D} (h : ∀ v ∈ F.vars, σ v = τ v) :
weight wt F σ = weight wt F τ

Weights are invariant under assignments agreeing on every occurring variable.

@[simp]
theorem Cslib.Logic.PL.CSP.weight_nil {Rel : Type u_1} {V : Type u_2} {D : Type u_4} {R : Type u_5} [Monoid R] (wt : Rel → List D → R) (σ : V → D) :
weight wt [] σ = 1

The weight of the empty CSP is 1.

@[simp]
theorem Cslib.Logic.PL.CSP.weight_cons {Rel : Type u_1} {V : Type u_2} {D : Type u_4} {R : Type u_5} [Monoid R] (wt : Rel → List D → R) (c : Constraint Rel V) (F : CSP Rel V) (σ : V → D) :
weight wt (c :: F) σ = wt c.rel (List.map σ c.scope) * weight wt F σ

Weight of a single prepended constraint.

@[simp]
theorem Cslib.Logic.PL.CSP.weight_append {Rel : Type u_1} {V : Type u_2} {D : Type u_4} {R : Type u_5} [Monoid R] (wt : Rel → List D → R) (F₁ F₂ : CSP Rel V) (σ : V → D) :
weight wt (F₁ ++ F₂) σ = weight wt F₁ σ * weight wt F₂ σ

Weight multiplies over list append.

@[simp]
theorem Cslib.Logic.PL.CSP.weight_relabel {Rel : Type u_1} {V : Type u_2} {W : Type u_3} {D : Type u_4} {R : Type u_5} [Monoid R] (wt : Rel → List D → R) (f : V → W) (F : CSP Rel V) (σ : W → D) :
weight wt (relabel f F) σ = weight wt F (σ ∘ f)

Relabeling variables precomposes the assignment.

def Cslib.Logic.PL.CSP.partitionFunctionOn {Rel : Type u_1} {V : Type u_2} {D : Type u_4} {R : Type u_5} [Semiring R] [DecidableEq V] [Fintype D] [Inhabited D] (wt : Rel → List D → R) (F : CSP Rel V) (declared : Finset V) :
R

Weighted partition function of F over a declared variable set declared (extending assignments outside declared by default).

theorem Cslib.Logic.PL.CSP.partitionFunction_eq_partitionFunctionOn {Rel : Type u_1} {V : Type u_2} {D : Type u_4} {R : Type u_5} [Semiring R] [DecidableEq V] [Fintype D] [Inhabited D] (wt : Rel → List D → R) (F : CSP Rel V) :

The occurring-variable partition function agrees with partitionFunctionOn on F.vars.toFinset.

theorem Cslib.Logic.PL.CSP.partitionFunctionOn_boole {Rel : Type u_1} {V : Type u_2} {D : Type u_4} [DecidableEq V] [Fintype D] [Inhabited D] (sem : Rel → List D → Bool) (F : CSP Rel V) (declared : Finset V) :
partitionFunctionOn (fun (r : Rel) (w : List D) => if sem r w = true then 1 else 0) F declared = modelCountOn sem F declared

Over ℕ with 0/1 weights, partitionFunctionOn recovers modelCountOn.

theorem Cslib.Logic.PL.CSP.map_partitionFunctionOn {Rel : Type u_1} {V : Type u_2} {D : Type u_4} {R : Type u_5} {S : Type u_6} [Semiring R] [Semiring S] [DecidableEq V] [Fintype D] [Inhabited D] (f : R →+* S) (wt : Rel → List D → R) (F : CSP Rel V) (declared : Finset V) :
f (partitionFunctionOn wt F declared) = partitionFunctionOn (fun (r : Rel) (w : List D) => f (wt r w)) F declared

Semiring homomorphisms commute with partitionFunctionOn.

theorem Cslib.Logic.PL.CSP.partitionFunctionOn_nil {Rel : Type u_1} {V : Type u_2} {D : Type u_4} {R : Type u_5} [Semiring R] [DecidableEq V] [Fintype D] [Inhabited D] (wt : Rel → List D → R) (declared : Finset V) :
partitionFunctionOn wt [] declared = ↑(Fintype.card D) ^ declared.card

The partition function of the empty instance over declared counts all D-assignments.

theorem Cslib.Logic.PL.CSP.partitionFunctionOn_cons_nil {Rel : Type u_1} {V : Type u_2} {D : Type u_4} {R : Type u_5} [Semiring R] [DecidableEq V] [Fintype D] [Inhabited D] (wt : Rel → List D → R) (r : Rel) (F : CSP Rel V) (declared : Finset V) :
partitionFunctionOn wt ({ rel := r, scope := [] } :: F) declared = wt r [] * partitionFunctionOn wt F declared

Prepending a constraint with empty scope scales partitionFunctionOn by its constant weight.

def Cslib.Logic.PL.CSP.sdiffPiEquiv {V : Type u_6} {D : Type u_7} [DecidableEq V] {S T : Finset V} (hST : S ⊆ T) :
(↥T → D) ≃ (↥S → D) × (↥(T \ S) → D)

Split assignments on T into assignments on S ⊆ T and T \ S, derived from Equiv.piFinsetUnion along S ∪ (T \ S) = T.

@[simp]
theorem Cslib.Logic.PL.CSP.sdiffPiEquiv_symm_apply_left {V : Type u_6} {D : Type u_7} [DecidableEq V] {S T : Finset V} (hST : S ⊆ T) (p : (↥S → D) × (↥(T \ S) → D)) {v : V} (hvS : v ∈ S) (hvT : v ∈ T) :
(sdiffPiEquiv hST).symm p ⟨v, hvT⟩ = p.1 ⟨v, hvS⟩
@[simp]
theorem Cslib.Logic.PL.CSP.sdiffPiEquiv_symm_apply_right {V : Type u_6} {D : Type u_7} [DecidableEq V] {S T : Finset V} (hST : S ⊆ T) (p : (↥S → D) × (↥(T \ S) → D)) {v : V} (hvRest : v ∈ T \ S) (hvT : v ∈ T) :
(sdiffPiEquiv hST).symm p ⟨v, hvT⟩ = p.2 ⟨v, hvRest⟩
theorem Cslib.Logic.PL.CSP.partitionFunctionOn_eq_card_pow_mul_of_subset {Rel : Type u_1} {V : Type u_2} {D : Type u_4} {R : Type u_5} [Semiring R] [DecidableEq V] [Fintype D] [Inhabited D] (wt : Rel → List D → R) {F : CSP Rel V} {S T : Finset V} (hvars : F.vars.toFinset ⊆ S) (hST : S ⊆ T) :

Enlarging declared multiplies partitionFunctionOn by |D| ^ (T \ S).card whenever all occurring variables already lie in S.

theorem Cslib.Logic.PL.CSP.partitionFunctionOn_eq_card_pow_mul_partitionFunction {Rel : Type u_1} {V : Type u_2} {D : Type u_4} {R : Type u_5} [Semiring R] [DecidableEq V] [Fintype D] [Inhabited D] (wt : Rel → List D → R) {F : CSP Rel V} {declared : Finset V} (hvars : F.vars.toFinset ⊆ declared) :
partitionFunctionOn wt F declared = ↑(Fintype.card D) ^ (declared \ F.vars.toFinset).card * partitionFunction wt F

Over a declared set containing all occurring variables, isolated variables contribute a factor of |D| ^ (declared \ F.vars.toFinset).card.

theorem Cslib.Logic.PL.CSP.partitionFunctionOn_relabel_equiv {Rel : Type u_1} {V : Type u_2} {W : Type u_3} {D : Type u_4} {R : Type u_5} [Semiring R] [DecidableEq V] [DecidableEq W] [Fintype D] [Inhabited D] (wt : Rel → List D → R) (e : V ≃ W) (F : CSP Rel V) (declared : Finset V) :
partitionFunctionOn wt (relabel (⇑e) F) (Finset.map e.toEmbedding declared) = partitionFunctionOn wt F declared

Variable renaming via an equivalence preserves partitionFunctionOn.

theorem Cslib.Logic.PL.CSP.partitionFunction_relabel_equiv {Rel : Type u_1} {V : Type u_2} {W : Type u_3} {D : Type u_4} {R : Type u_5} [Semiring R] [DecidableEq V] [DecidableEq W] [Fintype D] [Inhabited D] (wt : Rel → List D → R) (e : V ≃ W) (F : CSP Rel V) :

Variable renaming via an equivalence preserves partitionFunction.

theorem Cslib.Logic.PL.CSP.partitionFunctionOn_denseRelabel {Rel : Type u_1} {V : Type u_2} {D : Type u_4} {R : Type u_5} [Semiring R] [DecidableEq V] [Fintype D] [Inhabited D] (wt : Rel → List D → R) (F : CSP Rel V) :

Dense variable relabeling preserves partitionFunctionOn on Finset.range F.numVars and hence equals F.partitionFunction wt.

structure Cslib.Logic.PL.CSP.PinnedRel (Rel : Type u_5) (D : Type u_6) :
Type (max u_5 u_6)

A relation symbol paired with a partial-assignment template specifying which positions of the original constraint scope were pinned (some d) or kept as free variables (none).

  • rel : Rel

    Underlying relation symbol.

  • template : List (Option D)

    Pattern of pinned domain values and remaining free slots.

Instances For
    def Cslib.Logic.PL.CSP.instDecidableEqPinnedRel.decEq {Rel✝ : Type u_5} {D✝ : Type u_6} [DecidableEq Rel✝] [DecidableEq D✝] (x✝ x✝¹ : PinnedRel Rel✝ D✝) :
    Decidable (x✝ = x✝¹)
    @[instance_reducible]
    instance Cslib.Logic.PL.CSP.instDecidableEqPinnedRel {Rel✝ : Type u_5} {D✝ : Type u_6} [DecidableEq Rel✝] [DecidableEq D✝] :
    DecidableEq (PinnedRel Rel✝ D✝)
    def Cslib.Logic.PL.CSP.instReprPinnedRel.repr {Rel✝ : Type u_5} {D✝ : Type u_6} [Repr Rel✝] [Repr D✝] :
    PinnedRel Rel✝ D✝ → ℕ → Std.Format
    @[instance_reducible]
    instance Cslib.Logic.PL.CSP.instReprPinnedRel {Rel✝ : Type u_5} {D✝ : Type u_6} [Repr Rel✝] [Repr D✝] :
    Repr (PinnedRel Rel✝ D✝)
    def Cslib.Logic.PL.CSP.fillTemplate {D : Type u_3} :
    List (Option D) → List D → List D

    Merge free argument values into the none slots of a template.

    def Cslib.Logic.PL.CSP.pinnedWeight {Rel : Type u_1} {D : Type u_3} {R : Type u_4} (wt : Rel → List D → R) (pr : PinnedRel Rel D) (xs : List D) :
    R

    Weight evaluator for conditioned constraints.

    def Cslib.Logic.PL.CSP.Constraint.restrictOn {Rel : Type u_1} {V : Type u_2} {D : Type u_3} [DecidableEq V] (S : Finset V) (α : V → D) (c : Constraint Rel V) :

    Condition one constraint by pinning all variables in S to α.

    def Cslib.Logic.PL.CSP.restrictOn {Rel : Type u_1} {V : Type u_2} {D : Type u_3} [DecidableEq V] (S : Finset V) (α : V → D) (F : CSP Rel V) :
    CSP (PinnedRel Rel D) V

    Condition every constraint in F by pinning variables in S to α.

    @[simp]
    theorem Cslib.Logic.PL.CSP.restrictOn_append {Rel : Type u_1} {V : Type u_2} {D : Type u_3} [DecidableEq V] (S : Finset V) (α : V → D) (F₁ F₂ : CSP Rel V) :
    restrictOn S α (F₁ ++ F₂) = restrictOn S α F₁ ++ restrictOn S α F₂

    Restricting over append maps cleanly across F₁ ++ F₂.

    theorem Cslib.Logic.PL.CSP.mem_vars_restrictOn {Rel : Type u_1} {V : Type u_2} {D : Type u_3} [DecidableEq V] (S : Finset V) (α : V → D) (F : CSP Rel V) (v : V) :
    v ∈ (restrictOn S α F).vars ↔ v ∈ F.vars ∧ v ∉ S

    Variables remaining in a restricted CSP are exactly the variables outside S.

    @[simp]
    theorem Cslib.Logic.PL.CSP.vars_restrictOn {Rel : Type u_1} {V : Type u_2} {D : Type u_3} [DecidableEq V] (S : Finset V) (α : V → D) (F : CSP Rel V) :

    Occurring variables of F.restrictOn S α equal F.vars.toFinset \ S.

    theorem Cslib.Logic.PL.CSP.weight_restrictOn {Rel : Type u_1} {V : Type u_2} {D : Type u_3} {R : Type u_4} [Monoid R] [DecidableEq V] (wt : Rel → List D → R) (S : Finset V) (α σ : V → D) (F : CSP Rel V) :
    weight (pinnedWeight wt) (restrictOn S α F) σ = weight wt F fun (v : V) => if v ∈ S then α v else σ v

    Weight of a restricted CSP agrees with weight of the combined assignment.

    theorem Cslib.Logic.PL.CSP.partitionFunctionOn_eq_sum_restrictOn {Rel : Type u_1} {V : Type u_2} {D : Type u_3} {R : Type u_4} [Semiring R] [DecidableEq V] [Fintype D] [Inhabited D] (wt : Rel → List D → R) (F : CSP Rel V) {S declared : Finset V} (hS : S ⊆ declared) :
    partitionFunctionOn wt F declared = ∑ α : ↥S → D, partitionFunctionOn (pinnedWeight wt) (restrictOn S (fun (v : V) => if h : v ∈ S then α ⟨v, h⟩ else default) F) (declared \ S)

    Conditioning on a subset S ⊆ declared partitions the sum over declared → D into an outer sum over S → D and inner conditioned partition functions on declared \ S.

    theorem Cslib.Logic.PL.CSP.partitionFunctionOn_append_of_disjoint {Rel : Type u_1} {V : Type u_2} {D : Type u_3} {R : Type u_4} [CommSemiring R] [DecidableEq V] [Fintype D] [Inhabited D] (wt : Rel → List D → R) {F₁ F₂ : CSP Rel V} {d₁ d₂ : Finset V} (hdisj : Disjoint d₁ d₂) (h₁ : F₁.vars.toFinset ⊆ d₁) (h₂ : F₂.vars.toFinset ⊆ d₂) :
    partitionFunctionOn wt (F₁ ++ F₂) (d₁ ∪ d₂) = partitionFunctionOn wt F₁ d₁ * partitionFunctionOn wt F₂ d₂

    Product factorization of disjoint components over a commutative semiring.

    theorem Cslib.Logic.PL.CSP.partitionFunction_append_of_disjoint {Rel : Type u_1} {V : Type u_2} {D : Type u_3} {R : Type u_4} [CommSemiring R] [DecidableEq V] [Fintype D] [Inhabited D] (wt : Rel → List D → R) {F₁ F₂ : CSP Rel V} (hdisj : Disjoint F₁.vars.toFinset F₂.vars.toFinset) :

    Disjoint occurring variable sets yield multiplicative partition functions.

    theorem Cslib.Logic.PL.CSP.restrictOn_append_partitionFunction_of_separator {Rel : Type u_1} {V : Type u_2} {D : Type u_3} {R : Type u_4} [CommSemiring R] [DecidableEq V] [Fintype D] [Inhabited D] (wt : Rel → List D → R) {S : Finset V} {F₁ F₂ : CSP Rel V} (hsep : F₁.vars.toFinset ∩ F₂.vars.toFinset ⊆ S) (α : V → D) :

    Conditioning on a separator S makes the conditioned partition functions of the two components variable-disjoint, so the conditioned partition function factorizes as a product.

    theorem Cslib.Logic.PL.CSP.partitionFunctionOn_separator {Rel : Type u_1} {V : Type u_2} {D : Type u_3} {R : Type u_4} [CommSemiring R] [DecidableEq V] [Fintype D] [Inhabited D] (wt : Rel → List D → R) {S d₁ d₂ declared : Finset V} {F₁ F₂ : CSP Rel V} (hS : S ⊆ declared) (hpart : d₁ ∪ d₂ = declared \ S) (hdisj : Disjoint d₁ d₂) (h₁ : F₁.vars.toFinset \ S ⊆ d₁) (h₂ : F₂.vars.toFinset \ S ⊆ d₂) :
    partitionFunctionOn wt (F₁ ++ F₂) declared = ∑ α : ↥S → D, have ext := fun (v : V) => if h : v ∈ S then α ⟨v, h⟩ else default; partitionFunctionOn (pinnedWeight wt) (restrictOn S ext F₁) d₁ * partitionFunctionOn (pinnedWeight wt) (restrictOn S ext F₂) d₂

    General separator conditioning over declared variables: if S ⊆ declared contains all shared variables of F₁ and F₂, and d₁ ∪ d₂ = declared \ S splits the remaining declared variables around F₁ and F₂, then partitionFunctionOn wt (F₁ ++ F₂) declared is the sum over assignments α : S → D of the product of conditioned component partition functions.

    theorem Cslib.Logic.PL.CSP.partitionFunction_separator {Rel : Type u_1} {V : Type u_2} {D : Type u_3} {R : Type u_4} [CommSemiring R] [DecidableEq V] [Fintype D] [Inhabited D] (wt : Rel → List D → R) {S : Finset V} {F₁ F₂ : CSP Rel V} (hsep : F₁.vars.toFinset ∩ F₂.vars.toFinset ⊆ S) (hS : S ⊆ (F₁ ++ F₂).vars.toFinset) :
    partitionFunction wt (F₁ ++ F₂) = ∑ α : ↥S → D, have ext := fun (v : V) => if h : v ∈ S then α ⟨v, h⟩ else default; partitionFunction (pinnedWeight wt) (restrictOn S ext F₁) * partitionFunction (pinnedWeight wt) (restrictOn S ext F₂)

    Separator conditioning on occurring variables: whenever S ⊆ (F₁ ++ F₂).vars.toFinset separates F₁ and F₂ (F₁.vars.toFinset ∩ F₂.vars.toFinset ⊆ S), summing the products of the conditioned component partition functions over S → D recovers partitionFunction wt (F₁ ++ F₂).