WState
WState | |
Generates a (generalized) W-state | |
Other toolboxes required | none |
---|---|
Related functions | DickeState GHZState MaxEntangled |
Function category | Special states, vectors, and operators |
WState is a function that returns a W-state on a given number of qubits. For example, the usual $3$-qubit W-state is $\frac{1}{\sqrt{3}}(|100\rangle + |010\rangle + |001\rangle)$. More generally, the W-state on $q$ qudits is $\frac{1}{\sqrt{q}}(|10\cdots 00\rangle + |01\cdots 00\rangle + \cdots + |00\cdots 01\rangle)$. The output of this function is a sparse vector.
Syntax
- W_STATE = WState(Q)
- W_STATE = WState(Q,COEFF)
Argument descriptions
- Q: The number of qubits.
- COEFF (optional, default [1,1,...,1]/sqrt(Q)): A vector whose $j$-th entry is the coefficient of the term $|0\rangle^{\otimes (j-1)} \otimes |1\rangle \otimes |0\rangle^{\otimes q-j}$ in the sum that defines the W-state.
Examples
3-qubit W-state
The following code generates the usual 3-qubit GHZ state:
>> full(WState(3))
ans =
0
0.5774
0.5774
0
0.5774
0
0
0
A generalized W-state
The following code generates the following generalized 4-qubit W-state: \[\frac{1}{\sqrt{30}}\big( |1000\rangle + 2|0100\rangle + 3|0010\rangle + 4|0001\rangle \big).\]
>> WState(4,[1,2,3,4]/sqrt(30))
ans =
(2,1) 0.7303
(3,1) 0.5477
(5,1) 0.3651
(9,1) 0.1826
A very large W-state
This script has no trouble creating W-states on very large numbers of qubits. The following code generates the 30-qubit W-state:
>> WState(30)
ans =
(2,1) 0.1826
(3,1) 0.1826
(5,1) 0.1826
(9,1) 0.1826
(17,1) 0.1826
(33,1) 0.1826
(65,1) 0.1826
(129,1) 0.1826
(257,1) 0.1826
(513,1) 0.1826
(1025,1) 0.1826
(2049,1) 0.1826
(4097,1) 0.1826
(8193,1) 0.1826
(16385,1) 0.1826
(32769,1) 0.1826
(65537,1) 0.1826
(131073,1) 0.1826
(262145,1) 0.1826
(524289,1) 0.1826
(1048577,1) 0.1826
(2097153,1) 0.1826
(4194305,1) 0.1826
(8388609,1) 0.1826
(16777217,1) 0.1826
(33554433,1) 0.1826
(67108865,1) 0.1826
(134217729,1) 0.1826
(268435457,1) 0.1826
(536870913,1) 0.1826
Source code
Click here to view this function's source code on github.