[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]
Back to Logic Programming, Continued. On to Prolog, Concluded.
Held Friday, March 19
Summary
Contents
Handouts
Notes
/usr/local/bin/bp
.
http://www.binnetcorp.com/BinProlog/user.html
.pro
suffice.
[filename]
.
lou_reed
, influential
, ....
Musician
.
influencedBy(Musician,lou_reed)
.
[]
-- the empty list
[a,b,c]
-- a list of three elements
[a|X]
-- a list whose first element is a and whose
remainder is the list X.
[a,b|X]
-- a list whose first two elements are a and b and
whose remainder is the list X.
P :- Q1,Q2,...,Qn.
influential(X) :- influencedBy(X,Y).
mathlan.pro
dependsOn(church,newton). dependsOn(church,euler). dependsOn(weyl,newton). dependsOn(newton,scienceRouter). dependsOn(scienceRouter,grinnellRouter). dependsOn(euler,scienceRouter). dependsOn(grinnellRouter,hunkOcable). dependsOn(hunkOcable,iowaState).
pcof(X,Y)
holds if Y can cause X to fail.
pcof(X,Y) :- dependsOn(X,Y). pcof(X,Y) :- dependsOn(X,Z), pcof(Z,Y).
?- [mathlan].
?- pcof(church,iowaState). yes
?- pcof(iowaState,church). no
?- pcof(newton,X). X=scienceRouter; X=grinnellRouter; X=hunkOcable; X=iowaState; no
?- pcof(X,scienceRouter). X=newton; X=euler; X=church; X=church; X=weyl;
Keep track of collections of intermediate "goals" (predicates whose truth/falsity must be determined) Repeatedly Pick a goal (usually the first in the collection) Find a rule that might help solve that goal (usually the first rule whose lhs matches the goal) Determine replacements necessary to match the rule to the goal (variables to be replaced by atoms) Replace the goal in the set with the corresponding preconditions (the stuff to the right of :-, after the substition is made). If you run out of goals, the predicate holds. If you can't solve a goal, "backtrack" to try another rule.
lists.pro
.
[]
-- the empty list
[a,b,c]
-- a list of three elements
[a|X]
-- a list whose first element is a and whose
remainder is the list X.
[a,b|X]
-- a list whose first two elements are a and b and
whose remainder is the list X.
head
. Traditionally, we think of head as
removing the first element of a list. However, in Prolog, we need
to think of it as determining whether something is at the head of
the list (and then use to proof techniques to extract the head of
the list).
head(X,L) :- equal(L,[Y|YS]), equal(X,Y).
head(X,[Y|Ys]) :- equal(X,Y).
head(X,[X|XS]).
tail(XS,[X|XS]).
History
Back to Logic Programming, Continued. On to Prolog, Concluded.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Assignments] [Labs]
Disclaimer Often, these pages were created ``on the fly'' with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS302/99S/Outlines/outline.24.html
Source text last modified Mon Apr 5 14:38:01 1999.
This page generated on Wed Apr 7 12:44:23 1999 by SiteWeaver. Validate this page's HTML.
Contact our webmaster at rebelsky@math.grin.edu