GHZState

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.

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

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).$$

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}$: