Live data from Hacker News

Introduction to Datalog

x775.net

21–30 of 40 posts

Re: Introduction to Datalog

#21
post #14
post #6

Earlier quoted context omitted.

I was wondering about termination. With finite ground facts that appears not to be an issue. Complexity is another matter.

Termination is achieved in brian_cloutier's example ( https://news.ycombinator.com/item?id=19423320 ) by the use of different clauses (e.g., `Path` vs. `Edge`), so that all recursion is productive.

Datalog always terminates because there is no way to derive new atoms.

Re: Introduction to Datalog

#23

Nice post. Still, I find the most accessible article describing datalog is "What you Always Wanted to Know About Datalog (And Never Dared to Ask)." by Ceri, Gottlob, Tanca (1989)

Thanks for your feedback!

For those interested in the mentioned paper, see: https://www.utdallas.edu/~gupta/courses/acl/papers/datalog-p...

Re: Introduction to Datalog

#24
post #21
post #14

Earlier quoted context omitted.

Termination is achieved in brian_cloutier's example ( https://news.ycombinator.com/item?id=19423320 ) by the use of different clauses (e.g., `Path` vs. `Edge`), so that all recursion is productive.

Datalog always terminates because there is no way to derive new atoms.

Yes, but there's more to it than just that. It's possible to write Prolog programs which never derive new atoms yet still fail to terminate.

It might be more accurate to say that Datalog programs cannot derive new atoms and this allows Datalog interpreters to use a search strategy which is guaranteed to terminate.

EDIT: Thinking about this more, I'm not sure why Prolog couldn't also use breadth-first search. So maybe both are necessary: Datalog not only disallows creating new atoms, but it also has a better search strategy; the combination of the two results in guaranteed termination.

Re: Introduction to Datalog

#25
post #10

Thanks for sharing. There is one very significant conceptual error early on, however, and it is captured first in this statement: "The :- means if and only if, or iff". `:-` means if - or more precisely represents material conditional - where the consequent is on the left and the antecedent is on the right. iff is logical biconditional.

Indeed, ":-" is meant to represent the left-facing arrow of implication. In logic programming papers it is common to typeset it as an actual arrow, for example:

  p(X,Y) ← q(Y,X)
etc.

Re: Introduction to Datalog

#26
post #21
post #14

Earlier quoted context omitted.

Termination is achieved in brian_cloutier's example ( https://news.ycombinator.com/item?id=19423320 ) by the use of different clauses (e.g., `Path` vs. `Edge`), so that all recursion is productive.

Datalog always terminates because there is no way to derive new atoms.

My understanding is that Datalog terminates because it does not allow functions as arguments to predicates. No functions means it's not possible to create infinite terms:

  P(f(x)).
  p(f(f(x)).
  p(f(f(f(x)))).
  ... etc
In fact I understand that termination is guaranteed even if a datalog program is executed by a Prolog interpreter. Or in other words, it's a result of the language semantics, not its implementation.

(but I might be wrong about this- corrections welcome).

Re: Introduction to Datalog

#27
post #15

Earlier quoted context omitted.

Check out Datahike aswell, if you are interested in a durable datalog database. https://github.com/replikativ/datahike

Cool, ty! Seems similar to DataScript.

It’s actually a port of Datascript — consider it a durable Datascript.

Re: Introduction to Datalog

#28

Can anyone recommend any implementation of Datalog (+ negation) that is not datomic? I haven't tried datascript, which appears to support negation. Maybe I will try that if/when I revisit this interest someday.

If you're interested in experimenting with Datalog rather than necessarily writing something for production, have a look at Datalog Educational System: http://des.sourceforge.net/

Re: Introduction to Datalog

#29
post #21

Earlier quoted context omitted.

Datalog always terminates because there is no way to derive new atoms.

Yes, but there's more to it than just that. It's possible to write Prolog programs which never derive new atoms yet still fail to terminate. It might be more accurate to say that Datalog programs cannot derive new atoms and this allows Datalog interpreters to use a search strategy which is guaranteed to terminate. EDIT: Thinking about this more, I'm not sure why Prolog couldn't also use breadth-first search. So maybe…

Datalog does not have a search strategy per se. The general "strategy" (or definition) is the fixpoint of the T_p operator that derives all one-step-derivable facts from the facts and the rules.

The minimal model (result of derivation) is defined as the fixpoint of this operation. And the minimal model is finite because of the fixed number of atoms.

Every other evaluation strategy must be equivalent to this. Both in terms of termination and minimal model.

Prolog could use breadth first instead of SLD (and there are other Prolog evaluation strategies that, for example, use tabling for derived facts) but then you might get an infinite number of backtracking points instead of terms of infinite depth. You haven't really won anything by doing that.

Re: Introduction to Datalog

#30
post #21

Earlier quoted context omitted.

Datalog always terminates because there is no way to derive new atoms.

My understanding is that Datalog terminates because it does not allow functions as arguments to predicates. No functions means it's not possible to create infinite terms: P(f(x)). p(f(f(x)). p(f(f(f(x)))). ... etc In fact I understand that termination is guaranteed even if a datalog program is executed by a Prolog interpreter. Or in other words, it's a result of the language semantics, not its implementation. (but I…

You are wrong.

p(X) :- p(X). does usually not terminate in a top-down (Prolog) system but does in a bottom-up (Datalog) system. Datalog doesn't even allow terms as predicate arguments so of course you can't construct them of infinite size. But also this isn't allowed (where it is in Prolog)

p(X) :- p(Y), X is Y + 1.

Given a fact p(0) you get p(X) true for any integer X or generate all positive integers. This doesn't terminate for some binding patterns.

Post reply on HN