% Elements
member(pair(X,Y)) :-
	number(X),
	number(Y),
	X>=0, X=<1,
	Y>=0, Y=<1.

% Ordering relation
leq(pair(X,Y),pair(Z,W)) :- X<Z ; X=Z,Y=<W.

% Supremum and infimum
bot(pair(0,0)).
top(pair(1,1)).

% Binary operations
and_godel(pair(X1,X2),pair(Y1,Y2),pair(Z1,Z2)) :- pri_min(X1,Y1,Z1), pri_min(X2,Y2,Z2).
or_godel(pair(X1,X2),pair(Y1,Y2),pair(Z1,Z2)) :- pri_max(X1,Y1,Z1), pri_max(X2,Y2,Z2).

% Aggregators
agr_aver(pair(X1,X2),pair(Y1,Y2),pair(Z1,Z2)) :- pri_add(X1,Y1,U1), pri_prod(U1,0.5,Z1), pri_add(X2,Y2,U2), pri_prod(U2,0.5,Z2).
agr_very(pair(X1,X2),pair(Y1,Y2)) :- pri_prod(X1,X1,Y1), pri_prod(X2,X2,Y2).

% Auxiliar operations
pri_prod(X,Y,Z) :- Z is X * Y.
pri_div(X,Y,Z) :- Z is X / Y.
pri_sub(X,Y,Z) :- Z is X - Y.
pri_add(X,Y,Z) :- Z is X + Y.
pri_min(X,Y,Z) :- (X=<Y,Z=X;X>Y,Z=Y).
pri_max(X,Y,Z) :- (X=<Y,Z=Y;X>Y,Z=X).
