(cls, a, b)
The Commutator [A,B] is on canonical form if A < B.

        Examples
        ========

        >>> from sympy.physics.secondquant import Commutator, F, Fd
        >>> from sympy.abc import x
        >>> c1 = Commutator(F(x), Fd(x))
        >>> c2 = Commutator(Fd(x), F(x))
        >>> Commutator.eval(c1, c2)
        0
The Commutator [A,B] is on canonical form if A < B.
The Commutator [ A B ] is on canonical form if A < B .
def eval(cls, a, b):
        """
        The Commutator [A,B] is on canonical form if A < B.

        Examples
        ========

        >>> from sympy.physics.secondquant import Commutator, F, Fd
        >>> from sympy.abc import x
        >>> c1 = Commutator(F(x), Fd(x))
        >>> c2 = Commutator(Fd(x), F(x))
        >>> Commutator.eval(c1, c2)
        0
        """
        if not (a and b):
            return S.Zero
        if a == b:
            return S.Zero
        if a.is_commutative or b.is_commutative:
            return S.Zero

        #
        # [A+B,C]  ->  [A,C] + [B,C]
        #
        a = a.expand()
        if isinstance(a, Add):
            return Add(*[cls(term, b) for term in a.args])
        b = b.expand()
        if isinstance(b, Add):
            return Add(*[cls(a, term) for term in b.args])

        #
        # [xA,yB]  ->  xy*[A,B]
        #
        ca, nca = a.args_cnc()
        cb, ncb = b.args_cnc()
        c_part = list(ca) + list(cb)
        if c_part:
            return Mul(Mul(*c_part), cls(Mul._from_args(nca), Mul._from_args(ncb)))

        #
        # single second quantization operators
        #
        if isinstance(a, BosonicOperator) and isinstance(b, BosonicOperator):
            if isinstance(b, CreateBoson) and isinstance(a, AnnihilateBoson):
                return KroneckerDelta(a.state, b.state)
            if isinstance(a, CreateBoson) and isinstance(b, AnnihilateBoson):
                return S.NegativeOne*KroneckerDelta(a.state, b.state)
            else:
                return S.Zero
        if isinstance(a, FermionicOperator) and isinstance(b, FermionicOperator):
            return wicks(a*b) - wicks(b*a)

        #
        # Canonical ordering of arguments
        #
        if a.sort_key() > b.sort_key():
            return S.NegativeOne*cls(b, a)
def eval ( cls , a , b ) : if not ( a and b ) : return S . Zero if a == b : return S . Zero if a . is_commutative or b . is_commutative : return S . Zero # # [A+B,C]  ->  [A,C] + [B,C] # a = a . expand ( ) if isinstance ( a , Add ) : return Add ( * [ cls ( term , b ) for term in a . args ] ) b = b . expand ( ) if isinstance ( b , Add ) : return Add ( * [ cls ( a , term ) for term in b . args ] ) # # [xA,yB]  ->  xy*[A,B] # ca , nca = a . args_cnc ( ) cb , ncb = b . args_cnc ( ) c_part = list ( ca ) + list ( cb ) if c_part : return Mul ( Mul ( * c_part ) , cls ( Mul . _from_args ( nca ) , Mul . _from_args ( ncb ) ) ) # # single second quantization operators # if isinstance ( a , BosonicOperator ) and isinstance ( b , BosonicOperator ) : if isinstance ( b , CreateBoson ) and isinstance ( a , AnnihilateBoson ) : return KroneckerDelta ( a . state , b . state ) if isinstance ( a , CreateBoson ) and isinstance ( b , AnnihilateBoson ) : return S . NegativeOne * KroneckerDelta ( a . state , b . state ) else : return S . Zero if isinstance ( a , FermionicOperator ) and isinstance ( b , FermionicOperator ) : return wicks ( a * b ) - wicks ( b * a ) # # Canonical ordering of arguments # if a . sort_key ( ) > b . sort_key ( ) : return S . NegativeOne * cls ( b , a )