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
Computer program
(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==== [[Prolog]] (1972) stands for "PROgramming in LOGic". It is a [[logic programming]] language, based on formal [[logic]]. The language was developed by [[Alain Colmerauer]] and Philippe Roussel in Marseille, France. It is an implementation of [[SLD resolution|Selective Linear Definite clause resolution]], pioneered by [[Robert Kowalski]] and others at the [[University of Edinburgh]].<ref>{{Cite journal | publisher = Association for Computing Machinery | doi = 10.1145/155360.155362 | first1 = A. | last1 = Colmerauer | first2 = P. | last2 = Roussel | title = The birth of Prolog | journal = ACM SIGPLAN Notices | volume = 28 | issue = 3 | page = 5 | year = 1992 | url=http://alain.colmerauer.free.fr/alcol/ArchivesPublications/PrologHistory/19november92.pdf}}</ref> The building blocks of a Prolog program are ''facts'' and ''rules''. Here is a simple example: <syntaxhighlight lang=prolog> cat(tom). % tom is a cat mouse(jerry). % jerry is a mouse animal(X) :- cat(X). % each cat is an animal animal(X) :- mouse(X). % each mouse is an animal big(X) :- cat(X). % each cat is big small(X) :- mouse(X). % each mouse is small eat(X,Y) :- mouse(X), cheese(Y). % each mouse eats each cheese eat(X,Y) :- big(X), small(Y). % each big animal eats each small animal </syntaxhighlight> After all the facts and rules are entered, then a question can be asked: : Will Tom eat Jerry? <syntaxhighlight lang=prolog> ?- eat(tom,jerry). true </syntaxhighlight> The following example shows how Prolog will convert a letter grade to its numeric value: <syntaxhighlight lang="prolog"> numeric_grade('A', 4). numeric_grade('B', 3). numeric_grade('C', 2). numeric_grade('D', 1). numeric_grade('F', 0). numeric_grade(X, -1) :- not X = 'A', not X = 'B', not X = 'C', not X = 'D', not X = 'F'. grade('The Student', 'A'). </syntaxhighlight> <syntaxhighlight lang="prolog"> ?- grade('The Student', X), numeric_grade(X, Y). X = 'A', Y = 4 </syntaxhighlight> Here is a comprehensive example:<ref name="Logical English">Kowalski, R., Dávila, J., Sartor, G. and Calejo, M., 2023. Logical English for law and education. In Prolog: The Next 50 Years (pp. 287–299). Cham: Springer Nature Switzerland.</ref> 1) All dragons billow fire, or equivalently, a thing billows fire if the thing is a dragon: <syntaxhighlight lang="prolog"> billows_fire(X) :- is_a_dragon(X). </syntaxhighlight> 2) A creature billows fire if one of its parents billows fire: <syntaxhighlight lang="prolog"> billows_fire(X) :- is_a_creature(X), is_a_parent_of(Y,X), billows_fire(Y). </syntaxhighlight> 3) A thing X is a parent of a thing Y if X is the mother of Y or X is the father of Y: <syntaxhighlight lang="prolog"> is_a_parent_of(X, Y):- is_the_mother_of(X, Y). is_a_parent_of(X, Y):- is_the_father_of(X, Y). </syntaxhighlight> 4) A thing is a creature if the thing is a dragon: <syntaxhighlight lang="prolog"> is_a_creature(X) :- is_a_dragon(X). </syntaxhighlight> 5) Norberta is a dragon, and Puff is a creature. Norberta is the mother of Puff. <syntaxhighlight lang="prolog"> is_a_dragon(norberta). is_a_creature(puff). is_the_mother_of(norberta, puff). </syntaxhighlight> Rule (2) is a [[Recursion (computer science)|recursive]] (inductive) definition. It can be understood declaratively, without the need to understand how it is executed. Rule (3) shows how [[Function (computer programming)|functions]] are represented by using relations. Here, the mother and father functions ensure that every individual has only one mother and only one father. Prolog is an untyped language. Nonetheless, [[Inheritance (object-oriented programming)|inheritance]] can be represented by using predicates. Rule (4) asserts that a creature is a superclass of a dragon. Questions are answered using [[backward reasoning]]. Given the question: <syntaxhighlight lang="prolog"> ?- billows_fire(X). </syntaxhighlight> Prolog generates two answers : <syntaxhighlight lang="prolog"> X = norberta X = puff </syntaxhighlight> Practical applications for Prolog are [[knowledge representation]] and [[problem solving]] in [[artificial intelligence]].
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)