Does pyDatalog have a "cut" operator like prolog?

204 Views Asked by At

This may be quite simple, but i can't find the answer anywhere. In Prolog, when you want to prevent it from searching for additional answers, once a variable has already been instantiated, you can use the ! sign (usually called the "cut" sign). You can see it in this link to understand what i mean: http://www.learnprolognow.org/lpnpage.php?pagetype=html&pageid=lpn-htmlse44

for example, given the rule:

max(X,Y,Z)  :-  X  =<  Y,!,  Y  =  Z.

if we query:

max(X,Y,X).

the ! sign will prevent prolog from backtracking and trying to prove (X =< Y) by re-instantiating X. This means that all answers will have the same value for X in them.

Is there something like this in pyDatalaog?

1

There are 1 best solutions below

1
Pierre Carbonnelle On

No, it doesn't have the cut operator. Cut is not part of Datalog, in general.

However, pyDatalog stops after finding the first value for given arguments of a function. The reference page says : "a function should be defined with the most general clause first, and more specific clauses next. When querying a function, the last one is used first, and the query stops when an answer is found."

So, you may get what you need with the following definition:

+ (max[X,Y] == Y)
(max[X,Y] == X) <= (Y < X)

Note however that there is an open issue.