18 const std::vector<int64_t>&
a,
19 const std::vector<int64_t>&
b,
20 const std::vector<int64_t>& f,
23 if (
a.empty() ||
b.empty()) {
26 size_t prod_size =
a.size() +
b.size() - 1;
27 std::vector<int64_t> product(prod_size, 0);
29 for (
size_t i = 0; i <
a.size(); ++i) {
30 if (
a[i] == 0)
continue;
31 for (
size_t j = 0; j <
b.size(); ++j) {
32 product[i + j] = (product[i + j] +
a[i] *
b[j]) % p;
33 if (product[i + j] < 0) product[i + j] += p;
37 std::vector<int64_t> q,
r;
56 const std::vector<int64_t>& base,
58 const std::vector<int64_t>& f,
66 std::vector<int64_t> q,
r;
70 std::vector<int64_t> result = {1};
71 std::vector<int64_t> cur = base;
73 std::vector<int64_t> q,
r;
107 const std::vector<int64_t>& f,
110 int n =
static_cast<int>(f.size()) - 1;
112 std::vector<std::vector<int64_t>> Q(n, std::vector<int64_t>(n, 0));
122 std::vector<int64_t> x_poly = {0, 1};
124 for (
size_t j = 0; j < h.size() && j <
static_cast<size_t>(n); ++j) {
127 std::vector<int64_t> current = h;
128 for (
int i = 2; i < n; ++i) {
130 for (
size_t j = 0; j < current.size() && j <
static_cast<size_t>(n); ++j) {
131 Q[i][j] = current[j];
139 int current_row,
int col, int64_t p) {
140 const int n =
static_cast<int>(matrix.size());
142 for (
int j = 0; j < n; ++j) {
143 matrix[current_row][j] = (matrix[current_row][j] * inverse) % p;
145 for (
int row = 0; row < n; ++row) {
146 if (row == current_row)
continue;
147 int64_t factor = matrix[row][col];
148 if (factor == 0)
continue;
149 for (
int j = 0; j < n; ++j) {
151 (matrix[row][j] - factor * matrix[current_row][j] % p + p) % p;
157 std::vector<int>& pivot_col, std::vector<int>& pivot_row) {
158 const int n =
static_cast<int>(M.size());
160 for (
int col = 0; col < n && current_row < n; ++col) {
162 for (
int row = current_row; row < n; ++row) {
163 if (M[row][col] != 0) {
173 if (pivot != current_row) {
174 std::swap(M[pivot], M[current_row]);
177 pivot_col[current_row] = col;
178 pivot_row[col] = current_row;
185 const std::vector<std::vector<int64_t>>& Q,
188 int n =
static_cast<int>(Q.size());
192 std::vector<std::vector<int64_t>> M(n, std::vector<int64_t>(n, 0));
193 for (
int i = 0; i < n; ++i) {
194 for (
int j = 0; j < n; ++j) {
195 int64_t val = Q[j][i];
197 val = (val - 1 + p) % p;
202 std::vector<int> pivot_col(n, -1);
203 std::vector<int> pivot_row(n, -1);
206 std::vector<std::vector<int64_t>>
basis;
208 for (
int col = 0; col < n; ++col) {
209 if (pivot_row[col] != -1) {
213 std::vector<int64_t> vec(n, 0);
216 for (
int row = 0; row < n; ++row) {
217 int pc = pivot_col[row];
218 if (pc == -1)
continue;
224 vec[pc] = (p - M[row][col]) % p;
227 basis.push_back(std::move(vec));
int64_t bk_mod_inverse(int64_t a, int64_t p)
模 p 下求乘法逆元.
std::vector< std::vector< int64_t > > bk_build_q_matrix(const std::vector< int64_t > &f, int64_t p)
构造 F_p 上的 Berlekamp 矩阵 Q。
static void bk_eliminate_column(std::vector< std::vector< int64_t > > &matrix, int current_row, int col, int64_t p)
void bk_div_mod(const std::vector< int64_t > &a, const std::vector< int64_t > &b, int64_t p, std::vector< int64_t > &q, std::vector< int64_t > &r)
模 p 多项式带余除法.
static std::vector< int64_t > bk_poly_mul_mod(const std::vector< int64_t > &a, const std::vector< int64_t > &b, const std::vector< int64_t > &f, int64_t p)
在 F_p 上计算 a(x) * b(x) mod f(x)。
std::vector< std::vector< int64_t > > bk_null_space(const std::vector< std::vector< int64_t > > &Q, int64_t p)
static void bk_reduce_matrix(std::vector< std::vector< int64_t > > &M, int64_t p, std::vector< int > &pivot_col, std::vector< int > &pivot_row)
static std::vector< int64_t > bk_poly_pow_mod(const std::vector< int64_t > &base, int64_t exp, const std::vector< int64_t > &f, int64_t p)
在 F_p 上用平方乘法计算 base^exp mod f(x)。
ExprResult exp(const ExprPtr &expression, ComputationContext &context)
__attribute__((visibility("default"))) ComplexSymbolicResult complex_exp_form_checked(std __attribute__((visibility("default"))) ComplexSymbolicResult complex_exp_form_checked(std __attribute__((visibility("default"))) ComplexSymbolicResult complex_trig_form_checked(std __attribute__((visibility("default"))) ComplexSymbolicResult complex_trig_form_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_nth_root_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_nth_root_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_quadratic_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_quadratic_checked(std std::shared_ptr< SymbolicExpr > r
__attribute__((visibility("default"))) VectorCalculusExprResult curve_integral_scalar_checked(const std __attribute__((visibility("default"))) VectorCalculusExprResult curve_integral_scalar_checked(const std __attribute__((visibility("default"))) std const VectorField const std::string const std::shared_ptr< SymbolicExpr > & a
const std::vector< FGLMPoly > & basis