void M1( Complex a[]) { // measure qubit 1 int k = Mk( a); if( k == 0 || k == 1) { // qubit 1 is 0 printf( "M1 = 0\n"); a[2] = a[3] = 0; // normalize remaining states double s = sqrt( abs2(a[0]) + abs2(a[1])); a[0] /= s; a[1] /= s; } else { // qubit 1 is 1 printf( "M1 = 1\n"); a[0] = a[1] = 0; double s = sqrt( abs2(a[2]) + abs2(a[3])); a[2] /= s; a[3] /= s; } }