(expr, **options)
return qapply(bra*expr*ket)
Returns an ``<x'|A|x>`` type representation for the given operator.

    Parameters
    ==========

    expr : Operator
        Operator to be represented in the specified basis

    Examples
    ========

    >>> from sympy.physics.quantum.cartesian import XOp, XKet, PxOp, PxKet
    >>> from sympy.physics.quantum.represent import rep_expectation
    >>> rep_expectation(XOp())
    x_1*DiracDelta(x_1 - x_2)
    >>> rep_expectation(XOp(), basis=PxOp())
    <px_2|*X*|px_1>
    >>> rep_expectation(XOp(), basis=PxKet())
    <px_2|*X*|px_1>
Returns an ``<x'|A|x>`` type representation for the given operator.
Returns an <x |A|x > type representation for the given operator .
def rep_expectation(expr, **options):
    """
    Returns an ``<x'|A|x>`` type representation for the given operator.

    Parameters
    ==========

    expr : Operator
        Operator to be represented in the specified basis

    Examples
    ========

    >>> from sympy.physics.quantum.cartesian import XOp, XKet, PxOp, PxKet
    >>> from sympy.physics.quantum.represent import rep_expectation
    >>> rep_expectation(XOp())
    x_1*DiracDelta(x_1 - x_2)
    >>> rep_expectation(XOp(), basis=PxOp())
    <px_2|*X*|px_1>
    >>> rep_expectation(XOp(), basis=PxKet())
    <px_2|*X*|px_1>

    """

    if not "index" in options:
        options["index"] = 1

    if not isinstance(expr, Operator):
        raise TypeError("The passed expression is not an operator")

    basis_state = get_basis(expr, **options)

    if basis_state is None or not isinstance(basis_state, StateBase):
        raise NotImplementedError("Could not get basis kets for this operator")

    basis_kets = enumerate_states(basis_state, options["index"], 2)

    bra = basis_kets[1].dual
    ket = basis_kets[0]

    return qapply(bra*expr*ket)
def rep_expectation ( expr , * * options ) : if not "index" in options : options [ "index" ] = 1 if not isinstance ( expr , Operator ) : raise TypeError ( "The passed expression is not an operator" ) basis_state = get_basis ( expr , * * options ) if basis_state is None or not isinstance ( basis_state , StateBase ) : raise NotImplementedError ( "Could not get basis kets for this operator" ) basis_kets = enumerate_states ( basis_state , options [ "index" ] , 2 ) bra = basis_kets [ 1 ] . dual ket = basis_kets [ 0 ] return qapply ( bra * expr * ket )