% PD 2008-09: practica_8.pl (16 de Diciembre de 2008)
% Departamento de Ciencias de la Computación e I.A.
% Universidad de Sevilla 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 1. Definir, usando append, la  relación pertenece(X,L) que se
% verifique si X es un elemento de la lista L. Por ejemplo, 
%    ?- pertenece(b,[a,b]).
%    Yes
%    ?- pertenece(c,[a,b]).
%    No
%    ?- pertenece(X,[a,b]).
%    X = a ;
%    X = b ;
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 2. Definir la relación sublista(L1,L2) que se verifique si L1
% es una sublista de L2. Por ejemplo, 
%   ?- sublista([b,c],[a,b,c,d]).
%   Yes
%   ?- sublista([b,d],[a,b,c,d]).
%   No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 3. Definir la relación último(X,L) que se verifique si X es
% el último elemento de la lista L. Por ejemplo,  
%     ?- último(X,[a,b,c]).
%     X = c ;
%     No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 4. Definir la relación inversa(L1,L2) que se verifique si L2
% es la lista L1 en orden inverso, Por ejemplo,  
%   ?- inversa([a,b,c],L).
%   L = [c, b, a] ;
%   No
%   ?- inversa([a,[b,c],d,e],L).
%   L = [e, d, [b, c], a] ;
%   No
%  Nota: La relación predefinida correspondiente a inversa es reverse.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 5. Definir la relación palíndromo(L) que se verifique si L es
% un palíndromo; es decir, da igual leerlo de izquierda a derecha que
% leerlo de derecha a izquierda. Por ejemplo, 
%    ?- palíndromo([r,o,m,a,y,a,m,o,r]).
%    Yes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 6. Definir la relación selecciona(X,L1,L2) que se verifique
% si X es un elemento de la lista L1 y L2 es la lista de los restantes
% elementos. Por ejemplo, 
%   ?- selecciona(X,[a,b,c],L).
%   X = a     L = [b, c] ;
%   X = b     L = [a, c] ;
%   X = c     L = [a, b] ;
%   No
% Nota: La relación predefinida correspondiente a selecciona es select. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 7. Definir la relación inserta(X,L1,L2) que se verifique si
% L2 es una lista obtenida insertando X en algún lugar de L1. Por ejemplo, 
%    ?- inserta(1,[a,b,c],L).
%    L = [1,a,b,c] ;
%    L = [a,1,b,c] ;
%    L = [a,b,1,c] ;
%    L = [a,b,c,1] ;
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 8. Definir la relación mayor(L1,L2) que se verifique si la 
% lista L1 tiene más elementos que la lista L2. Por ejemplo,
%    ?- mayor([a,b,c],[1,2]).
%    Yes
%    ?- mayor([a],[a,b]).
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 9. Definir la relación duplica(L1,L2) que se verifique si la 
% lista L2 se obtiene duplicando los elementos de L1. Por ejemplo,
%    ?- duplica([a,b,c],L).
%    L = [a,a,b,b,c,c] ;
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 10. Definir la relación copia(L1,L2,L3) que se verifique si
% L3 se obtiene concatenando L1 consigo misma tantas veces como
% elementos tenga la lista L2. Por ejemplo,
%    ?- copia([a,b],[1,2,3],L).
%    L = [a,b,a,b,a,b] ;
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 11. Definir la relación subconjunto(L1,L2) que se verifique si
% L2 es un subconjunto de L1. Por ejemplo,
%    ?- subconjunto([a,b,c],L).
%    L = [] ;
%    L = [c] ;
%    L = [b] ;
%    L = [b, c] ;
%    L = [a] ;
%    L = [a, c] ;
%    L = [a, b] ;
%    L = [a, b, c] ;
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ejercicio 12. Definir la relación permutacion(L1,L2) que se verifique si
% L2 es una permutacion de L1. Por ejemplo,
%    ?- permutacion([1,2,3],L).
%    L = [1, 2, 3] ;
%    L = [2, 1, 3] ;
%    L = [2, 3, 1] ;
%    L = [1, 3, 2] ;
%    L = [3, 1, 2] ;
%    L = [3, 2, 1] ;
%    No
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

