0

I want to change a SymPy expression, for example x+y ( x=symbols("x") and the same thing for y), into a polynomial, and then get the generators of this polynomial and the length of this polynomial.

I've tried

op=x+y
op = op[:as_poly](domain="C")
op_a = op.x[:gens]
nab = op[:length]()

but it seems that it doesn't work .

The error that i'm getting is this:

ERROR: MethodError: no method matching getindex(::Sym, ::Symbol)
Closest candidates are:
  getindex(::Sym, ::Sym...) at /Users/midow/.julia/packages/SymPy/1Cwgd/src/utils.jl:18
  getindex(::Number) at number.jl:75
  getindex(::Number, ::Integer) at number.jl:77
  ...
Stacktrace:
 [1] top-level scope at REPL[11]:1
phipsgabler
  • 20,535
  • 4
  • 40
  • 60
Marouane1994
  • 534
  • 3
  • 11
  • Hi @Marouane1994! I fixed your code formatting a bit, and tried to improve some parts of the text. Please make sure I didn't change any relevant parts of the meaning. – phipsgabler Oct 17 '19 at 07:29
  • I never used `PyCall`, but we recently got `getproperty` overloading in Julia. Maybe the `getindex` interface is is deprecated? Have you tried something like `op.as_poly(domain = "C")`? – phipsgabler Oct 17 '19 at 07:30

1 Answers1

1

As @phipsgabler mentioned, the interface changed from getindex to getproperty so

using SymPy
x=symbols("x")
y=symbols("y")
op = op.as_poly(domain="C")
op_a = op.x.gens
nab = op.length()

should give you what you want.

loki
  • 142
  • 1
  • 9