apply_deriv
work in progress