Calculating higher-order derivatives