%  MULHL   performs an O(n) matrix vector multiplication
%    
%    B=MULHL(G,d,R,X) is the vector B=HL*X where HL is the Hessenberg-like
%    matrix whose lower triangular part is represented with the Givens-vector
%    representation G,d, and the strictly upper triangular part is given
%    by R
%
%
%    Software of the MaSe - Group
%    mase-at-cs.kuleuven.ac.be
%    Revision Date: 04/05/2004
%
%


function b=MULHL(G,d,R,x)
    
  n=length(d);
  if n~=0
    % performs the multiplication
    % with the lower triangular semiseparable
    % part
    b(1)=x(1)*d(1);
    for i=1:n-1
      wv=b(i);
      b(i)=G(1,i)*wv;
      b(i+1)=G(2,i)*wv+x(i+1)*d(i+1);    
    end
  
    % performs the multiplication with the
    % upper triangular part of the matrix
    if n~=1
      for i=1:n-1
        b2(i)=R(i,i:n-1)*x(i+1:n);
      end
      %      b2(n-1)=R(n-1,n-1)*x(n); 
      %for i=n-2:-1:1
      %  b2(i)=b2(i+1)*G1(2,i)+G1(1,i)*x(i+1);
      %  b2(i+1)=b2(i+1)*d1(i+1);
      %end
      
      %b2(1)=b2(1)*d1(1);
      
      b=(b+[b2,0])';
    end
  else
    b=[];
  end
  
  