Density Matrices I

Consider a matrix

A=Table[Random[],{i,1,2},{j,1,2}];
MatrixForm[A]

The trace of a matrix is defined as the sum over all diagonal elements of the matrix

Tr[A]

An important property of the trace is that it is invarinat under a unditary transformation

U[θ_,ϕ_]=(({{Cos[(θ/2)], -(E^(-I ϕ)) Sin[(θ/2)]}, {(E^(I ϕ)) Sin[(θ/2)], Cos[(θ/2)]}}));
Udag[θ_,ϕ_]=(({{Cos[(θ/2)], (E^(-I ϕ)) Sin[(θ/2)]}, {-(E^(I ϕ)) Sin[(θ/2)], Cos[(θ/2)]}}));

Atransformed=FullSimplify[U[θ,ϕ].A.Udag[θ,ϕ]];
MatrixForm[Atransformed]

Tr[Atransformed]
Chop[%]

We know that matrices are representations of operators in Hilbert space.  According  to the above  definition if A is an operator in Hilbert space , then

Tr[A]=   (∑_i) (Subscript[A, ii])   where   (Subscript[A, ii]) =⟨ i|A|i ⟩ ; and  |i  >  
is an orthonormal  basis     vector in our Hilbert space, the sum is over a complete   set of basis  states  |i >.    

(Note: Different basis will result in different  matrices,
it  is our custom to always work in the computational basis)

Suppose A is an  operator and  ρ =  |ψ ⟩⟨ψ| is a projection operator. |ψ ⟩ is our system state  vector;  then  
                                                      
                                                      Tr[A ρ]  =  ⟨ψ|A|ψ⟩

Proof:     Tr[A ρ]=∑ ⟨ i | A ρ|i ⟩ = ∑  ⟨i| A|ψ⟩<ψ|i ⟩=   ∑ ⟨ ψ|i ⟩⟨ i| A|ψ⟩=⟨ψ|A|ψ⟩

Thus in order to find the expectation value of a measurement all we need  to do
is to construct the projection operator in our computation basis

ψ=1/Sqrt[2]{Exp[I ω t],I}
Sz={{1,0},{0,-1}};
Sx={{0,1},{1,0}};
Sy={{0,-I},{I,0}};

ρ=ComplexExpand[KroneckerProduct[ψ,Conjugate[ψ]]];
MatrixForm[ρ]

⟨ψ| (Subscript[S, z])| ψ⟩

Tr[Sz.ρ]

⟨ψ| (Subscript[S, y])| ψ⟩

Simplify[Tr[Sy.ρ]]

⟨ψ| (Subscript[S, x])| ψ⟩

"<σx>";

Simplify[Tr[Sx.ρ]]

But that’s not all

Consider the following

Tr[ (SuperDagger[(Subscript[M, a])])(Subscript[M, a])  ρ]    where   (Subscript[M, a])=|a ⟩⟨a|   and |a⟩  is an eigenstate of  some  operator Hermitian
operator M.

then  Tr[ (SuperDagger[(Subscript[M, a])])(Subscript[M, a])  ρ] =⟨ψ|(SuperDagger[(Subscript[M, a])])(Subscript[M, a])|ψ⟩  =⟨ψ | a ⟩  ⟨a|ψ⟩   = |⟨a|ψ⟩((|)^2)

but by the Born rule, |⟨a|ψ⟩((|)^2) is the probability to obtain eigenvalue a after a
measurement of the physical observable associated with operator M.

i.e.
                  p(a) = Tr[ (SuperDagger[(Subscript[M, a])])(Subscript[M, a])  ρ]

Suppose we wish to make a measurement with the Pauli gate, whose eigenvalues are ±1, when
the system is in state |ψ⟩. In order to find the probability that a measurement of (Subscript[S, x]) gives the value
+1, we need to construct   (Subscript[M, a]) = |a⟩⟨a| for this eigenvalue. We know from previous work that
|a= 1⟩ = (1/(Sqrt[2])) |0⟩ + (1/(Sqrt[2])) |1⟩

astate=1/Sqrt[2]{1,1};
Ma=KroneckerProduct[astate,astate]
Madagger=Ma;

Simplify[Tr[Madagger.Ma.ρ]]

To find the probability of a measurement resulting in -1, we construct  Ma from the state
|a= -1⟩ = (1/(Sqrt[2])) |0⟩ -  (1/(Sqrt[2])) |1⟩

astate=1/Sqrt[2]{1,-1};
Ma=KroneckerProduct[astate,astate]
Madagger=Ma;

Simplify[Tr[Madagger.Ma.ρ]]

The operator  ρ=|ψ⟩⟨ψ|  where |ψ⟩  is the system state function is called a density operator.   With it, and the measurement projection operators   (Subscript[M, a]); we can predict all possible probablities,mean values and other statistical properties, of  repeated measurement (ensemble of measurements) of the system in quantum state |ψ⟩.
The probability p(a) of outcome "a"   associated with measurement  M=∑ a  (Subscript[M, a])  is equal to
Tr[  (SuperDagger[(Subscript[M, a])]) (Subscript[M, a]) ρ] where ρ=|ψ ⟩⟨ψ|