function H = symptimesmat(w,k,K)
% H=SYMPTIMESMAT(w,k,K) performs the multiplication of the elementary
% symplectic matrix S(w,k) by the matrix K
% w: a vector of length 2n
% k: an integer less than or equal to n
% K: a matrix of size 2nx2n
% H: the result of S(w,k)*K
n = length(w)/2;
H = K;
% Constructing the parameters of the first Householder matrix
[u1,b1] = householder(w(n+k:2*n));
% Updating the rows of H and w affected by the Householder matrix
H(k:n,:) = H(k:n,:) - b1*u1*(H(k:n,:)'*u1)'; 
H(n+k:2*n,:) = H(n+k:2*n,:) - b1*u1*(H(n+k:2*n,:)'*u1)';
w(k:n) = w(k:n) - b1*u1*u1'*w(k:n);
w(n+k:2*n) = w(n+k:2*n) - b1*u1*u1'*w(n+k:2*n);
% Constructing the Givens matrix
G = givens([w(k),w(n+k)]);
% Updating the two rows of H and w affected by the Givens matrix
H([k n+k],:) = G*H([k n+k],:);
w([k n+k]) = G*w([k n+k]);
% Constructing the parameter of the second Householder matrix
[u3,b3] = householder(w(k:n));
% Updating the two rows of H affected by the Householder matrix
H(k:n,:) = H(k:n,:) - b3*u3*(H(k:n,:)'*u3)';
H(n+k:2*n,:) = H(n+k:2*n,:) - b3*u3*(H(n+k:2*n,:)'*u3)';
