Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Correct way to compute the modulus of a polynomial

I am dealing with a large list of monomials of degree 1. One such (small) example would be

x0x2x3x4 + x1x2x3x4 - x0x2x3 - x1x2x3 - x0x3x4 - x1x3x4 + x2x3x4 + x0x3 + x1x3 - x2x3 - x3x4 + x3

I need to create a dict that, encodes each of the above summands (recording the respective variable indices) and the respective value of the coefficient. So for the above expression I'd like to make the dictionary:

{'0,2,3': -1, '0,2,3,4': 1, '0,3': 1, '0,3,4': -1, '1,2,3': -1, '1,2,3,4': 1, '1,3': 1, '1,3,4': -1, '2,3': -1, '2,3,4': 1, '3': 1, '3,4': -1}

I would like this to be as efficient as possible. As far as I understand it is not possible to use coefficients() to return this and the only way I see how to accomplish this is by converting the expression to a string and parse it. Given that this is quite inefficient and ugly I was wondering

What would be an efficient way to extract the described dictionary from a given monomial expression?