Department of Computer Science and Engineering
University of Kalyani
Prolog Assignment, 2023
y + z̄
a + b̄ c + d¯ ē + f
ḡ h j̄ i k̄
Figure 1: Familty tree
1. Consider the family tree given in the figure 1. Every female member of the family is
denoted with a bar on top of their names. a, c and e are children of y and z. + symbol
defines that two people are married. Create a knowledge base in PROLOG in such a way
that the whole family tree can be implemented. You have to write facts for all
male(x): x is a male;
female(x): x is a female;
parents(u,v,w): u and v are parents of w;
married(x,y): x and y are married;
Write the rules for finding
(a) husband(x,y): x is husband of y;
(b) wife(x,y): x is wife of y;
(c) son(x,y): x is son of y;
(d) daughter(x,y): x is daughter of y;
(e) brother(x,y): x is brother of y;
(f) sister(x,y): x is sister of y;
(g) grandfather(x,y): x is grandfather of y;
(h) grandmother(x,y): x is grandmother of y;
(i) cousin(x,y): x is cousin of y;
Now run the following queries: find the cousins of h; find the brother(s) of c; find
sister(s) of i; find grandfather of j; and find the brother of e who is not the father of g.
2. Write a PROLOG program to calculate the sum of two numbers.
3. Write a PROLOG program to find the maximum of two numbers.
4. Write a PROLOG program to find the area and perimeter of a square with the side length
being provided by the user.
1
5. Write a PROLOG program to find the area and perimeter of a circle with the radius
being provided by the user.
6. Write a PROLOG program to print a Fibonacci series with stating numbers are provided
by user.
7. Write a PROLOG program to calculate the sum of natural numbers up to a limit (using
recursion).
8. Write a PROLOG program to calculate the sum of a range.
9. Write a PROLOG program to calculate the factorial of a given number.
10. Write a PROLOG program to find the last element of a list(list must have at least 4
items).
11. Write a PROLOG program to find the length of a list (list must have at least 4 elements).
12. Write a PROLOG program to find the average of a list of numbers.
13. Write a PROLOG program to implement maxlist(List,Max) so that Max is the greatest
among all the elements present in the list (list must have at least 4 items).
14. Write a PROLOG program to calculate the sum of numbers present in the List. ( At first
create a list of numbers. The length of the list must not be less than 4.)
15. Write a PROLOG program to find out the GCD and LCM of two numbers. Use these
predicates to find out the GCD and LCM of a list of numbers.
16. Write a PROLOG program to insert an element at the kth position of a list.
17. Write a PROLOG program to compute the sum of the digits of an integer.
18. Write a PROLOG program to implement the following digital circuit.
Figure 2: Digital Circuit
2
19. Write a PROLOG program to print the reverse of a given list.
20. Write a PROLOG program to concatenate two given lists.
21. Write a PROLOG program to find the union, difference and intersection of two given
lists.
22. Write a PROLOG program to check whether a given list is palindrome or not.
23. Write a PROLOG program to check whether a given number is prime or not. Use this
predicate to print all the prime numbers upto a given number.
24. Write a PROLOG program to print the reverse of a given list.
25. Write a PROLOG program to delete the kth element of a list.
26. Write a PROLOG program to check whether a path exists between two nodes of a graph.
You can implement any arbitrary graph. Print the series of the nodes in the path(s) if
some path exists.