Day 1
Key Points
- Logical
- Declarative
- Function (a.k.a. Clause)
- Function Body (a.k.a Predicate)
Key Terms
- Facts
- Rules
- Queries
- Knowledge Base
Loading Files
consult('lists.pl').
reconsult('lists.pl').
['lists']
['file1.pl', 'file2.pl', 'file3.pl'].
Atoms
A symbol is called an atom and begins with lowercase
Variable
Begins with uppercase
Knowledge Base
likes(wallace, cheese).
likes(grommit, cheese).
likes(wendolene, sheep).
Rules
friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).
:- To the right is a subgoal
\+ To the right is a logical negation
friend/2 with 3 Subgoals
Using Variables
food_type(velveeta, cheese).
food_type(ritz, cracker).
food_type(spam, meat).
food_type(sausage, meat).
food_type(jolt, soda).
food_type(twinkie, dessert).
flavor(sweet, dessert).
flavor(savory, meat).
flavor(savory, cheese).
flavor(sweet, soda).
food_flavor(X, Y) :- food_type(X, Z), flavor(Y, Z).
food_type(What, meat).
Using Variables
food_type(What, meat).
food_flavor(sausage, sweet).
flavor(sweet, What).
Where's the program?
Just describe your problem, let Prolog solve it!
Unification
= is the Prolog symbol for unification
cat(lion).
cat(tiger).
dorothy(X, Y, Z) :- X = lion, Y = tiger, Z = bear.
twin_cats(X, Y) :- cat(X), cat(Y).
dorothy(lion, tiger, bear).
dorothy(One, Two, Three).
twin_cats(One, Two)
Unification
twin_cats(One, Two)
How does this actually work?
Assignment
Start the Assignment
Read Day 2
Resources
- http://www.lix.polytechnique.fr/~liberti/public/computing/prog/prolog/prolog-tutorial.html
- http://www.cpp.edu/~jrfisher/www/prolog_tutorial/contents.html