#NEWLINE# @ staticmethod #NEWLINE# def simplify_gpgp( ex , sort = True ) : #NEWLINE# #INDENT# "\n        simplify products ``G(i)*p(-i)*G(j)*p(-j) -> p(i)*p(-i)``\n\n        Examples\n        ========\n\n        >>> from sympy.physics.hep.gamma_matrices import GammaMatrix as G\n        >>> from sympy.tensor.tensor import tensor_indices, tensorhead\n        >>> p, q = tensorhead('p, q', [G.LorentzIndex], [[1]])\n        >>> i0,i1,i2,i3,i4,i5 = tensor_indices('i0:6', G.LorentzIndex)\n        >>> ps = p(i0)*G(-i0)\n        >>> qs = q(i0)*G(-i0)\n        >>> G.simplify_gpgp(ps*qs*qs)\n        gamma(-L_0, auto_left, -auto_right)*p(L_0)*q(L_1)*q(-L_1)\n        " #NEWLINE# def _simplify_gpgp( ex ) : #NEWLINE# #INDENT# tids = ex . _tids #NEWLINE# components = tids . components #NEWLINE# a = [ ] #NEWLINE# for i in range ( len ( components ) ) : #NEWLINE# #INDENT# if ( not isinstance ( components [ i ] , GammaMatrixHead ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# dum = tids . dum #NEWLINE# for dx in dum : #NEWLINE# #INDENT# if ( dx [ 2 ] == i ) : #NEWLINE# #INDENT# p_pos1 = dx [ 3 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( dx [ 3 ] == i ) : #NEWLINE# #INDENT# p_pos1 = dx [ 2 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# comp1 = components [ p_pos1 ] #NEWLINE# if ( ( comp1 . comm == 0 ) and ( comp1 . rank == 1 ) ) : #NEWLINE# #INDENT# a . append ( ( i , p_pos1 ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not a ) : #NEWLINE# #INDENT# return ex #NEWLINE# #UNINDENT# elim = set ( ) #NEWLINE# tv = [ ] #NEWLINE# hit = True #NEWLINE# coeff = S . One #NEWLINE# ta = None #NEWLINE# while hit : #NEWLINE# #INDENT# hit = False #NEWLINE# for ( i , ai ) in enumerate ( a [ : ( - 1 ) ] ) : #NEWLINE# #INDENT# if ( ai [ 0 ] in elim ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( ai [ 0 ] != ( a [ ( i + 1 ) ] [ 0 ] - 1 ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( components [ ai [ 1 ] ] != components [ a [ ( i + 1 ) ] [ 1 ] ] ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# elim . add ( ai [ 0 ] ) #NEWLINE# elim . add ( ai [ 1 ] ) #NEWLINE# elim . add ( a [ ( i + 1 ) ] [ 0 ] ) #NEWLINE# elim . add ( a [ ( i + 1 ) ] [ 1 ] ) #NEWLINE# if ( not ta ) : #NEWLINE# #INDENT# ta = ex . split ( ) #NEWLINE# mu = TensorIndex ( 'mu' , GammaMatrix . LorentzIndex ) #NEWLINE# #UNINDENT# ind1 = ta [ ai [ 0 ] ] . get_indices ( ) [ 1 ] #NEWLINE# ind2 = ta [ ( ai [ 0 ] + 1 ) ] . get_indices ( ) [ 2 ] #NEWLINE# hit = True #NEWLINE# if ( i == 0 ) : #NEWLINE# #INDENT# coeff = ex . coeff #NEWLINE# #UNINDENT# tx = ( components [ ai [ 1 ] ] ( mu ) * components [ ai [ 1 ] ] ( ( - mu ) ) ) #NEWLINE# tv . append ( ( tx * DiracSpinorIndex . delta ( ind1 , ind2 ) ) ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if tv : #NEWLINE# #INDENT# a = [ x for ( j , x ) in enumerate ( ta ) if ( j not in elim ) ] #NEWLINE# a . extend ( tv ) #NEWLINE# t = ( tensor_mul ( * a ) * coeff ) #NEWLINE# t = t . contract_metric ( DiracSpinorIndex . delta ) #NEWLINE# return t #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ex #NEWLINE# #UNINDENT# #UNINDENT# if sort : #NEWLINE# #INDENT# ex = ex . sorted_components ( ) #NEWLINE# #UNINDENT# while 1 : #NEWLINE# #INDENT# t = _simplify_gpgp ( ex ) #NEWLINE# if ( t != ex ) : #NEWLINE# #INDENT# ex = _simplify_gpgp #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return t