LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
fglm_linear.cpp
浏览该文件的文档.
2#include <algorithm>
3
4namespace LMCAS::fglm_detail {
5
6 MonomialEnumerator::MonomialEnumerator(size_t num_vars, const MonomialOrder& order, int max_deg)
7 : num_vars_(num_vars), order_(order), max_degree_(max_deg) {
8
9 Monomial one(num_vars, 0);
10 push(one);
11 }
12
14 if (heap_.empty()) return false;
15 out = heap_.front();
16 std::pop_heap(heap_.begin(), heap_.end(), cmp_);
17 heap_.pop_back();
18
19 int out_deg = total_degree(out);
20 if (out_deg < max_degree_) {
21 for (size_t i = 0; i < num_vars_; ++i) {
22 Monomial succ = out;
23 succ[i] += 1;
24 push(succ);
25 }
26 }
27 return true;
28 }
29
31 if (visited_.count(m)) return;
32 visited_.insert(m);
33 heap_.push_back(m);
34 std::push_heap(heap_.begin(), heap_.end(), cmp_);
35 }
36
37 bool GaussianEliminator::add_vector(const std::vector<Rational>& v,
38 std::vector<Rational>& combination) {
39 size_t n = v.size();
40
41 for (auto& row : rows_) {
42 row.resize(n, Rational(0));
43 }
44
45 std::vector<Rational> working = v;
46
47 combination.assign(basis_count_, Rational(0));
48
49 for (size_t i = 0; i < pivots_.size(); ++i) {
50 size_t col = pivots_[i];
51 if (col >= working.size()) continue;
52 if (working[col].is_zero()) continue;
53
54 Rational factor = working[col] / rows_[i][col];
55 for (size_t j = 0; j < n; ++j) {
56 if (j < working.size() && j < rows_[i].size()) {
57 working[j] = working[j] - factor * rows_[i][j];
58 }
59 }
60
61 for (size_t j = 0; j < combinations_[i].size(); ++j) {
62 combination[j] =
63 combination[j] - factor * combinations_[i][j];
64 }
65 }
66
67 size_t pivot_col = n;
68 for (size_t j = 0; j < n; ++j) {
69 if (!working[j].is_zero()) {
70 pivot_col = j;
71 break;
72 }
73 }
74
75 if (pivot_col == n) {
76
77 for (auto& c : combination) {
78 c = -c;
79 }
80 return false;
81 }
82
83 Rational pivot_val = working[pivot_col];
84 for (size_t j = 0; j < n; ++j) {
85 working[j] = working[j] / pivot_val;
86 }
87
88 std::vector<Rational> comb_row(basis_count_ + 1, Rational(0));
89 for (size_t j = 0; j < combination.size(); ++j) {
90 comb_row[j] = combination[j] / pivot_val;
91 }
92
93 comb_row[basis_count_] = Rational(1) / pivot_val;
94
95 rows_.push_back(working);
96 pivots_.push_back(pivot_col);
97 combinations_.push_back(comb_row);
99
100 return true;
101 }
102
103}
单项式序比较器,支持 Lex、GrevLex、DegLex、DegRevLex
std::vector< std::vector< Rational > > rows_
bool add_vector(const std::vector< Rational > &vector, std::vector< Rational > &combination)
std::vector< std::vector< Rational > > combinations_
void push(const Monomial &monomial)
MonomialEnumerator(size_t num_vars, const MonomialOrder &order, int max_degree)
std::vector< int > Monomial
单项式类型,以整数向量表示各变量的指数
__attribute__((visibility("default"))) VectorCalculusExprResult surface_integral_scalar_checked(const std __attribute__((visibility("default"))) VectorCalculusExprResult surface_integral_scalar_checked(const std __attribute__((visibility("default"))) std const VectorField const std::string const std::string & v
const std::vector< FGLMPoly > const MonomialOrder & order
const VectorField const VectorField & c
int total_degree(const Monomial &m)
计算单项式的全次数