Skip to content

Commit f277725

Browse files
committed
Switched to tabs
1 parent 92095f1 commit f277725

File tree

2 files changed

+84
-85
lines changed

2 files changed

+84
-85
lines changed

content/numerical/FFTPolynomial.h

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -8,127 +8,127 @@
88
#include "../number-theory/ModularArithmetic.h"
99
#include "FastFourierTransform.h"
1010
#include "FastFourierTransformMod.h"
11-
// #include "NumberTheoreticTransform.h"
11+
#include "NumberTheoreticTransform.h"
1212

1313
typedef Mod num;
1414
typedef vector<num> poly;
1515
vector<Mod> conv(vector<Mod> a, vector<Mod> b) {
16-
// auto res = convMod<mod>(vl(all(a)), vl(all(b)));
17-
auto res = conv(vl(all(a)), vl(all(b)));
18-
return vector<Mod>(all(res));
16+
auto res = convMod<mod>(vl(all(a)), vl(all(b)));
17+
// auto res = conv(vl(all(a)), vl(all(b)));
18+
return vector<Mod>(all(res));
1919
}
2020
poly &operator+=(poly &a, const poly &b) {
21-
a.resize(max(sz(a), sz(b)));
22-
rep(i, 0, sz(b)) a[i] = a[i] + b[i];
23-
return a;
21+
a.resize(max(sz(a), sz(b)));
22+
rep(i, 0, sz(b)) a[i] = a[i] + b[i];
23+
return a;
2424
}
2525
poly &operator-=(poly &a, const poly &b) {
26-
a.resize(max(sz(a), sz(b)));
27-
rep(i, 0, sz(b)) a[i] = a[i] - b[i];
28-
return a;
26+
a.resize(max(sz(a), sz(b)));
27+
rep(i, 0, sz(b)) a[i] = a[i] - b[i];
28+
return a;
2929
}
3030

3131
poly &operator*=(poly &a, const poly &b) {
32-
if (sz(a) + sz(b) < 100){
33-
poly res(sz(a) + sz(b) - 1);
32+
if (sz(a) + sz(b) < 100){
33+
poly res(sz(a) + sz(b) - 1);
3434
rep(i,0,sz(a)) rep(j,0,sz(b))
3535
res[i + j] = (res[i + j] + a[i] * b[j]);
36-
return (a = res);
37-
}
38-
return a = conv(a, b);
36+
return (a = res);
37+
}
38+
return a = conv(a, b);
3939
}
4040
poly operator*(poly a, const num b) {
41-
poly c = a;
42-
trav(i, c) i = i * b;
43-
return c;
41+
poly c = a;
42+
trav(i, c) i = i * b;
43+
return c;
4444
}
4545
#define OP(o, oe) \
46-
poly operator o(poly a, poly b) { \
47-
poly c = a; \
48-
return c oe b; \
49-
}
46+
poly operator o(poly a, poly b) { \
47+
poly c = a; \
48+
return c oe b; \
49+
}
5050
OP(*, *=) OP(+, +=) OP(-, -=);
5151
poly modK(poly a, int k) { return {a.begin(), a.begin() + min(k, sz(a))}; }
5252
poly inverse(poly A) {
53-
poly B = poly({num(1) / A[0]});
54-
while (sz(B) < sz(A))
55-
B = modK(B * (poly({num(2)}) - modK(A, 2*sz(B)) * B), 2 * sz(B));
56-
return modK(B, sz(A));
53+
poly B = poly({num(1) / A[0]});
54+
while (sz(B) < sz(A))
55+
B = modK(B * (poly({num(2)}) - modK(A, 2*sz(B)) * B), 2 * sz(B));
56+
return modK(B, sz(A));
5757
}
5858
poly &operator/=(poly &a, poly b) {
59-
if (sz(a) < sz(b))
60-
return a = {};
61-
int s = sz(a) - sz(b) + 1;
62-
reverse(all(a)), reverse(all(b));
63-
a.resize(s), b.resize(s);
64-
a = a * inverse(b);
65-
a.resize(s), reverse(all(a));
66-
return a;
59+
if (sz(a) < sz(b))
60+
return a = {};
61+
int s = sz(a) - sz(b) + 1;
62+
reverse(all(a)), reverse(all(b));
63+
a.resize(s), b.resize(s);
64+
a = a * inverse(b);
65+
a.resize(s), reverse(all(a));
66+
return a;
6767
}
6868
OP(/, /=)
6969
poly &operator%=(poly &a, poly &b) {
70-
if (sz(a) < sz(b))
71-
return a;
72-
poly c = (a / b) * b;
73-
a.resize(sz(b) - 1);
74-
rep(i, 0, sz(a)) a[i] = a[i] - c[i];
75-
return a;
70+
if (sz(a) < sz(b))
71+
return a;
72+
poly c = (a / b) * b;
73+
a.resize(sz(b) - 1);
74+
rep(i, 0, sz(a)) a[i] = a[i] - c[i];
75+
return a;
7676
}
7777
OP(%, %=)
7878
poly deriv(poly a) {
79-
if (a.empty())
80-
return {};
81-
poly b(sz(a) - 1);
82-
rep(i, 1, sz(a)) b[i - 1] = a[i] * num(i);
83-
return b;
79+
if (a.empty())
80+
return {};
81+
poly b(sz(a) - 1);
82+
rep(i, 1, sz(a)) b[i - 1] = a[i] * num(i);
83+
return b;
8484
}
8585
poly integr(poly a) {
86-
if (a.empty()) return {0};
87-
poly b(sz(a) + 1);
88-
b[1] = num(1);
89-
rep(i, 2, sz(b)) b[i] = b[mod%i]*Mod(-mod/i+mod);
90-
rep(i, 1 ,sz(b)) b[i] = a[i-1] * b[i];
91-
return b;
86+
if (a.empty()) return {0};
87+
poly b(sz(a) + 1);
88+
b[1] = num(1);
89+
rep(i, 2, sz(b)) b[i] = b[mod%i]*Mod(-mod/i+mod);
90+
rep(i, 1 ,sz(b)) b[i] = a[i-1] * b[i];
91+
return b;
9292
}
9393
poly log(poly a) { return modK(integr(deriv(a) * inverse(a)), sz(a)); }
9494
poly exp(poly a) {
95-
poly b(1, num(1));
96-
if (a.empty())
97-
return b;
98-
while (sz(b) < sz(a)) {
99-
b.resize(sz(b) * 2);
100-
b *= (poly({num(1)}) + modK(a, sz(b)) - log(b));
101-
b.resize(sz(b) / 2 + 1);
102-
}
103-
return modK(b, sz(a));
95+
poly b(1, num(1));
96+
if (a.empty())
97+
return b;
98+
while (sz(b) < sz(a)) {
99+
b.resize(sz(b) * 2);
100+
b *= (poly({num(1)}) + modK(a, sz(b)) - log(b));
101+
b.resize(sz(b) / 2 + 1);
102+
}
103+
return modK(b, sz(a));
104104
}
105105
poly pow(poly a, ll m) {
106-
int p = 0, n = sz(a);
107-
while (p < sz(a) && a[p].x == 0)
108-
++p;
109-
if (ll(m)*p >= sz(a)) return poly(sz(a));
110-
num j = a[p];
111-
a = {a.begin() + p, a.end()};
112-
a = a * (num(1) / j);
113-
a.resize(n);
114-
auto res = exp(log(a) * num(m)) * (j ^ m);
115-
res.insert(res.begin(), p*m, 0);
116-
return modK(res, n);
106+
int p = 0, n = sz(a);
107+
while (p < sz(a) && a[p].x == 0)
108+
++p;
109+
if (ll(m)*p >= sz(a)) return poly(sz(a));
110+
num j = a[p];
111+
a = {a.begin() + p, a.end()};
112+
a = a * (num(1) / j);
113+
a.resize(n);
114+
auto res = exp(log(a) * num(m)) * (j ^ m);
115+
res.insert(res.begin(), p*m, 0);
116+
return modK(res, n);
117117
}
118118

119119
vector<num> eval(const poly &a, const vector<num> &x) {
120-
int n = sz(x);
121-
if (!n) return {};
122-
vector<poly> up(2 * n);
123-
rep(i, 0, n) up[i + n] = poly({num(0) - x[i], 1});
124-
for (int i = n - 1; i > 0; i--)
125-
up[i] = up[2 * i] * up[2 * i + 1];
126-
vector<poly> down(2 * n);
127-
down[1] = a % up[1];
128-
rep(i, 2, 2 * n) down[i] = down[i / 2] % up[i];
129-
vector<num> y(n);
130-
rep(i, 0, n) y[i] = down[i + n][0];
131-
return y;
120+
int n = sz(x);
121+
if (!n) return {};
122+
vector<poly> up(2 * n);
123+
rep(i, 0, n) up[i + n] = poly({num(0) - x[i], 1});
124+
for (int i = n - 1; i > 0; i--)
125+
up[i] = up[2 * i] * up[2 * i + 1];
126+
vector<poly> down(2 * n);
127+
down[1] = a % up[1];
128+
rep(i, 2, 2 * n) down[i] = down[i / 2] % up[i];
129+
vector<num> y(n);
130+
rep(i, 0, n) y[i] = down[i + n][0];
131+
return y;
132132
}
133133

134134
poly interp(vector<num> x, vector<num> y) {

content/numerical/chapter.tex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
\chapter{Numerical}
22

33
\kactlimport{GoldenSectionSearch.h}
4-
\kactlimport{Polynomial.h}
4+
\kactlimport{FFTPolynomial.h}
55
\kactlimport{PolyRoots.h}
6-
\kactlimport{PolyInterpolate.h}
76
\kactlimport{BerlekampMassey.h}
87
\kactlimport{LinearRecurrence.h}
98
\kactlimport{HillClimbing.h}

0 commit comments

Comments
 (0)