Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intelligent Architectures for Electronic Commerce A (Brief) Prolog Tutorial.

Similar presentations


Presentation on theme: "Intelligent Architectures for Electronic Commerce A (Brief) Prolog Tutorial."— Presentation transcript:

1 Intelligent Architectures for Electronic Commerce A (Brief) Prolog Tutorial

2 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 2 Overview 1.Introduction 2.Syntax (the shape of Prolog programs) 3.Semantics (the meaning of Prolog programs) 4.Pragmatics (how to write Prolog programs) 5.Practicalities 6.Reading List

3 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 3 1. Introduction Prolog: –PROgramming (in) LOGic –logic + control = program –results/behaviour obtained as a proof This tutorial: –quick look over essential issues –not exhaustive, not authoritative –wont be enough to write very clever agents in Prolog, but hopefully will help! –is idiosyncratic…

4 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 4 2. Syntax Prolog programs are made up of –facts –clauses And these are made up of –atoms –variables –terms

5 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 5 2.1 Atoms Atoms are the most essential components. Numbers are atoms. Strings starting with small letter are atoms. Strings within single quotes are atoms. Examples: freddie 123 car sam umbrella 123

6 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 6 2.2 Variables Variables are: –any string starting with capital letter, or –any string starting with _ (underscore) Variables are untyped. Variables are defined at run-time (no need to declare). Examples A Var1 Freddie Xs

7 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 7 2.3 Terms Structure with atoms and variables. General format: atomNotNumber ( AtomOrVar, …, AtomOrVar ) Examples: p(23,rover) owns(sam,X,23) Terms can be nested: odd(p(23,rover),owns(sam,X,23)) Terms are used to build data structures.

8 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 8 2.4 Facts Facts are terms asserted as true. Examples owns(freddie,car). owns(sam,X). Period. indicates end of fact. No intrinsic meaning.

9 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 9 2.5 Clauses General format: Term :- Term,…, Term. Examples rich(X):- owns(X,house),owns(X,car). siblings(X,Y):- mother(X,Z),mother(Y,Z). Period. indicates end of clause. Clauses are also known as rules. Terms of clauses also called goals or literals. head body

10 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 10 2.5 Editing Programs Create a file with extension.pl Type in your program (facts and rules). Do not forget the. !! Save your file. Load your file in a Prolog session. Always make sure you save and re-load files.

11 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 11 3. Semantics Meaning of program defined by its inferences Scenario: –given a program, try to prove if goal P is true P –goal P is also called a query –queries may also be a conjunction of goals: P 1, P 2, …, P n Essential concepts: –unification –resolution

12 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 12 3.1 Unification Process of making two or more terms equal. Variables are assigned values (computation!) Examples: –rich(X) unifies with rich(tom) if X = tom –rich(tom) doesnt unify with rich(abe) Not always possible! Unification problem: find values for variables to make terms equal

13 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 13 3.1 Unification (Contd) Unification also obtains a substitution –set of pairs Variable /Term = { A / a, B / f(1) } –apply it by replacing Variable by Term: p(A,B) = p(a,f(1)) unify(TermLeft,TermRight, ) iff TermLeft = TermRight

14 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 14 3.1 Unification (Contd) More examples: –unify( p(a,q(X,X),t),p(Y,q(a,a),B), ) ? –unify( q(b,c(d)), X, ) ? –unify( s(f(1,2),X),s(f(X,C),1), ) ?

15 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 15 3.2 Resolution process to prove if P resolution(,P, ) iff P : 1.resolution(,P, ) if Q and unify(P,Q, ) 2.resolution(,P, ) if (Q :- R 1,…, R n ) and unify(P,Q, ) and resolution(, (R 1,…, R n ), ) 3.resolution(, (R 1,…, R n ), ) if resolution(,R 1, 1 ) and resolution(,(R 2,…, R n ) 1, )

16 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 16 3.2 Resolution (Contd) Prolog: clauses/facts are chosen top-down. Prolog tries different clauses and facts. example: mother(john,barbara). father(john,philip). mother(mary,barbara). father(mary,philip). parent(X,Y):- mother(X,Y). parent(X,Y):- father(X,Y). siblings(X,Y):- parent(X,P),parent(Y,P). ?- siblings(john,mary).

17 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 17 4. Pragmatics recursive data structures lists: dynamic allocation sequence of elements within [ and ] examples: [1,2,rtu] [hello,(p(X):-q(X)),[4]] generic way to break list: head and tail –[1,2,rtu] = [Head|Tail] Head = 1 Tail = [2,rtu]

18 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 18 4. Pragmatics (Contd) example: creation of list create([X|Xs]):- read(X), \+ X = stop, create(Xs). create([]).

19 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 19 4. Pragmatics (Contd) generic agent loop(MntlSt):- final_condition(MntlSt). loop(MntlSt):- senseEnvironment(Percepts), react(Percepts,MntlSt,NewMntlSt), loop(MntlSt).

20 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 20 5. Practicalities CIAO Prolog: free, efficient. Emacs: integrated editor. Dowload and install them. Loop: edit-load-run (be careful!) Debugging is possible and useful CIAO Prolog talks to JAVA (and hence JADE)

21 Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 21 6. Reading List Bratko, I (2001). Prolog Programming for Artificial Intelligence, 3 rd Edition, Addison- Wesley. Stirling, L & Shapiro, E (1997). The Art of Prolog, 2 nd Edition, MIT Press.


Download ppt "Intelligent Architectures for Electronic Commerce A (Brief) Prolog Tutorial."

Similar presentations


Ads by Google