# Revision history [back]

The correct way is to define the polynomial ring in which your polynomial lives, and then use the method dict(). For instance:

sage: R.<x0,x1,x2,x3,x4> = QQ[] # polynomials in x0, ..., x4 over the field of rational numbers
sage: p = x0*x2*x3*x4 + x1*x2*x3*x4 - x0*x2*x3 - x1*x2*x3 - x0*x3*x4 - x1*x3*x4 + x2*x3*x4 + x0*x3 + x1*x3 - x2*x3 - x3*x4 + x3
sage: p.dict()
{(0, 0, 0, 1, 0): 1,
(0, 0, 0, 1, 1): -1,
(0, 0, 1, 1, 0): -1,
(0, 0, 1, 1, 1): 1,
(0, 1, 0, 1, 0): 1,
(0, 1, 0, 1, 1): -1,
(0, 1, 1, 1, 0): -1,
(0, 1, 1, 1, 1): 1,
(1, 0, 0, 1, 0): 1,
(1, 0, 0, 1, 1): -1,
(1, 0, 1, 1, 0): -1,
(1, 0, 1, 1, 1): 1}


Now you can parse the ductionary to replace (1,0,0,1,0) by (0,3) for instance.

sage: dict1 = p.dict()
sage: dict2 = { tuple(i for i in range(5) if k[i] == 1): dict1[k] for k in dict1 }
sage: dict2
{(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}