Skip to content

Commit 640a997

Browse files
committed
Split out inverse.h
1 parent a4616a9 commit 640a997

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

content/numerical/PolyBase.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,4 @@ poly operator*(poly a, const num b) {
4444
poly c = a; \
4545
return c o##= b; \
4646
}
47-
OP(*, *=) OP(+, +=) OP(-, -=);
48-
poly modK(poly a, int k) { return {a.begin(), a.begin() + min(k, sz(a))}; }
49-
poly inverse(poly A) {
50-
poly B = poly({num(1) / A[0]});
51-
while (sz(B) < sz(A))
52-
B = modK(B * (poly({num(2)}) - modK(A, 2*sz(B)) * B), 2 * sz(B));
53-
return modK(B, sz(A));
54-
}
47+
OP(*, *=) OP(+, +=) OP(-, -=);

content/numerical/PolyInverse.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Author: chilli, Andrew He, Adamant
3+
* Date: 2019-04-27
4+
* Description: A FFT based Polynomial class.
5+
*/
6+
#pragma once
7+
8+
#include "PolyBase.h"
9+
10+
poly modK(poly a, int k) { return {a.begin(), a.begin() + min(k, sz(a))}; }
11+
poly inverse(poly A) {
12+
poly B = poly({num(1) / A[0]});
13+
while (sz(B) < sz(A))
14+
B = modK(B * (poly({num(2)}) - modK(A, 2*sz(B)) * B), 2 * sz(B));
15+
return modK(B, sz(A));
16+
}

content/numerical/PolyLogExp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#pragma once
77

88
#include "PolyBase.h"
9+
#include "PolyInverse.h"
910
#include "PolyIntegDeriv.h"
1011

1112
poly log(poly a) {

content/numerical/PolyPow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ poly pow(poly a, ll m) {
1919
a.resize(n);
2020
auto res = exp(log(a) * num(m)) * (j ^ m);
2121
res.insert(res.begin(), p*m, 0);
22-
return modK(res, n);
22+
return {res.begin(), res.begin()+n};
2323
}

fuzz-tests/numerical/Polynomial.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ template <class A, class B> void testPow(string name, A f1, B f2, int mxSz = 5,
537537
}
538538
cout << name + " tests passed!" << endl;
539539
auto a = genVec((rand() % mxSz) + 1);
540-
int p = mxSz;
540+
int p = mxSz/2;
541541
{
542542
timeit x("mine");
543543
for (int it = 0; it < NUMITERS; it++) {
@@ -612,18 +612,18 @@ signed main() {
612612
ios::sync_with_stdio(0);
613613
cin.tie(0);
614614
int SZ = 100000;
615-
testBinary("sub", mine::operator-, MIT::operator-, SZ);
616-
testBinary("add", mine::operator+, MIT::operator+, SZ);
617-
testBinary("div", mine::operator/, MIT::operator/, SZ);
618-
testBinary("mod", mine::operator%, MIT::operator%, SZ);
619-
testUnary("inv", mine::inverse, MIT::inverse, SZ);
620-
testUnary("derivative", mine::deriv, MIT::deriv, SZ);
621-
testUnary("integral", mine::integr, MIT::integ, SZ);
622-
testUnary("log", mine::log, MIT::log, SZ);
623-
testUnary("exp", mine::exp, MIT::exp, SZ);
615+
// testBinary("sub", mine::operator-, MIT::operator-, SZ);
616+
// testBinary("add", mine::operator+, MIT::operator+, SZ);
617+
// testBinary("div", mine::operator/, MIT::operator/, SZ);
618+
// testBinary("mod", mine::operator%, MIT::operator%, SZ);
619+
// testUnary("inv", mine::inverse, MIT::inverse, SZ);
620+
// testUnary("derivative", mine::deriv, MIT::deriv, SZ);
621+
// testUnary("integral", mine::integr, MIT::integ, SZ);
622+
// testUnary("log", mine::log, MIT::log, SZ);
623+
// testUnary("exp", mine::exp, MIT::exp, SZ);
624624
SZ = 10000;
625625
testPow("pow", mine::pow, MIT::pow, SZ, 5);
626-
testEval("eval", mine::eval, MIT::eval, SZ);
627-
testInterp("interp", mine::interp, MIT::interp, SZ);
626+
// testEval("eval", mine::eval, MIT::eval, SZ);
627+
// testInterp("interp", mine::interp, MIT::interp, SZ);
628628
return 0;
629629
}

0 commit comments

Comments
 (0)