The algorithm for differentiation relies on some pretty obscure mathematics, but it works! Mark Williams demonstrates Forward Mode Automatic Differentiation.