1. Prolog :
Prolog is a logic programming language associated with artificial intelligence and
computational linguistics. Prolog is intended primarily as a declarative programming language.
In prolog, logic is expressed as relations (called as Facts and Rules). Core heart of prolog lies at
the logic being applied. Formulation or Computation is carried out by running a query over these
relations. It has important role in artificial intelligence. Prolog facts are expressed in definite
pattern. Facts contain entities and their relation. Entities are written within the parenthesis
separated by comma (, ). Their relation is expressed at the start and outside the parenthesis.
Every fact/rule ends with a dot (.).
Applications :
I. expert systems
II. specification language
III. machine learning
IV. robot planning
V. automated reasoning
VI. problem solving
VII. intelligent data base retrieval
VIII. natural language understanding
2. 1. Designa simple family relationship tree, assign necessary clause and rules to
evaluate the following relationships:
(a) Father
(b) Mother
8. 2. DesignProlog clause and rules to check the membership of an element in an list.
Prolog also has a special facility to split the first part of the list. The Head away from the
rest of the list i.e. the Tail. We can place a special symbol | in the list to distinguish
between the first item in the list and the remaining list.
For example,
[first,second,third] = [A|B] where A = first and B= [second,third]
3. Write a Prolog Program to find a factorial of a number.
Formula for calculating n! (Factorial of n) is: n! = n * (n-1)!
We will use two predicates here,
i. Factorial predicate with one argument N, that will calculate and N!
ii. Factorial predicate with two arguments N and F. This function is recursively used. It will
also calculate N!, but store it in the argument F in the process if recursion.
9. 4. Write a Prolog program to find the maximum between two numbers.
We first check whether the numbers are equal or not. Then we check which number is larger i.e.
the First one or the Second
10. 5. Write a Prolog program to concatenate two lists.
Combining two list into one.
6. Write a Prolog program to delete an element from a list.
11. 7. Create Knowledge Base in Prolog for data given below:
Person Name City Code Phone Number
Kashif 02 544342
Asif 02 112345
Fahad 031 531612
Tareq 031 674245
Noman 081 753232
Aslam 081 812341
Jamil 02 912331
City Name City Code
Dhaka 02
Cumilla 081
Chittagong 031
Find the solutions using the Knowledge Base:
(a) What is the phone number of Kashif?
12. (b) Does Asif belong to Dhaka?
(c) Where does Noman live?
(d) Do Fahad and Tareq live in the same city?
(e) Who lives in same city where Kashif lives?