Changeset c616d1 in git for Singular/ideals.cc


Ignore:
Timestamp:
Sep 30, 1998, 4:12:48 PM (26 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
d3e295ae509633cf6ba993a8680945f24b9ab5ec
Parents:
8f14736613d731d65fa80a0322e2debe3dd2a3b0
Message:
hannes/pohl: minor fix


git-svn-id: file:///usr/local/Singular/svn/trunk@2529 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/ideals.cc

    r8f1473 rc616d1  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: ideals.cc,v 1.37 1998-09-29 21:14:43 siebert Exp $ */
     4/* $Id: ideals.cc,v 1.38 1998-09-30 14:12:47 Singular Exp $ */
    55/*
    66* ABSTRACT - all basic methods to manipulate ideals
     
    2525
    2626
     27// #define WITH_OLD_MINOR
     28
    2729static poly * idpower;
    2830/*collects the monomials in makemonoms, must be allocated befor*/
     
    3739* initialise an ideal
    3840*/
    39 #ifdef MDEBUG
     41#ifdef PDEBUG
    4042ideal idDBInit(int idsize, int rank, char *f, int l)
    4143#else
     
    4446{
    4547  /*- initialise an ideal -*/
    46 #ifdef MDEBUG
     48#if defined(MDEBUG) && defined(PDEBUG)
    4749  ideal hh = (ideal )mmDBAllocBlock(sizeof(*hh),f,l);
    4850#else
     
    5456  if (idsize>0)
    5557  {
    56 #ifdef MDEBUG
     58#if defined(MDEBUG) && defined(PDEBUG)
    5759    hh->m = (poly *)mmDBAllocBlock0(idsize*sizeof(poly),f,l);
    5860#else
     
    8688* deletes an ideal/matrix
    8789*/
    88 #ifdef MDEBUG
     90#ifdef PDEBUG
    8991void idDBDelete (ideal* h, char *f, int l)
    9092#else
     
    100102    do
    101103    {
    102       #ifdef MDEBUG
     104      #ifdef PDEBUG
    103105      pDBDelete(&((*h)->m[--j]),f,l);
    104106      #else
     
    107109    }
    108110    while (j>0);
    109     #ifdef MDEBUG
     111    #if defined(MDEBUG) && defined(PDEBUG)
    110112    mmDBFreeBlock((ADDRESS)((*h)->m),sizeof(poly)*elems,f,l);
    111113    #else
     
    113115    #endif
    114116  }
    115   #ifdef MDEBUG
     117  #if defined(MDEBUG) && defined(PDEBUG)
    116118  mmDBFreeBlock((ADDRESS)(*h),sizeof(**h),f,l);
    117119  #else
     
    298300* copy an ideal
    299301*/
    300 #ifdef MDEBUG
     302#ifdef PDEBUG
    301303ideal idDBCopy(ideal h1,char *f,int l)
    302304#else
     
    310312  if (h1 == NULL)
    311313  {
    312 #ifdef MDEBUG
     314#ifdef PDEBUG
    313315    h2=idDBInit(1,1,f,l);
    314316#else
     
    319321//#endif
    320322  {
    321 #ifdef MDEBUG
     323#ifdef PDEBUG
    322324    h2=idDBInit(IDELEMS(h1),h1->rank,f,l);
    323325#else
     
    325327#endif
    326328    for (i=IDELEMS(h1)-1; i>=0; i--)
    327 #ifdef MDEBUG
     329#ifdef PDEBUG
    328330      h2->m[i] = pDBCopy(h1->m[i],f,l);
    329331#else
     
    22682270}
    22692271
     2272//void idEnterSet (poly p,ideal r, int * next)
     2273//{
     2274//
     2275//  if ((*next) == IDELEMS(r)-1)
     2276//  {
     2277//    pEnlargeSet(&(r->m),IDELEMS(r),16);
     2278//    IDELEMS(r)+=16;
     2279//  }
     2280//  int at;
     2281//  int i;
     2282//  if (*next==0) at=0;
     2283//  else
     2284//  {
     2285//    int an = 0;
     2286//    int en= *next-1;
     2287//    int c;
     2288//    if (pComp0(r->m[(*next)-1],p)!= 1)
     2289//      at=*next;
     2290//    else
     2291//    {
     2292//      loop
     2293//      {
     2294//        if (an >= en-1)
     2295//        {
     2296//          if (pComp0(r->m[an],p) == 1)
     2297//          {
     2298//            at=an; break;
     2299//          }
     2300//          else
     2301//          {
     2302//            at=en; break;
     2303//          }
     2304//        }
     2305//        i=(an+en) / 2;
     2306//        if (pComp0(r->m[i],p) == 1) en=i;
     2307//        else                       an=i;
     2308//      }
     2309//    }
     2310//  }
     2311//  if (pComp(r->m[at],p)==0)
     2312//  {
     2313//    pDelete(&p);
     2314//  }
     2315//  else
     2316//  {
     2317//    (*next)++;
     2318//    for (i=(*next); i>=at+1; i--)
     2319//    {
     2320//      r->m[i] = r->m[i-1];
     2321//    }
     2322//    /*- save result -*/
     2323//    r->m[at] = p;
     2324//  }
     2325//}
    22702326/*3
    22712327* produces recursively the ideal of all arxar-minors of a
     
    22782334  if((ar<0) || (ar>min(a->ncols,a->nrows)-1))
    22792335  {
     2336    idDelete((ideal *)&a);
     2337    pDelete(barDiv);
    22802338    return;
    22812339  }
     
    22832341/*--- initializing temporary structures-------------------*/
    22842342  int i,j,r=rowToChose,c,newi,newp,k;
    2285   poly p=NULL,pp;
     2343  poly p=NULL;
    22862344
    22872345  if (ar==0)
     
    22952353        if (p!=NULL)
    22962354        {
     2355          //idEnterSet(p,result,nextPlace);
    22972356          if (*nextPlace>=IDELEMS(result))
    22982357          {
    2299             pEnlargeSet(&(result->m),IDELEMS(result),16);
    2300             IDELEMS(result) += 16;
     2358            pEnlargeSet(&(result->m),IDELEMS(result),IDELEMS(result));
     2359            IDELEMS(result) *=2;
    23012360          }
    2302           MATELEM(a,i,j) = NULL;
    23032361          result->m[*nextPlace] = p;
    23042362          (*nextPlace)++;
     2363          MATELEM(a,i,j) = NULL;
    23052364        }
    23062365      }
     
    23082367    idTest(result);
    23092368    idDelete((ideal*)&a);
     2369    pDelete(barDiv);
    23102370    return;
    23112371  }
    23122372/*--- ar>0, we perform one step of the Bareiss algorithm--*/
    23132373  p = pCopy(*barDiv);   //we had to store barDiv for the remaining loops
    2314   pp = pCopy(p);   //we had to store barDiv for the remaining loops
    23152374  matrix nextStep = mpOneStepBareiss(a,barDiv,&r,&c);
    23162375//Print("next row is: %d, next col: %d\n",r,c);
    2317 /*--- there is no pivot - the matrix is zero -------------*/
     2376/*--- there is no pivot - the det of matrix is zero -------------*/
    23182377  if ((r*c==0) || (MATELEM(nextStep,nextStep->nrows,nextStep->ncols)==NULL))
    23192378  {
     2379    idDelete((ideal*)&nextStep);
    23202380    idDelete((ideal*)&a);
    2321     idDelete((ideal*)&nextStep);
     2381    pDelete(&p);
     2382    // pDelete(barDiv); barDiv==NULL in this case
    23222383    return;
    23232384  }
     
    23392400    next = NULL;
    23402401  }
     2402  if ((*barDiv)!=NULL) pDelete(barDiv);
    23412403/*--- now we have to take out the r-th row...------------*/
    23422404  if (((a->nrows)>1) && (rowToChose==0))
    23432405  {
     2406    if (nextStep!=NULL) idDelete((ideal*)&nextStep);
    23442407    nextStep = mpNew(a->nrows-1,a->ncols);
    23452408    for (i=r-1;i>0;i--)
     
    23582421    }
    23592422/*--- and to perform the algorithm with the rest---------*/
    2360     idRecMin(nextStep,ar,&p,result,nextPlace);
     2423    poly q=pCopy(p);
     2424    idRecMin(nextStep,ar,&q,result,nextPlace);
     2425    assume(q==NULL);
    23612426    nextStep = NULL;
    23622427  }
     
    23642429  if ((a->nrows)>1)
    23652430  {
     2431    if (nextStep!=NULL) idDelete((ideal*)&nextStep);
    23662432    nextStep = mpNew(a->nrows,a->ncols-1);
    23672433    for (i=a->nrows;i>0;i--)
     
    23842450    idDelete((ideal*)&a);
    23852451    idRecMin(nextStep,ar,&p,result,nextPlace,r);
     2452    //assume(p==NULL);
    23862453    nextStep = NULL;
    23872454  }
    23882455/*--- deleting temporary structures and returns----------*/
    2389   pDelete(barDiv);
    23902456  pDelete(&p);
    2391   pDelete(&pp);
    23922457  return;
    23932458}
    23942459
     2460#ifdef WITH_OLD_MINOR
     2461/*2
     2462* compute all ar-minors of the matrix a
     2463*/
     2464ideal idMinors(matrix a, int ar)
     2465{
     2466  int     i,j,k,size;
     2467  int *rowchoise,*colchoise;
     2468  BOOLEAN rowch,colch;
     2469  ideal result;
     2470  matrix tmp;
     2471  poly p;
     2472
     2473  i = binom(a->rows(),ar);
     2474  j = binom(a->cols(),ar);
     2475
     2476  rowchoise=(int *)Alloc(ar*sizeof(int));
     2477  colchoise=(int *)Alloc(ar*sizeof(int));
     2478  if ((i>512) || (j>512) || (i*j >512)) size=512;
     2479  else size=i*j;
     2480  result=idInit(size,1);
     2481  tmp=mpNew(ar,ar);
     2482  k = 0; /* the index in result*/
     2483  idInitChoise(ar,1,a->rows(),&rowch,rowchoise);
     2484  while (!rowch)
     2485  {
     2486    idInitChoise(ar,1,a->cols(),&colch,colchoise);
     2487    while (!colch)
     2488    {
     2489      for (i=1; i<=ar; i++)
     2490      {
     2491        for (j=1; j<=ar; j++)
     2492        {
     2493          MATELEM(tmp,i,j) = MATELEM(a,rowchoise[i-1],colchoise[j-1]);
     2494        }
     2495      }
     2496      p = mpDetBareiss(tmp);
     2497      if (p!=NULL)
     2498      {
     2499        if (k>=size)
     2500        {
     2501          pEnlargeSet(&result->m,size,32);
     2502          size += 32;
     2503        }
     2504        result->m[k] = p;
     2505        k++;
     2506      }
     2507      idGetNextChoise(ar,a->cols(),&colch,colchoise);
     2508    }
     2509    idGetNextChoise(ar,a->rows(),&rowch,rowchoise);
     2510  }
     2511  /*delete the matrix tmp*/
     2512  for (i=1; i<=ar; i++)
     2513  {
     2514    for (j=1; j<=ar; j++) MATELEM(tmp,i,j) = NULL;
     2515  }
     2516  idDelete((ideal*)&tmp);
     2517  if (k==0)
     2518  {
     2519    k=1;
     2520    result->m[0]=NULL;
     2521  }
     2522  Free((ADDRESS)rowchoise,ar*sizeof(int));
     2523  Free((ADDRESS)colchoise,ar*sizeof(int));
     2524  pEnlargeSet(&result->m,size,k-size);
     2525  IDELEMS(result) = k;
     2526  return (result);
     2527}
     2528#else
    23952529/*2
    23962530* compute all ar-minors of the matrix a
     
    24072541  poly barDiv=NULL;
    24082542  ideal result=idInit(16,1);
    2409 
    2410   idRecMin(mpCopy(a),ar-1,&barDiv,result,&i);
     2543  if (a->ncols>=a->nrows)
     2544  {
     2545    idRecMin(mpCopy(a),ar-1,&barDiv,result,&i);
     2546  }
     2547  else
     2548  {
     2549    idRecMin(mpTransp(a),ar-1,&barDiv,result,&i);
     2550  }
    24112551  idSkipZeroes(result);
    24122552  return result;
    24132553}
     2554#endif
     2555
    24142556
    24152557/*2
Note: See TracChangeset for help on using the changeset viewer.