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))

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 ) )
returns an <x|a|x> type representation for the given operator .