cost generating function