Quiz 3  - 3:30 class

 

Name __________________  Max Points: 10   Earned Points:  ___

 

 

Write the following statements (rules) in Prolog:

 

1.                    If Fido is a yellow lab, then Fido is a dog

 

/*  will tell who the yellow_lab dogs are */

dog (Fido) :- yellow_lab (Fido).

 

         /* will tell if a particular dog named fido is a yellow_lab (i.e. “yes” or “no”) */

          dog(fido) :- yellow_lab(fido).

 

2.   If it is Tuesday and it is February, then there is school.

 

/* will return “yes” or “no” depending on whether the two facts are in the db */

     school :-  day (tuesday) ,  month (february).

 

3.    If Fred is a male and Fred is your parent, then Fred is your father.

 

/* tells who fathers are */                                       

    father(Fred) :-  male(Fred) ,  parent(Fred).    

 

/* tells who fathers are and who they are fathers of */

     father(Fred,Who) :- male(Fred) ,  parent(Fred, Who).

 

4.    If X is your parent, then X is your father or X is your mother.

/ be careful not to get the implication reversed */

father(X) :- parent (X).

mother(X) :- parent(X).

 


Quiz 3  - 5:00 class

 

Name __________________  Max Points: 10   Earned Points:  ___

 

 

Write the following statements  (rules) in Prolog:

 

 

1.   If Fluffy is a tabby, then Fluffy is a cat.

 

/*  will tell who the tabby cats are */

cat(Fluffy) :- tabby (Fluffy).

 

         /* will tell if a particular cat named fluffy is a tabby (i.e. “yes” or “no”) */

cat(fluffy) :- tabby (fluffy).

 

2.   If it is Saturday and it is April,  then it is raining.

 

/* will return “yes” or “no” depending on whether the two facts are in the db */

raining :-  day(Saturday) ,  month(april).

 

3.    If Sally is a female and Sally is your child, then Sally is your daughter.

 

/* tells who daughters are */

daughter(Sally) :- female(Sally) , child(Sally).

 

/* tells who daughters are and who they are daughters of */

daughter (Sally, Who) :- female(Sally),  child(Sally, Who).

 

4.    If X is happy, then X is rich or X is beautiful.

 

/ be careful not to get the implication reversed */

rich(X) :- happy(X).

beautiful(X) :- happy(X).