#NEWLINE# def square( self ) : #NEWLINE# #INDENT# "square of a polynomial\n\n        Examples\n        ========\n\n        >>> from sympy.polys.rings import ring\n        >>> from sympy.polys.domains import ZZ\n\n        >>> _, x, y = ring('x, y', ZZ)\n        >>> p = x + y**2\n        >>> p.square()\n        x**2 + 2*x*y**2 + y**4\n\n        " #NEWLINE# ring = self . ring #NEWLINE# p = ring . zero #NEWLINE# get = p . get #NEWLINE# keys = list ( self . keys ( ) ) #NEWLINE# zero = ring . domain . zero #NEWLINE# monomial_mul = ring . monomial_mul #NEWLINE# for i in range ( len ( keys ) ) : #NEWLINE# #INDENT# k1 = keys [ k1 ] #NEWLINE# pk = self [ k1 ] #NEWLINE# for j in range ( i ) : #NEWLINE# #INDENT# k2 = keys [ j ] #NEWLINE# exp = monomial_mul ( k1 , k2 ) #NEWLINE# p [ exp ] = ( get ( exp , zero ) + ( pk * self [ k2 ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# p = p . imul_num ( 2 ) #NEWLINE# get = p . get #NEWLINE# for ( k , v ) in self . items ( ) : #NEWLINE# #INDENT# k2 = monomial_mul ( k , k ) #NEWLINE# p [ k2 ] = ( get ( k2 , zero ) + ( v ** 2 ) ) #NEWLINE# #UNINDENT# p . strip_zero ( ) #NEWLINE# return p