Marco Bellan
Marco Bellan

Reputation: 65

Sympy: AttributeError: Multiply polynomial by complex constant

I'm trying to multiply a Sympy polynomial by the complex coefficient "i". However I am getting an error. I am using Python 3.6 and Sympy 1.8.

Code:

from sympy import *
from sympy.abc import x, y, z, w

p = Poly(1.0*x, x, domain='C')
p*I

Error:

AttributeError: 'ComplexField' object has no attribute 'from_GaussianIntegerRing'

Call Stack:

<ipython-input-106-a133adf8aac7> in <module>
----> 1 p*I

~/Code/University/Tesi/tesi/lib/python3.6/site-packages/sympy/polys/polytools.py in wrapper(f, g)
     80                 return result
     81             else:
---> 82                 return func(f, g)
     83         else:
     84             return NotImplemented

~/Code/University/Tesi/tesi/lib/python3.6/site-packages/sympy/polys/polytools.py in __mul__(f, g)
   4110     @_polifyit
   4111     def __mul__(f, g):
-> 4112         return f.mul(g)
   4113 
   4114     @_polifyit

~/Code/University/Tesi/tesi/lib/python3.6/site-packages/sympy/polys/polytools.py in mul(f, g)
   1493             return f.mul_ground(g)
   1494 
-> 1495         _, per, F, G = f._unify(g)
   1496 
   1497         if hasattr(f.rep, 'mul'):

~/Code/University/Tesi/tesi/lib/python3.6/site-packages/sympy/polys/polytools.py in _unify(f, g)
    485                 G = DMP(dict(list(zip(g_monoms, g_coeffs))), dom, lev)
    486             else:
--> 487                 G = g.rep.convert(dom)
    488         else:
    489             raise UnificationFailed("can't unify %s with %s" % (f, g))

~/Code/University/Tesi/tesi/lib/python3.6/site-packages/sympy/polys/polyclasses.py in convert(f, dom)
    297             return f
    298         else:
--> 299             return DMP(dmp_convert(f.rep, f.lev, f.dom, dom), dom, f.lev)
    300 
    301     def slice(f, m, n, j=0):

Is there a workaround to multiply the polynomial as intended?

Thanks, Marco

Upvotes: 0

Views: 138

Answers (1)

smichr
smichr

Reputation: 19047

You can try the domain "EX":

>>> p = Poly(1.0*x, x, domain='EX')
>>> p*I
Poly(1.0*I*x, x, domain='EX')

Upvotes: 1

Related Questions