Work in pairs!
Two or three pages of notes on what you have learned.
These notes can be on paper or online. They can be put
on the web if you want.
End of lab
Harry Potter and the Puzzle Potions
Here is a logic puzzle.
I solve it by modeling the situation as a
list of elements and trying out various permutations to find
those that match the problem.
In the first Harry Potter book, Harry and Hermione have to solve a puzzle involving 7 potions. See [ Potions.htm ]
You can download the source code here: [ potion1.plg ] and then test it out. Note if you are running gprolog then you need [ potion1.pro ] instead.
From the Book
Try out some examples in the book on pages 211.. 218.
Some of my Examples
A Simple Data Base
I have rapidly prototyped a data base of chemical elements.
I typed in a database describing the chemical
and physical properties of the elements...(most of them).
Each element has a record structure (called element) that lists
element(Name, Symbol, Number).I also define some properties of the atomic numbers: Is the element metallic or non-metallic, and what group and period in the periodic table is assigned to the element. There also three utility commands that print information about an element: period(Atomic_number), group(Atomic_Number), and print_element(Name_of_an_element).
The data and program are in [ chem.plg ] save/download a copy of this file. Load it into Prolog and try a query:
print_element(boron).To see how this works list the prolog program:
listing(print_element).Now try the following simple searches/queries of our knowledge base:
element(boron, Symbol, Number).
element(Name, 'F', Number).
element(Name, Symbol, 14).
element(barium, 'Ba', 56).
element(hydrogen, 'H', 24).
element(hydrogen, 'H', Nbr, Rad, Class,Normally,Melt, Boil).
element(Name, _, _, radioactive, _,_,_, _).The last of these above has several answers... tap ';' to get each radioactive element in turn. Notice the wild-card variable _.
You will have a chance to fix the problems in this data base in the next lab.
How to Write Bad Science Fiction
Find, download and test out the 1950-style sci-fi
pulp-fiction processor that is in
[ story.plg ]
Note... do not take this seriously. They are intended to be
jokes parodying the popular magazines and movies
of a less enlightened century. Here
[ http://www.badmovies.org/movies/ ]
are the kind of bad movies that this little program writes
whenever you type the go. command.
How does it do it? Try
listing(go).Using 'help', 'listing', and some guessing can you see how I encoded the "structure" of these stories as a grammar?
Prolog can be used to solve puzzles where you are given a sum and all the numbers have been coded as letters. The file [ crptarth.plg ] shows a clever way to this by using the fact that Prolog variables are rather like algebraic variables. They stand for blanks that need to filled in. All you have to do is generate all the possibilities and reject the ones that do not fit the rules.
Download it and use pl to compile the program:
Look at the notes from the last lab and my handout
[ Prolog.html ]
and also Prolog's "help" and "trace" predicates.
. . . . . . . . . ( end of section CSci620 Programming Languages -- More, Prolog) <<Contents | Index>>