some generic functions for doing algebra