First Steps in Julia¶

no side effect for vector¶

compare these results to Python!

In [1]:
let

    xv = [1, 2, 3]
    yv = [4, 5, 6]
    
    cc = xv
    cc += yv
    
    [cc, xv, yv]
    
end
Out[1]:
3-element Vector{Vector{Int64}}:
 [5, 7, 9]
 [1, 2, 3]
 [4, 5, 6]

Beware of side effects in matrix!¶

In [2]:
let

    xmat = [1 2; 3 4]
    ymat = [4 5; 6 7]

    cmat = xmat
    cmat[1,2] = 101

    [cmat, xmat, ymat]
    
end
Out[2]:
3-element Vector{Matrix{Int64}}:
 [1 101; 3 4]
 [1 101; 3 4]
 [4 5; 6 7]
In [3]:
let

    function f(x, y, z)
        return exp(-x^2-y^2-z^2)
    end
    
    function main()
    
        N = 500
        xv = range(0.0, 2.0, length=N)
    
        dx = xv[2]-xv[1]
    
        ret = 0.0
    
        for x1 in xv, x2 in xv, x3 in xv
            ret += exp(-x1^2-x2^2-x3^2) * dx^3
        end
    
        return ret
    end
    
    main()
    
end
Out[3]:
0.6910931690128204

SU(2) and Pauli matrices¶

Pauli's matrices¶

satisfy the commutation relation:

$[\sigma(i), \sigma(j)] = 2 i \epsilon_{ijk} \, \sigma(k)$

and anti-commutation relation:

$\{ \sigma(i), \sigma(j) \} = 2 \delta_{ij} \, I$

In [4]:
iden = [1 0; 0 1];
sigmax = [0 1; 1 0];
sigmay = [0 -im; im 0];
sigmaz = [1 0; 0 -1];
In [5]:
commute = (m1, m2) -> m1*m2 - m2*m1
anti_commute = (m1, m2) -> m1*m2 + m2*m1

ret = [commute(sigmax, sigmay) - 2*im*sigmaz,
anti_commute(sigmax, sigmax) - 2*iden];

ret
Out[5]:
2-element Vector{Matrix{Complex{Int64}}}:
 [0 + 0im 0 + 0im; 0 + 0im 0 + 0im]
 [0 + 0im 0 + 0im; 0 + 0im 0 + 0im]

representation of a general 2x2 (complex) matrix¶

$M = M_0 \, I + i \vec{M} \cdot \vec{\sigma}$

M0 = tr(M * sigma(0)) / 2

Mi = tr(M * sigma(i)) / (2 im)

representation of SU(2)¶

generators: $\{ \frac{\vec{\sigma}}{2} \}$

$D(\phi, \hat{n}) = e^{-i \frac{\phi}{2} \, \vec{\sigma} \cdot \hat{n}} = I \, \cos(\frac{\phi}{2}) - i \, \sin(\frac{\phi}{2}) \vec{\sigma} \cdot \hat{n}$

see, e.g. Modern Quantum Mechanics by Sakurai pp. 166 (revised edition)

3 generators for SU(2): 3 DoFs.¶

If we write: $D = a_0 \, I - i \vec{a} \cdot \vec{\sigma}$

there is a relation among [a0, $\vec{a}$], namely

$a_0^2 = 1 - \vec{a}^2$.

(they are all real)

This gives another way to sample SU(2) matrices:

e.g. to generate ensembles of SU(2) matrix, e.g. for LQCD study, we need to sample [a0, a1, a2, a3] randomly but subjected to this constraint.

Rotation formula¶

$D \vec{\sigma} D^{-1} = \cos \phi \, \vec{\sigma} + (1-\cos \phi) \, \hat{n} \, \hat{n} \cdot \vec{\sigma} - \sin \phi \, \hat{n} \times \vec{\sigma}$

In [6]:
let
	
	sigv = [sigmax, sigmay, sigmaz]

    # normalized 3-vector
    nhat = rand(3)
	nhat /= sqrt(sum(@. nhat^2))
	
	phi = (-1 + 2*rand())/rand()
	
	# alternative
	# u0 = (-1 + 2*rand())
	# phi = 2*acos(u0)

    A1 = exp(-im * phi/2 * sum(nhat .* [sigmax, sigmay, sigmaz]))

    A2 = iden * cos(phi/2) - im * sin(phi/2) * sum(nhat .* sigv)

    [A1, A2]

end
Out[6]:
2-element Vector{Matrix{ComplexF64}}:
 [0.9480152631306031 + 0.2291292686020539im 0.21234289991734592 + 0.06064100919339364im; -0.21234289991734592 + 0.06064100919339364im 0.9480152631306032 - 0.22912926860205393im]
 [0.948015263130603 + 0.22912926860205396im 0.21234289991734592 + 0.06064100919339364im; -0.21234289991734592 + 0.06064100919339364im 0.948015263130603 - 0.22912926860205396im]
In [7]:
let
    # checking the rotation formula:
    
    phi = pi/3
    # nhat = xhat
    D = exp(-im * phi/2 * sigmax)
    lhs = D * sigmaz * inv(D);

    # take along the z-direction: no 2nd term as it is along x
    rhs = cos(phi) * sigmaz + 0(1-cos(phi)) * sigmax - sin(phi) * sigmay;

    [lhs, rhs]
end
Out[7]:
2-element Vector{Matrix{ComplexF64}}:
 [0.5000000000000003 + 0.0im 0.0 + 0.8660254037844384im; 0.0 - 0.8660254037844387im -0.5000000000000002 + 0.0im]
 [0.5000000000000001 - 0.0im 0.0 + 0.8660254037844386im; 0.0 - 0.8660254037844386im -0.5000000000000001 - 0.0im]

Important matrix relations in Lie Algebras¶

$\begin{align} e^A &= \sum_{n=0}^\infty \, \frac{1}{n!} \, A^n \\ &= \lim_{N \rightarrow \infty} \, \left( \mathcal{I} + \frac{1}{N} \, A\right)^N \end{align}$

$\begin{align} \ln (\cal{I} - A) = -\sum_{n=1}^\infty \, \frac{A^n}{n} \end{align}$

From these (expand in $1/N$), we can verify

$\begin{align} \det e^A &= e^{{\rm tr} \, A} \\ \ln \det A &= {\rm tr} \, \ln A \end{align}$

In [8]:
function su2_gen()
    
    # generate a random su2 matrix
    sigv = [sigmax, sigmay, sigmaz]
    
    # normalized 3-vector
    nhat = rand(3)
    nhat /= sqrt(sum(@. nhat^2))
    
    phi = -pi + rand()*(2*pi)

    A1 = exp(-im * phi/2 * sum(nhat .* [sigmax, sigmay, sigmaz]))
    return A1
    
end
Out[8]:
su2_gen (generic function with 1 method)
In [9]:
let

    using LinearAlgebra
    
    mm = su2_gen()
    [log(det(mm)), tr(log(mm)), det(exp([1 2; 3 4])), exp(tr([1 2; 3 4]))]

end
Out[9]:
4-element Vector{ComplexF64}:
 -2.2204460492503136e-16 + 0.0im
   8.153567435230626e-16 + 1.6653345369377348e-16im
       148.4131591025794 + 0.0im
       148.4131591025766 + 0.0im