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

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Applications Computational LogicLecture 11 Michael Genesereth Spring 2004.
Bellwork If you roll a die, what is the probability that you roll a 2 or an odd number? P(2 or odd) 2. Is this an example of mutually exclusive, overlapping,
Chapter 5: Control Structures II (Repetition)
1 Knowledge Representation Introduction KR and Logic.
Artificial Intelligence: Natural Language and Prolog
Inference in First-Order Logic
Chapter 6 Cost and Choice. Copyright © 2001 Addison Wesley LongmanSlide 6- 2 Figure 6.1 A Simplified Jam-Making Technology.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Peer-to-peer and agent-based computing Basic Theory of Agency.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
Formal Models of Computation Part II The Logic Model
CS4026 Formal Models of Computation Part II The Logic Model Lecture 6 – Arithmetic, fail and the cut.
Lecture 10 Flow of Control: Loops (Part 2) COMP1681 / SE15 Introduction to Programming.
ZMQS ZMQS
Richmond House, Liverpool (1) 26 th January 2004.
Introduction A function is called higher-order if it takes a function as an argument or returns a function as a result. twice :: (a  a)  a  a twice.
Artificial Intelligence
First-Order Logic.
Randomized Algorithms Randomized Algorithms CS648 1.
0 PROGRAMMING IN HASKELL Chapter 5 - List Comprehensions.
ABC Technology Project
Logic Programming Two possible work modes: 1.At the lab: Use SICstus Prolog. To load a prolog file (*.pl or *.pro extension) to the interpreter, use: ?-
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
Squares and Square Root WALK. Solve each problem REVIEW:
Getting started with Prolog
Logic Programming Lecture 1: Course orientation; Getting started with Prolog.
1 Logic Programming Technical Foundation Second part of Cmput325 Fall 2004 R Greiner + B Price.
Logic Programming Lecture 1: Getting started. Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines
C-LISP. LISP 2 Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT).John McCarthyMassachusetts Institute.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Query Answering for OWL-DL with Rules Boris Motik Ulrike Sattler Rudi Studer.
Lecturer: Dr. Abeer Mahmoud Logic Programming in Prolog.
Addition 1’s to 20.
25 seconds left…...
Test B, 100 Subtraction Facts
Week 1.
We will resume in: 25 Minutes.
TASK: Skill Development A proportional relationship is a set of equivalent ratios. Equivalent ratios have equal values using different numbers. Creating.
How Cells Obtain Energy from Food
Prolog.1 Prolog. Prolog.2 Textbook and Software  Title PROLOG programming for artificial intelligence  Author Ivan Bratko  Get the software – windows.
Prolog.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Formal Models of Computation Part II The Logic Model
Artificial Intelligence Programming in Prolog Lecture 1: An Introduction 23/09/04.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
Intelligent Architectures for Electronic Commerce Prolog/JADE Tutorial.
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
CSE 341, S. Tanimoto Logic Programming -
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Presentation transcript:

Intelligent Architectures for Electronic Commerce A (Brief) Prolog Tutorial

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

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…

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

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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.

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

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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.

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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), ) ?

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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, )

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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).

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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]

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

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

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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)

Intelligent Architectures for Electronic Commerce Timothy J Norman and Wamberto Vasconcelos 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.