|| GROUP ASSIGNMENT#5 ASSIGNMENT #4 - 13th 1st and 2nd October 2015
|| PART I) Complete the following
|| The time of your group lab is:
|| Your group number is :
|| The names of the group members present:
|| PART II) Read through the following data
male = ["doug", "paul", "bill", "simon"]
female = ["angela", "sue", "mary", "beth", "anne"]
parent_of
= [("doug", "paul") , ("doug", "sue") , ("paul", "cathy"),
("paul", "james"), ("sue", "simon") , ("sue", "mary"),
("mary", "bill") , ("bill", "angela"), ("angela", "beth"),
("anne", "cathy")]
married_to = [("anne", "paul"), ("paul", "anne")]
|| QUESTION 1
|| DRAW A TABLE FOR EACH OF THE RELATIONS ABOVE
|| The following are example programs for relational
|| algebra operators
project_first_of_2 r = mkset[(x) | (x, y) <- r]
project_second_of_2 r = mkset[(y) | (x, y) <- r]
project_first_and_third_of_3 r = mkset[(x,z) | (x,y,z) <- r]
select_first_of_2 r key = [(x,y) | (x, y) <- r; x = key]
join_second_of_2_with_first_of_2 r s
= [(x, y, z) | (x, y) <- r; (a , z) <- s; y = a]
union s t = s ++ (t --s)
intersection s t = s -- (s -- t)
|| do not worry, the following is definition if difficult.
|| It just adds all the missing pairs to make a relation
|| transitive
||
make_transitive [] = []
make_transitive ((x, y):ps)
= new_direct_paths ++
[(a,c) | (a,b) <- mtps; (d,c) <- new_direct_paths;
b = d] ++ mtps
where mtps = make_transitive ps
new_direct_paths = (x, y):[(x, b) | (n, b) <- mtps; n = y]
|| QUESTION 2)
|| DRAW THE TABLE THAT WOULD BE RETURNED FOR EACH OF THE
|| FOLLOWING RELATIONAL ALGEBRA EXPRESSIONS
|| union male female
|| project_first_of_2 parent_of
|| select_first_of_2 parent_of "paul"
|| project_second_of_2 parent_of
|| join_second_of_2_with_first_of_2 parent_of parent_of
|| PART III) Discuss within the group how the following
|| definition of the "grandparent" realtion works:
grandparent = project_first_and_third_of_3
(join_second_of_2_with_first_of_2
parent_of parent_of)
||
|| Now try to define the following relations, using only
|| relational algebra operators applied to the relations
|| given above
|| QUESTION 3)
|| child_of
|| Hint: Define an operator called project_second_and_first_of_2
|| which you can apply to parent_of to get the child_of
|| relation.
||
|| QUESTION 4)
|| brother_or_sister_of
|| (Hint - similar to grandparent but a different join of
|| the parent_of with itself, followed by a project)
||
|| QUESTION 5)
|| sister_of
||
|| QUESTION 6)
|| aunty_or_uncle_of
||
|| QUESTION 7)
|| aunty_or_uncle_of_mary
|| (Hint - do a select operation on the aunty_or_uncle_of
|| relation)
||
|| QUESTION 8)
|| neice_of
||
|| QUESTION 9)
|| cousin_of
||
|| QUESTION 10)
|| mother_in_law_of
|| To answer the above, you need to define some additional
|| relational algebra operators similar to those above.
|| For example,
|| you may need an operator join_first_of_2_with_first_of_2
||
|| You can use list comprehensions to define the new relational
|| algebra operators that you need.
|| Note that the following operator removes all tuples which
|| contain the same value in both fields:
remove_reflexives r = [(x, y) | (x, y) <- r; x ~= y]
||NOTES
|| This assignment is intended to give you an understanding of
|| relational algebra.
|| Each of your programs must be defined using a combination of || relational algebra operators chosen from select, project,
|| join, union, intersection, make-transitive and
|| remove_refexives.
|| You should not use recursion in your programs, nor should
|| you define the new relations "sister_of" etc. by listing
|| the contents, or by using list comprehensions.
|| In order to determine which relational algebra operators
|| are needed for each new relation, you should draw tables
|| to represent the given data (male, female, parent_of,
|| married_to) and then draw more tables that can be
|| generated from the original tables using relational algebra
|| operators, until you can generate the required table.