Beruflich Dokumente
Kultur Dokumente
and Prolog
Danielle and Joseph Bennett 24 April 2007
The use of mathematical logic for computer programming. (Wikipedia) A declarative, relational style of programming based on first-order logic. (Dictionary.com)
Came about in 1960s and 1970s due to debates about using declarative or procedural representations in AI Stanford and Edinburgh declarative MIT - procedural
ALF CLP ECLiPSe Elf Fish Flang Gdel KLIC LIFE MONA Oz System RELFUN SAMPLE XSB Just to name a few.
&-Prolog, And-parallel Prolog. ACE, And-Or-parallel Prolog. Actor Prolog Andorra-I, an Or- and (deterministic) and-parallel Prolog. Aurora, Or-parallel Prolog. cu-Prolog, a constraint logic programming language lambda Prolog LeanTaP, a small theorem prover written in SICStus Prolog. Logtalk, an extension for Object-Oriented Programming in Prolog. Mixtus, an automatic partial evaluator for full Prolog. Muse, Or-parallel Prolog.
Developed in 1972 by Alain Colmerauer and Philippe Roussel Name comes from PROgramming in LOGic A solution to the debate about which kinds of logic to use
Prolog Structure
Prolog facts a database of predicates and associations. Prolog rules define new predicates by using Prolog facts. Note: Prolog considers capital letters to denote variables, not predicates.
A query searches the database for the first fact that satisfies its goal. If a fact is found it either unifies the variable with a constant or returns yes. If a fact is not found that meets that condition it returns no.
Use a semi-colon to request subsequent answers. In other words, a semi-colon signifies disjunction. A comma signifies conjunction.
A query resolves by unifying all of its elements. A constant unifies with itself and any variable. Scope is limited to the rule in which a variable occurs. When a variable is unified with a constant in a rule, all instances of that variable in that rule are unified to that constant.
In more complex examples, Prolog uses backtracking to find possible solutions. Prolog will attempt to resolve the first fact of its rule, unifying any variables with the first constant that satisfies that fact It then attempts to resolve the rest of that rules facts. If it is unable to do so under those conditions it backs up and tries again with the next available unifying constant.
Prolog rules can also be used write programs that do more than find the answers to simple database queries. append([], L, L). append([H|T], L, [H|L1]):-append(T, L, L1). This will append a list to another list recursively. A binary tree can be defined as follows tree(nil). tree(node(_, Left, Right):-tree(left), tree(right).
This is to say that an instructor only teaches if he teaches a class and students are enrolled in that class.
Prolog answers queries based off of the database that has been given.
?enrolled (joseph, cs365) yes ?enrolled (X, cs365) joseph danielle ?teaches (X, joseph) bebis looney yuksel
instructor (bebis, cs365) instructor (looney, cs311) instructor (yuksel, cs446) instructor (helfand, cs493) instructor (quint, math486) enrolled (ben, cs365) enrolled (bill, cs365) enrolled (bill, cs446) enrolled (brian, cs311) enrolled (brian, cs365) enrolled (brittney, cs311) enrolled (brittney, cs365) enrolled (brittney, cs446) enrolled (cody, cs311) enrolled (cody, cs365) enrolled (danielle, cs365) enrolled (danielle, cs446) enrolled (danielle, cs493) enrolled (david, cs365) enrolled (javier, cs365) enrolled (jeffrey, cs365) enrolled (jessica, cs311) enrolled (jessica, cs446) enrolled (jessica, math486)
enrolled (joel, cs365) enrolled (joseph, cs311) enrolled (joseph, cs365) enrolled (joseph, cs446) enrolled (joseph, cs493) enrolled (joseph, math486) enrolled (kellen, cs365) enrolled (matts, cs311) enrolled (matts, cs365) enrolled (mattw, cs311) enrolled (mattw, cs365) enrolled (mattw, cs446) enrolled (miran, cs365) enrolled (ryan, cs365) enrolled (samuel, cs365) enrolled (shane, cs311) enrolled (shane, cs365) enrolled (shane, cs446) enrolled (tiffany, cs311) enrolled (tiffany, cs365) enrolled (tiffany, cs446)
Sources
http://www.afm.sbu.ac.uk/logic-prog/ http://en.wikipedia.org/wiki/Logic_programming http://dictionary.reference.com/browse/logic%20program ming Pages 45-46 of our textbook CS 326 lectures on Prolog (written by Dr. Mircea Nicolescu)