LMCAS
Lamina Computer Algebra System
Toggle main menu visibility
载入中...
搜索中...
未找到
fglm_linear.cpp
浏览该文件的文档.
1
#include "
internal/fglm_internal.hpp
"
2
#include <algorithm>
3
4
namespace
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
13
bool
MonomialEnumerator::next
(
Monomial
& out) {
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
30
void
MonomialEnumerator::push
(
const
Monomial
& m) {
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);
98
++
basis_count_
;
99
100
return
true
;
101
}
102
103
}
LMCAS::MonomialOrder
单项式序比较器,支持 Lex、GrevLex、DegLex、DegRevLex
定义
monomial_order.hpp:67
LMCAS::fglm_detail::GaussianEliminator::rows_
std::vector< std::vector< Rational > > rows_
定义
fglm_internal.hpp:36
LMCAS::fglm_detail::GaussianEliminator::basis_count_
size_t basis_count_
定义
fglm_internal.hpp:39
LMCAS::fglm_detail::GaussianEliminator::add_vector
bool add_vector(const std::vector< Rational > &vector, std::vector< Rational > &combination)
定义
fglm_linear.cpp:37
LMCAS::fglm_detail::GaussianEliminator::pivots_
std::vector< size_t > pivots_
定义
fglm_internal.hpp:37
LMCAS::fglm_detail::GaussianEliminator::combinations_
std::vector< std::vector< Rational > > combinations_
定义
fglm_internal.hpp:38
LMCAS::fglm_detail::MonomialEnumerator::push
void push(const Monomial &monomial)
定义
fglm_linear.cpp:30
LMCAS::fglm_detail::MonomialEnumerator::next
bool next(Monomial &out)
定义
fglm_linear.cpp:13
LMCAS::fglm_detail::MonomialEnumerator::MonomialEnumerator
MonomialEnumerator(size_t num_vars, const MonomialOrder &order, int max_degree)
定义
fglm_linear.cpp:6
LMCAS::fglm_detail::MonomialEnumerator::max_degree_
int max_degree_
定义
fglm_internal.hpp:23
LMCAS::fglm_detail::MonomialEnumerator::heap_
std::vector< Monomial > heap_
定义
fglm_internal.hpp:24
LMCAS::fglm_detail::MonomialEnumerator::order_
MonomialOrder order_
定义
fglm_internal.hpp:22
LMCAS::fglm_detail::MonomialEnumerator::num_vars_
size_t num_vars_
定义
fglm_internal.hpp:21
LMCAS::fglm_detail::MonomialEnumerator::visited_
std::set< Monomial > visited_
定义
fglm_internal.hpp:25
LMCAS::fglm_detail::MonomialEnumerator::cmp_
HeapCmp cmp_
定义
fglm_internal.hpp:26
fglm_internal.hpp
LMCAS::fglm_detail
定义
fglm_dimension.cpp:3
LMCAS::Monomial
std::vector< int > Monomial
单项式类型,以整数向量表示各变量的指数
定义
monomial_order.hpp:15
LMCAS::v
__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
定义
vector_calculus_surfaces.hpp:59
LMCAS::order
const std::vector< FGLMPoly > const MonomialOrder & order
定义
fglm.hpp:103
LMCAS::c
const VectorField const VectorField & c
定义
vector_calculus_vectors.hpp:60
LMCAS::total_degree
int total_degree(const Monomial &m)
计算单项式的全次数
定义
monomial_order.hpp:30
src
fglm_linear.cpp
生成于
, 为 LMCAS使用
1.18.0