ML-KULeuven / problog

ProbLog is a Probabilistic Logic Programming Language for logic programs with probabilities.
https://dtai.cs.kuleuven.be/problog/
308 stars 36 forks source link

Invalid argument types for call to '>/2': arguments: (X1, 0), expected: (ground, ground) #20

Closed XVilka closed 5 years ago

XVilka commented 5 years ago

If I have a rule, like that:

:- use_module(library(apply)).

byte_nonzero(B, R) :-
    B > 0, R = true.
byte_nonzero_acc(B, Acc0, Acc)  :- 
    Acc0, byte_nonzero(B, Acc).
bytes_nonzero(B, R) :- 
   foldl(byte_nonzero_acc, B, true, R).

query(bytes_nonzero([10, 200, 3, 4], R)).

It will throw an error complaining of the different argument types:

Invalid argument types for call to '>/2': arguments: (X1, 0), expected: (ground, ground) at 4:7 in ./sample.pl.
VincentDerk commented 5 years ago

Thank you for opening the issue.

I might need more information on how you are performing the inference. I can not reproduce this error on my files, nor on the online editor.

https://dtai.cs.kuleuven.be/problog/editor.html#task=prob&hash=b61f2e3e4af7df334b6c12f0e1564468

VincentDerk commented 5 years ago

I assume this is the same as #18 where you got it to work?

XVilka commented 5 years ago

Ok, sorry for wrongly minizing the sample. It should be then

:- use_module(library(apply)).

byte_nonzero(B, R) :-
    B > 0, R = true.
byte_nonzero_acc(B, Acc0, Acc)  :- 
    Acc0, byte_nonzero(B, Acc).
bytes_nonzero(B, R) :- 
   foldl(byte_nonzero_acc, B, true, R).

some_sample_fact(0, [10, 20, 30], "fact1").
some_sample_fact(10, [10, 0, 30], "fact2").

some_relation(rule, Arg1) :-
   some_sample_fact(Arg1, B, _),
   call(rule, B, true).

query(some_relation(bytes_nonzero, R), some_sample_fact(A, B, C)).

But now it complains that "No clauses found for 'foldl/4'", strange.

XVilka commented 5 years ago

Nevermind, the offending predicate is:

byte_nonzero(B) :- B > 0.

If I write it in the problog shell. It is the one that cause this error:

Invalid argument types for call to '>/2': arguments: (X1, 0), expected: (ground, ground).

At the same time the similar predicate works:

byte_zero(B) :- B = 0.

Seems > operation is defined improperly? Or (more likely) I am doing this wrongly?

VincentDerk commented 5 years ago

Using

:- use_module(library(apply)).

byte_nonzero(B, R) :-
    B > 0, R = true.
byte_nonzero_acc(B, Acc0, Acc)  :- 
    Acc0, byte_nonzero(B, Acc).
bytes_nonzero(B, R) :- 
   foldl(byte_nonzero_acc, B, true, R).

some_sample_fact(0, [10, 20, 30], "fact1").
some_sample_fact(10, [10, 0, 30], "fact2").

some_relation(rule, Arg1) :-
   some_sample_fact(Arg1, B, _),
   call(rule, B, true).

in SWI-Prolog (https://swish.swi-prolog.org/) and querying for

byte_nonzero(B, true).

will result in a similar error.

XVilka commented 5 years ago

Yes, sorry for the noise, seems I got it all wrong.