# Braket

Braket(psi1, O, psi2) calculates the expectation value or matrix element $\left\langle \psi_1 \mid O \mid \psi_2 \right\rangle$. In Quanty Braket(psi1, O, psi2) is the same as psi1 * O * psi2. The difference is that the function Braket can be faster. Braket can work on lists of functions and then returns a matrix or vector with all possible expectation values

## Input

• psi1 or psiList1 : Wavefunction or list of Wavefunctions
• O : Operator
• psi2 or psiList2 : Wavefunction or list of Wavefunctions

## Output

• real or complex number, or a list of these or a matrix of these

## Example

The example calculates the expectation values of a few states

### Input

Example.Quanty
NF=2
NB=0
IndexDn={0}
IndexUp={1}

psi0=NewWavefunction(NF,NB,{{"10",1}})
psi1=NewWavefunction(NF,NB,{{"01",1}})

OppSx   = NewOperator("Sx"   ,NF,IndexUp,IndexDn)
OppSy   = NewOperator("Sy"   ,NF,IndexUp,IndexDn)
OppSz   = NewOperator("Sz"   ,NF,IndexUp,IndexDn)

print("The expectation value of a single state")
print(Braket(psi0,OppSz,psi0))

print("The expectation value of two states with a single state")
print(Braket(psi0,OppSx,{psi0,psi1}))

-- note that I made one list of length 3, the other of length 2 so that the order is clear
print("The expectation value of a three states with two other states")
print(Braket({psi0,psi1},OppSy,{psi0,psi1,psi1}))

### Result

The expectation value of a single state
-0.5
The expectation value of two states with a single state
{ 0 , 0.5 }
The expectation value of a three states with two other states
{ { 0 , (0 + 0.5 I) , (0 + 0.5 I) } ,
{ (0 - 0.5 I) , 0 , 0 } }