1. 问题背景

Bernstein–Vazirani 算法解决的是这样一个 oracle 问题

假设有一个黑盒函数

        f : \{0,1\}^n \to \{0,1\}

它定义为

        f(x) = x \cdot s \quad (\text{mod } 2)

其中 ss 是一个固定的 n 位二进制串 s \in \{0,1\}^n
而 x \cdot s \quad (\text{mod } 2) 表示按位点乘然后求和模 2(即两个二进制串的按位与之后数 1 的个数再模 2)。

点乘(dot product)定义

        x \cdot s = (x_0 s_0 + x_1 s_1 + \dots + x_{n-1} s_{n-1}) \bmod 2

等价于

        x \cdot s = \bigoplus_{i=0}^{n-1} (x_i \wedge s_i) 

这里 \oplus 是异或(模 2 加法,每次完成加法后直接 mod 2后,再参与下一个 mod-2-加,或者全部加法的结果 mod 2),\wedge 是按位与。

例子
若 s = 110x = 011

        x \cdot s = (0\cdot1) \oplus (1\cdot1) \oplus (1\cdot0) = 0 \oplus 1 \oplus 0 = 1

2. 经典解法

黑盒 f(x) 对任何输入 x 返回 x \cdot s

目标:找出隐藏的 s

经典做法:

        输入 x = 100\dots 0(只有第 0 位是 1),得到 f(100\dots 0) = s_0​。

        输入 x = 010\dots 0(只有第 1 位是 1),得到 f(010\dots 0) = s_1​。

        依此类推,输入 n 个不同的“只有一个 1”的串,得到 s 的所有位。

所以 经典需要 n 次查询

3. 量子解法(Bernstein–Vazirani 算法)

量子情况下,我们假设黑盒是一个 量子 oracle U_f​,它作用在 |x\rangle|y\rangle 上:

        U_f |x\rangle|y\rangle = |x\rangle|y \oplus f(x)\rangle

其中 |y\rangle 是单个量子位。

关键步骤

  1. 初始态:

         |0\rangle^{\otimes n} |1\rangle

  1. 对前 n 位(查询寄存器)施加 H^{\otimes n},对最后一位(目标位)施加 H( 得到 |-\rangle = \frac{|0\rangle - |1\rangle}{\sqrt{2}} ​)。

    此时整体态为:

        \frac{1}{\sqrt{2^n}} \sum_{x \in \{0,1\}^n} |x\rangle \cdot \frac{|0\rangle - |1\rangle}{\sqrt{2}} 

  1. 应用 U_f​:

         U_f \left[ \frac{1}{\sqrt{2^n}} \sum_x |x\rangle \frac{|0\rangle - |1\rangle}{\sqrt{2}} \right] = \frac{1}{\sqrt{2^n}} \sum_x |x\rangle \frac{|0 \oplus f(x)\rangle - |1 \oplus f(x)\rangle}{\sqrt{2}}

注意:

        |0 \oplus f(x)\rangle - |1 \oplus f(x)\rangle = (-1)^{f(x)} (|0\rangle - |1\rangle)

因为若 f(x) = 1,则 |0\rangle - |1\rangle 变成 |1\rangle - |0\rangle = - (|0\rangle - |1\rangle) 。

所以:

        \text{State} = \frac{1}{\sqrt{2^n}} \sum_x (-1)^{f(x)} |x\rangle \cdot \frac{|0\rangle - |1\rangle}{\sqrt{2}}

其中 f(x) = x \cdot s ,所以:

        = \frac{1}{\sqrt{2^n}} \sum_x (-1)^{x \cdot s} |x\rangle \cdot \frac{|0\rangle - |1\rangle}{\sqrt{2}}

  1. 丢弃最后一个量子位(它已分离),对前 n 位再作用 H^{\otimes n}

回忆:

        H^{\otimes n} |x\rangle = \frac{1}{\sqrt{2^n}} \sum_{z} (-1)^{x\cdot z} |z\rangle

反过来:

        H^{\otimes n} \left[ \frac{1}{\sqrt{2^n}} \sum_x (-1)^{x\cdot s} |x\rangle \right] = \frac{1}{2^n} \sum_x (-1)^{x\cdot s} \sum_z (-1)^{x\cdot z} |z\rangle

交换求和:

        = \sum_z \left[ \frac{1}{2^n} \sum_x (-1)^{x\cdot (s \oplus z)} \right] |z\rangle

  1. 括号内的求和:

        \frac{1}{2^n} \sum_x (-1)^{x\cdot t}

其中 t = s \oplus z
这个求和是 0,除非 t = 0(即 z = s),此时为 1。

所以结果是 |s\rangle

最终:测量前 n 位,确定性地得到 s

4. 结论

        经典:需要 n 次查询。

        量子:只需要 1 次查询 就得到 s

        x \cdot s 是二进制点乘模 2,它出现在 oracle 的相位 (-1)^{x\cdot s} 中,量子并行 + 干涉把它提取出来。

        这个算法是量子计算比经典有查询复杂度优势的早期例子之一(1992年),比 Grover 还早,并且是 Deustch–Jozsa 的推广。

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐