There's a very inconvenient mismatch of choice in polynomials at the moment:

sage: R.<x,y,z>=QQ[]
sage: f=x+2*y+z
sage: list(f)
[(1, x), (2, y), (1, z)]

As you can see, polynomials are iterable and produce (coefficient, 
monomial) pairs. The nasty thing is: that looks like the appropriate input 
for a dictionary constructor, and indeed, it sort-of seems to work:

sage: dict(f)
{1: z, 2: y}

except of course that the dict should be keyed by monomials, not by the 
coefficients.

We do have:

sage: f.dict()
{(0, 0, 1): 1, (0, 1, 0): 2, (1, 0, 0): 1}

which raises expectations that dict(f) would work reasonably too. It could, 
if we would swap to (monomial, coefficient) tuples. When I encountered this 
behaviour, I was sure this was some silly typo. It's not: f.__iter__() is 
behaving as documented. Is it going to be too painful to try and change 
this now?

Incidentally, the correct dictionary (keyed by monomials rather than 
exponent vectors) can be obtained via the relatively hard to discover

sage: {R({a:1}):b for a,b in f.dict().iteritems()}
{z: 1, y: 2, x: 1}

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to