# Demo 2:Abel HSP 离散对数 > 第 10 章 隐藏结构与群算法 · [本章演示](index.md) · [代码演示总索引](../index.md) **可视化**:双图 —— N=15 拆 p1, p2 + CRT **对应教程**:[第 10 章 隐藏结构与群算法 中相关小节](https://tutorial.chenzhaoyun.com/quantum-tutorial/ch10-hidden-structures/) · 依赖安装:`pip install "unified-quantum[visualization,simulation]"` ## 实现要点 问题:求 x 使 2^x ≡ 8 (mod 15),期望 x=3。 Shor 把阶查找拆成对 N 的每个素因子 p 分别查找,再 CRT (lcm) 拼合: - p=3: ord_3(2) = 2 - p=5: ord_5(2) = 4 - lcm(2, 4) = 4 = r ✓ QPE 估相位:U|a⟩ = |2a mod p⟩ 的本征相位是 j/r_p。 实操:用 numpy 模拟 QPE 输出(直接构造 U 所需门代价过高),CRT 与恢复 x 经典完成。 ## 完整源码 ```{literalinclude} 02_abel_hsp.py :language: python :linenos: :caption: demos/ch10-hidden-structures/02_abel_hsp.py ``` ## 运行结果 ![Demo 2:Abel HSP 离散对数](02_abel_hsp.png) ## 运行方式 ```bash # 仓库根目录执行;输出 PNG 到 demos/ch10-hidden-structures/02_abel_hsp.png,关键统计到 stdout .venv/bin/python3 demos/ch10-hidden-structures/02_abel_hsp.py ``` --- [← 本章演示](index.md) · [↑ 代码演示总索引](../index.md) · [⌂ 教程门户](https://tutorial.chenzhaoyun.com/)