#NEWLINE# def str( self , printer , precedence , exp_pattern , mul_symbol ) : #NEWLINE# #INDENT# if ( not self ) : #NEWLINE# #INDENT# return printer . _print ( self . ring . domain . zero ) #NEWLINE# #UNINDENT# prec_add = precedence [ 'Add' ] #NEWLINE# prec_mul = precedence [ 'Mul' ] #NEWLINE# prec_atom = precedence [ 'Atom' ] #NEWLINE# ring = self . ring #NEWLINE# symbols = ring . symbols #NEWLINE# ngens = ring . ngens #NEWLINE# zm = ring . zero_monom #NEWLINE# sexpvs = [ ] #NEWLINE# for ( expv , coeff ) in self . terms ( ) : #NEWLINE# #INDENT# positive = ring . domain . is_positive ( coeff ) #NEWLINE# sign = ( ' + ' if positive else ' - ' ) #NEWLINE# sexpvs . append ( sign ) #NEWLINE# if ( expv == zm ) : #NEWLINE# #INDENT# scoeff = printer . _print ( coeff ) #NEWLINE# if scoeff . startswith ( '-' ) : #NEWLINE# #INDENT# scoeff = scoeff [ 1 : ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not positive ) : #NEWLINE# #INDENT# coeff = ( - coeff ) #NEWLINE# #UNINDENT# if ( coeff != 1 ) : #NEWLINE# #INDENT# scoeff = printer . parenthesize ( coeff , prec_mul , strict = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# scoeff = '' #NEWLINE# #UNINDENT# #UNINDENT# sexpv = [ ] #NEWLINE# for i in range ( ngens ) : #NEWLINE# #INDENT# exp = expv [ i ] #NEWLINE# if ( not exp ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# symbol = printer . parenthesize ( symbols [ i ] , prec_atom , strict = True ) #NEWLINE# if ( exp != 1 ) : #NEWLINE# #INDENT# if ( ( exp != int ( exp ) ) or ( exp < 0 ) ) : #NEWLINE# #INDENT# sexp = printer . parenthesize ( exp , prec_atom , strict = False ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sexp = exp #NEWLINE# #UNINDENT# sexpv . append ( ( exp_pattern % ( symbol , sexp ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sexpv . append ( ( '%s' % symbol ) ) #NEWLINE# #UNINDENT# #UNINDENT# if scoeff : #NEWLINE# #INDENT# sexpv = ( [ scoeff ] + sexpv ) #NEWLINE# #UNINDENT# sexpvs . append ( mul_symbol . join ( sexpv ) ) #NEWLINE# #UNINDENT# if ( sexpvs [ 0 ] in [ ' + ' , ' - ' ] ) : #NEWLINE# #INDENT# head = sexpvs . pop ( 0 ) #NEWLINE# if ( head == ' - ' ) : #NEWLINE# #INDENT# sexpvs . insert ( 0 , '-' ) #NEWLINE# #UNINDENT# #UNINDENT# return '' . join ( sexpvs )