Weighted Model Counting in FO with Cardinality Constraints and Counting Quantifiers: A Closed Form Formula
Weighted First Order Model Counting (WFOMC) computes the weighted sum of the models of a first order theory on a domain of a given finite size. WFOMC has emerged as a fundamental tool for probabilistic inference. Algorithms for WFOMC that run in polynomial time w.r.t. the domain size are called lifted inference algorithms. Such algorithms have been developed for multiple extensions of FO (the fragment of First Order Logic with two variables) for the special case of symmetric weight functions. In this paper, instead of developing a specific algorithm, we derive a closed form formula for WFOMC in FO. The three key advantages of our proposal are: (i) it deals with existential quantifiers without introducing negative weights; (ii) it easily extends to FO with cardinality constraints and counting quantifiers (aka C); finally, (iii) it supports WFOMC for a class of weight functions strictly larger than symmetric weight functions, which can model count distributions, without introducing complex or negative weights.
Statistical Relational Learning (SRL) attempts to reason about probabilistic distributions over properties of relational domains [7, 15]. Most SRL frameworks use formulas in a logical language to provide a compact representation of the domain structure. Probabilistic knowledge on relational domain can be specified by assigning a weight to every interpretation of the logical language. One of the advantage of this approach is that probabilistic inference can be cast as Weighted Model Counting .
First Order Logic (FOL) allows specifying structural knowledge with formulas that contain individual variables that range over all the individuals of the domain. Probabilistic inference on domains described in FOL requires the grounding (aka instantiation) of all the individual variables with all the occurrences of the domain elements. This grounding leads to an exponential blow up of the complexity of the model description and hence the probabilistic inference.
Lifted inference [14, 2] aims at resolving this problem by carrying out probabilistic inference without the need for grounding. In recent years, Weighted First Order Model Counting has emerged as a useful formulation for probabilistic inference in SRL. Formally, WFOMC refers to the task of calculating the weighted sum of the models of a formula over a domain of a finite size.
where is the cardinality of the domain and is a weight function that associates a real number to each interpretation . FOL formulas which admit an algorithm that computes in a polynomial time w.r.t. are referred to as domain-liftable .
In the past decade, multiple extensions of FO (the fragment of First Order Logic with two variables) have been proven to be domain-liftable [19, 9, 11, 13]. These results are formulated over a special class of weight functions known as symmetric weight functions  and utilise lifted inference rules which are able to exploit the symmetry of FOL formulas in a rule based manner.
In this paper, we derive a closed form formula for WFOMC in FO, the fragment of first order logic consisting of the formulas that contain at most two individual variables. The formula can be computed in polynomial time with respect to the size of the domain, and therefore it constitutes a lifted inference algorithm. We see three main advantages of the proposed approach:
The proposed formula solves the weighted model counting problem without introducing negative weights.  proposes a method for WFOMC of formulas containing existential quantifiers by introducing negative weights. Though it has been shown that WFOMC is well defined also with negative weights, the connections between negative weights and probability turns out to be less clean, as it leads to negative and larger than one probability values.
The formula is easily extended to FO with cardinality constraints and counting quantifiers, without loosing domain-liftability. A cardinality constraint on an interpretation, is a constraint on the number of elements for which a certain predicate holds; counting quantifiers admit quantification of the variables with operators like , they allow expressions of the form expressing the fact that there exist at least elements that satisfy .
The formula computes WFOMC for a class of weight functions larger than symmetric weight functions. This extended class of weight functions allow to models the recently introduced count distributions .
For the sake of presentation, most of the paper focuses on First Order Model Counting (FOMC), i.e., the weight function is constantly equal to 1. We then show how weighted model counting can be obtained by multiplying each term of the resulting formula with the corresponding weight. This allows us to simplify the treatment of the counting part and renders an easier notation for the reader. The paper is therefore structured as follows: The next section describes the related work in the literature on WFOMC. We then introduce the main result, i.e., a closed form formula for First Order Model Counting for universally quantified formulas in FO, and it’s extension with cardinality restriction. In the successive section, we show how this formula can be used to compute FOMC also in presence of existential quantifiers and counting quantifiers. The last part of the paper elaborates how these formulas extend to WFOMC. In particular we show how the formula for FOMC can be adapted to WFOMC for symmetric weight functions and a larger class of weight function that allow us to define counting distributions .
Weighted first order model counting (WFOMC) was initially defined in . The paper provides an algorithm for WFOMC over universally quantified theories based on the knowledge compilation technique, which transforms a FOL theory to a first order deterministic decomposable
normal form (FO d-DNNF)
FOMC for Universal Formulas
Let be a first-order function free language with equality. A pure universal formula in is a formula of the form
where is a set of distinct variables occurring in , and is a quantifier free formula that does not contain any constant symbol. We use the compact notation for , where . Notice that we distinguish between the -tuple of variables and the set of variables denoted by . We denote an arbitrary -tuple of constants or variables by , is the result of uniform substitution of with in . If is the set of constants or variables of and a pure universal formula then denotes the formula:
For any arbitrary quantifier free formula , the following equivalence holds:
For any , we have that is valid. Which implies that is also valid. Since and commute, we have that . The viceversa is obvious since is one of the conjuncts in . ∎
Let , then is the following formula
Notice that in we can assume that two distinct variables and are grounded to different domain elements. Indeed, the cases in which and are grounded to the same domain element is taken into account by the conjunct in which is replaced by . See for instance the first and the last conjunct of (4).
A first order truth assignment of a quantifier free formula is a function that assigns to each atom of either or ( means false and true) and assigns 1 to and 0 to if and are two distinct individual variables. A first order truth assignment allows associating a truth value to a first order quantifier free formula. The truth value of under the truth assignment , denoted by , is obtained by applying the classical propositional logic of the connectives. Notice that is not a FOL interpretation as it assigns truth values to atoms that contain free variables, and not to their groundings.
As highlighted in the previous example, any assignment can be split in three partial assignments , , and that assign only the atoms containing , and both and , respectively.
Consider the assignment of example 2 and the one obtained by the permutation that exchanges and
It is easy to see that . This is not a coincidence, it is actually a property that derives from the shape of . This is stated in the following property.
For every quantifier free formula , every permutation of and every first order truth assignment for , ; where , for every atom of .
If then for some . This implies that , which implies that . The proof of the opposite direction follows form the fact that . ∎
From now on, we concentrate on the special case where .
For any assignment of , let
and be the partial assignments that assign only the atoms
containing and respectively.
Notice that if is an atom of , so is and
vice-versa. This implies that and assign two sets
of atoms that are isomorphic under the exchange of with .
Let be the number of atoms contained in each of these two sets
and let be an enumeration of the predicate symbols of
these atoms. In other words, we have that assigns truth value to
and that assigns to
where is the empty string and is . Notice that Proposition 1 guarantees that .
Example 4 (Example 1 cont’d).
The set of atoms containing only or only in the formula (4) are and respectively. In this case . The partial assignments and corresponding to the assignment of Example 2 are: and . is the number of first order assignments satisfying (4) and agreeing with and . In this case . The other cases are as follows:
For any set of constants and any -tuple such that , let be any partition of such that . We define as follows:
Examples of , on are and .
Note there are such partitions, and all the for such partitions will have the same model count. These observations have been formalised in lemma 2
Let and , be two partitions with the same . Notice that can be obtained by applying some permutation on from . From Proposition 1 we have that
Furthermore notice that if is different from then and cannot be simultaneously satisfied. This implies that
Since there are partitions of , of the form , then
For any partition
Where for all , are the indices such that and .
can be rewritten in
is obtained by replacing each atom with if and otherwise and each atom with if and otherwise. Notice that all the atoms of contain both and . Furthermore notice that if then and do not contain common atoms. Finally we have that . Hence
For any pure universal formula in
Example 6 (Example 1 cont’d).
Consider a domain of 3 elements (i.e., n=3). Each term of the summation (6) is of the form
which is the number of models with elements for which and are both false; elements for which is false and true, elements for which is true and is false and elements for which and are both true. For instance
is the number of models in which 2 elements are such that and is false and element where and are both true.
As a final remark for this section, notice that the computational cost of computing is constant with respect to the domain cardinality. We assume the cost of multiplication to be constant. Hence, the computational complexity of computing (6) depends on the domain only through the multinomial coefficients and the multiplications involved in . The computational cost of computing is polynomial in and the total number of are , which has as an upper-bound. Also, the term has multiplication operations. Hence, we can conclude that the (6) is computable in polynomial time with respect to the domain cardinality.
FOMC for Cardinality Constraints
Cardinality constraints are arithmetic constraints on the number of true interpretations of a set of predicates in a given FOL formula. In Example 6, we showed how different values of can represent different unary predicate cardinalities. Let’s formalize the correspondence between the multinomial factor and the cardinality of the unary predicates of the models that satisfy . For every with and for every unary predicate , we define
The following lemma states that is the number of such that .
For every -tuple of integers with , and every unary predicate , if then
The lemma follows immediately from the definition of given in equation (5). ∎
Let be any arithmetic constraint on the integer variables representing the cardinality of unary predicates. We say that , if is satisfied when each is substituted for the integer .
Corollary 1 (of Theorem 1).
For every cardinality restriction on unary predicates,
To count the models of (4) with the additional constraint that is balanced i.e., , we have to consider only the terms where is such . Equivalently in equation (8) we should consider only the such that . (Notice that is the number of elements that satisfy and and is the number of elements that satisfy and ).
To count models that satisfy cardinality restriction on binary predicates, we need to extend the result of Theorem 1. Similarly to what we have done for unary atoms, let be an enumeration of the atoms of that contain both variables and . Notice that the order of variables is not respected; for instance in Example 1, we have two predicates and . Every partial assignment to these predicates can be represented with an integer , with , with the usual convention that, if , then . Now for every and every , , where , and . We start by observing that
For instance introduced in Example 4 expands to where corresponds to the following assignments:
which can be rewritten as
where, for every , is a vector of integers that sum up to . Similarly to what we have done for unary predicates, we define for every binary predicate as follows:
where and are the indexes such that corresponds to and to .
Let be any arithmetic constraint on the integer variables representing the cardinality of arbitrarily selected unary and binary predicates. We say that , if is satisfied when each is substituted for the integer if is unary and with if is binary.
A graphical representation of the pair for the formula (4) is provided in the following picture:
This configuration represent the models in which a set of constants are partitioned in four sets , each containing elements (hence ). Furthermore, for each pair and the relation is partitioned in 4 sub relations where each contains pairs (hence ). For instance if the pair it means that we are considering assignments that satisfy .
Corollary 2 (of Theorem 1).
For every cardinality restriction is equal to
Consider formula (4) with the additional conjunct and . The constraint implies that we have to consider such that . constraint translates to only considering monomials with .
FOMC for the Existential Quantifier
Any arbitrary formula in FO can be reduced to an equisatisfiable reduction called Scott’s Normal Form(SNF) , see equation (19). In  prove that SNF also preserves WFOMC of the FO formulas. In this section, we extend our result for FOMC in universally quantified formulas to the whole FO fragment by providing an FOMC formula for SNF. We first show our method for the following special case of SNF:
where and are formulae without quantifiers. First of all notice that:
where is a new unary predicate. In the following lemma we show that can be expressed as a function of ’s.
Proof of lemma 5.
An expansion of the statement of Lemma 5 with and is
Since is the first order model counting of a pure universal formula with cardinality restriction, it can be computed by the formula of Corollary 1. Lemma 5 tells us how to compute also starting from the ’s. Finally notice that, the second term of equation (14) can be computed by summing from . This is possible since the set of models counted in are disjoint from the set of models counted in , where . This allows us to state the following theorem:
Let be the formula and let be the number of models of which are extensions of the partial assignments and , then
|by Lemma 5|
The expansion of the right terms is as follows: