 # SymPy.jl analogue of `as_dict` and `gens`

Hi,
What are the SymPy.jl analogues for `as_dict` and `gens`? See below for a minimal piece of code I would like to translate from SymPy to SymPy.jl. This is part of a larger project I am translating from Python to Julia which involves sum of squares of polynomials. Thanks in advance for any help!

``````from sympy import poly

poly = poly('5*y**7 + 3*x**2 + 2*x*y**2 + 1')
print(poly.as_dict())  # {(0, 0): 1, (0, 7): 5, (1, 2): 2, (2, 0): 3}
print(poly.gens)  # (x, y)
``````

It is quite similar:

``````julia> p = sympy.poly("5*y^7 + 3*x^2 + 2*x*y^2 + 1")
Poly(3*x**2 + 2*x*y**2 + 5*y**7 + 1, x, y, domain='ZZ')

julia> p.as_dict()
Dict{Any,Any} with 4 entries:
(0, 0) => 1
(1, 2) => 2
(2, 0) => 3
(0, 7) => 5

julia> p.gens
(x, y)
``````

Thank you for your solution. I was constructing my polynomials like so:

``````using SymPy
@vars x y
p = 5 * y^7 + 3 * x^2 + 2 * x*y^2 + 1
``````

for which both `p.as_dict` and `p.gens` give errors.

This leads me to another question: why does the last line in the code below return `false`?

``````using SymPy
@vars x y
p = 5 * y^7 + 3 * x^2 + 2 * x*y^2 + 1

typeof(p) == typeof(sympy.poly(p)) # true
p == sympy.poly(p) # false
``````

The Poly class in SymPy is different than a symbolic expression, that happens to represent a polynomial. You’ll need the constructor. The typeof will be the same (Sym objects), but they aren’t identical.