derivative implementation and tests for Jacobian