Skip to content

Commit 5ea7caa

Browse files
committed
Added log/exp
1 parent 3fe590e commit 5ea7caa

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

content/numerical/FFTPolynomial.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,20 @@ poly deriv(poly a) {
6868
}
6969
poly integr(poly a) {
7070
if (a.empty())
71-
return {};
71+
return {0};
7272
poly b(sz(a) + 1);
73-
rep(i, 0, sz(a) + 1) b[i + 1] = a[i] / num(i + 1);
73+
rep(i,1,sz(b)) b[i] = a[i - 1] / num(i);
7474
return b;
7575
}
76+
poly log(poly a) { return modK(integr(deriv(a) * inverse(a)), sz(a)); }
77+
poly exp(poly a) {
78+
poly b(1, num(1));
79+
if (a.empty())
80+
return b;
81+
while (sz(b) < sz(a)) {
82+
b.resize(sz(b)*2);
83+
b *= (poly({num(1)}) + modK(a, sz(b)) - log(b));
84+
b.resize(sz(b)/2 + 1);
85+
}
86+
return modK(b, sz(a));
87+
}

0 commit comments

Comments
 (0)