I can't run the code right now (and you didn't include the output / the actual problem). The problem is with generating the equations, yes? The point is that equality testing in the polynomial ring R will give a yes or no answer, instead of the symbolic (unevaluated) equality that you want. To get the symbolic equality, convert to the symbolic ring SR beforehand. I guess it would be SR(m[i]*v) == SR(v[i]). Probably you can also avoid using the symbolic ring, but that is a separate story.