Changeset 95a6f3 in git


Ignore:
Timestamp:
Oct 9, 2009, 3:46:30 PM (14 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
Children:
60e4be265398f8004f3b093179a74b59f4fdcb74
Parents:
70f63ab39d1a6a435e42e041336a21e13c1269d9
Message:
more functionality: compute int minors modulo p


git-svn-id: file:///usr/local/Singular/svn/trunk@12182 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
Singular
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • Singular/MinorProcessor.cc

    r70f63a r95a6f3  
    270270
    271271IntMinorValue IntMinorProcessor::getMinor(const int dimension, const int* rowIndices, const int* columnIndices,
    272                                             Cache<MinorKey, IntMinorValue>& c) {
     272                                            Cache<MinorKey, IntMinorValue>& c, const int characteristic) {
    273273    defineSubMatrix(dimension, rowIndices, dimension, columnIndices);
    274274    _minorSize = dimension;
    275275    // call a helper method which recursively computes the minor using the cache c:
    276     return getMinorPrivate(dimension, _container, false, c);
    277 }
    278 
    279 IntMinorValue IntMinorProcessor::getMinor(const int dimension, const int* rowIndices, const int* columnIndices) {
     276    return getMinorPrivate(dimension, _container, false, c, characteristic);
     277}
     278
     279IntMinorValue IntMinorProcessor::getMinor(const int dimension, const int* rowIndices, const int* columnIndices, const int characteristic) {
    280280    defineSubMatrix(dimension, rowIndices, dimension, columnIndices);
    281281    _minorSize = dimension;
    282282    // call a helper method which recursively computes the minor (without using a cache):
    283     return getMinorPrivate(_minorSize, _container);
    284 }
    285 
    286 IntMinorValue IntMinorProcessor::getNextMinor() {
     283    return getMinorPrivate(_minorSize, _container, characteristic);
     284}
     285
     286IntMinorValue IntMinorProcessor::getNextMinor(const int characteristic) {
    287287    // computation without cache
    288     return getMinorPrivate(_minorSize, _minor);
    289 }
    290 
    291 IntMinorValue IntMinorProcessor::getNextMinor(Cache<MinorKey, IntMinorValue>& c) {
     288    return getMinorPrivate(_minorSize, _minor, characteristic);
     289}
     290
     291IntMinorValue IntMinorProcessor::getNextMinor(Cache<MinorKey, IntMinorValue>& c, const int characteristic) {
    292292    // computation with cache
    293     return getMinorPrivate(_minorSize, _minor, true, c);
    294 }
    295 
    296 IntMinorValue IntMinorProcessor::getMinorPrivate(const int k, const MinorKey& mk) {
     293    return getMinorPrivate(_minorSize, _minor, true, c, characteristic);
     294}
     295
     296IntMinorValue IntMinorProcessor::getMinorPrivate(const int k, const MinorKey& mk, const int characteristic) {
    297297    assert(k > 0); // k is the minor's dimension; the minor must be at least 1x1
    298298    // The method works by recursion, and using Lapace's Theorem along the row/column with the most zeros.
     
    317317                MinorKey subMk = mk.getSubMinorKey(b, absoluteC);  // This is MinorKey when we omit row b and column absoluteC.
    318318                if (_matrix[b][absoluteC] != 0) { // Only then do we have to consider this sub-determinante.
    319                     IntMinorValue mv = getMinorPrivate(k - 1, subMk);  // recursive call
     319                    IntMinorValue mv = getMinorPrivate(k - 1, subMk, characteristic);  // recursive call
    320320                    m += mv.getMultiplications();
    321321                    s += mv.getAdditions();
     
    324324                    result += sign * mv.getResult() * _matrix[b][absoluteC]; // adding sub-determinante times matrix entry
    325325                                                                             // times appropriate sign
     326                    if (characteristic != 0) result = result % characteristic;
    326327                    s++; m++; as++, am++; // This is for the addition and multiplication in the previous line of code.
    327328                }
     
    339340                MinorKey subMk = mk.getSubMinorKey(absoluteR, b); // This is MinorKey when we omit row absoluteR and column b.
    340341                if (_matrix[absoluteR][b] != 0) { // Only then do we have to consider this sub-determinante.
    341                     IntMinorValue mv = getMinorPrivate(k - 1, subMk);  // recursive call
     342                    IntMinorValue mv = getMinorPrivate(k - 1, subMk, characteristic);  // recursive call
    342343                    m += mv.getMultiplications();
    343344                    s += mv.getAdditions();
     
    346347                    result += sign * mv.getResult() * _matrix[absoluteR][b]; // adding sub-determinante times matrix entry
    347348                                                                             // times appropriate sign
     349                    if (characteristic != 0) result = result % characteristic;
    348350                    s++; m++; as++, am++; // This is for the addition and multiplication in the previous line of code.
    349351                }
     
    362364
    363365IntMinorValue IntMinorProcessor::getMinorPrivate(const int k, const MinorKey& mk,
    364                                                    const bool multipleMinors,
    365                                                    Cache<MinorKey, IntMinorValue>& cch) {
     366                                                 const bool multipleMinors,
     367                                                 Cache<MinorKey, IntMinorValue>& cch,
     368                                                 const int characteristic) {
    366369    assert(k > 0); // k is the minor's dimension; the minor must be at least 1x1
    367370    // The method works by recursion, and using Lapace's Theorem along the row/column with the most zeros.
     
    392395                    }
    393396                    else {
    394                         mv = getMinorPrivate(k - 1, subMk, multipleMinors, cch); // recursive call
     397                        mv = getMinorPrivate(k - 1, subMk, multipleMinors, cch, characteristic); // recursive call
    395398                        // As this minor was not in the cache, we count the additions and
    396399                        // multiplications that we needed to do in the recursive call:
     
    403406                    result += sign * mv.getResult() * _matrix[b][absoluteC]; // adding sub-determinante times matrix entry
    404407                                                                             // times appropriate sign
     408                    if (characteristic != 0) result = result % characteristic;
    405409                    s++; m++; as++; am++; // This is for the addition and multiplication in the previous line of code.
    406410                }
     
    425429                    }
    426430                    else {
    427                         mv = getMinorPrivate(k - 1, subMk, multipleMinors, cch); // recursive call
     431                        mv = getMinorPrivate(k - 1, subMk, multipleMinors, cch, characteristic); // recursive call
    428432                        // As this minor was not in the cache, we count the additions and
    429433                        // multiplications that we needed to do in the recursive call:
     
    436440                    result += sign * mv.getResult() * _matrix[absoluteR][b]; // adding sub-determinante times matrix entry
    437441                                                                             // times appropriate sign
     442                    if (characteristic != 0) result = result % characteristic;
    438443                    s++; m++; as++; am++; // This is for the addition and multiplication in the previous line of code.
    439444                }
  • Singular/MinorProcessor.h

    r70f63a r95a6f3  
    237237        */
    238238        IntMinorValue getMinorPrivate (const int k, const MinorKey& mk,
    239                                         const bool multipleMinors,
    240                                         Cache<MinorKey, IntMinorValue>& c);
     239                                       const bool multipleMinors,
     240                                       Cache<MinorKey, IntMinorValue>& c,
     241                                       int characteristic);
    241242
    242243        /**
     
    250251        * @see MinorProcessor::getMinorPrivate (const int, const MinorKey&, const bool, Cache<MinorKey, MinorValue>&)
    251252        */
    252         IntMinorValue getMinorPrivate (const int k, const MinorKey& mk);
     253        IntMinorValue getMinorPrivate (const int k, const MinorKey& mk, int characteristic);
    253254    protected:
    254255        bool isEntryZero (const int absoluteRowIndex, const int absoluteColumnIndex) const;
     
    284285        * @see MinorProcessor::getMinor (const int, const int*, const int*, Cache<MinorKey, MinorValue>&)
    285286        */
    286         IntMinorValue getMinor (const int dimension, const int* rowIndices, const int* columnIndices);
     287        IntMinorValue getMinor (const int dimension, const int* rowIndices, const int* columnIndices, const int characteristic);
    287288
    288289        /**
     
    299300        */
    300301        IntMinorValue getMinor (const int dimension, const int* rowIndices, const int* columnIndices,
    301                                  Cache<MinorKey, IntMinorValue>& c);
     302                                 Cache<MinorKey, IntMinorValue>& c, const int characteristic);
    302303
    303304        /**
     
    311312        * @see MinorProcessor::hasNextMinor ()
    312313        */
    313         IntMinorValue getNextMinor ();
     314        IntMinorValue getNextMinor (const int characteristic);
    314315
    315316        /**
     
    324325        * @see MinorProcessor::hasNextMinor ()
    325326        */
    326         IntMinorValue getNextMinor (Cache<MinorKey, IntMinorValue>& c);
     327        IntMinorValue getNextMinor (Cache<MinorKey, IntMinorValue>& c, const int characteristic);
    327328
    328329        /**
  • Singular/TestMinors.cc

    r70f63a r95a6f3  
    6969  PrintS("\nweight of the cache equals the total number of monomials counted over");
    7070  PrintS("\nall cached polynomials.)");
    71   PrintS("\nFor this command, there will be no file or console outputs.\n\n");
     71  PrintS("\nFor this command, there will be no file or console outputs.");
     72  PrintS("\n\nType 'ideal i = system(\"minors\", m, k, strategy, nCache, wCache, ch);'");
     73  PrintS("\nto obtain the ideal generated by all k x k non-zero minors of the");
     74  PrintS("\ninteger matrix m modulo ch. (For the remaining parameters, see the");
     75  PrintS("\nprevious call.)\n\n");
    7276}
    7377
     
    409413}
    410414
     415ideal testAllIntMinorsAsIdeal(matrix mat, int minorSize, int strategy, int cacheEntries, int cacheWeight, int characteristic)
     416{
     417    // counters + auxiliary stuff
     418  int totalMultiplications = 0;
     419  int totalAdditions = 0;
     420  int totalMultiplicationsAccumulated = 0;
     421  int totalAdditionsAccumulated = 0;
     422  char h[30];
     423
     424  int rowCount = mat->nrows;
     425  int columnCount = mat->ncols;
     426
     427  int* myPolyMatrix = (int*)(mat->m);
     428  IntMinorProcessor mp;
     429  mp.defineMatrix(rowCount, columnCount, myPolyMatrix);
     430
     431  /* The next lines are for defining the sub-matrix of myPolyMatrix
     432     from which we want to compute all k x k - minors.
     433     In the given setting, we want the entire matrix to form the sub-matrix. */
     434  int minorRows = rowCount;
     435  int minorColumns = columnCount;
     436  int myRowIndices[minorRows];  for (int i = 0; i < minorRows; i++) myRowIndices[i] = i;
     437  int myColumnIndices[minorColumns]; for (int i = 0; i < minorColumns; i++) myColumnIndices[i] = i;
     438
     439  // setting sub-matrix and size of minors of interest within that sub-matrix:
     440  mp.defineSubMatrix(minorRows, myRowIndices, minorColumns, myColumnIndices);
     441  mp.setMinorSize(minorSize);
     442
     443  // containers for all upcoming results
     444  IntMinorValue theMinor;
     445  int theValue;
     446  ideal iii = idInit(1, 0);
     447
     448  if (strategy == 0)
     449  {
     450    PrintLn(); PrintS("new code uses no cache");
     451    // iteration over all minors of size "minorSize x minorSize"
     452    while (mp.hasNextMinor()) {
     453      // retrieving the minor:
     454      theMinor = mp.getNextMinor(characteristic);
     455      theValue = theMinor.getResult();
     456      totalMultiplicationsAccumulated += theMinor.getAccumulatedMultiplications();
     457      totalMultiplications += theMinor.getMultiplications();
     458      totalAdditionsAccumulated += theMinor.getAccumulatedAdditions();
     459      totalAdditions += theMinor.getAdditions();
     460      idInsertPoly(iii, pISet(theValue)); // will include theValue only if it is not zero
     461    }
     462  }
     463  else
     464  {
     465    PrintLn(); PrintS("new code uses cache with caching strategy ");
     466    sprintf(h, "%d", strategy); PrintS(h);
     467    MinorValue::SetRankingStrategy(strategy);
     468    Cache<MinorKey, IntMinorValue> cch(cacheEntries, cacheWeight);
     469    // iteration over all minors of size "minorSize x minorSize"
     470    while (mp.hasNextMinor()) {
     471      // retrieving the minor:
     472      theMinor = mp.getNextMinor(cch, characteristic);
     473      theValue = theMinor.getResult();
     474      totalMultiplicationsAccumulated += theMinor.getAccumulatedMultiplications();
     475      totalMultiplications += theMinor.getMultiplications();
     476      totalAdditionsAccumulated += theMinor.getAccumulatedAdditions();
     477      totalAdditions += theMinor.getAdditions();
     478      idInsertPoly(iii, pISet(theValue)); // will include theValue only if it is not zero
     479    }
     480  }
     481  idSkipZeroes(iii);  // remove zero generators (resulting from block-wise allocation of memory)
     482
     483  PrintLn(); PrintS("numbers of performed operations");
     484  PrintLn(); PrintS("   multiplications: ");
     485  sprintf(h, "%d", totalMultiplications); PrintS(h);
     486  PrintLn(); PrintS("   additions: ");
     487  sprintf(h, "%d", totalAdditions); PrintS(h);
     488  PrintLn(); PrintS("   (multiplications without cache would be: ");
     489  sprintf(h, "%d", totalMultiplicationsAccumulated); PrintS(h); PrintS(")");
     490  PrintLn(); PrintS("   (additions without cache would be: ");
     491  sprintf(h, "%d", totalAdditionsAccumulated); PrintS(h); PrintS(")");
     492  PrintLn(); PrintLn();
     493
     494  return iii;
     495}
     496
    411497/**
    412498* A method for testing the computation of one minor; without and with cache, respectively.<br>
     
    442528    prpr << "Results - " << testHeader << " - no cache";
    443529    start = clock();
    444     IntMinorValue mv = mp.getMinor(minorSize, myRowIndices, myColumnIndices);
     530    IntMinorValue mv = mp.getMinor(minorSize, myRowIndices, myColumnIndices, 0);
    445531    end = clock();
    446532    ++prpr << "value of minor = " << mv.toString();
     
    459545        IntMinorValue::SetRankingStrategy(strategy);
    460546        start = clock();
    461         mv = mp.getMinor(minorSize, myRowIndices, myColumnIndices, cch);
     547        mv = mp.getMinor(minorSize, myRowIndices, myColumnIndices, cch, 0);
    462548        end = clock();
    463549
     
    526612    while (mp.hasNextMinor()) {
    527613        // retrieving the minor:
    528         theMinor = mp.getNextMinor();
     614        theMinor = mp.getNextMinor(0);
    529615        printTimeStart = clock();
    530616
     
    587673        while (mp.hasNextMinor()) {
    588674            // retrieving the minor:
    589             theMinor = mp.getNextMinor(cch);
     675            theMinor = mp.getNextMinor(cch, 0);
    590676            printTimeStart = clock();
    591677
     
    697783
    698784        // retrieving the minor:
    699         theMinor = mp.getNextMinor();
     785        theMinor = mp.getNextMinor(0);
    700786        printTimeStart = clock();
    701787        minorFound = (checkForEquality ? (theMinor.getResult() == targetMinor) : (theMinor.getResult() != targetMinor));
     
    748834
    749835            // retrieving the minor:
    750             theMinor = mp.getNextMinor(cch);
     836            theMinor = mp.getNextMinor(cch, 0);
    751837            printTimeStart = clock();
    752838            minorFound = (checkForEquality ? (theMinor.getResult() == targetMinor) : (theMinor.getResult() != targetMinor));
  • Singular/TestMinors.h

    r70f63a r95a6f3  
    1212                      int dumpMinors, int dumpResults, int dumpComplete, int dumpConsole);
    1313ideal testAllPolyMinorsAsIdeal(matrix m, int minorSize, int strategy, int cacheEntries, int cacheWeight);
     14ideal testAllIntMinorsAsIdeal(matrix m, int minorSize, int strategy, int cacheEntries, int cacheWeight, int characteristic);
    1415void testStuff (const poly p);
    1516
  • Singular/extra.cc

    r70f63a r95a6f3  
    22*  Computer Algebra System SINGULAR      *
    33*****************************************/
    4 /* $Id: extra.cc,v 1.324 2009-10-09 09:05:18 seelisch Exp $ */
     4/* $Id: extra.cc,v 1.325 2009-10-09 13:46:30 seelisch Exp $ */
    55/*
    66* ABSTRACT: general interface to internals of Singular ("system" command)
     
    21472147            // starts the computation of all k x k minors in the
    21482148            // provided matrix m (which is assumed to have polynomial
    2149             // entries) using a cache with 200 entries and a maximum total
    2150             // number of 10000 cached monomials;
     2149            // entries);
    21512150            // when calling this method, a ring must be declared before;
    2152             // there will be a run without using a cache; afterwards all 5
    2153             // caching strategies will be run
     2151            // there will be one run using a cache with specified properties
     2152          res->rtyp = IDEAL_CMD;
     2153          res->data = iii;
     2154        }
     2155        else if ((h->Typ() == MATRIX_CMD) &&
     2156                 (h->next->Typ() == INT_CMD) &&
     2157                 (h->next->next->Typ() == INT_CMD) &&
     2158                 (h->next->next->next->Typ() == INT_CMD) &&
     2159                 (h->next->next->next->next->Typ() == INT_CMD) &&
     2160                 (h->next->next->next->next->next->Typ() == INT_CMD) &&
     2161                 (h->next->next->next->next->next->next == NULL))
     2162        {
     2163          const matrix m           = (const matrix)h->Data();
     2164          const int k              = (const int)(long)h->next->Data();
     2165          const int strategy       = (const int)(long)h->next->next->Data();
     2166          const int cacheEntries   = (const int)(long)h->next->next->next->Data();
     2167          const int cacheWeight    = (const int)(long)h->next->next->next->next->Data();
     2168          const int characteristic = (const int)(long)h->next->next->next->next->next->Data();
     2169          ideal iii = testAllIntMinorsAsIdeal(m, k, strategy, cacheEntries, cacheWeight, characteristic);
     2170            // starts the computation of all k x k minors in the
     2171            // provided matrix m (which is assumed to have integer
     2172            // entries);
     2173            // when calling this method, a ring must be declared before;
     2174            // there will be one run using a cache with specified properties;
     2175            // the resulting minors will be computed modulo the given characteristic
    21542176          res->rtyp = IDEAL_CMD;
    21552177          res->data = iii;
     
    21622184                 (h->next->next->next->next->next->Typ() == INT_CMD) &&
    21632185                 (h->next->next->next->next->next->next->Typ() == INT_CMD) &&
    2164                  (h->next->next->next->next->next->next->next->Typ() == INT_CMD))
     2186                 (h->next->next->next->next->next->next->next->Typ() == INT_CMD) &&
     2187                 (h->next->next->next->next->next->next->next->next == NULL))
    21652188        {
    21662189          const matrix m           = (const matrix)h->Data();
Note: See TracChangeset for help on using the changeset viewer.