(self)
return p
square of a polynomial

        Examples
        --------
        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> _, x, y = ring('x, y', ZZ)
        >>> p = x + y**2
        >>> p.square()
        x**2 + 2*x*y**2 + y**4
square of a polynomial
square of a polynomial
def square(self):
        """square of a polynomial

        Examples
        --------
        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.domains import ZZ

        >>> _, x, y = ring('x, y', ZZ)
        >>> p = x + y**2
        >>> p.square()
        x**2 + 2*x*y**2 + y**4

        """
        ring = self.ring
        p = ring.zero
        get = p.get
        keys = list(self.keys())
        zero = ring.domain.zero
        monomial_mul = ring.monomial_mul
        for i in range(len(keys)):
            k1 = keys[i]
            pk = self[k1]
            for j in range(i):
                k2 = keys[j]
                exp = monomial_mul(k1, k2)
                p[exp] = get(exp, zero) + pk*self[k2]
        p = p.imul_num(2)
        get = p.get
        for k, v in self.items():
            k2 = monomial_mul(k, k)
            p[k2] = get(k2, zero) + v**2
        p.strip_zero()
        return p
def square ( self ) : ring = self . ring p = ring . zero get = p . get keys = list ( self . keys ( ) ) zero = ring . domain . zero monomial_mul = ring . monomial_mul for i in range ( len ( keys ) ) : k1 = keys [ i ] pk = self [ k1 ] for j in range ( i ) : k2 = keys [ j ] exp = monomial_mul ( k1 , k2 ) p [ exp ] = get ( exp , zero ) + pk * self [ k2 ] p = p . imul_num ( 2 ) get = p . get for k , v in self . items ( ) : k2 = monomial_mul ( k , k ) p [ k2 ] = get ( k2 , zero ) + v ** 2 p . strip_zero ( ) return p