% for a multiple tensor product of two vectors of symbols
% returns the compact representation of cross products (i.e. w/o
% repetitions).

function [S,w,v2]=order_vecX(V2);

[l,jj,ii]=unique(sym2cell(V2),'first');
S=sparse(eye(length(V2)));
W=sum(S(ii,ii));
S=S(sort(jj),:);
w=W(sort(jj));
if nargout>2
v2=w'.*(S*V2);
end
end