Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prolog programming Introduction to Prolog (part2)

Similar presentations


Presentation on theme: "Prolog programming Introduction to Prolog (part2)"— Presentation transcript:

1 Prolog programming Introduction to Prolog (part2)
CS 370 – CS461

2 Data Objects The arguments of relation can be:
Constant objects (such as bob and 12). General objects (such as X and Y). Structure objects ( such as date and time). data objects variables constants structures simple objects numbers atoms

3 Atoms Characters: Atoms can be constructed in three ways:
Upper-case letter A, B,…, Z Lower-case letter a, b,…, z Digits 0,1,2,…,9 Special characters such as +-*/<>=:.&_~ Atoms can be constructed in three ways: Strings of letters, digits and the underscore character,’_’, starting with a lower case letter, such as : anna, x25, x_35AB, x___y, miss_Jones. Strings of special characters such as: <--->, ===>, …,::=,.:., (except :- ). Strings of characters enclosed in single quotes, such as: ‘Tom’, ‘South_America’, ‘Sarah Jones’.

4 Numbers and Variables Number
Numbers used in Prolog include integer numbers and real numbers. Integer numbers: 1313, 0, -97 Real numbers: 3.14, , 100.2 In symbolic computation, integers are often used. Variables are start with an upper-case letter or an underscore character. Examples: X, Result, _x23, _23

5 Questions in prolog. Another question can be asked in Prolog:
pam tom bob liz ann pat jim Another question can be asked in Prolog: Who is Liz’s parent? ?- parent(X, liz). The answer here will not be true/false, rather, prolog will find the value of X. So the answer is : X= tom.

6 Class exercise(1) Who are bob’s children? pam tom bob liz ann pat jim

7 Class exercise(2) Who is parent of whom? pam tom bob liz ann pat jim

8 Questions in prolog. In prolog, we can ask more complicated questions such as: Who is a grandparent of jim? ?- parent(Y,jim) , parent( X,Y). The answer will be: Y = pat, X = bob. X Parent Y grandparent Parent jim

9 Class exercise(3) Who are Tom’s grandchildren?

10 Some important points A prolog program consists of clauses, each clause ends with a full stop. Questions in prolog consist of one or more goals. ?-parent(X,ann),parent(X,pat) . means the conjunctions of the goals: X is parent of ann , and X is parent of pat.

11 Homework Who is bob’s father? Who is bob’s sister?
Formulate the following questions and find Prolog answers : Who is bob’s father? Who is bob’s sister? Do ann and pat have a common parents?


Download ppt "Prolog programming Introduction to Prolog (part2)"

Similar presentations


Ads by Google