NOTE: all the math here has been updated and expanded with a ton more options; see here: http://detectmagic.blogspot.com/2014/03/edition-math-conver…