btw Eppstein has python routines for doing much of this. It might be worth
looking at what he's done.

http://www.ics.uci.edu/~eppstein/numth/egypt/egypt.py