BDDs. Finally, Monte Carlo simulation requires representing and manipulating samples. We discuss these issues next.

Source-to-source transformation
-------------------------------

We use the `term_expansion` mechanism to allow Prolog calls to labeled facts, and for labeled facts to call the ProbLog engine. As an example, the program: $$\begin{array}{l}
\mathtt{0\ldotp715::edge('PubMed\_2196878','MIM\_609065')\ldotp}\\
\mathtt{0\ldotp659::edge('PubMed\_8764571','HGNC\_5014')\ldotp}\\
\end{array}$$ would be compiled as: $$\begin{array}{lll}
  \mathtt{edge(A,B)} &\mathtt{:-} &  \mathtt{problog\_edge(ID,A,B,LogProb),}\\
  & & \mathtt{grounding\_id(edge(A,B),ID,GroundID),}\\
  & & \mathtt{add\_to\_proof(GroundID,LogProb)\ldotp}\\
  & & \\
  \multicolumn{3}{l}{\mathtt{problog\_edge(0,'PubMed\_2196878','MIM\_609065',-0\ldotp3348)\ldotp}}    \\
  \multicolumn{3}{l}{\mathtt{problog\_edge(1,'PubMed\_8764571','HGNC\_5014',-0\ldotp4166)\ldotp}}   \\
\end{array}$$ Thus, the internal representation of each fact contains an identifier, the original arguments, and the logarithm of the probability[^4]. The `grounding_id` procedure will create and store a grounding specific identifier for each new grounding of a non-ground probabilistic fact encountered during proving, and retrieve it on repeated use. For ground probabilistic facts, it simply returns the identifier itself. The `add_to_proof` procedure updates the data structure representing the current path through the search space, i.e., a queue of identifiers ordered by first use, together with its probability. Compared to the original meta-interpreter based implementation of [@DeRaedt07], the main benefit of source-to-source transformation is better scalability, namely by having a compact representation of the facts for the YAP engine [@DBLP:conf/padl/Costa07] and by allowing access to the YAP indexing mechanism [@jit-index].

Proof 