code: def controlled(num_ptr_bits, U):
      
      d = 2 ** (1 + num_ptr_bits)
      m = np.eye(d)
      m[d - 2:, d - 2:] = U
      return m
docs: Given a one-qubit gate matrix U, construct a controlled-U on all pointer
      qubits.