# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

This resource function is obsolete. Use the paclet Wolfram/QuantumFramework instead.

Function Repository Resource:

Represent a discrete quantum operator

Contributed by:
Jonathan Gorard (with modifications by Ruhi Shah and Taufiq Murtadho)

ResourceFunction["QuantumDiscreteOperator"][<| represents a discrete quantum operator with (tensor products of) basis elements | |

ResourceFunction["QuantumDiscreteOperator"][ represents a discrete quantum operator with matrix representation | |

ResourceFunction["QuantumDiscreteOperator"][" represents a named discrete quantum operator " | |

ResourceFunction["QuantumDiscreteOperator"][{" represents a | |

ResourceFunction["QuantumDiscreteOperator"][ResourceFunction["QuantumDiscreteOperator"][…],QuantumBasis[…]] transforms a specified ResourceFunction["QuantumDiscreteOperator"] into a new QuantumBasis. | |

ResourceFunction["QuantumDiscreteOperator"][ResourceFunction["QuantumDiscreteOperator"][…], transforms a specified ResourceFunction["QuantumDiscreteOperator"] into the new quantum mechanical picture |

The QuantumBasis object is produced by the resource function QuantumBasis. When a QuantumBasis object is not specified, the default is taken to be QuantumBasis["Computational"].

When an order *order* is not specified, the default is taken to be Range[*arity*], where *arity* designates the arity of the ResourceFunction["QuantumDiscreteOperator"].

The permitted values of *pic* in ResourceFunction["QuantumDiscreteOperator"][…,*pic*] are "Schrodinger" (default—may also be written "Schroedinger" or "Schrödinger"), "Heisenberg", "Interaction" and "PhaseSpace".

ResourceFunction["QuantumDiscreteOperator"][<|*b*_{11}→*e*_{11},*b*_{12}→*e*_{12},…|>,*d*,*order*] and ResourceFunction["QuantumDiscreteOperator"][*mat*,*d*,*order*] are used to represent a discrete quantum operator in the computational basis, specified by the Association <|*b*_{11}→*e*_{11},*b*_{12}→*e*_{12},…|> or the matrix *mat*, consisting of qudits of dimensionality *d* (when *d* is not specified, the default is taken to be 2).

The Association <|*b*_{11}→*e*_{11},*b*_{12}→*e*_{12},…|> has keys given by (tensor products of) named basis elements *b*_{ij} and values given by matrix elements *e*_{ij} (i.e. entries in the corresponding matrix representation). The order *order* is always a list of positive integers.

ResourceFunction["QuantumDiscreteOperator"][…]["*prop*"] gives the property "*prop*" of the specified discrete quantum operator. Possible properties include:

"Operator" | association <|b_{11}→e_{11},b_{12}→e_{12},…|> of tensor products of basis names and matrix elements |

"Basis" | which QuantumBasis the operator is defined with respect to |

"Picture" | which quantum mechanical picture the operator is defined with respect to |

"BasisElements" | list of basis elements b_{i} |

"MatrixRepresentation" | matrix representation mat of the operator |

"OrderedMatrixRepresentation" | matrix representation adjusted according to the order of the operator, assuming an input state containing Max[order] qudits (subsystems) |

{"OrderedMatrixRepresentation",n} | matrix representation adjusted according to the order of the operator, assuming an input state containing n qudits (subsystems) |

"Arity" | arity of the operator |

"Dimensions" | dimensionality of each qudit (subsystem) in the input state for the operator |

"Order" | order in which the operator should be applied to qudits (subsystems) in the input state |

"HermitianQ" | whether the operator is Hermitian (self-adjoint) |

"UnitaryQ" | whether the operator is unitary (an automorphism of Hilbert space) |

"Eigenvalues" | eigenvalues of the matrix representation of the operator |

"Eigenvectors" | eigenvectors of the matrix representation of the operator |

"Properties" | list of all property names |

A ResourceFunction["QuantumDiscreteOperator"] (in the Schrodinger picture) can act on a QuantumDiscreteState (also in the Schrodinger picture) using ResourceFunction["QuantumDiscreteOperator"][…][QuantumDiscreteState[…]], returning the resulting QuantumDiscreteState. Likewise for ResourceFunction["QuantumDiscreteOperator"] objects acting on ResourceFunction["QuantumDiscreteOperator"], QuantumMeasurementOperator, QuantumHamiltonianOperator or QuantumCircuitOperator objects in the Heisenberg picture, etc.

When applied to a QuantumCircuitOperator object, ResourceFunction["QuantumDiscreteOperator"] will return another ResourceFunction["QuantumDiscreteOperator"] object (i.e. ResourceFunction["QuantumDiscreteOperator"] always returns the operator representation of the resulting circuit).

ResourceFunction["QuantumDiscreteOperator"] can also be applied to QuantumMeasurement objects in order to evolve the corresponding states.

A QuantumDiscreteState, QuantumMeasurementOperator, QuantumMeasurement, QuantumHamiltonianOperator or QuantumCircuitOperator object can be created with the corresponding resource functions.

ResourceFunction["QuantumDiscreteOperator"]["*name*"] or ResourceFunction["QuantumDiscreteOperator"][{"*name*",*n*}] represents an (*n*-qudit, unless otherwise specified) named discrete quantum operator. Possible named operators include:

{"XRotation",ang} | rotation by an angle ang around the x axis of the Bloch sphere |

{"YRotation",ang} | rotation by an angle ang around the y axis of the Bloch sphere |

{"ZRotation",ang} | rotation by an angle ang around the z axis of the Bloch sphere (equivalent to a PHASE gate) |

"S" | S-gate (equivalent to a π/2 PHASE gate) |

"T" | T-gate (equivalent to a π/4 PHASE gate) |

"CNOT" | CNOT gate for qubits (controlled NOT - equivalent to a CX gate) |

{"CNOT",d} | CNOT gate for d-dimensional qudits |

"CPHASE" | CPHASE gate for qubits (controlled π PHASE gate) |

{"CPHASE",d} | CPHASE gate for d-dimensional qudits |

"CX" | CX gate for qubits (controlled Pauli-X gate - equivalent to a CNOT gate) |

{"CX",d} | CX gate for d-dimensional qudits |

"CY" | CY gate for qubits (controlled Pauli-Y gate) |

"CZ" | CZ gate for qubits (controlled Pauli-Z gate) |

{"CZ",d} | CZ gate for d-dimensional qudits |

{"ControlledU",mat} | controlled-U gate for qubits (apply operator with matrix representation mat with first qubit as a control) |

{"ControlledU",mat,d} | controlled-U gate for d-dimensional qudits |

{"ControlledU",ResourceFunction["QuantumDiscreteOperator"][…]} | controlled-U gate for qubits (apply specified ResourceFunction["QuantumDiscreteOperator"] with first qubit as a control) |

{"ControlledU",ResourceFunction["QuantumDiscreteOperator"][…],d} | controlled-U gate for d-dimensional qudits |

"Fourier" | QFT gate for qubits (quantum Fourier transform) |

{"Fourier",d} | QFT gate for d-dimensional qudits |

"InverseFourier" | IQFT gate for qubits (inverse quantum Fourier transform) |

{"InverseFourier",d} | IQFT gate for d-dimensional qudits |

"SWAP" | SWAP gate for qubits (swap two qubits) |

{"SWAP",d} | SWAP gate for d-dimensional qudits |

"RootSWAP" | square root of the SWAP gate for qubits (half swap two qubits) |

{"RootSWAP",d} | square root of the SWAP gate for d-dimensional qudits |

"SUM" | SUM gate for qubits (half-adder for qubits - equivalent to a CNOT gate) |

{"SUM",d} | SUM gate for d-dimensional qudits |

"PauliX" | Pauli-X gate for qubits (equivalent to a π rotation around the x axis of the Bloch sphere) |

{"PauliX",d} | Pauli-X gate for d-dimensional qudits |

"PauliY" | Pauli-Y gate for qubits (equivalent to a π rotation around the y axis of the Bloch sphere) |

"PauliZ" | Pauli-Z gate for qubits (equivalent to a π rotation around the z axis of the Bloch sphere) |

{"PauliZ",d} | Pauli-Z gate for d-dimensional qudits |

"RootNOT" | square root of the Pauli-X gate for qubits (half NOT operation on one qubit) |

{"RootNOT",d} | square root of the Pauli-X gate for d-dimensional qudits |

"Hadamard" | Hadamard gate for qubits (equivalent to a QFT gate on one qubit) |

"Toffoli" | Toffoli gate on 3 qubits (equivalent to a π/2 Deutsch gate) |

{"Toffoli",n} | Toffoli gate on n qubits |

"CSWAP" | controlled SWAP gate for qubits (Fredkin gate) |

{"XX",ang} | XX gate for x axis rotation angle ang (Ising coupling gate) |

{"YY",ang} | YY gate for y axis rotation angle ang (Ising coupling gate) |

{"ZZ",ang} | ZZ gate for z axis rotation angle ang (Ising coupling gate) |

{"Deutsch",ang} | Deutsch gate for rotation angle ang on 3 qubits |

"RandomUnitary" | random unitary operator for qubits (Gaussian unitary ensemble) |

{"RandomUnitary",d} | random unitary operator for d-dimensional qudits |

Create a discrete quantum operator from a matrix representation in the computational basis (default):

In[1]:= |

Out[1]= |

Return its operator association:

In[2]:= |

Out[2]= |

Apply the operator to the first qubit (default) of a two-qubit discrete quantum state in the computational basis:

In[3]:= |

Out[3]= |

In[4]:= |

Out[4]= |

Apply the operator instead to the second qubit of the state:

In[5]:= |

Out[5]= |

In[6]:= |

Out[6]= |

Create a discrete quantum operator from a matrix representation in a specified basis (Pauli-X) and return its matrix representation:

In[7]:= |

Out[7]= |

Return its operator association:

In[8]:= |

Out[8]= |

Show that the operator is unitary, but not Hermitian:

In[9]:= |

Out[9]= |

In[10]:= |

Out[10]= |

Return the ordered matrix representation (assuming a state of size 2):

In[11]:= |

Out[11]= |

Return the ordered matrix representation (assuming a state size of 3):

In[12]:= |

Out[12]= |

Return the ordered matrix representation (assuming a state of size 2) assuming that the operator is applied instead to the second qubit of the state:

In[13]:= |

Out[13]= |

Create a discrete quantum operator by explicitly specifying an association of matrix elements in a given (tensor product) basis and return its matrix representation:

In[14]:= |

Out[15]= |

Return its basis element association:

In[16]:= |

Out[16]= |

Return its operator association:

In[17]:= |

Out[17]= |

Create a CNOT gate for qubits (default), with the third qubit being the control and the fourth qubit being "active":

In[18]:= |

Out[18]= |

Create a CNOT gate for 3-dimensional qudits, with the second qudit being the control and the first qudit being "active":

In[19]:= |

Out[19]= |

Create an XX Ising coupling gate with rotation angle *π*/3, applied to qubits 5 and 2:

In[20]:= |

Out[20]= |

By default, all discrete quantum operators are created in the Schrodinger picture:

In[21]:= |

Out[21]= |

In[22]:= |

Out[22]= |

Operators in the Schrodinger picture can be applied to QuantumDiscreteState objects:

In[23]:= |

Out[23]= |

In[24]:= |

Out[24]= |

However, they cannot be applied to other operators (i.e. QuantumDiscreteOperator objects, QuantumMeasurementOperator objects, QuantumHamiltonianOperator objects or QuantumCircuitOperator objects). Doing so will return unevaluated:

In[25]:= |

Out[25]= |

In[26]:= |

Out[26]= |

On the other hand, operators created in the Heisenberg picture cannot be applied to QuantumDiscreteState objects (will return unevaluated):

In[27]:= |

Out[27]= |

In[28]:= |

Out[28]= |

However, they can be applied to other operators in the Heisenberg picture (i.e. QuantumDiscreteOperator objects, QuantumMeasurementOperator objects, QuantumHamiltonianOperator objects or QuantumCircuitOperator objects):

In[29]:= |

Out[29]= |

In[30]:= |

Out[30]= |

In[31]:= |

Out[31]= |

In[32]:= |

Out[32]= |

By default, all discrete quantum operators are assumed to apply to tensor products of 2-dimensional subsystems (i.e. qubits):

In[33]:= |

Out[33]= |

In[34]:= |

Out[34]= |

Create a discrete quantum operator with the same matrix representation applying to a single 4-dimensional subsystem (i.e. qudit) instead:

In[35]:= |

Out[35]= |

In[36]:= |

Out[36]= |

Create a discrete quantum operator in the computational basis (default):

In[37]:= |

Out[37]= |

In[38]:= |

Out[38]= |

Transform the operator to the Fourier basis:

In[39]:= |

Out[39]= |

In[40]:= |

Out[40]= |

Transform the operator back to the computational basis:

In[41]:= |

Out[41]= |

In[42]:= |

Out[42]= |

The initial and final operators are the same:

In[43]:= |

Out[43]= |

Represent the RootSWAP gate in the Heisenberg picture:

In[44]:= |

Out[44]= |

In[45]:= |

Out[45]= |

Transform the operator to the interaction picture:

In[46]:= |

Out[46]= |

In[47]:= |

Out[47]= |

Represent a 2-qubit random unitary operator in the computational basis:

In[48]:= |

Out[48]= |

In[49]:= |

Out[49]= |

Represent the same operator in the Pauli-X basis instead:

In[50]:= |

Out[50]= |

In[51]:= |

Out[51]= |

Operators in the Schrodinger picture can be applied to QuantumDiscreteState objects that are also in the Schrodinger picture:

In[52]:= |

Out[52]= |

In[53]:= |

Out[53]= |

In[54]:= |

Out[54]= |

However, they cannot be applied to other operators in the Schrodinger picture (returns unevaluated):

In[55]:= |

Out[55]= |

In[56]:= |

Out[56]= |

Likewise, operators in the "PhaseSpace" picture can be applied to QuantumDiscreteState objects in the "PhaseSpace" picture:

In[57]:= |

Out[57]= |

In[58]:= |

Out[58]= |

In[59]:= |

Out[59]= |

But they cannot be applied to other operators in the phase space picture (returns unevaluated):

In[60]:= |

Out[60]= |

In[61]:= |

Out[61]= |

On the other hand, operators in the Heisenberg picture cannot be applied to QuantumDiscreteState objects in the Heisenberg picture:

In[62]:= |

Out[62]= |

In[63]:= |

Out[63]= |

But they can be applied to other operators in the Heisenberg picture:

In[64]:= |

Out[64]= |

In[65]:= |

Out[65]= |

Finally, operators in the Interaction picture can be applied to both QuantumDiscreteState objects in the Interaction picture:

In[66]:= |

Out[66]= |

In[67]:= |

Out[67]= |

And also to other operators in the Interaction picture:

In[68]:= |

Out[68]= |

In[69]:= |

Out[69]= |

In general, the quantum mechanical pictures of a QuantumDiscreteOperator and the object that it is being applied to must match.

Represent a rotation gate for qubit number 3 with angle *π*/3 around the *x* axis of the Bloch sphere:

In[70]:= |

Out[70]= |

Represent a rotation gate for qubit number 3 with angle *π*/3 around the *y* axis of the Bloch sphere:

In[71]:= |

Out[71]= |

Represent a rotation gate for qubit number 3 with angle *π*/3 around the *z* axis of the Bloch sphere:

In[72]:= |

Out[72]= |

Represent an S-gate (a *π*/2 phase change gate) for qubit number 2:

In[73]:= |

Out[73]= |

Represent a T-gate (a *π*/4 phase change gate) for qubit number 2:

In[74]:= |

Out[74]= |

Represent a CNOT gate (a controlled NOT gate) on qubits for control qubit 2 and "active" qubit 3:

In[75]:= |

Out[75]= |

Represent a CNOT gate (a controlled NOT gate) on 3-dimensional qudits for control qudit 2 and "active" qudit 3:

In[76]:= |

Out[76]= |

Represent a CPHASE gate (a controlled *π* phase change gate) on qubits for control qubit 3 and "active" qubit 4:

In[77]:= |

Out[77]= |

Represent a CPHASE gate (a controlled *π* phase change gate) on 3-dimensional qudits for control qudit 3 and "active" qudit 4:

In[78]:= |

Out[78]= |

Represent a CX gate (a controlled Pauli-X gate—equivalent to a CNOT) on qubits for control qubit 1 and "active" qubit 2:

In[79]:= |

Out[79]= |

Represent a CX gate (a controlled Pauli-X gate - equivalent to a CNOT) on 3-dimensional qudits for control qudit 1 and "active" qudit 2:

In[80]:= |

Out[80]= |

Represent a CY gate (a controlled Pauli-Y gate) for control qubit 1 and "active" qubit 2:

In[81]:= |

Out[81]= |

Represent a CZ gate (a controlled Pauli-Z gate) on qubits for control qubit 1 and "active" qubit 2:

In[82]:= |

Out[82]= |

Represent a CZ gate (a controlled Pauli-Z gate) on 3-dimensional qudits for control qudit 1 and "active" qudit 2:

In[83]:= |

Out[83]= |

Represent a controlled-U gate (with U being a random 2-by-2 unitary matrix) on qubits for control qubit 2 and "active" qubit 3 and 2:

In[84]:= |

Out[84]= |

In[85]:= |

Out[85]= |

Represent a controlled-U gate (with U being a random 3-by-3 unitary matrix) on 3-dimensional qudits for control qudit 2 and "active" qudit 3:

In[86]:= |

Out[86]= |

In[87]:= |

Out[87]= |

Construct a controlled-U gate on qubits (with the same 2-by-2 matrix as before), for controlled qubit 2 and "active" qubit 3, directly using the operator form of the matrix:

In[88]:= |

Out[88]= |

In[89]:= |

Out[89]= |

In[90]:= |

Out[90]= |

Construct a controlled-U gate on 3-dimensional qudits (with the same 3-by-3 matrix as before), for controlled qudit 2 and "active" qudit 3, directly using the operator form of the matrix:

In[91]:= |

Out[91]= |

In[92]:= |

Out[92]= |

In[93]:= |

Out[93]= |

Represent a single-qubit QFT gate (quantum Fourier transform) for qubit number 3:

In[94]:= |

Out[94]= |

Represent a two-qubit QFT gate (quantum Fourier transform) for qubits 3 and 4:

In[95]:= |

Out[95]= |

Represent a single-qudit QFT gate (quantum Fourier transform) on 3-dimensional qudits for qudit number 3:

In[96]:= |

Out[96]= |

Represent a two-qudit QFT gate (quantum Fourier transform) on 3-dimensional qudits for qudits 3 and 4:

In[97]:= |

Out[97]= |

Represent a single-qubit IQFT gate (inverse quantum Fourier transform) for qubit number 3:

In[98]:= |

Out[98]= |

Represent a two-qubit IQFT gate (inverse quantum Fourier transform) for qubits 3 and 4:

In[99]:= |

Out[99]= |

Represent a single-qudit IQFT gate (inverse quantum Fourier transform) on 3-dimensional qudits for qudit number 3:

In[100]:= |

Out[100]= |

Represent a two-qudit IQFT gate (inverse quantum Fourier transform) on 3-dimensional qudits for qudits 3 and 4:

In[101]:= |

Out[101]= |

Represent a SWAP gate on qubits (swaps two qubits) for qubits 1 and 2:

In[102]:= |

Out[102]= |

Represent a SWAP gate on 3-dimensional qudits (swaps two qudits) for qudits 1 and 2:

In[103]:= |

Out[103]= |

Represent the square root of a SWAP gate on qubits (half swaps two qubits) for qubits 1 and 2:

In[104]:= |

Out[104]= |

Represent the square root of a SWAP gate on 3-dimensional qudits (half swaps two qudits) for qudits 1 and 2:

In[105]:= |

Out[105]= |

Represent a SUM gate on qubits (a half-adder for qubits—similar to a CNOT gate) for qubits 2 and 3:

In[106]:= |

Out[106]= |

Represent a SUM gate on 3-dimensional qudits (a half-adder for qudits—similar to a CNOT gate) for qudits 2 and 3:

In[107]:= |

Out[107]= |

Represent a Pauli-X gate (a *π* rotation around the *x* axis of the Bloch sphere) on qubits for qubit number 3:

In[108]:= |

Out[108]= |

Represent a Pauli-X gate on 3-dimensional qudits for qudit number 3:

In[109]:= |

Out[109]= |

Represent a Pauli-Y gate (a *π* rotation around the *y* axis of the Bloch sphere) on qubits for qubit number 3:

In[110]:= |

Out[110]= |

Represent a Pauli-Z gate (a *π* rotation around the *z* axis of the Bloch sphere) on qubits for qubit number 3:

In[111]:= |

Out[111]= |

Represent a Pauli-Z gate on 3-dimensional qudits for qudit number 3:

In[112]:= |

Out[112]= |

Represent the square root of a NOT gate on qubits (half a Pauli-X rotation) for qubit number 3:

In[113]:= |

Out[113]= |

Represent the square root of a NOT gate on 3-dimensional qudits (half a Pauli-X rotation) for qudit number 3:

In[114]:= |

Out[114]= |

Represent a Hadamard gate (a single-qubit quantum Fourier transform) for qubit number 1:

In[115]:= |

Out[115]= |

Represent a Toffoli gate (a *π*/2 Deutsch gate) on 3 qubits for qubits 2, 3 and 4:

In[116]:= |

Out[116]= |

Represent a Toffoli gate on 4 qubits for qubits 2, 3, 4 and 5:

In[117]:= |

Out[117]= |

Represent a CSWAP (controlled SWAP gate, otherwise known as a Fredkin gate) for qubits 3, 4 and 5:

In[118]:= |

Out[118]= |

Represent an XX gate for qubit 4 (an *x* axis Ising coupling gate) with angle *π*/3:

In[119]:= |

Out[119]= |

Represent a YY gate for qubit 4 (a *y* axis Ising coupling gate) with angle *π*/3:

In[120]:= |

Out[120]= |

Represent a ZZ gate for qubit 4 (a *z* axis Ising coupling gate) with angle *π*/3:

In[121]:= |

Out[121]= |

Represent a Deutsch gate for qubits 1, 2 and 3 with phase *π*/3:

In[122]:= |

Out[122]= |

Represent a single-qubit random unitary operator (selected from a Gaussian unitary ensemble) for qubit 2:

In[123]:= |

Out[123]= |

Represent a two-qubit random unitary operator (selected from a Gaussian unitary ensemble) for qubits 2 and 3:

In[124]:= |

Out[124]= |

Represent a single-qudit random unitary operator (selected from a Gaussian unitary ensemble) on 3-dimensional qudits for qudit 2:

In[125]:= |

Out[125]= |

Represent a two-qudit random unitary operator (selected from a Gaussian unitary ensemble) on 3-dimensional qudits for qudits 2 and 3:

In[126]:= |

Out[126]= |

QuantumDiscreteOperator objects can be constructed purely symbolically (without explicit matrix elements):

In[127]:= |

Out[127]= |

View the operator association:

In[128]:= |

Out[128]= |

Standard operations can still be performed on purely symbolic operators/states:

In[129]:= |

Out[129]= |

In[130]:= |

Out[130]= |

In[131]:= |

Out[131]= |

In[132]:= |

Out[132]= |

View a list of properties that can be extracted from a QuantumDiscreteOperator object:

In[133]:= |

Out[133]= |

In[134]:= |

Out[134]= |

Return the operator association:

In[135]:= |

Out[135]= |

Return which QuantumBasis the operator is defined with respect to:

In[136]:= |

Out[136]= |

Return which quantum mechanical picture the operator is defined with respect to:

In[137]:= |

Out[137]= |

Return the association of names and basis elements:

In[138]:= |

Out[138]= |

Return the matrix representation:

In[139]:= |

Out[139]= |

Return the ordered matrix representation (when applied to qubits 2 and 3) assuming a state consisting of 3 qubits:

In[140]:= |

Out[140]= |

Return the ordered matrix representation (when applied to qubits 2 and 3) assuming a state consisting of 4 qubits:

In[141]:= |

Out[141]= |

Return the arity (number of input subsystems):

In[142]:= |

Out[142]= |

Return the number of dimensions:

In[143]:= |

Out[143]= |

Return the order in which the operator is applied to subsystems:

In[144]:= |

Out[144]= |

Determine whether the operator is Hermitian:

In[145]:= |

Out[145]= |

Determine whether the operator is unitary:

In[146]:= |

Out[146]= |

Return the list of eigenvalues:

In[147]:= |

Out[147]= |

Return the list of eigenvectors:

In[148]:= |

Out[148]= |

- 1.1.0 – 02 June 2021

This work is licensed under a Creative Commons Attribution 4.0 International License