% % Author: Alex Roque % Assignment #: 1 % Due Date: 09/13/01 % Program Title: Assignment 1 % Program Description: This assignment writes the predicate half_sibling, % print_half_siblings, grandmother, print_grandmothers, exes(X,Y), and print_exes % % I certify that this is my work and have not consulted with anyone else. % % % % % CLAUSES % the parent clauses % parent(X,Y) means that X is a (biological) parent of Y. parent(bill,cathy). parent(mark,ann). parent(cathy, chris). parent(ray,alex). parent(mark,susan). parent(michelle,ann). parent(becky,susan). parent(david,mark). parent(mona,mark). parent(david,nina). parent(mona,nina). parent(ray,sophia). parent(michelle,jill). parent(john,jill). % the sex clause % sex(X,Y) means that the sex of X is Y sex(bill,male). sex(cathy,female). sex(mark,male). sex(chris,male). sex(ray,male). sex(alex,male). sex(susan,female). sex(mona,female). sex(nina,female). sex(sophia,female). sex(ann,female). sex(becky,female). sex(susan,female). sex(david,male). sex(john,male). sex(jill,female). sex(michelle,female). %%%%%%%%%%%%%%%% HALF SIBLINGS BLOCK % X is the half-sibling of Y if X and Y have a common parent, but the other one is different. half_sibling(X,Y) :- parent(Parent1,X), parent(Parent1,Y), parent(Parent2,X), parent(Parent3,Y), Parent1\==Parent2, Parent1\==Parent3, Parent2\==Parent3. % This is a loop that prints all half-siblings. print_half_siblings :- nl, nl, tab(10), write(' HALF SIBLING LIST'), nl, tab(10), write('==================='), nl, nl, print_all_half_siblings. print_all_half_siblings :- half_sibling(X,Y), write(X), write(' is half sibling of '), write(Y), nl, fail. print_all_half_siblings. %%%%%%%%%%%%%%%% END HALF SIBLINGS %%%%%%%%%%%%%%%% ABUELAS! % X is a grandmother of Y if X is a female, and X is the parent of Z, which is the parent of Y. grandmother(X,Y) :- sex(X,female), parent(X,Z), parent(Z,Y). % This is a loop that prints all grandmothers. print_grandmothers :- nl, nl, tab(10), write(' GRANDMOTHER LIST'), nl, tab(10), write('=================='), nl, nl, print_all_grandmothers. print_all_grandmothers :- grandmother(X,Y), write(X), write(' is the grandmother of '), write(Y), write('.'), nl, fail. print_all_grandmothers. %%%%%%%%%%%%%%%%% END OF ABUELAS! %%%%%%%%%%%%%%%%% EXES % X and Y are exes if they are married to different people and they have a child together. exes(X,Y) :- half_sibling(A,B), parent(X,A), parent(Y,B), sex(X,_Sex1), sex(Y,_Sex2), X\==Y, parent(X,D), parent(Y,E), D\==E, D\==A, E\==B. % This is a loop that prints all exes. print_exes :- nl, nl, tab(10), write(' EXES LIST'), nl, tab(10), write('==========='), nl, nl, print_all_exes. print_all_exes :- exes(X,Y), write(X), write(' is an ex of '), write(Y), write('.'), nl, fail. print_all_exes. %%%%%%%%%%%%%%%% END OF EXES go:- print_grandmothers,print_half_siblings,print_exes.