% MULTI-ADJOINT LATTICE MODELLNG TRUTH-DEGREES AS REAL NUMBERS IN 
% THE INTERVAL [0..1]. EACH VALUE ALSO CONTAINS A SECOND COMPONENT 
% (NOT ALTERING THE INITIAL ORDERING) FOR INDICATING USEFUL
% INFORMATION ON COMPUTATIONS IN THE FUZZY ''MALP'' PARADIGM.


:- dynamic pri_add/4, pri_prod/4, pri_div/4, pri_min/4, pri_app/4, and_prod/3, and_godel/3, agr_aver/3.

member(info(X,_)):-number(X),0=<X,X=<1.


bot(info(0,'')).
top(info(1,'')).


leq(info(X1,_),info(X2,_)):- X1 =< X2.


pri_add(X,Y,Z,'sis2(priADD)-') :- Z is X+Y.
pri_prod(X,Y,Z,'sis2(priPROD)-') :- Z is X * Y.
pri_div(X,Y,Z,'sis2(priDIV)-') :- Z is X/Y.
pri_min(X,Y,Z,'sis2(priMIN)-') :- (X=<Y,Z=X;X>Y,Z=Y).
pri_app(X,Y,Z) :- name(X,L1),name(Y,L2),append(L1,L2,L3),name(Z,L3).


and_prod(info(X1,X2),info(Y1,Y2),info(Z1,Z2)):-pri_prod(X1,Y1,Z1,DatPROD),pri_app(X2,Y2,Dat1),pri_app(Dat1,'sis1(&PROD)-',Dat2),pri_app(Dat2,DatPROD,Z2).

and_godel(info(X1,X2),info(Y1,Y2),info(Z1,Z2)):-pri_min(X1,Y1,Z1,DatMIN),pri_app(X2,Y2,Dat1),pri_app(Dat1,'sis1(&GODEL)-',Dat2),pri_app(Dat2,DatMIN,Z2).

agr_aver(info(X1,X2),info(Y1,Y2),info(Z1,Z2)):-pri_add(X1,Y1,Aux,DatADD), pri_div(Aux,2,Z1,DatDIV),pri_app(X2,Y2,Dat1),pri_app(Dat1,'sis1(@AVER)-',Dat2),pri_app(Dat2,DatADD,Dat3),pri_app(Dat3,DatDIV,Z2).


append([],X,X).
append([X|L],Y,[X|S]):-append(L,Y,S).