(Go: >> BACK << -|- >> HOME <<)

Logic programming: Difference between revisions

Content deleted Content added
Line 474:
Interestingly, the first version of Prolog already included a constraint predicate dif(term1, term2), from Philippe Roussel's 1972 PhD thesis, which succeeds if both of its arguments are different terms, but which is delayed if either of the terms contains a variable.<ref name=":02"/>
 
The following constraint logic program represents a toy temporal database of <kbdcode>john's</kbdcode> history as a teacher:
<syntaxhighlight lang="prolog">
teaches(john, hardware, T) :- 1990 ≤ T, T < 1999.
Line 482:
rank(john, professor, T) :- 2010 ≤ T, T < 2014.
</syntaxhighlight>
Here <kbdcode>≤</kbdcode> and <kbdcode><</kbdcode> are constraint predicates, with their usual intended semantics. The following goal clause queries the database to find out when <kbdcode>john</kbdcode> both taught <kbdcode>logic</kbdcode> and was a <kbdcode>professor</kbdcode>:
<syntaxhighlight lang="prolog">
?- teaches(john, logic, T), rank(john, professor, T).
</syntaxhighlight>
The solution
<kbdcode>
2010 ≤ T, T ≤ 2012
</kbdcode>
results from simplifying the constraints
<kbdcode>
2005 ≤ T, T ≤ 2012, 2010 ≤ T, T < 2014.
</kbdcode>
 
Constraint logic programming has been used to solve problems in such fields as [[civil engineering]], [[mechanical engineering]], [[digital circuit]] verification, [[automated timetabling]], [[air traffic control]], and finance. It is closely related to [[abductive logic programming]].