% Ejercicio: agata.in
% Autor: Jos� A. Alonso
% Fecha: 25 de Mayo de 2006
%==============================================================================

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% � Enunciado                                                               %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Se ha cometido un crimen en una casa por uno de sus habitantes. Se sabe que
%  1. Agata, el mayordomo y Carlos viven en la casa del crimen.
%  2. Un asesino siempre odia a sus v�ctimas, y nunca es m�s rico que su
%     v�ctima. 
%  3. Carlos no odia a nadie de los que odia la t�a Agata.
%  4. Agata odia a todos excepto al mayordomo (es decir, a ella y a Carlos).
%  5. El mayordomo odia a los que no son m�s rico que la t�a Agata.
%  6. El mayordomo odia a todos los que odia la t�a Agata.
%  7. Nadie odia a todos  (es decir, a Agata, al mayordomo y a Carlos).
% Demostrar que ni Carlos ni el mayordomo han asesinado a Agata.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% � Representaci�n                                                          %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

set(prolog_style_variables).

formula_list(usable).
 % 1. Agata, el mayordomo y Carlos viven en la casa del crimen.
 vive(agata) & vive(mayordomo) & vive(carlos).

 % 2. Un asesino siempre odia a sus v�ctimas, y nunca es m�s rico que su
 %    v�ctima. 
 all X Y (asesina(X,Y) -> odia(X,Y)).
 all X Y (asesina(X,Y) -> -mas_rico(X,Y)).

 % 3. Carlos no odia a nadie de los que odia la t�a Agata.
 all X (odia(agata,X) -> -odia(carlos,X)).

 % 4. Agata odia a todos excepto al mayordomo (es decir, a ella y a Carlos).
 odia(agata,agata) & odia(agata,carlos).

 % 5. El mayordomo odia a los que no son m�s rico que la t�a Agata.
 all X (vive(X) & -mas_rico(X,agata) -> odia(mayordomo,X)).

 % 6. El mayordomo odia a todos los que odia la t�a Agata.
 all X (odia(agata,X) -> odia(mayordomo,X)).
 
 % 7. Nadie odia a todos (es decir, a Agata, al mayordomo y a Carlos).
 -(exists X (odia(X,agata) & odia(X,mayordomo) & odia(X,carlos))).
end_of_list.

formula_list(sos).
 % Ni Carlos ni el mayordomo son los asesinos de Agata.
 -(-asesina(mayordomo,agata) & -asesina(carlos,agata)).
end_of_list.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% � Demostraci�n                                                            %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

set(binary_res).

% 1 [] vive(agata).
% 2 [] vive(mayordomo).
% 3 [] vive(carlos).
% 4 [] -asesina(X,Y)|odia(X,Y).
% 5 [] -asesina(X,Y)| -mas_rico(X,Y).
% 6 [] -odia(agata,X)| -odia(carlos,X).
% 7 [] odia(agata,agata).
% 8 [] odia(agata,carlos).
% 9 [] -vive(X)|mas_rico(X,agata)|odia(mayordomo,X).
% 10 [] -odia(agata,X)|odia(mayordomo,X).
% 11 [] -odia(X,agata)| -odia(X,mayordomo)| -odia(X,carlos).
% 12 [] asesina(mayordomo,agata)|asesina(carlos,agata).
% 16 [binary,12.2,4.1] asesina(mayordomo,agata)|odia(carlos,agata).
% 25 [binary,16.2,6.2,unit_del,7] asesina(mayordomo,agata).
% 26 [binary,25.1,5.1] -mas_rico(mayordomo,agata).
% 27 [binary,25.1,4.1] odia(mayordomo,agata).
% 28 [binary,26.1,9.2,unit_del,2] odia(mayordomo,mayordomo).
% 29 [binary,27.1,11.1,unit_del,28] -odia(mayordomo,carlos).
% 30 [binary,29.1,10.2] -odia(agata,carlos).
% 31 [binary,30.1,8.1] $F.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% � Estad�stica                                                             %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Generadas/Usadas = 23/7 = 3.3
