function x = l1_l2_sub(y,muL,mgL)

% This solves the subproblem
%
% min 0.5*||x - y||^2 + mu*||x||_1 - mg*||x||_2
%
% when norm(y,'inf') > mu. Else, returns zero, solution for majorization
% subproblem.
%
% mgL = muL*gamma
% subroutine of FBS_major_l1_l2

tmpy = abs(y);
v = tmpy - muL;
indexy = [v > 1e-8];

if sum(indexy) > 0 % if norm(y,'inf') > muL
  tmpy2 = v.*indexy;
  normy2 = norm(tmpy2);
  r = mgL + normy2;
  x = r/normy2*(sign(y).*tmpy2);
else % all entries of v are negative
  [tmpy2,I] = min(-v); 
  x = zeros(size(y));
  x(I) = sign(y(I))*max(mgL - tmpy2,0);  
%   fprintf('%g here\n', muL)
end

