copied alglib and cubature