27 F =
M->rows()->exterior(
p);
29 int *deg =
R->degree_monoid()->make_new(
M->degree_shift());
30 R->degree_monoid()->power(deg,
p, deg);
32 R->degree_monoid()->remove(deg);
36 F =
R->make_FreeModule(1);
51 result.set_entry(0, 0,
R->one());
53 result.append(
R->make_vec(0,
R->one()));
57 if (
p >
M->n_rows() ||
p >
M->n_cols())
68 for (
size_t i = 0; i <
p; i++)
75 for (
size_t i = 0; i <
p; i++)
89 for (
size_t i = 0; i <
p; i++)
freemem(
D[i]);
98 for (
int i = 0; i <
M->n_rows(); ++i)
101 for (
int j = 0; j <
M->n_cols(); ++j)
103 if (!
R->is_zero(
M->elem(i, j)))
116 for (
int minor_size = 1; minor_size <
p; ++minor_size)
118 for (
int top_row =
p - (minor_size + 1);
119 top_row <= n_nonzero_rows - minor_size;
133 for (
const auto &[Didx, Dval] : map)
136 const std::vector<int> &Dcols = Didx.second;
137 int xcol =
x.first.second[0];
139 std::find(Dcols.begin(), Dcols.end(), xcol);
140 if (col_find != Dcols.end())
146 newKey.first.insert(newKey.first.begin(),
149 auto xcol_position = std::upper_bound(
150 newKey.second.begin(), newKey.second.end(), xcol);
151 newKey.second.insert(xcol_position, xcol);
153 ((xcol_position - newKey.second.begin()) % 2 != 0);
160 {newKey,
R->mult(
x.second, Dval)});
173 R->mult(
x.second, Dval));
179 R->mult(
x.second, Dval));
210 std::vector<int> row_vec(
p), col_vec(
p);
211 for (
int i = 0; i <
p; ++i)
213 row_vec[i] =
static_cast<int>(
row_set[i]);
214 col_vec[i] =
static_cast<int>(
col_set[i]);
218 auto it = map.find({row_vec, col_vec});
219 if (it != map.end()) { r = it->second; }
230 result.append(
R->make_vec(0, r));
247 for (
size_t i = 0; i <
p; i++)
row_set[i] = i;
262 for (
size_t i = 0; i <
p; i++)
row_set[i] = rows[i];
264 for (
size_t i = 0; i <
p; i++)
row_set[i] = i;
267 for (
size_t i = 0; i <
p; i++)
col_set[i] = cols[i];
269 for (
size_t i = 0; i <
p; i++)
col_set[i] = i;
286 for (
size_t i = 0; i < p0; i++)
287 for (
size_t j = 0; j < p0; j++)
288 D0[i][j] =
M->elem(
static_cast<int>(r[i]),
static_cast<int>(c[j]));
298 for (
size_t c = 0; c <= r; c++)
299 if (!
R->is_zero(D0[r][c]))
316 R->subtract_to(a, b);
336 for (
size_t c = 0; c < pivot_col; c++)
337 D0[i][c] =
detmult(pivot, D0[i][c], f, D0[r][c], lastpivot);
339 for (
size_t c = pivot_col + 1; c <= r; c++)
340 D0[i][c - 1] =
detmult(pivot, D0[i][c], f, D0[r][c], lastpivot);
354 for (
size_t r =
p - 1; r >= 1; --r)
356 R->remove(lastpivot);
361 for (
size_t i = 0; i <= r; i++)
362 for (
size_t j = 0; j <= r; j++)
R->remove(
D[i][j]);
363 R->remove(lastpivot);
364 return R->from_long(0);
366 for (
size_t i = 0; i < r; i++)
gauss(
D, i, r, pivot_col, lastpivot);
368 if (((r + pivot_col) % 2) == 1)
371 for (
size_t c = 0; c <= r; c++)
379 R->remove(lastpivot);
383 if (sign < 0)
R->negate_to(r);
391 if (p0 == 1)
return M->elem(
static_cast<int>(r[0]),
static_cast<int>(c[0]));
395 for (
int i = p0 - 1; i >= 0; i--)
400 M->elem(
static_cast<int>(r[p0 - 1]),
static_cast<int>(c[p0 - 1]));
411 R->subtract_to(answer, gh);
413 R->add_to(answer, gh);
418 size_t temp = c[p0 - 1];
419 for (
size_t i = p0 - 1; i > 0; i--) c[i] = c[i - 1];
430 "determinant computations over RR or CC requires Strategy=>Cofactor");
445 "determinant computations over RR or CC requires Strategy=>Cofactor");
466 "determinant computations over RR or CC requires Strategy=>Cofactor");
469 if (first_row !=
nullptr || first_col !=
nullptr)
472 if (first_row ==
nullptr || first_row->len !=
p)
474 ERROR(
"row index set inappropriate");
477 if (first_col ==
nullptr || first_col->len !=
p)
479 ERROR(
"column index set inappropriate");
484 if (first_row !=
nullptr && first_col !=
nullptr)
486 d->
calc(n_to_compute);
std::pair< std::vector< int >, std::vector< int > > ColRowIndices
MinorsCache dynamic_cache
void set_next_minor(const int *rows, const int *cols)
void gauss(ring_elem **D, size_t i, size_t r, size_t pivot_col, ring_elem lastpivot)
std::map< ColRowIndices, ring_elem, std::less< ColRowIndices >, gc_allocator< std::pair< const ColRowIndices, ring_elem > > > Subdeterminant
ring_elem detmult(ring_elem f1, ring_elem g1, ring_elem f2, ring_elem g2, ring_elem d)
bool get_pivot(ring_elem **D, size_t p, ring_elem &pivot, size_t &pivot_col)
ring_elem calc_det(size_t *r, size_t *c, int p)
DetComputation(const Matrix *M, int p, bool do_exterior, int strategy)
void get_minor(size_t *r, size_t *c, int p, ring_elem **D)
std::map< int, int > row_lookup
Computation of minors of a matrix.
Engine-side free module R^n over a Ring.
const Ring * get_ring() const
Matrix * minors(int p, int strategy) const
Matrix(const FreeModule *rows, const FreeModule *cols, const_monomial degree_shift, VECTOR(vec) &entries)
Matrix * exterior(int p, int strategy) const
Mutable builder used to assemble an immutable Matrix one column (or one term) at a time.
static bool increment(size_t n, Subset &s)
bool isValid(const Subset &a)
Subsets — combinatorial-number-system encoding of p-subsets of {0,...,n-1}.
Determinants and minors of Matrix values via Bareiss, cofactor, or dynamic-programming strategies.
bool system_interrupted()
system_interrupted() — thread-safe polling predicate for Ctrl+C handling.
VALGRIND_MAKE_MEM_DEFINED & result(result)
M2_arrayint M2_arrayintOrNull
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
#define newarray_atomic(T, len)
TermIterator< Nterm > end(Nterm *)
void emit_wrapped(const char *s)
Text-formatting helpers layered on buffer: bignum print, line wrapping, M2_gbTrace-gated emit.