Define your answers to Exercises 1 through 6 in terms of the base relations pare
ID: 3822638 • Letter: D
Question
Define your answers to Exercises 1 through 6 in terms of the base relations parent (X, Y), female (X), and male (X). To test your code, define some parent facts like those in this chapter, along with apporpriates female and male facts. But your solutions should be gerneral enough to work with any set of such facts.
Exercise 16.) Define the isUnion predicate so that isUnion (X, Y, Z) says that the union of X and Y is Z. Do not use the predefined list predicates. Your predicate may choose a fixed order for Z. If you query isUnion ( [1, 2], [3], Z) it should find a binding for z, but it need not succeed on both isUnion ( [1], [2], [1, 2] ) and isUnion ([1], [2], [2,1]). Your predicate need not work well when X or Y are unbound variables.
Your Name Chapter 1 Exercises CSC 3750 Spring 2017 Facts females( brandy, ann mary, Susan jen jane, susie, nda] males (Doseph, brandon, jim, james, tom, john, clark, bob, steven, jason, bill, jude]). males (mark) parent(adam mary) parent(mary Susan) parent parent parent(steven,bill). parent(mary,clark) parent(maryim) parent clark Steven) Predicates male(X) males (L) member (X,L) female(X) females(L), member (X,L) "Exercise 19.1 mother (X,Y) female(X) parent sibling(X,Y) parent(P,X), parent(PY), not (X Y) "Exercise 19.4 grandson(X,Y) male (X) parent(P,X), parent(YP) ancestor (X,Y) parent(X,Y) parent(P,Y), ancestor (X,Y) ancestor (X,P) Exercise 19.12Explanation / Answer
Solution: Answers for your first 3 questions.
Exercise 19.1:
Query1:Mother(X,Y) :- female(X), parent(X,Y)
If Mother of Y is X, then X should be a member of Females fact and parent of Y should be X.
Eg:
Mother(Mary, Susan) – True as Mary is included in females fact list and Mary is the parent of Susan
Query2: Sibling(X,Y):- parent(p,X), parent(p,Y), not(X=Y)
X and Y can be siblings if and only if X and Y parents are same and X is not equal to Y.
Eg:
Sibling(Tom, Mark) – True as Parent of both Tom and Mark is Jim
Exercise 19.4:
Query1:
Grandson(X,Y):- male(X), Parent(P,X), Parent(Y,P)
X is the grandson of Y if and only if X is a male, X’s parent is P and P’s parent is Y.
Eg:
Grandson(Tom, Mary) – True as Tom is a male, Tom’s parent is Jim and Jim’s parent is Mary.
Query2:
Ancestor(X,Y):- Parent(X,Y)
X is the ancestor of Y if and only if X is the parent of Y
Eg:
Ancestor(Clark, Steven) – True as Clark is the parent of Steven
Query3:
Ancestor(X,Y):- Parent(P,Y) ,Ancestor(X,P)
X is the ancestor of Y if parent of Y is P and ancestor of P is X which means parent of P is X
Eg:
Ancestor(Adam, Clark) – True as Clark’s parent is Mary and Mary’s ancestor is Adam
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.