function m=spermat(k,p,n)
q=zeros(k,1);
q(1)=n;
for i=2:k
 q(i)=floor(q(i-1)/2);
end 
v=perms(1:k)(p,:);
m=eye(k)(:,v);
for i=1:k
 m(i,:)=(-1)^q(i)*m(i,:);
end

