{"raw_statement":[{"iden":"statement","content":"Implement a quantum oracle on 3 qubits which implements a majority function. Majority function on 3-bit vectors is defined as follows: if vector has two or three 1s, and 0 if it has zero or one 1s.\n\nFor an explanation on how this type of quantum oracles works, see [Introduction to quantum oracles](https://codeforces.com/blog/entry/60319).\n\nYou have to implement an operation which takes the following inputs:\n\n*   an array of 3 qubits _x_ in arbitrary state (input register),\n*   a qubit _y_ in arbitrary state (output qubit).\n\nThe operation doesn't have an output; its \"output\" is the state in which it leaves the qubits.\n\nYour code should have the following signature:\n\nnamespace Solution {\n    open Microsoft.Quantum.Primitive;\n    open Microsoft.Quantum.Canon;\n\n    operation Solve (x : Qubit\\[\\], y : Qubit) : ()\n    {\n        body\n        {\n            // your code here\n        }\n    }\n}"}],"translated_statement":[{"iden":"statement","content":"实现一个作用于 3 个量子比特的量子预言机，实现多数函数。3 位向量的多数函数定义如下：如果向量包含两个或三个 1，则输出 1；如果包含零个或一个 1，则输出 0。\n\n有关此类量子预言机的工作原理的说明，请参阅《量子预言机简介》。\n\n你需要实现一个操作，它接受以下输入：\n\n该操作没有输出；其“输出”是它留下的量子比特状态。\n\n你的代码应具有以下签名：\n\n"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n = 3 $ be the number of qubits. Let $ \\ket{x} = \\ket{x_1 x_2 x_3} $ denote a computational basis state, where $ x_i \\in \\{0,1\\} $.  \nLet $ f: \\{0,1\\}^3 \\to \\{0,1\\} $ be the majority function:  \n$$\nf(x_1, x_2, x_3) = \n\\begin{cases}\n1 & \\text{if } x_1 + x_2 + x_3 \\geq 2 \\\\\n0 & \\text{otherwise}\n\\end{cases}\n$$\n\n**Quantum Oracle Specification**  \nThe oracle is a unitary operator $ U_f $ acting on $ n+1 = 4 $ qubits: $ n $ input qubits $ \\ket{x_1 x_2 x_3} $ and one ancilla qubit $ \\ket{y} $.  \nIt satisfies:  \n$$\nU_f \\ket{x_1 x_2 x_3} \\ket{y} = \\ket{x_1 x_2 x_3} \\ket{y \\oplus f(x_1, x_2, x_3)}\n$$\n\n**Constraints**  \n- The oracle must be implemented using reversible quantum gates.  \n- The input qubits $ \\ket{x_1, x_2, x_3} $ must remain unchanged.  \n- The ancilla qubit $ \\ket{y} $ is flipped iff $ f(x_1, x_2, x_3) = 1 $.  \n\n**Objective**  \nImplement the unitary $ U_f $ such that for all $ x \\in \\{0,1\\}^3 $ and $ y \\in \\{0,1\\} $:  \n$$\nU_f \\ket{x} \\ket{y} = \\ket{x} \\ket{y \\oplus \\mathbf{1}_{\\sum_{i=1}^3 x_i \\geq 2}}\n$$","simple_statement":null,"has_page_source":false}