GHZState

From QETLAB
Jump to: navigation, search
GHZState
Generates a (generalized) GHZ state

Other toolboxes required none
Related functions DickeState
MaxEntangled
WState
Function category Special states, vectors, and operators

GHZState is a function that returns a GHZ state on a given number of qubits (or qudits). For example, the usual $3$-qubit GHZ state is $\frac{1}{\sqrt{2}}(|000\rangle + |111\rangle)$. More generally, the GHZ state on $q$ qudits with local dimension $d$ is $\frac{1}{\sqrt{d}}\sum_{j=0}^{d-1} |j\rangle^{\otimes q}$. The output of this function is a sparse vector.

Syntax

  • GHZ_STATE = GHZState(DIM,Q)
  • GHZ_STATE = GHZState(DIM,Q,COEFF)

Argument descriptions

  • DIM: The local dimension.
  • Q: The number of qubits (or qudits, if DIM > 2).
  • COEFF (optional, default [1,1,...,1]/sqrt(DIM)): A vector whose $j$-th entry is the coefficient of the term $|j-1\rangle^{\otimes q}$ in the generalized GHZ state.

Examples

3-qubit GHZ state

The following code generates the usual 3-qubit GHZ state:

>> full(GHZState(2,3))
 
ans =
 
    0.7071
         0
         0
         0
         0
         0
         0
    0.7071

A 7-qudit GHZ state

The following code generates the following GHZ state living in $(\mathbb{C}^4)^{\otimes 7}$: \[\frac{1}{\sqrt{30}}\big( |0000000\rangle + 2|1111111\rangle + 3|2222222\rangle + 4|3333333\rangle \big).\]

>> GHZState(4,7,[1,2,3,4]/sqrt(30))
 
ans =
 
         (1,1)             0.1826
      (5462,1)             0.3651
     (10923,1)             0.5477
     (16384,1)             0.7303

A very large GHZ state

This script has no trouble creating GHZ states on very large numbers of qudits. The following code generates the GHZ state in $(\mathbb{C}^3)^{\otimes 30}$:

>> GHZState(3,30)
 
ans =
 
                  (1,1)                      0.5774
    (102945566047325,1)                      0.5774
    (205891132094649,1)                      0.5774

Source code

Click on "expand" to the right to view the MATLAB source code for this function.

  1. %%	GHZSTATE    Generates a (generalized) GHZ state
  2. %	This function has two required input arguments:
  3. %     DIM: the local dimension
  4. %     Q: the number of parties (qubits/qudits)
  5. %
  6. %   GHZ_STATE = GHZState(DIM,Q) returns Q-partite GHZ state acting on DIM
  7. %   local dimensions, described in [1]. For example, GHZState(2,3) returns
  8. %   the standard 3-qubit GHZ state on qubits. The output of this function
  9. %   is sparse.
  10. %
  11. %   For a system of Q qubits (i.e., DIM = 2), the GHZ state can be
  12. %   written as |GHZ> = (|0>^{\otimes Q} + |1>^{\otimes Q})/sqrt(2).
  13. %
  14. %   This function has one optional input argument:
  15. %     COEFF (default [1,1,...,1]/sqrt(DIM)): a 1-by-DIM vector of coefficients
  16. %
  17. %   GHZ_STATE = GHZState(DIM,Q,COEFF) is as above, but the coefficient of
  18. %   the term |0>^{\otimes Q} is COEFF(1), the coefficient of the term
  19. %   |1>^{\otimes Q} is COEFF(2), and so on.
  20. %
  21. %	References:
  22. %   [1] Going beyond Bell's theorem. D. Greenberger and M. Horne and A. 
  23. %       Zeilinger. E-print: [quant-ph] arXiv:0712.0921. 2007.
  24. %
  25. %	URL: http://www.qetlab.com/GHZState
  26.  
  27. %	requires: opt_args.m
  28. % 	authors: Vincent Russo (vrusso@uwaterloo.ca)
  29. %            Nathaniel Johnston (nathaniel@njohnston.ca)
  30. %	package: QETLAB 
  31. %	last updated: December 15, 2014
  32.  
  33. function ghz_state = GHZState(dim,q,varargin)
  34.  
  35. % set optional argument defaults: coeff = [1,1,..,1]/sqrt(dim)
  36. [coeff] = opt_args({ ones(1,dim)/sqrt(dim) },varargin{:});
  37.  
  38. % Do some error checking.
  39. if dim < 2
  40.     error('GHZState:InvalidDim','DIM must be at least 2.');
  41. elseif q < 2
  42.     error('GHZState:InvalidQ','Q must be at least 2.');
  43. elseif length(coeff) ~= dim
  44.     error('GHZState:InvalidCoeff','COEFF must be a vector of length equal to DIM.');
  45. end
  46.  
  47. % Construct the state (and do it in a way that is less memory-intesting
  48. % than naively tensoring things together).
  49. dim_sum = 1;
  50. for j = 1:q-1
  51.     dim_sum = dim_sum + dim^j;
  52. end
  53.  
  54. ghz_state = sparse(dim^q,1);
  55. for j = 1:dim
  56.     ghz_state((j-1)*dim_sum + 1) = coeff(j);
  57. end