On Sat, 20 Nov 2021 at 07:59, Paul Royik <
distan...@gmail.com> wrote:
>
> Poly((x-1)**2, x) returns Poly(x**2-2x+1, x).
> Is it possbile to retain the expression as it is, i.e. (x-1)**2 ?
It is possible to retain the unexpanded expression: don't convert to Poly!
The internal representation of Poly cannot represent an unexpanded
power because it's just a list of coefficients:
In [6]: p = Poly((x - 1)**2, x)
In [7]: p
Out[7]: Poly(x**2 - 2*x + 1, x, domain='ZZ')
In [8]: p.rep
Out[8]: DMP([mpz(1), mpz(-2), mpz(1)], ZZ, None)
In [9]: p.rep.rep
Out[9]: [mpz(1), mpz(-2), mpz(1)]
This is the Dense Univariate Polynomial (DUP) representation:
https://docs.sympy.org/latest/modules/polys/domainsintro.html#dup-representation
--
Oscar