Move useful dual templates from splineimpl.h to dual.h

Just moving code around and augmenting.

The reason these templates are helpful is that they can be used inside other templates, without regard to whether the type T is a Dual or just an ordinary type.