6500 Programming Languages. What is Prolog? Great Prolog Tutorials. Lets look at a sample session

Prolog Download Binaries and Source !  CSCI: 4500/6500 Programming Languages SWI-prolog (swipl 5.10.4-6.0.2 depending on platform) website: »  http...
10 downloads 2 Views 923KB Size
Prolog Download Binaries and Source

! 

CSCI: 4500/6500 Programming Languages

SWI-prolog (swipl 5.10.4-6.0.2 depending on platform) website: »  http://www.swi-prolog.org/! »  Mac OS X on Intel & PPC (Tiger, Leopard (46.3 MB), Snow Leopard and Lion binaries available) »  Linux RPMs.

Prolog & Logic Programming

»  Windows NT, XP, Vista7, 2000, 64 Bit, »  Source Install ! 

Thanks to: William W. Clocksin, Oxford University, UK.,Jason Eisner, John Hopkins University, James Lu & Jerud Mead, Bucknell University.

1

Maria Hybinette, UGA

XQuartz (X11) 2.5.0 for help & development tools. 2

Maria Hybinette, UGA

Great Prolog Tutorials ! 

What is Prolog?

JR Fisher s original tutorial :

http://www.csupomona.edu/~jrfisher/www/ prolog_tutorial/contents.html ! 

! 

Roman Barták s interactive tutorial:

»  With help from theorem proving folks such as Robert Kowalski »  Colmerauer & Roussel wrote 20 years later:

http://ktiml.mff.cuni.cz/~bartak/prolog/ ! 

Mike Rosner s crash course:

http://www.cs.um.edu.mt/~mros/prologcc/ ! 

Alain Colmeraeur & Philippe Roussel, 1971-1973

James Lu and Jerud Mead s tutorial:

Prolog is so simple that one has the sense that sooner or later someone had to discover it … that period of our lives remains one of the happiest in our memories.

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

James Power s tutorial: http://www.cs.nuim.ie/~jpower/Courses/ PROLOG/ (2012 not available – BUT let me know if you find it –it is a good one) 3

Maria Hybinette, UGA

What is Prolog? ! 

Lets look at a sample session… {saffron:ingrid:815} swipl

A declarative or logic programming language

Welcome to SWI-Prolog (Multi-threaded, Version 5.6.9) Copyright (c) 1990-2006 University of Amsterdam.

»  specifies the results (describes what the results look like)

SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details.

–  in contrast to a procedure on how to produce the results. ! 

For help, use ?- help(Topic). or ?- apropos(Word).

Based on first order predicate calculus

?- [ second']. % first compiled 0.00 sec, 596 bytes

»  consists of propositions that may or may not be true ! 

CTRL-p moves up in command history CTRL-n next command -> edit command line history

»  Not the same as variables in other languages

Maria Hybinette, UGA

repeat commands by traversing the command line history

TailReverse!

reverse([],[]). reverse([Head|Tail],X) :reverse(Tail,Y), append(Y,[Head],X). Maria Hybinette, UGA

125

Maria Hybinette, UGA

solve [reverse([2],Y),

nothing

append(Y,[1],X)] solve [reverse([],X),

nothing

append(X,[2],X), append(X,[1],X)]

solve [append([],[2],[]),

append([],[1],[])]

nothing

nothing

126

Deficiencies of Prolog solve [reverse([1,2],X)]

This step is wrong: we substituted X for Y, but there is already a different X elsewhere in the goal list.

nothing

solve

[ reverse([2],Y)! append(Y1,[1],X1)]!

nothing

solve [ reverse([],Y2)!

append(Y2,[2],X2)]! append(X2,[1],X1)]! solve [append([],[2],X2),!

reverse([],[]). reverse([Head|Tail],X) :reverse(Tail,Y), append(Y,[Head],X).

! 

Resolution order control

! 

The closed-world assumption

! 

The negation problem

! 

Intrinsic limitations

nothing

append(X2,[1],X1)]!

[append([2],[1],X1)]!

solve Maria Hybinette, UGA

[]!

127

Advantages: ! 

Prolog programs based on logic, so likely to be more logically organized and written

! 

Processing is naturally parallel, so Prolog interpreters can take advantage of multiprocessor machines

! 

SWI-Prolog ?- set_prolog_flag(history, 50). Yes 27 ?- h.

129

% shows history of commands

2

eats(Person1,Food1).

3 4

eats(Person1,Food),eats(Person2,Food). eats(corey,fish).

?- !!.

Programs are concise, so development time is decreased – good for prototyping

Maria Hybinette, UGA

128

Maria Hybinette, UGA

Maria Hybinette, UGA

% Repeats last query

130