Initial commit of functions from github.com/btracey/optimize

Change order of dim and cap.