Constraint satisfaction problems #
A constraint satisfaction problem (CSP) instance F : CSP Rel V over a relation alphabet Rel
and variable type V is a conjunction (list) of constraints (R, vs) : Rel × List V, interpreted
over a domain D under a family of relations sem : Rel → List D → Bool by requiring
sem R (vs.map σ) = true for every (R, vs) ∈ F.
Relations are not assigned fixed arities at the type level: sem R is evaluated at the length of
each constraint's scope c.2. Under a uniform scope-length bound c.2.length ≤ k, each relation
symbol induces a relation of arity at most k.
For any finite inhabited domain D, CSP.modelCountOn sem F declared counts assignments on a
declared finite set of variables declared : Finset V (extended by default outside declared)
that satisfy F, and CSP.modelCount sem F counts satisfying assignments on the occurring
variables F.vars.toFinset. In the Boolean case D = Bool, default = false, matching
CNF.modelCountOn and CNF.modelCount.
Main definitions #
Cslib.Logic.PL.Constraint,Cslib.Logic.PL.CSP: constraints and CSP instances.Cslib.Logic.PL.Constraint.eval,Cslib.Logic.PL.CSP.eval,Cslib.Logic.PL.CSP.Satisfiable: evaluation and satisfiability over an arbitrary domainD.Cslib.Logic.PL.CSP.vars,Cslib.Logic.PL.CSP.numVars,Cslib.Logic.PL.CSP.distinctVars: variable occurrences, count of distinct variables, and first-occurrence variable list.Cslib.Logic.PL.Constraint.relabel,Cslib.Logic.PL.CSP.relabel,Cslib.Logic.PL.CSP.denseRelabel: variable renaming and dense0, …, numVars - 1relabeling.Cslib.Logic.PL.CSP.modelCountOn,Cslib.Logic.PL.CSP.modelCount: declared-variable and occurring-variable model counts over a finite inhabited domainD.Cslib.Logic.PL.CSP.validDeclaredCSP: executable guard checking scope lengths≤ kand variable indices< N.Cslib.Logic.PL.CSP.KCSP: the bounded-arity CSP decision problem.
Main results #
Cslib.Logic.PL.CSP.vars_denseRelabel_toFinset,Cslib.Logic.PL.CSP.numVars_denseRelabel: dense relabeling maps occurring variables ontoFinset.range F.numVars.Cslib.Logic.PL.CSP.modelCountOn_denseRelabel,Cslib.Logic.PL.CSP.modelCount_denseRelabel: dense relabeling preserves declared and occurring model counts.Cslib.Logic.PL.CSP.modelCount_pos_iff: a CSP instance is satisfiable iff its model count is positive.
References #
A constraint over relation alphabet Rel and variable type V pairs a relation symbol
R : Rel with its scope of variables vs : List V. Relations are not assigned fixed arities at
the type level; a semantics sem : Rel → List D → Bool is read at the length of each scope
vs.
Instances For
Rename variables in a constraint's scope.
Instances For
Evaluating a relabeled constraint composes the assignment with the relabeling.
Constraint evaluation depends only on the values assigned to the variables in its scope.
Number of distinct variables occurring in F.
Instances For
Distinct variables of F in order of first occurrence.
Instances For
F.varCNF has the same first-occurrence variable list as F.
A variable belongs to F.distinctVars iff it occurs in F.vars.
The length of F.distinctVars is F.numVars.
Rename each variable occurring in F by its first-occurrence index in F.distinctVars.
Instances For
The occurring variables of F.denseRelabel are Finset.range F.numVars.
Dense relabeling preserves the number of distinct occurring variables.
Dense relabeling preserves any uniform upper bound on constraint scope lengths.
Count assignments to declared : Finset V (extended by default outside declared) that
satisfy F under sem.
Instances For
Dense variable relabeling preserves the occurring-variable model count on
Finset.range F.numVars.
Dense variable relabeling preserves CSP.modelCount.
A CSP instance is satisfiable if and only if its model count is positive.
validDeclaredCSP k N F holds iff every constraint scope has length ≤ k and all occurring
variables lie in Finset.range N.