-
Notifications
You must be signed in to change notification settings - Fork 6
/
spatialEntropy_SVD.jl
66 lines (49 loc) · 1.42 KB
/
spatialEntropy_SVD.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# This function calculates the spatial entanglement entropy
# of a region A, using the SVD
#
function SpatialEE_SVD(N,M,Asize,d)
#N, M, size of region A, vector of eigenvalues from Lanczos
Bsize = M - Asize
#All you need is the sizes of the reduced hilbert spaces
DimA = 1 #start at 1, for the [0,0,0,....,0] element
DimB = 1
for i=0:N-1
DimA += binomial(N-i+Asize-1,Asize -1)
DimB += binomial(N-i+Bsize-1,Bsize -1)
end
#dimension of the total Hilbert space
D = div(length(basis),M)
#println("D ",D)
#dimension of the subspace A
#println("DimA ",DimA)
#println("DimB ",DimB)
Amatrix = zeros(DimA,DimB) #This is the matrix that we will SVD
#form the Amatrix
for i=1:D
bra = sub(basis,(i-1)*M+1:(i-1)*M+M) #unpack the bra/ket from the total basis vector
braA = sub(bra,1:Asize)
braB = sub(bra,Asize+1:M)
row = subSerialNum(sum(braA),Asize,N,braA)
col = subSerialNum(sum(braB),Bsize,N,braB)
Amatrix[row,col] = d[2][i] #Assign the matrix the appropriate element from PSI
end
#println(Amatrix)
(U, S, V) = svd(Amatrix) #singular value decomposition
#println(S,size(S))
#sum squares of singular values
#Ssize = min(DimA,DimB)
#println("Ssize ",Ssize," ",size(S,1))
sum2=0.0
sum4=0.0
for i=1:size(S,1)
sum2 += S[i]^2
sum4 += S[i]^4
end
#println(sum2)
if (sum2 - 1.0) > 1e-12 #some bounds on the eigenvalue sum
println("RDM eigenvalue error ",sum2)
end
#println(-log(sum4))
#return the second Renyi entropy
return -log(sum4)
end