#NEWLINE# def __sub__( p1 , p2 ) : #NEWLINE# #INDENT# "Subtract polynomial p2 from p1.\n\n        Examples\n        ========\n\n        >>> from sympy.polys.domains import ZZ\n        >>> from sympy.polys.rings import ring\n\n        >>> _, x, y = ring('x, y', ZZ)\n        >>> p1 = x + y**2\n        >>> p2 = x*y + y**2\n        >>> p1 - p2\n        -x*y + x\n\n        " #NEWLINE# if ( not p2 ) : #NEWLINE# #INDENT# return p1 . copy ( ) #NEWLINE# #UNINDENT# ring = p1 . ring #NEWLINE# if isinstance ( p2 , ring . dtype ) : #NEWLINE# #INDENT# p = p1 . copy ( ) #NEWLINE# get = p . get #NEWLINE# zero = ring . domain . zero #NEWLINE# for ( k , v ) in p2 . items ( ) : #NEWLINE# #INDENT# v = ( get ( k , zero ) - v ) #NEWLINE# if v : #NEWLINE# #INDENT# p [ k ] = v #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# del p [ k ] #NEWLINE# #UNINDENT# #UNINDENT# return p #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( p2 , PolyElement ) : #NEWLINE# #INDENT# if ( isinstance ( ring . domain , PolynomialRing ) and ( ring . domain . ring == p2 . ring ) ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( p2 . ring . domain , PolynomialRing ) and ( p2 . ring . domain . ring == ring ) ) : #NEWLINE# #INDENT# return p2 . __rsub__ ( zero ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return NotImplemented #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# p2 = ring . domain_new ( p2 ) #NEWLINE# #UNINDENT# except CoercionFailed : #NEWLINE# #INDENT# return NotImplemented #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# p = p1 . copy ( ) #NEWLINE# zm = ring . zero_monom #NEWLINE# if ( zm not in p1 . keys ( ) ) : #NEWLINE# #INDENT# p [ zm ] = ( - p2 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( p2 == p [ zm ] ) : #NEWLINE# #INDENT# del p [ zm ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# p [ zm ] -= p2 #NEWLINE# #UNINDENT# #UNINDENT# return p