/* Correction Examen 07/08/88 */
/*1a*/
ens(E):-differents(E).
differents([]).
differents([E1|E]):-hors(E1,E),differents(E).
hors(X,[]).
hors(X,[Y|R]):- X \== Y, hors(X,R).
/*1b*/
/* Verification que U,V,W forment une partition d'un ensemble */
partition(U,V,W,L):-
	nonvar(U),nonvar(V),nonvar(W),
        conc(U,V,Z),
        conc(Z,W,L),
	valid(U,V,W,U1).
/* Construction de partitions */
partition(U,V,W,L):-
	nonvar(L),
        conc(Z,W,L),
        conc(U,V,Z),
	valid(U,V,W,U1).
valid(U,V,W,U1):-
	U \== [], V \== [], W \== [],
	inter(U,V,[]),
	inter(U1,W,[]),!.

conc([],Y,Y).
conc([X|R],Y,[X|Z]):- 
conc(R,Y,Z).
inter([],X,[]).
inter([X|R],Y,Z):- hors(X,Y),inter(R,Y,Z).
inter([X|R],Y,[X|Z]):- dans(X,Y),inter(R,Y,Z).

/*1b en mieux.. */
partition1(U,V,W,L):-
	permut(L,L1),
	partition(U,V,W,L1).
permut(X,X):-var(X).
permut([],[]).
permut([X|L],M):-
	permut(L,U),
	inserer(X,U,M).
inserer(X,U,[X|U]).
inserer(X,[Y|U],[Y|V]):- inserer(X,U,V).
/*1c*/
union([X|M],V,[X|L]):-
    hors(X,V),
    union(M,V,L).
union([X|M],V,L):-
    dans(X,V),
    union(M,V,L).
union([],L,L).
dans(X,[X|L]).
dans(X,[Y|L]):- X \== Y, dans(X,L).
/*1c*/
uniono([X|M],V,[X|L]):-
    hors(X,V),
    !,
    uniono(M,V,L).
uniono([X|M],V,L):-
    uniono(M,V,L).
uniono([],L,L).

/*2*/
p([Y1,X1],[Y,Y1],[Y,X1]).
/*2.a Z = [_11,[a,b,c|_11]] */
/*2.b l'unification se fait en seule etape et la concatenation n'est plus
dependante de la longueur de liste */
/*2.c */
p([X,[a,b|X]],[Y,[c|Y]],[[],Z1].
/* Ce sont des listes de differences: la premiere sous-liste du deuxieme
argument est la difference entre le premier et le deuxieme argument
(pour p([X1,X2],...), avec X2=[L1|X1], on a L1 =X2-X1,et L2= Y2-Y1)*/

/*3*/
/*3.a*/
interprete(true):-!.
interprete((G1,G2)):- interprete(G1),interprete(G2).
interprete(But):- clause(But,Sousbuts),interprete(Sousbut).
/*3.b-c:objet d'un td Systeme Expert vu les resultats!*/
From mr Fri Feb 26 16:48:18 1988
To: lellouchmore /users/dess_isi/mr/prolog/exam_dess_88/ep


