Just a hint, for now: if I understand you correctly, you're trying to use v1, v2, v3 as the indeterminates of a (boolean) polynomial whose coefficients are themselves boolean polynomials. Try to implement that...