Search code examples
databaselogicdatalog

Not-safe expression in datalog


Why is this goal not considered safe?

MANAGER(Name) :- WORKER(Name, Age, _ ), ¬ SUBORDINATE (_, Name), Age <= 40

Our teacher says that it is because SUBORDINATE is negate, and so it can not have undefined (_) spaces, but it seems to be logic for me this expression. Anyone that can help me?


Solution

  • The safety requirements in Datalog are intended to prevent infinite results. If you have a variable that occurs in the head and only negated in the body, then it can be bound to infinitely many values, which would obviously be a problem.

    The specific requirements for safety are hard to precisely formulate, so usually you see the requirements simplified to 'every variable has to occur positively'. This is a bit more restrictive than needed.

    The most informative answer to the question would be that the rule is technically unsafe, but that it does not have an infinite result. Some Datalog engines would allows this rule and return the finite result.