diff function for rate