https://www.ifsqn.com/forum/index.php/topic/39731-rd-formulation-programming/
R