Formula class hierarchy

Some hefty changes here — you may want to look through them commit-by-commit and let me know if you have any questions. Comment away!