Barrett And Montgomery of Polynomials
Posted 山登绝顶我为峰 3(^v^)3
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Barrett And Montgomery of Polynomials相关的知识,希望对你有一定的参考价值。
Barrett reduction of polynomials
对于
f
,
g
∈
Z
p
[
x
]
f,g \\in Z_p[x]
f,g∈Zp[x],其中
p
p
p是素数。那么:
f
m
o
d
g
=
f
−
⌊
f
g
⌋
g
f \\mod g = f - \\lfloor \\fracfg \\rfloor g
fmodg=f−⌊gf⌋g
其中的分式属于分式域:
1
/
g
∈
f
g
∣
f
,
g
∈
Z
p
[
x
]
1/g \\in \\ \\dfracfg | f,g \\in Z_p[x] \\
1/g∈gf∣f,g∈Zp[x]
我们寻找一个
m
∈
Z
p
[
x
]
m \\in Z_p[x]
m∈Zp[x],使得:
1
g
=
m
R
\\frac1g = \\fracmR
g1=Rm
其中,
R
=
x
k
∈
Z
p
[
x
]
R=x^k \\in Z_p[x]
R=xk∈Zp[x],
k
k
k是某个正整数
那么选取:
m
=
⌊
R
g
⌋
∈
Z
p
[
x
]
m = \\lfloor \\fracRg \\rfloor \\in Z_p[x]
m=⌊gR⌋∈Zp[x]
误差大小为:
e
=
1
g
−
⌊
R
g
⌋
R
e = \\frac1g - \\dfrac\\lfloor \\fracRg \\rfloorR
e=g1−R⌊gR⌋
于是,
f
m
o
d
g
≈
f
−
⌊
f
⋅
m
R
⌋
g
f \\mod g \\approx f - \\lfloor \\fracf \\cdot mR \\rfloor g
fmodg≈f−⌊Rf⋅m⌋g
选取足够大的
k
k
k,使得
f
⋅
e
f \\cdot e
f⋅e的系数足够小,那么:
f
m
o
d
g
=
f
−
(
(
f
⋅
m
)
≫
k
)
g
∈
Z
p
[
x
]
f \\mod g = f - ((f \\cdot m) \\gg k) g \\in Z_p[x]
fmodg=f−((f⋅m)≫k)g∈Zp[x]
这里的
≫
\\gg
≫运算定义为
(
∑
i
=
0
n
−
1
a
i
x
i
≫
k
)
:
=
∑
i
=
k
n
−
1
a
i
x
i
−
k
(\\sum_i=0^n-1a_i x^i \\gg k) := \\sum_i=k^n-1a_i x^i-k
(∑i=0n−1aixi≫k):=∑i=kn−1aixi−k
Montgomery multiplication of polynomials
对于 f , g , h ∈ Z p [ x ] f,g,h \\in Z_p[x] f,g,h∈Zp[x],其中 p p p是素数。计算: f ⋅ g m o d h f \\cdot g \\mod h f⋅gmodh
首先,寻找 R = x k ∈ Z p [ x ] R=x^k \\in Z_p[x] R=xk∈Zp[x],其中 k k k是某个正整数,使得 g c d ( R , h ) = 1 gcd(R,h)=1 gcd(R,h)=1
计算:
h
−
1
⋅
h
≡
1
m
o
d
R
R
−
1
⋅
R
≡
1
m
o
d
h
h^-1 \\cdot h \\equiv 1 \\mod R\\\\ R^-1 \\cdot R \\equiv 1 \\mod h\\\\
h−1⋅h≡1modRR−1⋅R≡1modh
做可逆映射:
f
‾
=
f
R
m
o
d
h
g
‾
=
g
R
m
o
d
h
\\overlinef = f R \\mod h\\\\ \\overlineg = g R \\mod h\\\\
f=fRmodhg=gRmodh
那么
f
g
‾
=
f
g
R
=
f
‾
⋅
g
‾
⋅
R
−
1
m
o
d
h
\\overlinef g = f g R = \\overlinef \\cdot \\overlineg \\cdot R^-1 \\mod h
fg=fgR=f⋅g⋅R−1modh
简记
T
=
f
‾
⋅
g
‾
T = \\overlinef \\cdot \\overlineg
T=f⋅g,则
f
g
‾
=
T
R
−
1
\\overlinef g = TR^-1
Barrett约减
LeetcodeBitwise AND of Numbers Range
difference of top and left between Javascript and Jquery
Distributed Representations of Words and Phrases and their Compositionality
[GeeksForGeeks] Check sum of covered and uncovered nodes of binary tree