Refactor opId, opId_r, and isCommutative into free functions