% problem-set/puzzles/miscell/jobs.ver1.clauses
% created : 07/12/88
% revised : 07/12/88
 
% description:
%
% This run solves "The Jobs Puzzle" using UR-resolution.
%   
%                       The Jobs Puzzle
%                 
%    There are four people: Roberta, Thelma, Steve, and Pete.
%    Among them they hold eight different jobs. 
%    Each holds exactly two jobs.            
%    The jobs are: chef, guard,nurse, telephone operator,police officer
%        (no gender implied), teacher, actor, and boxer.
%    The job of a nurse is held by a male.
%    The husband of the chef is the telephone operator.
%    Roberta is not a boxer.
%    Pete has no education past the ninth grade.
%    Roberta, the chef, and the police officer went golfing together.
% 
%        Question : Who holds which job ?
 
% representation:
%
% declare_predicate(8,ANSWER).
% declare_predicates(2,[HJ,EQP,EQJ,HUSB]).
% declare_predicates(1,[EDUCATED,MALE,FEMALE]).
% declare_constants([gu,op,po,cte,ac,bo,ch,nu,roberta,thelma,steve,cvince]).
% declare_functions(1,[gu1,op1,po1,cte1,ac1,bo1,ch1,nu1]).
% declare_variables([u,z,y,x,x1,x2,x3,x4,x5,x6,x7,x8]).
%
% Predicates:     EDUCATED(x) - EDUCATED beyond the ninth grade. 
% 		   HJ(x,y)     - x has the job y.
%		   MALE(x)     - person x is a MALE.
%		   FEMALE(x)   - person y is a FEMALE.
%		   EQP(x,y)    - person x is the same as person y.
%		   EQJ(x,y)    - the job x is the same as job y.
%		   HUSB(x,y)   - person y is the husband of person x 
%          ANSWER(..) - a predicate to indicate the final answer 
%
% Constants: ch - the chef.
%		   gu - the guard.
%		   op - the telephone operator.
%		   po - the police officer.
%		   cte - the teacher.
%		   ac - the actor.
%		   bo - the boxer.
%		   nu - the nurse.
%		   roberta, thelma, steve, cvince - names of people */

% Every person is the same as himself. 
% These two clauses eliminate the generation of clauses: -EQP(Rob,Rob) 

eqp(x,x).
eqj(x,x).

% Commutative Property 
-eqp(x,y)| eqp(y,x).
-eqj(x,y)| eqj(y,x).

% No two people are the same. 

-eqp(Roberta,Thelma).
-eqp(Roberta,Vince).
-eqp(Roberta,Steve).
-eqp(Vince,Thelma).
-eqp(Vince,Steve).

% No two jobs are the same.

-eqj(CH,GU).
-eqj(CH,NU).
-eqj(CH,OP).
-eqj(CH,PO).
-eqj(CH,WA).
-eqj(CH,WR).
-eqj(CH,TE).

-eqj(GU,NU).
-eqj(GU,OP).
-eqj(GU,PO).
-eqj(GU,WA).
-eqj(GU,WR).
-eqj(GU,TE).

-eqj(NU,OP).
-eqj(NU,PO).
-eqj(NU,WA).
-eqj(NU,WR).
-eqj(NU,TE).

-eqj(OP,PO).
-eqj(OP,WA).
-eqj(OP,WR).
-eqj(OP,TE).

-eqj(PO,WA).
-eqj(PO,WR).
-eqj(PO,TE).

-eqj(WA,WR).
-eqj(WA,TE).

-eqj(WR,TE).

% The nurse and actor are MALEs, and the chef is a FEMALE. 

-hj(x,NU)| male(x).
-hj(x,WA)| male(x).
-hj(x,CH)| female(x).

% The nurse, teacher, and police officer are EDUCATED.

-hj(x,NU)| educated(x).
-hj(x,TE)| educated(x).
-hj(x,PO)| educated(x).

% If the person is a chef, she cannot be a police officer.

-hj(x,CH)| -hj(x,PO).

% Male and FEMALE properties are mutually exclusive of each other.

-male(x)| -female(x).
male(x)| female(x).

% A HUSBand is a MALE and a wife is a FEMALE.

-husb(x,y)| male(y).
-husb(x,y)| female(x).

% The chef and the operator are married.

-hj(x,CH)| -hj(y,OP)| husb(x,y).
-hj(x,CH)| hj(y,OP)| -husb(x,y).

% A job can be held by only one person.

-hj(x,z)| -hj(y,z)| eqp(x,y).

% If a person can have only 2 unique jobs. 

-hj(z,u)| -hj(z,x)| -hj(z,y)| eqj(u,x)| eqj(u,y) |eqj(x,y).

% A job has to be held by one of roberta, thelma,cvince,steve. 

hj(Roberta,x) | hj(Thelma,x) | hj(Vince,x) | hj(Steve,x).

% A person has to hold one of the given jobs :ch, gu,cte,ac,bo,po,op,nu

hj(x,CH) | hj(x,GU) | hj(x,NU) | hj(x,OP) | hj(x,PO) | hj(x,TE) |
    hj(x,WA) | hj(x,WR).

% If all of the listed people have a job then ANSWER gives the result.

-hj(x1,CH)| -hj(x2,GU)| -hj(x3,NU)| -hj(x4,OP)|
-hj(x5,PO)| -hj(x6,TE)| -hj(x7,WA)|
-hj(x8,WR)| $ANS(CHEF(x1),GUARD(x2),NURSE(x3),OPERATOR(x4),POLICE(x5),
    TEACHER(x6),ACTOR(x7),BOXER(x8)).

% Vince has no education past the ninth grade.

-educated(Vince).

% roberta is not a chef, boxer or police officer since roberta went 

-hj(Roberta,CH).

% golfing with the chef and the police officer.                     

-hj(Roberta,WR).
-hj(Roberta,PO).

% steve and vince are MALEs (deduced through gender of names),     

male(Steve).
male(Vince).

% roberta and thelma are FEMALEs for the same reason.              

female(Roberta).
female(Thelma).
