Can this function live outside of `solve_as_poly`?  This will make it easier to test and also help to keep functions small.