Skip to content

Commit 54ffbd2

Browse files
committed
rewrite stdgates.quil in more natural representations
1 parent 07e47ea commit 54ffbd2

File tree

1 file changed

+47
-78
lines changed

1 file changed

+47
-78
lines changed

src/quil/stdgates.quil

+47-78
Original file line numberDiff line numberDiff line change
@@ -28,107 +28,77 @@ DEFGATE H:
2828

2929
## Cartesian Rotation Gates
3030

31-
DEFGATE RX(%theta):
32-
cos(%theta/2), -i*sin(%theta/2)
33-
-i*sin(%theta/2), cos(%theta/2)
31+
DEFGATE RX(%theta) p AS PAULI-SUM:
32+
X(-%theta/2) p
3433

35-
DEFGATE RY(%theta):
36-
cos(%theta/2), -sin(%theta/2)
37-
sin(%theta/2), cos(%theta/2)
34+
DEFGATE RY(%theta) p AS PAULI-SUM:
35+
Y(-%theta/2) p
3836

39-
DEFGATE RZ(%theta):
40-
cis(-%theta/2), 0
41-
0, cis(%theta/2)
37+
DEFGATE RZ(%theta) p AS PAULI-SUM:
38+
Z(-%theta/2) p
4239

4340

4441
## Controlled-NOT Variants
4542

46-
DEFGATE CNOT:
47-
1, 0, 0, 0
48-
0, 1, 0, 0
49-
0, 0, 0, 1
50-
0, 0, 1, 0
43+
DEFGATE CNOT p q AS SEQUENCE:
44+
CONTROLLED X p q
5145

5246
# Also known as the Toffoli gate.
53-
DEFGATE CCNOT:
54-
1, 0, 0, 0, 0, 0, 0, 0
55-
0, 1, 0, 0, 0, 0, 0, 0
56-
0, 0, 1, 0, 0, 0, 0, 0
57-
0, 0, 0, 1, 0, 0, 0, 0
58-
0, 0, 0, 0, 1, 0, 0, 0
59-
0, 0, 0, 0, 0, 1, 0, 0
60-
0, 0, 0, 0, 0, 0, 0, 1
61-
0, 0, 0, 0, 0, 0, 1, 0
62-
47+
DEFGATE CCNOT p q r AS SEQUENCE:
48+
CONTROLLED CONTROLLED X p q r
6349

6450
## Phase Gates
6551

52+
## Equivalent to RZ(pi/2) up to global phase
6653
DEFGATE S:
6754
1, 0
6855
0, i
6956

57+
## Equivalent to RZ(pi/4) up to global phase
7058
DEFGATE T:
7159
1, 0
7260
0, cis(pi/4)
7361

62+
## Equivalent to RZ(%alpha) up to global phase
7463
DEFGATE PHASE(%alpha):
7564
1, 0
7665
0, cis(%alpha)
7766

78-
DEFGATE CPHASE00(%alpha):
79-
cis(%alpha), 0, 0, 0
80-
0, 1, 0, 0
81-
0, 0, 1, 0
82-
0, 0, 0, 1
83-
84-
DEFGATE CPHASE01(%alpha):
85-
1, 0, 0, 0
86-
0, cis(%alpha), 0, 0
87-
0, 0, 1, 0
88-
0, 0, 0, 1
89-
90-
DEFGATE CPHASE10(%alpha):
91-
1, 0, 0, 0
92-
0, 1, 0, 0
93-
0, 0, cis(%alpha), 0
94-
0, 0, 0, 1
95-
96-
DEFGATE CPHASE(%alpha):
97-
1, 0, 0, 0
98-
0, 1, 0, 0
99-
0, 0, 1, 0
100-
0, 0, 0, cis(%alpha)
101-
102-
DEFGATE CZ:
103-
1, 0, 0, 0
104-
0, 1, 0, 0
105-
0, 0, 1, 0
106-
0, 0, 0, -1
67+
DEFGATE CPHASE(%alpha) p q as SEQUENCE:
68+
CONTROLLED PHASE(%alpha) p q
69+
70+
DEFGATE CPHASE00(%alpha) p q as SEQUENCE:
71+
X p
72+
X q
73+
CONTROLLED PHASE(%alpha) p q
74+
X p
75+
X q
76+
77+
DEFGATE CPHASE01(%alpha) p q as SEQUENCE:
78+
X p
79+
CONTROLLED PHASE(%alpha) p q
80+
X p
81+
82+
DEFGATE CPHASE10(%alpha) p q as SEQUENCE:
83+
X q
84+
CONTROLLED PHASE(%alpha) p q
85+
X q
86+
87+
DEFGATE CZ p q as SEQUENCE:
88+
CONTROLLED Z p q
10789

10890
## Swap Gates
10991

110-
DEFGATE SWAP:
111-
1, 0, 0, 0
112-
0, 0, 1, 0
113-
0, 1, 0, 0
114-
0, 0, 0, 1
92+
DEFGATE SWAP AS PERMUTATION:
93+
1, 3, 2, 4
11594

11695
# Also known as the Fredkin gate.
117-
DEFGATE CSWAP:
118-
1, 0, 0, 0, 0, 0, 0, 0
119-
0, 1, 0, 0, 0, 0, 0, 0
120-
0, 0, 1, 0, 0, 0, 0, 0
121-
0, 0, 0, 1, 0, 0, 0, 0
122-
0, 0, 0, 0, 1, 0, 0, 0
123-
0, 0, 0, 0, 0, 0, 1, 0
124-
0, 0, 0, 0, 0, 1, 0, 0
125-
0, 0, 0, 0, 0, 0, 0, 1
126-
127-
DEFGATE ISWAP:
128-
1, 0, 0, 0
129-
0, 0, i, 0
130-
0, i, 0, 0
131-
0, 0, 0, 1
96+
DEFGATE CSWAP p q r AS PERMUTATION:
97+
CONTROLLED SWAP p q r
98+
99+
DEFGATE ISWAP p q AS PAULI-SUM:
100+
XX(-pi/4) p q
101+
YY(-pi/4) p q
132102

133103
DEFGATE PSWAP(%theta):
134104
1, 0, 0, 0
@@ -152,11 +122,10 @@ DEFGATE XY(%theta):
152122
0, i*sin(%theta/2), cos(%theta/2), 0
153123
0, 0, 0, 1
154124

155-
DEFGATE CAN(%alpha, %beta, %gamma):
156-
(cis((%alpha+%beta-%gamma)/2)+cis((%alpha-%beta+%gamma)/2))/2, 0, 0, (cis((%alpha-%beta+%gamma)/2)-cis((%alpha+%beta-%gamma)/2))/2
157-
0, (cis((%alpha+%beta+%gamma)/(-2))+cis((%beta+%gamma-%alpha)/2))/2, (cis((%alpha+%beta+%gamma)/(-2))-cis((%beta+%gamma-%alpha)/2))/2, 0
158-
0, (cis((%alpha+%beta+%gamma)/(-2))-cis((%beta+%gamma-%alpha)/2))/2, (cis((%alpha+%beta+%gamma)/(-2))+cis((%beta+%gamma-%alpha)/2))/2, 0
159-
(cis((%alpha-%beta+%gamma)/2)-cis((%alpha+%beta-%gamma)/2))/2, 0, 0, (cis((%alpha+%beta-%gamma)/2)+cis((%alpha-%beta+%gamma)/2))/2
125+
DEFGATE CAN(%alpha, %beta, %gamma) p q AS PAULI-SUM:
126+
XX(-%alpha/2) p q
127+
YY(-%beta/2) p q
128+
ZZ(-%gamma/2) p q
160129

161130
DEFGATE BLOCH(%alpha, %beta, %gamma) q AS PAULI-SUM:
162131
X(%alpha) q

0 commit comments

Comments
 (0)