Macaulay2 Engine
Loading...
Searching...
No Matches
matrix-symm.cpp
Go to the documentation of this file.
1
37
38#include "matrix.hpp"
39#include "matrix-con.hpp"
40
56{
57 public:
58 static Matrix /* or null */ *symmetricPower(const Matrix *m0, int p)
59 {
60 if (m0->n_rows() != 1)
61 {
62 ERROR("expected one row");
63 return nullptr;
64 }
65
66 SymmMatrix s(m0, p);
67 return s.value();
68 }
69
70 private:
72 const Ring *R;
73 int ncols;
74 const Matrix *m;
76
77 void symm1(vec f, // product so far generated
78 int lastn, // can use lastn..n_cols()-1 in product
79 int pow) // remaining power to take
80 {
81 if (pow == 0)
82 result.set_column(symm1_next++, f);
83 else
84 {
85 for (int i = lastn; i < ncols; i++)
86 {
87 ring_elem r = m->elem(0, i);
88 vec h = R->copy_vec(f);
89 R->mult_vec_to(h, r, false);
90 symm1(h, i, pow - 1);
91 }
92 R->remove_vec(f);
93 }
94 }
95
96 SymmMatrix(const Matrix *m0, int p)
97 : symm1_next(0), R(m0->get_ring()), ncols(m0->n_cols()), m(m0), result()
98 {
99 const FreeModule *Fp = m0->rows()->symm(p);
100 const FreeModule *Gp = m0->cols()->symm(p);
101
102 monomial dp = R->degree_monoid()->make_new(m->degree_shift());
103 R->degree_monoid()->power(dp, p, dp);
104
105 result = MatrixConstructor(Fp, Gp, dp);
106
107 if (p >= 0)
108 {
109 vec f = R->e_sub_i(0);
110 symm1(f, 0, p); // consumes f
111 }
112 }
113
114 Matrix *value() { return result.to_matrix(); }
115};
116
117Matrix /* or null */ *Matrix::symm(int n) const
118{
119 return SymmMatrix::symmetricPower(this, n);
120}
121
122#if 0
123//
124// namespace M2 {
125// Matrix /* or null */ *M2::symmetricPower(const Matrix *m, int p)
126// {
127// if (m->n_rows() != 1)
128// {
129// ERROR("expected one row");
130// return 0;
131// }
132//
133// SymmMatrix s(m,p);
134// return s.value();
135// }
136// };
137// class SymmMatrix
138// {
139// int symm1_next;
140// const Ring *R;
141// int ncols;
142// const Matrix *m;
143// MatrixConstructor result;
144//
145//
146// void symm1(vec f, // product so far generated
147// int lastn, // can use lastn..n_cols()-1 in product
148// int pow); // remaining power to take
149//
150// SymmMatrix(const Matrix *m, int p);
151// void compute();
152// Matrix * value();
153// public:
154// friend Matrix /* or null */ *M2::symmetricPower(const Matrix *m, int p);
155// static Matrix /* or null */ * symmetricPower(const Matrix *m, int p);
156// };
157//
158// void SymmMatrix::symm1(vec f, // product so far generated, consumed here
159// int lastn, // can use lastn..n_cols()-1 in product
160// int pow) // remaining power to take
161// {
162// if (pow == 0)
163// result.set_column(symm1_next++, f);
164// else
165// {
166// for (int i=lastn; i<ncols; i++)
167// {
168// ring_elem r = m->elem(0,i);
169// vec h = R->copy(f);
170// R->mult(h,r,false);
171// symm1(h, i, pow-1);
172// }
173// R->remove(f);
174// }
175// }
176//
177// SymmMatrix::SymmMatrix(const Matrix *m0, int p)
178// : symm1_next(0),
179// R(m0->get_ring()),
180// ncols(m0->n_cols()),
181// m(m0),
182// result()
183// {
184// const FreeModule *Fp = m0->rows()->symm(p);
185// const FreeModule *Gp = m0->cols()->symm(p);
186//
187// monomial dp = R->degree_monoid()->make_new(m->degree_shift());
188// R->degree_monoid()->power(dp, p, dp);
189//
190// result = MatrixConstructor(Fp,Gp,dp);
191//
192// if (p >= 0)
193// {
194// vec f = R->e_sub_i(0);
195// symm1(f, 0, p); // consumes f
196// }
197// }
198//
199// Matrix * SymmMatrix::value()
200// {
201// return result.to_matrix();
202// }
203//
204// Matrix /* or null */ * SymmMatrix::symmetricPower(const Matrix *m, int p)
205// {
206// if (m->n_rows() != 1)
207// {
208// ERROR("expected one row");
209// return 0;
210// }
211//
212// SymmMatrix s(m,p);
213// return s.value();
214// }
215//
216// namespace M2 {
217// Matrix /* or null */ *M2::symmetricPower(const Matrix *m, int p)
218// {
219// return SymmMatrix::symmetricPower(m,p);
220// }
221// };
222#endif
223// Local Variables:
224// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
225// indent-tabs-mode: nil
226// End:
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
Matrix(const FreeModule *rows, const FreeModule *cols, const_monomial degree_shift, VECTOR(vec) &entries)
Definition matrix.cpp:32
int n_rows() const
Definition matrix.hpp:146
Matrix * symm(int n) const
const FreeModule * rows() const
Definition matrix.hpp:144
const FreeModule * cols() const
Definition matrix.hpp:145
Mutable builder used to assemble an immutable Matrix one column (or one term) at a time.
xxx xxx xxx
Definition ring.hpp:102
void symm1(vec f, int lastn, int pow)
static Matrix * symmetricPower(const Matrix *m0, int p)
MatrixConstructor result
SymmMatrix(const Matrix *m0, int p)
const Matrix * m
Matrix * value()
const Ring * R
#define Matrix
Definition factory.cpp:14
#define monomial
Definition gb-toric.cpp:11
int p
void size_t s
Definition m2-mem.cpp:271
const int ERROR
Definition m2-mem.cpp:55
MatrixConstructor — the mutable builder that produces an immutable Matrix.
Matrix — the engine's immutable homomorphism F -> G between free modules.