private static alglib.ndimensional_pfunc CreatePFunc(AutoDiff.IParametricCompiledTerm compiledFunc) {
   return (double[] c, double[] x, ref double func, object o) => {
     func = compiledFunc.Evaluate(c, x);
   };
 }