A polynomial-time solution to the reducibility problem