Presentation is loading. Please wait.

Presentation is loading. Please wait.

ARTIFICIAL INTELLIGENCE LAB UCEL601 ( Second Term) Presented by Nirmala 1.

Similar presentations


Presentation on theme: "ARTIFICIAL INTELLIGENCE LAB UCEL601 ( Second Term) Presented by Nirmala 1."— Presentation transcript:

1 ARTIFICIAL INTELLIGENCE LAB UCEL601 (2017-2018 Second Term) Presented by Nirmala Shinde(nirmalashinde@somaiya.edu) 1

2 Outline SWI-Prolog Setup IDE Prolog Basic 2

3 SWI-Prolog 1. Download http://www.swi-prolog.org/download/stable (Official) http://www.swi-prolog.org/download/stable http://portableapps.com/apps/development/swi-prolog_portable (Portable) http://portableapps.com/apps/development/swi-prolog_portable 2. After installation, open 3 User query and interpreter output

4 Your First Prolog Program 4

5 Create and Consult 5 Consult Save (Ctrl-S)

6 Query 6 Have I taken the course wp? What courses have I taken? Press. to end the query Press ; to backtrack Have I taken the course wp1?

7 Modify Prolog File Editor Use Compile buffer to consult the whole Prolog file again and update the Prolog database Use Consult selection to consult the Prolog file partially Highlight when there is syntax error Query Window Use Reload modified files to reload the whole Prolog file (useful when you are using other editors) 7 New fact

8 1. Prolog Basics An atom is a bunch of alphanumeric characters (the underscore character( _) is also treated as an alphanumeric character), starting with a lowercase letter.Some atoms are constants, while others are predicates. A variable is a bunch of alphanumeric characters, starting with a capital letter or the bottom line character ( _ ). In Prolog, variables and constants need not be declared. Constants and variables are called terms. Uppercase and lowercase letters are different in Prolog. In addition to atoms and variables, Prolog can handle numbers as well. 8

9 1. Prolog Basics 9 Non-variable Atomic Atom Number Compound Variable csci3230 dept [] 100 f(f(a),f(X)) [1, 2, 3, 4] [[eric, kate], [[peter, mary]] X Csci3230 Dept (Person,Food) Terms: Data Objects

10 1. Prolog Basics: Fact Facts should always begin with a lowercase letter and end with a full stop. The facts themselves can consist of any letter or number combination, as well as the underscore _ character. However, names containing the characters -,+,*,/, or other mathematical operators should be avoided. Examples of Simple Facts john_is_cold. /* john is cold */ raining. /* it is raining */ fred_lost_his_car_keys. /* fred lost is car keys */ peter_footballer. /* peter plays football */ 10

11 1. Prolog Basics: Fact More complicated facts consist of a relation and the items that this refers to. These items are called arguments. Facts can have arbitrary number of arguments from zero upwards. A general model is shown below: relation(,,...., ). Example eats(fred,oranges). /* "Fred eats oranges" */ eats(fred,t_bone_steaks). /* "Fred eats T-bone steaks" */ eats(tony,apples). /* "Tony eats apples" */ 11

12 1. Prolog Basics: Fact 12 Example 1 %Fact leo_is_handsome. %Fact_with_Arguments handsome(leo). ?- leo_is_handsome. true. ?- leo_is_not_handsome. ERROR: Undefined procedure: leo_is_not_handsome/0 ?- handsome(leo). true. ?- handsome(tom). false. ?- handsome(X). X = leo.

13 Statements FACTS states a predicate holds between terms. 13 Example 2 father(harry,james).%Fact 1 mother(harry,lily).%Fact 2 ?- father(harry,james). true.

14 1. Prolog Basics: Variable 14 Example 1 %Fact_with_Arguments_including_atom_and_number age(leo, 26). age(sun, 26). age(peter, 27). ?- age(leo, 26). true. ?- age(leo, 16). false. ?- age(X, 26). X = leo; X = sun.

15 1. Prolog Basics: Variable 15 Example 1 %Fact_with_Arguments_including_atom_and_number age(leo, 26). age(sun, 26). age(peter, 27). ?- age(X, Y). X = leo, Y = 26 ; X = sun, Y = 26 ; X = peter, Y = 27.

16 1. Prolog Basics: Rule Rules allow us to make conditional statements about our world. Each rule can have several variations, called clauses. These clauses give us different choices about how to perform inference about our world. 16

17 1. Prolog Basics: Rule 17 %Rules_Examples likes(mary,apple). likes(mary,orange). likes(mary,lemon). likes(tom,X):-likes(mary,X). ?- likes(mary,apple). true. ?- likes(tom,apple). true. ?- likes(tom,banana). false. If

18 1. Prolog Basics: Rule 18 %Rules_Examples likes(mary,apple). likes(mary,orange). likes(mary,lemon). likes(tom,X):-likes(mary,X). likes(kate,grape). likes(kate,orange). taste(F):-likes(mary,F);likes(kate,F). buy(F):-likes(mary,F),likes(kate,F). ?- taste(apple). true. ?- buy(apple). false. ?- buy(orange). true. Or And

19 1. Prolog Basics: Rule RULES defines the relationship 19 MeaningPredicate CalculusPROLOG And, Or; if:- Notnot r(…) :- conditions for r(…) be true. body head

20 Debug Prolog 20 Open the GUI Debugger

21 Debug Prolog 21 Example likes(mary,apple). likes(mary,orange). likes(mary,lemon). likes(kate,grape). likes(kate,orange). buy(F):-likes(mary,F),likes(kate,F). ?- spy(likes/2). %Start the Graphical Debugger first true. [debug] ?- buy(F). %See the Graphical Debugger F = orange. [trace] ?- notrace. %Exit the trace mode true. [debug] ?- nodebug. %Exit the debug mode true.

22 22 Step Unification Green indicates true. Red indicates false. Skip this goal Finish the selected goal Call stack

23 Reference Reference manual of SWI-Prolog http://www.swi-prolog.org/pldoc/refman/ More advanced Prolog The Craft of Prolog by Richard A. O'Keefe http://lpn.swi-prolog.org/lpnpage.php?pageid=teaching https://www.doc.gold.ac.uk/~mas02gw/prolog_tutorial/prol ogpages/index.html#menu 23


Download ppt "ARTIFICIAL INTELLIGENCE LAB UCEL601 ( Second Term) Presented by Nirmala 1."

Similar presentations


Ads by Google