Changeset 5812c69 in git


Ignore:
Timestamp:
Sep 24, 1998, 11:59:51 AM (25 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '8d54773d6c9e2f1d2593a28bc68b7eeab54ed529')
Children:
56c52a7879fbc6de62cefba1da86b2edf2aadd4c
Parents:
073d2edeb03013a5c6ed0913687b024305a1427d
Message:
cosmetic changes


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

Legend:

Unmodified
Added
Removed
  • Singular/LIB/primdec.lib

    r073d2e r5812c69  
    1 // $Id: primdec.lib,v 1.25 1998-08-05 11:12:32 Singular Exp $
     1// $Id: primdec.lib,v 1.26 1998-09-24 09:59:51 Singular Exp $
    22////////////////////////////////////////////////////////////////////////////////
    33// primdec.lib                                                                //
     
    1111////////////////////////////////////////////////////////////////////////////////
    1212
    13 version="$Id: primdec.lib,v 1.25 1998-08-05 11:12:32 Singular Exp $";
     13version="$Id: primdec.lib,v 1.26 1998-09-24 09:59:51 Singular Exp $";
    1414info="
    1515LIBRARY: primdec.lib: PROCEDURE FOR PRIMARY DECOMPOSITION
     
    383383   if(size(k1)==size(k2))
    384384   {
    385       for(j=1;j<=size(k1);j++)
     385      for(j=size(k1);j>0;j--)
    386386      {
    387387         if(leadexp(k1[j])!=leadexp(k2[j]))
     
    401401   if(size(k1)==size(k2))
    402402   {
    403       for(j=1;j<=size(k1);j++)
     403      for(j=size(k1);j>0;j--)
    404404      {
    405405         if(leadexp(k1[j])!=leadexp(k2[j]))
  • Singular/clapconv.cc

    r073d2e r5812c69  
    33*  Computer Algebra System SINGULAR     *
    44****************************************/
    5 // $Id: clapconv.cc,v 1.17 1998-04-27 14:47:01 Singular Exp $
     5// $Id: clapconv.cc,v 1.18 1998-09-24 09:59:34 Singular Exp $
    66/*
    77* ABSTRACT: convert data between Singular and factory
     
    164164    {
    165165      result = pAdd( result, term );
    166     } 
     166    }
    167167  }
    168168}
  • Singular/claptmpl.cc

    r073d2e r5812c69  
    33*  Computer Algebra System SINGULAR     *
    44****************************************/
    5 // $Id: claptmpl.cc,v 1.17 1998-06-30 16:30:05 schmidt Exp $
     5// $Id: claptmpl.cc,v 1.18 1998-09-24 09:59:35 Singular Exp $
    66/*
    77* ABSTRACT - instantiation of all templates
     
    9494{
    9595    if ( this != &f ) {
    96         _factor = f._factor;
    97         _exp = f._exp;
     96        _factor = f._factor;
     97        _exp = f._exp;
    9898    }
    9999    return *this;
  • Singular/cntrlc.cc

    r073d2e r5812c69  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: cntrlc.cc,v 1.19 1998-07-30 17:49:15 Singular Exp $ */
     4/* $Id: cntrlc.cc,v 1.20 1998-09-24 09:59:36 Singular Exp $ */
    55/*
    66* ABSTRACT - interupt handling
     
    6262BOOLEAN siCntrlc = FALSE;
    6363
     64typedef void (*si_hdl_typ)(int);
     65
    6466/*0 implementation*/
    6567#ifndef MSDOS
     
    6769#ifndef macintosh
    6870/* signals are not right implemented in macintosh */
    69 typedef void (*si_hdl_typ)(int);
    7071void sigint_handler(int sig);
    7172#endif
     
    124125  }
    125126#endif
    126 #ifdef HAVE_FEREAD
    127   fe_reset_input_mode();
    128 #endif
    129127#ifndef __OPTIMIZE__
    130128  if (sig!=SIGINT) debug(INTERACTIVE);
     
    216214    PrintS("cannot set signal handler for IOT\n");
    217215  }
     216#ifndef macintosh
    218217  if (SIG_ERR==signal(SIGINT ,sigint_handler))
    219218  {
    220219    PrintS("cannot set signal handler for INT\n");
    221220  }
     221#endif
    222222}
    223223
     
    245245    longjmp(si_start_jmpbuf,1);
    246246  }
    247 #endif
    248 #ifdef HAVE_FEREAD
    249   fe_reset_input_mode(0,NULL);
    250247#endif
    251248#ifndef __OPTIMIZE__
     
    292289    longjmp(si_start_jmpbuf,1);
    293290  }
    294 #endif
    295 #ifdef HAVE_FEREAD
    296 #ifdef HAVE_ATEXIT
    297   fe_reset_input_mode();
    298 #else
    299   fe_reset_input_mode(0,NULL);
    300 #endif
    301291#endif
    302292#ifdef unix
     
    439429//}
    440430//#endif
    441 
    442 #ifndef MSDOS
    443 // /*2
    444 // * test for SIGINT, start an interpreter
    445 // */
    446 // void test_int_std(leftv v)
    447 // {
    448 // #ifndef macintosh
    449 // //#ifdef macintosh
    450 // //  beachball();
    451 // //#endif
    452 //   if (siCntrlc>1)
    453 //   {
    454 //     int saveecho = si_echo;
    455 //     siCntrlc = FALSE;
    456 //     signal(SIGINT ,sigint_handler);
    457 // //#ifdef macintosh
    458 // //    flush_intr();
    459 // //#endif
    460 //     //si_echo = 2;
    461 //     printf("\n//inside a computation, continue with `exit;`\n");
    462 //     iiPStart("STDIN","STDIN",NULL);
    463 //     si_echo = saveecho;
    464 //   }
    465 // #endif
    466 // }
    467 #endif
    468431
    469432#ifndef MSDOS
  • Singular/comm.cc

    r073d2e r5812c69  
    5252      delete(res);
    5353    }
    54    
     54
    5555  Free((ADDRESS)Warteliste,(Wartelistemax)*sizeof(LObject));
    5656}
     
    135135//   PrintS("Restore\n");
    136136  if(DEBUG) PrintS("Restore\n");
    137  
     137
    138138  int i = 0;
    139139  int l = 0;
     
    141141    {
    142142      while(i<aktuell)
    143         {
    144           l = strat->posInL(strat->L,strat->Ll,Warteliste[i],strat);
    145           enterL(&(strat->L),&(strat->Ll),&(strat->Lmax),Warteliste[i++],l);
    146         }
    147      
     143        {
     144          l = strat->posInL(strat->L,strat->Ll,Warteliste[i],strat);
     145          enterL(&(strat->L),&(strat->Ll),&(strat->Lmax),Warteliste[i++],l);
     146        }
     147
    148148      aktuell=0;
    149149      return TRUE;
     
    180180      lv->rtyp = INTVEC_CMD;
    181181      switch(msg)
    182         {
    183 
    184         case MsgTupel:
    185           for(i=0; i<pVariables; i++)
    186             exp[i+1]=pGetExp(strat->P.p, i+1);
    187           break;
    188 
    189         case MsgTupelPosition:
    190           for(i=0; i<pVariables; i++)
    191             exp[i+1]=0;
    192 
    193           // Neue Position von strat->P.p bestimmen
    194           pos=-1;
    195           for(i=strat->Ll-1; i>=0; i--)
    196             {
    197               if((strat->L[i].p1 == strat->P.p1) && (strat->L[i].p2 == strat->P.p2))
    198                 {
    199                   pos = i;
    200                   continue;
    201                 }
    202             }
    203           exp[1]=pos;
    204           break;
    205 
    206         default:
    207           for(i=0; i<pVariables; i++)
    208             exp[i+1]=0;
    209           break;
    210         }
     182        {
     183
     184        case MsgTupel:
     185          for(i=0; i<pVariables; i++)
     186            exp[i+1]=pGetExp(strat->P.p, i+1);
     187          break;
     188
     189        case MsgTupelPosition:
     190          for(i=0; i<pVariables; i++)
     191            exp[i+1]=0;
     192
     193          // Neue Position von strat->P.p bestimmen
     194          pos=-1;
     195          for(i=strat->Ll-1; i>=0; i--)
     196            {
     197              if((strat->L[i].p1 == strat->P.p1) && (strat->L[i].p2 == strat->P.p2))
     198                {
     199                  pos = i;
     200                  continue;
     201                }
     202            }
     203          exp[1]=pos;
     204          break;
     205
     206        default:
     207          for(i=0; i<pVariables; i++)
     208            exp[i+1]=0;
     209          break;
     210        }
    211211      lv->data=ivCopy(&exp);
    212212      if(li==-1)
    213         {
    214           for(i=0; i< procnum; i++)
    215             if((*links)[i]!=NULL)
    216               slWrite((*links)[i], lv);
    217         }
     213        {
     214          for(i=0; i< procnum; i++)
     215            if((*links)[i]!=NULL)
     216              slWrite((*links)[i], lv);
     217        }
    218218      else
    219         {
    220           slWrite((*links)[li], lv);
    221         }
     219        {
     220          slWrite((*links)[li], lv);
     221        }
    222222      lv->CleanUp();
    223223      Free(lv,sizeof(sleftv));
     
    235235      intvec *rec = NULL;
    236236      if(DEBUG) PrintS("ReceiveMsg\n");
    237  
     237
    238238      leftv lv = NULL;
    239239      for(int i=0; i<procnum;i++)
    240         {
    241           lv=slRead((*links)[i]);
    242           rec=ivCopy((intvec *) lv->Data());
    243           if((*res)[i]!=NULL)
    244             {
    245               delete (*res)[i];
    246               (*res)[i]=NULL;
    247             }
    248           (*msg)[i] = (*rec)[0];
    249           if((stdMsg)(*msg)[i]==MsgTupel)
    250             {
    251               (*res)[i] = new intvec(pVariables,1,0);
    252               for(int j = 0; j<pVariables ; j++)
    253                 (*(*res)[i])[j]=(*rec)[j+1];
    254             }
    255         }
     240        {
     241          lv=slRead((*links)[i]);
     242          rec=ivCopy((intvec *) lv->Data());
     243           if((*res)[i]!=NULL)
     244             {
     245               delete (*res)[i];
     246               (*res)[i]=NULL;
     247             }
     248          (*msg)[i] = (*rec)[0];
     249          if((stdMsg)(*msg)[i]==MsgTupel)
     250            {
     251              (*res)[i] = new intvec(pVariables,1,0);
     252              for(int j = 0; j<pVariables ; j++)
     253                (*(*res)[i])[j]=(*rec)[j+1];
     254            }
     255        }
    256256        lv->CleanUp();
    257257        Free(lv, sizeof(sleftv));
     
    259259      delete rec;
    260260      if(DEBUG) PrintS("ReceiveMsg Ende\n");
    261       return TRUE; 
     261      return TRUE;
    262262    }
    263263}
     
    286286    case ModWrite:
    287287    case ModRun:  // Berechne und sende Tupel
    288       Verwaltung  = TRUE;     
    289       Receive     = FALSE;   
    290       TupelL      = TRUE;     
    291       SPoly       = TRUE;     
    292       Reduzieren  = TRUE;     
    293       TupelMelden = TRUE;     
    294       TupelTesten = FALSE;   
     288      Verwaltung  = TRUE;
     289      Receive     = FALSE;
     290      TupelL      = TRUE;
     291      SPoly       = TRUE;
     292      Reduzieren  = TRUE;
     293      TupelMelden = TRUE;
     294      TupelTesten = FALSE;
    295295      TupelPosition = TRUE;
    296       ResultSend  = FALSE;   
    297       TupelStore  = FALSE;   
     296      ResultSend  = FALSE;
     297      TupelStore  = FALSE;
    298298      break;
    299299    case ModStep:  // Warte auf MsgStep, berechne und sende
    300       Verwaltung  = TRUE;     
    301       Receive     = TRUE;   
    302       TupelL      = TRUE;     
    303       SPoly       = TRUE;     
    304       Reduzieren  = TRUE;     
    305       TupelMelden = TRUE;     
     300      Verwaltung  = TRUE;
     301      Receive     = TRUE;
     302      TupelL      = TRUE;
     303      SPoly       = TRUE;
     304      Reduzieren  = TRUE;
     305      TupelMelden = TRUE;
    306306      TupelPosition = TRUE;
    307       TupelTesten = FALSE;   
    308       ResultSend  = TRUE;   
    309       TupelStore  = FALSE;   
     307      TupelTesten = FALSE;
     308      ResultSend  = TRUE;
     309      TupelStore  = FALSE;
    310310      break;
    311311    case ModCalc: // Warte auf Tupel und berechne
    312       Verwaltung  = TRUE; 
    313       Receive     = TRUE;   
    314       TupelL      = TRUE;     
    315       TupelMelden = FALSE;   
     312      Verwaltung  = TRUE;
     313      Receive     = TRUE;
     314      TupelL      = TRUE;
     315      TupelMelden = FALSE;
    316316      TupelPosition = FALSE;
    317317      ResultSend  = TRUE;
    318318      TupelStore  = (*msg)[0]==MsgTupelisZero;
    319319      if(TupelStore)
    320         {
    321           SPoly      = FALSE;
    322           Reduzieren = FALSE;
    323           TupelTesten = FALSE;
    324         }
     320        {
     321           SPoly      = FALSE;
     322           Reduzieren = FALSE;
     323           TupelTesten = FALSE;
     324        }
    325325      else
    326         {
    327           SPoly      = TRUE; 
    328           Reduzieren = TRUE; 
    329           TupelTesten = TRUE;
    330         }
     326        {
     327          SPoly      = TRUE;
     328          Reduzieren = TRUE;
     329          TupelTesten = TRUE;
     330        }
    331331      break;
    332332    case ModPosition: // Tupel neu positionieren
    333       Verwaltung  = TRUE; 
    334       Receive     = TRUE;   
    335       TupelL      = TRUE;     
    336       TupelMelden = FALSE;   
     333      Verwaltung  = TRUE;
     334      Receive     = TRUE;
     335      TupelL      = TRUE;
     336      TupelMelden = FALSE;
    337337      TupelPosition = FALSE;
    338338      ResultSend  = TRUE;
     
    345345      Restore(strat);
    346346      if(strat->Ll>=0)
    347         {
    348           Verwaltung  = TRUE;
    349           Receive     = FALSE;
    350           TupelL      = TRUE;
    351           TupelStore  = FALSE;   
    352           SPoly       = TRUE;
    353           TupelMelden = FALSE;
    354           TupelPosition = FALSE;
    355           TupelTesten = FALSE;
    356           ResultSend  = TRUE;
    357           Reduzieren  = TRUE;
    358         }
     347        {
     348          Verwaltung  = TRUE;
     349          Receive     = FALSE;
     350          TupelL      = TRUE;
     351          TupelStore  = FALSE;
     352          SPoly       = TRUE;
     353          TupelMelden = FALSE;
     354          TupelPosition = FALSE;
     355          TupelTesten = FALSE;
     356          ResultSend  = TRUE;
     357          Reduzieren  = TRUE;
     358        }
    359359      else
    360         {
    361           SetModus(ModEnde,strat);
    362         }
     360        {
     361          SetModus(ModEnde,strat);
     362        }
    363363      break;
    364364    case ModEnde:  //sofort beenden
    365365      Verwaltung  = FALSE;
    366       Receive     = FALSE;   
    367       TupelWarte  = FALSE;   
    368       TupelL      = FALSE;   
    369       TupelStore  = FALSE;   
    370       TupelTesten = FALSE;   
    371       SPoly       = FALSE;   
    372       Reduzieren  = FALSE;   
    373       TupelMelden = FALSE;   
    374       ResultSend  = FALSE;   
     366      Receive     = FALSE;
     367      TupelWarte  = FALSE;
     368      TupelL      = FALSE;
     369      TupelStore  = FALSE;
     370      TupelTesten = FALSE;
     371      SPoly       = FALSE;
     372      Reduzieren  = FALSE;
     373      TupelMelden = FALSE;
     374      ResultSend  = FALSE;
    375375      break;
    376376    }
     
    396396    case ModCalc:   // Beenden erst dann, wenn Calc2 erreicht ist.
    397397      SetModus(ModCalc);
    398       if(strat->Ll<0) 
    399         {
    400           if(BTEST1(OPT_INTERRUPT))
    401             return TRUE;
    402           if(TEST_OPT_PROT)
     398      if(strat->Ll<0)
     399        {
     400          if(BTEST1(OPT_INTERRUPT))
     401            return TRUE;
     402          if(TEST_OPT_PROT)
    403403            {
    404               PrintS("\n<C>\n");
     404              PrintS("\n<C>\n");
    405405              writeTime("used time: #");
    406406            }
    407           SetModus(ModCheck,strat);
    408         }
    409         return FALSE;
     407           SetModus(ModCheck,strat);
     408        }
     409        return FALSE;
    410410      break;
    411411    case ModCheck:
     
    436436    {
    437437      if(strat->Ll != oldLl )
    438         {
    439           SendMsg(strat, MsgTupelPosition);
    440           TupelMelden = FALSE;
    441         }
    442     }
    443  
     438        {
     439          SendMsg(strat, MsgTupelPosition);
     440          TupelMelden = FALSE;
     441        }
     442    }
     443
    444444}
    445445
     
    460460//   PrintS("ParseMessage\n");
    461461  if(DEBUG) PrintS("ParseMessage\n");
    462   BOOLEAN err=FALSE; 
     462  BOOLEAN err=FALSE;
    463463  // Testen, ob alle Nachrichten korrekt sind,
    464464  // wenn ja, dann ParseMessageFinal
    465465  // sonst die richtige finden, andere Prozesse killen
    466  
     466
    467467  // Ist nur ein proc vorhanden, dann automatisch weiter
    468   for(int i=1; i< procnum; i++) 
     468  for(int i=1; i< procnum; i++)
    469469    err = err || ((*msg)[i] != (*msg)[0]);
    470470  if(!err)
     
    477477      // Unterschiedliche Tupel : In TupelDifferent alle abweichler killen
    478478      for(int i=0; i<procnum; i++)
    479         if(((stdMsg)(*msg)[i]) == MsgTupelisZero)
    480           {
    481             PrintS(" AAA ");
    482             KillChild(strat,i);
    483           }
     479        if(((stdMsg)(*msg)[i]) == MsgTupelisZero)
     480          {
     481            PrintS(" AAA ");
     482             KillChild(strat,i);
     483          }
    484484      ParseMessageFinal(strat);
    485485    }
     
    493493//   PrintS("ParseMessageFinal\n");
    494494  if(DEBUG) PrintS("ParseMessageFinal\n");
    495  
     495
    496496  switch(((stdMsg) (*msg)[i]))
    497497    {
    498     case MsgTupel:  // In Step-Modus schalten bzw. bleiben.     
     498    case MsgTupel:  // In Step-Modus schalten bzw. bleiben.
    499499    case MsgTupelisZero:
    500500
    501501       if(procnum>0)
    502         {
    503           SetModus(ModCalc,strat);
    504         }
     502         {
     503           SetModus(ModCalc,strat);
     504         }
    505505       else
    506         {
    507           SetModus(ModCheck,strat);
    508         }
     506         {
     507           SetModus(ModCheck,strat);
     508         }
    509509      break;
    510510    case MsgTupelPosition:
    511511      // aktuelles Tupel neu positionieren
    512512      if(TEST_OPT_PROT)
    513         PrintS("P");
     513        PrintS("P");
    514514      SetModus(ModPosition);
    515515      break;
    516      case MsgEnd:  // In Calc1-Modus schalten bzw. bleiben.     
     516     case MsgEnd:  // In Calc1-Modus schalten bzw. bleiben.
    517517       SetModus(ModCheck,strat);
    518518       if (TEST_OPT_PROT) PrintS("\n<E>");
     
    534534    {
    535535      if(strat->P.p==NULL)
    536         {
    537           PrintS(" BBB ");
    538           KillChild(strat,i);
    539         }
     536        {
     537          PrintS(" BBB ");
     538           KillChild(strat,i);
     539        }
    540540      else
    541         {
    542           if((*res)[i]==NULL)
    543             {
    544               PrintS(" CCC ");
    545               KillChild(strat,i);
    546             }
    547           else
    548             {
    549               Different = FALSE;
    550               for(int j=0; j< pVariables; j++)
    551                 {
    552                   Different = Different || ((*(*res)[i])[j]!=pGetExp(strat->P.p,j+1));
    553                 }
    554               if(Different)
    555                 {
    556                   PrintS(" DDD ");
    557                   KillChild(strat,i);
    558                 }
    559             }
    560         }
     541        {
     542          if((*res)[i]==NULL)
     543            {
     544              PrintS(" CCC ");
     545               KillChild(strat,i);
     546            }
     547          else
     548            {
     549              Different = FALSE;
     550              for(int j=0; j< pVariables; j++)
     551                {
     552                  Different = Different || ((*(*res)[i])[j]!=pGetExp(strat->P.p,j+1));
     553                }
     554              if(Different)
     555                {
     556                  PrintS(" DDD ");
     557                   KillChild(strat,i);
     558                }
     559            }
     560        }
    561561    }
    562562  if(procnum<=0)
     
    587587     {
    588588       if(procnum>=2)
    589         {
    590           si_link swaplink = (*links)[li];
    591           intvec *swapres = (*res)[li];
    592           (*msg)[li]   = (*msg)[procnum-1];
    593           (*links)[li] = (*links)[procnum-1];
    594           (*res)[li]   = (*res)[procnum-1];
    595           (*links)[procnum-1] = swaplink;
    596           (*res)[procnum-1]   = swapres;
    597         }
     589         {
     590            si_link swaplink = (*links)[li];
     591            intvec *swapres = (*res)[li];
     592            (*msg)[li]   = (*msg)[procnum-1];
     593            (*links)[li] = (*links)[procnum-1];
     594            (*res)[li]   = (*res)[procnum-1];
     595            (*links)[procnum-1] = swaplink;
     596            (*res)[procnum-1]   = swapres;
     597         }
    598598        else
    599           {
    600             if(TEST_OPT_PROT)
    601               {
    602                 PrintS("\n<K>\n");
    603                 writeTime("used time: #");
    604               }
    605             SetModus(ModCheck,strat);
    606           }
     599          {
     600            if(TEST_OPT_PROT)
     601              {
     602                PrintS("\n<K>\n");
     603                writeTime("used time: #");
     604              }
     605            SetModus(ModCheck,strat);
     606          }
    607607       procnum--;
    608608     }
     
    610610     {
    611611       for(int i=procnum - 1 ; i>=0 ; i--)
    612         KillChild(strat,i,Cancled);
     612         KillChild(strat,i,Cancled);
    613613     }
    614614 }
     
    620620    if(lnModus==lnRead)
    621621      {
    622         SetModus(ModCalc);
     622        SetModus(ModCalc);
    623623      }
    624624    else
    625625      {
    626         SetModus(ModRun  );
     626        SetModus(ModRun  );
    627627      }
    628628}
     
    646646      l->Init(aktuell);
    647647      for(i=0; i<aktuell; i++)
    648         {
    649           I=idInit(2,1);
    650           l->m[i].rtyp = IDEAL_CMD;
    651           if(Warteliste[i].p1==NULL)
    652             I->m[0]=NULL;
    653           else
    654             I->m[0]=pCopy(Warteliste[i].p1);
    655           if(Warteliste[i].p2==NULL)
    656             I->m[1]=NULL;
    657           else
    658             I->m[1]=pCopy(Warteliste[i].p2);
    659           l->m[i].data = (void *) idCopy(I);
    660           idDelete(&I);
    661         }
     648        {
     649           I=idInit(2,1);
     650          l->m[i].rtyp = IDEAL_CMD;
     651          if(Warteliste[i].p1==NULL)
     652            I->m[0]=NULL;
     653          else
     654            I->m[0]=pCopy(Warteliste[i].p1);
     655          if(Warteliste[i].p2==NULL)
     656            I->m[1]=NULL;
     657          else
     658            I->m[1]=pCopy(Warteliste[i].p2);
     659           l->m[i].data = (void *) idCopy(I);
     660            idDelete(&I);
     661        }
    662662      return l;
    663663    }
     
    667667      return l;
    668668    }
    669  
     669
    670670}
    671671
     
    677677//       Print("r(%.5i) Msg =",-1);
    678678      switch(msg) {
    679       case MsgTupelisZero:  // In Step-Modus schalten bzw. bleiben.     
    680         PrintS("MsgTupelisZero ");
    681         break;
    682       case MsgTupel:  // In Step-Modus schalten bzw. bleiben.     
    683         PrintS("MsgTupel       ");
    684         break;
     679      case MsgTupelisZero:  // In Step-Modus schalten bzw. bleiben.
     680        PrintS("MsgTupelisZero ");
     681        break;
     682      case MsgTupel:  // In Step-Modus schalten bzw. bleiben.
     683        PrintS("MsgTupel       ");
     684        break;
    685685      case MsgEnd:
    686         PrintS("MsgEnd         ");
    687         break;
     686        PrintS("MsgEnd         ");
     687        break;
    688688      }
    689689    }
    690690}
    691  
     691
    692692void skstdLink::DispMod(int i)
    693693{
     
    695695    {
    696696      Print("r(%.5i) Mod = ",-1);
    697      
     697
    698698      switch(Modus) {
    699699      case ModCheck:
    700         PrintS("Check ");
    701         break;
     700        PrintS("Check ");
     701        break;
    702702      case ModRun:
    703         PrintS("Run   ");
    704         break;
     703        PrintS("Run   ");
     704        break;
    705705      case ModStep:
    706         PrintS("Step  ");
    707         break;
     706        PrintS("Step  ");
     707        break;
    708708      case ModCalc:
    709         PrintS("Calc  ");
    710         break;
     709        PrintS("Calc  ");
     710        break;
    711711      case ModRead:
    712         PrintS("Read ");
    713         break;
     712        PrintS("Read ");
     713        break;
    714714      case ModWrite:
    715         PrintS("Write  ");
    716         break;
     715        PrintS("Write  ");
     716        break;
    717717      }
    718718      PrintS("\n");
  • Singular/comm.h

    r073d2e r5812c69  
    8686     if(vec!=NULL)
    8787       {
    88         for(int i=0; i<nr; i++)
    89           {
    90             if((vec[i])!=NULL)
    91               delete (vec[i]);
    92             vec[i]=NULL;
    93           }
     88          for(int i=0; i<nr; i++)
     89           {
     90             if((vec[i])!=NULL)
     91               delete (vec[i]);
     92             vec[i]=NULL;
     93           }
    9494       }
    9595     Free((ADDRESS)vec,sizeof(intvec*)*nr);
  • Singular/fglmcomb.cc

    r073d2e r5812c69  
    11// emacs edit mode for this file is -*- C++ -*-
    2 // $Id: fglmcomb.cc,v 1.12 1998-06-04 13:38:48 wichmann Exp $
     2// $Id: fglmcomb.cc,v 1.13 1998-09-24 09:59:38 Singular Exp $
    33
    44/****************************************
     
    192192//         pSetExpV( m[k], temp->exp );
    193193//         pSetm( m[k] );
    194         m[k]= pNew();
    195         pCopy2( m[k], temp );
    196         pSetCoeff( m[k], nInit(1) );
     194        m[k]= pNew();
     195        pCopy2( m[k], temp );
     196        pSetCoeff( m[k], nInit(1) );
    197197        pIter( temp );
    198198    }
     
    242242        int b;
    243243        while ( temp != NULL )
    244         {
     244        {
    245245            BOOLEAN found = FALSE;
    246246            for ( b= 0; (b < basisSize) && (found == FALSE); b++ )
    247             {
     247            {
    248248                if ( pEqual( temp, basis[b] ) )
    249                 {
     249                {
    250250                    found= TRUE;
    251251                }
    252252            }
    253253            if ( found == FALSE )
    254             {
     254            {
    255255                if ( basisSize == basisMax )
    256                 {
     256                {
    257257                    // Expand the basis
    258258                    basis= (polyset)ReAlloc( basis, basisMax * sizeof( poly ), (basisMax + basisBS ) * sizeof( poly ) );
     
    262262//                 pSetExpV( basis[basisSize], temp->exp );
    263263//                 pSetm( basis[basisSize] );
    264                 basis[basisSize]= pNew();
    265                 pCopy2( basis[basisSize], temp );
    266                 pSetCoeff( basis[basisSize], nInit(1) );
     264                basis[basisSize]= pNew();
     265                pCopy2( basis[basisSize], temp );
     266                pSetCoeff( basis[basisSize], nInit(1) );
    267267                basisSize++;
    268268            }
     
    280280    for ( k= 0; k < numMonoms; k++ ) {
    281281        STICKYPROT( "." );
    282  
     282
    283283#ifndef HAVE_EXPLICIT_CONSTR
    284284        v[k].mac_constr_i( basisSize );
     
    352352        }
    353353#ifndef HAVE_EXPLICIT_CONSTR
    354         v[best-1].clearelems();
     354        v[best-1].clearelems();
    355355#else
    356356        v[best-1].~fglmVector();
  • Singular/fglmgauss.cc

    r073d2e r5812c69  
    11// emacs edit mode for this file is -*- C++ -*-
    2 // $Id: fglmgauss.cc,v 1.9 1998-06-04 13:39:21 wichmann Exp $
     2// $Id: fglmgauss.cc,v 1.10 1998-09-24 09:59:38 Singular Exp $
    33
    44/****************************************
    55*  Computer Algebra System SINGULAR     *
    66****************************************/
    7 /* 
     7/*
    88* ABSTRACT - class gaussReducer. Used in fglmzero.cc and fglmhom.cc
    99*  to find linear dependecies of fglmVectors.
     
    2727    number pdenom;
    2828    number fac;
    29     gaussElem( const fglmVector newv, const fglmVector newp, number & newpdenom, number & newfac ) : v( newv ), p( newp ), pdenom( newpdenom ), fac( newfac ) 
     29    gaussElem( const fglmVector newv, const fglmVector newp, number & newpdenom, number & newfac ) : v( newv ), p( newp ), pdenom( newpdenom ), fac( newfac )
    3030    {
    31         newpdenom= NULL;
    32         newfac= NULL;
     31        newpdenom= NULL;
     32        newfac= NULL;
    3333    }
    3434
     
    4242    pdenom=newpdenom;
    4343    fac=newfac;
    44         newpdenom= NULL;
    45         newfac= NULL;
    46     }
    47 #endif
    48 
    49     ~gaussElem() 
     44        newpdenom= NULL;
     45        newfac= NULL;
     46    }
     47#endif
     48
     49    ~gaussElem()
    5050    {
    51         nDelete( & pdenom );
    52         nDelete( & fac );
     51        nDelete( & pdenom );
     52        nDelete( & fac );
    5353    }
    5454};
    5555
    56 gaussReducer::gaussReducer( int dimen ) 
     56gaussReducer::gaussReducer( int dimen )
    5757{
    5858    int k;
     
    6565#endif
    6666    isPivot= (BOOLEAN *)Alloc( (max+1)*sizeof( BOOLEAN ) );
    67     for ( k= max; k > 0; k-- ) 
    68             isPivot[k]= FALSE;
     67    for ( k= max; k > 0; k-- )
     68            isPivot[k]= FALSE;
    6969    perm= (int *)Alloc( (max+1)*sizeof( int ) );
    7070}
    7171
    72 gaussReducer::~gaussReducer() 
     72gaussReducer::~gaussReducer()
    7373{
    7474    int k;
     
    7777    delete [] elems;
    7878#else
    79     for ( k= size; k > 0; k-- ) 
    80         elems[k].~gaussElem();
     79    for ( k= size; k > 0; k-- )
     80        elems[k].~gaussElem();
    8181    Free( (ADDRESS)elems, (max+1)*sizeof( gaussElem ) );
    8282#endif
     
    8787
    8888BOOLEAN
    89 gaussReducer::reduce( fglmVector thev ) 
     89gaussReducer::reduce( fglmVector thev )
    9090{
    9191    number fac1, fac2;
     
    9898    number vdenom = v.clearDenom();
    9999    if ( ! nIsOne( vdenom ) && ! nIsZero( vdenom ) ) {
    100         p.setelem( p.size(), vdenom );
     100        p.setelem( p.size(), vdenom );
    101101    }
    102102    else {
    103         nDelete( & vdenom );
     103        nDelete( & vdenom );
    104104    }
    105105    number gcd = v.gcd();
    106106    if ( ! nIsOne( gcd ) && ! nIsZero( gcd ) ) {
    107         v /= gcd;
    108         number temp= nMult( pdenom, gcd );
    109         nDelete( & pdenom );
    110         pdenom= temp;
     107        v /= gcd;
     108        number temp= nMult( pdenom, gcd );
     109        nDelete( & pdenom );
     110        pdenom= temp;
    111111    }
    112112    nDelete( & gcd );
    113    
     113
    114114    int k;
    115115    for ( k= 1; k <= size; k++ ) {
    116         if ( ! v.elemIsZero( perm[k] ) ) {
    117             fac1= elems[k].fac;
    118             fac2= nCopy( v.getconstelem( perm[k] ) );
    119             v.nihilate( fac1, fac2, elems[k].v );
    120             fac1= nMult( fac1, elems[k].pdenom );
    121             temp= nMult( fac2, pdenom );
    122             nDelete( & fac2 );
    123             fac2= temp;
    124             p.nihilate( fac1, fac2, elems[k].p );
    125             temp= nMult( pdenom, elems[k].pdenom );
    126             nDelete( & pdenom );
    127             pdenom= temp;
    128            
    129             nDelete( & fac1 );
    130             nDelete( & fac2 );
    131             number gcd = v.gcd();
    132             if ( ! nIsOne( gcd ) && ! nIsZero( gcd ) ) {
    133                 v/= gcd;
    134                 number temp = nMult( pdenom, gcd );
    135                 nDelete( & pdenom );
    136                 pdenom= temp;
    137             }
    138             nDelete( & gcd );
    139             gcd= p.gcd();
    140             temp= nGcd( pdenom, gcd );
    141             nDelete( & gcd );
    142             gcd= temp;
    143             if ( ! nIsZero( gcd ) && ! nIsOne( gcd ) ) {
    144                 p/= gcd;
    145                 temp= nDiv( pdenom, gcd );
    146                 nDelete( & pdenom );
    147                 pdenom= temp;
    148                 nNormalize( pdenom );
    149             }
    150             nDelete( & gcd );
    151         }
     116        if ( ! v.elemIsZero( perm[k] ) ) {
     117            fac1= elems[k].fac;
     118            fac2= nCopy( v.getconstelem( perm[k] ) );
     119            v.nihilate( fac1, fac2, elems[k].v );
     120            fac1= nMult( fac1, elems[k].pdenom );
     121            temp= nMult( fac2, pdenom );
     122            nDelete( & fac2 );
     123            fac2= temp;
     124            p.nihilate( fac1, fac2, elems[k].p );
     125            temp= nMult( pdenom, elems[k].pdenom );
     126            nDelete( & pdenom );
     127            pdenom= temp;
     128
     129            nDelete( & fac1 );
     130            nDelete( & fac2 );
     131            number gcd = v.gcd();
     132            if ( ! nIsOne( gcd ) && ! nIsZero( gcd ) ) {
     133                v/= gcd;
     134                number temp = nMult( pdenom, gcd );
     135                nDelete( & pdenom );
     136                pdenom= temp;
     137            }
     138            nDelete( & gcd );
     139            gcd= p.gcd();
     140            temp= nGcd( pdenom, gcd );
     141            nDelete( & gcd );
     142            gcd= temp;
     143            if ( ! nIsZero( gcd ) && ! nIsOne( gcd ) ) {
     144                p/= gcd;
     145                temp= nDiv( pdenom, gcd );
     146                nDelete( & pdenom );
     147                pdenom= temp;
     148                nNormalize( pdenom );
     149            }
     150            nDelete( & gcd );
     151        }
    152152    }
    153153    return ( v.isZero() );
    154154}
    155155
    156 void 
    157 gaussReducer::store() 
     156void
     157gaussReducer::store()
    158158{
    159159    // fglmASSERT( size < max );
    160160    number fac;
    161161    // find the pivot-element in v:
    162    
     162
    163163    size++;
    164164    int k= 1;
    165165    while ( nIsZero(v.getconstelem(k)) || isPivot[k] ) {
    166         k++;
     166        k++;
    167167    }
    168168    // fglmASSERT( k <= dimen, "Error(1) in fglmDdata::pivot-search");
     
    171171    k++;
    172172    while ( k <= max ) {
    173         if ( ! nIsZero( v.getconstelem(k) ) && ! isPivot[k] ) {
    174             if ( nGreater( v.getconstelem( k ), pivot ) ) {
    175                 pivot= v.getconstelem( k );
    176                 pivotcol= k;
    177             }
    178         }
    179         k++;
     173        if ( ! nIsZero( v.getconstelem(k) ) && ! isPivot[k] ) {
     174            if ( nGreater( v.getconstelem( k ), pivot ) ) {
     175                pivot= v.getconstelem( k );
     176                pivotcol= k;
     177            }
     178        }
     179        k++;
    180180    }
    181181    // fglmASSERT( ! nIsZero( pivot ), "Error(2) fglmDdata::Pivotelement ist Null" );
    182182    isPivot[ pivotcol ]= TRUE;
    183183    perm[size]= pivotcol;
    184    
     184
    185185    pivot= nCopy( v.getconstelem( pivotcol ) );
    186186#ifndef HAVE_EXPLICIT_CONSTR
     
    191191}
    192192
    193 fglmVector 
    194 gaussReducer::getDependence() 
     193fglmVector
     194gaussReducer::getDependence()
    195195{
    196196    nDelete( & pdenom );
  • Singular/fglmhom.cc

    r073d2e r5812c69  
    11// emacs edit mode for this file is -*- C++ -*-
    2 // $Id: fglmhom.cc,v 1.10 1998-06-15 14:30:06 Singular Exp $
     2// $Id: fglmhom.cc,v 1.11 1998-09-24 09:59:39 Singular Exp $
    33
    44/****************************************
    55*  Computer Algebra System SINGULAR     *
    66****************************************/
    7 /* 
     7/*
    88* ABSTRACT - The FGLM-Algorithm extended for homogeneous ideals.
    99*   Calculates via the hilbert-function a groebner basis.
     
    1818#include "tok.h"
    1919#include "structs.h"
    20 #include "subexpr.h" 
     20#include "subexpr.h"
    2121#include "polys.h"
    2222#include "ideals.h"
     
    6262    homogElem() : v(), dv(), basis(0), destbasis(0), inDest(FALSE) {}
    6363    homogElem( poly m, int b, BOOLEAN ind ) :
    64         basis(b), inDest(ind)
     64        basis(b), inDest(ind)
    6565    {
    66         mon.dm= m;
    67         mon.sm= NULL;
     66        mon.dm= m;
     67        mon.sm= NULL;
    6868    }
    6969};
    7070
    71 struct homogData 
     71struct homogData
    7272{
    7373    ideal sourceIdeal;
     
    8383    int overall;  // nur zum testen.
    8484    int numberofdestbasismonoms;
    85 //     homogData() : sourceHeads(NULL), numSourceHeads(0), monlist(NULL), 
    86 //      numMonoms(0), basisSize(0) {}
     85//     homogData() : sourceHeads(NULL), numSourceHeads(0), monlist(NULL),
     86//         numMonoms(0), basisSize(0) {}
    8787};
    8888
    8989int
    90 hfglmNextdegree( intvec * source, ideal current, int & deg ) 
     90hfglmNextdegree( intvec * source, ideal current, int & deg )
    9191{
    9292    int numelems;
    9393    intvec * newhilb = hHstdSeries( current, NULL, currQuotient );
    9494
    95     loop 
     95    loop
    9696    {
    97         if ( deg < newhilb->length() )
    98         {
    99             if ( deg < source->length() )
    100                 numelems= (*newhilb)[deg]-(*source)[deg];
    101             else
    102                 numelems= (*newhilb)[deg];
    103         }
    104         else
    105         {
    106             if (deg < source->length())
    107                 numelems= -(*source)[deg];
    108             else
    109             {
    110                 deg= 0;
    111                 return 0;
    112             }
    113         }
    114         if (numelems != 0)
    115             return numelems;
    116         deg++;
    117     } 
     97        if ( deg < newhilb->length() )
     98        {
     99            if ( deg < source->length() )
     100                numelems= (*newhilb)[deg]-(*source)[deg];
     101            else
     102                numelems= (*newhilb)[deg];
     103        }
     104        else
     105        {
     106            if (deg < source->length())
     107                numelems= -(*source)[deg];
     108            else
     109            {
     110                deg= 0;
     111                return 0;
     112            }
     113        }
     114        if (numelems != 0)
     115            return numelems;
     116        deg++;
     117    }
    118118    delete newhilb;
    119119}
    120120
    121 void 
     121void
    122122generateMonoms( poly m, int var, int deg, homogData * dat )
    123123{
    124124    if ( var == pVariables ) {
    125         BOOLEAN inSource = FALSE;
    126         BOOLEAN inDest = FALSE;
    127         poly mon = pCopy( m );
    128         pSetExp( mon, var, deg );
    129         pSetm( mon );
    130         ++dat->overall;
    131         int i;
    132         for ( i= dat->numSourceHeads - 1; (i >= 0) && (inSource==FALSE); i-- ) {
    133             if ( pDivisibleBy( dat->sourceHeads[i].dm, mon ) ) {
    134                 inSource= TRUE;
    135             }
    136         }
    137         for ( i= dat->numDestPolys - 1; (i >= 0) && (inDest==FALSE); i-- ) {
    138             if ( pDivisibleBy( (dat->destIdeal->m)[i], mon ) ) {
    139                 inDest= TRUE;
    140             }
    141         }
    142         if ( (!inSource) || (!inDest) ) {
    143             int basis = 0;
    144             if ( !inSource )
    145                 basis= ++(dat->basisSize);
    146             if ( !inDest )
    147                 ++dat->numberofdestbasismonoms;
    148             if ( dat->numMonoms == dat->monlistmax ) {
    149                 dat->monlist= (homogElem * )ReAlloc( dat->monlist, (dat->monlistmax)*sizeof( homogElem ), (dat->monlistmax+dat->monlistblock) * sizeof( homogElem ) );
    150                 int k;
    151                 for ( k= dat->monlistmax; k < (dat->monlistmax+dat->monlistblock); k++ )
    152                     dat->monlist[k].homogElem();
    153                 dat->monlistmax+= dat->monlistblock;
    154             }
    155             dat->monlist[dat->numMonoms]= homogElem( mon, basis, inDest );
    156             dat->numMonoms++;
    157             if ( inSource && ! inDest ) PROT( "\\" );
    158             if ( ! inSource && inDest ) PROT( "/" );
    159             if ( ! inSource && ! inDest ) PROT( "." );
    160         }
    161         else {
    162             pDelete( & mon );
    163         }
    164         return;
     125        BOOLEAN inSource = FALSE;
     126        BOOLEAN inDest = FALSE;
     127        poly mon = pCopy( m );
     128        pSetExp( mon, var, deg );
     129        pSetm( mon );
     130        ++dat->overall;
     131        int i;
     132        for ( i= dat->numSourceHeads - 1; (i >= 0) && (inSource==FALSE); i-- ) {
     133            if ( pDivisibleBy( dat->sourceHeads[i].dm, mon ) ) {
     134                inSource= TRUE;
     135            }
     136        }
     137        for ( i= dat->numDestPolys - 1; (i >= 0) && (inDest==FALSE); i-- ) {
     138            if ( pDivisibleBy( (dat->destIdeal->m)[i], mon ) ) {
     139                inDest= TRUE;
     140            }
     141        }
     142        if ( (!inSource) || (!inDest) ) {
     143            int basis = 0;
     144            if ( !inSource )
     145                basis= ++(dat->basisSize);
     146            if ( !inDest )
     147                ++dat->numberofdestbasismonoms;
     148            if ( dat->numMonoms == dat->monlistmax ) {
     149                dat->monlist= (homogElem * )ReAlloc( dat->monlist, (dat->monlistmax)*sizeof( homogElem ), (dat->monlistmax+dat->monlistblock) * sizeof( homogElem ) );
     150                int k;
     151                for ( k= dat->monlistmax; k < (dat->monlistmax+dat->monlistblock); k++ )
     152                    dat->monlist[k].homogElem();
     153                dat->monlistmax+= dat->monlistblock;
     154            }
     155            dat->monlist[dat->numMonoms]= homogElem( mon, basis, inDest );
     156            dat->numMonoms++;
     157            if ( inSource && ! inDest ) PROT( "\\" );
     158            if ( ! inSource && inDest ) PROT( "/" );
     159            if ( ! inSource && ! inDest ) PROT( "." );
     160        }
     161        else {
     162            pDelete( & mon );
     163        }
     164        return;
    165165    }
    166166    else {
    167         poly newm = pCopy( m );
    168         while ( deg >= 0 ) {
    169             generateMonoms( newm, var+1, deg, dat );
    170             pIncrExp( newm, var );
    171             pSetm( newm );
    172             deg--;
    173         }
    174         pDelete( & newm );
     167        poly newm = pCopy( m );
     168        while ( deg >= 0 ) {
     169            generateMonoms( newm, var+1, deg, dat );
     170            pIncrExp( newm, var );
     171            pSetm( newm );
     172            deg--;
     173        }
     174        pDelete( & newm );
    175175    }
    176176    return;
     
    178178
    179179void
    180 mapMonoms( ring oldRing, homogData & dat ) 
     180mapMonoms( ring oldRing, homogData & dat )
    181181{
    182182    int * vperm = (int *)Alloc( (currRing->N + 1)*sizeof(int) );
     
    185185    int s;
    186186    for ( s= dat.numMonoms - 1; s >= 0; s-- ) {
    187 //      dat.monlist[s].mon.sm= pPermPoly( dat.monlist[s].mon.dm, vperm, currRing->N, NULL, 0 );
     187//        dat.monlist[s].mon.sm= pPermPoly( dat.monlist[s].mon.dm, vperm, currRing->N, NULL, 0 );
    188188      // obachman: changed the folowing to reflect the new calling interface of
    189189      // pPermPoly -- Tim please check whether this is correct!
    190         dat.monlist[s].mon.sm= pPermPoly( dat.monlist[s].mon.dm, vperm, oldRing, NULL, 0 );     
     190        dat.monlist[s].mon.sm= pPermPoly( dat.monlist[s].mon.dm, vperm, oldRing, NULL, 0 );
    191191    }
    192192}
    193193
    194194void
    195 getVectorRep( homogData & dat ) 
     195getVectorRep( homogData & dat )
    196196{
    197197    // Calculate the NormalForms
    198198    int s;
    199199    for ( s= 0;  s < dat.numMonoms; s++ ) {
    200         if ( dat.monlist[s].inDest == FALSE ) {
    201             fglmVector v;
    202             if ( dat.monlist[s].basis == 0 ) {
    203                 v= fglmVector( dat.basisSize );
    204                 // now the monom is in L(source)
    205                 PROT( "(" );
    206                 poly nf = kNF( dat.sourceIdeal, NULL, dat.monlist[s].mon.sm );
    207                 PROT( ")" );
    208                 poly temp = nf;
    209                 while (temp != NULL ) {
    210                     int t;
    211                     for ( t= dat.numMonoms - 1; t >= 0; t-- ) {
    212                         if ( dat.monlist[t].basis > 0 ) {
    213                             if ( pEqual( dat.monlist[t].mon.sm, temp ) ) {
    214                                 number coeff= nCopy( pGetCoeff( temp ) );
    215                                 v.setelem( dat.monlist[t].basis, coeff );
    216                             }
    217                         }
    218                     }
    219                     pIter(temp);
    220                 }
    221                 pDelete( & nf );
    222             }
    223             else {
    224                 PROT( "." );
    225                 v= fglmVector( dat.basisSize, dat.monlist[s].basis );
    226             }
    227             dat.monlist[s].v= v;
    228         }
     200        if ( dat.monlist[s].inDest == FALSE ) {
     201            fglmVector v;
     202            if ( dat.monlist[s].basis == 0 ) {
     203                v= fglmVector( dat.basisSize );
     204                // now the monom is in L(source)
     205                PROT( "(" );
     206                poly nf = kNF( dat.sourceIdeal, NULL, dat.monlist[s].mon.sm );
     207                PROT( ")" );
     208                poly temp = nf;
     209                while (temp != NULL ) {
     210                    int t;
     211                    for ( t= dat.numMonoms - 1; t >= 0; t-- ) {
     212                        if ( dat.monlist[t].basis > 0 ) {
     213                            if ( pEqual( dat.monlist[t].mon.sm, temp ) ) {
     214                                number coeff= nCopy( pGetCoeff( temp ) );
     215                                v.setelem( dat.monlist[t].basis, coeff );
     216                            }
     217                        }
     218                    }
     219                    pIter(temp);
     220                }
     221                pDelete( & nf );
     222            }
     223            else {
     224                PROT( "." );
     225                v= fglmVector( dat.basisSize, dat.monlist[s].basis );
     226            }
     227            dat.monlist[s].v= v;
     228        }
    229229    }
    230230}
    231231
    232232void
    233 remapVectors( ring oldring, homogData & dat ) 
     233remapVectors( ring oldring, homogData & dat )
    234234{
    235235    nSetMap( oldring->ch, oldring->parameter, oldring->P, oldring->minpoly );
    236236    int s;
    237237    for ( s= dat.numMonoms - 1; s >= 0; s-- ) {
    238         if ( dat.monlist[s].inDest == FALSE ) {
    239             int k;
    240             fglmVector newv( dat.basisSize );
    241             for ( k= dat.basisSize; k > 0; k-- ){
    242                 number newnum= nMap( dat.monlist[s].v.getelem( k ) );
    243                 newv.setelem( k, newnum );
    244             }
    245             dat.monlist[s].dv= newv;
    246         }
     238        if ( dat.monlist[s].inDest == FALSE ) {
     239            int k;
     240            fglmVector newv( dat.basisSize );
     241            for ( k= dat.basisSize; k > 0; k-- ){
     242                number newnum= nMap( dat.monlist[s].v.getelem( k ) );
     243                newv.setelem( k, newnum );
     244            }
     245            dat.monlist[s].dv= newv;
     246        }
    247247    }
    248248}
    249249
    250250void
    251 gaussreduce( homogData & dat, int maxnum, int BS ) 
     251gaussreduce( homogData & dat, int maxnum, int BS )
    252252{
    253253    int s;
     
    256256    int destbasisSize = 0;
    257257    gaussReducer gauss( dat.basisSize );
    258    
     258
    259259    for ( s= 0; (s < dat.numMonoms) && (found < maxnum); s++ ) {
    260         if ( dat.monlist[s].inDest == FALSE ) {
    261             if ( gauss.reduce( dat.monlist[s].dv ) == FALSE ) {
    262                 destbasisSize++;
    263                 dat.monlist[s].destbasis= destbasisSize;
    264                 gauss.store();
    265                 PROT( "." );
    266             }
    267             else {
    268                 fglmVector p= gauss.getDependence();
    269                 poly result = pCopy( dat.monlist[s].mon.dm );
    270                 pSetCoeff( result, nCopy( p.getconstelem( p.size() ) ) );
    271                 int l = 0;
    272                 int k;
    273                 for ( k= 1; k < p.size(); k++ ) {
    274                     if ( ! p.elemIsZero( k ) ) {
    275                         while ( dat.monlist[l].destbasis != k )
    276                             l++;
    277                         poly temp = pCopy( dat.monlist[l].mon.dm );
    278                         pSetCoeff( temp, nCopy( p.getconstelem( k ) ) );
    279                         result= pAdd( result, temp );
    280                     }
    281                 }
    282                 if ( ! nGreaterZero( pGetCoeff( result ) ) ) result= pNeg( result );
    283 //              PROT2( "(%s)", pString( result ) );
    284                 PROT( "+" );
    285                 found++;
    286                 (dat.destIdeal->m)[dat.numDestPolys]= result;
    287                 dat.numDestPolys++;
    288                 if ( IDELEMS(dat.destIdeal) == dat.numDestPolys ) {
    289                     pEnlargeSet( & dat.destIdeal->m, IDELEMS( dat.destIdeal ), BS );
    290                     IDELEMS( dat.destIdeal )+= BS;
    291                 }
    292                
    293             }
    294                
    295         }
     260        if ( dat.monlist[s].inDest == FALSE ) {
     261            if ( gauss.reduce( dat.monlist[s].dv ) == FALSE ) {
     262                destbasisSize++;
     263                dat.monlist[s].destbasis= destbasisSize;
     264                gauss.store();
     265                PROT( "." );
     266            }
     267            else {
     268                fglmVector p= gauss.getDependence();
     269                poly result = pCopy( dat.monlist[s].mon.dm );
     270                pSetCoeff( result, nCopy( p.getconstelem( p.size() ) ) );
     271                int l = 0;
     272                int k;
     273                for ( k= 1; k < p.size(); k++ ) {
     274                    if ( ! p.elemIsZero( k ) ) {
     275                        while ( dat.monlist[l].destbasis != k )
     276                            l++;
     277                        poly temp = pCopy( dat.monlist[l].mon.dm );
     278                        pSetCoeff( temp, nCopy( p.getconstelem( k ) ) );
     279                        result= pAdd( result, temp );
     280                    }
     281                }
     282                if ( ! nGreaterZero( pGetCoeff( result ) ) ) result= pNeg( result );
     283//                PROT2( "(%s)", pString( result ) );
     284                PROT( "+" );
     285                found++;
     286                (dat.destIdeal->m)[dat.numDestPolys]= result;
     287                dat.numDestPolys++;
     288                if ( IDELEMS(dat.destIdeal) == dat.numDestPolys ) {
     289                    pEnlargeSet( & dat.destIdeal->m, IDELEMS( dat.destIdeal ), BS );
     290                    IDELEMS( dat.destIdeal )+= BS;
     291                }
     292
     293            }
     294
     295        }
    296296    }
    297297    PROT2( "(%i", s );
     
    313313    ring sourceRing = currRing;
    314314
    315     intvec * hilb = hHstdSeries( sourceIdeal, NULL, currQuotient ); 
     315    intvec * hilb = hHstdSeries( sourceIdeal, NULL, currQuotient );
    316316    int s;
    317317    dat.sourceIdeal= sourceIdeal;
    318318    dat.sourceHeads= (doublepoly *)Alloc( IDELEMS( sourceIdeal ) * sizeof( doublepoly ) );
    319319    for ( s= IDELEMS( sourceIdeal ) - 1; s >= 0; s-- ) {
    320         dat.sourceHeads[s].sm= pHead( (sourceIdeal->m)[s] );
     320        dat.sourceHeads[s].sm= pHead( (sourceIdeal->m)[s] );
    321321    }
    322322    dat.numSourceHeads= IDELEMS( sourceIdeal );
     
    329329    nSetMap( sourceRing->ch, sourceRing->parameter, sourceRing->P, sourceRing->minpoly );
    330330    for ( s= IDELEMS( sourceIdeal ) - 1; s >= 0; s-- ) {
    331         dat.sourceHeads[s].dm= pPermPoly( dat.sourceHeads[s].sm, vperm, sourceRing, NULL, 0 );
     331        dat.sourceHeads[s].dm= pPermPoly( dat.sourceHeads[s].sm, vperm, sourceRing, NULL, 0 );
    332332    }
    333333
     
    336336
    337337    while ( (numGBelems= hfglmNextdegree( hilb, dat.destIdeal, deg )) != 0 ) {
    338         int num = 0;  // the number of monoms of degree deg
    339         PROT2( "deg= %i ", deg );
    340         PROT2( "num= %i\ngen>", numGBelems );
    341         dat.monlistblock= 512;
    342         dat.monlistmax= dat.monlistblock;
    343         dat.monlist= (homogElem *)Alloc( dat.monlistmax*sizeof( homogElem ) );
    344         int j;
    345         for ( j= dat.monlistmax - 1; j >= 0; j-- ) dat.monlist[j].homogElem();
    346         dat.numMonoms= 0;
    347         dat.basisSize= 0;
    348         dat.overall= 0;
    349         dat.numberofdestbasismonoms= 0;
    350        
    351         poly start= pOne();
    352         generateMonoms( start, 1, deg, &dat );
    353         pDelete( & start );
    354 
    355         PROT2( "(%i/", dat.basisSize );
    356         PROT2( "%i)\nvec>", dat.overall );
    357         // switch to sourceRing and map monoms
    358         rSetHdl( sourceRingHdl, TRUE );
    359         mapMonoms( destRing, dat );
    360         getVectorRep( dat );
    361        
    362         // switch to destination Ring and remap the vectors
    363         rSetHdl( destRingHdl, TRUE );
    364         remapVectors( sourceRing, dat );
    365        
    366         PROT( "<\nred>" );
    367         // now do gaussian reduction
    368         gaussreduce( dat, numGBelems, groebnerBS );
    369 
    370         Free( (ADDRESS)dat.monlist, dat.monlistmax*sizeof( homogElem ) );
    371         PROT( "<\n" );
     338        int num = 0;  // the number of monoms of degree deg
     339        PROT2( "deg= %i ", deg );
     340        PROT2( "num= %i\ngen>", numGBelems );
     341        dat.monlistblock= 512;
     342        dat.monlistmax= dat.monlistblock;
     343        dat.monlist= (homogElem *)Alloc( dat.monlistmax*sizeof( homogElem ) );
     344        int j;
     345        for ( j= dat.monlistmax - 1; j >= 0; j-- ) dat.monlist[j].homogElem();
     346        dat.numMonoms= 0;
     347        dat.basisSize= 0;
     348        dat.overall= 0;
     349        dat.numberofdestbasismonoms= 0;
     350
     351        poly start= pOne();
     352        generateMonoms( start, 1, deg, &dat );
     353        pDelete( & start );
     354
     355        PROT2( "(%i/", dat.basisSize );
     356        PROT2( "%i)\nvec>", dat.overall );
     357        // switch to sourceRing and map monoms
     358        rSetHdl( sourceRingHdl, TRUE );
     359        mapMonoms( destRing, dat );
     360        getVectorRep( dat );
     361
     362        // switch to destination Ring and remap the vectors
     363        rSetHdl( destRingHdl, TRUE );
     364        remapVectors( sourceRing, dat );
     365
     366        PROT( "<\nred>" );
     367        // now do gaussian reduction
     368        gaussreduce( dat, numGBelems, groebnerBS );
     369
     370        Free( (ADDRESS)dat.monlist, dat.monlistmax*sizeof( homogElem ) );
     371        PROT( "<\n" );
    372372    }
    373373    PROT( "\n" );
  • Singular/fglmvec.cc

    r073d2e r5812c69  
    11// emacs edit mode for this file is -*- C++ -*-
    2 // $Id: fglmvec.cc,v 1.10 1998-06-04 13:39:14 wichmann Exp $
     2// $Id: fglmvec.cc,v 1.11 1998-09-24 09:59:40 Singular Exp $
    33
    44/****************************************
    55*  Computer Algebra System SINGULAR     *
    66****************************************/
    7 /* 
     7/*
    88* ABSTRACT - The FGLM-Algorithm
    99*   Implementation of number-vectors for the fglm algorithm.
    1010*   (See fglm.cc). Based on a letter-envelope implementation, mainly
    11 *   written to be used by the fglm algorithm. Hence they are 
     11*   written to be used by the fglm algorithm. Hence they are
    1212*   specialized for this purpose.
    1313*/
     
    1717#ifdef HAVE_FGLM
    1818#include "mmemory.h"
    19 #include "tok.h" 
     19#include "tok.h"
    2020#include "structs.h"
    2121#include "numbers.h"
     
    3838    fglmVectorRep() : ref_count(1), N(0), elems(0) {}
    3939    fglmVectorRep( int n, number * e ) : ref_count(1), N(n), elems(e) {}
    40     fglmVectorRep( int n ) : ref_count(1), N(n) 
    41     {
    42         fglmASSERT( N >= 0, "illegal Vector representation" );
    43         if ( N == 0 )
    44             elems= 0;
    45         else {
    46             elems= (number *)Alloc( N*sizeof( number ) );
    47             for ( int i= N-1; i >= 0; i-- )
    48                 elems[i]= nInit( 0 );
    49         }
     40    fglmVectorRep( int n ) : ref_count(1), N(n)
     41    {
     42        fglmASSERT( N >= 0, "illegal Vector representation" );
     43        if ( N == 0 )
     44            elems= 0;
     45        else {
     46            elems= (number *)Alloc( N*sizeof( number ) );
     47            for ( int i= N-1; i >= 0; i-- )
     48                elems[i]= nInit( 0 );
     49        }
    5050    }
    5151    ~fglmVectorRep()
    5252    {
    53         if ( N > 0 ) {
    54             for ( int i= N-1; i >= 0; i-- )
    55                 nDelete( elems + i );
    56             Free( (ADDRESS)elems, N*sizeof( number ) );
    57         }
     53        if ( N > 0 ) {
     54            for ( int i= N-1; i >= 0; i-- )
     55                nDelete( elems + i );
     56            Free( (ADDRESS)elems, N*sizeof( number ) );
     57        }
    5858    }
    5959
    6060    fglmVectorRep* clone() const
    6161    {
    62         if ( N > 0 ) {
    63             number * elems_clone;
    64             elems_clone= (number *)Alloc( N*sizeof( number ) );
    65             for ( int i= N-1; i >= 0; i-- )
    66                 elems_clone[i] = nCopy( elems[i] );
    67             return new fglmVectorRep( N, elems_clone );
    68         } else
    69             return new fglmVectorRep( N, 0 );
     62        if ( N > 0 ) {
     63            number * elems_clone;
     64            elems_clone= (number *)Alloc( N*sizeof( number ) );
     65            for ( int i= N-1; i >= 0; i-- )
     66                elems_clone[i] = nCopy( elems[i] );
     67            return new fglmVectorRep( N, elems_clone );
     68        } else
     69            return new fglmVectorRep( N, 0 );
    7070    }
    7171    BOOLEAN deleteObject() { return --ref_count == 0; }
     
    7575
    7676    int size() const { return N; }
    77     int isZero() const 
    78     {
    79         int k;
    80         for ( k= N; k > 0; k-- )
    81             if ( ! nIsZero( getconstelem( k ) ) )
    82                 return 0;
    83         return 1;
    84     }
    85     int numNonZeroElems() const 
    86     {
    87         int num = 0;
    88         int k;
    89         for ( k= N; k > 0; k-- )
    90             if ( ! nIsZero( getconstelem( k ) ) ) num++;
    91         return num;
     77    int isZero() const
     78    {
     79        int k;
     80        for ( k= N; k > 0; k-- )
     81            if ( ! nIsZero( getconstelem( k ) ) )
     82                return 0;
     83        return 1;
     84    }
     85    int numNonZeroElems() const
     86    {
     87        int num = 0;
     88        int k;
     89        for ( k= N; k > 0; k-- )
     90            if ( ! nIsZero( getconstelem( k ) ) ) num++;
     91        return num;
    9292    }
    9393    void setelem( int i, number n )
    9494    {
    95         fglmASSERT( 0 < i && i <= N, "setelem: wrong index" );
    96         nDelete( elems + i-1 );
    97         elems[i-1]= n;
    98     }
    99     number ejectelem( int i, number n ) 
    100     {
    101         fglmASSERT( isUnique(), "should only be called if unique!" );
    102         number temp= elems[i-1];
    103         elems[i-1]= n;
    104         return temp;
     95        fglmASSERT( 0 < i && i <= N, "setelem: wrong index" );
     96        nDelete( elems + i-1 );
     97        elems[i-1]= n;
     98    }
     99    number ejectelem( int i, number n )
     100    {
     101        fglmASSERT( isUnique(), "should only be called if unique!" );
     102        number temp= elems[i-1];
     103        elems[i-1]= n;
     104        return temp;
    105105    }
    106106    number & getelem( int i )
    107107    {
    108         fglmASSERT( 0 < i && i <= N, "getelem: wrong index" );
    109         return elems[i-1];
     108        fglmASSERT( 0 < i && i <= N, "getelem: wrong index" );
     109        return elems[i-1];
    110110    }
    111111    const number getconstelem( int i) const
    112112    {
    113         fglmASSERT( 0 < i && i <= N, "getconstelem: wrong index" );
    114         return elems[i-1];
     113        fglmASSERT( 0 < i && i <= N, "getconstelem: wrong index" );
     114        return elems[i-1];
    115115    }
    116116    friend class fglmVector;
     
    141141{
    142142    if ( rep->deleteObject() )
    143         delete rep;
     143        delete rep;
    144144}
    145145
     
    158158
    159159void
    160 fglmVector::clearelems() 
     160fglmVector::clearelems()
    161161{
    162162    if ( rep->deleteObject() )
     
    165165#endif
    166166
    167 void 
     167void
    168168fglmVector::makeUnique()
    169169{
    170170    if ( rep->refcount() != 1 ) {
    171         rep->deleteObject();
    172         rep= rep->clone();
    173     }
    174 }
    175 
    176 int 
     171        rep->deleteObject();
     172        rep= rep->clone();
     173    }
     174}
     175
     176int
    177177fglmVector::size() const
    178178{
     
    187187
    188188void
    189 fglmVector::nihilate( const number fac1, const number fac2, const fglmVector v ) 
     189fglmVector::nihilate( const number fac1, const number fac2, const fglmVector v )
    190190{
    191191    int i;
     
    194194    fglmASSERT( vsize <= rep->size(), "v has to be smaller oder equal" );
    195195    if ( rep->isUnique() ) {
    196         for ( i= vsize; i > 0; i-- ) {
    197             term1= nMult( fac1, rep->getconstelem( i ) );
    198             term2= nMult( fac2, v.rep->getconstelem( i ) );
    199             rep->setelem( i, nSub( term1, term2 ) );
    200             nDelete( &term1 );
    201             nDelete( &term2 );
    202         }
    203         for ( i= rep->size(); i > vsize; i-- ) {
    204             rep->setelem( i, nMult( fac1, rep->getconstelem( i ) ) );
    205         }
    206     }
    207     else 
    208     {
    209         number* newelems;
    210         newelems= (number *)Alloc( rep->size()*sizeof( number ) );
    211         for ( i= vsize; i > 0; i-- ) {
    212             term1= nMult( fac1, rep->getconstelem( i ) );
    213             term2= nMult( fac2, v.rep->getconstelem( i ) );
    214             newelems[i-1]= nSub( term1, term2 );
    215             nDelete( &term1 );
    216             nDelete( &term2 );
    217         }
    218         for ( i= rep->size(); i > vsize; i-- ) {
    219             newelems[i-1]= nMult( fac1, rep->getconstelem( i ) );
    220         }
    221         rep->deleteObject();
    222         rep= new fglmVectorRep( rep->size(), newelems );
    223     }
    224 }
    225 
    226 fglmVector & 
     196        for ( i= vsize; i > 0; i-- ) {
     197            term1= nMult( fac1, rep->getconstelem( i ) );
     198            term2= nMult( fac2, v.rep->getconstelem( i ) );
     199            rep->setelem( i, nSub( term1, term2 ) );
     200            nDelete( &term1 );
     201            nDelete( &term2 );
     202        }
     203        for ( i= rep->size(); i > vsize; i-- ) {
     204            rep->setelem( i, nMult( fac1, rep->getconstelem( i ) ) );
     205        }
     206    }
     207    else
     208    {
     209        number* newelems;
     210        newelems= (number *)Alloc( rep->size()*sizeof( number ) );
     211        for ( i= vsize; i > 0; i-- ) {
     212            term1= nMult( fac1, rep->getconstelem( i ) );
     213            term2= nMult( fac2, v.rep->getconstelem( i ) );
     214            newelems[i-1]= nSub( term1, term2 );
     215            nDelete( &term1 );
     216            nDelete( &term2 );
     217        }
     218        for ( i= rep->size(); i > vsize; i-- ) {
     219            newelems[i-1]= nMult( fac1, rep->getconstelem( i ) );
     220        }
     221        rep->deleteObject();
     222        rep= new fglmVectorRep( rep->size(), newelems );
     223    }
     224}
     225
     226fglmVector &
    227227fglmVector::operator = ( const fglmVector & v )
    228228{
    229229    if ( this != &v ) {
    230         if ( rep->deleteObject() )
    231             delete rep;
    232         rep = v.rep->copyObject();
     230        if ( rep->deleteObject() )
     231            delete rep;
     232        rep = v.rep->copyObject();
    233233    }
    234234    return *this;
     
    239239{
    240240    if ( rep->size() == v.rep->size() ) {
    241         if ( rep == v.rep ) return 1;
    242         else {
    243             int i;
    244             for ( i= rep->size(); i > 0; i-- )
    245                 if ( ! nEqual( rep->getconstelem( i ), v.rep->getconstelem( i ) ) )
    246                     return 0;
    247             return 1;
    248         }
     241        if ( rep == v.rep ) return 1;
     242        else {
     243            int i;
     244            for ( i= rep->size(); i > 0; i-- )
     245                if ( ! nEqual( rep->getconstelem( i ), v.rep->getconstelem( i ) ) )
     246                    return 0;
     247            return 1;
     248        }
    249249    }
    250250    return 0;
     
    257257}
    258258
    259 int 
     259int
    260260fglmVector::isZero()
    261261{
     
    263263}
    264264
    265 int 
     265int
    266266fglmVector::elemIsZero( int i )
    267267{
     
    276276    int i;
    277277    if ( rep->isUnique() ) {
    278         for ( i= rep->size(); i > 0; i-- )
    279             rep->setelem( i, nAdd( rep->getconstelem( i ), v.rep->getconstelem( i ) ) );
    280     }
    281     else 
    282     {
    283         int n = rep->size();
    284         number* newelems;
    285         newelems= (number *)Alloc( n*sizeof( number ) );
    286         for ( i= n; i > 0; i-- )
    287             newelems[i-1]= nAdd( rep->getconstelem( i ), v.rep->getconstelem( i ) );
    288         rep->deleteObject();
    289         rep= new fglmVectorRep( n, newelems );
     278        for ( i= rep->size(); i > 0; i-- )
     279            rep->setelem( i, nAdd( rep->getconstelem( i ), v.rep->getconstelem( i ) ) );
     280    }
     281    else
     282    {
     283        int n = rep->size();
     284        number* newelems;
     285        newelems= (number *)Alloc( n*sizeof( number ) );
     286        for ( i= n; i > 0; i-- )
     287            newelems[i-1]= nAdd( rep->getconstelem( i ), v.rep->getconstelem( i ) );
     288        rep->deleteObject();
     289        rep= new fglmVectorRep( n, newelems );
    290290    }
    291291    return *this;
     
    298298    int i;
    299299    if ( rep->isUnique() ) {
    300         for ( i= rep->size(); i > 0; i-- )
    301             rep->setelem( i, nSub( rep->getconstelem( i ), v.rep->getconstelem( i ) ) );
    302     }
    303     else 
    304     {
    305         int n = rep->size();
    306         number* newelems;
    307         newelems= (number *)Alloc( n*sizeof( number ) );
    308         for ( i= n; i > 0; i-- )
    309             newelems[i-1]= nSub( rep->getconstelem( i ), v.rep->getconstelem( i ) );
    310         rep->deleteObject();
    311         rep= new fglmVectorRep( n, newelems );
     300        for ( i= rep->size(); i > 0; i-- )
     301            rep->setelem( i, nSub( rep->getconstelem( i ), v.rep->getconstelem( i ) ) );
     302    }
     303    else
     304    {
     305        int n = rep->size();
     306        number* newelems;
     307        newelems= (number *)Alloc( n*sizeof( number ) );
     308        for ( i= n; i > 0; i-- )
     309            newelems[i-1]= nSub( rep->getconstelem( i ), v.rep->getconstelem( i ) );
     310        rep->deleteObject();
     311        rep= new fglmVectorRep( n, newelems );
    312312    }
    313313    return *this;
     
    320320    int i;
    321321    if ( ! rep->isUnique() ) {
    322         number * temp;
    323         temp= (number *)Alloc( s*sizeof( number ) );
    324         for ( i= s; i > 0; i-- )
    325             temp[i-1]= nMult( rep->getconstelem( i ), n );
    326         rep->deleteObject();
    327         rep= new fglmVectorRep( s, temp );
    328     }
    329     else 
    330     {
    331         for (i= s; i > 0; i-- )
    332             rep->setelem( i, nMult( rep->getconstelem( i ), n ) );
     322        number * temp;
     323        temp= (number *)Alloc( s*sizeof( number ) );
     324        for ( i= s; i > 0; i-- )
     325            temp[i-1]= nMult( rep->getconstelem( i ), n );
     326        rep->deleteObject();
     327        rep= new fglmVectorRep( s, temp );
     328    }
     329    else
     330    {
     331        for (i= s; i > 0; i-- )
     332            rep->setelem( i, nMult( rep->getconstelem( i ), n ) );
    333333    }
    334334    return *this;
     
    341341    int i;
    342342    if ( ! rep->isUnique() ) {
    343         number * temp;
    344         temp= (number *)Alloc( s*sizeof( number ) );
    345         for ( i= s; i > 0; i-- ) {
    346             temp[i-1]= nDiv( rep->getconstelem( i ), n );
    347             nNormalize( temp[i-1] );
    348         }
    349         rep->deleteObject();
    350         rep= new fglmVectorRep( s, temp );
    351     }
    352     else 
    353     {
    354         for (i= s; i > 0; i-- ) {
    355             rep->setelem( i, nDiv( rep->getconstelem( i ), n ) );
    356             nNormalize( rep->getelem( i ) );
    357         }
     343        number * temp;
     344        temp= (number *)Alloc( s*sizeof( number ) );
     345        for ( i= s; i > 0; i-- ) {
     346            temp[i-1]= nDiv( rep->getconstelem( i ), n );
     347            nNormalize( temp[i-1] );
     348        }
     349        rep->deleteObject();
     350        rep= new fglmVectorRep( s, temp );
     351    }
     352    else
     353    {
     354        for (i= s; i > 0; i-- ) {
     355            rep->setelem( i, nDiv( rep->getconstelem( i ), n ) );
     356            nNormalize( rep->getelem( i ) );
     357        }
    358358    }
    359359    return *this;
    360360}
    361361
    362 fglmVector 
    363 operator - ( const fglmVector & v ) 
     362fglmVector
     363operator - ( const fglmVector & v )
    364364{
    365365    fglmVector temp( v.size() );
     
    367367    number n ;
    368368    for ( i= v.size(); i > 0; i-- ) {
    369         n= nCopy( v.getconstelem( i ) );
    370         n= nNeg( n );
    371         temp.setelem( i, n );
     369        n= nCopy( v.getconstelem( i ) );
     370        n= nNeg( n );
     371        temp.setelem( i, n );
    372372    }
    373373    return temp;
    374374}
    375375
    376 fglmVector 
    377 operator + ( const fglmVector & lhs, const fglmVector & rhs ) 
     376fglmVector
     377operator + ( const fglmVector & lhs, const fglmVector & rhs )
    378378{
    379379    fglmVector temp= lhs;
     
    382382}
    383383
    384 fglmVector 
     384fglmVector
    385385operator - ( const fglmVector & lhs, const fglmVector & rhs )
    386386{
     
    390390}
    391391
    392 fglmVector 
     392fglmVector
    393393operator * ( const fglmVector & v, const number n )
    394394{
     
    413413}
    414414
    415 const number 
     415const number
    416416fglmVector::getconstelem( int i ) const
    417417{
     
    427427}
    428428
    429 number 
     429number
    430430fglmVector::gcd() const
    431 { 
     431{
    432432    int i= rep->size();
    433433    BOOLEAN found = FALSE;
     
    436436    number current;
    437437    while( i > 0 && ! found ) {
    438         current= rep->getconstelem( i );
    439         if ( ! nIsZero( current ) ) {
    440             theGcd= nCopy( current );
    441             found= TRUE;
    442             if ( ! nGreaterZero( theGcd ) ) {
    443                 theGcd= nNeg( theGcd );
    444             }
    445             if ( nIsOne( theGcd ) ) gcdIsOne= TRUE;
    446         }
    447         i--;
     438        current= rep->getconstelem( i );
     439        if ( ! nIsZero( current ) ) {
     440            theGcd= nCopy( current );
     441            found= TRUE;
     442            if ( ! nGreaterZero( theGcd ) ) {
     443                theGcd= nNeg( theGcd );
     444            }
     445            if ( nIsOne( theGcd ) ) gcdIsOne= TRUE;
     446        }
     447        i--;
    448448    }
    449449    if ( found ) {
    450         while ( i > 0 && ! gcdIsOne ) {
    451             current= rep->getconstelem( i );
    452             if ( ! nIsZero( current ) ) {
    453                 number temp= nGcd( theGcd, current );
    454                 nDelete( &theGcd );
    455                 theGcd= temp;
    456                 if ( nIsOne( theGcd ) ) gcdIsOne= TRUE;
    457             }
    458             i--;
    459         }
    460     }
    461     else 
    462         theGcd= nInit( 0 );
     450        while ( i > 0 && ! gcdIsOne ) {
     451            current= rep->getconstelem( i );
     452            if ( ! nIsZero( current ) ) {
     453                number temp= nGcd( theGcd, current );
     454                nDelete( &theGcd );
     455                theGcd= temp;
     456                if ( nIsOne( theGcd ) ) gcdIsOne= TRUE;
     457            }
     458            i--;
     459        }
     460    }
     461    else
     462        theGcd= nInit( 0 );
    463463    return theGcd;
    464464}
    465465
    466466number
    467 fglmVector::clearDenom() 
     467fglmVector::clearDenom()
    468468{
    469469    number theLcm = nInit( 1 );
     
    472472    int i;
    473473    for ( i= size(); i > 0; i-- ) {
    474         if ( ! nIsZero( rep->getconstelem(i) ) ) {
    475             isZero= FALSE;
    476             number temp= nLcm( theLcm, rep->getconstelem( i ) );
    477             nDelete( &theLcm );
    478             theLcm= temp;
    479         }
     474        if ( ! nIsZero( rep->getconstelem(i) ) ) {
     475            isZero= FALSE;
     476            number temp= nLcm( theLcm, rep->getconstelem( i ) );
     477            nDelete( &theLcm );
     478            theLcm= temp;
     479        }
    480480    }
    481481    if ( isZero ) {
    482         nDelete( &theLcm );
    483         theLcm= nInit( 0 );
     482        nDelete( &theLcm );
     483        theLcm= nInit( 0 );
    484484    }
    485485    else {
    486         if ( ! nIsOne( theLcm ) ) {
    487             *this *= theLcm;
    488             for ( i= size(); i > 0; i-- ) {
    489                 nNormalize( rep->getelem( i ) );
    490             }
    491         }
     486        if ( ! nIsOne( theLcm ) ) {
     487            *this *= theLcm;
     488            for ( i= size(); i > 0; i-- ) {
     489                nNormalize( rep->getelem( i ) );
     490            }
     491        }
    492492    }
    493493    return theLcm;
  • Singular/fglmzero.cc

    r073d2e r5812c69  
    11// emacs edit mode for this file is -*- C++ -*-
    2 // $Id: fglmzero.cc,v 1.17 1998-06-03 15:25:20 obachman Exp $
     2// $Id: fglmzero.cc,v 1.18 1998-09-24 09:59:40 Singular Exp $
    33
    44/****************************************
    55*  Computer Algebra System SINGULAR     *
    66****************************************/
    7 /* 
     7/*
    88* ABSTRACT - The FGLM-Algorithm
    99*   Implementation of the fglm algorithm for 0-dimensional ideals,
    1010*   based on an idea by Faugere/Gianni/Lazard and Mora.
    11 *   The procedure CalculateFunctionals calculates the functionals 
     11*   The procedure CalculateFunctionals calculates the functionals
    1212*   which define the given ideal in the source ring. They build the
    1313*   input for GroebnerViaFunctionals, which defines the reduced
     
    3535#include "fglmgauss.h"
    3636// assumes, that NOSTREAMIO is set in factoryconf.h, which is included
    37 // by templates/list.h. 
     37// by templates/list.h.
    3838#include <templates/ftmpl_list.h>
    3939#define PROT(msg)
     
    4646// internal Version: 1.3.1.12
    4747// ============================================================
    48 //!      The idealFunctionals 
     48//!      The idealFunctionals
    4949// ============================================================
    5050
     
    7171    int * currentSize;
    7272    matHeader ** func;
    73     matHeader * grow( int var ); 
     73    matHeader * grow( int var );
    7474public:
    7575    idealFunctionals( int blockSize, int numFuncs );
    7676    ~idealFunctionals();
    7777
    78     int dimen() const { fglmASSERT( _size>0, "called to early"); return _size; } 
     78    int dimen() const { fglmASSERT( _size>0, "called to early"); return _size; }
    7979    void endofConstruction();
    8080    void map( ring source );
     
    8585};
    8686
    87 idealFunctionals::idealFunctionals( int blockSize, int numFuncs ) 
     87idealFunctionals::idealFunctionals( int blockSize, int numFuncs )
    8888{
    8989    int k;
     
    9494
    9595    currentSize= (int *)Alloc( _nfunc*sizeof( int ) );
    96     for ( k= _nfunc-1; k >= 0; k-- ) 
    97         currentSize[k]= 0;
     96    for ( k= _nfunc-1; k >= 0; k-- )
     97        currentSize[k]= 0;
    9898
    9999    func= (matHeader **)Alloc( _nfunc*sizeof( matHeader * ) );
    100     for ( k= _nfunc-1; k >= 0; k-- ) 
    101         func[k]= (matHeader *)Alloc( _max*sizeof( matHeader ) );
     100    for ( k= _nfunc-1; k >= 0; k-- )
     101        func[k]= (matHeader *)Alloc( _max*sizeof( matHeader ) );
    102102}
    103103
     
    110110    matElem * elemp;
    111111    for ( k= _nfunc-1; k >= 0; k-- ) {
    112         for ( l= _size-1, colp= func[k]; l >= 0; l--, colp++ ) {
    113             if ( ( colp->owner == TRUE ) && ( colp->size > 0 ) ) {
    114                 for ( row= colp->size-1, elemp= colp->elems; row >= 0; row--, elemp++ )
    115                     nDelete( & elemp->elem );
    116                 Free( (ADDRESS)colp->elems, colp->size*sizeof( matElem ) );
    117             }
    118         }
    119         Free( (ADDRESS)func[k], _max*sizeof( matHeader ) );
     112        for ( l= _size-1, colp= func[k]; l >= 0; l--, colp++ ) {
     113            if ( ( colp->owner == TRUE ) && ( colp->size > 0 ) ) {
     114                for ( row= colp->size-1, elemp= colp->elems; row >= 0; row--, elemp++ )
     115                    nDelete( & elemp->elem );
     116                Free( (ADDRESS)colp->elems, colp->size*sizeof( matElem ) );
     117            }
     118        }
     119        Free( (ADDRESS)func[k], _max*sizeof( matHeader ) );
    120120    }
    121121    Free( (ADDRESS)func, _nfunc*sizeof( matHeader * ) );
     
    124124
    125125void
    126 idealFunctionals::endofConstruction() 
     126idealFunctionals::endofConstruction()
    127127{
    128128    _size= currentSize[0];
     
    130130
    131131void
    132 idealFunctionals::map( ring source ) 
     132idealFunctionals::map( ring source )
    133133{
    134134    // maps from ring source to currentRing.
     
    141141    maFindPerm( source->names, source->N, NULL, 0, currRing->names, currRing->N, NULL, 0, perm, NULL );
    142142    nSetMap( source->ch, source->parameter, source->P, source->minpoly );
    143    
     143
    144144    matHeader ** temp = (matHeader **)Alloc( _nfunc*sizeof( matHeader * ));
    145145    for ( var= 0; var < _nfunc; var ++ ) {
    146         for ( col= 0, colp= func[var]; col < _size; col++, colp++ ) {
    147             if ( colp->owner == TRUE ) {
    148                 for ( row= colp->size-1, elemp= colp->elems; row >= 0; row--, elemp++ ) {
    149                     newelem= nMap( elemp->elem );
    150                     nDelete( & elemp->elem );
    151                     elemp->elem= newelem;
    152                 }
    153             }
    154         }
    155         temp[ perm[var+1]-1 ]= func[var];
     146        for ( col= 0, colp= func[var]; col < _size; col++, colp++ ) {
     147            if ( colp->owner == TRUE ) {
     148                for ( row= colp->size-1, elemp= colp->elems; row >= 0; row--, elemp++ ) {
     149                    newelem= nMap( elemp->elem );
     150                    nDelete( & elemp->elem );
     151                    elemp->elem= newelem;
     152                }
     153            }
     154        }
     155        temp[ perm[var+1]-1 ]= func[var];
    156156    }
    157157    Free( (ADDRESS)func, _nfunc*sizeof( matHeader * ) );
     
    161161
    162162matHeader *
    163 idealFunctionals::grow( int var ) 
     163idealFunctionals::grow( int var )
    164164{
    165165    if ( currentSize[var-1] == _max ) {
    166         int k;
    167         for ( k= _nfunc; k > 0; k-- )
    168             func[k-1]= (matHeader *)ReAlloc( func[k-1], _max*sizeof( matHeader ), (_max + _block)*sizeof( matHeader ) );
    169         _max+= _block;
     166        int k;
     167        for ( k= _nfunc; k > 0; k-- )
     168            func[k-1]= (matHeader *)ReAlloc( func[k-1], _max*sizeof( matHeader ), (_max + _block)*sizeof( matHeader ) );
     169        _max+= _block;
    170170    }
    171171    currentSize[var-1]++;
    172     return func[var-1] + currentSize[var-1] - 1; 
     172    return func[var-1] + currentSize[var-1] - 1;
    173173}
    174174
     
    183183    elems->elem= nInit( 1 );
    184184    for ( k= divisors[0]; k > 0; k-- ) {
    185         fglmASSERT( 0 < divisors[k] && divisors[k] <= _nfunc, "wrong divisor" );
    186         matHeader * colp = grow( divisors[k] );
    187         colp->size= 1;
    188         colp->elems= elems;
    189         colp->owner= owner;
    190         owner= FALSE;
    191     }
    192 }
    193 
    194    
     185        fglmASSERT( 0 < divisors[k] && divisors[k] <= _nfunc, "wrong divisor" );
     186        matHeader * colp = grow( divisors[k] );
     187        colp->size= 1;
     188        colp->elems= elems;
     189        colp->owner= owner;
     190        owner= FALSE;
     191    }
     192}
     193
     194
    195195void
    196196idealFunctionals::insertCols( int * divisors, const fglmVector to )
     
    204204    BOOLEAN owner = TRUE;
    205205    if ( numElems > 0 ) {
    206         elems= (matElem *)Alloc( numElems * sizeof( matElem ) );
    207         for ( k= 1, l= 1, elemp= elems; k <= numElems; k++, elemp++ ) {
    208             while ( nIsZero( to.getconstelem(l) ) ) l++;
    209             elemp->row= l;
    210             elemp->elem= nCopy( to.getconstelem( l ) );
    211             l++; // hochzaehlen, damit wir nicht noch einmal die gleiche Stelle testen
    212         }
     206        elems= (matElem *)Alloc( numElems * sizeof( matElem ) );
     207        for ( k= 1, l= 1, elemp= elems; k <= numElems; k++, elemp++ ) {
     208            while ( nIsZero( to.getconstelem(l) ) ) l++;
     209            elemp->row= l;
     210            elemp->elem= nCopy( to.getconstelem( l ) );
     211            l++; // hochzaehlen, damit wir nicht noch einmal die gleiche Stelle testen
     212        }
    213213    }
    214214    else
    215         elems= NULL;
     215        elems= NULL;
    216216    for ( k= divisors[0]; k > 0; k-- ) {
    217         fglmASSERT( 0 < divisors[k] && divisors[k] <= _nfunc, "wrong divisor" );
    218         matHeader * colp = grow( divisors[k] );
    219         colp->size= numElems;
    220         colp->elems= elems;
    221         colp->owner= owner;
    222         owner= FALSE;
     217        fglmASSERT( 0 < divisors[k] && divisors[k] <= _nfunc, "wrong divisor" );
     218        matHeader * colp = grow( divisors[k] );
     219        colp->size= numElems;
     220        colp->elems= elems;
     221        colp->owner= owner;
     222        owner= FALSE;
    223223    }
    224224}
     
    236236    fglmASSERT( currentSize[var-1]+1 >= vsize, "wrong v.size()" );
    237237    for ( k= 1, colp= func[var-1]; k <= vsize; k++, colp++ ) {
    238         factor= v.getconstelem( k );
    239         if ( ! nIsZero( factor ) ) {
    240             for ( l= colp->size-1, elemp= colp->elems; l >= 0; l--, elemp++ ) {
    241                 temp= nMult( factor, elemp->elem );
    242                 number newelem= nAdd( result.getconstelem( elemp->row ), temp );
    243                 nDelete( & temp );
    244                 nNormalize( newelem );
    245                 result.setelem( elemp->row, newelem );
    246             }   
    247         }
     238        factor= v.getconstelem( k );
     239        if ( ! nIsZero( factor ) ) {
     240            for ( l= colp->size-1, elemp= colp->elems; l >= 0; l--, elemp++ ) {
     241                temp= nMult( factor, elemp->elem );
     242                number newelem= nAdd( result.getconstelem( elemp->row ), temp );
     243                nDelete( & temp );
     244                nNormalize( newelem );
     245                result.setelem( elemp->row, newelem );
     246            }
     247        }
    248248    }
    249249    return result;
     
    260260    int k, l;
    261261    for ( k= 1, colp= func[var-1]; k <= _size; k++, colp++ ) {
    262         factor= v.getconstelem( k );
    263         if ( ! nIsZero( factor ) ) {
    264             for ( l= colp->size-1, elemp= colp->elems; l >= 0; l--, elemp++ ) {
    265                 temp= nMult( factor, elemp->elem );
    266                 number newelem= nAdd( result.getconstelem( elemp->row ), temp );
    267                 nDelete( & temp );
    268                 nNormalize( newelem );
    269                 result.setelem( elemp->row, newelem );
    270             }
    271         }
     262        factor= v.getconstelem( k );
     263        if ( ! nIsZero( factor ) ) {
     264            for ( l= colp->size-1, elemp= colp->elems; l >= 0; l--, elemp++ ) {
     265                temp= nMult( factor, elemp->elem );
     266                number newelem= nAdd( result.getconstelem( elemp->row ), temp );
     267                nDelete( & temp );
     268                nNormalize( newelem );
     269                result.setelem( elemp->row, newelem );
     270            }
     271        }
    272272    }
    273273    return result;
     
    275275
    276276// ============================================================
    277 //!      The old basis 
     277//!      The old basis
    278278// ============================================================
    279279
     
    283283//      the basis when the normalForm was computed.
    284284//     monom gets deleted when borderElem comes out of scope.
    285 class borderElem 
     285class borderElem
    286286{
    287287public:
     
    292292    ~borderElem() { pDelete1( &monom ); }
    293293#ifndef HAVE_EXPLICIT_CONSTR
    294     void insertElem( poly p, fglmVector n ) 
     294    void insertElem( poly p, fglmVector n )
    295295    {
    296         monom= p;
    297         nf= n;
     296        monom= p;
     297        nf= n;
    298298    }
    299299#endif
     
    303303//     The declaration of class fglmSelem is found in fglm.h
    304304
    305 fglmSelem::fglmSelem( poly p, int var ) : numVars( 0 ), monom( p ) 
    306 {
    307     for ( int k = pVariables; k > 0; k-- ) 
    308         if ( pGetExp( monom, k ) > 0 )
    309             numVars++;
     305fglmSelem::fglmSelem( poly p, int var ) : numVars( 0 ), monom( p )
     306{
     307    for ( int k = pVariables; k > 0; k-- )
     308        if ( pGetExp( monom, k ) > 0 )
     309            numVars++;
    310310    divisors= (int *)Alloc( (numVars+1)*sizeof( int ) );
    311311    divisors[0]= 0;
     
    313313}
    314314
    315 void 
     315void
    316316fglmSelem::cleanup()
    317317{
     
    355355};
    356356
    357 fglmSdata::fglmSdata( const ideal thisIdeal ) 
     357fglmSdata::fglmSdata( const ideal thisIdeal )
    358358{
    359359    // An dieser Stelle kann die BlockSize ( =BS ) noch sinnvoller berechnet
     
    365365    basisMax= basisBS;
    366366    basisSize= 0;
    367     basis= (polyset)Alloc( basisMax*sizeof( poly ) ); 
     367    basis= (polyset)Alloc( basisMax*sizeof( poly ) );
    368368
    369369    borderBS= 100;
     
    382382{
    383383    for ( int k = basisSize; k > 0; k-- )
    384         pDelete1( basis + k );  //. rem: basis runs from basis[1]..basis[basisSize]
     384        pDelete1( basis + k );  //. rem: basis runs from basis[1]..basis[basisSize]
    385385    Free( (ADDRESS)basis, basisMax*sizeof( poly ) );
    386386#ifndef HAVE_EXPLICIT_CONSTR
     
    388388#else
    389389    for ( int l = borderSize; l > 0; l-- )
    390         // rem: the polys of borderElem are deleted via ~borderElem()
    391         border[l].~borderElem();
     390        // rem: the polys of borderElem are deleted via ~borderElem()
     391        border[l].~borderElem();
    392392    Free( (ADDRESS)border, borderMax*sizeof( borderElem ) );
    393393#endif
    394394}
    395395
    396 //     Inserts poly p without copying into basis, reAllocs Memory if necessary, 
     396//     Inserts poly p without copying into basis, reAllocs Memory if necessary,
    397397//      increases basisSize and returns the new basisSize.
    398398//     Remember: The elements of basis are deleted via pDelete in ~fglmSdata!
    399399//     Sets m= NULL to indicate that now basis is ow(e?)ing the poly.
    400400int
    401 fglmSdata::newBasisElem( poly & m ) 
     401fglmSdata::newBasisElem( poly & m )
    402402{
    403403    basisSize++;
    404404    if ( basisSize == basisMax ) {
    405         basis= (polyset)ReAlloc( basis, basisMax*sizeof( poly ), (basisMax + basisBS)*sizeof( poly ) );
    406         basisMax+= basisBS;
     405        basis= (polyset)ReAlloc( basis, basisMax*sizeof( poly ), (basisMax + basisBS)*sizeof( poly ) );
     406        basisMax+= basisBS;
    407407    }
    408408    basis[basisSize]= m;
     
    411411}
    412412
    413 //     Inserts poly p and fglmvector v without copying into border, reAllocs Memory 
     413//     Inserts poly p and fglmvector v without copying into border, reAllocs Memory
    414414//      if necessary, and increases borderSize.
    415415//     Remember: The poly of border is deleted via ~borderElem in ~fglmSdata!
     
    421421    if ( borderSize == borderMax ) {
    422422#ifndef HAVE_EXPLICIT_CONSTR
    423         borderElem * tempborder = new borderElem[ borderMax+borderBS ];
    424         for ( int k = 0; k < borderMax; k++ ) {
    425             tempborder[k]= border[k];
    426             border[k].insertElem( NULL, fglmVector() );
    427         }
    428         delete [] border;
    429         border= tempborder;
     423        borderElem * tempborder = new borderElem[ borderMax+borderBS ];
     424        for ( int k = 0; k < borderMax; k++ ) {
     425            tempborder[k]= border[k];
     426            border[k].insertElem( NULL, fglmVector() );
     427        }
     428        delete [] border;
     429        border= tempborder;
    430430#else
    431         border= (borderElem *)ReAlloc( border, borderMax*sizeof( borderElem ), (borderMax + borderBS)*sizeof( borderElem ) );
     431        border= (borderElem *)ReAlloc( border, borderMax*sizeof( borderElem ), (borderMax + borderBS)*sizeof( borderElem ) );
    432432#endif
    433         borderMax+= borderBS;
     433        borderMax+= borderBS;
    434434    }
    435435#ifndef HAVE_EXPLICIT_CONSTR
     
    449449}
    450450
    451 //     Multiplies basis[basisSize] with all ringvariables and inserts the new monomials 
     451//     Multiplies basis[basisSize] with all ringvariables and inserts the new monomials
    452452//      into the list of candidates, according to the given order. If a monomial already
    453 //      exists, then "insertions" and "divisors" are updated. 
    454 //     Assumes that ringvar(k) < ringvar(l) for k > l 
     453//      exists, then "insertions" and "divisors" are updated.
     454//     Assumes that ringvar(k) < ringvar(l) for k > l
    455455void
    456456fglmSdata::updateCandidates()
     
    464464    int state = 0;
    465465    while ( k >= 1 ) {
    466         newmonom = pCopy( m ); 
    467         pIncrExp( newmonom, k );
    468         pSetm( newmonom );
    469         done= FALSE;
    470         while ( list.hasItem() && (done == FALSE) ) {
    471             if ( (state= pComp( list.getItem().monom, newmonom )) < 0 )
    472                 list++;
    473             else done= TRUE;
    474         }
    475         if ( done == FALSE ) {
    476             nlist.append( fglmSelem( newmonom, k ) );
    477             break;
    478         }
    479         if ( state == 0 ) {
    480             list.getItem().newDivisor( k );
    481             pDelete1( &newmonom );
    482         }
    483         else {
    484             list.insert( fglmSelem( newmonom, k ) );
    485         }
    486         k--;
     466        newmonom = pCopy( m );
     467        pIncrExp( newmonom, k );
     468        pSetm( newmonom );
     469        done= FALSE;
     470        while ( list.hasItem() && (done == FALSE) ) {
     471            if ( (state= pComp( list.getItem().monom, newmonom )) < 0 )
     472                list++;
     473            else done= TRUE;
     474        }
     475        if ( done == FALSE ) {
     476            nlist.append( fglmSelem( newmonom, k ) );
     477            break;
     478        }
     479        if ( state == 0 ) {
     480            list.getItem().newDivisor( k );
     481            pDelete1( &newmonom );
     482        }
     483        else {
     484            list.insert( fglmSelem( newmonom, k ) );
     485        }
     486        k--;
    487487    }
    488488    while ( --k >= 1 ) {
    489         newmonom= pCopy( m ); // HIER
    490         pIncrExp( newmonom, k );
    491         pSetm( newmonom );
    492         nlist.append( fglmSelem( newmonom, k ) );
     489        newmonom= pCopy( m ); // HIER
     490        pIncrExp( newmonom, k );
     491        pSetm( newmonom );
     492        nlist.append( fglmSelem( newmonom, k ) );
    493493    }
    494494}
     
    498498//      coefficients.)
    499499int
    500 fglmSdata::getEdgeNumber( const poly m ) const 
    501 {
    502     for ( int k = idelems; k > 0; k-- ) 
    503         if ( pEqual( m, (theIdeal->m)[k-1] ) )
    504             return k;
     500fglmSdata::getEdgeNumber( const poly m ) const
     501{
     502    for ( int k = idelems; k > 0; k-- )
     503        if ( pEqual( m, (theIdeal->m)[k-1] ) )
     504            return k;
    505505    return 0;
    506506}
    507507
    508 //     Returns the fglmVector v, s.t. 
     508//     Returns the fglmVector v, s.t.
    509509//        p = v[1]*basis(1) + .. + v[basisSize]*basis(basisSize)
    510510//     So the size of v depends on the current size of the basis.
     
    512512//      smaller than basis[basisSize] and that basis[k] < basis[l] for k < l.
    513513fglmVector
    514 fglmSdata::getVectorRep( const poly p ) 
     514fglmSdata::getVectorRep( const poly p )
    515515{
    516516    fglmVector temp( basisSize );
     
    518518    int num = basisSize;
    519519    while ( m != NULL ) {
    520         int comp = pComp( m, basis[num] );
    521         if ( comp == 0 ) {
    522             fglmASSERT( num > 0, "Error(1) in fglmSdata::getVectorRep" );
    523             number newelem = nCopy( pGetCoeff( m ) );
    524             temp.setelem( num, newelem );
    525             num--;
    526             pIter( m );
    527         }
    528         else { 
    529             if ( comp < 0 ) {
    530                 num--;
    531             }
    532             else {
    533                 // This is the place where we can detect if the sourceIdeal
    534                 // is not reduced. In this case m is not in basis[]. Since basis[]
    535                 // is ordered this is then and only then the case, if basis[i]<m
    536                 // and basis[j]>m for all j>i
    537                 _state= FALSE;
    538                 return temp;
    539             }
    540         }
     520        int comp = pComp( m, basis[num] );
     521        if ( comp == 0 ) {
     522            fglmASSERT( num > 0, "Error(1) in fglmSdata::getVectorRep" );
     523            number newelem = nCopy( pGetCoeff( m ) );
     524            temp.setelem( num, newelem );
     525            num--;
     526            pIter( m );
     527        }
     528        else {
     529            if ( comp < 0 ) {
     530                num--;
     531            }
     532            else {
     533                // This is the place where we can detect if the sourceIdeal
     534                // is not reduced. In this case m is not in basis[]. Since basis[]
     535                // is ordered this is then and only then the case, if basis[i]<m
     536                // and basis[j]>m for all j>i
     537                _state= FALSE;
     538                return temp;
     539            }
     540        }
    541541    }
    542542    return temp;
     
    545545//     Searches through the border for a monomoial bm which devides m and returns
    546546//      its normalform in vector representation.
    547 //     var contains the number of the variable v, s.t. bm = m * v 
     547//     var contains the number of the variable v, s.t. bm = m * v
    548548fglmVector
    549549fglmSdata::getBorderDiv( const poly m, int & var ) const
     
    551551//     int num2 = borderSize;
    552552//     while ( num2 > 0 ) {
    553 //      poly temp = border[num2].monom;
    554 //      if ( pDivisibleBy( temp, m ) ) {
    555 //          poly divisor = pDivideM( m, temp );
    556 //          int var = pIsPurePower( divisor );
    557 //          if ( (var != 0) && (pGetCoeff( divisor, var ) == 1) ) {
    558 //              Print( "poly %s divides poly %s", pString( temp ), pString( m ) );
    559 //          }
    560 //      }
    561 //      num2--;
     553//         poly temp = border[num2].monom;
     554//         if ( pDivisibleBy( temp, m ) ) {
     555//             poly divisor = pDivideM( m, temp );
     556//             int var = pIsPurePower( divisor );
     557//             if ( (var != 0) && (pGetCoeff( divisor, var ) == 1) ) {
     558//                 Print( "poly %s divides poly %s", pString( temp ), pString( m ) );
     559//             }
     560//         }
     561//         num2--;
    562562//     }
    563563    int num = borderSize;
    564564    while ( num > 0 ) {
    565         poly temp = border[num].monom;
    566         if ( pDivisibleBy( temp, m ) ) {
    567             var = pVariables;
    568             while ( var > 0 ) {
    569                 if ( (pGetExp( m, var ) - pGetExp( temp, var )) == 1 )
    570                     return border[num].nf;
    571                 var--;
    572             }
    573         }
    574         num--;
     565        poly temp = border[num].monom;
     566        if ( pDivisibleBy( temp, m ) ) {
     567            var = pVariables;
     568            while ( var > 0 ) {
     569                if ( (pGetExp( m, var ) - pGetExp( temp, var )) == 1 )
     570                    return border[num].nf;
     571                var--;
     572            }
     573        }
     574        num--;
    575575    }
    576576    return fglmVector();
    577577}
    578578
    579 //     Calculates the defining Functionals for the ideal "theIdeal" and 
     579//     Calculates the defining Functionals for the ideal "theIdeal" and
    580580//     returns them in "l".
    581581//     The ideal has to be zero-dimensional and reduced and has to be a
    582582//     real subset of the polynomal ring.
    583 //     In any case it has to be zero-dimensional and minimal (check this 
     583//     In any case it has to be zero-dimensional and minimal (check this
    584584//      via fglmIdealcheck). Any minimal but not reduced ideal is detected.
    585585//      In this case it returns FglmNotReduced.
     
    600600    STICKYPROT(".");
    601601    while ( data.candidatesLeft() == TRUE ) {
    602         fglmSelem candidate = data.nextCandidate();
    603         if ( candidate.isBasisOrEdge() == TRUE ) {
    604             int edge = data.getEdgeNumber( candidate.monom );
    605             if ( edge != 0 ) {
    606                 // now candidate is an edge, i.e. we know its normalform:
    607                 // NF(p) = - ( tail(p)/LC(p) )
    608                 poly nf = data.getSpanPoly( edge );
    609                 pNorm( nf );
    610                 pDelete1( &nf );  //. deletes the leadingmonomial
    611                 nf= pNeg( nf );
    612                 fglmVector nfv = data.getVectorRep( nf );
    613                 l.insertCols( candidate.divisors, nfv );
    614                 data.newBorderElem( candidate.monom, nfv );
    615                 pDelete( &nf );
    616                 STICKYPROT( "+" );
    617             }
    618             else {
    619                 int basis= data.newBasisElem( candidate.monom );
    620                 data.updateCandidates();
    621                 l.insertCols( candidate.divisors, basis );
    622                 STICKYPROT( "." );
    623             }
    624         }
    625         else {
    626             int var = 0;
    627             fglmVector temp = data.getBorderDiv( candidate.monom, var );
    628             fglmASSERT( var > 0, "this should never happen" );
    629             fglmVector nfv = l.addCols( var, data.getBasisSize(), temp );
    630             data.newBorderElem( candidate.monom, nfv );
    631             l.insertCols( candidate.divisors, nfv );
    632             STICKYPROT( "-" );
    633         }
    634         candidate.cleanup();
     602        fglmSelem candidate = data.nextCandidate();
     603        if ( candidate.isBasisOrEdge() == TRUE ) {
     604            int edge = data.getEdgeNumber( candidate.monom );
     605            if ( edge != 0 ) {
     606                // now candidate is an edge, i.e. we know its normalform:
     607                // NF(p) = - ( tail(p)/LC(p) )
     608                poly nf = data.getSpanPoly( edge );
     609                pNorm( nf );
     610                pDelete1( &nf );  //. deletes the leadingmonomial
     611                nf= pNeg( nf );
     612                fglmVector nfv = data.getVectorRep( nf );
     613                l.insertCols( candidate.divisors, nfv );
     614                data.newBorderElem( candidate.monom, nfv );
     615                pDelete( &nf );
     616                STICKYPROT( "+" );
     617            }
     618            else {
     619                int basis= data.newBasisElem( candidate.monom );
     620                data.updateCandidates();
     621                l.insertCols( candidate.divisors, basis );
     622                STICKYPROT( "." );
     623            }
     624        }
     625        else {
     626            int var = 0;
     627            fglmVector temp = data.getBorderDiv( candidate.monom, var );
     628            fglmASSERT( var > 0, "this should never happen" );
     629            fglmVector nfv = l.addCols( var, data.getBasisSize(), temp );
     630            data.newBorderElem( candidate.monom, nfv );
     631            l.insertCols( candidate.divisors, nfv );
     632            STICKYPROT( "-" );
     633        }
     634        candidate.cleanup();
    635635    } //. while ( data.candidatesLeft() == TRUE )
    636636    l.endofConstruction();
     
    645645//     The declaration of class fglmDelem is found in fglm.h
    646646
    647 fglmDelem::fglmDelem( poly & m, fglmVector mv, int v ) : insertions( 0 ), v( mv ), var( v ) 
    648 {
    649     monom= m; 
     647fglmDelem::fglmDelem( poly & m, fglmVector mv, int v ) : insertions( 0 ), v( mv ), var( v )
     648{
     649    monom= m;
    650650    m= NULL;
    651651    for ( int k = pVariables; k > 0; k-- )
    652         if ( pGetExp( monom, k ) > 0 )
    653             insertions++;
     652        if ( pGetExp( monom, k ) > 0 )
     653            insertions++;
    654654    // Wir gehen davon aus, dass ein fglmDelem direkt bei der Erzeugung
    655655    // auch in eine Liste eingefuegt wird. Daher wird hier automatisch
     
    662662{
    663663    if ( monom != NULL ) {
    664         pDelete1( &monom );
     664        pDelete1( &monom );
    665665    }
    666666}
     
    679679    oldGaussElem( const fglmVector newv, const fglmVector newp, number & newpdenom, number & newfac ) : v( newv ), p( newp ), pdenom( newpdenom ), fac( newfac )
    680680    {
    681         newpdenom= NULL;
    682         newfac= NULL;
     681        newpdenom= NULL;
     682        newfac= NULL;
    683683    }
    684684    ~oldGaussElem();
    685685#ifndef HAVE_EXPLICIT_CONSTR
    686     void insertElem( const fglmVector newv, const fglmVector newp, number & newpdenom, number & newfac ) 
     686    void insertElem( const fglmVector newv, const fglmVector newp, number & newpdenom, number & newfac )
    687687    {
    688         v= newv;
    689         p= newp;
    690         pdenom= newpdenom;
    691         fac= newfac;
    692         newpdenom= NULL;
    693         newfac= NULL;
     688        v= newv;
     689        p= newp;
     690        pdenom= newpdenom;
     691        fac= newfac;
     692        newpdenom= NULL;
     693        newfac= NULL;
    694694    }
    695695#endif
     
    703703
    704704
    705 class fglmDdata 
     705class fglmDdata
    706706{
    707707private:
     
    712712    int basisSize;  //. the CURRENT basisSize, i.e. basisSize <= dimen
    713713    polyset basis;  // [1]..[dimen]. The monoms of the new Vectorspace-basis
    714    
     714
    715715    int groebnerBS;
    716716    int groebnerSize;
     
    729729    void newGroebnerPoly( fglmVector & v, poly & p );
    730730    void gaussreduce( fglmVector & v, fglmVector & p, number & denom );
    731     ideal buildIdeal() 
     731    ideal buildIdeal()
    732732    {
    733         idSkipZeroes( destId );
    734         return destId;
     733        idSkipZeroes( destId );
     734        return destId;
    735735    }
    736736};
     
    763763    delete [] gauss;
    764764#else
    765     for ( k= dimen; k > 0; k-- ) 
    766         gauss[k].~oldGaussElem();
     765    for ( k= dimen; k > 0; k-- )
     766        gauss[k].~oldGaussElem();
    767767    Free( (ADDRESS)gauss, (dimen+1)*sizeof( oldGaussElem ) );
    768768#endif
     
    771771    //. Remember: There is no poly in basis[0], thus k > 0
    772772    for ( k= dimen; k > 0; k-- )
    773         pDelete1( basis + k );
     773        pDelete1( basis + k );
    774774    Free( (ADDRESS)basis, (dimen+1)*sizeof( poly ) );
    775775}
    776776
    777777fglmDelem
    778 fglmDdata::nextCandidate() 
     778fglmDdata::nextCandidate()
    779779{
    780780    fglmDelem result = nlist.getFirst();
     
    783783}
    784784
    785 void 
     785void
    786786fglmDdata::newBasisElem( poly & m, fglmVector v, fglmVector p, number & denom )
    787787{
     
    793793    int k= 1;
    794794    while ( nIsZero(v.getconstelem(k)) || isPivot[k] ) {
    795         k++;
     795        k++;
    796796    }
    797797    fglmASSERT( k <= dimen, "Error(1) in fglmDdata::pivot-search");
     
    800800    k++;
    801801    while ( k <= dimen ) {
    802         if ( ! nIsZero( v.getconstelem(k) ) && ! isPivot[k] ) {
    803             if ( nGreater( v.getconstelem( k ), pivot ) ) {
    804                 pivot= v.getconstelem( k );
    805                 pivotcol= k;
    806             }
    807         }
    808         k++;
     802        if ( ! nIsZero( v.getconstelem(k) ) && ! isPivot[k] ) {
     803            if ( nGreater( v.getconstelem( k ), pivot ) ) {
     804                pivot= v.getconstelem( k );
     805                pivotcol= k;
     806            }
     807        }
     808        k++;
    809809    }
    810810    fglmASSERT( ! nIsZero( pivot ), "Error(2) fglmDdata::Pivotelement ist Null" );
    811811    isPivot[ pivotcol ]= TRUE;
    812812    perm[basisSize]= pivotcol;
    813    
     813
    814814    pivot= nCopy( v.getconstelem( pivotcol ) );
    815815#ifndef HAVE_EXPLICIT_CONSTR
     
    829829    int state = 0;
    830830    while ( k >= 1 ) {
    831         newmonom = pCopy( m );
    832         pIncrExp( newmonom, k );
    833         pSetm( newmonom );
    834         done= FALSE;
    835         while ( list.hasItem() && (done == FALSE) ) {
    836             if ( (state= pComp( list.getItem().monom, newmonom )) < 0 )
    837                 list++;
    838             else done= TRUE;
    839         }
    840         if ( done == FALSE ) {
    841             nlist.append( fglmDelem( newmonom, v, k ) );
    842             break;
    843         }
    844         if ( state == 0 ) {
    845             list.getItem().newDivisor();
    846             pDelete1( & newmonom );
    847         }
    848         else {
    849             list.insert( fglmDelem( newmonom, v, k ) );
    850         }
    851         k--;
     831        newmonom = pCopy( m );
     832        pIncrExp( newmonom, k );
     833        pSetm( newmonom );
     834        done= FALSE;
     835        while ( list.hasItem() && (done == FALSE) ) {
     836            if ( (state= pComp( list.getItem().monom, newmonom )) < 0 )
     837                list++;
     838            else done= TRUE;
     839        }
     840        if ( done == FALSE ) {
     841            nlist.append( fglmDelem( newmonom, v, k ) );
     842            break;
     843        }
     844        if ( state == 0 ) {
     845            list.getItem().newDivisor();
     846            pDelete1( & newmonom );
     847        }
     848        else {
     849            list.insert( fglmDelem( newmonom, v, k ) );
     850        }
     851        k--;
    852852    }
    853853    while ( --k >= 1 ) {
    854         newmonom= pCopy( m );
    855         pIncrExp( newmonom, k );
    856         pSetm( newmonom );
    857         nlist.append( fglmDelem( newmonom, v, k ) );
    858     }
    859 }
    860 
    861 void 
    862 fglmDdata::newGroebnerPoly( fglmVector & p, poly & m ) 
     854        newmonom= pCopy( m );
     855        pIncrExp( newmonom, k );
     856        pSetm( newmonom );
     857        nlist.append( fglmDelem( newmonom, v, k ) );
     858    }
     859}
     860
     861void
     862fglmDdata::newGroebnerPoly( fglmVector & p, poly & m )
    863863// Inserts gp = p[1]*basis(1)+..+p[basisSize]*basis(basisSize)+p[basisSize+1]*m as
    864864//  a new groebner polynomial for the ideal.
     
    873873    m= NULL;
    874874    if ( nGetChar() > 0 ) {
    875         number lead = nCopy( p.getconstelem( basisSize+1 ) );
    876         p /= lead;
    877         nDelete( & lead );
     875        number lead = nCopy( p.getconstelem( basisSize+1 ) );
     876        p /= lead;
     877        nDelete( & lead );
    878878    }
    879879    if ( nGetChar() == 0 ) {
    880         number gcd= p.gcd();
    881         fglmASSERT( ! nIsZero( gcd ), "FATAL: gcd and thus p is zero" );
    882         if ( ! nIsOne( gcd ) )
    883             p /= gcd;
    884         nDelete( & gcd );
     880        number gcd= p.gcd();
     881        fglmASSERT( ! nIsZero( gcd ), "FATAL: gcd and thus p is zero" );
     882        if ( ! nIsOne( gcd ) )
     883            p /= gcd;
     884        nDelete( & gcd );
    885885    }
    886886    pSetCoeff( result, nCopy( p.getconstelem( basisSize+1 ) ) );
    887887    for ( k= basisSize; k > 0; k-- ) {
    888         if ( ! nIsZero( p.getconstelem( k ) ) ) {
    889             temp->next= pCopy( basis[k] );
    890             pIter( temp );
    891             pSetCoeff( temp, nCopy( p.getconstelem( k ) ) );
    892         }
     888        if ( ! nIsZero( p.getconstelem( k ) ) ) {
     889            temp->next= pCopy( basis[k] );
     890            pIter( temp );
     891            pSetCoeff( temp, nCopy( p.getconstelem( k ) ) );
     892        }
    893893    }
    894894    pSetm( result );
    895895    if ( ! nGreaterZero( pGetCoeff( result ) ) ) result= pNeg( result );
    896896    if ( groebnerSize == IDELEMS( destId ) ) {
    897         pEnlargeSet( & destId->m, IDELEMS( destId ), groebnerBS );
    898         IDELEMS( destId )+= groebnerBS;
     897        pEnlargeSet( & destId->m, IDELEMS( destId ), groebnerBS );
     898        IDELEMS( destId )+= groebnerBS;
    899899    }
    900900    (destId->m)[groebnerSize]= result;
     
    903903
    904904void
    905 fglmDdata::gaussreduce( fglmVector & v, fglmVector & p, number & pdenom ) 
     905fglmDdata::gaussreduce( fglmVector & v, fglmVector & p, number & pdenom )
    906906{
    907907    int k;
     
    912912    number vdenom = v.clearDenom();
    913913    if ( ! nIsOne( vdenom ) && ! nIsZero( vdenom ) ) {
    914         p.setelem( p.size(), vdenom );
     914        p.setelem( p.size(), vdenom );
    915915    }
    916916    else {
    917         nDelete( &vdenom );
     917        nDelete( &vdenom );
    918918    }
    919919    number gcd = v.gcd();
    920920    if ( ! nIsOne( gcd ) && ! nIsZero( gcd ) ) {
    921         v /= gcd;
    922         number temp= nMult( pdenom, gcd );
    923         nDelete( &pdenom );
    924         pdenom= temp;
     921        v /= gcd;
     922        number temp= nMult( pdenom, gcd );
     923        nDelete( &pdenom );
     924        pdenom= temp;
    925925    }
    926926    nDelete( & gcd );
     
    928928    for ( k= 1; k <= basisSize; k++ ) {
    929929
    930         if ( ! v.elemIsZero( perm[k] ) ) {
    931             fac1= gauss[k].fac;
    932             fac2= nCopy( v.getconstelem( perm[k] ) );
    933             v.nihilate( fac1, fac2, gauss[k].v );
    934             fac1= nMult( fac1, gauss[k].pdenom );
    935             temp= nMult( fac2, pdenom );
    936             nDelete( &fac2 );
    937             fac2= temp;
    938             p.nihilate( fac1, fac2, gauss[k].p );
    939             temp= nMult( pdenom, gauss[k].pdenom );
    940             nDelete( &pdenom );
    941             pdenom= temp;
    942 
    943             nDelete( & fac1 );
    944             nDelete( & fac2 );
    945             number gcd = v.gcd();
    946             if ( ! nIsOne( gcd ) && ! nIsZero( gcd ) ) {
    947                 v /= gcd;
    948                 number temp= nMult( pdenom, gcd );
    949                 nDelete( &pdenom );
    950                 pdenom= temp;
    951             }
    952             nDelete( & gcd );
    953             gcd= p.gcd();
    954             temp= nGcd( pdenom, gcd );
    955             nDelete( &gcd );
    956             gcd= temp;
    957             if ( ! nIsZero( gcd ) && ! nIsOne( gcd ) ) {
    958                 p /= gcd;
    959                 temp= nDiv( pdenom, gcd );
    960                 nDelete( & pdenom );
    961                 pdenom= temp;
    962                 nNormalize( pdenom );
    963             }
    964             nDelete( & gcd );
    965         }
     930        if ( ! v.elemIsZero( perm[k] ) ) {
     931            fac1= gauss[k].fac;
     932            fac2= nCopy( v.getconstelem( perm[k] ) );
     933            v.nihilate( fac1, fac2, gauss[k].v );
     934            fac1= nMult( fac1, gauss[k].pdenom );
     935            temp= nMult( fac2, pdenom );
     936            nDelete( &fac2 );
     937            fac2= temp;
     938              p.nihilate( fac1, fac2, gauss[k].p );
     939            temp= nMult( pdenom, gauss[k].pdenom );
     940            nDelete( &pdenom );
     941            pdenom= temp;
     942
     943            nDelete( & fac1 );
     944            nDelete( & fac2 );
     945            number gcd = v.gcd();
     946            if ( ! nIsOne( gcd ) && ! nIsZero( gcd ) ) {
     947                v /= gcd;
     948                number temp= nMult( pdenom, gcd );
     949                nDelete( &pdenom );
     950                pdenom= temp;
     951            }
     952            nDelete( & gcd );
     953            gcd= p.gcd();
     954            temp= nGcd( pdenom, gcd );
     955            nDelete( &gcd );
     956            gcd= temp;
     957            if ( ! nIsZero( gcd ) && ! nIsOne( gcd ) ) {
     958                p /= gcd;
     959                temp= nDiv( pdenom, gcd );
     960                nDelete( & pdenom );
     961                pdenom= temp;
     962                nNormalize( pdenom );
     963            }
     964            nDelete( & gcd );
     965        }
    966966    }
    967967}
     
    971971// Calculates the groebnerBasis for the ideal which is defined by l.
    972972// The dimension of l has to be finite.
    973 // The result is in reduced form. 
     973// The result is in reduced form.
    974974{
    975975    fglmDdata data( l.dimen() );
    976    
     976
    977977    // insert pOne() and update workinglist:
    978978    poly one = pOne();
     
    982982    STICKYPROT( "." );
    983983    while ( data.candidatesLeft() == TRUE ) {
    984         fglmDelem candidate = data.nextCandidate();
    985         if ( candidate.isBasisOrEdge() == TRUE ) {
    986             // Now we have the chance to find a new groebner polynomial
    987            
    988             // v is the vector-representation of candidate.monom
    989             // some elements of v are zeroed in data.gaussreduce(). Which
    990             // ones and how this was done is stored in p.
    991             // originalV containes the unchanged v, which is later inserted
    992             // into the working list (via data.updateCandidates().
    993             fglmVector v = l.multiply( candidate.v, candidate.var );
    994             fglmVector originalV = v;
    995             fglmVector p( data.getBasisSize()+1, data.getBasisSize()+1 );
    996             number pdenom = NULL;
    997             data.gaussreduce( v, p, pdenom );
    998             if ( v.isZero() ) {
    999                 // Now v is linear dependend to the already found basis elements.
    1000                 // This means that v (rsp. candidate.monom) is the leading
    1001                 // monomial of the next groebner-basis polynomial.
    1002                 data.newGroebnerPoly( p, candidate.monom );
    1003                 nDelete( & pdenom );
    1004                 STICKYPROT( "+" );
    1005             }
    1006             else {
    1007                 // no linear dependence could be found, so v ( rsp. monom )
    1008                 // is a basis monomial. We store the zeroed version ( i.e. v
    1009                 // and not originalV ) as well as p, the denomiator and all
    1010                 // the other stuff.
    1011                 // erst updateCandidates, dann newBasisELem!!!
    1012                 data.updateCandidates( candidate.monom, originalV );
    1013                 data.newBasisElem( candidate.monom, v, p, pdenom );
    1014                 STICKYPROT( "." );
    1015             }
    1016         }
    1017         else {
    1018             STICKYPROT( "-" );
    1019             candidate.cleanup();
    1020         }
     984        fglmDelem candidate = data.nextCandidate();
     985        if ( candidate.isBasisOrEdge() == TRUE ) {
     986            // Now we have the chance to find a new groebner polynomial
     987
     988            // v is the vector-representation of candidate.monom
     989            // some elements of v are zeroed in data.gaussreduce(). Which
     990            // ones and how this was done is stored in p.
     991            // originalV containes the unchanged v, which is later inserted
     992            // into the working list (via data.updateCandidates().
     993            fglmVector v = l.multiply( candidate.v, candidate.var );
     994            fglmVector originalV = v;
     995            fglmVector p( data.getBasisSize()+1, data.getBasisSize()+1 );
     996            number pdenom = NULL;
     997            data.gaussreduce( v, p, pdenom );
     998            if ( v.isZero() ) {
     999                // Now v is linear dependend to the already found basis elements.
     1000                // This means that v (rsp. candidate.monom) is the leading
     1001                // monomial of the next groebner-basis polynomial.
     1002                data.newGroebnerPoly( p, candidate.monom );
     1003                nDelete( & pdenom );
     1004                STICKYPROT( "+" );
     1005            }
     1006            else {
     1007                // no linear dependence could be found, so v ( rsp. monom )
     1008                // is a basis monomial. We store the zeroed version ( i.e. v
     1009                // and not originalV ) as well as p, the denomiator and all
     1010                // the other stuff.
     1011                // erst updateCandidates, dann newBasisELem!!!
     1012                data.updateCandidates( candidate.monom, originalV );
     1013                data.newBasisElem( candidate.monom, v, p, pdenom );
     1014                STICKYPROT( "." );
     1015            }
     1016        }
     1017        else {
     1018            STICKYPROT( "-" );
     1019            candidate.cleanup();
     1020        }
    10211021    }  //. while data.candidatesLeft()
    10221022    STICKYPROT( "\n" );
     
    10311031    fglmVector p;
    10321032    ideal destIdeal = idInit( pVariables, 1 );
    1033    
     1033
    10341034    int i;
    10351035    BOOLEAN isZero;
    10361036    for ( i= 1; i <= pVariables; i++ ) {
    1037         // main loop
    1038         STICKYPROT2( "(%i)", i );
    1039         gaussReducer gauss( l.dimen() );
    1040         isZero= FALSE;
    1041         v= fglmVector( l.dimen(), 1 );
    1042         while ( isZero == FALSE ) {
    1043             if ( (isZero= gauss.reduce( v )) == TRUE ) {
    1044                 STICKYPROT( "+" );
    1045                 p= gauss.getDependence();
    1046                 number gcd= p.gcd();
    1047                 if ( ! nIsOne( gcd ) ) {
    1048                     p /= gcd;
    1049                 }
    1050                 nDelete( & gcd );
    1051                 int k;
    1052                 poly temp = NULL;
    1053                 poly result;
    1054                 for ( k= p.size(); k > 0; k-- ) {
    1055                     number n = nCopy( p.getconstelem( k ) );
    1056                     if ( ! nIsZero( n ) ) {
    1057                         if ( temp == NULL ) {
    1058                             result= pOne();
    1059                             temp= result;
    1060                         }
    1061                         else {
    1062                             temp->next= pOne();
    1063                             pIter( temp );
    1064                         }
    1065                         pSetCoeff( temp, n );
    1066                         pSetExp( temp, i, k-1 );
    1067                         pSetm( temp );
    1068                     }
    1069                 }
    1070                 if ( ! nGreaterZero( pGetCoeff( result ) ) ) result= pNeg( result );
    1071                 (destIdeal->m)[i-1]= result;
    1072             }
    1073             else {
    1074                 STICKYPROT( "." );
    1075                 gauss.store();
    1076                 v= l.multiply( v, i );
    1077             }
    1078         }
     1037        // main loop
     1038        STICKYPROT2( "(%i)", i );
     1039        gaussReducer gauss( l.dimen() );
     1040        isZero= FALSE;
     1041        v= fglmVector( l.dimen(), 1 );
     1042        while ( isZero == FALSE ) {
     1043            if ( (isZero= gauss.reduce( v )) == TRUE ) {
     1044                STICKYPROT( "+" );
     1045                p= gauss.getDependence();
     1046                number gcd= p.gcd();
     1047                if ( ! nIsOne( gcd ) ) {
     1048                    p /= gcd;
     1049                }
     1050                nDelete( & gcd );
     1051                int k;
     1052                poly temp = NULL;
     1053                poly result;
     1054                for ( k= p.size(); k > 0; k-- ) {
     1055                    number n = nCopy( p.getconstelem( k ) );
     1056                    if ( ! nIsZero( n ) ) {
     1057                        if ( temp == NULL ) {
     1058                            result= pOne();
     1059                            temp= result;
     1060                        }
     1061                        else {
     1062                            temp->next= pOne();
     1063                            pIter( temp );
     1064                        }
     1065                        pSetCoeff( temp, n );
     1066                        pSetExp( temp, i, k-1 );
     1067                        pSetm( temp );
     1068                    }
     1069                }
     1070                if ( ! nGreaterZero( pGetCoeff( result ) ) ) result= pNeg( result );
     1071                (destIdeal->m)[i-1]= result;
     1072            }
     1073            else {
     1074                STICKYPROT( "." );
     1075                gauss.store();
     1076                v= l.multiply( v, i );
     1077            }
     1078        }
    10791079    }
    10801080    STICKYPROT( "\n" );
     
    10881088    idhdl initialRingHdl = currRingHdl;
    10891089    BOOLEAN fglmok;
    1090    
     1090
    10911091    if ( currRingHdl != sourceRingHdl )
    1092         rSetHdl( sourceRingHdl, TRUE );
     1092        rSetHdl( sourceRingHdl, TRUE );
    10931093    idealFunctionals L( 100, pVariables );
    10941094    fglmok = CalculateFunctionals( sourceIdeal, L );
    10951095    if ( deleteIdeal == TRUE )
    1096         idDelete( & sourceIdeal );
     1096        idDelete( & sourceIdeal );
    10971097    rSetHdl( destRingHdl, TRUE );
    10981098    if ( fglmok == TRUE ) {
    1099         L.map( IDRING( sourceRingHdl ) );
    1100         destIdeal= GroebnerViaFunctionals( L );
     1099        L.map( IDRING( sourceRingHdl ) );
     1100        destIdeal= GroebnerViaFunctionals( L );
    11011101    }
    11021102    if ( (switchBack == TRUE) && (currRingHdl != initialRingHdl) )
    1103         rSetHdl( initialRingHdl, TRUE );
     1103        rSetHdl( initialRingHdl, TRUE );
    11041104    return fglmok;
    11051105}
    11061106
    11071107BOOLEAN
    1108 FindUnivariateWrapper( ideal source, ideal & destIdeal ) 
     1108FindUnivariateWrapper( ideal source, ideal & destIdeal )
    11091109{
    11101110    BOOLEAN fglmok;
    1111    
     1111
    11121112    idealFunctionals L( 100, pVariables );
    11131113    fglmok = CalculateFunctionals( source, L );
    11141114    if ( fglmok == TRUE ) {
    1115         destIdeal= FindUnivariatePolys( L );
    1116         return TRUE;
    1117     }
    1118     else 
    1119         return FALSE;
     1115        destIdeal= FindUnivariatePolys( L );
     1116        return TRUE;
     1117    }
     1118    else
     1119        return FALSE;
    11201120}
    11211121
  • Singular/getopt.h

    r073d2e r5812c69  
    1919#define _GETOPT_H 1
    2020
    21 #ifdef  __cplusplus
     21#ifdef        __cplusplus
    2222extern "C" {
    2323#endif
     
    6060
    6161   The field `has_arg' is:
    62    no_argument          (or 0) if the option does not take an argument,
    63    required_argument    (or 1) if the option requires an argument,
    64    optional_argument    (or 2) if the option takes an optional argument.
     62   no_argument                (or 0) if the option does not take an argument,
     63   required_argument        (or 1) if the option requires an argument,
     64   optional_argument         (or 2) if the option takes an optional argument.
    6565
    6666   If the field `flag' is not NULL, it points to a variable that is set
     
    7777struct option
    7878{
    79 #if     __STDC__
     79#if        __STDC__
    8080  const char *name;
    8181#else
     
    9191/* Names for the values of the `has_arg' field of `struct option'.  */
    9292
    93 #define no_argument             0
    94 #define required_argument       1
    95 #define optional_argument       2
     93#define        no_argument                0
     94#define required_argument        1
     95#define optional_argument        2
    9696
    9797#if __STDC__ || defined(PROTO) || defined(__MWERKS__)
     
    103103#endif /* not __GNU_LIBRARY__ */
    104104extern int getopt_long (int argc, char *const *argv, const char *shortopts,
    105                         const struct option *longopts, int *longind);
     105                        const struct option *longopts, int *longind);
    106106extern int getopt_long_only (int argc, char *const *argv,
    107                              const char *shortopts,
    108                              const struct option *longopts, int *longind);
     107                             const char *shortopts,
     108                             const struct option *longopts, int *longind);
    109109
    110110/* Internal only.  Users should not call this directly.  */
    111111extern int _getopt_internal (int argc, char *const *argv,
    112                              const char *shortopts,
    113                              const struct option *longopts, int *longind,
    114                              int long_only);
     112                             const char *shortopts,
     113                             const struct option *longopts, int *longind,
     114                             int long_only);
    115115#else /* not __STDC__ */
    116116extern int getopt ();
     
    121121#endif /* not __STDC__ */
    122122
    123 #ifdef  __cplusplus
     123#ifdef        __cplusplus
    124124}
    125125#endif
  • Singular/hdegree.cc

    r073d2e r5812c69  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: hdegree.cc,v 1.12 1998-04-08 10:01:58 pohl Exp $ */
     4/* $Id: hdegree.cc,v 1.13 1998-09-24 09:59:42 Singular Exp $ */
    55/*
    66*  ABSTRACT -  dimension, multiplicity, HC, kbase
     
    11581158      if (stc[i] && (stc[i][Nvar] >= y))
    11591159      {
    1160         Istc--;
    1161         stc[i] = NULL;
     1160        Istc--;
     1161        stc[i] = NULL;
    11621162      }
    11631163    }
     
    12671267      {
    12681268        Istc--;
    1269         sn[i] = NULL;
     1269        sn[i] = NULL;
    12701270      }
    12711271    }
     
    12821282      if (sn[i])
    12831283      {
    1284         sn[j] = sn[i];
    1285         j++;
     1284        sn[j] = sn[i];
     1285        j++;
    12861286      }
    12871287    }
     
    13281328      {
    13291329        Istc--;
    1330         sn[i] = NULL;
     1330        sn[i] = NULL;
    13311331      }
    13321332    }
     
    13381338      if (sn[i])
    13391339      {
    1340         sn[j] = sn[i];
    1341         j++;
     1340        sn[j] = sn[i];
     1341        j++;
    13421342      }
    13431343    }
  • Singular/hutil.cc

    r073d2e r5812c69  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: hutil.cc,v 1.7 1998-04-27 10:19:04 pohl Exp $ */
     4/* $Id: hutil.cc,v 1.8 1998-09-24 09:59:43 Singular Exp $ */
    55/*
    66* ABSTRACT: Utilities for staircase operations
     
    117117}
    118118
    119  
     119
    120120void hComp(scfmon exist, int Nexist, Exponent_t ak, scfmon stc, int *Nstc)
    121121{
     
    224224         g -= o;
    225225       else
    226         g = o - g;
     226        g = o - g;
    227227       if (g > h)
    228228         h = g;
  • Singular/intvec.cc

    r073d2e r5812c69  
    22*  Computer Algebra System SINGULAR      *
    33*****************************************/
    4 /* $Id: intvec.cc,v 1.9 1998-05-24 09:51:50 obachman Exp $ */
     4/* $Id: intvec.cc,v 1.10 1998-09-24 09:59:43 Singular Exp $ */
    55/*
    66* ABSTRACT: class intvec: lists/vectors of integers
     
    110110        }
    111111      }
    112       if (j+1<row) 
     112      if (j+1<row)
    113113      {
    114114        StringAppend("\n");
    115115        if (spaces>0) StringAppend("%-*.*s",spaces,spaces," ");
    116       } 
     116      }
    117117    }
    118118  }
     
    158158  if (intop == 0) return;
    159159  if (intop<0) intop*=(-1);
    160   for (int i=0; i<row*col; i++) 
     160  for (int i=0; i<row*col; i++)
    161161  { v[i] %= intop; if (v[i]<0) v[i] += intop; }
    162162}
     
    164164int intvec::compare(intvec* op)
    165165{
    166   if ((col!=1) ||(op->cols()!=1)) 
     166  if ((col!=1) ||(op->cols()!=1))
    167167  {
    168168    if((col!=op->cols())
    169169    || (row!=op->rows()))
    170170      return -2;
    171   }   
     171  }
    172172  int i;
    173173  for (i=0; i<min(length(),op->length()); i++)
  • Singular/ipconv.cc

    r073d2e r5812c69  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: ipconv.cc,v 1.10 1998-05-28 16:50:49 Singular Exp $ */
     4/* $Id: ipconv.cc,v 1.11 1998-09-24 09:59:44 Singular Exp $ */
    55/*
    66* ABSTRACT: automatic type conversions
     
    171171static void * iiR2L(void * data)
    172172{
    173   return (void *)syConvRes((syStrategy)data); 
     173  return (void *)syConvRes((syStrategy)data);
    174174}
    175175
    176176static void * iiL2R(void * data)
    177177{
    178   return (void *)syConvList((lists)data); 
     178  return (void *)syConvList((lists)data);
    179179}
    180180#else
     
    237237//  link
    238238   { STRING_CMD,      LINK_CMD,       iiS2Link },
    239 // resolution -> list   
     239// resolution -> list
    240240   { RESOLUTION_CMD,  LIST_CMD,       iiR2L },
    241241// list -> resolution
  • Singular/ipid.cc

    r073d2e r5812c69  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: ipid.cc,v 1.16 1998-09-09 13:10:26 Singular Exp $ */
     4/* $Id: ipid.cc,v 1.17 1998-09-24 09:59:44 Singular Exp $ */
    55
    66/*
     
    126126      case PROC_CMD:
    127127        len=sizeof(procinfo);
    128         break;
     128        break;
    129129    //other types: without init (int,script,poly,def,package)
    130130    }
     
    421421  else Print("=======>%s(%x)<====\n", IDID(h), IDID(h));
    422422#endif
    423  
     423
    424424  FreeL((ADDRESS)IDID(h));
    425425  //IDID(h)=NULL;
     
    722722#if 0
    723723  if(init && ns->isroot) {
    724     idhdl pl = enterid( mstrdup("Top"),0, PACKAGE_CMD, 
     724    idhdl pl = enterid( mstrdup("Top"),0, PACKAGE_CMD,
    725725                      &NSROOT(namespaceroot), TRUE );
    726726    if(pl != NULL) {
  • Singular/ipid.h

    r073d2e r5812c69  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: ipid.h,v 1.15 1998-08-25 13:33:18 krueger Exp $ */
     6/* $Id: ipid.h,v 1.16 1998-09-24 09:59:45 Singular Exp $ */
    77/*
    88* ABSTRACT: identfier handling
     
    150150#define NSROOT(a) ((a)->pack->idroot)
    151151#define NSPACK(a) ((a)->pack)
    152  
     152
    153153
    154154 namerec()  { memset(this,0,sizeof(*this)); }
  • Singular/khstd.cc

    r073d2e r5812c69  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: khstd.cc,v 1.6 1998-05-14 13:04:15 Singular Exp $ */
     4/* $Id: khstd.cc,v 1.7 1998-09-24 09:59:46 Singular Exp $ */
    55/*
    66* ABSTRACT:utils for hilbert driven kStd
     
    7575              PrintS("h");
    7676              mflush();
    77             } 
     77            }
    7878            deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
    7979          }
     
    9393        PrintS("h");
    9494        mflush();
    95       } 
     95      }
    9696      deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
    9797    }
  • Singular/lists.cc

    r073d2e r5812c69  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: lists.cc,v 1.10 1998-06-18 08:17:41 Singular Exp $ */
     4/* $Id: lists.cc,v 1.11 1998-09-24 09:59:46 Singular Exp $ */
    55/*
    66* ABSTRACT: handling of the list type
     
    217217        {
    218218          L->m[i].rtyp=typ0;
    219           int j=IDELEMS(r[0])-1;
    220           while ((j>0) && (r[0]->m[j]==NULL)) j--;
    221           j++;
    222           if (j!=IDELEMS(r[0]))
    223           {
    224             pEnlargeSet(&(r[0]->m),IDELEMS(r[0]),j-IDELEMS(r[0]));
    225             IDELEMS(r[0])=j;
    226           }
     219          int j=IDELEMS(r[0])-1;
     220          while ((j>0) && (r[0]->m[j]==NULL)) j--;
     221          j++;
     222          if (j!=IDELEMS(r[0]))
     223          {
     224            pEnlargeSet(&(r[0]->m),IDELEMS(r[0]),j-IDELEMS(r[0]));
     225            IDELEMS(r[0])=j;
     226          }
    227227        }
    228228        else
  • Singular/longalg.cc

    r073d2e r5812c69  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: longalg.cc,v 1.24 1998-04-23 09:52:14 Singular Exp $ */
     4/* $Id: longalg.cc,v 1.25 1998-09-24 09:59:47 Singular Exp $ */
    55/*
    66* ABSTRACT:   algebraic numbers
     
    10171017  if (!naIsChar0) x = napInit(1);
    10181018  else            x = napGcd0(g,h);
    1019   //int huhu=0;
    10201019  for (i=(naNumbOfPar-1); i>=0; i--)
    10211020  {
    10221021    x->e[i] = napExpi(i,a,b);
    1023     //huhu+=x->e[i];
    1024   }
    1025   //if (huhu!=0)
    1026   //{
    1027   //  Print("{%d}",huhu);
    1028   //}
     1022  }
    10291023  return x;
    10301024}
  • Singular/maps.cc

    r073d2e r5812c69  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: maps.cc,v 1.10 1998-05-14 13:04:20 Singular Exp $ */
     4/* $Id: maps.cc,v 1.11 1998-09-24 09:59:49 Singular Exp $ */
    55/*
    66* ABSTRACT - the mapping of polynomials to other rings
     
    4242  int i,modulComp;
    4343  int varnum = preimage_r->N;
    44  
     44
    4545//  for(i=1; i<=varnum; i++)
    4646//  {
  • Singular/mmalloc.c

    r073d2e r5812c69  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mmalloc.c,v 1.5 1998-01-24 17:22:06 Singular Exp $ */
     4/* $Id: mmalloc.c,v 1.6 1998-09-24 09:59:49 Singular Exp $ */
    55
    66/*
     
    9292void _memcpyW(void* p1, void* p2, long l)
    9393{
    94   long _i = l;                                 
    95   long* _s1 = (long*) p1;                       
    96   const long* _s2 = (long*) p2;                 
    97                                                
    98   for (;;)                                     
    99   {                                             
    100     *_s1 = *_s2;                               
    101     _i--;                                       
    102     if (_i == 0) break;                         
    103     _s1++;                                     
    104     _s2++;                                     
    105   }                                             
    106 }                                               
    107 #endif 
     94  long _i = l;
     95  long* _s1 = (long*) p1;
     96  const long* _s2 = (long*) p2;
    10897
     98  for (;;)
     99  {
     100    *_s1 = *_s2;
     101    _i--;
     102    if (_i == 0) break;
     103    _s1++;
     104    _s2++;
     105  }
     106}
     107#endif
     108
Note: See TracChangeset for help on using the changeset viewer.