Info Theory homework
from matplotlib.pyplot import plot
import matplotlib.pyplot as plt
import numpy as np
from numpy import array, sqrt, dot, matmul
Here is one set of basis vectors.
$$ \hat{a}_1 = [1, 0, 0, 0] \\ \hat{a}_2 = [0, 1, 0, 0] \\ \hat{a}_3 = [0, 0, 1, 0] \\ \hat{a}_4 = [0, 0, 0, 1] \\ $$And here is another set of basis vectors.
$$ \begin{align} \hat{b}_1 & = [1, 1, 1, 1] \frac{1}{2} \\ \hat{b}_2 & = [1, 0, -1, 0] \frac{1}{\sqrt{2}} \\ \hat{b}_3 & = [0, 1, 0, -1] \frac{1}{\sqrt{2}} \\ \hat{b}_4 & = [1, -1, 1, -1] \frac{1}{2} \\ \end{align} $$And here is a vector.
$$ \begin{align} \vec{c} & = c_1 \hat{a}_1 + c_2 \hat{a}_2 + c_3 \hat{a}_3 + c_4 \hat{a}_4 \\ & = [c_1, c_2, c_3, c_4] \\ & = [5, 1, 7, -3] \\ \end{align} $$Show by direct calculation using the dot product that each of these sets is orthonormal, which means that they are all length one and that any two different ones from the same set are perpendicular, i.e.
$$ \hat{x}_m \cdot \hat{x}_n =\begin{cases} 1 & \text{if} & m = n \\ 0 & \text{if} & m \ne n \\ \end{cases} $$where
$$ x \, \text{is either} \, a \, \text{or} \, b \\ m, n \, \text{are each one of } \, 1,2,3,4 \\ $$Find the coeficients $d_i$ of $\vec{c}$ in the $\hat{b}$ basis. In other words, find the four d's such that
$$ \vec{c} = d_1 \hat{b}_1 + d_2 \hat{b}_2 + d_3 \hat{b}_3 + d_4 \hat{b}_4 \\ $$Hints:
# basis vectors |a0> through |a3>
a = [None]*45
a[0] = array([1,0,0,0])
a[1] = array([0,1,0,0])
a[2] = array([0,0,1,0])
a[3] = array([0,0,0,1])
# show that dot(a_i, a_i) is 1 for all i
for i in range(4):
print(f"dot(a[{i}], a[{i}] is {dot(a[i], a[i])}")
dot(a[0], a[0] is 1 dot(a[1], a[1] is 1 dot(a[2], a[2] is 1 dot(a[3], a[3] is 1
# show that dot(a_i, a_j) is 0 for all i != j
for i in range(4):
for j in range(4):
if i != j:
print(f"dot(a[{i}], a[{j}] is {dot(a[i], a[j])}")
dot(a[0], a[1] is 0 dot(a[0], a[2] is 0 dot(a[0], a[3] is 0 dot(a[1], a[0] is 0 dot(a[1], a[2] is 0 dot(a[1], a[3] is 0 dot(a[2], a[0] is 0 dot(a[2], a[1] is 0 dot(a[2], a[3] is 0 dot(a[3], a[0] is 0 dot(a[3], a[1] is 0 dot(a[3], a[2] is 0
# basis vectors |b0> through |b3>
b = [None]*4
b[0] = array( [1, 1, 1, 1] ) * 1/2
b[1] = array( [1, 0, -1, 0]) * 1/sqrt(2)
b[2] = array( [0, 1, 0, -1]) * 1/sqrt(2)
b[3] = array( [1, -1, 1, -1]) * 1/2
# bra vector <foo| ... an example vector
foo = np.array([0, 1, 1, 0])
# show that dot(b_i, b_i) is 1 for all i
for i in range(4):
print(f"dot(b[{i}], b[{i}] is {dot(b[i], b[i])}")
dot(b[0], b[0] is 1.0 dot(b[1], b[1] is 0.9999999999999998 dot(b[2], b[2] is 0.9999999999999998 dot(b[3], b[3] is 1.0
# show that dot(b_i, b_j) is 0 for all i != j
for i in range(4):
for j in range(4):
if i != j:
print(f"dot(b[{i}], b[{j}] is {dot(b[i], b[j])}")
dot(b[0], b[1] is 0.0 dot(b[0], b[2] is 0.0 dot(b[0], b[3] is 0.0 dot(b[1], b[0] is 0.0 dot(b[1], b[2] is 0.0 dot(b[1], b[3] is 0.0 dot(b[2], b[0] is 0.0 dot(b[2], b[1] is 0.0 dot(b[2], b[3] is 0.0 dot(b[3], b[0] is 0.0 dot(b[3], b[1] is 0.0 dot(b[3], b[2] is 0.0
# bra vector <c| in the generic (a) basis.
c = array([5, 1, 7, -3])
# "c in the b basis" is the numbers <b[i] | c>
#
c_in_b_basis = array([ dot(b[i], c) for i in range(4)])
print(c_in_b_basis)
print("rows and columns")
print(c_in_b_basis.shape)
[ 5. -1.41421356 2.82842712 7. ] rows and columns (4,)
# all 4 b basis vectors as a matrix, one column per basis vector
b_columns = array(b).transpose()
b_columns.shape
(4, 4)
b_columns
array([[ 0.5 , 0.70710678, 0. , 0.5 ], [ 0.5 , 0. , 0.70710678, -0.5 ], [ 0.5 , -0.70710678, 0. , 0.5 ], [ 0.5 , 0. , -0.70710678, -0.5 ]])
# check to see if our "c_in_b_basis" is correct
# by adding together each column of b_columns multiplied by
# each column of b multiplied by one of the coefficients of "c_in_b_basis"
#
# In the bra-ket notation, this multiplication is :
#
# sum over j of ( <a_i | b_j> ) <b_j|c>
# matrix column vector
# a[i] coord of b[j] basis * b[j] coord of c vector
# which is all just
# <a_i | c >
# i'th coordinate of c in a basis
#
# since "sum over j of |b_j> <b_j| " is an identity operator,
# projecting onto an orthonomal basis.
#
matmul(b_columns, c_in_b_basis)
array([ 5., 1., 7., -3.])
... and we see that we get <a[i]|c> = <i|c> = c[i] = the coordinates of c in the a basis.