Skip to content

Commit e24a287

Browse files
committed
Factor out frobenius_pow from test to frobenius.hpp
1 parent 0440f37 commit e24a287

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

cp-algo/linalg/frobenius.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define CP_ALGO_LINALG_FROBENIUS_HPP
33
#include "matrix.hpp"
44
#include "../algebra/poly.hpp"
5+
#include <algorithm>
56
#include <vector>
67
namespace cp_algo::linalg {
78
enum frobenius_mode {blocks, full};
@@ -72,5 +73,23 @@ namespace cp_algo::linalg {
7273
return charps;
7374
}
7475
}
76+
77+
template<typename base>
78+
auto frobenius_pow(matrix<base> A, uint64_t k) {
79+
using polyn = algebra::poly_t<base>;
80+
auto [T, Tinv, charps] = frobenius_form<full>(A);
81+
std::vector<matrix<base>> blocks;
82+
for(auto charp: charps) {
83+
matrix<base> block(charp.deg());
84+
auto xk = polyn::xk(1).powmod(k, charp);
85+
for(size_t i = 0; i < block.n(); i++) {
86+
std::ranges::copy(xk.a, begin(block[i]));
87+
xk = xk.mul_xk(1) % charp;
88+
}
89+
blocks.push_back(block);
90+
}
91+
auto S = matrix<base>::block_diagonal(blocks);
92+
return Tinv * S * T;
93+
}
7594
};
7695
#endif // CP_ALGO_LINALG_FROBENIUS_HPP

verify/algebra/matrix/pow_fast.test.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,6 @@ const int mod = 998244353;
1313
using base = modular<mod>;
1414
using polyn = poly_t<base>;
1515

16-
template<typename base>
17-
auto frobenius_pow(matrix<base> A, uint64_t k) {
18-
using polyn = poly_t<base>;
19-
auto [T, Tinv, charps] = frobenius_form<full>(A);
20-
vector<matrix<base>> blocks;
21-
for(auto charp: charps) {
22-
matrix<base> block(charp.deg());
23-
auto xk = polyn::xk(1).powmod(k, charp);
24-
for(size_t i = 0; i < block.n(); i++) {
25-
ranges::copy(xk.a, begin(block[i]));
26-
xk = xk.mul_xk(1) % charp;
27-
}
28-
blocks.push_back(block);
29-
}
30-
auto S = matrix<base>::block_diagonal(blocks);
31-
return Tinv * S * T;
32-
}
33-
3416
void solve() {
3517
size_t n;
3618
uint64_t k;

0 commit comments

Comments
 (0)