Implement derivatives (#4035)