def evaluate_pauli_product(arg):
 start = arg
 end = arg
 if (not isinstance(arg, Mul)):
  return arg
 while ((not (start == end)) | ((start == arg) & (end == arg))):
  start = end
  tmp = start.as_coeff_mul()
  sigma_product = 1
  com_product = 1
  keeper = 1
  for el in tmp[1]:
   if isinstance(el, Pauli):
    sigma_product *= el
   elif (not el.is_commutative):
    keeper = ((keeper * sigma_product) * el)
    sigma_product = 1
   else:
    com_product *= el
  end = (((tmp[0] * keeper) * sigma_product) * com_product)
  if (end == arg):
   break
 return end

def evaluate_pauli_product ( arg ) : start = arg end = arg if ( not isinstance ( arg , Mul ) ) : return arg while ( ( not ( start == end ) ) | ( ( start == arg ) & ( end == arg ) ) ) : start = end tmp = start . as_coeff_mul ( ) sigma_product = 1 com_product = 1 keeper = 1 for el in tmp [ 1 ] : if isinstance ( el , Pauli ) : sigma_product *= el elif ( not el . is_commutative ) : keeper = ( ( keeper * sigma_product ) * el ) sigma_product = 1 else : com_product *= el end = ( ( ( tmp [ 0 ] * keeper ) * sigma_product ) * com_product ) if ( end == arg ) : break return end
help function to evaluate pauli matrices product with symbolic objects parameters arg: symbolic expression that contains paulimatrices examples .