Module ImportFrom alias alias ImportFrom alias alias alias alias alias alias alias ImportFrom alias ImportFrom alias FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call NameLoad NameLoad If Call NameLoad NameLoad NameLoad body If BoolOpOr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr BoolOpAnd AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Return NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str If CompareEq Call NameLoad NameLoad Num body Return NameLoad Assign NameStore Call NameLoad NameLoad keyword NameLoad Assign NameStore ListComp NameLoad comprehension TupleStore NameStore NameStore Call NameLoad NameLoad CompareEq NameLoad NameLoad Assign NameStore Call NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr BinOpAdd Call NameLoad NameLoad SubscriptLoad NameLoad Index Num Assign NameStore ListComp ListLoad SubscriptLoad NameLoad Slice SubscriptLoad NameLoad Index NameLoad SubscriptLoad NameLoad Index BinOpAdd NameLoad Num comprehension NameStore Call NameLoad BinOpSub Call NameLoad NameLoad Num Assign NameStore Call AttributeLoad NameLoad attr Call NameLoad NameLoad Assign NameStore SubscriptLoad NameLoad Slice SubscriptLoad NameLoad Index NameLoad BinOpAdd SubscriptLoad NameLoad Index NameLoad Call NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str If CompareEq Call NameLoad NameLoad Num body Return NameLoad Assign NameStore Call NameLoad SubscriptLoad NameLoad Slice Num Expr Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Slice Num Num Return AttributeLoad Call NameLoad NameLoad attr decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam defaults vararg body Expr Str If CompareEq Call NameLoad NameLoad Num body If UnaryOpNot Call NameLoad SubscriptLoad NameLoad Index Num TupleLoad NameLoad NameLoad NameLoad body Assign NameStore Call NameLoad SubscriptLoad NameLoad Index Num orelse Assign NameStore Call NameLoad SubscriptLoad NameLoad Index Num Assign NameStore SubscriptLoad NameLoad Index Num orelse If CompareEq Call NameLoad NameLoad Num body Assign NameStore Call NameLoad Assign NameStore SubscriptLoad NameLoad Index Num orelse Raise Call NameLoad Str If Call NameLoad NameLoad NameLoad body Return Call AttributeLoad NameLoad attr orelse If BoolOpAnd Call NameLoad NameLoad Str Call NameLoad AttributeLoad NameLoad attr body Return Call AttributeLoad NameLoad attr orelse If Call NameLoad NameLoad NameLoad body Return Call NameLoad ListComp Call NameLoad NameLoad NameLoad comprehension NameStore AttributeLoad NameLoad attr orelse If Call NameLoad NameLoad NameLoad body Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr If CompareEq Call NameLoad NameLoad Num body Return Call NameLoad NameLoad orelse Assign NameStore Call AttributeLoad NameLoad attr NameLoad Call NameLoad NameLoad NameLoad Return IfExp CompareGt Call NameLoad NameLoad Num BinOpMult Call NameLoad NameLoad NameLoad NameLoad orelse If Call NameLoad NameLoad NameLoad body If BoolOpAnd Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Num Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Num body Return NameLoad orelse Return Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad orelse If Call NameLoad NameLoad body Return NameLoad Return Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults kwarg body Expr Str If Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Num Str body Return Call AttributeLoad SubscriptLoad AttributeLoad NameLoad attr Index Num attr keyword SubscriptLoad AttributeLoad NameLoad attr Index Num Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Return NameLoad decorator_list NameLoad FunctionDef arguments args NameParam NameParam defaults body Expr Str If CompareGt NameLoad Num body Assign NameStore BinOpMod NameLoad Call NameLoad AttributeLoad SubscriptLoad AttributeLoad NameLoad attr Index Num attr orelse Assign NameStore UnaryOpUSub BinOpMod Call NameLoad NameLoad Call NameLoad AttributeLoad SubscriptLoad AttributeLoad NameLoad attr Index Num attr Assign NameStore Call NameLoad BinOpAdd SubscriptLoad AttributeLoad SubscriptLoad AttributeLoad NameLoad attr Index Num attr Slice UnaryOpUSub NameLoad SubscriptLoad AttributeLoad SubscriptLoad AttributeLoad NameLoad attr Index Num attr Slice Num UnaryOpUSub NameLoad Return Call NameLoad Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body If Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Num NameLoad body Assign NameStore Call NameLoad Call NameLoad AttributeLoad SubscriptLoad AttributeLoad NameLoad attr Index Num attr orelse Assign NameStore ListLoad SubscriptLoad AttributeLoad NameLoad attr Index Num Return BinOpAdd Call NameLoad NameLoad TupleLoad SubscriptLoad AttributeLoad NameLoad attr Index Num decorator_list decorator_list
N/A __future__ print_function division sympy Expr Add Mul Pow sympify Matrix Tuple sympy.core.compatibility range sympy.utilities default_sort_key _is_scalar N/A N/A e N/A N/A N/A  Helper method used in Tr N/A e N/A sympify e N/A N/A isinstance e Expr N/A N/A N/A N/A e is_Integer N/A e is_Float N/A e is_Rational N/A e is_Number N/A N/A e is_Symbol N/A e is_commutative N/A N/A True N/A False N/A _cycle_permute N/A N/A l N/A N/A N/A  Cyclic permutations based on canonical ordering

    This method does the sort based ascii values while
    a better approach would be to used lexicographic sort.
    TODO: Handle condition such as symbols have subscripts/superscripts
    in case of lexicographic sort

     N/A N/A N/A len l 1 N/A N/A l N/A min_item N/A min l key default_sort_key N/A indices N/A i N/A N/A i x N/A enumerate l N/A x min_item N/A le N/A list l N/A N/A N/A le extend l N/A N/A N/A indices append N/A N/A len l N/A indices N/A 0 N/A sublist N/A N/A N/A le N/A N/A indices N/A i N/A indices N/A N/A i 1 N/A i N/A range N/A N/A len indices 1 N/A idx N/A N/A sublist index N/A min sublist N/A ordered_l N/A le N/A N/A indices N/A idx N/A N/A indices N/A idx N/A len l N/A ordered_l N/A _rearrange_args N/A N/A l N/A N/A N/A  this just moves the last arg to first position
     to enable expansion of args
     A,B,A ==> A**2,B
     N/A N/A N/A len l 1 N/A N/A l N/A x N/A list N/A l N/A -1 N/A N/A N/A x extend N/A l N/A 0 -1 N/A N/A N/A Mul x args N/A Tr N/A Expr N/A N/A  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.core.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

     __new__ N/A N/A cls N/A args N/A N/A  Construct a Trace object.

        Parameters
        ==========
        args = sympy expression
        indices = tuple/list if indices, optional

         N/A N/A N/A len args 2 N/A N/A N/A N/A isinstance N/A args N/A 1 N/A list Tuple tuple N/A N/A indices N/A Tuple N/A args N/A 1 N/A N/A indices N/A Tuple N/A args N/A 1 N/A expr N/A args N/A 0 N/A N/A N/A N/A len args 1 N/A N/A indices N/A Tuple N/A expr N/A args N/A 0 N/A N/A N/A ValueError Arguments to Tr should be of form (expr[, [indices]]) N/A N/A isinstance expr Matrix N/A N/A N/A N/A expr trace N/A N/A N/A N/A hasattr expr trace N/A callable N/A expr trace N/A N/A N/A N/A expr trace N/A N/A N/A isinstance expr Add N/A N/A N/A Add N/A N/A Tr arg indices N/A arg N/A expr args N/A N/A N/A isinstance expr Mul N/A N/A N/A c_part nc_part N/A N/A expr args_cnc N/A N/A N/A len nc_part 0 N/A N/A N/A Mul c_part N/A N/A obj N/A N/A Expr __new__ cls N/A Mul nc_part indices N/A N/A N/A N/A len c_part 0 N/A N/A Mul c_part obj obj N/A N/A N/A isinstance expr Pow N/A N/A N/A N/A _is_scalar N/A N/A expr args N/A 0 N/A _is_scalar N/A N/A expr args N/A 1 N/A N/A expr N/A N/A N/A N/A Expr __new__ cls expr indices N/A N/A N/A _is_scalar expr N/A N/A expr N/A N/A N/A Expr __new__ cls expr indices N/A doit N/A N/A self N/A kwargs N/A N/A  Perform the trace operation.

        #TODO: Current version ignores the indices set for partial trace.

        >>> from sympy.core.trace import Tr
        >>> from sympy.physics.quantum.operator import OuterProduct
        >>> from sympy.physics.quantum.spin import JzKet, JzBra
        >>> t = Tr(OuterProduct(JzKet(1,1), JzBra(1,1)))
        >>> t.doit()
        1

         N/A N/A hasattr N/A N/A self args N/A 0 _eval_trace N/A N/A N/A N/A N/A N/A self args N/A 0 _eval_trace indices N/A N/A self args N/A 1 N/A self N/A is_number N/A N/A self N/A N/A N/A True N/A property permute N/A N/A self pos N/A N/A N/A  Permute the arguments cyclically.

        Parameters
        ==========
        pos : integer, if positive, shift-right, else shift-left

        Examples
        ========

        >>> from sympy.core.trace import Tr
        >>> from sympy import symbols
        >>> A, B, C, D = symbols('A B C D', commutative=False)
        >>> t = Tr(A*B*C*D)
        >>> t.permute(2)
        Tr(C*D*A*B)
        >>> t.permute(-2)
        Tr(C*D*A*B)

         N/A N/A pos 0 N/A N/A pos N/A pos N/A len N/A N/A N/A self args N/A 0 args N/A N/A pos N/A N/A N/A abs pos N/A len N/A N/A N/A self args N/A 0 args N/A args N/A list N/A N/A N/A N/A N/A self args N/A 0 args N/A N/A pos N/A N/A N/A N/A self args N/A 0 args N/A 0 N/A pos N/A N/A Tr N/A Mul args N/A _hashable_content N/A N/A self N/A N/A N/A N/A isinstance N/A N/A self args N/A 0 Mul N/A N/A args N/A _cycle_permute N/A _rearrange_args N/A N/A N/A self args N/A 0 args N/A N/A args N/A N/A N/A self args N/A 0 N/A N/A N/A tuple args N/A N/A N/A self args N/A 1 N/A N/A