PROLOG
PROLOG
University of Kalyani
Prolog Assignment, 2023
y + z̄
a + b̄ c + d¯ ē + f
ḡ h j̄ i k̄
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;
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.
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).
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).
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.
2
19. Write a PROLOG program to print the reverse of a given list.
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.
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.