From f9a004c64119192cd34cbf80c704e4b64f9d69b7 Mon Sep 17 00:00:00 2001 From: Tri-solaris Date: Fri, 1 Mar 2019 23:37:08 +0800 Subject: [PATCH] qwq --- docs/math/poly-div-mod.md | 130 ++++++++++++++++++++++ docs/math/poly-inv.md | 75 +++++++++++++ docs/math/poly-ln-exp.md | 137 ++++++++++++++++++++++++ docs/math/poly-multipoint-eval-interpolation.md | 102 ++++++++++++++++++ docs/math/poly-sqrt.md | 78 ++++++++++++++ docs/math/poly.md | 63 +++++++++++ mkdocs.yml | 5 + 7 files changed, 590 insertions(+) create mode 100755 docs/math/poly-div-mod.md create mode 100755 docs/math/poly-inv.md create mode 100755 docs/math/poly-ln-exp.md create mode 100644 docs/math/poly-multipoint-eval-interpolation.md create mode 100755 docs/math/poly-sqrt.md diff --git a/docs/math/poly-div-mod.md b/docs/math/poly-div-mod.md new file mode 100755 index 00000000..d5e88dc9 --- /dev/null +++ b/docs/math/poly-div-mod.md @@ -0,0 +1,130 @@ +# Description + +给定多项式 $f\left(x\right),g\left(x\right)$,求 $g\left(x\right)$ 除 $f\left(x\right)$ 的商 $Q\left(x\right)$ 和余数 $R\left(x\right)$. + +# Method + +发现若能消除 $R\left(x\right)$ 的影响则可直接[**多项式求逆**](../poly-inv)解决. + +考虑构造变换 + +$$f^{R}\left(x\right)=x^{\operatorname{deg}{f}}f\left(\frac{1}{x}\right)$$ + +观察可知其实质为反转 $f\left(x\right)$ 的系数. + +设 $n=\operatorname{deg}{f},m=\operatorname{deg}{g}$. + +将 $f\left(x\right)=Q\left(x\right)g\left(x\right)+R\left(x\right)$ 中的 $x$ 替换成 $\frac{1}{x}$ 并将其两边都乘上 $x^{n}$,得到: + +$$\begin{aligned} + f\left(\frac{1}{x}\right)&=x^{n-m}Q\left(x\right)x^{m}g\left(x\right)+x^{n-m+1}x^{m-1}R\left(x\right)\\ + f^{R}\left(x\right)&=Q^{R}\left(x\right)g^{R}\left(x\right)+x^{n-m+1}R^{R}\left(x\right) +\end{aligned}$$ + +注意到上式中 $R^{R}\left(x\right)$ 的系数为 $x^{n-m+1}$,则将其放到模 $x^{n-m+1}$ 意义下即可消除 $R^{R}\left(x\right)$ 带来的影响. + +又因 $Q^{R}\left(x\right)$ 的次数为 $\left(n-m\right)<\left(n-m+1\right)$,故 $Q^{R}\left(x\right)$ 不会受到影响. + +则: + +$$f^{R}\left(x\right)\equiv Q^{R}\left(x\right)g^{R}\left(x\right)\pmod{x^{n-m+1}}$$ + +使用多项式求逆即可求出 $Q\left(x\right)$,将其反代即可得到 $R\left(x\right)$. + +时间复杂度 $O\left(n\log{n}\right)$. + +# Code + +??? " `poly-div-mod.cpp` " + + ```cpp + using Z=int; + using mZ=long long; + using poly_t=Z[mxdg]; + using poly=Z*const; + + inline int calcpw2(const int&n){ + int t=1; + for(;t 当 $\left[x^{0}\right]g\left(x\right)\neq 1$ 时,可能需要使用二次剩余来计算 $\left[x^{0}\right]f\left(x\right)$. + +## Newton's Method + +参见 [**Newton's Method**](../poly-newton/#sqrt). + +# Code + +??? " `poly-sqrt.cpp` " + + ```cpp + using Z=int; + using mZ=long long; + using poly_t=Z[mxdg]; + using poly=Z*const; + + inline void cp(const Z*const&sl,const Z*const&sr,Z*const&dl,Z*const&dr){ + std::copy(sl,sr,dl); + if(sr-sl>1;i!=deg1;++i) + f[i]=div2(sqrt_t[i]); + std::fill(f+deg1,f+deg2,0); + } + } + ``` + +# Examples + +1. [**「Codeforces Round #250」E. The Child and Binary Tree**](/「Codeforces-Round-250」E-The-Child-and-Binary-Tree/) + diff --git a/docs/math/poly.md b/docs/math/poly.md index e69de29b..d900f09f 100644 --- a/docs/math/poly.md +++ b/docs/math/poly.md @@ -0,0 +1,63 @@ +# Basic Concepts + +## 多项式的度 + +对于一个多项式 $f\left(x\right)$,称其最高次项的次数为该多项式的**度(Degree)**,记作 $\operatorname{deg}{f}$. + +## 多项式的逆元 + +对于多项式 $f\left(x\right)$,若存在 $g\left(x\right)$ 满足: + +$$\begin{aligned} + f\left(x\right)g\left(x\right)&\equiv 1\pmod{x^{n}}\\ + \operatorname{deg}{g}&\leqslant\operatorname{deg}{f} +\end{aligned}$$ + +则称 $g\left(x\right)$ 为 $f\left(x\right)$ 在模 $x^{n}$ 意义下的**逆元(Inverse Element)**,记作 $f^{-1}\left(x\right)$. + +## 多项式的余数和商 + +对于多项式 $f\left(x\right),g\left(x\right)$,存在**唯一**的 $Q\left(x\right),R\left(x\right)$ 满足: + +$$\begin{aligned} + f\left(x\right)&=Q\left(x\right)g\left(x\right)+R\left(x\right)\\ + \operatorname{deg}{Q}&=\operatorname{deg}{f}-\operatorname{deg}{g}\\ + \operatorname{deg}{R}&<\operatorname{deg}{g} +\end{aligned}$$ + +我们称 $Q\left(x\right)$ 为 $g\left(x\right)$ 除 $f\left(x\right)$ 的**商(Quotient)**,$R\left(x\right)$ 为 $g\left(x\right)$ 除 $f\left(x\right)$ 的**余数(Remainder)**. + +亦可记作 + +$$f\left(x\right)\equiv R\left(x\right)\pmod{g\left(x\right)}$$ + +## 多项式的对数函数与指数函数 + +对于一个多项式 $f\left(x\right)$,可以将其对数函数看作其与麦克劳林级数的复合: + +$$\ln{\left(1-f\left(x\right)\right)}=-\sum_{i=1}^{+\infty}\frac{f^{i}\left(x\right)}{i}$$ + +其指数函数同样可以这样定义: + +$$\exp{f\left(x\right)}=e^{f\left(x\right)}=\sum_{i=0}^{+\infty}\frac{f^{i}\left(x\right)}{i!}$$ + +## 多项式的多点求值和插值 + +**多项式的多点求值(Multi-point evaluation)** 即给出一个多项式 $f\left(x\right)$ 和 $n$ 个点 $x_{1},x_{2},...,x_{n}$,求 + +$$f\left(x_{1}\right),f\left(x_{2}\right),...,f\left(x_{n}\right)$$ + +**多项式的插值(Interpolation)** 即给出 $n+1$ 个点 + +$$\left(x_{0},y_{0}\right),\left(x_{1},y_{1}\right),...,\left(x_{n},y_{n}\right)$$ + +求一个 $n$ 次多项式 $f\left(x\right)$ 使得这 $n+1$ 个点都在 $f\left(x\right)$ 上. + +这两种操作的实质就是将多项式在**系数表示**和**点值表示**间转化. + +# References + +[**Picks's Blog**](https://picks.logdown.com) + +[**Miskcoo's Space**](https://blog.miskcoo.com) + diff --git a/mkdocs.yml b/mkdocs.yml index 9b5e2eb6..38939974 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -122,7 +122,12 @@ nav: - 快速傅里叶变换: math/fft.md - 快速数论变换: math/ntt.md - 快速沃尔什变换: math/fwt.md + - 多项式求逆: math/poly-inv.md + - 多项式开方: math/poly-sqrt.md + - 多项式除法|取模: math/poly-div-mod.md + - 多项式对数函数|指数函数: math/poly-ln-exp.md - 多项式牛顿迭代: math/poly-newton.md + - 多项式多点求值|快速插值: math/poly-multipoint-eval-interpolation.md - 组合数学: - 排列组合: math/combination.md - 卡特兰数: math/catalan.md -- 2.11.0