typedef double complex Complex; // swap a[i] and a[j] void swap( Complex a[], int i, int j) { Complex t = a[i]; a[i] = a[j]; a[j] = t; } void X( Complex a[]) { swap( a, 0, 1); } // NOT void Z( Complex a[]) { a[1] = -a[1]; } // phase flip void S( Complex a[]) { a[1] = CMPLX(0,1)*a[1]; } // sqrt(Z) void H( Complex a[]) // Hadamard { double s2 = 1/sqrt(2); Complex t0 = a[0], t1 = a[1]; a[0] = s2*(t0+t1); a[1] = s2*(t0-t1); } ... int main( void) { Complex a[2] = { 3.0/5.0, CMPLX(0,4.0/5.0) }; // constraint: sum |a[i]|2 = 1 ...