# Zero degree polynomial copy() error #8210

Open
opened this Issue Oct 7, 2014 · 5 comments

Projects
None yet
5 participants

### dreqju commented Oct 7, 2014

 I have a list of polynomials that I need to `deepcopy()`. But thet procedure generates error on polynomials of zero degree. For example: ``````In [1]: p = Poly([0], x) In [2]: p.copy() `````` I get `GeneratorsNeeded: specify generators to give 0 a meaning`. And I want to have that `Poly([0],x)` as a neutral element of addition. Temporarily I use something like `Poly([10**(-10), 0], x)` but it is not very elegant, is it?
Member

### mattpap commented Oct 7, 2014

 This happens because `Poly.args` doesn't do what `Basic` (the parent class of `Poly`) expects it to do. This should be fixed, but for now you can use simply `Poly(p)` to copy a polynomial, e.g.: ``````In [1]: p = Poly(0, x) In [2]: p Out[2]: Poly(0, x, domain='ZZ') In [3]: p += 1 In [4]: p Out[4]: Poly(1, x, domain='ZZ') In [5]: p2 = Poly(p) In [6]: p2 Out[6]: Poly(1, x, domain='ZZ') In [7]: p2 += 1 In [8]: p2 Out[8]: Poly(2, x, domain='ZZ') In [9]: p Out[9]: Poly(1, x, domain='ZZ') `````` Also note that you don't have to use `Poly([0], x)`, because `Poly(0, x)` does the same and is shorter to write. Also, SymPy is a computer algebra library and types of coefficients matter, so `Poly([10**(-10), 0], x)` may not be exactly what you want (e.g. different algorithms are applied): ``````In [1]: Poly([10**(-10), 0], x) Out[1]: Poly(1.0e-10*x, x, domain='RR') ``````

### dreqju commented Oct 7, 2014

 The code I'm working on is still evolving but as for now I have a list of lists of the form `[interval_from, interval_to, Poly]` and I needed to make a copy of that list. `Poly(p)` is obviously a way to do that but would require me to write my own function. Using `copy.deepcopy(my_list)` was clearly shorter and maybe more reliable, so I was surprised to see that polynomials of zero degree fail to produce their own copies. This clearly needs to be fixed. And by the way, `Poly([10**(-10), 0], x)` in my case works as expected.
Member

### smichr commented Oct 7, 2014

 Should gens be part of Poly.args? ``````>>> Poly(0,x).args (0,) >>> Poly(0,x).gens (x,) >>> self=Poly(0,x) >>> self.func(*(self.args+self.gens)) # this fails if the gens are not included Poly(0, x, domain='ZZ') ``````
Member

### pbrady commented Oct 7, 2014

 I would strongly advise against using `deepcopy` #7672
Member

### mattpap commented Oct 7, 2014

 Should `gens` be part of `Poly.args`? Perhaps, yes, but I'm pretty sure many things will break. Anyway, it's insufficient to reconstruct polynomial based on an expression and generators. You would have to include options as well, e.g. consider `Poly(0, x, domain=QQ)`. If you are going to experiment with this, then just note that `__eq__` performs unification, so you will get `True` more often than reprs/opts would suggest.

### skirpichev added a commit to skirpichev/diofant that referenced this issue Sep 18, 2018

``` Add regression test ```
`Closes sympy/sympy#8210`
``` 53d06b8 ```