% adaptation for TALP

symmetric3([X1,X2,X3]) :-
	symmetric([X1,X2,X3]).

symmetric(M) :-
	transpose(M, M).

% an improved transpose

transpose2([],[]).
transpose2([MX|MXs], [TX|TXs]) :-
	transpose([MX|MXs], [TX|TXs]).

% Source: http://www.cs.kuleuven.ac.be/~dtai/prototypes/dppd/transpose.html
transpose(Xs,[]) :-
	nullrows(Xs).
transpose(Xs,[Y|Ys]) :-
	makerow(Xs,Y,Zs),
	transpose(Zs,Ys).

makerow([],[],[]).
makerow([[X|Xs]|Ys],[X|Xs1],[Xs|Zs]) :-
	makerow(Ys,Xs1,Zs).

nullrows([]).
nullrows([[]|Ns]) :-
	nullrows(Ns).

