Forward difference function

needs debugging