function x=prehadamard(x,index1,index2)

% sanity checks commented out to improve runtime

% [f,e] = log2(length(x));
% if f ~= 1/2 
%     error('computing hadamard on a vector of length not a power of 2.')
% elseif ~isequal(size(index1),size(index2)) || size(index1,1)~=1 || length(size(index1))~=2
%     error('index arrays not formatted properly')
% elseif length(index1)~=(e-1)*length(x)/2
%     error('computing hadamard on a vector whose length does not match the index arrays')
% end
    


% working serially, apply the hadamard transform to each pair of indexes
% specified in the array indexes.
for k=1:length(index1)
           temp1= x(index1(k)); 
           x(index1(k)) = temp1 + x(index2(k));
           x(index2(k)) = temp1 - x(index2(k));
end
% scale x so that this function doesn't change its norm. 
x=x/sqrt(length(x)); 

