add function opt/2, opt/3 and their tests