def integrate_result(orig_expr, result, **options):
 if (not isinstance(result, Expr)):
  return result
 options['replace_none'] = True
 if (not ('basis' in options)):
  arg = orig_expr.args[(-1)]
  options['basis'] = get_basis(arg, **options)
 elif (not isinstance(options['basis'], StateBase)):
  options['basis'] = get_basis(orig_expr, **options)
 basis = options.pop('basis', None)
 if (basis is None):
  return result
 unities = options.pop('unities', [])
 if (len(unities) == 0):
  return result
 kets = enumerate_states(basis, unities)
 coords = [k.label[0] for k in kets]
 for coord in coords:
  if (coord in result.free_symbols):
   basis_op = state_to_operators(basis)
   start = basis_op.hilbert_space.interval.start
   end = basis_op.hilbert_space.interval.end
   result = integrate(result, (coord, start, end))
 return result

def integrate_result ( orig_expr , result , ** options ) : if ( not isinstance ( result , Expr ) ) : return result options [ 'replace_none' ] = True if ( not ( 'basis' in options ) ) : arg = orig_expr . args [ ( - 1 ) ] options [ 'basis' ] = get_basis ( arg , ** options ) elif ( not isinstance ( options [ 'basis' ] , StateBase ) ) : options [ 'basis' ] = get_basis ( orig_expr , ** options ) basis = options . pop ( 'basis' , None ) if ( basis is None ) : return result unities = options . pop ( 'unities' , [ ] ) if ( len ( unities ) == 0 ) : return result kets = enumerate_states ( basis , unities ) coords = [ k . label [ 0 ] for k in kets ] for coord in coords : if ( coord in result . free_symbols ) : basis_op = state_to_operators ( basis ) start = basis_op . hilbert_space . interval . start end = basis_op . hilbert_space . interval . end result = integrate ( result , ( coord , start , end ) ) return result
returns the result of integrating over any unities in the given expression .