<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta>
      <journal-title-group>
        <journal-title>DL</journal-title>
      </journal-title-group>
    </journal-meta>
    <article-meta>
      <title-group>
        <article-title>Model Counting and Sampling in First-Order Logic</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Ondřej Kuželka</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Faculty of Electrical Engineering, Czech Technical University in Prague</institution>
          ,
          <country country="CZ">Czech Republic</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2024</year>
      </pub-date>
      <volume>37</volume>
      <fpage>18</fpage>
      <lpage>21</lpage>
      <abstract>
        <p>First-order model counting (FOMC) asks to count models of a first-order logic sentence over a given set of domain elements. Its weighted variant, WFOMC, generalizes FOMC by assigning weights to the models and has applications among others in statistical relational learning. Several non-trivial classes of WFOMC problems that can be solved in time polynomial in the number of domain elements were identified in the literature over the past decade, since the two seminal paper by Van den Broeck (2011) and Van den Broeck, Meert and Darwiche (2014) established tractability of FO2 for WFOMC. This talk is about recent developments on WFOMC and the related problem of weighted first-order model sampling (WFOMS). We also discuss applications of WFOMC and WFOMS, such as automated solving of problems from enumerative combinatorics and elementary probability theory.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Model counting</kwd>
        <kwd>sampling</kwd>
        <kwd>first-order Logic</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Weighted First-Order Model Counting</title>
      <p>
        Weighted first-order model counting (WFOMC) is the task of computing the weighted sum of
models of a given first-order logic sentence [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. It has applications in statistical relational
learning [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] and it is also relevant for probability theory and combinatorics [
        <xref ref-type="bibr" rid="ref3 ref4">3, 4</xref>
        ]. Formally,
given a set of domain elements ∆ and two functions ( ) and ( ) mapping predicate symbols
to real numbers, we define WFOMC as
      </p>
      <p>WFOMC(Ψ , ∆ , , ) =</p>
      <p>(, , ),
∑︁
:|=Ψ
where  (), i.e. the weight of , is computed as
 (, , ) = ∏︁ (pred()) ∏︁ (pred()).</p>
      <p>|=
|=¬
Example 1 (Illustrating the notion of WFOMC). Let us have a domain ∆ = {, }, and
suppose that we only have two predicates heads and tails, with weights given as (heads) = 2,
(tails) = (heads) = (tails) = 1. We will want to compute the WFOMC of the sentence
Γ = ∀ : (heads()∨tails())∧(¬heads()∨¬tails()). There are four models of Γ on the domain
∆ : 1 = {heads(), heads()}, 2 = {heads(), tails()}, 3 = {tails(), heads()} and
4 = {tails(), tails()}. The resulting first-order model count is FOMC(Γ , ∆) = 4 and the
weighted model count is WFOMC(Γ , , , ∆) = 4 + 2 + 2 + 1 = 9 .</p>
      <p>
        Example 2. Consider the following variant of the Secret Santa game. There are  people attending
the Christmas party. Each person is supposed to give presents to  other people and receive 
presents.1 The organizer decides to let everyone draw names from  hats each of which contains
everyone’s name once. The participants then come and each of them draws one name at random
from each hat. We ask what is the probability that no one, at the same time, (i) draws their own
name and (ii) draws the same name more than once. When  = 1, the solution is known since the
18th century and it is the ratio of the number of derangements (i.e., permutations without fixed
points) and the number of permutations on  elements. For  &gt; 1 the problem could still be solved
by hand, but with non-trivial efort and with good knowledge of combinatorics. The same problem
could, however, also be solved automatically using WFOMC in polynomial time because it can be
encoded in the two-variable fragment of first-order logic with counting quantifiers C2 [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ], which is
known to be tractable [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] (what we mean by “tractable” is explained in Section 3). The C2 sentence
with which we can achieve it is:
Ψ =

⋀︁ (︀ ∀∃=1 Draw(, ) ∧ ∀∃=1 Draw(, ) ∧ ∀ ¬Draw(, ))︀ ∧
=1

⋀︁ ⋀︁ (∀∀ ¬Draw(, ) ∨ ¬Draw (, )) .
      </p>
      <p>=1 &lt;
Here, Draw(, ) represents that  drew the name  from the hat . To compute the desired
probability, we just need to divide the WFOMC of the sentence Ψ on a domain of size  by (!)
which is the total number of all possible draws (obviously, if we did not know factorials, we could
compute this number by WFOMC as well).</p>
    </sec>
    <sec id="sec-2">
      <title>2. Weighted First-Order Model Sampling</title>
      <p>
        Another useful task one might need to solve is, given a first-order logic sentence, a domain
and weighting functions, to sample a model of the sentence with probability proportional to
its weight. This problem is known as weighted first-order model sampling (WFOMS) [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. It has
again applications in statistical relational learning, as it allows sampling from Markov logic
networks [
        <xref ref-type="bibr" rid="ref10 ref8 ref9">8, 9, 10</xref>
        ], but its potential applications are much broader—it generally provides a
principled approach for eficient sampling of combinatorial structures.
      </p>
      <p>
        Example 3. Suppose that after computing the probability of a successful draw in the Secret Santa
game from Example 2 (a successful draw is one in which no one got their own name and no one got
name of anyone else more than once), we conclude that the probability is too low for this procedure
to be practical. Then we might want to sample an assignment of who should give presents to whom
automatically. To achieve that we can sample models of the C2 sentence from Example 2 using
WFOMS. It turns out that sampling is also tractable for sentences from the C2 fragment [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ].
1In the normal variant of the Secret Santa game,  = 1.
      </p>
    </sec>
    <sec id="sec-3">
      <title>3. Tractability</title>
      <p>
        An important question about WFOMC and WFOMS is: How hard are they? First, it is not
dificult to observe that there is no hope for a WFOMC algorithm that would scale polynomially
with the size of the first-order logic sentence even if the sentence was guaranteed to have just
one logical variable (unless P = #P). Therefore focus has been on identifying fragments of
ifrst-order logic sentences for which WFOMC can be computed in time polynomial in the size
of the domain. The term coined for this type of tractability by Van den Broeck [2011] is domain
liftability. In general, WFOMC and WFOMS are intractable even in this sense already for some
sentences from FO3 [
        <xref ref-type="bibr" rid="ref12 ref9">12, 9</xref>
        ], however, there are non-trivial fragments of first-order logic which
have been identified as tractable for WFOMC [
        <xref ref-type="bibr" rid="ref11 ref13 ref14 ref15 ref6">13, 11, 14, 15, 16, 6, 17, 18, 19</xref>
        ] and for WFOMS
[
        <xref ref-type="bibr" rid="ref7 ref9">7, 9</xref>
        ], including the fragment C2 [
        <xref ref-type="bibr" rid="ref10 ref6">6, 10</xref>
        ].
      </p>
    </sec>
    <sec id="sec-4">
      <title>4. Some Applications</title>
      <p>Here we briefly mention several applications that go beyond the standard machine learning
uses of WFOMC and WFOMS.</p>
      <p>
        Combinatorics. WFOMC is well-suited for solving problems from enumerative
combinatorics.2 The various tractable fragments of WFOMC can be used to count many other non-trivial
structures as well, e.g., -regular graphs, trees with  leaves etc. [
        <xref ref-type="bibr" rid="ref3">3, 17</xref>
        ]. The close connection
between WFOMC and enumerative combinatorics was used for developing a method capable of
generating a database of integer sequences with combinatorial interpretation [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] that we hope
could complement the well known OEIS database [21].
      </p>
      <p>
        Samplers. Standard programming language libraries usually have some support for sampling.
For instance, NumPy provides functionality for sampling simple structures such as permutations
and combinations. However, when we need to sample a more complex structure, we typically
need to develop a sampler from scratch. Having a declarative framework based on WFOMS
would be a useful tool for programmers making their work easier. The main reason why
there is not such a framework based on the current WFOMS algorithms [
        <xref ref-type="bibr" rid="ref10 ref9">9, 10</xref>
        ] yet is their
practical performance, which is the focus of ongoing works. However, it is worth mentioning
that, unsurprisingly, these algorithms already outperform state-of-the-art propositional model
samplers on first-order sampling problems, as shown experimentally in [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ].
      </p>
    </sec>
    <sec id="sec-5">
      <title>Acknowledgments</title>
      <p>The author is grateful to the many collaborators who worked on the problems described in this
paper (alphabetically): Jáchym Barvínek, Timothy van Bremen, Peter Jung, Martin Svatoš, Jan
Tóth, Yuanhong Wang and Yuyi Wang. The work of the author was mainly supported by the
Czech Science Foundation projects 20-19104Y, 23-07299S, 24-11820S.
2There are also other approaches to automating combinatorics within the broader context of lifted inference, most
notably [20].
[16] A. Kuusisto, C. Lutz, Weighted model counting beyond two-variable logic, in: Proceedings
of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2018, 2018,
pp. 619–628.
[17] T. Van Bremen, O. Kuželka, Lifted inference with tree axioms, in: Proceedings of the
International Conference on Principles of Knowledge Representation and Reasoning, 2021,
pp. 599–608.
[18] J. Tóth, O. Kuželka, Lifted inference with linear order axiom, in: Thirty-Seventh AAAI</p>
      <p>Conference on Artificial Intelligence, AAAI Press, 2023.
[19] S. Malhotra, D. Bizzaro, L. Serafini, Lifted inference beyond first-order logic, 2024.</p>
      <p>arXiv:2308.11738.
[20] P. Totis, J. Davis, L. De Raedt, A. Kimmig, Lifted reasoning for combinatorial counting,</p>
      <p>Journal of Artificial Intelligence Research 76 (2023) 1–58.
[21] OEIS Foundation Inc., The on-line encyclopedia of integer sequences, http://oeis.org, 2023.</p>
      <p>Accessed: 2023-05-01.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>G.</given-names>
            <surname>Van den Broeck</surname>
          </string-name>
          , N. Taghipour,
          <string-name>
            <given-names>W.</given-names>
            <surname>Meert</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Davis</surname>
          </string-name>
          , L. De Raedt,
          <article-title>Lifted probabilistic inference by first-order knowledge compilation</article-title>
          ,
          <source>in: Proceedings of the Twenty-Second international joint conference on Artificial Intelligence</source>
          ,
          <year>2011</year>
          , pp.
          <fpage>2178</fpage>
          -
          <lpage>2185</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>L.</given-names>
            <surname>Getoor</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Taskar</surname>
          </string-name>
          ,
          <article-title>Introduction to statistical relational learning</article-title>
          , volume
          <volume>1</volume>
          , MIT press Cambridge,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>J.</given-names>
            <surname>Barvínek</surname>
          </string-name>
          , T. van Bremen,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Wang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Zelezný</surname>
          </string-name>
          ,
          <string-name>
            <given-names>O.</given-names>
            <surname>Kuzelka</surname>
          </string-name>
          ,
          <article-title>Automatic conjecturing of p-recursions using lifted inference</article-title>
          ,
          <source>in: Inductive Logic Programming - 30th International Conference, ILP</source>
          <year>2021</year>
          ,
          <article-title>Proceedings</article-title>
          , volume
          <volume>13191</volume>
          of Lecture Notes in Computer Science, Springer,
          <year>2021</year>
          , pp.
          <fpage>17</fpage>
          -
          <lpage>25</lpage>
          . URL: https://doi.org/10.1007/978-3-
          <fpage>030</fpage>
          -97454-
          <issue>1</issue>
          _2. doi:
          <volume>10</volume>
          .1007/ 978-3-
          <fpage>030</fpage>
          -97454-1\_2.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>M.</given-names>
            <surname>Svatoš</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Jung</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Tóth</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Wang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>O.</given-names>
            <surname>Kuželka</surname>
          </string-name>
          ,
          <article-title>On discovering interesting combinatorial integer sequences</article-title>
          ,
          <source>in: Proceedings of the Thirty-Second International Joint Conference on Artificial Intelligence</source>
          ,
          <year>2023</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>E.</given-names>
            <surname>Graedel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Otto</surname>
          </string-name>
          , E. Rosen,
          <article-title>Two-variable logic with counting is decidable</article-title>
          ,
          <source>in: Proceedings of Twelfth Annual IEEE Symposium on Logic in Computer Science</source>
          , IEEE,
          <year>1997</year>
          , pp.
          <fpage>306</fpage>
          -
          <lpage>317</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>O.</given-names>
            <surname>Kuželka</surname>
          </string-name>
          ,
          <article-title>Weighted first-order model counting in the two-variable fragment with counting quantifiers</article-title>
          ,
          <source>Journal of Artificial Intelligence Research</source>
          <volume>70</volume>
          (
          <year>2021</year>
          )
          <fpage>1281</fpage>
          -
          <lpage>1307</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Wang</surname>
          </string-name>
          , T. van Bremen,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Wang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>O.</given-names>
            <surname>Kuželka</surname>
          </string-name>
          ,
          <article-title>Domain-lifted sampling for universal two-variable logic and extensions</article-title>
          ,
          <source>in: Proceedings of the Thirty-Sixth AAAI Conference on Artificial Intelligence (AAAI-22)</source>
          , AAAI Press,
          <year>2022</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>M.</given-names>
            <surname>Richardson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Domingos</surname>
          </string-name>
          ,
          <article-title>Markov logic networks</article-title>
          ,
          <source>Machine Learning</source>
          <volume>62</volume>
          (
          <year>2006</year>
          )
          <fpage>107</fpage>
          -
          <lpage>136</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Wang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Pu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Wang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>O.</given-names>
            <surname>Kuželka</surname>
          </string-name>
          ,
          <article-title>On exact sampling in the two-variable fragment of ifrst-order logic</article-title>
          ,
          <source>in: LICS '23: 37th Annual ACM/IEEE Symposium on Logic in Computer Science</source>
          , IEEE,
          <year>2023</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Wang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Pu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Wang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>O.</given-names>
            <surname>Kuzelka</surname>
          </string-name>
          ,
          <article-title>Lifted algorithms for symmetric weighted first-order model sampling</article-title>
          ,
          <source>Artif. Intell</source>
          .
          <volume>331</volume>
          (
          <year>2024</year>
          )
          <article-title>104114</article-title>
          . URL: https://doi.org/10.1016/j.artint.
          <year>2024</year>
          .
          <volume>104114</volume>
          . doi:
          <volume>10</volume>
          .1016/J.ARTINT.
          <year>2024</year>
          .
          <volume>104114</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <surname>G. Van den Broeck</surname>
          </string-name>
          ,
          <article-title>On the completeness of first-order knowledge compilation for lifted probabilistic inference</article-title>
          ,
          <source>in: Advances in Neural Information Processing Systems</source>
          ,
          <year>2011</year>
          , pp.
          <fpage>1386</fpage>
          -
          <lpage>1394</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>P.</given-names>
            <surname>Beame</surname>
          </string-name>
          , G. Van den Broeck, E. Gribkof,
          <string-name>
            <given-names>D.</given-names>
            <surname>Suciu</surname>
          </string-name>
          ,
          <article-title>Symmetric weighted first-order model counting</article-title>
          ,
          <source>in: Proceedings of the 34th ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems</source>
          , ACM,
          <year>2015</year>
          , pp.
          <fpage>313</fpage>
          -
          <lpage>328</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>V.</given-names>
            <surname>Gogate</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P. M.</given-names>
            <surname>Domingos</surname>
          </string-name>
          ,
          <article-title>Probabilistic theorem proving</article-title>
          ,
          <source>in: UAI</source>
          <year>2011</year>
          ,
          <source>Proceedings of the Twenty-Seventh Conference on Uncertainty in Artificial Intelligence</source>
          , Barcelona, Spain,
          <source>July 14-17</source>
          ,
          <year>2011</year>
          ,
          <year>2011</year>
          , pp.
          <fpage>256</fpage>
          -
          <lpage>265</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <given-names>G.</given-names>
            <surname>Van den Broeck</surname>
          </string-name>
          , W. Meert,
          <string-name>
            <given-names>A.</given-names>
            <surname>Darwiche</surname>
          </string-name>
          ,
          <article-title>Skolemization for weighted first-order model counting</article-title>
          ,
          <source>in: Proceedings of the 14th International Conference on Principles of Knowledge Representation and Reasoning (KR)</source>
          ,
          <year>2014</year>
          , pp.
          <fpage>1</fpage>
          -
          <lpage>10</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <given-names>S. M.</given-names>
            <surname>Kazemi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Kimmig</surname>
          </string-name>
          , G. V. den Broeck, D. Poole,
          <article-title>New liftable classes for first-order probabilistic inference</article-title>
          ,
          <source>in: Advances in Neural Information Processing Systems 29: Annual Conference on Neural Information Processing Systems</source>
          ,
          <year>2016</year>
          , pp.
          <fpage>3117</fpage>
          -
          <lpage>3125</lpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>