function [x,g,s,y,seq] = sequence_update(t,m,x,g,s,y,xnew,grad_f_x,seq)
    if t >= m
        seq = mod(seq - 1,m); % update sequence
        I = find(seq == 0);
        seq(I) = m;
        s( :,I ) = xnew - x;
        y( :,I ) = grad_f_x - g;
    else
        s( :,1:t+1 ) = [ s(:,1:t),xnew - x ];
        y( :,1:t+1 ) = [ y(:,1:t),grad_f_x - g ];
        seq = 1:t+1;
    end
    x = xnew;
    g = grad_f_x;
end