-
Notifications
You must be signed in to change notification settings - Fork 0
/
BitwiseOperations.jl
139 lines (99 loc) · 2.74 KB
/
BitwiseOperations.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using LinearAlgebra
"""
This file consists of all the bitwise operation functions.
Inputs:
conf -> statevector as integer
i/j -> site indices
N -> system size
"""
function readsite(conf::Int64,i::Int64,N::Int64)
"""
reads the state of i^th site in the state
"""
return (conf&(1<<(N-i)))>>(N-i)
end
function spins_flip(conf::Int64,i::Int64,j::Int64,N::Int64,typeof::String)
"""
flips the two sites i and j in a given conf
applies S+ S- + S- S+
"""
if readsite(conf,i,N) != readsite(conf,j,N)
if typeof == "Pauli"
return 2.0, conf ⊻ ((1<<(N-i) ⊻ (1<<(N-j))))
else
return 1.0/2.0, conf ⊻ ((1<<(N-i) ⊻ (1<<(N-j))))
end
else
return 0.0, conf
end
end
function Z(conf::Int64,i::Int64,N::Int64,typeof::String)
"""
applies sZ to i^th site of conf
"""
if typeof == "Pauli"
return 2.0*readsite(conf,i,N)-1.0, conf
else
return readsite(conf,i,N)-1.0/2.0, conf
end
end
function ZZ(conf::Int64,i::Int64,j::Int64,N::Int64,typeof::String)
"""
applies sZsZ to i^th and j^th sites of conf
"""
si = 2.0*readsite(conf,i,N)-1.0
sj = 2.0*readsite(conf,j,N)-1.0
if typeof == "Pauli"
return si*sj, conf
else
return si*sj/4.0, conf
end
end
function X(conf::Int64,i::Int64,N::Int64,typeof::String)
"""
applies sX to i^th site of conf
"""
if typeof == "Pauli"
return 1.0, conf ⊻ (1<<(N-i))
else
return 1.0/2.0,conf ⊻ (1<<(N-i))
end
end
function XX(conf::Int64,i::Int64,j::Int64,N::Int64,typeof::String)
"""
applies sXsX to i^th and j^th sites of conf
"""
if typeof == "Pauli"
return 1.0, X(X(conf,i,N,typeof)[2],j,N,typeof)[2]
else
return 1.0/4.0, X(X(conf,i,N,typeof)[2],j,N,typeof)[2]
end
end
function Y(conf::Int64,i::Int64,N::Int64,typeof::String)
"""
applies sY to i^th site of conf
"""
if typeof == "Pauli"
return (2.0*readsite(conf,i,N)-1.0)*im, conf ⊻ (1<<(N-i))
else
return (readsite(conf,i,N)-1.0/2.0)*im, conf ⊻ (1<<(N-i))
end
end
function YY(conf::Int64,i::Int64,j::Int64,N::Int64,typeof::String)
"""
applies sYsY to i^th and j^th sites of conf
"""
si = (2.0*readsite(conf,i,N)-1.0)*im
sj = (2.0*readsite(conf,j,N)-1.0)*im
if typeof == "Pauli"
return si*sj, Y(Y(conf,i,N,typeof)[2],j,N,typeof)[2]
else
return si*sj/4.0, Y(Y(conf,i,N,typeof)[2],j,N,typeof)[2]
end
end
function shift_bits(conf::Int64,N::Int64)
"""
translates bits one step to right
"""
return (conf>>1)|(readsite(conf,N,N)<<(N-1))
end