Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Logic programming
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Datalog === {{Main|Datalog}} Datalog is a database definition language, which combines a relational view of data, as in [[relational database]]s, with a logical view, as in logic programming. Relational databases use a relational calculus or relational algebra, with [[Relational database#Relational operations|relational operations]], such as ''union'', ''intersection'', ''set difference'' and ''cartesian product'' to specify queries, which access a database. Datalog uses logical connectives, such as ''or'', ''and'' and ''not'' in the bodies of rules to define relations as part of the database itself. It was recognized early in the development of relational databases that recursive queries cannot be expressed in either relational algebra or relational calculus, and that this defficiency can be remedied by introducing a least-fixed-point operator.<ref>Aho, A.V. and Ullman, J.D., 1979, January. Universality of data retrieval languages. In Proceedings of the 6th ACM SIGACT-SIGPLAN symposium on Principles of programming languages (pp. 110-119).</ref><ref>Maier, D., Tekle, K.T., Kifer, M. and Warren, D.S., 2018. Datalog: concepts, history, and outlook. In Declarative Logic Programming: Theory, Systems, and Applications (pp. 3-100).</ref> In contrast, recursive relations can be defined naturally by rules in logic programs, without the need for any new logical connectives or operators. Datalog differs from more general logic programming by having only constants and variables as terms. Moreover, all facts are variable-free, and rules are restricted, so that if they are executed bottom-up, then the derived facts are also variable-free. For example, consider the family database: <syntaxhighlight lang="prolog"> mother_child(elizabeth, charles). father_child(charles, william). father_child(charles, harry). parent_child(X, Y) :- mother_child(X, Y). parent_child(X, Y) :- father_child(X, Y). ancestor_descendant(X, Y) :- parent_child(X, X). ancestor_descendant(X, Y) :- ancestor_descendant(X, Z), ancestor_descendant(Z, Y). </syntaxhighlight> Bottom-up execution derives the following set of additional facts and terminates: <syntaxhighlight lang="prolog"> parent_child(elizabeth, charles). parent_child(charles, william). parent_child(charles, harry). ancestor_descendant(elizabeth, charles). ancestor_descendant(charles, william). ancestor_descendant(charles, harry). ancestor_descendant(elizabeth, william). ancestor_descendant(elizabeth, harry). </syntaxhighlight> Top-down execution derives the same answers to the query: <syntaxhighlight lang="prolog"> ?- ancestor_descendant(X, Y). </syntaxhighlight> But then it goes into an infinite loop. However, top-down execution with [[Tabled logic programming|tabling]] gives the same answers and terminates without looping.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Logic programming
(section)
Add topic