Add gradient function.