WState

From QETLAB
Jump to: navigation, search
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 on "expand" to the right to view the MATLAB source code for this function.

  1. %%  WSTATE    Generates a (generalized) W-state
  2. %   This function has one required input argument:
  3. %     Q: the number of qubits
  4. %
  5. %   W_STATE = WState(Q) returns the Q-qubit W-state described in [1].
  6. %
  7. %   The W-state on Q qubits is defined by
  8. %       |W> = 1/sqrt(Q)*(|100...0> + |010...0> + ... + |000...1>).
  9. %
  10. %   This function has one optional input argument:
  11. %     COEFF (default [1,1,...,1]/sqrt(Q)): a 1-by-Q vector of coefficients
  12. %
  13. %   W_STATE = WState(Q,COEFF) returns the same state as above, except the
  14. %   coefficient of the j-th term in the sum that defines the W-state is
  15. %   COEFF(j).
  16. %
  17. %   References:
  18. %   [1] Three qubits can be entangled in two inequivalent ways. W. Dur,
  19. %       G. Vidal, and J. I. Cirac. E-print: arXiv:quant-ph/0005115, 2000.
  20. %
  21. %   URL: http://www.qetlab.com/WState
  22.  
  23. %   requires: opt_args.m
  24. % 	author: Vincent Russo (vrusso@uwaterloo.ca)
  25. %           Nathaniel Johnston (nathaniel@njohnston.ca)
  26. %   package: QETLAB 
  27. %   last updated: December 24, 2014
  28.  
  29. function w_state = WState(q,varargin)
  30.  
  31. % set optional argument defaults: coeff = [1,1,...,1]/sqrt(q)
  32. [coeff] = opt_args({ ones(1,q)/sqrt(q), 1 },varargin{:});
  33.  
  34. % Do some error checking.
  35. if q < 2
  36.     error('WState:InvalidQ','Q must be at least 2.');
  37. elseif length(coeff) ~= q
  38.     error('WState:InvalidCoeff','COEFF must be a vector of length equal to Q.');
  39. end
  40.  
  41. w_state = sparse(2^q,1);
  42. for j = 1:q
  43.     w_state(2^(j-1)+1) = coeff(q-j+1);
  44. end