Solving Thurston's equation in a commutative ring