File: quantum_computing.texi

package info (click to toggle)
maxima 5.47.0-9
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 193,104 kB
  • sloc: lisp: 434,678; fortran: 14,665; tcl: 10,990; sh: 4,577; makefile: 2,763; ansic: 447; java: 328; python: 262; perl: 201; xml: 60; awk: 28; sed: 15; javascript: 2
file content (332 lines) | stat: -rw-r--r-- 10,287 bytes parent folder | download | duplicates (3)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
@menu
* Package quantum_computing::
* Functions and Variables for Quantum_Computing::       
@end menu

@node Package quantum_computing, Functions and Variables for Quantum_Computing, quantum_computing-pkg, quantum_computing-pkg
@section Package quantum_computing

The @code{quantum_computing} package provides several functions to
simulate quantum computing circuits. The state of a system of @var{n}
qubits is represented by a list of 2^@var{n} complex numbers and an
operator acting on @var{m} qubits is represented by a 2^@var{m} by
2^@var{m} matrix. A hash array @var{qmatrix} is defined with 6 common
one-qubit matrices: the identity, the Pauli matrices, the Hadamard
matrix and the phase matrix.

The major disadvantage compared to a real quantum computer is very slow
computing times even with a few qubits. An advantage is that, unlike a
quantum computer, in this simulator a quantum state can be cloned using
@mrefdot{copylist}

This is an additional package that must be loaded with
@code{load("quantum_computing")} in order to use it.

@opencatbox{Categories:}
@category{Share packages}
@category{Package quantum_computing}
@closecatbox

@node Functions and Variables for Quantum_Computing,  , Package quantum_computing, quantum_computing-pkg
@section Functions and Variables for Quantum_Computing

@anchor{binlist}
@deffn {Function} binlist @
@fname{binlist} (@var{k}) @
@fname{binlist} (@var{k}, @var{n})

@code{binlist}(@var{k}), where @var{k} must be a natural number,
returns a list of binary digits 0 or 1 corresponding to the digits of
@var{k} in binary representation. @code{binlist}(@var{k}, @var{n}) does
the same but returns a list of length @var{n}, with leading zeros as
necessary. Notice that for the result to represent a possible state of
@var{m} qubits, @var{n} should be equal to 2^@var{m} and @var{k} should
be between 0 and 2^@var{m}-1.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{binlist2dec}
@deffn {Function} binlist2dec (@var{lst})

Given a list @var{lst} with @var{n} binary digits, it returns the decimal
number it represents.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{CNOT}
@deffn {Function} CNOT (@var{q}, @var{i}, @var{j})

Changes the value of the @var{j}'th qubit, in a state @var{q} of @var{m}
qubits, when the value of the @var{i}'th qubit equals 1. It modifies the
list @var{q} and returns its modified value.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{controlled}
@deffn {Function} controlled (@var{U}, @var{q}, @var{c}, @var{i})

Applies a matrix @var{U}, acting on @var{m} qubits, on qubits @var{i}
through @var{i}+@var{m}-1 of the state @var{q} of @var{n} qubits
(@var{n} > @var{m}), when the value of the @var{c}'th qubit in @var{q}
equals 1. @var{i} should be an integer between 1 and @var{n}+1-@var{m}
and @var{c} should be an integer between 1 and @var{n}, excluding the
qubits to be modified (@var{i} through @var{i}+@var{m}-1).

@var{U} can be one of the indices of the array of common matrices
@var{qmatrix} (see @mref{qmatrix}). The state @var{q} is modified and
shown in the output.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{gate}
@deffn {Function} gate @
@fname{gate} (@var{U}, @var{q}) @
@fname{gate} (@var{U}, @var{q}, @var{i}) @
@fname{gate} (@var{U}, @var{q}, @var{i1}, @dots{}, @var{im})

@var{U} must be a matrix acting on states of @var{m} qubits; @var{q} a
list corresponding to a state of @var{n} qubits (@var{n} >= @var{m});
@var{i} and the @var{m} numbers @var{i1}, @dots{}, @var{im} must be
different integers between 1 and @var{n}.

@code{gate}(@var{U}, @var{q}) applies matrix @var{U} to each qubit of
@var{q}, when @var{m} equals 1, or to the first @var{m} qubits of
@var{q} when @var{m} is bigger than 1.

@code{gate}(@var{U}, @var{q}, @var{i}) applies matrix @var{U} to the
qubits @var{i} through @var{i}+@var{m}-1 of @var{q}.

@code{gate}(@var{U}, @var{q}, @var{i1}, @dots{}, @var{in}) applies
matrix @var{U} to the in the positions @var{i1}, @dots{}, @var{im}.

@var{U} can be one of the indices of the array of common matrices
@var{qmatrix} (see @mref{qmatrix}). The state @var{q} is modified and
shown in the output.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{gate_matrix}
@deffn {Function} gate_matrix @
@fname{gate_matrix} (@var{U}, @var{n}) @
@fname{gate_matrix} (@var{U}, @var{n}, @var{i1}, @dots{}, @var{im})

@var{U} must be a 2 by 2 matrix or one of the indices of the array of
common matrices @var{qmatrix} (see @mref{qmatrix}).
@code{gate_matrix}(@var{U}, @var{n}) returns the matrix corresponding to
the action of @var{U} on each qubit in a state of @var{n} qubits.

@code{gate_matrix} (@var{U}, @var{n}, @var{i1}, @dots{}, @var{im})
returns the matrix corresponding to the action of @var{U} on qubits
@var{i1}, @dots{}, @var{im} of a state of @var{n} qubits, where
@var{i1}, @dots{}, @var{im} are different integers between 1 and
@var{n}.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{linsert}
@deffn {Function} linsert (@var{e}, @var{lst}, @var{p})

Inserts the expression or list @var{e} into the list @var{lst} at position
@var{p}. The list can be empty and @var{p} must be an integer between 1 and
the length of @var{lst} plus 1.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{lreplace}
@deffn {Function} lreplace (@var{e}, @var{lst}, @var{p})

If @var{e} is a list of length @var{n}, the elements in the positions
@var{p}, @var{p}+1, @dots{}, @var{p}+@var{n}-1 of the list @var{lst} are
replaced by @var{e}, or the first elements of @var{e} if the end of
@var{lst} is reached.  If @var{e} is an expression, the element in
position @var{p} of list @var{lst} is replaced by that expression.
@var{p} must be an integer between 1 and the length of @var{lst}.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{normalize}
@deffn {Function} normalize (@var{q})

Returns the normalized version of a quantum state given as a list @var{q}.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{qdisplay}
@deffn {Function} qdisplay (@var{q})

Represents the state @var{q} of a system of @var{n} qubits as a linear
combination of the computational states with @var{n} binary digits.  It
returns an expression including strings and symbols.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{qmatrix}
@defvr {System variable} qmatrix

This variable is a predefined hash array of two by two matrices with the
standard matrices: identity, Pauli matrices, Hadamard matrix and the
phase matrix. The six possible indices are I, X, Y, Z, H,
S. @var{qmatrix}[I] is the identity matrix, @var{qmatrix}[X] the Pauli x
matrix, @var{qmatrix}[Y] the Pauli y matrix, @var{qmatrix}[Z] the Pauli
z matrix, @var{qmatrix}[H] the Hadamard matrix and @var{qmatrix}[S] the
phase matrix.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end defvr

@anchor{qmeasure}
@deffn {Function} qmeasure @
@fname{qmeasure} (@var{q}) @
@fname{qmeasure} (@var{q}, @var{i1}, @dots{}, @var{im})

Measures the value of one or more qubits in a system of @var{n} qubits
with state @var{q}. The @var{m} positive integers @var{i1}, @dots{},
@var{im} are the positions of the qubits to be measured It requires 1 or
more arguments. The first argument must be the state q. If the only
argument given is @var{q}, all the n qubits will be measured.

It returns a list with the values of the qubits measured (either 0 or
1), in the same order they were requested or in ascending order if the
only argument given was @var{q}. It modifies the list @var{q},
reflecting the collapse of the quantum state after the measurement.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{qubits}
@deffn {Function} qubits @
@fname{qubits} (@var{n}) @
@fname{qubits} (@var{i1}, @dots{}, @var{in})

@code{qubits}(@var{n}) returns a list representing the ground state of a
system of @var{n} qubits.

@code{qubits}(@var{i1}, @dots{}, @var{in}) returns a list with
representing the state of @var{n} qubits with values @var{i1}, @dots{},
@var{in}.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{qswap}
@deffn {Function} qswap (@var{q}, @var{i}, @var{j})

Interchanges the states of qubits @var{i} and @var{j} in the state
@var{q} of a system of several qubits.  It modifies the list @var{q} and
returns its modified value.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{Rx}
@deffn {Function} Rx (@var{a})

Returns the 2 by two matrix (acting on one qubit) corresponding to a
rotation of with an angle of @var{a} radians around the x axis.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{Ry}
@deffn {Function} Ry (@var{a})

Returns the 2 by two matrix (acting on one qubit) corresponding to a
rotation of with an angle of @var{a} radians around the y axis.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{Rz}
@deffn {Function} Rz (@var{a})

Returns the 2 by two matrix (acting on one qubit) corresponding to a
rotation of with an angle of @var{a} radians around the z axis.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{tprod}
@deffn {Function} tprod (@var{o1}, @dots{}, @var{on})

Returns the tensor product of the @var{n} matrices or lists @var{o1},
@dots{}, @var{on}.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn

@anchor{toffoli}
@deffn {Function} toffoli (@var{q}, (@var{i}, (@var{j}, (@var{k})

Changes the value of the @var{k}'th qubit, in the state @var{q} of
@var{n} qubits, if the values of the @var{i}'th anf @var{j}'th qubits
are equal to 1. It modifies the list @var{q} and returns its new value.

@opencatbox{Categories:}
@category{Package quantum_computing}
@closecatbox

@end deffn