PDA

View Full Version : about Prolog



zak
14-04-2011, 10:59
prolog is an old programming language, a few sentences from "Logic Programming with Prolog" / Max Bramer:
The style of programming called procedural corresponds closely to
the way computers are generally built.
The way users write programs should depend as little as possible on how the underlying machine was built and as much as possible on what the user is trying to do
Prolog lends itself to a style of programming making particular use of two powerful techniques recursion and list processing.
i was planning to post about the subject after finishing a few chapters but i may took ages to finish chapter 2, so this is an early notes.
the best freeware prolog interpreter is from
http://www.swi-prolog.org/index.html
install it first (accept pl as an extension even it is used by perl) then download an IDE from :
http://lakk.bildung.hessen.de/netzwerk/faecher/informatik/swiprolog/indexe.html
there is an example in the "c:\program files\pl\demo\likes.pl" demonstrate first encounter with prolog:

likes(sam,Food) :-
indian(Food),
mild(Food).
likes(sam,Food) :-
chinese(Food).
likes(sam,Food) :-
italian(Food).
likes(sam,chips).
indian(curry).
indian(dahl).
indian(tandoori).
indian(kurma).
mild(dahl).
mild(tandoori).
mild(kurma).
chinese(chow_mein).
chinese(chop_suey).
chinese(sweet_and_sour).
italian(pizza).
italian(spaghetti).

from the IDE click start->consult, then in the bottom command pane write:
likes(sam,pizza).
and it will answer true, don't forget the full stop "." after your question and without space between "." and the question.
write:
likes(sam,curry).
answer false. i guess because in:
likes(sam,Food) :-
indian(Food),
mild(Food).
the condition is that: sam likes intersection between indian food and mild food, he don't like hot food, so curry abandoned. "," serve as "AND" .
write:
likes(sam,X).
remember that chars begins with upper case letters serve as variable
the first answer:
X = dahl
now to proceed to the second food press ";"
if you want to print all food which sam likes write:
likes(sam,X),write(' '),write(X),fail.
or:
likes(sam,X),nl,write(X),fail.
answer:
dahl tandoori kurma chow_mein chop_suey sweet_and_sour pizza spaghetti chips
false.
so there is a continuous backtracking until we reach "false" condition.
now look at factorial program:

factorial(0,1).
factorial(N,F) :-
N>0,
N1 is N-1,
factorial(N1,F1),
F is N * F1.
after consulting it, write:
factorial(50,X).
answer 30414093201713378043612608166064768844377641568960512000000000000
but i don't know how to measure Timing yet.
just notes about how to load a program from command pane:
['c:/demo/factor.pl'].
or ['c:\\demo\\factor.pl'].
or consult('c:/demo/factor.pl').

references:
tutorial:
1- http://boklm.eu/prolog/
2- book: "Logic Programming with Prolog" / Max Bramer
3- http://www.softwareforeducation.com/tutorials/Prolog/
4- http://www.thefreecountry.com/documentation/onlineprolog.shtml
5- snippets:http://www.mindpicnic.com/cardbox/prolog-snippets/
6- LPA Win-Prolog Goodies:
http://colin.barker.pagesperso-orange.fr/lpa/lpa.htm

compilers: ( i havn't tried it yet)
http://www.ciaohome.org/
seems good but install first emacs from:
http://www.ourcomments.org/cgi-bin/emacsw32-dl-latest.pl (29MB)
http://www.gprolog.org/ gnu prolog
http://www.ncc.up.pt/~vsc/Yap/ (yet another prolog)

danbaron
14-04-2011, 23:31
IBM --> Watson:

http://www.cs.nmsu.edu/ALP/2011/03/natural-language-processing-with-prolog-in-the-ibm-watson-system/

Visual Prolog:

http://www.visual-prolog.com/default.htm

Books:

http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dstripbooks&field-keywords=prolog+language&x=0&y=0&ajr=6

http://www.amazon.com/Learn-Prolog-Texts-Computing-Vol/dp/1904987176/ref=pd_sim_b_2

http://www.amazon.com/Programming-Artificial-Intelligence-International-Computer/dp/0321417461/ref=sr_1_1?s=books&ie=UTF8&qid=1302815813&sr=1-1

http://www.amazon.com/Craft-Prolog-Logic-Programming/dp/0262512270/ref=pd_sim_b_1

http://www.amazon.com/Programming-Prolog-Using-ISO-Standard/dp/3540006788/ref=sr_1_2?s=books&ie=UTF8&qid=1302815482&sr=1-2

http://www.amazon.com/Practice-Prolog-Logic-Programming/dp/0262514451/ref=pd_sim_b_5

http://www.freebookcentre.net/Language/Free-Prolog-Books-Download.html

Tutorials:

http://www.bitwisemag.com/copy/programming/prolog/intro/firststeps.html

http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/pt_framer.html (http://www.csupomona.edu/%7Ejrfisher/www/prolog_tutorial/pt_framer.html)

http://www.learnprolognow.org/

http://www.lix.polytechnique.fr/~liberti/public/computing/prog/prolog/prolog-tutorial.html (http://www.lix.polytechnique.fr/%7Eliberti/public/computing/prog/prolog/prolog-tutorial.html)

http://www.soe.ucsc.edu/classes/cmps112/Spring03/languages/prolog/PrologIntro.pdf

[/URL][URL]http://www.amzi.com/articles/prolog_books_tutorials.htm (http://boklm.eu/prolog/page_0.html)