optimize the codes for computing grad(b(y)).