Package quantum_computing
=========================

The quantum_computing package provides several functions to simulate quantum computing circuits. The state of a system of N qubits is represented by a list of 2^N complex numbers and an operator acting on M qubits is represented by a 2^M by 2^M matrix. A hash array 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 copylist

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

Categories: Share packages Package quantum_computing

Functions and Variables for Quantum_Computing
=============================================

 -- Function: binlist
     binlist (K)
     binlist (K, N)

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

     Categories: Package quantum_computing

 -- Function: binlist2dec (LST)

     Given a list LST with N binary digits, it returns the decimal number it represents.

     Categories: Package quantum_computing

 -- Function: CNOT (Q, I, J)

     Changes the value of the J'th qubit, in a state Q of M qubits, when the value of the I'th qubit equals 1. It modifies the list Q and returns its modified value.

     Categories: Package quantum_computing

 -- Function: controlled (U, Q, C, I)

     Applies a matrix U, acting on M qubits, on qubits I through I+M-1 of the state Q of N qubits (N > M), when the value of the C'th qubit in Q equals 1. I should be an integer between 1 and N+1-M and C should be an integer between 1 and N, excluding the qubits to be modified (I through I+M-1).

     U can be one of the indices of the array of common matrices QMATRIX (see qmatrix). The state Q is modified and shown in the output.

     Categories: Package quantum_computing

 -- Function: gate
     gate (U, Q)
     gate (U, Q, I)
     gate (U, Q, I1, ..., IM)

     U must be a matrix acting on states of M qubits; Q a list corresponding to a state of N qubits (N >= M); I and the M numbers I1, ..., IM must be different integers between 1 and N.

     gate(U, Q) applies matrix U to each qubit of Q, when M equals 1, or to the first M qubits of Q when M is bigger than 1.

     gate(U, Q, I) applies matrix U to the qubits I through I+M-1 of Q.

     gate(U, Q, I1, ..., IN) applies matrix U to the in the positions I1, ..., IM.

     U can be one of the indices of the array of common matrices QMATRIX (see qmatrix). The state Q is modified and shown in the output.

     Categories: Package quantum_computing

 -- Function: gate_matrix
     gate_matrix (U, N)
     gate_matrix (U, N, I1, ..., IM)

     U must be a 2 by 2 matrix or one of the indices of the array of common matrices QMATRIX (see qmatrix). gate_matrix(U, N) returns the matrix corresponding to the action of U on each qubit in a state of N qubits.

     gate_matrix (U, N, I1, ..., IM) returns the matrix corresponding to the action of U on qubits I1, ..., IM of a state of N qubits, where I1, ..., IM are different integers between 1 and N.

     Categories: Package quantum_computing

 -- Function: linsert (E, LST, P)

     Inserts the expression or list E into the list LST at position P. The list can be empty and P must be an integer between 1 and the length of LST plus 1.

     Categories: Package quantum_computing

 -- Function: lreplace (E, LST, P)

     If E is a list of length N, the elements in the positions P, P+1, ..., P+N-1 of the list LST are replaced by E, or the first elements of E if the end of LST is reached.  If E is an expression, the element in position P of list LST is replaced by that expression. P must be an integer between 1 and the length of LST.

     Categories: Package quantum_computing

 -- Function: normalize (Q)

     Returns the normalized version of a quantum state given as a list Q.

     Categories: Package quantum_computing

 -- Function: qdisplay (Q)

     Represents the state Q of a system of N qubits as a linear combination of the computational states with N binary digits.  It returns an expression including strings and symbols.

     Categories: Package quantum_computing

 -- 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. QMATRIX[I] is the identity matrix, QMATRIX[X] the Pauli x matrix, QMATRIX[Y] the Pauli y matrix, QMATRIX[Z] the Pauli z matrix, QMATRIX[H] the Hadamard matrix and QMATRIX[S] the phase matrix.

     Categories: Package quantum_computing

 -- Function: qmeasure
     qmeasure (Q)
     qmeasure (Q, I1, ..., IM)

     Measures the value of one or more qubits in a system of N qubits with state Q. The M positive integers I1, ..., 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 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 Q. It modifies the list Q, reflecting the collapse of the quantum state after the measurement.

     Categories: Package quantum_computing

 -- Function: qubits
     qubits (N)
     qubits (I1, ..., IN)

     qubits(N) returns a list representing the ground state of a system of N qubits.

     qubits(I1, ..., IN) returns a list with representing the state of N qubits with values I1, ..., IN.

     Categories: Package quantum_computing

 -- Function: qswap (Q, I, J)

     Interchanges the states of qubits I and J in the state Q of a system of several qubits.  It modifies the list Q and returns its modified value.

     Categories: Package quantum_computing

 -- Function: Rx (A)

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

     Categories: Package quantum_computing

 -- Function: Ry (A)

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

     Categories: Package quantum_computing

 -- Function: Rz (A)

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

     Categories: Package quantum_computing

 -- Function: tprod (O1, ..., ON)

     Returns the tensor product of the N matrices or lists O1, ..., ON.

     Categories: Package quantum_computing

 -- Function: toffoli (Q, (I, (J, (K)

     Changes the value of the K'th qubit, in the state Q of N qubits, if the values of the I'th anf J'th qubits are equal to 1. It modifies the list Q and returns its new value.

     Categories: Package quantum_computing