merge functions from a jerrington_tools module in another project

The dm_optimizer project where fun.py originally started was still using
the so-called jerrington_tools module, and had since acquired a few new
functions, that I have merged now.