code to implement adaptive-rejection sampler