converting between vertex and factored form