class_docstr: Generic Trace operation than can trace over:
  
  a) SymPy matrix
  b) operators
  c) outer products
  
  Parameters
  ==========
  o : operator, matrix, expr
  i : tuple/list indices (optional)
  
  Examples
  ========
  
  # TODO: Need to handle printing
  
  a) Trace(A+B) = Tr(A) + Tr(B)
  b) Trace(scalar*Operator) = scalar*Trace(Operator)
  
  >>> from sympy.physics.quantum.trace import Tr
  >>> from sympy import symbols, Matrix
  >>> a, b = symbols('a b', commutative=True)
  >>> A, B = symbols('A B', commutative=False)
  >>> Tr(a*A,[2])
  a*Tr(A)
  >>> m = Matrix([[1,2],[1,1]])
  >>> Tr(m)
  2
class_docstr_tok: ["Generic","Trace","operation","than","can","trace","over",":","a",")","SymPy","matrix","b",")","operators","c",")","outer","products","Parameters","==========","o",":","operator",",","matrix",",","expr","i",":","tuple\/list","indices","(","optional",")","Examples","========","#","TODO",":","Need","to","handle","printing","a",")","Trace","(","A+B",")","=","Tr","(","A",")","+","Tr","(","B",")","b",")","Trace","(","scalar","*","Operator",")","=","scalar","*","Trace","(","Operator",")",">",">",">","from","sympy.physics.quantum.trace","import","Tr",">",">",">","from","sympy","import","symbols",",","Matrix",">",">",">","a",",","b","=","symbols","(","'","a","b","'",",","commutative=True",")",">",">",">","A",",","B","=","symbols","(","'","A","B","'",",","commutative=False",")",">",">",">","Tr","(","a","*","A",",","[","2","]",")","a","*","Tr","(","A",")",">",">",">","m","=","Matrix","(","[","[","1,2","]",",","[","1,1","]","]",")",">",">",">","Tr","(","m",")","2"]
docstr: Construct a Trace object.
  
  Parameters
  ==========
  args = SymPy expression
  indices = tuple/list if indices, optional
docstr_tok: ["Construct","a","Trace","object",".","Parameters","==========","args","=","SymPy","expression","indices","=","tuple\/list","if","indices",",","optional"]
code: def __new__(cls, *args):
      """Construct a Trace object.
  
      Parameters
      ==========
      args = SymPy expression
      indices = tuple/list if indices, optional
  
      """
  
      # expect no indices,int or a tuple/list/Tuple
      if len(args) == 2:
          if not isinstance(args[1], (list, Tuple, tuple)):
              indices = Tuple(args[1])
          else:
              indices = Tuple(*args[1])
  
          expr = args[0]
      elif len(args) == 1:
          indices = Tuple()
          expr = args[0]
      else:
          raise ValueError(
              "Arguments to Tr should be of form " "(expr[, [indices]])"
          )
  
      if isinstance(expr, Matrix):
          return expr.trace()
      elif hasattr(expr, "trace") and callable(expr.trace):
          # for any objects that have trace() defined e.g numpy
          return expr.trace()
      elif isinstance(expr, Add):
          return Add(*[Tr(arg, indices) for arg in expr.args])
      elif isinstance(expr, Mul):
          c_part, nc_part = expr.args_cnc()
          if len(nc_part) == 0:
              return Mul(*c_part)
          else:
              obj = Expr.__new__(cls, Mul(*nc_part), indices)
              # this check is needed to prevent cached instances
              # being returned even if len(c_part)==0
              return Mul(*c_part) * obj if len(c_part) > 0 else obj
      elif isinstance(expr, Pow):
          if _is_scalar(expr.args[0]) and _is_scalar(expr.args[1]):
              return expr
          else:
              return Expr.__new__(cls, expr, indices)
      else:
          if _is_scalar(expr):
              return expr
  
          return Expr.__new__(cls, expr, indices)
  
file_path: sympy/sympy/physics/quantum/trace.py
imports: from sympy.core.add import Add
  from sympy.core.containers import Tuple
  from sympy.core.expr import Expr
  from sympy.core.mul import Mul
  from sympy.core.power import Pow
  from sympy.core.sorting import default_sort_key
  from sympy.core.sympify import sympify
  from sympy.matrices import Matrix
label_desc: Use image node_id 1 for calling the Tr obj's underlying member method code with example usage: obj.__new__(cls) and returns: expr, expr, Add, Mul, unknown, Expr, expr, Expr, expr