Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How similar are Relational Database Languages and Logic Programming?

What are the similarities and differences in terms of the fundamental concepts and implementation between a relational database language sql and a logic programming language such as prolog and clojure's core.logic? Are the two interchangeable?

like image 435
zcaudate Avatar asked Jun 29 '12 12:06

zcaudate


1 Answers

Although SQL and Prolog both demonstrate first-order logic concepts, neither is a complete implementation of the predicate calculus.

Prolog and other logic programming languages are heavily dependent on recursion, both for definition of data structures as well as for predicates.

SQL per se does not allow recursion, and the introduction of stored procedures has been done with limitations on the depth of nesting of such calls. Eg. SQL Server 2000 thru 2012 allow at most 32 nested calls.

In relational databases the "relations" are reified as tables (or more flexibly, as views). The most similar aspect of Prolog is dynamic factbases, which in some implementations (SWI, Amzi) allow indexing for performance, very similar to indexing of relational tables for performance in SQL.

Although SQL RDBMS are designed to efficiently work with much large sets of data than a Prolog implementation typically needs, Prolog can at least be used to prototype both the database and process aspects of a system design.

See here for a 2005 thesis that explores extending relational databases with Prolog inference.

like image 157
hardmath Avatar answered Sep 30 '22 19:09

hardmath