肖尔算法#

Shor算法和辅助函数。

待办事项:

  • 使用新的gateapi让CMod门再次工作。

  • 解决一切。

  • 更新docstrings并重新格式化。

class sympy.physics.quantum.shor.CMod(*args, **kwargs)[源代码]#

一个受控的模门。

这是一个黑盒控制的Mod函数,供shor算法使用。TODO:实现一个decompose属性,该属性根据基本门返回如何执行此操作

property N#

N是我们正在做的模运算类型。

property a#

受控mod功能的基础。

property t#

1/2输入寄存器的大小。前1/2保持输出。

sympy.physics.quantum.shor.period_find(a, N)[源代码]#

求模N算术中a的周期

这是肖尔算法的量子部分。它有两个寄存器,第一个是与Hadamards的叠加态,所以: |k>|0> k是所有可能的选择。然后它进行一个受控的mod和QFT来确定a的顺序。

sympy.physics.quantum.shor.shor(N)[源代码]#

此函数在整数N上实现Shor的因式分解算法

The algorithm starts by picking a random number (a) and seeing if it is coprime with N. If it is not, then the gcd of the two numbers is a factor and we are done. Otherwise, it begins the period_finding subroutine which finds the period of a in modulo N arithmetic. This period, if even, can be used to calculate factors by taking a**(r/2)-1 and a**(r/2)+1. These values are returned.