Fixed bug in derivative.  Fixes #3787

Some tests needed re-golding to fix minor discrepancies.