implementation of various lua algorithms for ML