惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
F
Full Disclosure
B
Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
L
Lohrmann on Cybersecurity
月光博客
月光博客
I
Intezer
博客园 - 三生石上(FineUI控件)
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Darknet – Hacking Tools, Hacker News & Cyber Security
博客园_首页
P
Proofpoint News Feed
C
Check Point Blog
N
News | PayPal Newsroom
H
Heimdal Security Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
G
GRAHAM CLULEY
WordPress大学
WordPress大学
C
CERT Recently Published Vulnerability Notes
Y
Y Combinator Blog
Recorded Future
Recorded Future
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Tailwind CSS Blog
W
WeLiveSecurity
L
LINUX DO - 热门话题
Microsoft Azure Blog
Microsoft Azure Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Schneier on Security
Schneier on Security
爱范儿
爱范儿
Martin Fowler
Martin Fowler
U
Unit 42
T
Troy Hunt's Blog
S
Securelist
V
V2EX
V2EX - 技术
V2EX - 技术
MongoDB | Blog
MongoDB | Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
T
Tor Project blog
Cisco Talos Blog
Cisco Talos Blog
罗磊的独立博客
小众软件
小众软件
阮一峰的网络日志
阮一峰的网络日志
Vercel News
Vercel News

Posts on Changkun's Blog

Why High-Output Systems Are Often the First to Stop Growing Dark Forest Theory: A Formal Derivation Agents (or Humans) in Goal-Directed and Goalless Environments: On Pipelines, Priors, and the Rhythm Between Exploration and Exploitation At the Boundary of Self-Reference: From Stable Structures in Artificial Intelligence to the Self as a Recursive Model in an Open Dissipative System 2023 Reading List 2022 Reading List 2021 Reading List Are PSS/USS and RSS Actually the Same Thing? Performance Differences from Page Faults vs. Prefetching 2020 Year-End Review Migration with Zero Downtime 2020 Reading List The All in Go Stack Pointers Might Not Be Ideal for Parameters Eliminating A Source of Measurement Errors in Benchmarks Setup Wordpress in 10 Minutes 我为什么不再写博客了? 2019 年终总结 2018-2019 读书清单 Ten years of blogging Rethinking the Reflections on Communications and Trusts 2018 年终总结 Go source code study is open source Go source study: unsafe Pattern Go source study: sync.Pool Go runtime programming A Million WebSocket and Go Designing Asynchronous RESTful APIs 分布式杂谈01:CAP 理论的误解 Issues of Human-Bot Interaction 压缩法与深度网络的泛化性 Go in 1 Hour UMSLT04: The Past and Present of SGD UMSLT03: A Gentle Start of Learning Theory UMSLT02: A Breif History of Neural Networks UMSLT01: A Breif History of Regularization 不笑不足以为道 论文笔记:Generalization in Deep Learning 2017 年终总结 2017 读书清单 深度学习的泛化理论简介 删除 GitHub 上已经提交的敏感信息 硕士生涯的第一年就这样告一段落了 人肉计算(10): 系统参与激励 人肉计算(9): 陷阱的解法 别聊,一聊你就暴露 人肉计算(8): 人肉计算与数据科学中的陷阱 人肉计算(7): 社会行为分析 Hexo + GitHub + Travis CI + VPS 自动部署 人肉计算(6): 预测市场 人肉计算(5): 信用风险评级模型 读书与回报 瞎扯: 对现代企业理论与当下IT企业的商业模式和信息产业链的规律性的思考 人肉计算(4): 输入数据聚合与PageRank 又一次打整了一下博客 人肉计算(3): 输入数据聚合与链路预测 人肉计算(2): 意图博弈 GWAPs 人肉计算(1): 众包与群众智慧 对后辈同学在计算机专业上的答疑与解惑 在德国的医疗及住院体验 这可能不是一个技术博客了 实验楼楼赛第3期-Python-题解 迅速更换了 DISQUS Electron 深度实践总结 良好的编码体验的三个方面 2016 年终总结 2016 读书清单 最近在着手写的文章 微信小程序文档极致总结 谈谈过去三个月在实验楼的实习经历 Built a Desktop Client for My Blog Guacamole 源码分析与 VNC 中 RFB 协议的坑 《高速上手 C++11/14》正式发布 Docker 极速入门教程02 - 镜像与容器管理 Docker 极速入门教程01 - 基本概念和操作 阶段性沉默 ELK+Redis 最佳实践 终于全面启用了 HTTPS 苹果开源了LZFSE无损压缩 Hash 碰撞的一种思路 记一次完整的 Kaldi-TIMIT 示例运行 Kaldi 上的 TIMIT 例子 Kaldi 安装与部署 从科研写作谈起 Swift API 设计指南 有趣的人类 所以其实论文并没有什么鬼用 Githug 通关记录及指南 小结一下这学期的收获 2015 读书清单 2015 年终总结 负能量爆表 转眼就快两个月了 博客迁移记录 大三总结 这个世界,终究不会是我们的。 Linux 内核分析 之六:Linux 内核创建进程的过程 小说「泽缘」 Linux 内核分析 之五:system_call中断处理过程的简要分析 大创项目的标题真是每年都在考验同学们的想象力啊
Fourier变换应用小记
Changkun Ou · 2013-10-07 · via Posts on Changkun's Blog

Published at发布于:   |   PV/UV: /   |   Reading阅读: 4 min

大整数问题一直很头疼,采用乘法原理的结果复杂度为$O(n^{2})$,最近看傅里叶变换有尝试用傅里叶变换加以改进。

$$ a=(a_{N-1}a_{N-2}…a_{1}a_{0}){10}=a{N-1}10^{N-1}+…+a_{0}10^{0}] [b=(b_{N-1}b_{N-2}…b_{1}b_{0}){10}=b{N-1}10^{N-1}+…+b_{0}10^{0} $$

两个式子的乘积

$$ c = ab = c_{2N-2}10^{2N-2}+c_{2N-3}10^{2N-3}+…+c_{1}10^{1}+c_{0}10^{0} $$

其中

$$ c_{k}=\sum_{i+j=k}a_{i}b_{j},(i=0,…,N-1) $$

这种算法的时间复杂度为$O(n^{2})$。

逆天的是,${c_{k}}$居然逆天的等于${a_{k}}$和${b_{k}}$点的卷积。我们知道,卷积可以通过傅里叶变换的方式转化为普通乘法(函数卷积的傅里叶变换是函数傅里叶变换的乘积)。 于是,我们有: (1)求${a_{i}}$和${b_{j}}$的傅里叶变换(离散)${A_{i}}$和${B_{j}}$ (2)${A_{i}}$和${B_{j}}$逐项相乘得到${C_{k}}$ (3)对${C_{k}}$求傅里叶逆变换,得到${c_{k}}$ (4)进位,出结果

对复向量${x_{N-1},…,x_{1},x_{0}}$,离散傅里叶变换为:

$$ X_{k}=\sum_{n=0}^{N-1}x_{n}e^{\frac{-2i\pi nk}{N}},(k=0,…,N-1) $$

逆变换公式为:

$$ x_{k}=\frac{1}{N}\sum_{k=0}^{N-1}X_{k}e^{\frac{-2i\pi kn}{N}},(n=0,…,N-1) $$

例: 三位数($N=3$)$a=456,b=987$,求c=ab。 结果为:c=450072。共 6 位数字,$N$扩展到$2^3 = 8$。

$$ { a_7, a_6, a_5, a_4, a_3, a_2, a_1, a_0 } = { 0, 0, 0, 0, 0, 4, 5, 6 } $$

$$ { b_7, b_6, b_5, b_4, b_3, b_2, b_1, b_0 } = { 0, 0, 0, 0, 0, 9, 8, 7 } $$

令:

$$ \omega=e^{\frac{-2i\pi}{N}}=e^{\frac{-2i\pi}{8}}=e^{\frac{-i\pi}{4}}=cos\left(-\frac{\pi}{4}\right)+isin\left(-\frac{\pi}{4}\right)=\frac{\sqrt{2}}{2}-i\frac{\sqrt{2}}{2} \approx 0.7-0.7i $$

为了方便:

$$ \begin{eqnarray} && \omega^{8} =\omega^{0} = 1 \nonumber\ && \omega^{9} =\omega^{1} \approx 0.7-0.7i \nonumber\ && \omega^{10}=\omega^{2} = -i \nonumber\ && \omega^{11}=\omega^{3} \approx -0.7-0.7i \nonumber\ && \omega^{12}=\omega^{4} = -1 \nonumber\ && \omega^{13}=\omega^{5} \approx -0.7+0.7i \nonumber\ && \omega^{14}=\omega^{6} = i \nonumber\ && \omega^{15}=\omega^{7} \approx 0.7+0.7i \nonumber \end{eqnarray} $$

注意到当$n>2$时,$a_{n}=0$,于是

$$ \begin{eqnarray} && A_0 = a_0\times \omega^{0\times 0} + a_1\times \omega^{1\times 0} + a_2\times \omega^{2\times 0} = 6\times\omega^{0} + 5\times\omega^{0} + 4\times\omega^{0} = 15 \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && A_1 = a_0\times \omega^{0\times 1} + a_1\times \omega^{1\times 1} + a_2\times \omega^{2\times 1} = 6\times\omega^{0} + 5\times\omega^{1} + 4\times\omega^{2} = \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && A_2 = a_0\times \omega^{0\times 0} + a_1\times \omega^{1\times 2} + a_2\times \omega^{2\times 2} = 6\times\omega^{0} + 5\times\omega^{2} + 4\times\omega^{4} = \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && A_3 = a_0\times \omega^{0\times 0} + a_1\times \omega^{1\times 3} + a_2\times \omega^{2\times 3} = 6\times\omega^{0} + 5\times\omega^{3} + 4\times\omega^{6} = \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && A_4 = a_0\times \omega^{0\times 0} + a_1\times \omega^{1\times 4} + a_2\times \omega^{2\times 4} = 6\times\omega^{0} + 5\times\omega^{4} + 4\times\omega^{8} = \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && A_5 = a_0\times \omega^{0\times 0} + a_1\times \omega^{1\times 5} + a_2\times \omega^{2\times 5} = 6\times\omega^{0} + 5\times\omega^{5} + 4\times\omega^{10} = \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && A_6 = a_0\times \omega^{0\times 0} + a_1\times \omega^{1\times 6} + a_2\times \omega^{2\times 6} = 6\times\omega^{0} + 5\times\omega^{6} + 4\times\omega^{12} = \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && A_7 = a_0\times \omega^{0\times 0} + a_1\times \omega^{1\times 7} + a_2\times \omega^{2\times 7} = 6\times\omega^{0} + 5\times\omega^{7} + 4\times\omega^{14} = \nonumber \end{eqnarray} $$

同样,当$n>2$时,$b_{n}=0$,于是

$$ \begin{eqnarray} && B_0 = b_0\times \omega^{0\times 0} + b_1\times \omega^{1\times 0} + b_2\times \omega^{2\times 0} = 7\times\omega^{0} + 8\times\omega^{0} + 9\times\omega^{0} = 24 \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && B_1 = b_0\times \omega^{0\times 1} + b_1\times \omega^{1\times 1} + b_2\times \omega^{2\times 1} = 7\times\omega^{0} + 8\times\omega^{1} + 9\times\omega^{2} = \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && B_2 = b_0\times \omega^{0\times 2} + b_1\times \omega^{1\times 2} + b_2\times \omega^{2\times 2} = 7\times\omega^{0} + 8\times\omega^{2} + 9\times\omega^{4} = \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && B_3 = b_0\times \omega^{0\times 3} + b_1\times \omega^{1\times 3} + b_2\times \omega^{2\times 3} = 7\times\omega^{0} + 8\times\omega^{3} + 9\times\omega^{6} = \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && B_4 = b_0\times \omega^{0\times 4} + b_1\times \omega^{1\times 4} + b_2\times \omega^{2\times 4} = 7\times\omega^{0} + 8\times\omega^{4} + 9\times\omega^{8} = \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && B_5 = b_0\times \omega^{0\times 5} + b_1\times \omega^{1\times 5} + b_2\times \omega^{2\times 5} = 7\times\omega^{0} + 8\times\omega^{5} + 9\times\omega^{10} = \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && B_6 = b_0\times \omega^{0\times 6} + b_1\times \omega^{1\times 6} + b_2\times \omega^{2\times 6} = 7\times\omega^{0} + 8\times\omega^{6} + 9\times\omega^{12} = \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} B_7 = b_0\times \omega^{0\times 7} + b_1\times \omega^{1\times 7} + b_2\times \omega^{2\times 7} = 7\times\omega^{0} + 8\times\omega^{7} + 9\times\omega^{14} = \nonumber \end{eqnarray} $$

于是得到${A_i}$和${B_i}$

$$ \begin{eqnarray} && {A_7,A_6,A_5,A_4,A_3,A_2,A_1,A_0}={,,,,,,,15} \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && {B_7,B_6,B_5,B_4,B_3,B_2,B_1,B_0}={,,,,,,,24} \nonumber \end{eqnarray} $$

再求${A_i}$和${B_i}$的点积得到${C_{k}}$:

$$ \begin{eqnarray} && {C_7,C_6,C_5,C_4,C_3,C_2,C_1,C_0}={,,,,,,,360} \nonumber \end{eqnarray} $$

求${C_{k}}$的离散傅里叶逆变换,令

$$ \omega=e^{\frac{2i\pi}{N}}=e^{\frac{2i\pi}{8}}=e^{\frac{i\pi}{4}}=cos\left(\frac{\pi}{4}\right)+isin\left(\frac{\pi}{4}\right)=\frac{\sqrt{2}}{2}+i\frac{\sqrt{2}}{2} \approx 0.7+0.7i $$

为了方便:

$$ \begin{eqnarray} && \omega^{8} =\omega^{0} = 1 \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && \omega^{9} =\omega^{1} \approx 0.7+0.7i \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && \omega^{10}=\omega^{2} = -i \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && \omega^{11}=\omega^{3} \approx -0.7-0.7i \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && \omega^{12}=\omega^{4} = -1 \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && \omega^{13}=\omega^{5} \approx -0.7+0.7i \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && \omega^{14}=\omega^{6} = i \nonumber\ \end{eqnarray} $$

$$ \begin{eqnarray} && \omega^{15}=\omega^{7} \approx 0.7+0.7i \nonumber \end{eqnarray} $$

于是计算$c_{i}$得到:

于是获得${c_{i}}$,,于是${c_i}$就是大整数的计算结果。 但是可惜离散傅里叶变换的时间复杂度还是$O(n^{2})$。关键在于:直接进行离散傅里叶变换的计算复杂度是$O(N^2)$。快速傅里叶变换可以计算出与直接计算相同的结果,但只需要$O(NlogN)$的计算复杂度。

部分运算结果没有写完,时间问题,改日再补。