1
votes

I had a quick question about an error I got. I am new to prolog so please excuse me if its a simple fix.

here is what i was trying to do:

Consider the database created in question 1. In implementing the following rules, you can add additional rules to make your implementation easier.


2.1 Add the following set of rules that extend the family relations among the members: (1) parent_of, (2) sibling_of, (3) uncle_of, (4) uncleOrAunt_of, (5) spouse_of, and (6) descendant_of


2.2 Add at least 10 facts into the database. These new facts should show consistent relationship among family members and must ensure (1) no conflict facts,(2) no redundant information, (3) each rule defined in question 2.1 can return a "yes" value for at least one set of parameters.


2.4 Add a rule called fullQuestions at the end of database to test all the rules that you have defined in the homework. Include sufficient write statements, so that the answers to individual questions are printed. Make sure that the compound question can terminate (will not cause a "dead loop"). Include the output as comments.

Here is what I got so far:

/* Database for family. It consists of facts and
rules. */

/* Facts */
/* female(ella).
female(jodi).
female(sonya).
/*
male(arnold).
*/
male(chris).
/*
male(louis).
male(mark).
 */
father_of(X,Y) :- 
   parent_of(X,Y), is_male(X).
father_of(arnold, chris). /* arnold is the father of chris */
father_of(louis, mark).
father_of(mark, arnold).

mother_of(X,Y) :- 
  parent_of(X,Y), is_female(X).
mother_of(ella, sonya).
mother_of(jodi, mark).

child(X, Y) :-
    parent_of(Y, X).

parent_of(X, Y) :-
    child(Y, X).

parent_of(jodi, ella).
parent_of(jodi, mark).
parent_of(louis, mark).
parent_of(mark, arnold).
parent_of(jose, sergio).
parent_of(ana, sergio).
parent_of(jose, gio).
parent_of(ana, gio).
parent_of(joe, jose).
parent_of(mary, jose).

/* Rules */


grandmother_of(X, Z) :-
            mother_of(X, Y),
            (mother_of(Y, Z); father_of(Y, Z)).

is_male(X) :-
    father_of(X, _).
is_female(X) :-
    mother_of(X, _).

sibling_of(X, Y) :-
 parent_of(Z, X), parent_of(Z, Y).

sister(X,Y) :- 
   siblings(X,Y), is_female(X), X \= Y.

brother(X,Y) :- 
    siblings(X,Y), is_male(X), X \= Y.

uncle_of(X,Y) :- 
brother(X,Z), mother_of(Z,Y).
uncle_of(X,Y) :- 
 brother(X,Z), father_of(Z,Y).

uncleOrAunt_of(X, Y) :-
    brother(X,Z), mother_of(Z,Y).
uncleorAunt_of(X, Y) :-
    brother(X,Z), father_of(Z,Y).
uncleorAunt_of(X, Y) :-
    sister(X,Z), father_of(Z,Y).
uncleorAunt_of(X, Y) :-
    sister(X,Z), mother_of(Z,Y).

spouse_of(X,Y) :-
    child(P, X), child(P, Y).

ancestor( X , Y ) :-
  parent_of( X , Y ).
ancestor( X , Y ) :-
     parent_of( X , Z ) , ancestor( Z , Y ).

descendant_of(X, Y) :-
    ancestor(Y, X).

familyquestions :-
    grandmother_of(X, arnold),
    write('The grandmother of Arnold is '), write(X), nl,
    father_of(Y, mark),
    write(Y), write(' is the father of Mark'), nl, nl.

However, when i try to compile it i get multiple errors:

/tmp/gplcExLkpg.o: In function `predicate(sister/2)':

(.text+0x7b3): undefined reference to `predicate(siblings/2)'

/tmp/gplcExLkpg.o: In function `predicate(brother/2)':

(.text+0x843): undefined reference to `predicate(siblings/2)'

collect2: error: ld returned 1 exit status

compilation failed

1
You have a typo in parent_of(mary, jose),. It should end with a dot and not a comma.gusbro
oh ok thanks! i fixed it but now i got two different erros?devil_0695
family.pl:64-65: warning: discontiguous predicate parent_of/2 - clause ignored family.pl:75: fatal error: redefining control construct (',')/2 compilation faileddevil_0695

1 Answers

1
votes

the "warning: discontiguous predicate parent_of/2 - clause ignored error" pops because there is separation of the parent_of/2 predicate. try to parent_of(X, Y) :- child(Y, X). right under the parent_of(mary, jose).

like this:

father_of(X,Y) :- parent_of(X,Y), is_male(X).
father_of(arnold, chris). /* arnold is the father of chris */
father_of(louis, mark).
father_of(mark, arnold).

mother_of(X,Y) :- parent_of(X,Y), is_female(X).
mother_of(ella, sonya).
mother_of(jodi, mark).

parent_of(X, Y) :- child(Y, X).
parent_of(jodi, ella).
parent_of(jodi, mark).
parent_of(louis, mark).
parent_of(mark, arnold).
parent_of(jose, sergio).
parent_of(ana, sergio).
parent_of(jose, gio).
parent_of(ana, gio).
parent_of(joe, jose).
parent_of(mary, jose).

etc..

i dont remember the exact syntax but almost sure the ";" (or) should work:

uncleOrAunt_of(X, Y) :-
    (brother(X,Z), mother(Z,Y));
    (brother(X,Z), father(Z,Y));
    (sister(X,Z), father(Z,Y));
    (sister(X,Z), mother(Z,Y)).

give it a try and let me know. any way this you can fix the fatal error with rewriting to

uncleOrAunt_of(X, Y) :-brother(X,Z), mother(Z,Y).
uncleOrAunt_of(X, Y) :-brother(X,Z), father(Z,Y).
uncleOrAunt_of(X, Y) :-sister(X,Z), father(Z,Y).
uncleOrAunt_of(X, Y) :-sister(X,Z), mother(Z,Y).

hope made things clear and that im right.

....................................................