(ex)
return res
simplify a product of gamma matrices

        Examples
        ========

        >>> from sympy.physics.hep.gamma_matrices import GammaMatrix, DiracSpinorIndex
        >>> from sympy.tensor.tensor import tensor_indices
        >>> i0,i1,i2,i3,i4,i5 = tensor_indices('i0:6', GammaMatrix.LorentzIndex)
        >>> s0,s1,s2,s3,s4,s5,s6,s7 = tensor_indices('s0:8', DiracSpinorIndex)
        >>> G = GammaMatrix
        >>> t = G(i1,s1,-s2)*G(i4,s7,-s6)*G(i2,s2,-s3)*G(i3,s4,-s5)*G(i5,s6,-s7)
        >>> G.simplify_lines(t)
        4*gamma(i3, s4, -s5)*gamma(i1, s1, -S_0)*gamma(i2, S_0, -s3)*metric(i4, i5)
simplify a product of gamma matrices
simplify a product of gamma matrices
def simplify_lines(ex):
        """
        simplify a product of gamma matrices

        Examples
        ========

        >>> from sympy.physics.hep.gamma_matrices import GammaMatrix, DiracSpinorIndex
        >>> from sympy.tensor.tensor import tensor_indices
        >>> i0,i1,i2,i3,i4,i5 = tensor_indices('i0:6', GammaMatrix.LorentzIndex)
        >>> s0,s1,s2,s3,s4,s5,s6,s7 = tensor_indices('s0:8', DiracSpinorIndex)
        >>> G = GammaMatrix
        >>> t = G(i1,s1,-s2)*G(i4,s7,-s6)*G(i2,s2,-s3)*G(i3,s4,-s5)*G(i5,s6,-s7)
        >>> G.simplify_lines(t)
        4*gamma(i3, s4, -s5)*gamma(i1, s1, -S_0)*gamma(i2, S_0, -s3)*metric(i4, i5)

        """
        lines, traces, rest = get_lines(ex, DiracSpinorIndex)
        a = ex.split()
        trest = tensor_mul(*[x for i, x in enumerate(a) if i in rest])
        tlines = []
        for line in lines:
            first = a[line[0]]
            last = a[line[-1]]
            first = [x[0] for x in first.free if x[1] == 1][0]
            last = [x[0] for x in last.free if x[1] == 2][0]
            tx = tensor_mul(*[x for i, x in enumerate(a) if i  in line])
            tx1 = GammaMatrixHead._simplify_single_line(tx)
            tlines.append(tx1)
        traces = [GammaMatrix._trace_single_line(tensor_mul(*[x for i, x in enumerate(a) if i  in line])) for line in traces]
        res = tensor_mul(*([trest] + tlines + traces))
        return res
def simplify_lines ( ex ) : lines , traces , rest = get_lines ( ex , DiracSpinorIndex ) a = ex . split ( ) trest = tensor_mul ( * [ x for i , x in enumerate ( a ) if i in rest ] ) tlines = [ ] for line in lines : first = a [ line [ 0 ] ] last = a [ line [ - 1 ] ] first = [ x [ 0 ] for x in first . free if x [ 1 ] == 1 ] [ 0 ] last = [ x [ 0 ] for x in last . free if x [ 1 ] == 2 ] [ 0 ] tx = tensor_mul ( * [ x for i , x in enumerate ( a ) if i in line ] ) tx1 = GammaMatrixHead . _simplify_single_line ( tx ) tlines . append ( tx1 ) traces = [ GammaMatrix . _trace_single_line ( tensor_mul ( * [ x for i , x in enumerate ( a ) if i in line ] ) ) for line in traces ] res = tensor_mul ( * ( [ trest ] + tlines + traces ) ) return res