New answers tagged

0

I think this snippet from Cirq's Deutsch's algorithm example (disclosure: I am its author) should be fairly easy to understand: def make_oracle(q0, q1, secret_function): """ Gates implementing the secret function f(x).""" # coverage: ignore if secret_function[0]: yield [CNOT(q0, q1), X(q1)] if secret_function[1]: yield CNOT(...


1

I implemented them as a "subcircuit" so it looks "hidden" from the "outside". constant 0: input = QuantumRegister(1, name='input') temp = QuantumRegister(1, name='temp') constant0 = QuantumCircuit(input, temp, name='oracle') oracle = constant0.to_instruction() identity: input = QuantumRegister(1, name='input') temp = QuantumRegister(1, name='temp') ...


1

@cgranade and I have a chapter on the Deutsch-Jozsa algorithm (Chapter 7) as well as implementations of the oracles for Q# in our book Learn Quantum Computing with Python and Q#. You can find the code samples for the book in the repo here. In particular, the oracles look like this: namespace DeutschJozsa { open Microsoft.Quantum.Intrinsic; ...


1

An oracle $U_f$ is actually $\mathrm{X}$ gate (or a negation). The circuit implementing the oracle is following Qubit $q_0$ is input and qubit $q_{1}$ is output. Firstly $\mathrm{X}$ is applied on $q_{0}$. This negate the qubit, however, we want to have an output on $q_1$. Therefore, we apply $\mathrm{CNOT}$ which in this setting "copy" the $q_{0}$ to ...


1

The $(-1)^{x\cdot y}$ terms come from the matrix elements of $H^{\otimes n}$. To see this, start from considering the matrix elements of $H$. You can check that they can be written as $H_{ij}=(-1)^{ij}$ where $i,j\in\{0,1\}$. The matrix elements of $H^{\otimes n}$ are indexed by tuples of $n$ binary numbers, that is, writing $I\equiv (i_1,...,i_n), J\equiv(...


3

Your first formula is not correct. The correct formula for Hadamard gates for the arbitrary $|x\rangle$ from the calculational basis is (it can be proved by induction): $$H^{\otimes n}|x\rangle=\frac{1}{\sqrt{2^n}} \sum_{y=0}^{2n-1}{(-1)^{x\cdot y}}|y\rangle$$ where $x\cdot y=x_0y_0\oplus x_1y_1\oplus x_2y_2\oplus ...\oplus x_ny_n$ In case $|x\rangle = |0\...


Top 50 recent answers are included