ML-KULeuven / problog

ProbLog is a Probabilistic Logic Programming Language for logic programs with probabilities.

Home Page:https://dtai.cs.kuleuven.be/problog/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistent integer casting

EdGaere opened this issue · comments

May have found a bug, casting to an integer is inconsitent and error prone. Consider this simple example:

Let's create a trivial function that evaluates if X <= 99

lte_99(X) :- intgr(X) @=< intgr(99) .

Now we call our function with value 100

query(lte_99(100)) .

Output

lte_99(100):	1   <-- ?? Expected 0

Workaround is wordy... but works.

query(lte_99(intgr(100))) .

Workaround output

lte_99(intgr(100)):	0  <-- OK

Conclusion: Explicit casting to intgr should not be necessary as it's performed in lte_99

problog==2.2.2
Python 3.8.3

This does not seem te be a bug. The problem originates from

  1. Casting to integer is done using the integer/1 functor, not intgr
  2. The reason that ProbLog doesn't complain is that you're using @=< instead of =<. The former is a struct comparison. So in the first case you're performing a structured comparison.
    a(X) @=< a(99)
    which is true since variables are considered smaller than numbers w.r.t. the standard order of terms, and in the second case
    a(a(X)) @=< a(99) which is considered false, since a compound term is considered larger than a number.

`lte_99(X) :- integer(X) =< integer(99) .

query(lte_99(100)) .`
Results in the desired behaviour.

Hi Robin - Thank so much for the explanations, indeed this solves my problem. Sorry for having reported this as a bug.

As a suggestion, perhaps provide basic arithmetic examples on the web page / getting started ? problog is so powerful, yet so confusing for newbies.

integer(X) =< integer(99) .

Thanks again
Edward

Hi Edward

Thanks for your suggestion, I've added it to our list of future work.