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!
===Prolog=== {{Main|Prolog}} The SLD resolution rule of inference is neutral about the order in which subgoals in the bodies of clauses can be ''selected'' for solution. For the sake of efficiency, Prolog restricts this order to the order in which the subgoals are written. SLD is also neutral about the strategy for searching the space of SLD proofs. Prolog searches this space, top-down, depth-first, trying different clauses for solving the same (sub)goal in the order in which the clauses are written. This search strategy has the advantage that the current branch of the tree can be represented efficiently by a [[Stack (abstract data type)|stack]]. When a goal clause at the top of the stack is reduced to a new goal clause, the new goal clause is pushed onto the top of the stack. When the selected subgoal in the goal clause at the top of the stack cannot be solved, the search strategy ''[[Backtracking|backtracks]]'', removing the goal clause from the top of the stack, and retrying the attempted solution of the selected subgoal in the previous goal clause using the next clause that matches the selected subgoal. Backtracking can be restricted by using a subgoal, called ''[[Cut (logic programming)|cut]]'', written as !, which always succeeds but cannot be backtracked. Cut can be used to improve efficiency, but can also interfere with the logical meaning of clauses. In many cases, the use of cut can be replaced by negation as failure. In fact, negation as failure can be defined in Prolog, by using cut, together with any literal, say ''fail'', that unifies with the head of no clause: <syntaxhighlight lang="prolog"> not(P) :- P, !, fail. not(P). </syntaxhighlight> Prolog provides other features, in addition to cut, that do not have a logical interpretation. These include the built-in predicates ''assert'' and ''retract'' for destructively updating the state of the program during program execution. For example, the [[#Knowledge representation|toy blocks world example above]] can be implemented without frame axioms using destructive change of state: <syntaxhighlight lang="prolog"> on(green_block, table). on(red_block, green_block). move(Object, Place2) :- retract(on(Object, Place1)), assert(on(Object, Place2). </syntaxhighlight> The sequence of move events and the resulting locations of the blocks can be computed by executing the query: <syntaxhighlight lang="prolog"> ?- move(red_block, table), move(green_block, red_block), on(Object, Place). Object = red_block, Place = table. Object = green_block, Place = red_block. </syntaxhighlight> Various extensions of logic programming have been developed to provide a logical framework for such destructive change of state.<ref name="TL">Bonner, A.J. and Kifer, M., 1993, February. Transaction Logic Programming. In ICLP (Vol. 93, pp. 257-279).</ref><ref>Genesereth, M., 2023. Dynamic logic programming. In Prolog: The Next 50 Years (pp. 197-209). Cham: Springer Nature Switzerland.</ref><ref>Kowalski, R., Sadri, F., Calejo, M. and Dávila, J., 2023. Combining logic programming and imperative programming in LPS. In Prolog: The Next 50 Years (pp. 210-223). Cham: Springer Nature Switzerland.</ref> The broad range of Prolog applications, both in isolation and in combination with other languages is highlighted in the Year of Prolog Book,<ref name="Prolog Book"/> celebrating the 50 year anniversary of Prolog in 2022. Prolog has also contributed to the development of other programming languages, including [[Algebraic Logic Functional programming language|ALF]], [[Fril]], [[Gödel (programming language)|Gödel]], [[Mercury programming language|Mercury]], [[Oz (programming language)|Oz]], [[Ciao (programming language)|Ciao]], [[Visual Prolog]], [[XSB]], and [[λProlog]].
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)