Define your answers to Exercises 1 through 6 in terms of the base relations pare
ID: 3822637 • 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 8.) Define a firstPair predicate so that firstPair (X) succeeds if and only if X is a list of at least two elements, with the first element the same as the second element. Hint: This can be expressed as a fact.
Exercise 12.) Define the oddSize predicate so that oddSize (X) says that X is a list whose length is an odd number. Hint: You do not need to compute the actual length, or do any integer arithmetic.
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
8)
firstPair(X) :- firstPair(X,[ X| _ ]).
The firxt X in the RHS means that it's the first element and the second X means that it's the second element in the list and _ represents any anonymous elements.
So, it means the first and second elements are the same which would be same as value of X. Then only firstPair(X) would be true for that value of X.
12)
oddSize(X) :- oddSize([ _ ]).
oddSize([ _ , _ |Rest]):- oddSize(Rest).
The first statement means that a list with one element is of oddsize.
In the second statement, the first _ represents first element and second _ represents the second element and Rest means Rest of the list.
It means size of the list would be odd if size of Rest is odd (Rest means leaving first 2 elements of the list).
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.