Macaulay2 Engine
Loading...
Searching...
No Matches
det.hpp
Go to the documentation of this file.
1// Copyright 1996 by Michael E. Stillman.
2
3#ifndef _det_hh_
4# define _det_hh_
5
37
38# include "matrix.hpp"
39# include "matrix-con.hpp"
40# include <utility>
41# include <vector>
42# include <map>
43# include <algorithm>
44
45const int DET_BAREISS = 0;
46const int DET_COFACTOR = 1;
47const int DET_DYNAMIC = 2;
48
55{
56 const Ring *R;
57 const Matrix *M;
58 const FreeModule *F; // target free module of the result
59 // Matrix *result; // Either:One row matrix collecting non-zero
60 // determinants, or the resulting
61 // exterior power; depending on 'do_exterior'
62 MatrixConstructor result; // Either:One row matrix collecting non-zero
63 // determinants, or the resulting
64 // exterior power; depending on 'do_exterior'
65
66 bool done;
67 int p;
68
69 bool do_exterior; // true = construct exterior
70 // power of matrix, false =
71 // collect non-zero minors
72 int strategy; // 0: use Bareiss (fraction free, DOMAINS only)
73 // 1: use cofactor method.
74 // 2: use dynamic method (cache subcomputations)
75 size_t *row_set;
76 size_t *col_set;
79
80 ring_elem **D; // size p by p, dense representation.
81
82 // Dynamic method, vector of maps
83 using ColRowIndices = std::pair<std::vector<int>, std::vector<int>>;
85 std::map<ColRowIndices,
87 std::less<ColRowIndices>,
88 gc_allocator<std::pair<const ColRowIndices, ring_elem>>>;
90 std::map<int,
92 std::less<int>,
93 gc_allocator<std::pair<const int, Subdeterminant>>>;
94 using MinorsCache = std::vector<MinorsSubCache, gc_allocator<MinorsSubCache>>;
95 // The entry dynamic_cache[i][j][{r, c}] is the determinant of the submatrix
96 // corresponding to rows r and columns c, given as vectors of ints.
97 // The sizes of r and c are i, and the first entry of r is the jth nonzero
98 // row. The jth nonzero row is also the row given by row_lookup[j].
100 std::map<int, int> row_lookup;
101
102 void get_minor(size_t *r, size_t *c, int p, ring_elem **D);
103 // Sets D[0..p-1,0..p-1] with the given minor of M.
104
105 // Used in Dynamic:
106 int make_dynamic_cache();
107
108 // Used in Bareiss:
109 bool get_pivot(ring_elem **D, size_t p, ring_elem &pivot, size_t &pivot_col);
111 ring_elem g1,
112 ring_elem f2,
113 ring_elem g2,
114 ring_elem d);
115 void gauss(ring_elem **D,
116 size_t i,
117 size_t r,
118 size_t pivot_col,
119 ring_elem lastpivot);
120
121 ring_elem calc_det(size_t *r, size_t *c, int p);
122 // Compute the determinant of the minor with rows r[0]..r[p-1]
123 // and columns c[0]..c[p-1].
124
126 // Compute the determinant of the minor with rows r[0]..r[p-1]
127 // and columns c[0]..c[p-1].
128
129 // Subroutines for use in Bareiss algorithm:
130
131 public:
132 DetComputation(const Matrix *M, int p, bool do_exterior, int strategy);
134
135 int step();
136 int calc(int nsteps);
137
138 // The following two routines are only valid for 'do_exterior=0'
139 void clear();
140 void discard() { clear(); }
141 void set_next_minor(const int *rows, const int *cols);
142
143 Matrix *determinants() { return result.to_matrix(); }
144};
145
146#endif
147
148// Local Variables:
149// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
150// indent-tabs-mode: nil
151// End:
std::pair< std::vector< int >, std::vector< int > > ColRowIndices
Definition det.hpp:83
MinorsCache dynamic_cache
Definition det.hpp:99
void set_next_minor(const int *rows, const int *cols)
Definition det.cpp:258
const Ring * R
Definition det.hpp:56
void gauss(ring_elem **D, size_t i, size_t r, size_t pivot_col, ring_elem lastpivot)
Definition det.cpp:327
size_t * row_set
Definition det.hpp:75
int make_dynamic_cache()
Definition det.cpp:94
std::map< ColRowIndices, ring_elem, std::less< ColRowIndices >, gc_allocator< std::pair< const ColRowIndices, ring_elem > > > Subdeterminant
Definition det.hpp:84
size_t * col_set
Definition det.hpp:76
ring_elem ** D
Definition det.hpp:80
ring_elem detmult(ring_elem f1, ring_elem g1, ring_elem f2, ring_elem g2, ring_elem d)
Definition det.cpp:308
int calc(int nsteps)
Definition det.cpp:272
MatrixConstructor result
Definition det.hpp:62
const FreeModule * F
Definition det.hpp:58
std::map< int, Subdeterminant, std::less< int >, gc_allocator< std::pair< const int, Subdeterminant > > > MinorsSubCache
Definition det.hpp:89
int step()
Definition det.cpp:190
ring_elem bareiss_det()
Definition det.cpp:345
int strategy
Definition det.hpp:72
int this_col
Definition det.hpp:78
bool done
Definition det.hpp:66
~DetComputation()
Definition det.cpp:82
bool get_pivot(ring_elem **D, size_t p, ring_elem &pivot, size_t &pivot_col)
Definition det.cpp:291
bool do_exterior
Definition det.hpp:69
ring_elem calc_det(size_t *r, size_t *c, int p)
Definition det.cpp:387
DetComputation(const Matrix *M, int p, bool do_exterior, int strategy)
Definition det.cpp:8
void get_minor(size_t *r, size_t *c, int p, ring_elem **D)
Definition det.cpp:284
std::map< int, int > row_lookup
Definition det.hpp:100
int this_row
Definition det.hpp:77
void clear()
Definition det.cpp:252
void discard()
Definition det.hpp:140
const Matrix * M
Definition det.hpp:57
Matrix * determinants()
Definition det.hpp:143
std::vector< MinorsSubCache, gc_allocator< MinorsSubCache > > MinorsCache
Definition det.hpp:94
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
Mutable builder used to assemble an immutable Matrix one column (or one term) at a time.
xxx xxx xxx
Definition ring.hpp:102
const int DET_COFACTOR
Definition det.hpp:46
const int DET_BAREISS
Definition det.hpp:45
const int DET_DYNAMIC
Definition det.hpp:47
#define Matrix
Definition factory.cpp:14
MatrixConstructor — the mutable builder that produces an immutable Matrix.
Matrix — the engine's immutable homomorphism F -> G between free modules.