0% found this document useful (0 votes)
40 views

(Mandatory - Graded) : Logic Programming

The document describes 5 logic programming exercises to implement using pyDatalog: 1) Define predicates for relations between family members like brother, cousin, grandson, descendant based on given father facts. 2) Encode facts and rules about animal attributes like size, color, darkness and write a query to find dark and big animals. 3) Enter student name and mark data and write queries to print results, find those who scored 80, check Priya's mark, find students who failed based on a pass mark rule, and define a rule to find grade letters. 4) Solve the student data queries using imperative Python with a dictionary instead of pyDatalog. 5) Write a recursive pyDatalog program to find

Uploaded by

Das Pankajashan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

(Mandatory - Graded) : Logic Programming

The document describes 5 logic programming exercises to implement using pyDatalog: 1) Define predicates for relations between family members like brother, cousin, grandson, descendant based on given father facts. 2) Encode facts and rules about animal attributes like size, color, darkness and write a query to find dark and big animals. 3) Enter student name and mark data and write queries to print results, find those who scored 80, check Priya's mark, find students who failed based on a pass mark rule, and define a rule to find grade letters. 4) Solve the student data queries using imperative Python with a dictionary instead of pyDatalog. 5) Write a recursive pyDatalog program to find

Uploaded by

Das Pankajashan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Ex. No.

7 Logic Programming

(Mandatory – Graded)

1. Implement using pyDatalog:


Assume given a set of facts of the form father(name1,name2) (name1 is the father
of name2).

a. Define a predicate brother(X,Y) which holds iff X and Y are brothers.


b. Define a predicate cousin(X,Y) which holds iff X and Y are cousins.
c. Define a predicate grandson(X,Y) which holds iff X is a grandson of Y.
d. Define a predicate descendent(X,Y) which holds iff X is a descendent of Y.
e. Consider the following genealogical tree:
a
/ \
b c
/ \ |
d e f

What are the answers generated by your definitions for the queries:
brother(X,Y)
cousin(X,Y)
grandson(X,Y)
descendent(X,Y)

2. Encode the following facts and rules in pyDatalog:


• Bear is big
• Elephant is big
• Cat is small
• Bear is brown
• Cat is black
• Elephant is gray
• An animal is dark if it is black
• An animal is dark if it is brown
Write a query to find which animal is dark and big.
3. The following are the marks scored by 5 students.
Student Name Mark
Ram 90
Raju 45
Priya 85
Carol 70
Shyam 80
Enter the above data using pyDatalog.
Write queries for the following:
a. Print Student name and mark of all students.
b. Who has scored 80 marks?
c. What mark has been scored by Priya?
d. Write a rule ‘passm’ denoting that pass mark is greater than 50. Use the
rule to print all students who failed.
e. Write rules for finding grade letters for a marks and use the rule to find
the grade letter of a given mark.

4. Solve the set of queries in the previous question using imperative programming
paradigm in Python. Store the data in a dictionary.

5. Write a recursive program to find factorial of a number using pyDatalog.

You might also like