Documentation

Complexity.Logics.Propositional.CNF.ModelCount.Declared

Counting assignments on a declared set of variables #

CNF.modelCountOn counts assignments of a supplied finite set, extending them by false outside that set. When the set contains all occurring variables, each unused variable contributes a free Boolean choice. The original occurring-variable CNF.modelCount is unchanged and is recovered by declaring exactly the occurring variables.

Renaming by positions in distinctVars gives dense natural labels below numVars. This differs from the existing compact, whose first literal-occurrence positions can have gaps. The dense renaming preserves literal order, clause lengths and the occurring-variable count.

These are elementary semantic transport facts for the declared-variable convention of the native counting development in #1226. They do not implement a counting algorithm or assert a runtime bound.

Main definitions #

Main results #

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

Count assignments of declared that satisfy the existing CNF evaluation, extending by false outside declared. To interpret this as a declared-variable formula, require that every occurring variable belongs to declared. No inhabitedness of the variable type is needed.

Instances For
    @[simp]

    Declaring exactly the occurring variables recovers the existing model count.

    @[simp]
    theorem Cslib.Logic.PL.CNF.modelCountOn_nil {V : Type u_1} [DecidableEq V] (declared : Finset V) :
    modelCountOn [] declared = 2 ^ declared.card

    Every declared variable is free in an empty formula, including when the declared set is empty.

    theorem Cslib.Logic.PL.CNF.modelCountOn_eq_zero_of_nil_mem {V : Type u_1} [DecidableEq V] {φ : CNF V} (h : [] ∈ φ) (declared : Finset V) :
    φ.modelCountOn declared = 0

    An empty clause rules out every assignment, regardless of the declared variables.

    theorem Cslib.Logic.PL.CNF.modelCountOn_eq_mul_modelCount {V : Type u_1} [DecidableEq V] (φ : CNF V) (declared : Finset V) (hvars : φ.vars.toFinset ⊆ declared) :
    φ.modelCountOn declared = 2 ^ (declared.card - φ.numVars) * φ.modelCount

    If the declared set contains all occurring variables, its unused variables independently contribute two choices each. The containment premise is essential because assignments outside the declared set are extended by false.

    Renaming by the duplicate-free variable list uses every index below numVars, without gaps. The original clause and literal order is retained.

    Dense natural relabeling preserves the occurring-variable model count.

    Dense natural relabeling gives the original count on exactly numVars declared variables. This includes the empty formula without requiring a total map from V into Fin 0.

    Guard checking that every clause of φ has width ≤ k and every variable lies in < N.

    Instances For
      def Cslib.Logic.PL.CNF.normalizeDeclaredLeaf {P : Type u_2} (NOf : P → ℕ) (h : P × CNF ℕ → ℕ) (x : P × CNF ℕ) :

      Right-shift normalization converting a declared-range count ψ.modelCountOn (Finset.range N) into ψ.modelCount (= h (p, ψ) >>> (NOf p - ψ.distinctVars.length)).

      Instances For
        theorem Cslib.Logic.PL.CNF.normalizeDeclaredLeaf_eq_div {P : Type u_2} (NOf : P → ℕ) (h : P × CNF ℕ → ℕ) (x : P × CNF ℕ) :
        normalizeDeclaredLeaf NOf h x = h x / 2 ^ (NOf x.1 - x.2.numVars)
        theorem Cslib.Logic.PL.CNF.normalizeDeclaredLeaf_eq_modelCount {P : Type u_2} {NOf : P → ℕ} {h : P × CNF ℕ → ℕ} {p : P} {ψ : CNF ℕ} (hsub : ψ.vars.toFinset ⊆ Finset.range (NOf p)) (hh : h (p, ψ) = ψ.modelCountOn (Finset.range (NOf p))) :

        When ψ's variables lie in Finset.range (NOf p) and h (p, ψ) equals the declared-range count ψ.modelCountOn (Finset.range (NOf p)), normalizeDeclaredLeaf recovers ψ.modelCount.

        theorem Cslib.Logic.PL.CNF.normalizeDeclaredLeaf_le_two_pow_numVars {P : Type u_2} {NOf : P → ℕ} {h : P × CNF ℕ → ℕ} {p : P} {ψ : CNF ℕ} (hsub : ψ.vars.toFinset ⊆ Finset.range (NOf p)) (hh : h (p, ψ) ≤ 2 ^ NOf p) :

        When ψ's variables lie in Finset.range (NOf p) and h (p, ψ) ≤ 2 ^ NOf p, normalizeDeclaredLeaf NOf h (p, ψ) is at most 2 ^ ψ.numVars.