Presentation is loading. Please wait.

Presentation is loading. Please wait.

علمتني الثلوج أن أكون كبياض الثلج لا يحمل قلبي غير الحب والعطف والرحمة لا أسيئ الظن بالأخرين ولا أحكم عليهم من مظهرهم فإذا لم تعاشرهم فأنت تجهلهم !

Similar presentations


Presentation on theme: "علمتني الثلوج أن أكون كبياض الثلج لا يحمل قلبي غير الحب والعطف والرحمة لا أسيئ الظن بالأخرين ولا أحكم عليهم من مظهرهم فإذا لم تعاشرهم فأنت تجهلهم !"— Presentation transcript:

1 علمتني الثلوج أن أكون كبياض الثلج لا يحمل قلبي غير الحب والعطف والرحمة لا أسيئ الظن بالأخرين ولا أحكم عليهم من مظهرهم فإذا لم تعاشرهم فأنت تجهلهم !

2 الذكاء الاصطناعي Artificial Intelligence ( AI) comp323 Lab (2)

3 Knowledge Base 3 happy(vincent). listensToMusic(butch). playsAirGuitar(vincent):- listensToMusic(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listensToMusic(butch). how many clauses in the KB3 ? What does this rule mean?

4 if we posed the query ?- playsAirGuitar(vincent). ?- playsAirGuitar(butch).

5 playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listensToMusic(butch). We could replace the pair of rules given above by the single rule playsAirGuitar(butch):- happy(butch); listensToMusic(butch).

6 Knowledge Base 4 woman(mia). woman(jody). woman(yolanda). loves(vincent,mia). loves(marcellus,mia). loves(pumpkin,honey_bunny). loves(honey_bunny,pumpkin).

7 for the first time we’re going to make use of variables ?- woman(X).

8 Let’s try a more complicated query, namely ?- loves(marcellus,X),woman(X).

9 Knowledge Base 5 loves(vincent,mia). loves(marcellus,mia). loves(pumpkin,honey_bunny). loves(honey_bunny,pumpkin). jealous(X,Y) :- loves(X,Z),loves(Y,Z).

10 Suppose we pose the query: ?- jealous(marcellus,W).

11 Prolog Syntax what are facts, rules, and queries built out of? The answer is terms, and there are four kinds of terms in Prolog: atoms, numbers, variables, and complex terms (or structures). Atoms and numbers are lumped together under the heading constants, and constants and variables together make up the simple terms of Prolog.

12 Atoms 1. A string of characters made up of upper-case letters, lower-case letters, digits, and the underscore character, that begins with a lower- case letter. For example: butch, big_kahuna_burger, and m_monroe2.

13 Atoms 2. An arbitrary sequence of character enclosed in single quotes. For example ’Vincent’, ’The Gimp’, ’Five_Dollar_Shake’, ’&^%&#@$ &*’, and ’ ’. The character between the single quotes is called the atom name.

14 Atoms 3. A string of special characters. For example: @= and ====> and ; and :- are all atoms. As we have seen, some of these atoms, such as ; and :- have a pre-defined meaning

15 Numbers integers (that is:... -2, -1, 0, 1, 2, 3,...) are useful for such tasks as counting the elements of a list

16 Variables A variable is a string of upper-case letters, lower-case letters, digits and underscore characters that starts either with an upper- case letter or with underscore. For example, X, Y, Variable, _tag, X_526, and List, List24, _head, Tail, _input and Output are all Prolog variables.

17 Complex terms Complex terms are build out of a functor followed by a sequence of arguments. The arguments are put in ordinary brackets, separated by commas, and placed after the functor. The functor must be an atom. That is, variables cannot be used as functors. On the other hand, arguments can be any kind of term.

18 For example, playsAirGuitar(jody) its functor is playsAirGuitar and its argument is jody The number of arguments that a complex term has is called its arity

19 arity Arity is important to Prolog. Prolog would be quite happy for us to define two predicates with the same functor but with a different number of arguments

20 it is usual to use a suffix / followed by a number to indicate the predicate’s arity To return to KB2 listensToMusic/1 happy/1 playsAirGuitar/1

21 Practical Session 1 ?- listing. command is to display the contents of the current knowledge base ?- listing(playsAirGuitar).

22 References Prolog note

23 H.W ( group ) Exercise 1.1 – 1,2,3,6,9 Exercise 1.2 – 1,2,3 Exercise 1.3 Exercise 1.4 – 2,3 Exercise 1.5 – 2,5,7


Download ppt "علمتني الثلوج أن أكون كبياض الثلج لا يحمل قلبي غير الحب والعطف والرحمة لا أسيئ الظن بالأخرين ولا أحكم عليهم من مظهرهم فإذا لم تعاشرهم فأنت تجهلهم !"

Similar presentations


Ads by Google