% PD 2007-08: practica_3a.pl (3 de Diciembre de 2008)
% Departamento de Ciencias de la Computación e I.A.
% Universidad de Sevilla 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 1 (Relaciones familiares)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% En este ejercicio se considera la siguiente base de conocimiento que
% describe algunas relaciones familiares mediante la relación
% padre(X,Y), que se verifica si X es padre de Y, y madre(X,Y), que se
% verifica si X es madre de Y.  
padre(andres,bernardo).
padre(andres,belen).
padre(andres,baltasar).
padre(baltasar,david).
padre(david,emilio).
padre(emilio,francisco).
madre(ana,bernardo).
madre(ana,belen).
madre(ana,baltasar).
madre(belen,carlos).
madre(belen,carmen).
% Se pide:
% (a) Extender la base de conocimiento anterior mediante reglas para
%     definir las siguientes relaciones familiares: 
%     (a.1) progenitor(X,Y) que se verifica si X es progenitor de Y (es
%           decir, X es el padre o la madre de Y),
%     (a.2) abuelo(X,Y) que se verifica si X es abuelo de Y.
% (b) Usar las relaciones definidas para responder a las siguientes
%     cuestiones: 
%     (b.1) ¿quiénes son los progenitores de Bernardo?
%     (b.2) ¿quién es el abuelo de Carlos?
%     (b.3) ¿quiénes son los hijos de Andrés?
%     (b.4) ¿quiénes son los hijos de algún hijo de Ana?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2 (Números naturales)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% En este ejercicio se usa la representación de los números naturales
% construidos con 0 y s; es decir, la serie 
%    0, s(0), s(s(0)), s(s(s(0))), ...
% representa a la serie de los números naturales
%    0, 1, 2, 3, ...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2.1 Definir la relación suma(X,Y,Z) que se verifique si Z es
% la suma de los números naturales X e Y. Por ejemplo,
%    ?- suma(s(s(0)),s(s(s(0))),X).
%    X = s(s(s(s(s(0))))) ;
%    No
%    ?- suma(s(s(0)),X,s(s(s(s(s(0)))))).
%    X = s(s(s(0))) ;
%    No
%    ?- suma(X,s(s(s(0))),s(s(s(s(s(0)))))).
%    X = s(s(0)) ;
%    No
%    ?- suma(X,Y,s(s(s(s(s(0)))))).
%    X = 0
%    Y = s(s(s(s(s(0))))) ;
%    X = s(0)
%    Y = s(s(s(s(0)))) 
%    Yes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2.2 Definir la relación menor(X,Y) que se verifique si el
% número natural X es menor que el número natural Y. Por ejemplo, 
%    ?- menor(s(0),s(s(0))).
%    Yes
%    ?- menor(s(s(0)),s(0)).
%    No
%    ?- menor(s(0),s(0)).
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2.2. Definir la relación mayor(X,Y) que se verifique si el
% número natural X es mayor que el número natural Y. Por ejemplo, 
%    ?- mayor(s(0),s(s(0))).
%    No
%    ?- mayor(s(s(0)),s(0)).
%    Yes
%    ?- mayor(s(0),s(0)).
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2.3. Definir la relación resta(X,Y,Z) que se verifique si Z
% es X menos Y si X es mayor o igual que Y y 0, en caso contrario. Por
% ejemplo, 
%    ?- resta(s(s(s(0))),s(0),X).
%    X = s(s(0)) ;
%    No
%    ?- resta(s(s(s(0))),s(s(0)),X).
%    X = s(0) ;
%    No
%    ?- resta(s(s(s(0))),s(s(s(0))),X).
%    X = 0 ;
%    No
%    ?- resta(s(s(s(0))),s(s(s(s(0)))),X).
%    X = 0 ;
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2.4 Definir la relación producto(X,Y,Z) que se verifique si
% Z es el producto de los números naturales X e Y. Por ejemplo, 
%    ?- producto(s(s(0)),s(s(s(0))),X).
%    X = s(s(s(s(s(s(0)))))) ;
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2.5 Definir la relación cuadrado(X,Y) que se verifique si Y
% es el cuadrado de X. Por ejemplo, 
%    ?- cuadrado(s(s(0)),X).
%    X = s(s(s(s(0)))) ;
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2.6 Definir la relación cubo(X,Y) que se verifique si Y es
% el cubo de X. Por ejemplo, 
%    ?- cubo(s(s(0)),X).
%    X = s(s(s(s(s(s(s(s(0)))))))) ;
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2.7 Definir la relación potencia(X,Y,Z) que se verifique si
% Z es la potencia Y-ésima de X. Por ejemplo, 
%    ?- potencia(s(s(0)),s(s(s(0))),X).
%    X = s(s(s(s(s(s(s(s(0)))))))) ;
%    No
%    ?- potencia(s(s(s(0))),s(s(0)),X).
%    X = s(s(s(s(s(s(s(s(s(0))))))))) ;
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2.8 Definir la relación divisor_propio(X,Y) que se verifique
% si X es un divisor propio del número natural Y; es decir, X es un
% divisor de Y mayor 1 y menor que Y. Por ejemplo, 
%    ?- divisor_propio(X,s(s(s(s(s(s(0))))))).
%    X = s(s(0)) ;
%    X = s(s(s(0))) ;
%    No
%    ?- divisor_propio(X,s(s(s(0)))).
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2.9 Definir la relación compuesto(X) que se verifique si X
% es un número compuesto; es decir, que pose un divisor mayor que 1 y
% menor que X. Por ejemplo, 
%    ?- compuesto(s(s(s(s(0))))).
%    Yes
%    ?- compuesto(s(s(s(0)))).
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2.10 Definir la relación número_natural(X) que se verifique
% si X es un número natural. Por ejemplo, 
%    ?- número_natural(s(s(0))).
%    Yes
%    ?- número_natural(s(s(3))).
%    No
%    ?- número_natural(X).
%    X = 0 ;
%    X = s(0) ;
%    X = s(s(0)) ;
%    X = s(s(s(0))) 
%    Yes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2.11 Definir la relación número_compuesto(X) que se
% verifique si X es un número compuesto; es decir, que posee un divisor
% mayor que 1 y menor que X. Por ejemplo,  
%    ?- número_compuesto(X).
%    X = s(s(s(s(0)))) ;
%    X = s(s(s(s(s(s(0)))))) 
%    Yes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2.12 Definir la relación entre(X,Y,Z) que se verifique si Z
% es un número natural mayor o igual que X y menor o igual que Y. Por
% ejemplo,
%    ?- entre(s(0),s(s(s(0))),X).
%    X = s(0) ;
%    X = s(s(0)) ;
%    X = s(s(s(0))) ;
%    No
%    ?- entre(s(s(s(0))),s(0),X).
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

