Changeset 2024f6a in git


Ignore:
Timestamp:
May 24, 2011, 2:15:59 PM (13 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'spielwiese', '2a584933abf2a2d3082034c7586d38bb6de1a30a')
Children:
db33b222f62ceda81505d77c37cc004904d921ba
Parents:
fab2cca2c0bc1394ddf0712513e994b18368d0f1
Message:
added minpoly code by Sebastian Jambor, accessable through extra.cc

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

Legend:

Unmodified
Added
Removed
  • Singular/extra.cc

    rfab2cca r2024f6a  
    5757#include <kernel/mpr_complex.h>
    5858#include <kernel/ffields.h>
     59#include <Singular/minpoly.h>
    5960
    6061#ifdef HAVE_RINGS
     
    176177static int PyInitialized = 0;
    177178#endif
     179
     180/* expects a SINGULAR square matrix with number entries
     181   where currRing is expected to be over some field F_p;
     182   returns a long** matrix with the "same", i.e.,
     183   appropriately mapped entries;
     184   leaves singularMatrix unmodified */
     185unsigned long** singularMatrixToLongMatrix(matrix singularMatrix)
     186{
     187  int n = singularMatrix->rows();
     188  assume(n == singularMatrix->cols());
     189  unsigned long **longMatrix = 0;
     190  longMatrix = new unsigned long *[n] ;
     191  for (int i = 0 ; i < n; i++)
     192    longMatrix[i] = new unsigned long [n];
     193  number entry;
     194  for (int r = 0; r < n; r++)
     195    for (int c = 0; c < n; c++)
     196    {
     197      entry = p_GetCoeff(MATELEM(singularMatrix, r + 1, c + 1), currRing);
     198      int entryAsInt = n_Int(entry, currRing);
     199      if (entryAsInt < 0) entryAsInt += currRing->ch;
     200      longMatrix[r][c] = (unsigned long)entryAsInt;
     201    }
     202  return longMatrix;
     203}
     204
     205/* expects an array of unsigned longs with valid indices 0..degree;
     206   returns the following poly, where x denotes the first ring variable
     207   of currRing, and d = degree:
     208      polyCoeffs[d] * x^d + polyCoeffs[d-1] * x^(d-1) + ... + polyCoeffs[0]
     209   leaves polyCoeffs unmodified */
     210poly longCoeffsToSingularPoly(unsigned long *polyCoeffs, const int degree)
     211{
     212  poly result = NULL;
     213  for (int i = 0; i <= degree; i++)
     214  {
     215    if ((int)polyCoeffs[i] != 0)
     216    {
     217      poly term = p_ISet((int)polyCoeffs[i], currRing);
     218      if (i > 0)
     219      {
     220        p_SetExp(term, 1, i, currRing);
     221        p_Setm(term, currRing);
     222      }
     223      result = p_Add_q(result, term, currRing);
     224    }
     225  }
     226  return result;
     227}
    178228
    179229//void emStart();
     
    27152765      else
    27162766  #endif
     2767  /*==== connection to Sebastian Jambor's code ======*/
     2768  /* This code connects Sebastian Jambor's code for
     2769     computing the minimal polynomial of an (n x n) matrix
     2770     with entries in F_p to SINGULAR. Two conversion methods
     2771     are needed; see further up in this file:
     2772        (1) conversion of a matrix with long entries to
     2773            a SINGULAR matrix with number entries, where
     2774            the numbers are coefficients in currRing;
     2775        (2) conversion of an array of longs (encoding the
     2776            coefficients of the minimal polynomial) to a
     2777            SINGULAR poly living in currRing. */
     2778      if (strcmp(sys_cmd, "minpoly") == 0)
     2779      {
     2780        if ((h == NULL) || (h->Typ() != MATRIX_CMD) || h->next != NULL)
     2781        {
     2782          Werror("expected exactly one argument: %s",
     2783                 "a square matrix with number entries");
     2784          return TRUE;
     2785        }
     2786        else
     2787        {
     2788          matrix m = (matrix)h->Data();
     2789          int n = m->rows();
     2790          unsigned long p = (unsigned long)currRing->ch;
     2791          if (n != m->cols())
     2792          {
     2793            Werror("expected exactly one argument: %s",
     2794                   "a square matrix with number entries");
     2795            return TRUE;
     2796          }
     2797          unsigned long** ml = singularMatrixToLongMatrix(m);
     2798          unsigned long* polyCoeffs = computeMinimalPolynomial(ml, n, p);
     2799          poly theMinPoly = longCoeffsToSingularPoly(polyCoeffs, n);
     2800          res->rtyp = POLY_CMD;
     2801          res->data = (void *)theMinPoly;
     2802          for (int i = 0; i < n; i++) delete[] ml[i];
     2803          delete[] ml;
     2804          delete[] polyCoeffs;
     2805          return FALSE;
     2806        }
     2807      }
     2808      else
    27172809  /*==================== sdb_flags =================*/
    27182810  #ifdef HAVE_SDB
Note: See TracChangeset for help on using the changeset viewer.