Jump to content

Syntax and semantics of logic programming

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Siddharthist (talk | contribs) at 13:59, 3 March 2023 (Created page with '{{Userspace draft|source=ArticleWizard|date={{Subst:CURRENTMONTHNAME}} {{Subst:CURRENTYEAR}}}} {{Subst:Nul| ← do not change this line, it will set the date automatically}} Logic programming is a programming paradigm that includes languages based on formal logic, including Datalog and Prolog. This article describes the syntax and semantics of the purely declarative subset of these languages that consist entirely...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)


Logic programming is a programming paradigm that includes languages based on formal logic, including Datalog and Prolog. This article describes the syntax and semantics of the purely declarative subset of these languages that consist entirely of Horn clauses. Programs in the languages considered in this article consist entirely of rules of the form

h(x1, ..., xn) :- b1(y1, ..., ym), ..., bk(z1, ..., zm).

which can be read as implications

Concrete syntax

Datalog

A logic program consists of a list of rules (Horn clauses).[1] If constant and variable are two countable sets of constants and variables respectively and relation is a countable set of predicate symbols, then the following grammar expresses the structure of a logic program:

<program> ::= <rule> <program> | ɛ
<rule> ::= <atom> ":-" <atom-list> "."
<atom> ::= <relation> "(" <term-list> ")"
<atom-list> ::= <atom> | <atom> "," <atom-list>
<term> ::= <constant> | <variable>
<term-list> ::= <term> | <term> "," <term-list>
<constant-list> ::= <constant> | <constant> "," <constant-list>

Atoms are also referred to as literals. The atom to the left of the :- symbol is called the head of the rule; the atoms to the right are the body.

Rules with empty bodies are called facts. For example, the following rule is a fact:

r(x) :- .

Facts are sometimes written without the :-, like so:

r(x).

There are two common conventions for variable names: capitalizing variables, or prefixing them with a question mark ?.[2]

The set of facts is called the extensional database or EDB of the Datalog program. The tuples computed by evaluating the Datalog program is called the intensional database or IDB.

References

Notes

  1. ^ Ceri, Gottlob & Tanca 1989, p. 146.
  2. ^ Maier, David; Tekle, K. Tuncay; Kifer, Michael; Warren, David S. (2018-09-01), "Datalog: concepts, history, and outlook", Declarative Logic Programming: Theory, Systems, and Applications, vol. 20, Association for Computing Machinery and Morgan & Claypool, pp. 3–100, doi:10.1145/3191315.3191317, ISBN 978-1-970001-99-0, retrieved 2023-03-02

Sources