A generalization of the Katzman-Zhang algorithm. (March 2021)