Macaulay2 Engine
Loading...
Searching...
No Matches
freemodule.cpp
Go to the documentation of this file.
1// Copyright 1995 Michael E. Stillman
2
4
5#include "buffer.hpp"
6#include "error.h"
7#include "exceptions.hpp"
8#include "freemod.hpp"
9#include "monoid.hpp"
10#include "newdelete.hpp"
11#include "ring.hpp"
12
13class Matrix;
14
15const Ring *IM2_FreeModule_ring(const FreeModule *F) { return F->get_ring(); }
16int IM2_FreeModule_rank(const FreeModule *F) { return F->rank(); }
18{
19 buffer o;
20 F->text_out(o);
21 return o.to_string();
22}
23
24unsigned int rawFreeModuleHash(const FreeModule *F) { return F->hash(); }
25const FreeModule /* or null */ *IM2_FreeModule_make(const Ring *R, int rank)
26{
27 try
28 {
29 if (rank < 0)
30 {
31 ERROR("freemodule rank must be non-negative");
32 return nullptr;
33 }
34 return R->make_FreeModule(rank);
35 } catch (const exc::engine_error& e)
36 {
37 ERROR(e.what());
38 return nullptr;
39 }
40}
41
42const FreeModule /* or null */ *IM2_FreeModule_make_degs(const Ring *R,
43 M2_arrayint degs)
44{
45 try
46 {
47 auto D = R->degree_monoid();
48 unsigned int eachdeg = D->n_vars();
49 if (eachdeg == 0)
50 {
51 ERROR("rawFreeModule: degree rank 0, but sequence of degrees given");
52 return nullptr;
53 }
54 unsigned int rank = degs->len / eachdeg;
55 if (rank * eachdeg != degs->len)
56 {
57 ERROR("inappropriate number of degrees");
58 return nullptr;
59 }
60 monomial deg = D->make_one();
62 for (unsigned int i = 0; i < rank; i++)
63 {
64 D->from_expvector(degs->array + i * eachdeg, deg);
65 F->append(deg);
66 }
67 return F;
68 } catch (const exc::engine_error& e)
69 {
70 ERROR(e.what());
71 return nullptr;
72 }
73}
74
75const FreeModule /* or null */ *IM2_FreeModule_make_schreyer(const Matrix *m)
76{
77 try
78 {
80 } catch (const exc::engine_error& e)
81 {
82 ERROR(e.what());
83 return nullptr;
84 }
85}
86
88{
89 auto D = F->get_ring()->degree_monoid();
90 auto n = D->n_vars();
91 auto r = F->rank();
93 for (int i = 0; i < r; i++)
94 D->to_expvector(F->degree(i), result->array + i * n);
95 return result;
96}
97
99{
100 return F->get_induced_order();
101}
102
104/* Determines if F and G are the same graded module. If one has a
105 Schreyer order and one does not, but their ranks and degrees are the
106 same, then they are considered equal by this routine. */
107{
108 return F->is_equal(G);
109}
110
111const FreeModule /* or null */ *IM2_FreeModule_sum(const FreeModule *F,
112 const FreeModule *G)
113{
114 return F->direct_sum(G);
115}
116
117const FreeModule /* or null */ *IM2_FreeModule_tensor(const FreeModule *F,
118 const FreeModule *G)
119{
120 try
121 {
122 return F->tensor(G);
123 } catch (const exc::engine_error& e)
124 {
125 ERROR(e.what());
126 return nullptr;
127 }
128}
129
130const FreeModule /* or null */ *IM2_FreeModule_dual(const FreeModule *F)
131{
132 try
133 {
134 return F->transpose();
135 } catch (const exc::engine_error& e)
136 {
137 ERROR(e.what());
138 return nullptr;
139 }
140}
141
143{
144 try
145 {
146 return F->symm(n);
147 } catch (const exc::engine_error& e)
148 {
149 ERROR(e.what());
150 return nullptr;
151 }
152}
153
155{
156 try
157 {
158 return F->exterior(n);
159 } catch (const exc::engine_error& e)
160 {
161 ERROR(e.what());
162 return nullptr;
163 }
164}
165
167 M2_arrayint selection)
168{
169 try
170 {
171 return F->sub_space(selection);
172 } catch (const exc::engine_error& e)
173 {
174 ERROR(e.what());
175 return nullptr;
176 }
177}
178
180 M2_arrayint lo,
181 M2_arrayint hi)
182{
183 try
184 {
185 return F->select_by_degrees(lo, hi);
186 } catch (const exc::engine_error& e)
187 {
188 ERROR(e.what());
189 return nullptr;
190 }
191}
192
193// Local Variables:
194// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
195// indent-tabs-mode: nil
196// End:
Append-only GC-backed byte buffer used throughout the engine for text output.
unsigned int hash() const
Definition hash.hpp:70
FreeModule * transpose() const
Definition freemod.cpp:227
M2_arrayintOrNull select_by_degrees(M2_arrayintOrNull lo, M2_arrayintOrNull hi) const
Definition freemod.cpp:415
FreeModule * tensor(const FreeModule *G) const
Definition freemod.cpp:271
const Ring * get_ring() const
Definition freemod.hpp:102
const_monomial degree(int i) const
Definition freemod.hpp:104
void append(const_monomial d)
Definition freemod.cpp:130
FreeModule * exterior(int p) const
Definition freemod.cpp:296
FreeModule * symm(int p) const
Definition freemod.cpp:395
bool is_equal(const FreeModule *F) const
Definition freemod.cpp:154
Matrix * get_induced_order() const
Definition freemod.cpp:100
FreeModule * sub_space(int n) const
Definition freemod.cpp:197
FreeModule * direct_sum(const FreeModule *G) const
Definition freemod.cpp:244
int rank() const
Definition freemod.hpp:105
static FreeModule * make_schreyer(const Matrix *m)
Definition freemod.cpp:53
void text_out(buffer &o) const
Definition freemod.cpp:471
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
int n_vars() const
Definition monoid.hpp:207
virtual FreeModule * make_FreeModule() const
Definition ring.cpp:53
const Monoid * degree_monoid() const
Definition ring.cpp:13
xxx xxx xxx
Definition ring.hpp:102
M2_string to_string()
Definition buffer.cpp:20
Engine error-reporting primitives: ERROR, INTERNAL_ERROR, error, error_message.
namespace exc — internal C++ exception types and the TRY / CATCH macro pair.
#define Matrix
Definition factory.cpp:14
FreeModule — finite-rank free module R^n, the type-level anchor for every Matrix.
const Ring * IM2_FreeModule_ring(const FreeModule *F)
unsigned int rawFreeModuleHash(const FreeModule *F)
M2_bool IM2_FreeModule_is_equal(const FreeModule *F, const FreeModule *G)
const FreeModule * IM2_FreeModule_tensor(const FreeModule *F, const FreeModule *G)
const FreeModule * IM2_FreeModule_symm(int n, const FreeModule *F)
const Matrix * IM2_FreeModule_get_schreyer(const FreeModule *F)
const FreeModule * IM2_FreeModule_exterior(int n, const FreeModule *F)
const FreeModule * IM2_FreeModule_submodule(const FreeModule *F, M2_arrayint selection)
const FreeModule * IM2_FreeModule_sum(const FreeModule *F, const FreeModule *G)
const FreeModule * IM2_FreeModule_dual(const FreeModule *F)
int IM2_FreeModule_rank(const FreeModule *F)
M2_arrayintOrNull rawFreeModuleSelectByDegrees(const FreeModule *F, M2_arrayint lo, M2_arrayint hi)
const FreeModule * IM2_FreeModule_make(const Ring *R, int rank)
const FreeModule * IM2_FreeModule_make_degs(const Ring *R, M2_arrayint degs)
M2_string IM2_FreeModule_to_string(const FreeModule *F)
M2_arrayint IM2_FreeModule_get_degrees(const FreeModule *F)
const FreeModule * IM2_FreeModule_make_schreyer(const Matrix *m)
Engine-boundary C API for constructing and querying FreeModules.
#define monomial
Definition gb-toric.cpp:11
const int ERROR
Definition m2-mem.cpp:55
VALGRIND_MAKE_MEM_DEFINED & result(result)
M2_arrayint M2_makearrayint(int n)
Definition m2-types.cpp:6
M2_arrayint M2_arrayintOrNull
Definition m2-types.h:99
char M2_bool
Definition m2-types.h:82
Monoid — variable count, naming, grading, and monomial order of a polynomial ring.
our_new_delete — per-class opt-in routing of new / delete through bdwgc.
tbb::flow::graph G
Ring — the legacy abstract base class for every coefficient and polynomial ring.