Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Logic programming
(section)
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!
{{short description|Programming paradigm based on formal logic}} '''Logic programming''' is a [[programming paradigm|programming]], [[database]] and [[knowledge representation]] paradigm based on formal [[logic]]. A logic program is a set of sentences in logical form, representing knowledge about some problem domain. Computation is performed by applying logical reasoning to that knowledge, to solve problems in the domain. Major logic programming language families include [[Prolog]], [[answer set programming|Answer Set Programming]] (ASP) and [[Datalog]]. In all of these languages, rules are written in the form of ''[[Clause (logic)|clauses]]'': :<code>A :- B<sub>1</sub>, ..., B<sub>n</sub>.</code> and are read as declarative sentences in logical form: :<code>A if B<sub>1</sub> and ... and B<sub>n</sub>.</code> <code>A</code> is called the ''head'' of the rule, <code>B<sub>1</sub></code>, ..., <code>B<sub>n</sub></code> is called the ''body'', and the <code>B<sub>i</sub></code> are called ''[[Literal (mathematical logic)|literals]]'' or conditions. When n = 0, the rule is called a ''fact'' and is written in the simplified form: :<code>A.</code> Queries (or goals) have the same syntax as the bodies of rules and are commonly written in the form: :<code>?- B<sub>1</sub>, ..., B<sub>n</sub>.</code> In the simplest case of [[Horn clause]]s (or "definite" clauses), all of the A, B<sub>1</sub>, ..., B<sub>n</sub> are [[atomic formula]]e of the form p(t<sub>1</sub> ,..., t<sub>m</sub>), where p is a predicate symbol naming a relation, like "motherhood", and the t<sub>i</sub> are terms naming objects (or individuals). Terms include both constant symbols, like "charles", and variables, such as X, which start with an upper case letter. Consider, for example, the following Horn clause program: <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). grandparent_child(X, Y) :- parent_child(X, Z), parent_child(Z, Y). </syntaxhighlight> Given a query, the program produces answers. For instance for a query <code>?- parent_child(X, william)</code>, the single answer is <syntaxhighlight lang="prolog"> X = charles </syntaxhighlight> Various queries can be asked. For instance the program can be queried both to generate grandparents and to generate grandchildren. It can even be used to generate all pairs of grandchildren and grandparents, or simply to check if a given pair is such a pair: <syntaxhighlight lang="prolog"> grandparent_child(X, william). X = elizabeth ?- grandparent_child(elizabeth, Y). Y = william; Y = harry. ?- grandparent_child(X, Y). X = elizabeth Y = william; X = elizabeth Y = harry. ?- grandparent_child(william, harry). no ?- grandparent_child(elizabeth, harry). yes </syntaxhighlight> Although Horn clause logic programs are [[Turing completeness|Turing complete]],<ref>{{cite journal |last=Tärnlund |first=S.Å. |date=1977 |title=Horn clause computability |journal=[[BIT Numerical Mathematics]] |volume=17 |issue=2 |pages=215–226 |doi=10.1007/BF01932293|s2cid=32577496 }}</ref><ref>{{cite journal |last1=Andréka |first1=H. |last2=Németi |first2=I. |date=1978 |title=The generalised completeness of Horn predicate-logic as a programming language |url=https://cyber.bibl.u-szeged.hu/index.php/actcybern/article/view/3160 |journal=Acta Cybernetica |volume=4 |issue=1 |pages=3–10}}</ref> for most practical applications, Horn clause programs need to be extended to "normal" logic programs with negative conditions. For example, the definition of sibling uses a negative condition, where the [[Predicate (mathematical logic)|predicate]] = is defined by the clause <code> X = X </code>: <syntaxhighlight lang="prolog"> sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y), not(X = Y). </syntaxhighlight> Logic programming languages that include negative conditions have the knowledge representation capabilities of a [[non-monotonic logic]]. In ASP and Datalog, logic programs have only a [[Declarative programming|declarative]] reading, and their execution is performed by means of a proof procedure or model generator whose behaviour is not meant to be controlled by the programmer. However, in the Prolog family of languages, logic programs also have a [[Procedural programming|procedural]] interpretation as goal-reduction procedures. From this point of view, clause A :- B<sub>1</sub>,...,B<sub>n</sub> is understood as: :to solve <code>A</code>, solve <code>B<sub>1</sub></code>, and ... and solve <code>B<sub>n</sub></code>. Negative conditions in the bodies of clauses also have a procedural interpretation, known as ''[[negation as failure]]'': A negative literal <code> not B</code> is deemed to hold if and only if the positive literal <code> B</code> fails to hold. Much of the research in the field of logic programming has been concerned with trying to develop a logical semantics for negation as failure and with developing other semantics and other implementations for negation. These developments have been important, in turn, for supporting the development of [[formal methods]] for logic-based [[Formal verification|program verification]] and [[program transformation]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)