source: git/Singular/MinorProcessor.h @ 237b3e4

spielwiese
Last change on this file since 237b3e4 was ad8608, checked in by Hans Schönemann <hannes@…>, 14 years ago
removed debug messages git-svn-id: file:///usr/local/Singular/svn/trunk@12699 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 34.7 KB
Line 
1#ifndef MINOR_PROCESSOR_H
2#define MINOR_PROCESSOR_H
3
4#include <Cache.h>
5#include <Minor.h>
6#include <assert.h>
7#include <string>
8
9/* write "##define COUNT_AND_PRINT_OPERATIONS x" if you want
10   to count all basic operations and have them printed when
11   one of the methods documented herein will be invoked;
12   otherwise, comment this line;
13   x = 1: only final counters (after computing ALL
14          specified minors) will be printed, i.e., no
15          intermediate results;
16   x = 2: print counters after the computation of each
17          minor; this will be much more information
18   x = 3: print also all intermediate matrices with the
19          numbers of monomials in each entry;
20          this will be much much more information */
21//#define COUNT_AND_PRINT_OPERATIONS 2
22
23void printCounters (char* prefix, bool resetToZero);
24
25/*! \class MinorProcessor
26    \brief Class MinorProcessor implements the key methods for computing one
27    or all sub-determinantes of a given size in a pre-defined matrix; either
28    without caching or by using a cache.
29
30    After defining the entire matrix (e.g. 10 x 14) using<br>
31    MinorProcessor::defineMatrix (const int, const int, const int*),<br>
32    the user may do two different things:<br>
33    1. He/she can simply compute a minor in this matrix using<br>
34    MinorProcessor::getMinor (const int, const int*, const int*,
35                              Cache<MinorKey, MinorValue>&), or<br>
36    MinorProcessor::getMinor (const int, const int*, const int*);<br>
37    depending on whether a cache shall or shall not be used, respectively.<br>
38    In the first case, the user simply provides all row and column indices of
39    the desired minor.
40    2. He/she may define a smaller sub-matrix (e.g. 8 x 7) using
41    MinorValue::defineSubMatrix (const int, const int*, const int, const int*).
42    Afterwards, he/she may compute all minors of an even smaller size (e.g.
43    5 x 5) that consist exclusively of rows and columns of this (8 x 7)
44    sub-matrix (inside the entire 10 x 14 matrix).<br>
45    The implementation at hand eases the iteration over all such minors. Also
46    in the second case there are both implementations, i.e., with and without
47    using a cache.<br><br>
48    MinorProcessor makes use of MinorKey, MinorValue, and Cache. The
49    implementation of all mentioned classes (MinorKey, MinorValue, and
50    MinorProcessor) is generic to allow for the use of different types of
51    keys and values.
52    \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch
53*/
54class MinorProcessor
55{
56  protected:
57    /**
58    * A static method for computing the maximum number of retrievals of a
59    * minor.<br>
60    * More concretely, we are given a matrix of size \c rows x \c columns. We
61    * furthermore assume that we have - as part of this matrix - a minor of
62    * size \c containerMinorSize x \c containerMinorSize. Now we are
63    * interested in the number of times a minor of yet smaller size
64    * \c minorSize x \c minorSize will be needed when we compute the
65    * containerMinor by Laplace's Theorem.<br>
66    * The method returns the combinatorial results for both cases:
67    * containerMinor is fixed within the matrix
68    * (<c>multipleMinors == false</c>), or it can vary inside the matrix
69    * (<c>multipleMinors == true</c>).<br>
70    * The notion is here that we want to cache the small minor of size
71    * \c minorSize x \c minorSize, i.e. compute it just once.
72    * @param rows the number of rows of the underlying matrix
73    * @param columns the number of columns of the underlying matrix
74    * @param containerMinorSize the size of the container minor
75    * @param minorSize the size of the small minor (which may be retrieved
76    *        multiple times)
77    * @param multipleMinors decides whether containerMinor is fixed within
78    *        the underlying matrix or not
79    * @return the number of times, the small minor will be needed when
80    *         computing one or all containerMinors
81    */
82    static int NumberOfRetrievals (const int rows, const int columns,
83                                   const int containerMinorSize,
84                                   const int minorSize,
85                                   const bool multipleMinors);
86    /**
87    * A static method for computing the binomial coefficient i over j.
88    * \par Assert
89    * The method checks whether <em>i >= j >= 0</em>.
90    * @param i a positive integer greater than or equal to \a j
91    * @param j a positive integer less than or equal to \a i, and greater
92    *        than or equal to \e 0.
93    * @return the binomial coefficient i over j
94    */
95    static int IOverJ (const int i, const int j);
96
97    /**
98    * A static method for computing the factorial of i.
99    * \par Assert
100    * The method checks whether <em>i >= 0</em>.
101    * @param i an integer greater than or equal to \a 0
102    * @return the factorial of i
103    */
104    static int Faculty (const int i);
105
106    /**
107    * A method for iterating through all possible subsets of \c k rows and
108    * \c k columns inside a pre-defined submatrix of a pre-defined matrix.<br>
109    * The method will set \c _rowKey and \c columnKey to represent the
110    * next possbile subsets of \c k rows and columns inside the submatrix
111    * determined by \c _globalRowKey and \c _globalColumnKey.<br>
112    * When first called, this method will just shift \c _rowKey and
113    * \c _columnKey to point to the first sensible choices. Every subsequent
114    * call will move to the next \c _columnKey until there is no next.
115    * In this situation, a next \c _rowKey will be set, and \c _columnKey
116    * again to the first possible choice.<br>
117    * Finally, in case there is also no next \c _rowkey, the method returns
118    * \c false. (Otherwise \c true is returned.)
119    * @param k the size of the minor / all minors of interest
120    * @return true iff there is a next possible choice of rows and columns
121    */
122    bool setNextKeys (const int k);
123
124    /**
125    * private store for the rows and columns of the container minor within
126    * the underlying matrix;
127    * \c _container will be used to fix a submatrix (e.g. 40 x 50) of a
128    * larger matrix (e.g. 70 x 100). This is usefull when we would like to
129    * compute all minors of a given size (e.g. 4 x 4) inside such a
130    * pre-defined submatrix.
131    */
132    MinorKey _container;
133
134    /**
135    * private store for the number of rows in the container minor;
136    * This is set by MinorProcessor::defineSubMatrix (const int, const int*,
137    *                                                 const int, const int*).
138    */
139    int _containerRows;
140
141    /**
142    * private store for the number of columns in the container minor;
143    * This is set by MinorProcessor::defineSubMatrix (const int, const int*,
144    *                                                 const int, const int*).
145    */
146    int _containerColumns;
147
148    /**
149    * private store for the rows and columns of the minor of interest;
150    * Usually, this minor will encode subsets of the rows and columns in
151    * _container.
152    */
153    MinorKey _minor;
154
155    /**
156    * private store for the dimension of the minor(s) of interest
157    */
158    int _minorSize;
159
160    /**
161    * private store for the number of rows in the underlying matrix
162    */
163    int _rows;
164
165    /**
166    * private store for the number of columns in the underlying matrix
167    */
168    int _columns;
169
170    /**
171    * A method for identifying the row or column with the most zeros.<br>
172    * Using Laplace's Theorem, a minor can more efficiently be computed when
173    * developing along this best line.
174    * The returned index \c bestIndex is 0-based within the pre-defined
175    * matrix. If some row has the most zeros, then the (0-based) row index is
176    * returned. If, contrarywise, some column has the most zeros, then
177    * <c>x = - 1 - c</c> where \c c is the column index, is returned.
178    * (Note that in this case \c c can be reconstructed by computing
179    * <c>c = - 1 - x</c>.)
180    * @param k the size of the minor / all minors of interest
181    * @param mk the representation of rows and columns of the minor of
182    *        interest
183    * @return an int encoding which row or column has the most zeros
184    */
185    int getBestLine (const int k, const MinorKey& mk) const;
186
187    /**
188    * A method for testing whether a matrix entry is zero.
189    * @param absoluteRowIndex the absolute (zero-based) row index
190    * @param absoluteColumnIndex the absolute (zero-based) column index
191    * @return true iff the specified matrix entry is zero
192    */
193    virtual bool isEntryZero (const int absoluteRowIndex,
194                              const int absoluteColumnIndex) const;
195  public:
196    /**
197    * The default constructor
198    */
199    MinorProcessor ();
200
201    /**
202    * A method for defining a sub-matrix within a pre-defined matrix.
203    * @param numberOfRows the number of rows in the sub-matrix
204    * @param rowIndices an array with the (0-based) indices of rows inside
205    *        the pre-defined matrix
206    * @param numberOfColumns the number of columns in the sub-matrix
207    * @param columnIndices an array with the (0-based) indices of columns
208    *        inside the pre-defined matrix
209    * @see MinorValue::defineMatrix (const int, const int, const int*)
210    */
211    void defineSubMatrix (const int numberOfRows, const int* rowIndices,
212                          const int numberOfColumns, const int* columnIndices);
213
214    /**
215    * Sets the size of the minor(s) of interest.<br>
216    * This method needs to be performed before beginning to compute all minors
217    * of size \a minorSize inside a pre-defined submatrix of an underlying
218    * (also pre-defined) matrix.
219    * @param minorSize the size of the minor(s) of interest
220    * @see MinorValue::defineSubMatrix (const int, const int*, const int,
221    *                                   const int*)
222    */
223    void setMinorSize (const int minorSize);
224
225    /**
226    * A method for checking whether there is a next choice of rows and columns
227    * when iterating through all minors of a given size within a pre-defined
228    * sub-matrix of an underlying matrix.<br>
229    * The number of rows and columns has to be set before using
230    * MinorValue::setMinorSize(const int).<br>
231    * After calling MinorValue::hasNextMinor (), the current sets of rows and
232    * columns may be inspected using
233    * MinorValue::getCurrentRowIndices(int* const) const and
234    * MinorValue::getCurrentColumnIndices(int* const) const.
235    * @return true iff there is a next choice of rows and columns
236    * @see MinorProcessor::getMinor (const int, const int*, const int*)
237    * @see MinorValue::getCurrentRowIndices(int* const) const
238    * @see MinorValue::getCurrentColumnIndices(int* const) const
239    */
240    bool hasNextMinor ();
241
242    /**
243    * A method for obtaining the current set of rows corresponding to the
244    * current minor when iterating through all minors of a given size within
245    * a pre-defined sub-matrix of an underlying matrix.<br>
246    * This method should only be called after MinorProcessor::hasNextMinor ()
247    * had been called and yielded \c true.<br>
248    * The user of this method needs to know the number of rows in order to
249    * know which entries of the newly filled \c target will be valid.
250    * @param target an int array to be filled with the row indices
251    * @see MinorProcessor::hasNextMinor ()
252    */
253    void getCurrentRowIndices (int* const target) const;
254
255    /**
256    * A method for obtaining the current set of columns corresponding to the
257    * current minor when iterating through all minors of a given size within
258    * a pre-defined sub-matrix of an underlying matrix.<br>
259    * This method should only be called after MinorProcessor::hasNextMinor ()
260    * had been called and yielded \c true.<br>
261    * The user of this method needs to know the number of columns in order to
262    * know which entries of the newly filled \c target will be valid.
263    * @param target an int array to be filled with the column indices
264    * @see MinorProcessor::hasNextMinor ()
265    */
266    void getCurrentColumnIndices (int* const target) const;
267
268    /**
269    * A method for providing a printable version of the represented
270    * MinorProcessor.
271    * @return a printable version of the given instance as instance of class
272    * string
273    */
274    virtual string toString () const;
275
276    /**
277    * A method for printing a string representation of the given
278    * MinorProcessor to std::cout.
279    */
280    void print () const;
281};
282
283/*! \class IntMinorProcessor
284    \brief Class IntMinorProcessor is derived from class MinorProcessor.
285   
286    This class implements the special case of integer matrices.
287    \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch
288*/
289class IntMinorProcessor : public MinorProcessor
290{
291  private:
292    /**
293    * private store for integer matrix entries
294    */
295    int* _intMatrix;
296   
297    /**
298    * A method for retrieving the matrix entry.
299    * @param rowIndex the absolute (zero-based) row index
300    * @param columnIndex the absolute (zero-based) column index
301    * @return the specified matrix entry
302    */
303    int getEntry (const int rowIndex, const int columnIndex) const;
304
305    /**
306    * A method for computing the value of a minor, using a cache.<br>
307    * The sub-matrix is specified by \c mk. Computation works recursively
308    * using Laplace's Theorem. We always develop along the row or column with
309    * the most zeros; see
310    * MinorProcessor::getBestLine (const int k, const MinorKey& mk).
311    * If an ideal is given, it is assumed to be a standard basis. In this case,
312    * all results will be reduced w.r.t. to this basis. Moreover, if the given
313    * characteristic is non-zero, all results will be computed modulo this
314    * characteristic.
315    * @param k the number of rows and columns in the minor to be comuted
316    * @param mk the representation of rows and columns of the minor to be
317    *        comuted
318    * @param multipleMinors decides whether we compute just one or all minors
319    *        of a specified size
320    * @param c a cache to be used for caching reusable sub-minors
321    * @param characteristic 0 or the characteristic of the underlying
322    *        coefficient ring/field
323    * @param iSB NULL or a standard basis
324    * @return an instance of MinorValue representing the value of the
325    *         corresponding minor
326    * @see MinorProcessor::getMinorPrivateLaplace (const int k,
327                                                   const MinorKey& mk,
328                                                   const int characteristic,
329                                                   const ideal& iSB)
330    */
331    IntMinorValue getMinorPrivateLaplace (const int k, const MinorKey& mk,
332                                          const bool multipleMinors,
333                                          Cache<MinorKey, IntMinorValue>& c,
334                                          int characteristic,
335                                          const ideal& iSB);
336
337    /**
338    * A method for computing the value of a minor, without using a cache.<br>
339    * The sub-matrix is specified by \c mk. Computation works recursively
340    * using Laplace's Theorem. We always develop along the row or column with
341    * the most zeros; see
342    * MinorProcessor::getBestLine (const int k, const MinorKey& mk).
343    * If an ideal is given, it is assumed to be a standard basis. In this case,
344    * all results will be reduced w.r.t. to this basis. Moreover, if the given
345    * characteristic is non-zero, all results will be computed modulo this
346    * characteristic.
347    * @param k the number of rows and columns in the minor to be comuted
348    * @param mk the representation of rows and columns of the minor to be
349    *        comuted
350    * @param characteristic 0 or the characteristic of the underlying
351    *        coefficient ring/field
352    * @param iSB NULL or a standard basis
353    * @return an instance of MinorValue representing the value of the
354    *         corresponding minor
355    * @see MinorProcessor::getMinorPrivateLaplace (const int k,
356                                                   const MinorKey& mk,
357                                                   const bool multipleMinors,
358                                                   Cache<MinorKey,
359                                                         IntMinorValue>& c,
360                                                   int characteristic,
361                                                   const ideal& iSB)
362    */
363    IntMinorValue getMinorPrivateLaplace (const int k, const MinorKey& mk,
364                                          const int characteristic,
365                                          const ideal& iSB);
366
367    /**
368    * A method for computing the value of a minor using Bareiss's
369    * algorithm.<br>
370    * The sub-matrix is specified by \c mk.
371    * If an ideal is given, it is assumed to be a standard basis. In this
372    * case, all results will be reduced w.r.t. to this basis. Moreover, if the
373    * given characteristic is non-zero, all results will be computed modulo
374    * this characteristic.
375    * @param k the number of rows and columns in the minor to be comuted
376    * @param mk the representation of rows and columns of the minor to be
377    *        computed
378    * @param characteristic 0 or the characteristic of the underlying
379    *        coefficient ring/field
380    * @param iSB NULL or a standard basis
381    * @return an instance of MinorValue representing the value of the
382    *         corresponding minor
383    * @see MinorProcessor::getMinorPrivateLaplace (const int k,
384                                                   const MinorKey& mk,
385                                                   const int characteristic,
386                                                   const ideal& iSB)
387    */
388    IntMinorValue getMinorPrivateBareiss (const int k, const MinorKey& mk,
389                                          const int characteristic,
390                                          const ideal& iSB);
391  protected:
392    /**
393    * A method for testing whether a matrix entry is zero.
394    * @param absoluteRowIndex the absolute (zero-based) row index
395    * @param absoluteColumnIndex the absolute (zero-based) column index
396    * @return true iff the specified matrix entry is zero
397    */
398    bool isEntryZero (const int absoluteRowIndex,
399                      const int absoluteColumnIndex) const;
400  public:
401    /**
402    * A constructor for creating an instance.
403    */
404    IntMinorProcessor ();
405
406    /**
407    * A destructor for deleting an instance.
408    */
409    ~IntMinorProcessor ();
410
411    /**
412    * A method for defining a matrix with integer entries.
413    * @param numberOfRows the number of rows
414    * @param numberOfColumns the number of columns
415    * @param matrix the matrix entries in a linear array, i.e., from left to
416    *        right and top to bottom
417    * @see MinorValue::defineSubMatrix (const int, const int*, const int,
418    *                                   const int*)
419    */
420    void defineMatrix (const int numberOfRows, const int numberOfColumns,
421                       const int* matrix);
422
423    /**
424    * A method for computing the value of a minor without using a cache.<br>
425    * The sub-matrix is determined by \c rowIndices and \c columnIndices.
426    * Computation works either by Laplace's algorithm or by Bareiss's
427    * algorithm.<br>
428    * If an ideal is given, it is assumed to be a standard basis. In this
429    * case, all results will be reduced w.r.t. to this basis. Moreover, if the
430    * given characteristic is non-zero, all results will be computed modulo
431    * this characteristic.
432    * @param dimension the size of the minor to be computed
433    * @param rowIndices 0-based indices of the rows of the minor
434    * @param columnIndices 0-based indices of the column of the minor
435    * @param characteristic 0 or the characteristic of the underlying
436    *        coefficient ring/field
437    * @param iSB NULL or a standard basis
438    * @param algorithm either "Bareiss" or "Laplace"
439    * @return an instance of MinorValue representing the value of the
440    *         corresponding minor
441    * @see MinorProcessor::getMinor (const int dimension,
442                                     const int* rowIndices,
443                                     const int* columnIndices,
444                                     Cache<MinorKey, IntMinorValue>& c,
445                                     const int characteristic,
446                                     const ideal& iSB)
447    */
448    IntMinorValue getMinor (const int dimension, const int* rowIndices,
449                            const int* columnIndices,
450                            const int characteristic, const ideal& iSB,
451                            const char* algorithm);
452
453    /**
454    * A method for computing the value of a minor using a cache.<br>
455    * The sub-matrix is determined by \c rowIndices and \c columnIndices.
456    * Computation works by Laplace's algorithm together with caching of
457    * subdeterminants.<br>
458    * If an ideal is given, it is assumed to be a standard basis. In this case,
459    * all results will be reduced w.r.t. to this basis. Moreover, if the given
460    * characteristic is non-zero, all results will be computed modulo this
461    * characteristic.
462    * @param dimension the size of the minor to be computed
463    * @param rowIndices 0-based indices of the rows of the minor
464    * @param columnIndices 0-based indices of the column of the minor
465    * @param c the cache for storing subdeterminants
466    * @param characteristic 0 or the characteristic of the underlying
467    *        coefficient ring/field
468    * @param iSB NULL or a standard basis
469    * @return an instance of MinorValue representing the value of the
470    *         corresponding minor
471    * @see MinorProcessor::getMinor (const int dimension,
472                                     const int* rowIndices,
473                                     const int* columnIndices,
474                                     const int characteristic,
475                                     const ideal& iSB,
476                                     const char* algorithm)
477    */
478    IntMinorValue getMinor (const int dimension, const int* rowIndices,
479                            const int* columnIndices,
480                            Cache<MinorKey, IntMinorValue>& c,
481                            const int characteristic,  const ideal& iSB);
482
483    /**
484    * A method for obtaining the next minor when iterating
485    * through all minors of a given size within a pre-defined sub-matrix of an
486    * underlying matrix.<br>
487    * This method should only be called after MinorProcessor::hasNextMinor ()
488    * had been called and yielded \c true.<br>
489    * Computation works by Laplace's algorithm (without using a cache) or by
490    * Bareiss's algorithm.<br>
491    * If an ideal is given, it is assumed to be a standard basis. In this case,
492    * all results will be reduced w.r.t. to this basis. Moreover, if the given
493    * characteristic is non-zero, all results will be computed modulo this
494    * characteristic.
495    * @param characteristic 0 or the characteristic of the underlying
496    *        coefficient ring/field
497    * @param iSB NULL or a standard basis
498    * @param algorithm either "Bareiss" or "Laplace"
499    * @return the next minor
500    * @see IntMinorValue::getNextMinor (Cache<MinorKey, IntMinorValue>& c,
501    *                                   const int characteristic,
502    *                                   const ideal& iSB)
503    */
504    IntMinorValue getNextMinor (const int characteristic, const ideal& iSB,
505                                const char* algorithm);
506
507    /**
508    * A method for obtaining the next minor when iterating
509    * through all minors of a given size within a pre-defined sub-matrix of an
510    * underlying matrix.<br>
511    * This method should only be called after MinorProcessor::hasNextMinor ()
512    * had been called and yielded \c true.<br>
513    * Computation works using the cache \a c which may already contain useful
514    * results from previous calls of
515    * IntMinorValue::getNextMinor (Cache<MinorKey, IntMinorValue>& c,
516                                   const int characteristic,
517                                   const ideal& iSB).
518    * If an ideal is given, it is assumed to be a standard basis. In this case,
519    * all results will be reduced w.r.t. to this basis. Moreover, if the given
520    * characteristic is non-zero, all results will be computed modulo this
521    * characteristic.
522    * @param c the cache
523    * @param characteristic 0 or the characteristic of the underlying
524    *        coefficient ring/field
525    * @param iSB NULL or a standard basis
526    * @return the next minor
527    * @see IntMinorValue::getNextMinor (const int characteristic,
528    *                                   const ideal& iSB,
529    *                                   const char* algorithm)
530    */
531    IntMinorValue getNextMinor (Cache<MinorKey, IntMinorValue>& c,
532                                const int characteristic,
533                                const ideal& iSB);
534
535    /**
536    * A method for providing a printable version of the represented
537    * MinorProcessor.
538    * @return a printable version of the given instance as instance of class
539    *         string
540    */
541    string toString () const;
542};
543
544/*! \class PolyMinorProcessor
545    \brief Class PolyMinorProcessor is derived from class MinorProcessor.
546   
547    This class implements the special case of polynomial matrices.
548    \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch
549*/
550class PolyMinorProcessor : public MinorProcessor
551{
552  private:
553    /**
554    * private store for polynomial matrix entries
555    */
556    poly* _polyMatrix;
557   
558    /**
559    * A method for retrieving the matrix entry.
560    * @param rowIndex the absolute (zero-based) row index
561    * @param columnIndex the absolute (zero-based) column index
562    * @return the specified matrix entry
563    */
564    poly getEntry (const int rowIndex, const int columnIndex) const;
565
566    /**
567    * A method for computing the value of a minor, using a cache.<br>
568    * The sub-matrix is specified by \c mk. Computation works recursively
569    * using Laplace's Theorem. We always develop along the row or column with
570    * the most zeros; see
571    * MinorProcessor::getBestLine (const int k, const MinorKey& mk).
572    * If an ideal is given, it is assumed to be a standard basis. In this case,
573    * all results will be reduced w.r.t. to this basis.
574    * @param k the number of rows and columns in the minor to be comuted
575    * @param mk the representation of rows and columns of the minor to be
576    *        comuted
577    * @param multipleMinors decides whether we compute just one or all minors
578    *        of a specified size
579    * @param c a cache to be used for caching reusable sub-minors
580    * @param iSB NULL or a standard basis
581    * @return an instance of MinorValue representing the value of the
582    *         corresponding minor
583    * @see MinorProcessor::getMinorPrivateLaplace (const int k,
584    *                                              const MinorKey& mk,
585    *                                              const ideal& iSB)
586    */
587    PolyMinorValue getMinorPrivateLaplace (const int k, const MinorKey& mk,
588                                           const bool multipleMinors,
589                                           Cache<MinorKey, PolyMinorValue>& c,
590                                           const ideal& iSB);
591
592    /**
593    * A method for computing the value of a minor, without using a cache.<br>
594    * The sub-matrix is specified by \c mk. Computation works recursively
595    * using Laplace's Theorem. We always develop along the row or column with
596    * the most zeros; see
597    * MinorProcessor::getBestLine (const int k, const MinorKey& mk).
598    * If an ideal is given, it is assumed to be a standard basis. In this case,
599    * all results will be reduced w.r.t. to this basis.
600    * @param k the number of rows and columns in the minor to be comuted
601    * @param mk the representation of rows and columns of the minor to be
602    *        comuted
603    * @param iSB NULL or a standard basis
604    * @return an instance of MinorValue representing the value of the
605    *         corresponding minor
606    * @see MinorProcessor::getMinorPrivate (const int, const MinorKey&,
607    *                                       const bool,
608    *                                       Cache<MinorKey, MinorValue>&)
609    */
610    PolyMinorValue getMinorPrivateLaplace (const int k, const MinorKey& mk,
611                                           const ideal& iSB);
612   
613    /**
614    * A method for computing the value of a minor, without using a cache.<br>
615    * The sub-matrix is specified by \c mk. Computation works
616    * using Bareiss's algorithm.
617    * If an ideal is given, it is assumed to be a standard basis. In this case,
618    * all results will be reduced w.r.t. to this basis.
619    * @param k the number of rows and columns in the minor to be comuted
620    * @param mk the representation of rows and columns of the minor to be
621    *        comuted
622    * @param iSB NULL or a standard basis
623    * @return an instance of MinorValue representing the value of the
624    *         corresponding minor
625    * @see MinorProcessor::getMinorPrivateLaplace (const int k,
626    *                                              const MinorKey& mk,
627    *                                              const ideal& iSB)
628    */
629    PolyMinorValue getMinorPrivateBareiss (const int k, const MinorKey& mk,
630                                           const ideal& iSB);
631  protected:
632    /**
633    * A method for testing whether a matrix entry is zero.
634    * @param absoluteRowIndex the absolute (zero-based) row index
635    * @param absoluteColumnIndex the absolute (zero-based) column index
636    * @return true iff the specified matrix entry is zero
637    */
638    bool isEntryZero (const int absoluteRowIndex,
639                      const int absoluteColumnIndex) const;
640  public:
641    /**
642    * A constructor for creating an instance.
643    */
644    PolyMinorProcessor ();
645
646    /**
647    * A destructor for deleting an instance.
648    */
649    ~PolyMinorProcessor ();
650
651    /**
652    * A method for defining a matrix with polynomial entries.
653    * @param numberOfRows the number of rows
654    * @param numberOfColumns the number of columns
655    * @param polyMatrix the matrix entries in a linear array, i.e., from left
656    *        to right and top to bottom
657    * @see MinorValue::defineSubMatrix (const int, const int*, const int,
658    *                                   const int*)
659    */
660    void defineMatrix (const int numberOfRows, const int numberOfColumns,
661                       const poly* polyMatrix);
662
663    /**
664    * A method for computing the value of a minor, without using a cache.<br>
665    * The sub-matrix is determined by \c rowIndices and \c columnIndices.
666    * Computation works either by Laplace's algorithm or by Bareiss's
667    * algorithm.<br>
668    * If an ideal is given, it is assumed to be a standard basis. In this case,
669    * all results will be reduced w.r.t. to this basis.
670    * @param dimension the size of the minor to be computed
671    * @param rowIndices 0-based indices of the rows of the minor
672    * @param columnIndices 0-based indices of the column of the minor
673    * @param algorithm either "Laplace" or "Bareiss"
674    * @param iSB NULL or a standard basis
675    * @return an instance of MinorValue representing the value of the
676    *         corresponding minor
677    * @see MinorProcessor::getMinor (const int dimension,
678    *                                const int* rowIndices,
679    *                                const int* columnIndices,
680    *                                Cache<MinorKey, PolyMinorValue>& c,
681    *                                const ideal& iSB)
682    */
683    PolyMinorValue getMinor (const int dimension, const int* rowIndices,
684                             const int* columnIndices, const char* algorithm,
685                             const ideal& iSB);
686
687    /**
688    * A method for computing the value of a minor, using a cache.<br>
689    * The sub-matrix is determined by \c rowIndices and \c columnIndices.
690    * Computation works recursively using Laplace's Theorem. We always develop
691    * along the row or column with most zeros; see
692    * MinorProcessor::getBestLine (const int, const int, const int).
693    * If an ideal is given, it is assumed to be a standard basis. In this case,
694    * all results will be reduced w.r.t. to this basis.
695    * @param dimension the size of the minor to be computed
696    * @param rowIndices 0-based indices of the rows of the minor
697    * @param columnIndices 0-based indices of the column of the minor
698    * @param c a cache to be used for caching reusable sub-minors
699    * @param iSB NULL or a standard basis
700    * @return an instance of MinorValue representing the value of the
701    *         corresponding minor
702    * @see MinorProcessor::(const int dimension, const int* rowIndices,
703    *                       const int* columnIndices, const char* algorithm,
704    *                       const ideal& iSB)
705    */
706    PolyMinorValue getMinor (const int dimension, const int* rowIndices,
707                             const int* columnIndices,
708                             Cache<MinorKey, PolyMinorValue>& c,
709                             const ideal& iSB);
710
711    /**
712    * A method for obtaining the next minor when iterating
713    * through all minors of a given size within a pre-defined sub-matrix of an
714    * underlying matrix.<br>
715    * This method should only be called after MinorProcessor::hasNextMinor ()
716    * had been called and yielded \c true.<br>
717    * Computation works either by Laplace's algorithm (without using a cache)
718    * or by Bareiss's algorithm.<br>
719    * If an ideal is given, it is assumed to be a standard basis. In this case,
720    * all results will be reduced w.r.t. to this basis.
721    * @param algorithm either "Laplace" or "Bareiss"
722    * @param iSB NULL or a standard basis
723    * @return true iff there is a next choice of rows and columns
724    * @see PolyMinorValue::getNextMinor (Cache<MinorKey, PolyMinorValue>& c,
725    *                                    const ideal& iSB)
726    */
727    PolyMinorValue getNextMinor (const char* algorithm, const ideal& iSB);
728
729    /**
730    * A method for obtaining the next minor when iterating
731    * through all minors of a given size within a pre-defined sub-matrix of an
732    * underlying matrix.<br>
733    * This method should only be called after MinorProcessor::hasNextMinor ()
734    * had been called and yielded \c true.<br>
735    * Computation works using Laplace's algorithm and a cache \a c which may
736    * already contain useful results from previous calls of
737    * PolyMinorValue::getNextMinor (Cache<MinorKey, PolyMinorValue>& c,
738    *                               const ideal& iSB).
739    * If an ideal is given, it is assumed to be a standard basis. In this case,
740    * all results will be reduced w.r.t. to this basis.
741    * @param iSB NULL or a standard basis
742    * @return the next minor
743    * @see PolyMinorValue::getNextMinor (const char* algorithm,
744    *                                    const ideal& iSB)
745    */
746    PolyMinorValue getNextMinor (Cache<MinorKey, PolyMinorValue>& c,
747                                 const ideal& iSB);
748
749    /**
750    * A method for providing a printable version of the represented
751    * MinorProcessor.
752    * @return a printable version of the given instance as instance of class
753    *         string
754    */
755    string toString () const;
756};
757
758#endif
759/* MINOR_PROCESSOR_H */
Note: See TracBrowser for help on using the repository browser.