Macaulay2 Engine
Loading...
Searching...
No Matches
gbweight.cpp
Go to the documentation of this file.
1#include "gbweight.hpp"
2#include "freemod.hpp"
3#include "gbring.hpp"
4#include "polyring.hpp"
5
6
8{
9 // If wts has length 0 or is NULL:
10 // Use the primary degrees, if they are positive.
11 // For each that is negative, use "1"
12
13 // If the wt vector is not part of the degrees, then set
14 // use_component_degrees to false.
15
16 const PolynomialRing *A = F->get_ring()->cast_to_PolynomialRing();
17 assert(A != 0);
18 R_ = A->get_gb_ring();
19
20 const Monoid *M = R_->get_flattened_monoid();
21 nvars_ = R_->n_vars();
22
24
25 if (!wts0 || wts0->len != nvars_)
26 {
28 for (int i = 0; i < nvars_; i++)
29 {
30 int d = M->primary_degree_of_var(i);
31 wts_->array[i] = (d > 0 ? d : 1);
32 if (d <= 0) use_component_degrees_ = false;
33 }
34 }
35 else
36 {
37 // Use the provided wt vector
39 for (int i = 0; i < nvars_; i++)
40 {
41 int d = wts0->array[i];
42 wts_->array[i] = (d > 0 ? d : 1);
43 }
44 }
45
47
49 {
50 Fdegs_ = newarray_atomic(long, F->rank() + 1);
51 Fdegs_[0] = 0;
52 for (int j = 0; j < F->rank(); j++) Fdegs_[j + 1] = F->primary_degree(j);
53 }
54 else
55 Fdegs_ = nullptr;
56}
57
59{
60 int sum = exponents::weight(nvars_, e, wts_);
61 if (use_component_degrees_ && comp > 0) sum += Fdegs_[comp];
62 return sum;
63}
64
66{
67 if (f == nullptr) return 0;
69 R_->gbvector_get_lead_exponents(F_, f, EXP);
70 return exponents_weight(EXP, f->comp);
71}
72
73int GBWeight::gbvector_weight(const gbvector *f, int &initial_term_weight) const
74{
75 /* Return the maximum degree of any term of f */
76
77 if (f == nullptr)
78 {
79 initial_term_weight = 0;
80 return 0;
81 }
82 int deg = gbvector_term_weight(f);
83 initial_term_weight = deg;
84 for (const gbvector *t = f->next; t != nullptr; t = t->next)
85 {
86 int tdeg = gbvector_term_weight(t);
87 if (tdeg > deg) deg = tdeg;
88 }
89
90 return deg;
91}
92
94{
95 int not_used;
96 return gbvector_weight(f, not_used);
97}
98
99int GBWeight::monomial_weight(const_monomial monom, int comp) const
100{
102 R_->get_flattened_monoid()->to_expvector(monom, EXP);
103 return exponents_weight(EXP, comp);
104}
105
106// Local Variables:
107// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
108// indent-tabs-mode: nil
109// End:
exponents::ConstExponents const_exponents
exponents::Exponents exponents_t
static Exponent weight(int nvars, ConstExponents a, const std::vector< Exponent > &wts)
const Ring * get_ring() const
Definition freemod.hpp:102
int primary_degree(int i) const
Definition freemod.cpp:440
int rank() const
Definition freemod.hpp:105
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
int gbvector_term_weight(const gbvector *f) const
Definition gbweight.cpp:65
int monomial_weight(const_monomial m, int comp) const
Definition gbweight.cpp:99
GBRing * R_
Definition gbweight.hpp:73
M2_arrayint wts_
Definition gbweight.hpp:68
bool use_component_degrees_
Definition gbweight.hpp:69
const FreeModule * F_
Definition gbweight.hpp:70
size_t exp_size
Definition gbweight.hpp:75
int gbvector_weight(const gbvector *f) const
Definition gbweight.cpp:93
int nvars_
Definition gbweight.hpp:72
GBWeight(const FreeModule *F, M2_arrayint wts)
Definition gbweight.cpp:7
long * Fdegs_
Definition gbweight.hpp:76
int exponents_weight(const_exponents e, int comp) const
Definition gbweight.cpp:58
int primary_degree_of_var(int v) const
Definition monoid.hpp:177
Engine-side commutative monomial monoid: variable names, ordering, multidegree machinery,...
Definition monoid.hpp:89
virtual GBRing * get_gb_ring() const
Definition polyring.hpp:276
Abstract base for the engine's polynomial-ring hierarchy.
Definition polyring.hpp:96
FreeModule — finite-rank free module R^n, the type-level anchor for every Matrix.
GBRing and gbvector — the GB-tuned polynomial-ring view used by classical Buchberger code.
GBWeight — packed-weight evaluator that drives S-pair selection.
const int * const_monomial
Definition imonorder.hpp:45
M2_arrayint M2_makearrayint(int n)
Definition m2-types.cpp:6
#define ALLOCATE_EXPONENTS(byte_len)
Definition monoid.hpp:62
#define EXPONENT_BYTE_SIZE(nvars)
Definition monoid.hpp:63
#define newarray_atomic(T, len)
Definition newdelete.hpp:91
PolynomialRing — abstract polynomial-ring base, the engine's most-reused class.
gbvector * next
Definition gbring.hpp:80
int comp
Definition gbring.hpp:82