Some maths algorithms as explained in different posts in albertmata.net.