Restore Poly from dict

67 views
Skip to first unread message

Paul Royik

unread,
Mar 27, 2015, 3:50:45 PM3/27/15
to sy...@googlegroups.com
Suppose I have following polynomial:
poly= Poly(6*x**4*y**5 + 3*x*y**2,y,x)

It's dictionary is
poly.as_dict() # {(5, 4): 6, (2, 1): 3}


How can I restore poly from dict?
How do I know that (5, 4) - > (y, x) ?
poly.free_symbols is set, so it is unordered.

Is there any way to fetch that from Poly?

One way I think is following:

variables = [x,y]
poly
= Poly(6*x**4*y**5 + 3*x*y**2,variables)

#(5, 4) - > variables


And next question: how are coeffcients are ordered? Can I change order? order keyword throws exception...

Aaron Meurer

unread,
Mar 27, 2015, 3:55:21 PM3/27/15
to sy...@googlegroups.com
It looks like Poly.from_dict will do it:

In [6]: p = Poly(6*x**4*y**5 + 3*x*y**2,y,x)

In [7]: p.as_dict()
Out[7]: {(2, 1): 3, (5, 4): 6}

In [8]: p.from_dict(p.as_dict(), y, x)
Out[8]: Poly(6*y**5*x**4 + 3*y**2*x, y, x, domain='ZZ')

The order of the generators is the same as the order in the Poly. I
don't remember if there is a better method on Poly for reordering
generators, but in the above example Poly(p, x, y) will reorder them.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/b03e1f10-6b62-4725-ab01-a142b26d8a06%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Paul Royik

unread,
Mar 27, 2015, 6:03:15 PM3/27/15
to sy...@googlegroups.com
Thank you.
Reply all
Reply to author
Forward
0 new messages