<!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 />
    <article-meta>
      <title-group>
        <article-title>From PRISM to ProbLog and Back Again</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>KU Leuven firstname.lastname@kuleuven.be</string-name>
        </contrib>
      </contrib-group>
      <fpage>26</fpage>
      <lpage>39</lpage>
      <abstract>
        <p>PRISM and ProbLog are two prominent languages for Probabilistic Logic Programming. While they are superficially very similar, there are subtle differences between them that lead to different formulations of the same probabilistic model. This paper aims to shed more light on the differences by developing two source-to-source transformations, from PRISM to ProbLog and back.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <sec id="sec-1-1">
        <title>In the introduction we mentioned that both ProbLog and PRISM implement</title>
      </sec>
      <sec id="sec-1-2">
        <title>Sato’s distribution semantics [7], which itself subsumes the regular fixpoint semantics of logic programs [2]. This section briefly summarises how both systems implement this semantics. 26</title>
        <p>Semantics of Probabilistic Logic Programs The semantics divides a program P
in two distinct parts: a set of probabilistic facts F and a set of rules R (logical
clauses). A total choice C is any subset of F . A fact f is said to be true in
C (false) if and only if f ∈ C (f 6∈ C). A total choice C and a set of clauses
R together form a conventional logic program. We use P |= a to denote that
program P logically entails an atom a in the perfect model semantics [6].</p>
        <p>Let F = {p1 :: f1, . . . , pn :: fn}, then the probability of a choice C ⊆ F is
given by the product of the probabilities of the true and false facts:
P (C) =</p>
        <p>Y
pi ×</p>
        <p>Y</p>
        <p>(1 − pi)
pi::fi∈C pi::fi6∈C</p>
      </sec>
      <sec id="sec-1-3">
        <title>The distribution semantics defines the probability of a query q for a program</title>
        <p>P = F ∪ R as the sum of probabilities of all total choices that entail q:
X
PP (q) =</p>
        <p>P (C)</p>
        <p>C⊆F∧C∪R|=q</p>
      </sec>
      <sec id="sec-1-4">
        <title>ProbLog ProbLog follows the above semantic fairly closely , denoting probabilistic facts and rules in the same way, e.g., as: (blue code denotes ProbLog code):</title>
        <p>0:5 :: heads.
win :- heads.</p>
      </sec>
      <sec id="sec-1-5">
        <title>However, ProbLog also provides advanced syntax, such as disjunctions annotated</title>
        <p>with probabilities (this syntax was inspired by the LPAD-language [4]):
0.5 :: heads ; 0.5 :: tails.</p>
      </sec>
      <sec id="sec-1-6">
        <title>This expresses that exactly one of heads or tails is true. It easily desugars to regular probabilistic facts and rules:</title>
        <p>0.5 :: heads.</p>
        <p>tails :- not(heads).</p>
      </sec>
      <sec id="sec-1-7">
        <title>ProbLog also allows a rule to be annotated with a probability. This too is merely syntactic sugar, which is desugared into a regular rule and a probabilistic fact.</title>
      </sec>
      <sec id="sec-1-8">
        <title>PRISM PRISM follows a different approach. It features a special predicate</title>
        <p>msw(i,X) that introduces an anonymous probabilistic choice, also called switch.</p>
      </sec>
      <sec id="sec-1-9">
        <title>Every new occurrence of an msw-predicate during SLD-resolution is seen as a dis</title>
        <p>tinct probabilistic choice. The argument X is the value that the fact assumes. The
range and probability are associated with the identifier argument i and provided
separately with the predicate values x(i,[v1,...,vn],[p1,...,pn]) (green
code denotes PRISM code).</p>
        <p>ProbLog vs. PRISM In what follows, we use the following running example,
expressed in PRISM as:1
1 Strictly speaking PRISM requires that probabilistic predicates have at least one
(possibly dummy) argument, for the purpose of tabling; we ignore this requirement
for simplicity.</p>
        <p>Here the probability of p is 25%. Since there are two choices with two values
each, there are four possible combinations, each with probability 25%, but in
only one both q and r are true. The corresponding ProbLog program is:
0.5 :: q.
0.5 :: r.</p>
        <p>p :- q,r.
0.5 :: q.</p>
        <p>p :- q,q.</p>
      </sec>
      <sec id="sec-1-10">
        <title>Again the probability of p is 25%.</title>
      </sec>
      <sec id="sec-1-11">
        <title>Note that the following ProbLog program is not equivalent to the PRISM code:</title>
      </sec>
      <sec id="sec-1-12">
        <title>The reason is that ProbLog treats multiple occurrences of identical atoms as a</title>
        <p>single probabilistic fact (this is called stochastic memoisation). Hence the
probability of p is 50%, since q is either true or false with probability 50%. Contrast
this with PRISM, where each msw is its own random variable, as can be seen
from the previous example, where the probability was only 25%.
3</p>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>Translating PRISM to ProbLog</title>
      <sec id="sec-2-1">
        <title>This section shows how to translate PRISM programs to ProbLog.</title>
        <p>3.1</p>
        <p>Naive Approach</p>
      </sec>
      <sec id="sec-2-2">
        <title>Consider the translation of the following PRISM program, a simplification of our running example, where the probability of p is 25%:</title>
        <p>values_x(i,[t,f],[0.5,0.5]).
p :- msw(i,t),msw(i,t).
0.5 :: msw(i,t); 0.5 :: msw(i,f).
p :- msw(i,t),msw(i,t).</p>
      </sec>
      <sec id="sec-2-3">
        <title>We could try to simulate the msw-predicate in ProbLog with the following anno</title>
        <p>tated disjunction:
Unfortunately, this naive transformation is not faithful: there are only two total
choices, one where msw(i,t) is true and msw(i,f) is false, and vice versa. Both
have 50% probability, and p only holds in the first. The issue is that for ProbLog
both occurrences of msw refer to the same probabilistic fact that always assumes
the same value, while in PRISM they are considered distinct facts that can take
different values.
3.2</p>
        <p>Labeling Approach</p>
      </sec>
      <sec id="sec-2-4">
        <title>In order to distinguish different references to the same msw fact in ProbLog, we extend the msw predicate with a third argument that uniquely labels each reference. We develop this labelling strategy in several steps, motivating each step with an example.</title>
      </sec>
      <sec id="sec-2-5">
        <title>Labeling First, the annotated disjunction for msw is extended with a third argument:</title>
        <p>0.5 :: msw(i,t,_) ; 0.5 :: msw(i,f,_).</p>
      </sec>
      <sec id="sec-2-6">
        <title>The disjunction does not actually care what the value of this “label” argument</title>
        <p>is; its sole purpose is to distinguish different references to the fact.</p>
      </sec>
      <sec id="sec-2-7">
        <title>From the previous example it is clear that different references to the fact</title>
        <p>should have a different label value. This is accomplished by using the goal
position as an identifier. More precisely: every msw is labeled with gi, where i is the
position in the body of the clause:
0.5 :: msw(i,t,_) ; 0.5 :: msw(i,f,_).</p>
        <p>p :- msw(i,t,g1),msw(i,f,g2).</p>
      </sec>
      <sec id="sec-2-8">
        <title>The goal p now succeeds with probability 25%.</title>
        <p>Clause Labelling The above labeling is too simplistic to work in general: it does
not distinguish calls that occur in the same position of different clauses, or
branches of a disjunction. The following PRISM program illustrates the problem.
values_x(i,[t,f],[0.5,0.5]).
p :- msw(i,X),q(X).
q(t).
q(f) :- msw(i,f).</p>
        <p>0.5:: msw(i,t,_); 0.5:: msw(i,f,_).</p>
        <p>p :- msw(i,X,g1),q(X).
7→ q(t).</p>
        <p>q(f) :- msw(i,f,g1).</p>
        <p>Both switches in the program above map to the same fact in ProbLog, since they
share the same g1 label. In ProbLog, p succeeds with probability 100%, while
the probability that PRISM computes is 75%. Clearly we need to label switches
not just with their position within a clause, but also with the clause that they
occur in. The result is the following ProbLog program:
p :- msw(i,X,g1(c1)),q(X).
q(t).</p>
        <p>q(f) :- msw(i,t,g1(c3)).</p>
      </sec>
      <sec id="sec-2-9">
        <title>Now the computed probability is indeed 75%. 29</title>
        <p>Translation of Switch i:
Translation of Clause j:
values x(i, [v1, . . . , vn], [p1, . . . , pn]).</p>
        <p>7−→
p1 :: msw(i, v1, X) ; · · · ; pn :: msw(i, vn, X).
p(X) :- q1(X1), . . . , qn(Xn).</p>
        <p>7−→
p(X, L) :- q1(X1, g1(cj(L))), . . . , qn(Xn, gn(cj(L))).</p>
      </sec>
      <sec id="sec-2-10">
        <title>Context Labelling Finally, the context also matters: consider the following code:</title>
        <p>values_x(i,[t,f],[0.5,0.5]). 0.5 :: msw(i,t,_) ; 0.5 :: msw(i,f,_).
p :- q,q. p :- q,q.
q :- msw(i,t). 7→ q :- msw(i,t,g1(c2)).</p>
      </sec>
      <sec id="sec-2-11">
        <title>The labelling does not distinguish between the switches that are called due to</title>
        <p>the first and second occurrence of q in p. Hence, ProbLog determines that p
holds with 50% probability, where PRISM computes a 25% probability.</p>
        <p>Our solution is to include the label of the parent goal, and by extension
that of all ancestors, in the label. In other words, the label becomes a kind of
stack trace that documents the path from the top-level goal to the particular
invocation of the msw fact. To pass this trace around we extend every predicate
with a label argument:
0.5 :: msw(i,t,_) ; 0.5 :: msw(i,f,_).
p(Label) :- q(g1(c1(Label))),q(g2(c1(Label)).</p>
        <p>q(Label) :- msw(i,t,g1(c2(Label))).</p>
      </sec>
      <sec id="sec-2-12">
        <title>This ensures that the labels of the two switches are distinct, allowing ProbLog to compute the intended probability. In effect, we accurately model the following requirement from the PRISM manual [1, Section 2.2,p. 17]:</title>
        <p>The truth-values of switch instances at the different positions of a proof
tree are independently assigned. This means that the predicate calls of
msw/2 behave independently of each other.</p>
      </sec>
      <sec id="sec-2-13">
        <title>Summary Figure 1 summarises the translation. Switches are translated to an</title>
        <p>notated disjunctions of the msw/3 predicate, and all predicates receive a label
argument that identifies the execution trace up to the call to predicate.</p>
        <p>Note that PRISM makes a number of assumptions [1, Section 2.4.6,p. 27]
about programs, such as the exclusiveness condition which states that branches
in a disjunction must be mutually exclusive. The meaning of programs that
violate these assumptions is not defined. Hence we also do not define the behavior
of the ProbLog translation of undefined PRISM programs.</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Translating ProbLog to PRISM</title>
      <sec id="sec-3-1">
        <title>The transformation from ProbLog to PRISM is more involved, because ProbLog</title>
        <p>allows richer expressions for its facts (including non-ground arguments), and
ProbLog’s memoisation of probabilistic facts must be simulated. 2
4.1</p>
        <p>Naive Approach
First we consider a naive approach: assume that the ProbLog program has a
finite number of probabilistic facts f1, . . . , fn. We can choose the values of these
facts up front, and modify the remainder of the program to pass these values
around. Consider the following example:
0.5 :: f1.
0.4 :: f2.
p :- f1, f2.</p>
        <p>query(p).</p>
      </sec>
      <sec id="sec-3-2">
        <title>For the two probabilistic ProbLog facts f1 and f2 we get the PRISM range [t,f] for true and false and the corresponding probability distributions.</title>
        <p>values_x(f1,[t,f],[0.5,0.5]).
values_x(f2,[t,f],[0.4,0.6]).</p>
      </sec>
      <sec id="sec-3-3">
        <title>The translated query predicate chooses the truth values of the two probabilistic facts, and passes the list of true facts to predicate p.</title>
        <p>query :- choose_fact(f1,[],F1), choose_fact(f2,F1,Fs), p(Fs).</p>
      </sec>
      <sec id="sec-3-4">
        <title>Here, the PRISM predicate choose fact chooses the truth value for the given</title>
        <p>fact with msw, and, if true, adds it to the given list (see Figure 2).</p>
      </sec>
      <sec id="sec-3-5">
        <title>Finally, the program’s clauses are modified to pass the list of true facts around, and invocations of the facts are realised by member/2 lookups in the list.</title>
        <p>p(Fs) :- f1(Fs), f2(Fs).
f1(Fs) :- member(f1,Fs).</p>
        <p>f2(Fs) :- member(f2,Fs).
2 In theory, there is a predicate msw(i,N,V), where n distinguishes different instances
of the switch i, such that different calls to i with unifying N always have the same
value V , like stochastic memoisation. In practice, msw/3 is not implemented [8].
Translation of Facts:
Translation of the Query:
( values x(fi, [t, f ], [pi, 1 − pi]).)</p>
        <p>fi(Fs) :- member(fi, Fs).
 query(X) :- choose fact(f1, [], Fs1),

 ...,</p>
      </sec>
      <sec id="sec-3-6">
        <title>This transformation closely follows the distribution semantics of ProbLog programs given in Section 2: the choose fact calls compute all possible total choices through backtracking, and PRISM counts the probabilities of those choices for which the query succeeds.</title>
        <p>Unfortunately there are a number of problems with this approach. Firstly, the
set of probabilistic facts has to be known statically. This is clearly problematic
for programs whose grounding contains infinitely many facts (even if answering a
query involves only a finite subset). Secondly, even if the program contains only
a finite number of facts, the naive translation explores an exponential number of
total choices, even if the truth value of many facts in those choices is immaterial.
This section relaxes the requirement that all facts must be known statically
with a more dynamic approach. This approach maintains a partial choice, (i.e.,
a choice where some facts haven not yet been assigned a value) and extends
it dynamically whenever an unknown fact is is encountered during the
evaluation of the program. At first glance, it seems that this can be accomplished by
fail</p>
        <p>query([])
[f1:t]
query([f1:t])
[f1:t]
[f1:t]
p
f1
tu
[f1:f]
[f1:f]</p>
        <p>p
[f1:f]</p>
        <p>f1
[f1:f]
fail
[f1:f]
f2
query([f1:f])
[f1:f,f2:t]
...
maintaining separate input and output lists of facts, and adding new facts to
the output list. However, this violates PRISM’s exclusiveness condition. Instead,
communicating the discovery of as yet unknown facts requires more advanced
control flow manipulation, which is nicely captured by Prolog’s exception
mechanism.3 The program then simply throws an exception whenever it encounters
an unknown fact. The exception raised by the occurence of an unknown fact
is handled by probabilistically choosing a value for the fact, and extending the
partial choice accordingly. The query is then restarted with this new partial
choice. When the query terminates (succeeds or fails), PRISM backtracks over
the probabilistic switches, choosing new values for the facts. In this manner, all
total choices are eventually explored.</p>
      </sec>
      <sec id="sec-3-7">
        <title>Unfortunately exceptions are incompatible with PRISM’s use of tabling. Nev</title>
        <p>ertheless we use them to explain our translation because it nicely captures the
idea of the control flow used in our translation. The appendix contains the
actual working implementation, encoding the exception control flow in terms of
assert/1 and retract/1.</p>
        <p>Translation by Example It is instructive to look in more detail at a ProbLog
example:
0.5 :: f1.
0.4 :: f2.
p :- f1.</p>
        <p>p :- f2.
3 Where catch(Goal,Ball,Handler) calls the Goal, which may throw an exception
with throw/1. If an exception is indeed thrown, the goal and any of its alternatives
are aborted, the exception is unified with Ball and the Handler is called.
which translates to the follwing PRISM code:
values_x(f1,[t,f],[0.5,0.5]).
values_x(f2,[t,f],[0.4,0.6]).
f1(Pc) :- member(f1:t,Pc), !.
f1(Pc) :- not(member(f1:f,Pc)),throw(unkown(f1)).
f2(Pc) :- member(f2:t,Pc), !.
f2(Pc) :- not(member(f2:f,Pc)),throw(unkown(f2)).
p(Pc) :- f1(Pc).
p(Pc) :- f2(Pc).
query(Pc)
:</p>
        <p>
          catch(once(p(Pc)),unknown(F),extend(F,Pc)).
extend(F,Pc)
:msw(F,V),
query([F:V|T]).
– Lines 1-6 deal with probabilistic facts. There are multiple important
concepts: (
          <xref ref-type="bibr" rid="ref1">1</xref>
          ) In lines 1 and 2, the probabilities and values for facts are defined.
(
          <xref ref-type="bibr" rid="ref2">2</xref>
          ) Lines 3-4 define the logic for facts. Facts take a single argument Pc, the
partial choice, represented as a list of known facts with their truth value.
If the fact does not appear in the list, it is unknown and an
unknown/1exception is thrown.
– Lines 8-9 implement the clauses of the program. They are identical to the
original, except that the partial choice are passed around.
– Finally, lines 11-12 implement the overall query logic. The main goal is
called with the current partial choice, which is initially empty. There are
three possible outcomes:
1. If the query succeeds, the current partial choice is sufficient and the
once/1 discards any alternative ways to make the query succeed under
the same partial choice. This is valid because further ways to make the
query succeed do not affect its truth or probability.
2. If the query fails, this means it fails under the current partial choice and
other partial choices can be considered elsewhere (see † below).
3. If the main predicate depends on an unknown fact, its execution and
all its choicepoints are aborted by a throw/1 call which is intercepted
by catch/3 and extend/2 is called to recover from the exception. Lines
13-15 define this auxiliary predicate, which extends the current partial
choice to include the additional fact. Firstly, it conveys the additional
fact to PRISM with an msw-call (when PRISM backtracks over the msw, it
chooses different truth values for the fact, thereby exploring alternative
partial choices†), and then recursively calls query/1 with the extended
fact list.
        </p>
        <p>Figure 3 shows a partial execution of this program. The edges have been
annotated with the current partial choice at that point in the execution. Dashed
p(X) :- q1(Y 1), . . . , qn(Y n), not(r1(Z1)), . . . , not(rm(Zm)).
 fi(X, Pc) :- not(member(fi(X) : f, Pc), 
 throw(unknown(fi(X))). 
 :- query(X, []).

 query(X, Pc) :- catch( once(p(X, Pc)),
 unknown(F ),</p>
        <p>extend(X, F, Pc)).
 
 extend(X, F, Pc) :- msw(F, B), query(X, [F : B|Pc]).







Translation of Facts:</p>
        <p>pi :: fi(X). 7−→
Translation of the Query:
edges represent several derivation steps. Red edges represent the path of an
exception. A path of red edges always begins at a node that has been circled in red,
the unknown fact where the exception originates. Note how an exception always
backtracks to the nearest ancestor query, where it is dealt with by extending
the partial choice.</p>
      </sec>
      <sec id="sec-3-8">
        <title>This example execution demonstrates an advantage of the dynamic approach: once a proof has been found for p under partial choice [f1:t] (the middle branch), we need not consider any extension of this partial choice. This is safe, because p is also true in any extension of [f1:t].</title>
      </sec>
      <sec id="sec-3-9">
        <title>Summary The general formulation of the translation is shown in Figure 4. It supports ProbLog facts with arguments, where different instantiations of these arguments represent independent probabilistic choices in their own right. These are naturally supported by our translation.</title>
      </sec>
      <sec id="sec-3-10">
        <title>Extension: Flexible Probabilities ProbLog takes the dynamic nature of probabilistic facts one step further by allowing facts whose probability depends on their parameters. Consider the fact coin(Bias) for biased coins where Bias is the probability of the fact.</title>
        <p>Bias :: coin(Bias).</p>
      </sec>
      <sec id="sec-3-11">
        <title>We can incorporate this into our translation. However, we need to decou</title>
        <p>ple the statically determined range of values, expressed with facts of PRISM’s
values/2 predicate,
from the dynamically determined probability, for which we introduce the
predicate probability/2:</p>
      </sec>
      <sec id="sec-3-12">
        <title>We use the latter when we extend the partial choice, to dynamically set the probability distribution using PRISM’s set sw/2.</title>
        <p>values(coin(Bias),[t,f]).
probability(coin(Bias),Bias).
extend(F,Pc)
:probability(F,P),
Q is 1.0 - P,
set_sw(F,[P,Q]),
msw(F,B),
query([F:B|Pc]).</p>
      </sec>
      <sec id="sec-3-13">
        <title>The above approach naturally generalises to ProbLog rules of the form</title>
        <p>P :: p(X) :- q1(Y 1), . . . , qn(Y n).
which we can desugar into a regular rule and a parameterised probabilistic fact.</p>
        <p>P :: f(P ).</p>
        <p>p(X) :- q1(Y 1), . . . , qn(Y n), f(P ).
5</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Conclusion and Future Work</title>
      <sec id="sec-4-1">
        <title>This paper has presented two source-to-source transformations. One translates a</title>
        <p>model written in PRISM to ProbLog, the other travels in the opposite direction.</p>
      </sec>
      <sec id="sec-4-2">
        <title>The transformations clearly show where PRISM and ProbLog diverge in their interpretation of the distribution semantics.</title>
      </sec>
      <sec id="sec-4-3">
        <title>There are several possible avenues for future work:</title>
      </sec>
      <sec id="sec-4-4">
        <title>Missing Features The translation does not touch upon PRISM’s and ProbLog’s different facilities for incorporating observations in probabilistic models. In future work the translations presented here can be extended to allow for such observations.</title>
        <p>Formal Correctness We have not formally shown the translations to be
faithful, that is, preserve the semantics of the program. We have only demonstrated
them through examples. Preservation proofs are, of course, complicated by the
additional infrastructure that ProbLog and PRISM introduce on top of the
distribution semantics, and the complex control flow in the ProbLog to PRISM
translation. Nevertheless, a formal proof can vindicate the translation, or bring
to light potential errors. Proof Idea: Under a suitable semantics for exceptions,
show that a program, and its translation have identical logical behaviour, and
compute the same set of probabilistic facts. It then follows that their distribution
semantics coincide. Finally, the transformed program must satisfy exclusiveness.</p>
      </sec>
      <sec id="sec-4-5">
        <title>Performance Aside from correctness, another important aspect is the overhead</title>
        <p>introduced by the transformation. We have not yet made any effort to quantify
this overhead either in concrete timings or asymptotically. Particularly desirable
is a round-trip property, that shows that running the translations in sequence
(e.g. ProbLog to PRISM and back again) does not introduce excessive overhead.</p>
      </sec>
      <sec id="sec-4-6">
        <title>Two obstacles to such a round-trip property are readily apparent: first, since</title>
        <p>the PRISM to ProbLog translation cannot translate the output of the
ProbLogto-PRISM translation, due to its reliance on exceptions. Secondly, ProbLog’s
inference is #P-Complete in the worst case, as opposed to PRISM’s inference,
which runs in linear time. Careful analysis is needed tot ensure that ProbLog’s
running time does not explode in these cases.</p>
      </sec>
      <sec id="sec-4-7">
        <title>Acknowledgments We are grateful to Angelika Kimmig, Anton Dries, Wannes</title>
      </sec>
      <sec id="sec-4-8">
        <title>Meert and Luc De Raedt, and the anonymous reviewers for their helpful comments. Alexander Vandenbroucke is an SB PhD Fellow at FWO.</title>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>ProbLog to PRISM Transformation without catch/3</title>
      <p>and throw/1
This section reimplements the translation given in Section 4.2, using assert/1
and retract/1, instead of throw/1 and catch/3. Recall once more the example
from Section 4.2. It is now translated as follows:
1: :- dynamic unknown/1.
2: values_x(f1,[f1:t,f1:f],[0.5,0.5]).
3: values_x(f2,[f2:t,f2:f],[0.4,0.6]).
4: f1(Pc) :- member(f1:t,Pc), !.
5: f1(Pc) :- not(member(f1:f,Pc)),assert(unknown(f1)),fail.
6: f2(Pc) :- member(f2:t,Pc), !.
7: f2(Pc) :- not(member(f2:f,Pc)),assert(unknown(f2)),fail.
8: p(Pc) :- not(unknown(_)),f1(Pc),not(unknown(_)).
9: p(Pc) :- not(unknown(_)),f2(Pc),not(unknown(_)).
10: query(Pc)
:11: once(p(Pc))
12: ;
13: ( unknown(F),
14: retract(unknown(F)),
15: extend(F,Pc)
16: ).
17: extend(F,Pc)
:18: msw(F,V),
19: query(X,[F:V|Pc]).</p>
      <p>
        – Lines 2-7 simulate probabilistic facts. However, where the original
translation throws an exception, this translation instead dynamically asserts
unknown fact/1 (lines 5 and 7), to indicate that an unknown fact has been
detected. The predicate then fails, to simulate an exception.
– Lines 8-9 implement the clauses of the program, they are identical to the
original translation, except that the bodies are now guarded by
not(unknown( )). They serve two purposes: (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) the check at the beginning
of the body prevents backtracking from exploring alternatives, when an
unknown fact has been detected; (
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) the check at the end of the body ensures
that the clause does not inadvertently succeed when an exception is raised
inside a fact that occurs inside a negation (causing that fact to fail, and the
negation to succeed).
– Finally lines 10-19 implement the main query logic. As before there are
three possible outcomes:
      </p>
      <sec id="sec-5-1">
        <title>1. The query succeeds, and the behaviour is exactly as before (line 11). 38</title>
      </sec>
      <sec id="sec-5-2">
        <title>2. The query fails, and there is no unknown fact (line 13), this means that</title>
        <p>the query fails under the current partial choice, and other partial choices
can be considered like the original translation.</p>
      </sec>
      <sec id="sec-5-3">
        <title>3. The query fails, and there is an unknown fact (unknown(F) succeeds).</title>
      </sec>
      <sec id="sec-5-4">
        <title>This event is handled by (1) resetting the exception with retract/1(line</title>
        <p>
          14) and (
          <xref ref-type="bibr" rid="ref2">2</xref>
          ) extending the partial choice with extend/2, which is
unchanged.
        </p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <source>PRISM manual version 2</source>
          .2 (
          <issue>Retrieved Jun 11</issue>
          ,
          <year>2017</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2. van Emden,
          <string-name>
            <given-names>M.H.</given-names>
            ,
            <surname>Kowalski</surname>
          </string-name>
          ,
          <string-name>
            <surname>R.A.</surname>
          </string-name>
          :
          <article-title>The semantics of predicate logic as a programming language</article-title>
          .
          <source>J. ACM</source>
          <volume>23</volume>
          (
          <issue>4</issue>
          ),
          <fpage>733</fpage>
          -
          <lpage>742</lpage>
          (
          <year>1976</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Fierens</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          , den Broeck, G.V.,
          <string-name>
            <surname>Renkens</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Shterionov</surname>
            ,
            <given-names>D.S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gutmann</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Thon</surname>
            ,
            <given-names>I.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Janssens</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Raedt</surname>
          </string-name>
          , L.D.:
          <article-title>Inference and learning in probabilistic logic programs using weighted boolean formulas</article-title>
          .
          <source>TPLP</source>
          <volume>15</volume>
          (
          <issue>3</issue>
          ),
          <fpage>358</fpage>
          -
          <lpage>401</lpage>
          (
          <year>2015</year>
          ), https://doi.org/10.1017/S1471068414000076
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Kimmig</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          :
          <article-title>A Probabilistic Prolog and its Applications</article-title>
          .
          <source>Ph.D. thesis</source>
          , KU Leuven (
          <year>November 2010</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Kozen</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          :
          <article-title>Semantics of probabilistic programs</article-title>
          .
          <source>J. Comput. Syst. Sci</source>
          .
          <volume>22</volume>
          (
          <issue>3</issue>
          ),
          <fpage>328</fpage>
          -
          <lpage>350</lpage>
          (
          <year>1981</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Przymusinski</surname>
          </string-name>
          , T.C.:
          <article-title>Every logic program has a natural stratification and an iterated least fixed point model</article-title>
          .
          <source>In: PODS</source>
          . pp.
          <fpage>11</fpage>
          -
          <lpage>21</lpage>
          . ACM Press (
          <year>1989</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Sato</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          :
          <article-title>A statistical learning method for logic programs with distribution semantics</article-title>
          .
          <source>In: ICLP</source>
          . pp.
          <fpage>715</fpage>
          -
          <lpage>729</lpage>
          . MIT Press (
          <year>1995</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Sato</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kameya</surname>
            ,
            <given-names>Y.</given-names>
          </string-name>
          :
          <article-title>New advances in logic-based probabilistic modeling by PRISM</article-title>
          .
          <source>In: Probabilistic Inductive Logic Programming. Lecture Notes in Computer Science</source>
          , vol.
          <volume>4911</volume>
          , pp.
          <fpage>118</fpage>
          -
          <lpage>155</lpage>
          . Springer (
          <year>2008</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Staton</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          :
          <article-title>Commutative semantics for probabilistic programming</article-title>
          .
          <source>In: ESOP. Lecture Notes in Computer Science</source>
          , vol.
          <volume>10201</volume>
          , pp.
          <fpage>855</fpage>
          -
          <lpage>879</lpage>
          . Springer (
          <year>2017</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Tolpin</surname>
            , D., van de Meent,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Yang</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wood</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>Design and implementation of probabilistic programming language anglican</article-title>
          .
          <source>In: IFL</source>
          . pp.
          <volume>6</volume>
          :
          <fpage>1</fpage>
          -
          <lpage>6</lpage>
          :
          <fpage>12</fpage>
          .
          <string-name>
            <surname>ACM</surname>
          </string-name>
          (
          <year>2016</year>
          )
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>