Changeset e858e7 in git


Ignore:
Timestamp:
Jun 28, 1999, 6:06:34 PM (25 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
6035d5fe0c5ee43d9a8eb9a890ecdfb7fd03236f
Parents:
0f5091ea1879ab5dca9d221f9cfc0b248090d973
Message:
* hannes: fixed factorize(0), introduced bug_12.*
     usage of WerrorS instead Werror (where possible)
     change source according to Singular style


git-svn-id: file:///usr/local/Singular/svn/trunk@3180 2c84dea3-7e68-4137-9b89-c4e89433aadc
Files:
3 added
15 edited

Legend:

Unmodified
Added
Removed
  • Singular/clapsing.cc

    r0f5091 re858e7  
    33*  Computer Algebra System SINGULAR     *
    44****************************************/
    5 // $Id: clapsing.cc,v 1.52 1999-06-15 08:32:31 Singular Exp $
     5// $Id: clapsing.cc,v 1.53 1999-06-28 16:06:22 Singular Exp $
    66/*
    77* ABSTRACT: interface between Singular and factory
     
    639639    {
    640640      (*v)=new intvec(1);
    641       (*v)[1]=1;
     641      (**v)[0]=1;
    642642    }
    643643    return res;
     
    11381138  ideal f=singclap_factorize((poly)(u->Data()), &v, 0);
    11391139  if (f==NULL) return TRUE;
     1140  #ifdef MDEBUG
     1141  v->ivTEST();
     1142  #endif
    11401143  lists l=(lists)Alloc(sizeof(slists));
    11411144  l->Init(2);
  • Singular/intvec.cc

    r0f5091 re858e7  
    22*  Computer Algebra System SINGULAR      *
    33*****************************************/
    4 /* $Id: intvec.cc,v 1.12 1999-04-17 12:30:17 Singular Exp $ */
     4/* $Id: intvec.cc,v 1.13 1999-06-28 16:06:23 Singular Exp $ */
    55/*
    66* ABSTRACT: class intvec: lists/vectors of integers
     
    8282  if ((col == 1)&&(mat!=INTMAT_CMD))
    8383  {
    84     int i;
    85     for (i=0; i<row-1; i++)
     84    int i=0;
     85    for (; i<row-1; i++)
    8686    {
    8787      StringAppend("%d,",v[i]);
  • Singular/intvec.h

    r0f5091 re858e7  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: intvec.h,v 1.7 1999-04-16 07:53:34 obachman Exp $ */
     6/* $Id: intvec.h,v 1.8 1999-06-28 16:06:23 Singular Exp $ */
    77/*
    88* ABSTRACT: class intvec: lists/vectors of integers
     
    3232    int range(int i, int j)
    3333       { return ((i<row) && (i>=0) && (j<col) && (j>=0)); }
    34     int& operator[](int i) {
     34    int& operator[](int i)
     35    {
     36       #ifndef NDEBUG
    3537       if((i<0)||(i>=row*col))
    3638       {
    3739          Werror("wrong intvec index:%d\n",i);
    3840       }
    39        return v[i];}
     41       #endif
     42       return v[i];
     43    }
    4044#define IMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
    4145    void operator+=(int intop);
     
    6872         }
    6973       }
     74    void ivTEST()
     75       {
     76#ifdef MDEBUG
     77         mmTestL(this);
     78         mmTest((ADDRESS)v,sizeof(int)*row*col);
     79#endif
     80       }
    7081};
    7182intvec * ivCopy(intvec * o);
  • Singular/mpr_base.cc

    r0f5091 re858e7  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mpr_base.cc,v 1.1 1999-06-28 12:48:11 wenk Exp $ */
    5 
    6 /* 
     4/* $Id: mpr_base.cc,v 1.2 1999-06-28 16:06:24 Singular Exp $ */
     5
     6/*
    77 * ABSTRACT - multipolynomial resultants - resultant matrices
    88 *            ( sparse, dense, u-resultant solver )
     
    5353#define MINVDIST       0.0
    5454#define RVMULT         0.00005 // 0.000000005
    55 #define MAXVARS        100           
     55#define MAXVARS        100
    5656//<-
    5757
     
    6262
    6363/* Linear Program stuff */
    64 struct linProg {          // Linear Program stuff
    65   mprfloat **LiPM;           
    66   int *izrov, *iposv;       
    67   int LiPM_cols,LiPM_rows;
     64struct linProg
     65{
     66  mprfloat **LiPM;
     67  int *izrov, *iposv;
     68  int LiPM_cols,LiPM_rows;
    6869};
    6970
     
    8990
    9091  const poly getUDet( const number* evpoint );
    91  
     92
    9293private:
    9394  resMatrixSparse( const resMatrixSparse & );
     
    102103
    103104  /* Remaps a result of LP to the according point set Qi.
    104    * Returns false iff remaping was not possible, otherwise true. 
     105   * Returns false iff remaping was not possible, otherwise true.
    105106   */
    106107  bool remapXiToPoint( const int indx, pointSet **pQ, int *set, int *vtx );
     
    120121private:
    121122  ideal gls;
    122  
     123
    123124  int n, idelem;     // number of variables, polynoms
    124125  int numSet0;       // number of elements in S0
    125126  int msize;         // size of matrix
    126  
     127
    127128  intvec *uRPos;
    128129
    129130  ideal rmat;        // sparse matrix representation
    130  
     131
    131132  linProg LP;
    132133};
     
    138139typedef unsigned int Coord_t;
    139140
    140 struct setID {
     141struct setID
     142{
    141143  int set;
    142144  int pnt;
    143145};
    144146
    145 struct onePoint {
     147struct onePoint
     148{
    146149  Coord_t * point;             // point[0] is unused, maxial dimension is MAXVARS+1
    147150  setID rc;                    // filled in by Row Content Function
     
    151154typedef struct onePoint * onePointP;
    152155
    153 /* sparse matrix entry */
    154 struct _entry {
     156/* sparse matrix entry */
     157struct _entry
     158{
    155159  number num;
    156160  int col;
     
    162166
    163167//-> class pointSet
    164 class pointSet {
     168class pointSet
     169{
    165170private:
    166171  onePointP *points;     // set of onePoint's, index [1..num], supports of monoms
     
    218223  /* Returns index of supp(LT(p)) in pointSet. */
    219224  int getExpPos( const poly p );
    220  
     225
    221226  /** sort lex
    222227   */
     
    252257//-> class convexHull
    253258/* Compute convex hull of given exponent set */
    254 class convexHull {
     259class convexHull
     260{
    255261public:
    256262  convexHull( linProgP _pLP ) : pLP(_pLP) {}
     
    264270
    265271private:
    266   /** Returns true iff the support of poly pointPoly is inside the 
     272  /** Returns true iff the support of poly pointPoly is inside the
    267273   * convex hull of all points given by the  support of poly p.
    268274   */
     
    278284//-> class mayanPyramidAlg
    279285/* Compute all lattice points in a given convex hull */
    280 class mayanPyramidAlg {
     286class mayanPyramidAlg
     287{
    281288public:
    282289  mayanPyramidAlg( linProgP _pLP ) : n(pVariables), pLP(_pLP) {}
     
    290297private:
    291298
    292   /** Recursive Mayan Pyramid algorithm for directly computing MinkowskiSum 
    293    * lattice points for (n+1)-fold MinkowskiSum of given point sets Qi[].               
     299  /** Recursive Mayan Pyramid algorithm for directly computing MinkowskiSum
     300   * lattice points for (n+1)-fold MinkowskiSum of given point sets Qi[].
    294301   * Recursively for range of dim: dim in [0..n); acoords[0..var) fixed.
    295302   * Stores only MinkowskiSum points of udist > 0: done by storeMinkowskiSumPoints.
     
    299306  /**  Compute v-distance via Linear Programing
    300307   * Linear Program finds the v-distance of the point in accords[].
    301    * The v-distance is the distance along the direction v to boundary of 
     308   * The v-distance is the distance along the direction v to boundary of
    302309   * Minkowski Sum of Qi (here vector v is represented by shift[]).
    303310   * Returns the v-distance or -1.0 if an error occured.
     
    307314  /** LP for finding min/max coord in MinkowskiSum, given previous coors.
    308315   * Assume MinkowskiSum in non-negative quadrants
    309    * coor in [0,n); fixed coords in acoords[0..coor)                   
     316   * coor in [0,n); fixed coords in acoords[0..coor)
    310317   */
    311318  void mn_mx_MinkowskiSum( int dim, Coord_t *minR, Coord_t *maxR );
     
    315322   */
    316323  bool storeMinkowskiSumPoint();
    317  
     324
    318325private:
    319326  pointSet **Qi;
     
    335342  int i, j;
    336343
    337   for (i = 1; i <= maxrow; i++) {
     344  for (i = 1; i <= maxrow; i++)
     345  {
    338346    Print("[");
    339347    for (j = 1; j <= maxcol; j++) Print("% 7.2f, ", a[i][j]);
     
    346354
    347355  printf("Output matrix from LinProg");
    348   for (i = 1; i <= nrows; i++) {
     356  for (i = 1; i <= nrows; i++)
     357  {
    349358    printf("\n[ ");
    350359    if (i == 1) printf("  ");
     
    360369{
    361370  int i;
    362   for ( i= 1; i <= n; i++ ) {
     371  for ( i= 1; i <= n; i++ )
     372  {
    363373    Print(" %d",vert->point[i] );
    364374#ifdef LONG_OUTPUT
     
    372382  int val;
    373383  Print(" matrix m[%d][%d]=(\n",MATROWS( omat ),MATCOLS( omat ));
    374   for ( i= 1; i <= MATROWS( omat ); i++ ) {
    375     for ( j= 1; j <= MATCOLS( omat ); j++ ) {
    376       if ( MATELEM( omat, i, j) && pGetCoeff( MATELEM( omat, i, j) ) ) {
    377         val= nInt(pGetCoeff( MATELEM( omat, i, j) ));
    378         if ( i==MATROWS(omat) && j==MATCOLS(omat) ) {
    379           if ( !val ) Print(" 0 ");
    380           else Print("%d ",val);
    381         } else {
    382           if ( !val ) Print(" 0, ");
    383           else Print("%d, ",val);
    384         }
    385       } else {
    386         if ( i==MATROWS(omat) && j==MATCOLS(omat) ) {
    387           Print("  0");
    388         } else {
    389           Print("  0, ");
    390         }
     384  for ( i= 1; i <= MATROWS( omat ); i++ )
     385  {
     386    for ( j= 1; j <= MATCOLS( omat ); j++ )
     387    {
     388      if ( MATELEM( omat, i, j) && pGetCoeff( MATELEM( omat, i, j) ) )
     389      {
     390        val= nInt(pGetCoeff( MATELEM( omat, i, j) ));
     391        if ( i==MATROWS(omat) && j==MATCOLS(omat) )
     392        {
     393          if ( !val ) Print(" 0 ");
     394          else Print("%d ",val);
     395        }
     396        else
     397        {
     398          if ( !val ) Print(" 0, ");
     399          else Print("%d, ",val);
     400        }
     401      }
     402      else
     403      {
     404        if ( i==MATROWS(omat) && j==MATCOLS(omat) )
     405        {
     406          Print("  0");
     407        }
     408        else
     409        {
     410          Print("  0, ");
     411        }
    391412      }
    392413    }
     
    394415  }
    395416  Print(");\n");
    396 }   
     417}
    397418#endif
    398419//<-
     
    404425  int i;
    405426  points = (onePointP *)Alloc( (count+1) * sizeof(onePointP) );
    406   for ( i= 0; i <= max; i++ ) {
     427  for ( i= 0; i <= max; i++ )
     428  {
    407429    points[i]= (onePointP)Alloc( sizeof(onePoint) );
    408430    points[i]->point= (Coord_t *)Alloc0( (dim+2) * sizeof(Coord_t) );
     
    415437  int i;
    416438  int fdim= lifted ? dim+1 : dim+2;
    417   for ( i= 0; i <= max; i++ ) {
     439  for ( i= 0; i <= max; i++ )
     440  {
    418441    Free( (ADDRESS) points[i]->point, fdim * sizeof(Coord_t) );
    419442    Free( (ADDRESS) points[i], sizeof(onePoint) );
     
    430453inline bool pointSet::checkMem()
    431454{
    432   if ( num >= max ) {
     455  if ( num >= max )
     456  {
    433457    int i;
    434458    int fdim= lifted ? dim+1 : dim+2;
    435     points= (onePointP*)ReAlloc( points,
    436                                  (max+1) * sizeof(onePointP),
    437                                  (2*max + 1) * sizeof(onePointP) );
    438     for ( i= max+1; i <= max*2; i++ ) {
     459    points= (onePointP*)ReAlloc( points,
     460                                 (max+1) * sizeof(onePointP),
     461                                 (2*max + 1) * sizeof(onePointP) );
     462    for ( i= max+1; i <= max*2; i++ )
     463    {
    439464      points[i]= (onePointP)Alloc( sizeof(struct onePoint) );
    440465      points[i]->point= (Coord_t *)Alloc0( fdim * sizeof(Coord_t) );
     
    483508{
    484509  assume( indx > 0 && indx <= num );
    485   if ( indx != num ) {
     510  if ( indx != num )
     511  {
    486512    onePointP tmp;
    487513    tmp= points[indx];
     
    498524  int i,j;
    499525
    500   for ( i= 1; i <= num; i++ ) {
     526  for ( i= 1; i <= num; i++ )
     527  {
    501528    for ( j= 1; j <= dim; j++ )
    502529      if ( points[i]->point[j] != vert->point[j] ) break;
    503530    if ( j > dim ) break;
    504531  }
    505  
    506   if ( i > num ) {
     532
     533  if ( i > num )
     534  {
    507535    addPoint( vert );
    508536    return true;
     
    515543  int i,j;
    516544
    517   for ( i= 1; i <= num; i++ ) {
     545  for ( i= 1; i <= num; i++ )
     546  {
    518547    for ( j= 1; j <= dim; j++ )
    519548      if ( points[i]->point[j] != (Coord_t) vert[j] ) break;
    520549    if ( j > dim ) break;
    521550  }
    522  
    523   if ( i > num ) {
     551
     552  if ( i > num )
     553  {
    524554    addPoint( vert );
    525555    return true;
     
    535565  vert= (Exponent_t *)Alloc( (dim+1) * sizeof(Exponent_t) );
    536566
    537   while ( piter ) {
     567  while ( piter )
     568  {
    538569    pGetExpV( piter, vert );
    539570
    540     for ( i= 1; i <= num; i++ ) {
     571    for ( i= 1; i <= num; i++ )
     572    {
    541573      for ( j= 1; j <= dim; j++ )
    542         if ( points[i]->point[j] != (Coord_t) vert[j] ) break;
     574        if ( points[i]->point[j] != (Coord_t) vert[j] ) break;
    543575      if ( j > dim ) break;
    544576    }
    545577
    546     if ( i > num ) {
     578    if ( i > num )
     579    {
    547580      addPoint( vert );
    548581    }
     
    562595
    563596  pGetExpV( p, vert );
    564   for ( i= 1; i <= num; i++ ) {
     597  for ( i= 1; i <= num; i++ )
     598  {
    565599    for ( j= 1; j <= dim; j++ )
    566600      if ( points[i]->point[j] != (Coord_t) vert[j] ) break;
     
    586620{
    587621  int i;
    588  
    589   for ( i= 1; i <= dim; i++ ) {
    590     if ( points[a]->point[i] > points[b]->point[i] ) {
     622
     623  for ( i= 1; i <= dim; i++ )
     624  {
     625    if ( points[a]->point[i] > points[b]->point[i] )
     626    {
    591627      return false;
    592628    }
    593     if ( points[a]->point[i] < points[b]->point[i] ) {
     629    if ( points[a]->point[i] < points[b]->point[i] )
     630    {
    594631      return true;
    595632    }
     
    602639{
    603640  int i;
    604  
    605   for ( i= 1; i <= dim; i++ ) {
    606     if ( points[a]->point[i] < points[b]->point[i] ) {
     641
     642  for ( i= 1; i <= dim; i++ )
     643  {
     644    if ( points[a]->point[i] < points[b]->point[i] )
     645    {
    607646      return false;
    608647    }
    609     if ( points[a]->point[i] > points[b]->point[i] ) {
     648    if ( points[a]->point[i] > points[b]->point[i] )
     649    {
    610650      return true;
    611651    }
     
    621661  onePointP tmp;
    622662
    623   while ( found ) {
     663  while ( found )
     664  {
    624665    found= false;
    625     for ( i= 1; i < num; i++ ) {
    626       if ( larger( i, i+1 ) ) {
    627         tmp= points[i];
    628         points[i]= points[i+1];
    629         points[i+1]= tmp;
    630        
    631         found= true;
     666    for ( i= 1; i < num; i++ )
     667    {
     668      if ( larger( i, i+1 ) )
     669      {
     670        tmp= points[i];
     671        points[i]= points[i+1];
     672        points[i+1]= tmp;
     673
     674        found= true;
    632675      }
    633676    }
     
    642685
    643686  time_t *tp = NULL;
    644   seed = ((int)time(tp) % MAXSEED) + index; // secs since 1/1/70 ->[1,MAXSEED] 
     687  seed = ((int)time(tp) % MAXSEED) + index; // secs since 1/1/70 ->[1,MAXSEED]
    645688  //seed= 100+index;
    646  
     689
    647690  dim++;
    648691
    649   if ( !l ) {
     692  if ( l==NULL )
     693  {
    650694    outerL= false;
    651695    l= (int *)Alloc( (dim+1) * sizeof(int) ); // [1..dim-1]
    652    
     696
    653697    srand48( (long)(seed*(index+MAXSEED*18)) );  // index+MAXSEED*MAXVARS
    654     for(i = 1; i < dim; i++) {
     698    for(i = 1; i < dim; i++)
     699    {
    655700      l[i]= 1 + ((unsigned int) mrand48()) % LIFT_COOR;
    656701    }
    657702  }
    658   for ( j=1; j <= num; j++ ) {
     703  for ( j=1; j <= num; j++ )
     704  {
    659705    sum= 0;
    660     for ( i=1; i < dim; i++ ) {
     706    for ( i=1; i < dim; i++ )
     707    {
    661708      sum += (int)points[j]->point[i] * l[i];
    662709    }
    663710    points[j]->point[dim]= sum;
    664711  }
    665  
     712
    666713#ifdef mprDEBUG_ALL
    667714  Print(" lift vector: ");
     
    670717#ifdef mprDEBUG_ALL
    671718  Print(" lifted points: \n");
    672   for ( j=1; j <= num; j++ ) {
     719  for ( j=1; j <= num; j++ )
     720  {
    673721    Print("%d: <",j);print_exp(points[j],dim);Print(">\n");
    674722  }
     
    698746{
    699747  int i, j, col, icase;
    700   int numcons;          // num of constraints
    701   int numpts;           // num of pts in defining support
    702   int numcols;          // tot number of cols
    703  
    704   numcons = n+1;       
    705   numpts = m-1;
    706   numcols = numpts+1;           // this includes col of cts
    707 
    708   pLP->LiPM[1][1] = +0.0;  pLP->LiPM[1][2] = +1.0;      // optimize (arbitrary) var
    709   pLP->LiPM[2][1] = +1.0;  pLP->LiPM[2][2] = -1.0;      // lambda vars sum up to 1
    710   for ( j=3; j<=numcols; j++) {
     748  int numcons;                // num of constraints
     749  int numpts;                // num of pts in defining support
     750  int numcols;                // tot number of cols
     751
     752  numcons = n+1;
     753  numpts = m-1;
     754  numcols = numpts+1;                // this includes col of cts
     755
     756  pLP->LiPM[1][1] = +0.0;  pLP->LiPM[1][2] = +1.0;        // optimize (arbitrary) var
     757  pLP->LiPM[2][1] = +1.0;  pLP->LiPM[2][2] = -1.0;         // lambda vars sum up to 1
     758  for ( j=3; j<=numcols; j++)
     759  {
    711760    pLP->LiPM[1][j] = +0.0; pLP->LiPM[2][j] = -1.0;
    712761  }
    713762
    714   for( i= 1; i <= n; i++) {     // each row constraints one coor
     763  for( i= 1; i <= n; i++) {        // each row constraints one coor
    715764    pLP->LiPM[i+2][1] = (mprfloat)pGetExp(pointPoly,i);
    716765    col = 2;
    717     for( j= 1; j <= m; j++ ) {
    718       if( j != site ) {
     766    for( j= 1; j <= m; j++ )
     767    {
     768      if( j != site )
     769      {
    719770        pLP->LiPM[i+2][col] = -(mprfloat)pGetExp( monomAt(p,j), i );
    720771        col++;
     
    728779#endif
    729780#if 1
    730   if ( numcons + 1 > pLP->LiPM_rows ) Werror("convexHull::inHull: #rows > #pLP->LiPM_rows!");
    731   if ( numcols + 1 > pLP->LiPM_cols ) Werror("convexHull::inHull: #cols > #pLP->LiPM_cols!");
     781  if ( numcons + 1 > pLP->LiPM_rows )
     782    WerrorS("convexHull::inHull: #rows > #pLP->LiPM_rows!");
     783  if ( numcols + 1 > pLP->LiPM_cols )
     784    WerrorS("convexHull::inHull: #cols > #pLP->LiPM_cols!");
    732785#endif
    733786
    734787  simplx( pLP->LiPM, numcons, numcols-1, 0, 0, numcons, &icase, pLP->izrov, pLP->iposv);
    735788
    736   return (icase == 0); 
     789  return (icase == 0);
    737790}
    738791
     
    747800  Exponent_t * vert;
    748801
    749   n= pVariables;       
     802  n= pVariables;
    750803  vert= (Exponent_t *)Alloc( (idelem+1) * sizeof(Exponent_t) );
    751804
    752   Q = (pointSet **)Alloc( idelem * sizeof(pointSet*) ); // support hulls
     805  Q = (pointSet **)Alloc( idelem * sizeof(pointSet*) );        // support hulls
    753806  for ( i= 0; i < idelem; i++ )
    754807    Q[i] = new pointSet( pVariables, i+1, pLength((gls->m)[i])+1 );
    755808
    756   for( i= 0; i < idelem; i++ ) {
     809  for( i= 0; i < idelem; i++ )
     810  {
    757811    k=1;
    758812    m = pLength( (gls->m)[i] );
    759813
    760814    poly p= (gls->m)[i];
    761     for( j= 1; j <= m; j++) {  // für jeden Exponentvektor
    762       if( !inHull( (gls->m)[i], p, m, j ) ) {
    763         pGetExpV( p, vert );
     815    for( j= 1; j <= m; j++) {  // für jeden Exponentvektor
     816      if( !inHull( (gls->m)[i], p, m, j ) )
     817      {
     818        pGetExpV( p, vert );
    764819        Q[i]->addPoint( vert );
    765         k++;
    766         mprSTICKYPROT(ST_SPARSE_VADD);
    767       } else {
    768         mprSTICKYPROT(ST_SPARSE_VREJ);
     820        k++;
     821        mprSTICKYPROT(ST_SPARSE_VADD);
     822      }
     823      else
     824      {
     825        mprSTICKYPROT(ST_SPARSE_VREJ);
    769826      }
    770827      pIter( p );
     
    777834#ifdef mprDEBUG_PROT
    778835  PrintLn();
    779   for( i= 0; i < idelem; i++ ) {
     836  for( i= 0; i < idelem; i++ )
     837  {
    780838    Print(" \\Conv(Qi[%d]): #%d\n", i,Q[i]->num );
    781     for ( j=1; j <= Q[i]->num; j++ ) {
     839    for ( j=1; j <= Q[i]->num; j++ )
     840    {
    782841      Print("%d: <",j);print_exp( (*Q[i])[j] , pVariables );Print(">\n");
    783842    }
     
    815874
    816875  numverts = 0;
    817   for( i=0; i<=n; i++) {
     876  for( i=0; i<=n; i++)
     877  {
    818878    numverts += Qi[i]->num;
    819879  }
    820   cols = numverts + 2; 
    821 
    822   //if( dim < 1 || dim > n ) Werror("mayanPyramidAlg::vDistance: Known coords dim off range");
    823 
    824   pLP->LiPM[1][1] = 0.0;
    825   pLP->LiPM[1][2] = 1.0;        // maximize     
     880  cols = numverts + 2;
     881
     882  //if( dim < 1 || dim > n )
     883  //  WerrorS("mayanPyramidAlg::vDistance: Known coords dim off range");
     884
     885  pLP->LiPM[1][1] = 0.0;
     886  pLP->LiPM[1][2] = 1.0;        // maximize
    826887  for( j=3; j<=cols; j++) pLP->LiPM[1][j] = 0.0;
    827888
    828   for( i=0; i <= n; i++ ) {                     
     889  for( i=0; i <= n; i++ ) {
    829890    pLP->LiPM[i+2][1] = 1.0;
    830891    pLP->LiPM[i+2][2] = 0.0;
    831892  }
    832   for( i=1; i<=dim; i++) {             
     893  for( i=1; i<=dim; i++) {
    833894    pLP->LiPM[n+2+i][1] = (mprfloat)(acoords[i-1]);
    834895    pLP->LiPM[n+2+i][2] = -shift[i];
     
    837898  ii = -1;
    838899  col = 2;
    839   for ( i= 0; i <= n; i++ ) {                   
     900  for ( i= 0; i <= n; i++ ) {
    840901    ii++;
    841     for( k= 1; k <= Qi[ii]->num; k++ ) {
     902    for( k= 1; k <= Qi[ii]->num; k++ )
     903    {
    842904      col++;
    843       for ( r= 0; r <= n; r++ ) {
    844         if ( r == i ) pLP->LiPM[r+2][col] = -1.0;
    845         else pLP->LiPM[r+2][col] = 0.0;
     905      for ( r= 0; r <= n; r++ )
     906      {
     907        if ( r == i ) pLP->LiPM[r+2][col] = -1.0;
     908        else pLP->LiPM[r+2][col] = 0.0;
    846909      }
    847910      for( r= 1; r <= dim; r++ ) pLP->LiPM[r+n+2][col] = -(mprfloat)((*Qi[ii])[k]->point[r]);
     
    849912  }
    850913
    851   if( col != cols) Werror("mayanPyramidAlg::vDistance:"
    852                           "setting up matrix for udist: col %d != cols %d",col,cols);
    853   constr = n+dim+1;                     
     914  if( col != cols)
     915    Werror("mayanPyramidAlg::vDistance:"
     916           "setting up matrix for udist: col %d != cols %d",col,cols);
     917  constr = n+dim+1;
    854918
    855919#ifdef mprDEBUG_ALL
     
    861925
    862926#if 1
    863   if ( constr + 1 > pLP->LiPM_rows ) Werror("mayanPyramidAlg::vDistance: #rows > #pLP->LiPM_rows!");
    864   if ( cols + 1 > pLP->LiPM_cols ) Werror("mayanPyramidAlg::vDistance: #cols > #pLP->LiPM_cols!");
     927  if ( constr + 1 > pLP->LiPM_rows )
     928    WerrorS("mayanPyramidAlg::vDistance: #rows > #pLP->LiPM_rows!");
     929  if ( cols + 1 > pLP->LiPM_cols )
     930    WerrorS("mayanPyramidAlg::vDistance: #cols > #pLP->LiPM_cols!");
    865931#endif
    866932
     
    873939  print_bmat( pLP->LiPM, constr+1, cols+1-constr, cols, pLP->iposv);
    874940#endif
    875    
     941
    876942  if( icase != 0 ) {  // check for errors
    877     Werror("mayanPyramidAlg::vDistance: \n");
    878     if( icase == 1 ) Werror(" vDistance: Unbounded v-distance: probably 1st v-coor=0");
    879     if( icase == -1 ) Werror(" vDistance: Infeasible v-distance");
     943    WerrorS("mayanPyramidAlg::vDistance:");
     944    if( icase == 1 )
     945      WerrorS(" vDistance: Unbounded v-distance: probably 1st v-coor=0");
     946    if( icase == -1 )
     947      WerrorS(" vDistance: Infeasible v-distance");
    880948    return -1.0;
    881949  }
     
    895963
    896964  // common part of the matrix
    897   pLP->LiPM[1][1] = 0.0;               
    898   for( i=2; i<=n+2; i++) {     
    899     pLP->LiPM[i][1] = 1.0;      // 1st col     
    900     pLP->LiPM[i][2] = 0.0;      // 2nd col     
     965  pLP->LiPM[1][1] = 0.0;
     966  for( i=2; i<=n+2; i++) {
     967    pLP->LiPM[i][1] = 1.0;        // 1st col
     968    pLP->LiPM[i][2] = 0.0;        // 2nd col
    901969  }
    902970
    903971  la_cons_row = 1;
    904972  cols = 2;
    905   for( i=0; i<=n; i++) {
     973  for( i=0; i<=n; i++)
     974  {
    906975    la_cons_row++;
    907     for( j=1; j<= Qi[i]->num; j++) {
     976    for( j=1; j<= Qi[i]->num; j++)
     977    {
    908978      cols++;
    909       pLP->LiPM[1][cols] = 0.0; // set 1st row 0
     979      pLP->LiPM[1][cols] = 0.0;        // set 1st row 0
    910980      for( k=2; k<=n+2; k++) {  // lambdas sum up to 1
    911         if( k != la_cons_row) pLP->LiPM[k][cols] = 0.0;
    912         else pLP->LiPM[k][cols] = -1.0;
     981        if( k != la_cons_row) pLP->LiPM[k][cols] = 0.0;
     982        else pLP->LiPM[k][cols] = -1.0;
    913983      }
    914984      for( k=1; k<=n; k++) pLP->LiPM[k+n+2][cols] = -(mprfloat)((*Qi[i])[j]->point[k]);
     
    916986  } // i
    917987
    918   for( i= 0; i < dim; i++ ) {           // fixed coords
     988  for( i= 0; i < dim; i++ ) {                // fixed coords
    919989    pLP->LiPM[i+n+3][1] = acoords[i];
    920990    pLP->LiPM[i+n+3][2] = 0.0;
     
    922992  pLP->LiPM[dim+n+3][1] = 0.0;
    923993
    924  
    925   pLP->LiPM[1][2] = -1.0;                       // minimize
     994
     995  pLP->LiPM[1][2] = -1.0;                        // minimize
    926996  pLP->LiPM[dim+n+3][2] = 1.0;
    927997
     
    9341004
    9351005#if 1
    936   if ( cons + 1 > pLP->LiPM_rows ) Werror(" mn_mx_MinkowskiSum: #rows > #pLP->LiPM_rows!");
    937   if ( cols + 1 > pLP->LiPM_cols ) Werror(" mn_mx_MinkowskiSum: #cols > #pLP->LiPM_cols!");
     1006  if ( cons + 1 > pLP->LiPM_rows )
     1007    WerrorS(" mn_mx_MinkowskiSum: #rows > #pLP->LiPM_rows!");
     1008  if ( cols + 1 > pLP->LiPM_cols )
     1009    WerrorS(" mn_mx_MinkowskiSum: #cols > #pLP->LiPM_cols!");
    9381010#endif
    9391011
    9401012  // simplx finds MIN for obj.fnc, puts it in [1,1]
    9411013  simplx(pLP->LiPM, cons, cols-1, 0, 0, cons, &icase, pLP->izrov, pLP->iposv);
    942  
     1014
    9431015  if ( icase != 0 ) { // check for errors
    944     if( icase < 0) Werror(" mn_mx_MinkowskiSum: LinearProgram: minR: infeasible");
    945     if( icase > 0) Werror(" mn_mx_MinkowskiSum: LinearProgram: minR: unbounded");
     1016    if( icase < 0)
     1017      WerrorS(" mn_mx_MinkowskiSum: LinearProgram: minR: infeasible");
     1018    else if( icase > 0)
     1019      WerrorS(" mn_mx_MinkowskiSum: LinearProgram: minR: unbounded");
    9461020  }
    9471021
     
    9521026
    9531027  // common part of the matrix again
    954   pLP->LiPM[1][1] = 0.0;                       
    955   for( i=2; i<=n+2; i++) {             
    956     pLP->LiPM[i][1] = 1.0;                     
    957     pLP->LiPM[i][2] = 0.0;                     
     1028  pLP->LiPM[1][1] = 0.0;
     1029  for( i=2; i<=n+2; i++) {
     1030    pLP->LiPM[i][1] = 1.0;
     1031    pLP->LiPM[i][2] = 0.0;
    9581032  }
    9591033  la_cons_row = 1;
    9601034  cols = 2;
    961   for( i=0; i<=n; i++) {
     1035  for( i=0; i<=n; i++)
     1036  {
    9621037    la_cons_row++;
    963     for( j=1; j<=Qi[i]->num; j++) {
     1038    for( j=1; j<=Qi[i]->num; j++)
     1039    {
    9641040      cols++;
    965       pLP->LiPM[1][cols] = 0.0;         
    966       for( k=2; k<=n+2; k++) { 
    967         if( k != la_cons_row) pLP->LiPM[k][cols] = 0.0;
    968         else pLP->LiPM[k][cols] = -1.0;
     1041      pLP->LiPM[1][cols] = 0.0;
     1042      for( k=2; k<=n+2; k++) {
     1043        if( k != la_cons_row) pLP->LiPM[k][cols] = 0.0;
     1044        else pLP->LiPM[k][cols] = -1.0;
    9691045      }
    9701046      for( k=1; k<=n; k++) pLP->LiPM[k+n+2][cols] = -(mprfloat)((*Qi[i])[j]->point[k]);
     
    9721048  }  // i
    9731049
    974   for( i= 0; i < dim; i++ ) {           // fixed coords
     1050  for( i= 0; i < dim; i++ ) {                // fixed coords
    9751051    pLP->LiPM[i+n+3][1] = acoords[i];
    9761052    pLP->LiPM[i+n+3][2] = 0.0;
     
    9781054  pLP->LiPM[dim+n+3][1] = 0.0;
    9791055
    980   pLP->LiPM[1][2] = 1.0;                        // maximize 
    981   pLP->LiPM[dim+n+3][2] = 1.0;          // var = sum of pnt coords
     1056  pLP->LiPM[1][2] = 1.0;                        // maximize
     1057  pLP->LiPM[dim+n+3][2] = 1.0;                // var = sum of pnt coords
    9821058
    9831059#ifdef mprDEBUG_ALL
     
    9871063
    9881064#if 1
    989   if ( cons + 1 > pLP->LiPM_rows ) Werror(" mn_mx_MinkowskiSum: #rows > #pLP->LiPM_rows!");
    990   if ( cols + 1 > pLP->LiPM_cols ) Werror(" mn_mx_MinkowskiSum: #cols > #pLP->LiPM_cols!");
     1065  if ( cons + 1 > pLP->LiPM_rows )
     1066    WerrorS(" mn_mx_MinkowskiSum: #rows > #pLP->LiPM_rows!");
     1067  if ( cols + 1 > pLP->LiPM_cols )
     1068    WerrorS(" mn_mx_MinkowskiSum: #cols > #pLP->LiPM_cols!");
    9911069#endif
    9921070
     
    9941072  simplx(pLP->LiPM, cons, cols-1, 0, 0, cons, &icase, pLP->izrov, pLP->iposv);
    9951073
    996   if ( icase != 0 ) {
    997     if( icase < 0) Werror(" mn_mx_MinkowskiSum: LinearProgram: maxR: infeasible");
    998     if( icase > 0) Werror(" mn_mx_MinkowskiSum: LinearProgram: maxR: unbounded");
    999   }
    1000 
    1001   *maxR = (Coord_t)( pLP->LiPM[1][1] + SIMPLEX_EPS );   
     1074  if ( icase != 0 )
     1075  {
     1076    if( icase < 0)
     1077      WerrorS(" mn_mx_MinkowskiSum: LinearProgram: maxR: infeasible");
     1078    else if( icase > 0)
     1079      WerrorS(" mn_mx_MinkowskiSum: LinearProgram: maxR: unbounded");
     1080  }
     1081
     1082  *maxR = (Coord_t)( pLP->LiPM[1][1] + SIMPLEX_EPS );
    10021083
    10031084#ifdef mprDEBUG_ALL
     
    10071088
    10081089// mprSTICKYPROT:
    1009 // ST_SPARSE_VREJ: rejected point 
    1010 // ST_SPARSE_VADD: added point to set 
     1090// ST_SPARSE_VREJ: rejected point
     1091// ST_SPARSE_VADD: added point to set
    10111092bool mayanPyramidAlg::storeMinkowskiSumPoint()
    10121093{
     
    10161097  dist= vDistance( &(acoords[0]), n );
    10171098
    1018   // store only points with v-distance > minVdist
    1019   if( dist <= MINVDIST + SIMPLEX_EPS ) {
     1099  // store only points with v-distance > minVdist
     1100  if( dist <= MINVDIST + SIMPLEX_EPS )
     1101  {
    10201102    mprSTICKYPROT(ST_SPARSE_VREJ);
    10211103    return false;
     
    10241106  E->addPoint( &(acoords[0]) );
    10251107  mprSTICKYPROT(ST_SPARSE_VADD);
    1026  
    1027   return true; 
     1108
     1109  return true;
    10281110}
    10291111
     
    10471129
    10481130  // step 5 -> terminate
    1049   if( dim == n-1 ) {   
    1050     int lastKilled = 0;                 
     1131  if( dim == n-1 ) {
     1132    int lastKilled = 0;
    10511133    // insert points
    10521134    acoords[dim] = minR;
    1053     while( acoords[dim] <= maxR ) {
     1135    while( acoords[dim] <= maxR )
     1136    {
    10541137      if( !storeMinkowskiSumPoint() ) lastKilled++;
    10551138      acoords[dim]++;
     
    10601143
    10611144  // step 4 -> recurse at step 3
    1062   acoords[dim] = minR;                         
    1063   while ( acoords[dim] <= maxR ) {
     1145  acoords[dim] = minR;
     1146  while ( acoords[dim] <= maxR )
     1147  {
    10641148    if ( (acoords[dim] > minR) && (acoords[dim] <= maxR) ) {     // acoords[dim] >= minR  ??
    10651149      mprSTICKYPROT(ST_SPARSE_MREC1);
    10661150      runMayanPyramid( dim + 1 );         // recurse with higer dimension
    1067     } else {   
     1151    } else {
    10681152      // get v-distance of pt
    10691153      dist= vDistance( &(acoords[0]), dim + 1 );// dim+1 == known coordinates
    10701154
    1071       if( dist >= SIMPLEX_EPS ) { 
    1072         mprSTICKYPROT(ST_SPARSE_MREC2);
    1073         runMayanPyramid( dim + 1 );       // recurse with higer dimension
     1155      if( dist >= SIMPLEX_EPS )
     1156      {
     1157        mprSTICKYPROT(ST_SPARSE_MREC2);
     1158        runMayanPyramid( dim + 1 );       // recurse with higer dimension
    10741159      }
    10751160    }
     
    10861171  int i,n= pVariables;
    10871172  int loffset= 0;
    1088   for ( i= 0; i <= n; i++ ) {
    1089     if ( (loffset < indx) && (indx <= pQ[i]->num + loffset) ) {
     1173  for ( i= 0; i <= n; i++ )
     1174  {
     1175    if ( (loffset < indx) && (indx <= pQ[i]->num + loffset) )
     1176    {
    10901177      *set= i;
    10911178      *pnt= indx-loffset;
     
    11131200
    11141201  // fill in LP matrix
    1115   for ( i= 0; i <= n; i++ ) {
     1202  for ( i= 0; i <= n; i++ )
     1203  {
    11161204    size= pQ[i]->num;
    1117     for ( k= 1; k <= size; k++ ) {
     1205    for ( k= 1; k <= size; k++ )
     1206    {
    11181207      ncols++;
    11191208
    11201209      // objective funtion, minimize
    11211210      LP.LiPM[1][ncols] = - ( (mprfloat) (*pQ[i])[k]->point[pQ[i]->dim] / SCALEDOWN );
    1122      
     1211
    11231212      // lambdas sum up to 1
    1124       for ( j = 0; j <= n; j++ ) 
    1125         if ( i==j )
    1126           LP.LiPM[j+2][ncols] = -1.0;
    1127         else
    1128           LP.LiPM[j+2][ncols] = 0.0;
     1213      for ( j = 0; j <= n; j++ )
     1214        if ( i==j )
     1215          LP.LiPM[j+2][ncols] = -1.0;
     1216        else
     1217          LP.LiPM[j+2][ncols] = 0.0;
    11291218
    11301219      // the points
    1131       for ( j = 1; j <= n; j++ ) {
    1132         LP.LiPM[j+n+2][ncols] =  - ( (mprfloat) (*pQ[i])[k]->point[j] );
    1133       }
    1134     }
    1135   }
    1136    
    1137   for ( j = 0; j <= n; j++ ) LP.LiPM[j+2][1] = 1.0;   
    1138   for ( j= 1; j <= n; j++ ) {
     1220      for ( j = 1; j <= n; j++ )
     1221      {
     1222        LP.LiPM[j+n+2][ncols] =  - ( (mprfloat) (*pQ[i])[k]->point[j] );
     1223      }
     1224    }
     1225  }
     1226
     1227  for ( j = 0; j <= n; j++ ) LP.LiPM[j+2][1] = 1.0;
     1228  for ( j= 1; j <= n; j++ )
     1229  {
    11391230    LP.LiPM[j+n+2][1]= (mprfloat)(*E)[vert]->point[j] - shift[j];
    11401231  }
     
    11461237  PrintLn();
    11471238  Print(" n= %d, NumCons=M= %d, ncols=N= %d\n",n,NumCons,ncols);
    1148   print_mat(LP.LiPM, NumCons+1, ncols+1);   
    1149 #endif 
     1239  print_mat(LP.LiPM, NumCons+1, ncols+1);
     1240#endif
    11501241
    11511242#if 1
    1152   if ( NumCons + 1 > LP.LiPM_rows ) Werror("resMatrixSparse::RC: #rows > #LP.LiPM_rows!");
    1153   if ( ncols + 1 > LP.LiPM_cols ) Werror("resMatrixSparse::RC: #cols > #LP.LiPM_cols!");
     1243  if ( NumCons + 1 > LP.LiPM_rows )
     1244    WerrorS("resMatrixSparse::RC: #rows > #LP.LiPM_rows!");
     1245  if ( ncols + 1 > LP.LiPM_cols )
     1246    WerrorS("resMatrixSparse::RC: #cols > #LP.LiPM_cols!");
    11541247#endif
    11551248
     
    11571250  simplx(LP.LiPM, NumCons, ncols,  0,  0, NumCons, &icase, LP.izrov, LP.iposv);
    11581251
    1159   if (icase < 0) {
     1252  if (icase < 0)
     1253  {
    11601254    // infeasibility: the point does not lie in a cell -> remove it
    11611255    return -1;
     
    11701264  //print_mat(LP.LiPM, NumCons+1, ncols);
    11711265#endif
    1172  
     1266
    11731267#if 1
    11741268  // sort LP results
    1175   while (found) {
     1269  while (found)
     1270  {
    11761271    found=false;
    1177     for ( i= 1; i < NumCons; i++ ) {
    1178       if ( LP.iposv[i] > LP.iposv[i+1] ) {
    1179 
    1180         c= LP.iposv[i];
    1181         LP.iposv[i]=LP.iposv[i+1];
    1182         LP.iposv[i+1]=c;
    1183 
    1184         cd=LP.LiPM[i+1][1];
    1185         LP.LiPM[i+1][1]=LP.LiPM[i+2][1];
    1186         LP.LiPM[i+2][1]=cd;
    1187 
    1188         found= true;
     1272    for ( i= 1; i < NumCons; i++ )
     1273    {
     1274      if ( LP.iposv[i] > LP.iposv[i+1] )
     1275      {
     1276
     1277        c= LP.iposv[i];
     1278        LP.iposv[i]=LP.iposv[i+1];
     1279        LP.iposv[i+1]=c;
     1280
     1281        cd=LP.LiPM[i+1][1];
     1282        LP.LiPM[i+1][1]=LP.LiPM[i+2][1];
     1283        LP.LiPM[i+2][1]=cd;
     1284
     1285        found= true;
    11891286      }
    11901287    }
     
    12031300  c=0;
    12041301  optSum= (setID*)Alloc( (NumCons) * sizeof(struct setID) );
    1205   for ( i= 0; i < NumCons; i++ ) {
     1302  for ( i= 0; i < NumCons; i++ )
     1303  {
    12061304    //Print("% .15f\n",LP.LiPM[i+2][1]);
    1207     if ( LP.LiPM[i+2][1] > 1e-12 ) {
    1208       if ( !remapXiToPoint( LP.iposv[i+1], pQ, &(optSum[c].set), &(optSum[c].pnt) ) ) {
    1209         Werror(" resMatrixSparse::RC: Found bad solution in LP: %d!",LP.iposv[i+1]);
    1210         Werror(" resMatrixSparse::RC: remapXiToPoint faild!");
    1211         return -1;
     1305    if ( LP.LiPM[i+2][1] > 1e-12 )
     1306    {
     1307      if ( !remapXiToPoint( LP.iposv[i+1], pQ, &(optSum[c].set), &(optSum[c].pnt) ) )
     1308      {
     1309        Werror(" resMatrixSparse::RC: Found bad solution in LP: %d!",LP.iposv[i+1]);
     1310        WerrorS(" resMatrixSparse::RC: remapXiToPoint faild!");
     1311        return -1;
    12121312      }
    12131313      bucket[optSum[c].set]++;
     
    12191319  // find last min in bucket[]: maximum i such that Fi is a point
    12201320  c= 0;
    1221   for ( i= 1; i < E->dim; i++ ) {
    1222     if ( bucket[c] >= bucket[i] ) {
     1321  for ( i= 1; i < E->dim; i++ )
     1322  {
     1323    if ( bucket[c] >= bucket[i] )
     1324    {
    12231325      c= i;
    12241326    }
    12251327  }
    12261328  // find matching point set
    1227   for ( i= onum - 1; i >= 0; i-- ) {
    1228     if ( optSum[i].set == c )
     1329  for ( i= onum - 1; i >= 0; i-- )
     1330  {
     1331    if ( optSum[i].set == c )
    12291332      break;
    12301333  }
     
    12331336  (*E)[vert]->rc.pnt= optSum[i].pnt;
    12341337  (*E)[vert]->rcPnt= (*pQ[c])[optSum[i].pnt];
    1235   // count 
     1338  // count
    12361339  if ( (*E)[vert]->rc.set == linPolyS ) numSet0++;
    12371340
    12381341#ifdef mprDEBUG_PROT
    12391342  Print("\n Point E[%d] was <",vert);print_exp((*E)[vert],E->dim-1);Print(">, bucket={");
    1240   for ( j= 0; j < E->dim; j++ ) {
     1343  for ( j= 0; j < E->dim; j++ )
     1344  {
    12411345    Print(" %d",bucket[j]);
    12421346  }
    12431347  Print(" }\n optimal Sum: Qi ");
    1244   for ( j= 0; j < NumCons; j++ ) {
     1348  for ( j= 0; j < NumCons; j++ )
     1349  {
    12451350    Print(" [ %d, %d ]",optSum[j].set,optSum[j].pnt);
    12461351  }
     
    12531358  mprSTICKYPROT(ST_SPARSE_RC);
    12541359
    1255   return (int)(-LP.LiPM[1][1] * SCALEDOWN); 
     1360  return (int)(-LP.LiPM[1][1] * SCALEDOWN);
    12561361}
    12571362
     
    12901395  for ( i= 1; i <= E->num; i++ ) {       // for every row
    12911396    E->getRowMP( i, epp_mon );           // compute (p-a[ij]), (i,j) = RC(p)
    1292     pSetExpV( epp, epp_mon );           
    1293 
    1294     // 
     1397    pSetExpV( epp, epp_mon );
     1398
     1399    //
    12951400    rowp= pMult( pCopy(epp), pCopy((gls->m)[(*E)[i]->rc.set]) );  // x^(p-a[ij]) * f(i)
    12961401    pSetm( rowp );
     
    12991404    // get column for every monomial in rowp and store it
    13001405    iterp= rowp;
    1301     while ( iterp ) {
     1406    while ( iterp )
     1407    {
    13021408      epos= E->getExpPos( iterp );
    1303       if ( epos == 0 ) {
    1304         // this can happen, if the shift vektor or the lift funktions
    1305         // are not generically choosen.
    1306         Werror("resMatrixSparse::createMatrix: Found exponent not in E, id %d, set [%d, %d]!",
    1307                i,(*E)[i]->rc.set,(*E)[i]->rc.pnt);
    1308         return i;
     1409      if ( epos == 0 )
     1410      {
     1411        // this can happen, if the shift vektor or the lift funktions
     1412        // are not generically choosen.
     1413        Werror("resMatrixSparse::createMatrix: Found exponent not in E, id %d, set [%d, %d]!",
     1414               i,(*E)[i]->rc.set,(*E)[i]->rc.pnt);
     1415        return i;
    13091416      }
    13101417      pSetExpV(iterp,eexp);
    13111418      pSetComp(iterp, epos );
    13121419      if ( (*E)[i]->rc.set == linPolyS ) { // store coeff positions
    1313         IMATELEM(*uRPos,rp,cp)= epos;
    1314         cp++;
     1420        IMATELEM(*uRPos,rp,cp)= epos;
     1421        cp++;
    13151422      }
    13161423      pIter( iterp );
     
    13291436
    13301437#ifdef mprDEBUG_ALL
    1331   if ( E->num <= 40 ) {
     1438  if ( E->num <= 40 )
     1439  {
    13321440    matrix mout= idModule2Matrix( idCopy(rmat) );
    13331441    print_matrix(mout);
    13341442  }
    1335   for ( i= 1; i <= numSet0; i++ ) {
     1443  for ( i= 1; i <= numSet0; i++ )
     1444  {
    13361445    Print(" row  %d contains coeffs of f_%d\n",IMATELEM(*uRPos,i,1),linPolyS);
    13371446  }
     
    13511460  srand((long)(((int)time(tp) % MAXSEED)+MAXSEED*18));
    13521461
    1353   while ( i <= dim ) {
     1462  while ( i <= dim )
     1463  {
    13541464    shift[i]= (mprfloat) (RVMULT*rand()/(RAND_MAX+1.0));
    13551465    i++;
    1356     for ( j= 1; j < i-1; j++ ) {
    1357       if ( (shift[j] < shift[i-1] + SIMPLEX_EPS) && (shift[j] > shift[i-1] - SIMPLEX_EPS) ) {
    1358         i--;
    1359         break;
     1466    for ( j= 1; j < i-1; j++ )
     1467    {
     1468      if ( (shift[j] < shift[i-1] + SIMPLEX_EPS) && (shift[j] > shift[i-1] - SIMPLEX_EPS) )
     1469      {
     1470        i--;
     1471        break;
    13601472      }
    13611473    }
     
    13731485  vs= new pointSet( dim );
    13741486
    1375   for ( j= 1; j <= Q1->num; j++ ) {
    1376     for ( k= 1; k <= Q2->num; k++ ) {
    1377       for ( l= 1; l <= dim; l++ ) {
    1378         vert.point[l]= (*Q1)[j]->point[l] + (*Q2)[k]->point[l];
     1487  for ( j= 1; j <= Q1->num; j++ )
     1488  {
     1489    for ( k= 1; k <= Q2->num; k++ )
     1490    {
     1491      for ( l= 1; l <= dim; l++ )
     1492      {
     1493        vert.point[l]= (*Q1)[j]->point[l] + (*Q2)[k]->point[l];
    13791494      }
    13801495      vs->mergeWithExp( &vert );
     
    13971512  for ( j= 1; j <= pQ[0]->num; j++ ) vs->addPoint( (*pQ[0])[j] );
    13981513
    1399   for ( j= 1; j < numq; j++ ) {
     1514  for ( j= 1; j < numq; j++ )
     1515  {
    14001516    vs_old= vs;
    14011517    vs= minkSumTwo( vs_old, pQ[j], dim );
     
    14191535  mprfloat shift[MAXVARS+2];   // shiftvector delta, index [1..dim]
    14201536
    1421   if ( pVariables > MAXVARS ) {
    1422     Werror("resMatrixSparse::resMatrixSparse: To many variables!");
     1537  if ( pVariables > MAXVARS )
     1538  {
     1539    WerrorS("resMatrixSparse::resMatrixSparse: To many variables!");
    14231540    return;
    14241541  }
     
    14471564
    14481565  // need AllocAligned since we allocate mem for type double
    1449   LP.LiPM = (mprfloat **)Alloc( LP.LiPM_rows * sizeof(mprfloat *) );  // LP matrix
    1450   for( i= 0; i < LP.LiPM_rows; i++ ) {
     1566  LP.LiPM = (mprfloat **)Alloc( LP.LiPM_rows * sizeof(mprfloat *) );  // LP matrix
     1567  for( i= 0; i < LP.LiPM_rows; i++ )
     1568  {
    14511569    // Mem must be allocated aligned, also for type double!
    14521570    LP.LiPM[i] = (mprfloat *)AllocAligned0( LP.LiPM_cols * sizeof(mprfloat) );
     
    14751593
    14761594#ifdef mprMINKSUM
    1477   E= minkSumAll( Qi, n+1, n); 
     1595  E= minkSumAll( Qi, n+1, n);
    14781596#else
    14791597  // get inner points
     
    14871605#endif
    14881606  Print("\n E = (Q_0 + ... + Q_n) \\cap \\N :\n");
    1489   for ( pnt= 1; pnt <= E->num; pnt++ ) {
     1607  for ( pnt= 1; pnt <= E->num; pnt++ )
     1608  {
    14901609    Print("%d: <",pnt);print_exp( (*E)[pnt], E->dim );Print(">\n");
    14911610  }
     
    14951614#ifdef mprTEST
    14961615  int lift[5][5];
    1497   lift[0][1]=3; lift[0][2]=4; lift[0][3]=8;  lift[0][4]=2; 
    1498   lift[1][1]=6; lift[1][2]=1; lift[1][3]=7;  lift[1][4]=4; 
     1616  lift[0][1]=3; lift[0][2]=4; lift[0][3]=8;  lift[0][4]=2;
     1617  lift[1][1]=6; lift[1][2]=1; lift[1][3]=7;  lift[1][4]=4;
    14991618  lift[2][1]=2; lift[2][2]=5; lift[2][3]=9;  lift[2][4]=6;
    15001619  lift[3][1]=2; lift[3][2]=1; lift[3][3]=9;  lift[3][4]=5;
     
    15101629
    15111630  // run Row Content Function for every point in E
    1512   for ( pnt= 1; pnt <= E->num; pnt++ ) {
     1631  for ( pnt= 1; pnt <= E->num; pnt++ )
     1632  {
    15131633    RC( Qi, E, pnt, shift );
    15141634  }
     
    15161636  // remove points not in cells
    15171637  k= E->num;
    1518   for ( pnt= k; pnt > 0; pnt-- ) {
    1519     if ( (*E)[pnt]->rcPnt == NULL ) {
     1638  for ( pnt= k; pnt > 0; pnt-- )
     1639  {
     1640    if ( (*E)[pnt]->rcPnt == NULL )
     1641    {
    15201642      E->removePoint(pnt);
    15211643      mprSTICKYPROT(ST_SPARSE_RCRJ);
     
    15261648#ifdef mprDEBUG_PROT
    15271649  Print(" points which lie in a cell:\n");
    1528   for ( pnt= 1; pnt <= E->num; pnt++ ) {
     1650  for ( pnt= 1; pnt <= E->num; pnt++ )
     1651  {
    15291652    Print("%d: <",pnt);print_exp( (*E)[pnt], E->dim );Print(">\n");
    15301653  }
     
    15391662#ifdef mprDEBUG_PROT
    15401663  Print(" points with a[ij] (%d):\n",E->num);
    1541   for ( pnt= 1; pnt <= E->num; pnt++ ) {
     1664  for ( pnt= 1; pnt <= E->num; pnt++ )
     1665  {
    15421666    Print("Punkt p \\in E[%d]: <",pnt);print_exp( (*E)[pnt], E->dim );
    15431667    Print(">, RC(p) = (i:%d, j:%d), a[i,j] = <",(*E)[pnt]->rc.set,(*E)[pnt]->rc.pnt);
     
    15481672
    15491673  // now create matrix
    1550   if ( createMatrix( E ) != E->num ) {
     1674  if ( createMatrix( E ) != E->num )
     1675  {
    15511676    // this can happen if the shiftvector shift is to large or not generic
    15521677    istate= resMatrixBase::fatalError;
    1553     Werror("resMatrixSparse::resMatrixSparse: Error in resMatrixSparse::createMatrix!");
     1678    WerrorS("resMatrixSparse::resMatrixSparse: Error in resMatrixSparse::createMatrix!");
    15541679    goto theEnd;
    15551680    //return;
     
    15581683 theEnd:
    15591684  // clean up
    1560   for ( i= 0; i < idelem; i++ ) {
     1685  for ( i= 0; i < idelem; i++ )
     1686  {
    15611687    delete Qi[i];
    15621688  }
     
    15651691  delete E;
    15661692
    1567   for( i= 0; i < LP.LiPM_rows; i++ ) {
     1693  for( i= 0; i < LP.LiPM_rows; i++ )
     1694  {
    15681695    FreeAligned( (ADDRESS) LP.LiPM[i], LP.LiPM_cols * sizeof(mprfloat) );
    15691696    //    Free( (ADDRESS) LP.LiPM[i], LP.LiPM_cols * sizeof(mprfloat) );
    15701697  }
    1571   Free( (ADDRESS) LP.LiPM, LP.LiPM_rows * sizeof(mprfloat *) ); 
     1698  Free( (ADDRESS) LP.LiPM, LP.LiPM_rows * sizeof(mprfloat *) );
    15721699
    15731700  Free( (ADDRESS) LP.iposv, (idelem * MAXPOINTS) * sizeof(int) );
     
    15921719
    15931720  // now fill in coeffs of f0
    1594   for ( i= 1; i <= numSet0; i++ ) {
     1721  for ( i= 1; i <= numSet0; i++ )
     1722  {
    15951723
    15961724    pgls= (gls->m)[0]; // f0
     
    16051733    // u_1,..,u_k
    16061734    cp=2;
    1607     while ( pNext(pgls) ) {
     1735    while ( pNext(pgls) )
     1736    {
    16081737      phelp= pOne();
    16091738      pSetCoeff( phelp, nCopy(pGetCoeff(pgls)) );
    16101739      pSetComp( phelp, IMATELEM(*uRPos,i,cp) );
    1611       if ( piter ) {
    1612         pNext(piter)= phelp;
    1613         piter= phelp;
    1614       } else {
    1615         pp= phelp;
    1616         piter= phelp;
     1740      if ( piter )
     1741      {
     1742        pNext(piter)= phelp;
     1743        piter= phelp;
     1744      }
     1745      else
     1746      {
     1747        pp= phelp;
     1748        piter= phelp;
    16171749      }
    16181750      cp++;
     
    16431775  mprPROTnl("smCallDet");
    16441776
    1645   for ( i= 1; i <= numSet0; i++ ) {
     1777  for ( i= 1; i <= numSet0; i++ )
     1778  {
    16461779    pp= (rmat->m)[IMATELEM(*uRPos,i,1)];
    16471780    pDelete( &pp );
     
    16501783    piter= NULL;
    16511784    // u_1,..,u_n
    1652     for ( cp= 2; cp <= idelem; cp++ ) {
    1653       if ( !nIsZero(evpoint[cp-1]) ) {
    1654         phelp= pOne();
    1655         pSetCoeff( phelp, nCopy(evpoint[cp-1]) );
    1656         pSetComp( phelp, IMATELEM(*uRPos,i,cp) );
    1657         if ( piter ) {
    1658           pNext(piter)= phelp;
    1659           piter= phelp;
    1660         } else {
    1661           pp= phelp;
    1662           piter= phelp;
    1663         }
     1785    for ( cp= 2; cp <= idelem; cp++ )
     1786    {
     1787      if ( !nIsZero(evpoint[cp-1]) )
     1788      {
     1789        phelp= pOne();
     1790        pSetCoeff( phelp, nCopy(evpoint[cp-1]) );
     1791        pSetComp( phelp, IMATELEM(*uRPos,i,cp) );
     1792        if ( piter )
     1793        {
     1794          pNext(piter)= phelp;
     1795          piter= phelp;
     1796        }
     1797        else
     1798        {
     1799          pp= phelp;
     1800          piter= phelp;
     1801        }
    16641802      }
    16651803    }
     
    16951833  mprPROTnl("smCallDet");
    16961834
    1697   for ( i= 1; i <= numSet0; i++ ) {
     1835  for ( i= 1; i <= numSet0; i++ )
     1836  {
    16981837    pp= (rmat->m)[IMATELEM(*uRPos,i,1)];
    16991838    pDelete( &pp );
     
    17021841    piter= NULL;
    17031842    for ( cp= 2; cp <= idelem; cp++ ) { // u1 .. un
    1704       if ( !nIsZero(evpoint[cp-1]) ) {
    1705         phelp= pOne();
    1706         pSetCoeff( phelp, nCopy(evpoint[cp-1]) );
    1707         pSetComp( phelp, IMATELEM(*uRPos,i,cp) );
    1708         if ( piter ) {
    1709           pNext(piter)= phelp;
    1710           piter= phelp;
    1711         } else {
    1712           pp= phelp;
    1713           piter= phelp;
    1714         }
     1843      if ( !nIsZero(evpoint[cp-1]) )
     1844      {
     1845        phelp= pOne();
     1846        pSetCoeff( phelp, nCopy(evpoint[cp-1]) );
     1847        pSetComp( phelp, IMATELEM(*uRPos,i,cp) );
     1848        if ( piter )
     1849        {
     1850          pNext(piter)= phelp;
     1851          piter= phelp;
     1852        }
     1853        else
     1854        {
     1855          pp= phelp;
     1856          piter= phelp;
     1857        }
    17151858      }
    17161859    }
     
    17481891   * _gls: system of multivariate polynoms
    17491892   * special: -1 -> resMatrixDense is a symbolic matrix
    1750    *    0,1, ... -> resMatrixDense ist eine u-Resultante, wobei special das 
     1893   *    0,1, ... -> resMatrixDense ist eine u-Resultante, wobei special das
    17511894   *                        lineare u-Polynom angibt
    17521895   */
     
    17741917   */
    17751918  const number getSubDet();
    1776  
     1919
    17771920private:
    17781921  /** deactivated copy constructor */
     
    17891932  void generateMonomData( int deg, intvec* polyDegs , intvec* iVO );
    17901933
    1791   /** Recursively generate all homogeneous monoms of 
     1934  /** Recursively generate all homogeneous monoms of
    17921935   * pVariables variables of degree deg.
    17931936   */
     
    18121955//<-
    18131956
    1814 //-> struct resVector 
     1957//-> struct resVector
    18151958/* Holds a row vector of the dense resultant matrix */
    18161959struct resVector
    18171960{
    18181961public:
    1819   void init() {
     1962  void init()
     1963  {
    18201964    isReduced = FALSE;
    1821     elementOfS = SFREE; 
     1965    elementOfS = SFREE;
    18221966    mon = NULL;
    18231967  }
    1824   void init( const poly m ) {
     1968  void init( const poly m )
     1969  {
    18251970    isReduced = FALSE;
    1826     elementOfS = SFREE; 
    1827     mon = m; 
     1971    elementOfS = SFREE;
     1972    mon = m;
    18281973  }
    18291974
    18301975  /** index von 0 ... numVectors-1 */
    1831   poly getElem( const int i ); 
     1976  poly getElem( const int i );
    18321977
    18331978  /** index von 0 ... numVectors-1 */
     
    18421987  int elementOfS;
    18431988
    1844   /** holds the index of u0, u1, ..., un, if (elementOfS == linPolyS) 
    1845    *  the size is given by pVariables 
     1989  /** holds the index of u0, u1, ..., un, if (elementOfS == linPolyS)
     1990   *  the size is given by pVariables
    18461991   */
    1847   int *numColParNr;       
     1992  int *numColParNr;
    18481993
    18491994  /** holds the column vector if (elementOfS != linPolyS) */
    1850   number *numColVector;   
     1995  number *numColVector;
    18511996
    18521997  /** size of numColVector */
    1853   int numColVectorSize;   
     1998  int numColVectorSize;
    18541999
    18552000  number *numColVecCopy;
     
    18592004//-> resVector::*
    18602005poly resVector::getElem( const int i ) // inline ???
    1861 { 
     2006{
    18622007  assume( 0 < i || i > numColVectorSize );
    18632008  poly out= pOne();
    18642009  pSetCoeff( out, numColVector[i] );
    18652010  pTest( out );
    1866   return( out ); 
     2011  return( out );
    18672012}
    18682013
     
    18702015{
    18712016  assume( i >= 0 && i < numColVectorSize );
    1872   return( numColVector[i] ); 
     2017  return( numColVector[i] );
    18732018}
    18742019//<-
     
    18772022resMatrixDense::resMatrixDense( const ideal _gls, const int special )
    18782023  : resMatrixBase()
    1879 { 
     2024{
    18802025  int i;
    1881  
     2026
    18822027  sourceRing=currRing;
    18832028  gls= idCopy( _gls );
     
    18862031
    18872032  // init all
    1888   generateBaseData(); 
     2033  generateBaseData();
    18892034
    18902035  totDeg= 1;
    1891   for ( i= 0; i < IDELEMS(gls); i++ ) {
     2036  for ( i= 0; i < IDELEMS(gls); i++ )
     2037  {
    18922038    totDeg*=pTotaldegree( (gls->m)[i] );
    18932039  }
     
    18972043  istate= resMatrixBase::ready;
    18982044}
    1899  
     2045
    19002046resMatrixDense::~resMatrixDense()
    19012047{
    19022048  int i,j;
    1903   for (i=0; i < numVectors; i++)
    1904     {
    1905       pDelete( &resVectorList[i].mon );
    1906       pDelete( &resVectorList[i].dividedBy );
    1907       for ( j=0; j < resVectorList[i].numColVectorSize; j++ ) {
    1908         nDelete( resVectorList[i].numColVector+j );
    1909       }
    1910       Free( (ADDRESS)resVectorList[i].numColVector, numVectors*sizeof( number ) );
    1911       Free( (ADDRESS)resVectorList[i].numColParNr, (pVariables+1) * sizeof(int) );
    1912     }
    1913  
     2049  for (i=0; i < numVectors; i++)
     2050  {
     2051    pDelete( &resVectorList[i].mon );
     2052    pDelete( &resVectorList[i].dividedBy );
     2053    for ( j=0; j < resVectorList[i].numColVectorSize; j++ )
     2054    {
     2055        nDelete( resVectorList[i].numColVector+j );
     2056    }
     2057    Free( (ADDRESS)resVectorList[i].numColVector, numVectors*sizeof( number ) );
     2058    Free( (ADDRESS)resVectorList[i].numColParNr, (pVariables+1) * sizeof(int) );
     2059  }
     2060
    19142061  Free( (ADDRESS)resVectorList, veclistmax*sizeof( resVector ) );
    19152062
    1916   // free matrix m
    1917   if ( m != NULL ) {
     2063  // free matrix m
     2064  if ( m != NULL )
     2065  {
    19182066    for ( i= 1; i <= numVectors; i++ )
    19192067      for ( j= 1; j <= numVectors; j++ )
    1920         pDelete( &MATELEM(m , i, j) );
     2068        pDelete( &MATELEM(m , i, j) );
    19212069    Free( (ADDRESS)m->m, numVectors * numVectors * sizeof(poly) );
    19222070    Free( (ADDRESS)m, sizeof(ip_smatrix) );
     
    19312079  int k,i,j;
    19322080  resVector *vecp;
    1933  
     2081
    19342082  m= mpNew( numVectors, numVectors );
    1935  
    1936   for ( i= 1; i <= MATROWS( m ); i++ )
    1937     for ( j= 1; j <= MATCOLS( m ); j++ ) {
     2083
     2084  for ( i= 1; i <= MATROWS( m ); i++ )
     2085    for ( j= 1; j <= MATCOLS( m ); j++ )
     2086    {
    19382087      MATELEM(m,i,j)= pInit();
    19392088      pSetCoeff0( MATELEM(m,i,j), nInit(0) );
    19402089    }
    1941  
    1942 
    1943   for ( k= 0; k <= numVectors - 1; k++ ) {
    1944     if ( linPolyS == getMVector(k)->elementOfS ) {
     2090
     2091
     2092  for ( k= 0; k <= numVectors - 1; k++ )
     2093  {
     2094    if ( linPolyS == getMVector(k)->elementOfS )
     2095    {
    19452096      mprSTICKYPROT(ST_DENSE_FR);
    1946       for ( i= 0; i < pVariables; i++ ) {
    1947         MATELEM(m,numVectors-k,numVectors-(getMVector(k)->numColParNr)[i])= pInit();
    1948       }
    1949     } else {
     2097      for ( i= 0; i < pVariables; i++ )
     2098      {
     2099        MATELEM(m,numVectors-k,numVectors-(getMVector(k)->numColParNr)[i])= pInit();
     2100      }
     2101    }
     2102    else
     2103    {
    19502104      mprSTICKYPROT(ST_DENSE_NR);
    19512105      vecp= getMVector(k);
    1952       for ( i= 0; i < numVectors; i++)
    1953         if ( !nIsZero( vecp->getElemNum(i) ) ) {
    1954           MATELEM(m,numVectors - k,i + 1)= pInit();
    1955           pSetCoeff( MATELEM(m,numVectors - k,i + 1), nCopy(vecp->getElemNum(i)) );
    1956         }
     2106      for ( i= 0; i < numVectors; i++)
     2107        if ( !nIsZero( vecp->getElemNum(i) ) )
     2108        {
     2109          MATELEM(m,numVectors - k,i + 1)= pInit();
     2110          pSetCoeff( MATELEM(m,numVectors - k,i + 1), nCopy(vecp->getElemNum(i)) );
     2111        }
    19572112    }
    19582113  } // for
    19592114  mprSTICKYPROT("\n");
    1960  
     2115
    19612116#ifdef mprDEBUG_ALL
    1962   for ( k= numVectors - 1; k >= 0; k-- )
    1963     if ( linPolyS == getMVector(k)->elementOfS ) {
    1964       for ( i=0; i < pVariables; i++ ) {
    1965         Print(" %d ",(getMVector(k)->numColParNr)[i]);
     2117  for ( k= numVectors - 1; k >= 0; k-- )
     2118    if ( linPolyS == getMVector(k)->elementOfS )
     2119    {
     2120      for ( i=0; i < pVariables; i++ )
     2121      {
     2122        Print(" %d ",(getMVector(k)->numColParNr)[i]);
    19662123      }
    19672124      PrintLn();
    19682125    }
    1969   for (i=1; i <= numVectors; i++) {
    1970     for (j=1; j <= numVectors; j++ ) {
     2126  for (i=1; i <= numVectors; i++)
     2127  {
     2128    for (j=1; j <= numVectors; j++ )
     2129    {
    19712130      pWrite0(MATELEM(m,i,j));Print("  ");
    19722131    }
     
    19842143    poly mon = pCopy( m );
    19852144    pSetm( mon );
    1986        
    1987     if ( numVectors == veclistmax ) {
    1988       resVectorList= (resVector * )ReAlloc( resVectorList,
    1989                                             (veclistmax) * sizeof( resVector ),
    1990                                             (veclistmax + veclistblock) * sizeof( resVector ) );
     2145
     2146    if ( numVectors == veclistmax )
     2147    {
     2148      resVectorList= (resVector * )ReAlloc( resVectorList,
     2149                                            (veclistmax) * sizeof( resVector ),
     2150                                            (veclistmax + veclistblock) * sizeof( resVector ) );
    19912151      int k;
    1992       for ( k= veclistmax; k < (veclistmax + veclistblock); k++ ) 
    1993         resVectorList[k].init();
     2152      for ( k= veclistmax; k < (veclistmax + veclistblock); k++ )
     2153        resVectorList[k].init();
    19942154      veclistmax+= veclistblock;
    19952155      mprSTICKYPROT(ST_DENSE_MEM);
     
    19982158    resVectorList[numVectors].init( mon );
    19992159    numVectors++;
    2000     mprSTICKYPROT(ST_DENSE_NMON); 
     2160    mprSTICKYPROT(ST_DENSE_NMON);
    20012161    return;
    2002   } else {
     2162  }
     2163  else
     2164  {
    20032165    if ( var == pVariables+1 ) return;
    20042166    poly newm = pCopy( m );
    2005     while ( deg >= 0 ) {
     2167    while ( deg >= 0 )
     2168    {
    20062169      generateMonoms( newm, var+1, deg );
    20072170      pIncrExp( newm, var );
     
    20112174    pDelete( & newm );
    20122175  }
    2013  
     2176
    20142177  return;
    20152178}
     
    20232186  veclistmax= veclistblock;
    20242187  resVectorList= (resVector *)Alloc( veclistmax*sizeof( resVector ) );
    2025  
     2188
    20262189  // Init resVector()s
    20272190  for ( j= veclistmax - 1; j >= 0; j-- ) resVectorList[j].init();
    20282191  numVectors= 0;
    20292192
    2030   // Generate all monoms of degree deg 
     2193  // Generate all monoms of degree deg
    20312194  poly start= pOne();
    20322195  generateMonoms( start, 1, deg );
     
    20342197
    20352198  mprSTICKYPROT("\n");
    2036  
     2199
    20372200  // Check for reduced monoms
    20382201  // First generate polyDegs.rows() monoms
    20392202  //  x(k)^(polyDegs[k]),  0 <= k < polyDegs.rows()
    20402203  ideal pDegDiv= idInit( polyDegs->rows(), 1 );
    2041   for ( k= 0; k < polyDegs->rows(); k++ ) {
     2204  for ( k= 0; k < polyDegs->rows(); k++ )
     2205  {
    20422206    poly p= pOne();
    20432207    pSetExp( p, k + 1, (*polyDegs)[k] );
     
    20502214  // exactly one x(k)^(polyDegs[k]) that divides the monom.
    20512215  int divCount;
    2052   for ( j= numVectors - 1; j >= 0; j-- ) {
     2216  for ( j= numVectors - 1; j >= 0; j-- )
     2217  {
    20532218    divCount= 0;
    2054     for ( k= 0; k < IDELEMS(pDegDiv); k++ ) 
    2055       if ( pDivisibleBy2( (pDegDiv->m)[k], resVectorList[j].mon ) ) 
    2056         divCount++;
     2219    for ( k= 0; k < IDELEMS(pDegDiv); k++ )
     2220      if ( pDivisibleBy2( (pDegDiv->m)[k], resVectorList[j].mon ) )
     2221        divCount++;
    20572222    resVectorList[j].isReduced= (divCount == 1);
    20582223  }
    20592224
    20602225  // create the sets S(k)s
    2061   // a monom x(i)^deg, deg given, is element of the set S(i) 
     2226  // a monom x(i)^deg, deg given, is element of the set S(i)
    20622227  // if all x(0)^(polyDegs[0]) ... x(i-1)^(polyDegs[i-1]) DONT divide
    20632228  // x(i)^deg and only x(i)^(polyDegs[i]) divides x(i)^deg
    20642229  bool doInsert;
    2065   for ( k= 0; k < iVO->rows(); k++) {
     2230  for ( k= 0; k < iVO->rows(); k++)
     2231  {
    20662232    //mprPROTInl(" ------------ var:",(*iVO)[k]);
    2067     for ( j= numVectors - 1; j >= 0; j-- ) {
     2233    for ( j= numVectors - 1; j >= 0; j-- )
     2234    {
    20682235      //mprPROTPnl("testing monom",resVectorList[j].mon);
    2069       if ( resVectorList[j].elementOfS == SFREE ) {
    2070         //mprPROTnl("\tfree");
    2071         if ( pDivisibleBy2( (pDegDiv->m)[ (*iVO)[k] ], resVectorList[j].mon ) ) {
    2072           //mprPROTPnl("\tdivisible by ",(pDegDiv->m)[ (*iVO)[k] ]);
    2073           doInsert=TRUE;
    2074           for ( i= 0; i < k; i++ ) {
    2075             //mprPROTPnl("\tchecking db ",(pDegDiv->m)[ (*iVO)[i] ]);
    2076             if ( pDivisibleBy2( (pDegDiv->m)[ (*iVO)[i] ], resVectorList[j].mon ) ) {
    2077               //mprPROTPnl("\t and divisible by",(pDegDiv->m)[ (*iVO)[i] ]);
    2078               doInsert=FALSE;
    2079               break;
    2080             }
    2081           }
    2082           if ( doInsert ) {
    2083             //mprPROTInl("\t------------------> S ",(*iVO)[k]);
    2084             resVectorList[j].elementOfS= (*iVO)[k];
    2085             resVectorList[j].dividedBy= pCopy( (pDegDiv->m)[ (*iVO)[i] ] );
    2086             pSetm( resVectorList[j].dividedBy );
    2087           }
    2088         }
     2236      if ( resVectorList[j].elementOfS == SFREE )
     2237      {
     2238        //mprPROTnl("\tfree");
     2239        if ( pDivisibleBy2( (pDegDiv->m)[ (*iVO)[k] ], resVectorList[j].mon ) )
     2240        {
     2241          //mprPROTPnl("\tdivisible by ",(pDegDiv->m)[ (*iVO)[k] ]);
     2242          doInsert=TRUE;
     2243          for ( i= 0; i < k; i++ )
     2244          {
     2245            //mprPROTPnl("\tchecking db ",(pDegDiv->m)[ (*iVO)[i] ]);
     2246            if ( pDivisibleBy2( (pDegDiv->m)[ (*iVO)[i] ], resVectorList[j].mon ) )
     2247            {
     2248              //mprPROTPnl("\t and divisible by",(pDegDiv->m)[ (*iVO)[i] ]);
     2249              doInsert=FALSE;
     2250              break;
     2251            }
     2252          }
     2253          if ( doInsert )
     2254          {
     2255            //mprPROTInl("\t------------------> S ",(*iVO)[k]);
     2256            resVectorList[j].elementOfS= (*iVO)[k];
     2257            resVectorList[j].dividedBy= pCopy( (pDegDiv->m)[ (*iVO)[i] ] );
     2258            pSetm( resVectorList[j].dividedBy );
     2259          }
     2260        }
    20892261      }
    20902262    }
     
    20952267  subSize= 0;
    20962268  int sub;
    2097   for ( i= 0; i < polyDegs->rows(); i++ ) {
     2269  for ( i= 0; i < polyDegs->rows(); i++ )
     2270  {
    20982271    sub= 1;
    2099     for ( k= 0; k < polyDegs->rows(); k++ ) 
     2272    for ( k= 0; k < polyDegs->rows(); k++ )
    21002273      if ( i != k ) sub*= (*polyDegs)[k];
    21012274    subSize+= sub;
     
    21092282  // Print a list of monoms and their properties
    21102283  Print("// \n");
    2111   for ( j= numVectors - 1; j >= 0; j-- ) {
     2284  for ( j= numVectors - 1; j >= 0; j-- )
     2285  {
    21122286    Print("// %s, S(%d),  db ",
    2113           resVectorList[j].isReduced?"reduced":"nonreduced",
    2114           resVectorList[j].elementOfS);
    2115     pWrite0(resVectorList[j].dividedBy); 
     2287          resVectorList[j].isReduced?"reduced":"nonreduced",
     2288          resVectorList[j].elementOfS);
     2289    pWrite0(resVectorList[j].dividedBy);
    21162290    Print("  monom ");
    21172291    pWrite(resVectorList[j].mon);
     
    21362310  // make sure that the homogenization variable goes last!
    21372311  intvec iVO( pVariables );
    2138   if ( linPolyS != SNONE ) {
     2312  if ( linPolyS != SNONE )
     2313  {
    21392314    iVO[pVariables - 1]= linPolyS;
    21402315    int p=0;
    2141     for ( k= pVariables - 1; k >= 0; k-- ) {
    2142       if ( k != linPolyS ) {
    2143         iVO[p]= k;
    2144         p++;
    2145       }
    2146     }
    2147   } else {
     2316    for ( k= pVariables - 1; k >= 0; k-- )
     2317    {
     2318      if ( k != linPolyS )
     2319      {
     2320        iVO[p]= k;
     2321        p++;
     2322      }
     2323    }
     2324  }
     2325  else
     2326  {
    21482327    linPolyS= 0;
    2149     for ( k= 0; k < pVariables; k++ ) 
     2328    for ( k= 0; k < pVariables; k++ )
    21502329      iVO[k]= pVariables - k - 1;
    21512330  }
     
    21612340
    21622341  // generate "matrix"
    2163   for ( k= numVectors - 1; k >= 0; k-- ) {
    2164     if ( resVectorList[k].elementOfS != linPolyS ) {
     2342  for ( k= numVectors - 1; k >= 0; k-- )
     2343  {
     2344    if ( resVectorList[k].elementOfS != linPolyS )
     2345    {
    21652346      // column k is a normal column with numerical or symbolic entries
    21662347      // init stuff
     
    21772358
    21782359      // fill in "matrix"
    2179       while ( pi ) {
    2180         matEntry= nCopy(pGetCoeff(pi));
    2181         pmatchPos= pHead0( pi );
    2182         pSetCoeff( pmatchPos, nInit(1) );
    2183         pSetm( pmatchPos );
    2184 
    2185         for ( i= 0; i < numVectors; i++)
    2186           if ( pEqual( pmatchPos, resVectorList[i].mon ) )
    2187             break;
    2188 
    2189         resVectorList[k].numColVector[numVectors - i - 1] = nCopy(matEntry);
    2190 
    2191         pDelete( &pmatchPos );
    2192         nDelete( &matEntry );
    2193 
    2194         pIter( pi );
     2360      while ( pi )
     2361      {
     2362        matEntry= nCopy(pGetCoeff(pi));
     2363        pmatchPos= pHead0( pi );
     2364        pSetCoeff( pmatchPos, nInit(1) );
     2365        pSetm( pmatchPos );
     2366
     2367        for ( i= 0; i < numVectors; i++)
     2368          if ( pEqual( pmatchPos, resVectorList[i].mon ) )
     2369            break;
     2370
     2371        resVectorList[k].numColVector[numVectors - i - 1] = nCopy(matEntry);
     2372
     2373        pDelete( &pmatchPos );
     2374        nDelete( &matEntry );
     2375
     2376        pIter( pi );
    21952377      }
    21962378      pDelete( &pi );
    2197     } else {
     2379    }
     2380    else
     2381    {
    21982382      // column is a special column, i.e. is generated by S0 and F0
    21992383      // safe only the positions of the ui's in the column
     
    22092393      j=0;
    22102394      while ( pi ) { // fill in "matrix"
    2211         pmp= pMult( pHead( pi ), pCopy( factor ) );
    2212         pSetm( pmp );pTest( pi );
    2213 
    2214         for ( i= 0; i < numVectors; i++)
    2215           if ( pEqual( pmp, resVectorList[i].mon ) )
    2216             break;
    2217 
    2218         resVectorList[k].numColParNr[j]= i;
    2219         pDelete( &pmp );
    2220         pIter( pi );
    2221         j++;
     2395        pmp= pMult( pHead( pi ), pCopy( factor ) );
     2396        pSetm( pmp );pTest( pi );
     2397
     2398        for ( i= 0; i < numVectors; i++)
     2399          if ( pEqual( pmp, resVectorList[i].mon ) )
     2400            break;
     2401
     2402        resVectorList[k].numColParNr[j]= i;
     2403        pDelete( &pmp );
     2404        pIter( pi );
     2405        j++;
    22222406      }
    22232407      pDelete( &pi );
     
    22332417}
    22342418
    2235 resVector *resMatrixDense::getMVector(int i) 
    2236 { 
     2419resVector *resMatrixDense::getMVector(int i)
     2420{
    22372421  assume( i >= 0 && i < numVectors );
    2238   return &resVectorList[i]; 
     2422  return &resVectorList[i];
    22392423}
    22402424
    22412425const ideal resMatrixDense::getMatrix()
    2242 { 
     2426{
    22432427  int k,i,j;
    22442428
    22452429  // copy matrix
    22462430  matrix resmat= mpNew(numVectors,numVectors);
    2247   for (i=1; i <= numVectors; i++) {
    2248     for (j=1; j <= numVectors; j++ ) {
    2249       if ( MATELEM(m,i,j) && pGetCoeff(MATELEM(m,i,j)) ) {
    2250         MATELEM(resmat,i,j)= pCopy( MATELEM(m,i,j) );
    2251       }
    2252     }
    2253   }
    2254   for (i=0; i < numVectors; i++) {
    2255     if ( resVectorList[i].elementOfS == linPolyS ) {
    2256       for (j=1; j <= pVariables; j++ ) {
    2257         if ( MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]) )
    2258           pDelete( &MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]) );
    2259         MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1])= pOne();
    2260         // FIX ME
    2261         if ( true ) {
    2262           pSetCoeff( MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]), nPar(j) );
    2263         } else {
    2264           pSetExp( MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]), j, 1 );
    2265         }
     2431  for (i=1; i <= numVectors; i++)
     2432  {
     2433    for (j=1; j <= numVectors; j++ )
     2434    {
     2435      if ( MATELEM(m,i,j) && pGetCoeff(MATELEM(m,i,j)) )
     2436      {
     2437        MATELEM(resmat,i,j)= pCopy( MATELEM(m,i,j) );
     2438      }
     2439    }
     2440  }
     2441  for (i=0; i < numVectors; i++)
     2442  {
     2443    if ( resVectorList[i].elementOfS == linPolyS )
     2444    {
     2445      for (j=1; j <= pVariables; j++ )
     2446      {
     2447        if ( MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]) )
     2448          pDelete( &MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]) );
     2449        MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1])= pOne();
     2450        // FIX ME
     2451        if ( true )
     2452        {
     2453          pSetCoeff( MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]), nPar(j) );
     2454        }
     2455        else
     2456        {
     2457          pSetExp( MATELEM(resmat,numVectors-i,numVectors-resVectorList[i].numColParNr[j-1]), j, 1 );
     2458        }
    22662459      }
    22672460    }
     
    22702463  ideal resmod= idMatrix2Module(resmat);
    22712464
    2272   if ( resmat != NULL ) {
     2465  if ( resmat != NULL )
     2466  {
    22732467    for ( i= 1; i <= numVectors; i++ )
    22742468      for ( j= 1; j <= numVectors; j++ )
    2275         pDelete( &MATELEM(resmat , i, j) );
     2469        pDelete( &MATELEM(resmat , i, j) );
    22762470    Free( (ADDRESS)resmat->m, numVectors * numVectors * sizeof(poly) );
    22772471    Free( (ADDRESS)resmat, sizeof(ip_smatrix) );
     
    22902484
    22912485  j=1;
    2292   for ( k= numVectors - 1; k >= 0; k-- ) {
     2486  for ( k= numVectors - 1; k >= 0; k-- )
     2487  {
    22932488    vecp= getMVector(k);
    22942489    if ( vecp->isReduced ) continue;
    22952490    l=1;
    2296     for ( i= numVectors - 1; i >= 0; i-- ) {
     2491    for ( i= numVectors - 1; i >= 0; i-- )
     2492    {
    22972493      if ( getMVector(i)->isReduced ) continue;
    2298       if ( !nIsZero(vecp->getElemNum(numVectors - i - 1)) ) {
    2299         MATELEM(resmat,j,l)= pInit();
    2300         MATELEM(resmat,j,l)= pCopy( vecp->getElem(numVectors-i-1) );
     2494      if ( !nIsZero(vecp->getElemNum(numVectors - i - 1)) )
     2495      {
     2496        MATELEM(resmat,j,l)= pInit();
     2497        MATELEM(resmat,j,l)= pCopy( vecp->getElem(numVectors-i-1) );
    23012498      }
    23022499      l++;
    23032500    }
    23042501    j++;
    2305   } 
     2502  }
    23062503
    23072504  ideal resmod= idMatrix2Module(resmat);
    23082505
    2309   if ( resmat != NULL ) {
     2506  if ( resmat != NULL )
     2507  {
    23102508    for ( i= 1; i <= numVectors; i++ )
    23112509      for ( j= 1; j <= numVectors; j++ )
    2312         pDelete( &MATELEM(resmat , i, j) );
     2510        pDelete( &MATELEM(resmat , i, j) );
    23132511    Free( (ADDRESS)resmat->m, numVectors * numVectors * sizeof(poly) );
    23142512    Free( (ADDRESS)resmat, sizeof(ip_smatrix) );
     
    23242522  // copy evaluation point into matrix
    23252523  // p0, p1, ..., pn replace u0, u1, ..., un
    2326   for ( k= numVectors - 1; k >= 0; k-- ) {
    2327     if ( linPolyS == getMVector(k)->elementOfS ) {
    2328       for ( i= 0; i < pVariables; i++ ) {
    2329         pSetCoeff( MATELEM(m,numVectors-k,numVectors-(getMVector(k)->numColParNr)[i]),
    2330                    nCopy(evpoint[i]) );
     2524  for ( k= numVectors - 1; k >= 0; k-- )
     2525  {
     2526    if ( linPolyS == getMVector(k)->elementOfS )
     2527    {
     2528      for ( i= 0; i < pVariables; i++ )
     2529      {
     2530        pSetCoeff( MATELEM(m,numVectors-k,numVectors-(getMVector(k)->numColParNr)[i]),
     2531                   nCopy(evpoint[i]) );
    23312532      }
    23322533    }
     
    23402541  // avoid errors for det==0
    23412542  number numres;
    2342   if ( res && pGetCoeff( res ) ) {
     2543  if ( res && pGetCoeff( res ) )
     2544  {
    23432545    numres= nCopy( pGetCoeff( res ) );
    2344   } else {
     2546  }
     2547  else
     2548  {
    23452549    numres= nInit(0);
    23462550    mprPROT("0");
    23472551  }
    2348   pDelete( &res ); 
     2552  pDelete( &res );
    23492553
    23502554  mprSTICKYPROT(ST__DET);
     
    23612565  matrix mat= mpNew( subSize, subSize );
    23622566
    2363   for ( i= 1; i <= MATROWS( mat ); i++ ) {
    2364     for ( j= 1; j <= MATCOLS( mat ); j++ ) {
     2567  for ( i= 1; i <= MATROWS( mat ); i++ )
     2568  {
     2569    for ( j= 1; j <= MATCOLS( mat ); j++ )
     2570    {
    23652571      MATELEM(mat,i,j)= pInit();
    23662572      pSetCoeff0( MATELEM(mat,i,j), nInit(0) );
     
    23682574  }
    23692575  j=1;
    2370   for ( k= numVectors - 1; k >= 0; k-- ) {
     2576  for ( k= numVectors - 1; k >= 0; k-- )
     2577  {
    23712578    vecp= getMVector(k);
    23722579    if ( vecp->isReduced ) continue;
    23732580    l=1;
    2374     for ( i= numVectors - 1; i >= 0; i-- ) {
     2581    for ( i= numVectors - 1; i >= 0; i-- )
     2582    {
    23752583      if ( getMVector(i)->isReduced ) continue;
    2376       if ( vecp->getElemNum(numVectors - i - 1) && !nIsZero(vecp->getElemNum(numVectors - i - 1)) ) {
    2377         pSetCoeff(MATELEM(mat, j , l ), nCopy(vecp->getElemNum(numVectors - i - 1)));
    2378       } /* else {
    2379            MATELEM(mat, j , l )= pOne();
    2380            pSetCoeff(MATELEM(mat, j , l ), nInit(0) );
    2381            }
    2382         */
     2584      if ( vecp->getElemNum(numVectors - i - 1) && !nIsZero(vecp->getElemNum(numVectors - i - 1)) )
     2585      {
     2586        pSetCoeff(MATELEM(mat, j , l ), nCopy(vecp->getElemNum(numVectors - i - 1)));
     2587      }
     2588      /* else
     2589      {
     2590           MATELEM(mat, j , l )= pOne();
     2591           pSetCoeff(MATELEM(mat, j , l ), nInit(0) );
     2592      }
     2593      */
    23832594      l++;
    23842595    }
    23852596    j++;
    2386   } 
     2597  }
    23872598
    23882599  poly res= singclap_det( mat );
    23892600
    23902601  number numres;
    2391   if ( res && pGetCoeff( res ) ) {
     2602  if ( res && pGetCoeff( res ) )
     2603  {
    23922604    numres= nCopy(pGetCoeff( res ));
    2393     pDelete( &res );   
    2394   } else {
     2605    pDelete( &res );
     2606  }
     2607  else
     2608  {
    23952609    numres= nInit(0);
    23962610  }
     
    24162630  mpz_init(md);mpz_set_ui(md,1);
    24172631  mpz_init(mn);mpz_set_ui(mn,1);
    2418  
     2632
    24192633  mpz_fac_ui(m,n+d);
    24202634  mpz_fac_ui(md,d);
     
    24362650uResultant::uResultant( const ideal _gls, const resMatType _rmt, BOOLEAN extIdeal )
    24372651  : rmt( _rmt )
    2438 {
    2439   if ( extIdeal ) {
     2652{
     2653  if ( extIdeal )
     2654  {
    24402655    // extend given ideal by linear poly F0=u0x0 + u1x1 +...+ unxn
    24412656    gls= extendIdeal( _gls, linearPoly( rmt ), rmt );
    24422657    n= IDELEMS( gls );
    2443   } else 
     2658  } else
    24442659    gls= idCopy( _gls );
    24452660
    2446   switch ( rmt ) {
     2661  switch ( rmt )
     2662  {
    24472663  case sparseResMat:
    24482664    resMat= new resMatrixSparse( gls );
     
    24522668    break;
    24532669  default:
    2454     Werror("uResultant::uResultant: Unknown resultant matrix type choosen!");
     2670    WerrorS("uResultant::uResultant: Unknown resultant matrix type choosen!");
    24552671  }
    24562672}
     
    24642680{
    24652681  ideal newGls= idCopy( gls );
    2466   newGls->m= (poly *)ReAlloc( newGls->m, 
    2467                               IDELEMS(gls) * sizeof(poly),
    2468                               (IDELEMS(gls) + 1) * sizeof(poly) );
     2682  newGls->m= (poly *)ReAlloc( newGls->m,
     2683                              IDELEMS(gls) * sizeof(poly),
     2684                              (IDELEMS(gls) + 1) * sizeof(poly) );
    24692685  IDELEMS(newGls)++;
    2470  
    2471   switch ( rmt ) {
     2686
     2687  switch ( rmt )
     2688  {
    24722689  case sparseResMat:
    24732690  case denseResMat:
    24742691    {
    24752692      int i;
    2476       for ( i= IDELEMS(newGls)-1; i > 0; i-- ) {
    2477         newGls->m[i]= newGls->m[i-1];
     2693      for ( i= IDELEMS(newGls)-1; i > 0; i-- )
     2694      {
     2695        newGls->m[i]= newGls->m[i-1];
    24782696      }
    24792697      newGls->m[0]= linPoly;
     
    24812699    break;
    24822700  default:
    2483     Werror("uResultant::extendIdeal: Unknown resultant matrix type choosen!");
    2484   }
    2485      
     2701    WerrorS("uResultant::extendIdeal: Unknown resultant matrix type choosen!");
     2702  }
     2703
    24862704  return( newGls );
    24872705}
     
    24942712  poly actlp, rootlp= newlp;
    24952713
    2496   for ( i= 1; i <= pVariables; i++ ) {
     2714  for ( i= 1; i <= pVariables; i++ )
     2715  {
    24972716    actlp= newlp;
    24982717    pSetExp( actlp, i, 1 );
     
    25042723  pDelete( &newlp );
    25052724
    2506   if ( rmt == sparseResMat ) {
     2725  if ( rmt == sparseResMat )
     2726  {
    25072727    newlp= pOne();
    25082728    actlp->next= newlp;
     
    25242744  // long mdg= (facul(tdg+n-1) / facul( tdg )) / facul( n - 1 );
    25252745  long mdg= over( n-1, tdg );
    2526  
     2746
    25272747  // maxiaml number of terms in a polynom of degree tdg
    25282748  long l=(long)pow( tdg+1, n );
     
    25342754#endif
    25352755
    2536   // we need mdg results of D(p0,p1,...,pn) 
     2756  // we need mdg results of D(p0,p1,...,pn)
    25372757  number *presults;
    25382758  presults= (number *)Alloc( mdg * sizeof( number ) );
     
    25462766  // initial evaluatoin point
    25472767  p=1;
    2548   for (i=0; i < n; i++) {
    2549     // init pevpoint with primes 3,5,7,11, ...
     2768  for (i=0; i < n; i++)
     2769  {
     2770    // init pevpoint with primes 3,5,7,11, ...
    25502771    p= nextPrime( p );
    25512772    pevpoint[i]=nInit( p );
     
    25562777  // evaluate the determinant in the points pev^0, pev^1, ..., pev^mdg
    25572778  mprPROTnl("// evaluating:");
    2558   for ( i=0; i < mdg; i++ ) {
    2559     for (j=0; j < n; j++) {
     2779  for ( i=0; i < mdg; i++ )
     2780  {
     2781    for (j=0; j < n; j++)
     2782    {
    25602783      nDelete( &pev[j] );
    25612784      nPower(pevpoint[j],i,&pev[j]);
     
    25742797  mprPROTnl("// interpolating:");
    25752798  number *ncpoly;
    2576   { 
     2799  {
    25772800    vandermonde vm( mdg, n, tdg, pevpoint );
    25782801    ncpoly= vm.interpolateDense( presults );
     
    25812804  if ( subDetVal != NULL ) {   // divide by common factor
    25822805      number detdiv;
    2583       for ( i= 0; i <= mdg; i++ ) {
    2584         detdiv= nDiv( ncpoly[i], subDetVal );
    2585         nNormalize( detdiv );
    2586         nDelete( &ncpoly[i] );
    2587         ncpoly[i]= detdiv;
    2588       }
    2589     }
    2590  
     2806      for ( i= 0; i <= mdg; i++ )
     2807      {
     2808        detdiv= nDiv( ncpoly[i], subDetVal );
     2809        nNormalize( detdiv );
     2810        nDelete( &ncpoly[i] );
     2811        ncpoly[i]= detdiv;
     2812      }
     2813    }
     2814
    25912815#ifdef mprDEBUG_ALL
    25922816  PrintLn();
    2593   for ( i=0; i < mdg; i++ ) {
    2594     nPrint(ncpoly[i]); Print(" --- ");
     2817  for ( i=0; i < mdg; i++ )
     2818  {
     2819    nPrint(ncpoly[i]); Print(" --- ");
    25952820  }
    25962821  PrintLn();
     
    25992824  // prepare ncpoly for later use
    26002825  number nn=nInit(0);
    2601   for ( i=0; i < mdg; i++ ) {
    2602     if ( nEqual(ncpoly[i],nn) ) {
     2826  for ( i=0; i < mdg; i++ )
     2827  {
     2828    if ( nEqual(ncpoly[i],nn) )
     2829    {
    26032830      nDelete( &ncpoly[i] );
    26042831      ncpoly[i]=NULL;
     
    26162843  long c=0;
    26172844
    2618   for ( i=0; i < l; i++ ) {
    2619     if ( sum == tdg ) {
    2620       if ( ncpoly[c] ) {
    2621         poly p= pOne();
    2622         if ( rmt == denseResMat ) {
    2623           for ( j= 0; j < n; j++ ) pSetExp( p, j+1, exp[j] );
    2624         } else if ( rmt == sparseResMat ) {
    2625           for ( j= 1; j < n; j++ ) pSetExp( p, j, exp[j] );
    2626         }
    2627         pSetCoeff( p, ncpoly[c] );
    2628         pSetm( p );
    2629         if (result) result= pAdd( pCopy(result), pCopy(p) );
    2630         else result= pCopy( p );
    2631         pDelete( &p );
     2845  for ( i=0; i < l; i++ )
     2846  {
     2847    if ( sum == tdg )
     2848    {
     2849      if ( ncpoly[c] )
     2850      {
     2851        poly p= pOne();
     2852        if ( rmt == denseResMat )
     2853        {
     2854          for ( j= 0; j < n; j++ ) pSetExp( p, j+1, exp[j] );
     2855        }
     2856        else if ( rmt == sparseResMat )
     2857        {
     2858          for ( j= 1; j < n; j++ ) pSetExp( p, j, exp[j] );
     2859        }
     2860        pSetCoeff( p, ncpoly[c] );
     2861        pSetm( p );
     2862        if (result) result= pAdd( pCopy(result), pCopy(p) );
     2863        else result= pCopy( p );
     2864        pDelete( &p );
    26322865      }
    26332866      c++;
     
    26352868    sum=0;
    26362869    exp[0]++;
    2637     for ( j= 0; j < n - 1; j++ ) {
    2638       if ( exp[j] > tdg ) {
    2639         exp[j]= 0;
    2640         exp[j + 1]++;
     2870    for ( j= 0; j < n - 1; j++ )
     2871    {
     2872      if ( exp[j] > tdg )
     2873      {
     2874        exp[j]= 0;
     2875        exp[j + 1]++;
    26412876      }
    26422877      sum+=exp[j];
    2643     } 
     2878    }
    26442879    sum+=exp[n-1];
    2645   } 
    2646  
     2880  }
     2881
    26472882  pSetm( result );
    26482883  pTest( result );
    2649  
     2884
    26502885  return result;
    26512886}
     
    26622897
    26632898  // evaluate D in tdg+1 distinct points, so
    2664   // we need tdg+1 results of D(p0,1,0,...,0) = 
     2899  // we need tdg+1 results of D(p0,1,0,...,0) =
    26652900  //              c(0)*u0^tdg + c(1)*u0^tdg-1 + ... + c(tdg-1)*u0 + c(tdg)
    26662901  number *presults;
     
    26822917  // this gives us n-1 evaluations
    26832918  p=3;
    2684   for ( uvar= 0; uvar < loops; uvar++ ) {
     2919  for ( uvar= 0; uvar < loops; uvar++ )
     2920  {
    26852921    // generate initial evaluation point
    2686     if ( matchUp ) {
    2687       for (i=0; i < n; i++) {
    2688         // prime(random number) between 1 and MAXEVPOINT
    2689         nDelete( &pevpoint[i] );
    2690         if ( i == 0 ) {
    2691           //p= nextPrime( p );
    2692           pevpoint[i]= nInit( p );
    2693         } else
    2694           if ( i <= uvar + 2 ) {
    2695             pevpoint[i]=nInit(IsPrime(1+(int) (MAXEVPOINT*rand()/(RAND_MAX+1.0))));
    2696             //pevpoint[i]=nInit(383);
    2697           } else pevpoint[i]=nInit(0);
    2698         mprPROTNnl(" ",pevpoint[i]);
    2699       }
    2700     } else {
    2701       for (i=0; i < n; i++) {
    2702         // init pevpoint with  prime,0,...0,1,0,...,0
    2703         nDelete( &pevpoint[i] );
    2704         if ( i == 0 ) {
    2705           //p=nextPrime( p );
    2706           pevpoint[i]=nInit( p );
    2707         }
    2708         else
    2709           if ( i == (uvar + 1) ) pevpoint[i]= nInit(-1);
    2710           else pevpoint[i]= nInit(0);
    2711         mprPROTNnl(" ",pevpoint[i]);
     2922    if ( matchUp )
     2923    {
     2924      for (i=0; i < n; i++)
     2925      {
     2926        // prime(random number) between 1 and MAXEVPOINT
     2927        nDelete( &pevpoint[i] );
     2928        if ( i == 0 )
     2929        {
     2930          //p= nextPrime( p );
     2931          pevpoint[i]= nInit( p );
     2932        }
     2933        else if ( i <= uvar + 2 )
     2934        {
     2935          pevpoint[i]=nInit(IsPrime(1+(int) (MAXEVPOINT*rand()/(RAND_MAX+1.0))));
     2936          //pevpoint[i]=nInit(383);
     2937        }
     2938        else
     2939          pevpoint[i]=nInit(0);
     2940        mprPROTNnl(" ",pevpoint[i]);
     2941      }
     2942    }
     2943    else
     2944    {
     2945      for (i=0; i < n; i++)
     2946      {
     2947        // init pevpoint with  prime,0,...0,1,0,...,0
     2948        nDelete( &pevpoint[i] );
     2949        if ( i == 0 )
     2950        {
     2951          //p=nextPrime( p );
     2952          pevpoint[i]=nInit( p );
     2953        }
     2954        else
     2955          if ( i == (uvar + 1) ) pevpoint[i]= nInit(-1);
     2956          else pevpoint[i]= nInit(0);
     2957        mprPROTNnl(" ",pevpoint[i]);
    27122958      }
    27132959    }
    27142960
    27152961    // prepare aktual evaluation point
    2716     for (i=0; i < n; i++) {
     2962    for (i=0; i < n; i++)
     2963    {
    27172964      nDelete( &pev[i] );
    27182965      pev[i]= nCopy( pevpoint[i] );
    27192966    }
    27202967    // evaluate the determinant in the points pev^0, pev^1, ..., pev^tdg
    2721     for ( i=0; i <= tdg; i++ ) {
     2968    for ( i=0; i <= tdg; i++ )
     2969    {
    27222970      nDelete( &pev[0] );
    27232971      nPower(pevpoint[0],i,&pev[0]);          // new evpoint
     
    27332981    mprSTICKYPROT("\n");
    27342982
    2735     // now interpolate 
     2983    // now interpolate
    27362984    vandermonde vm( tdg + 1, 1, tdg, pevpoint, FALSE );
    27372985    number *ncpoly= vm.interpolateDense( presults );
     
    27392987    if ( subDetVal != NULL ) {  // divide by common factor
    27402988      number detdiv;
    2741       for ( i= 0; i <= tdg; i++ ) {
    2742         detdiv= nDiv( ncpoly[i], subDetVal );
    2743         nNormalize( detdiv );
    2744         nDelete( &ncpoly[i] );
    2745         ncpoly[i]= detdiv;
     2989      for ( i= 0; i <= tdg; i++ )
     2990      {
     2991        detdiv= nDiv( ncpoly[i], subDetVal );
     2992        nNormalize( detdiv );
     2993        nDelete( &ncpoly[i] );
     2994        ncpoly[i]= detdiv;
    27462995      }
    27472996    }
     
    27492998#ifdef mprDEBUG_ALL
    27502999    PrintLn();
    2751     for ( i=0; i <= tdg; i++ ) {
    2752       nPrint(ncpoly[i]); Print(" --- ");
     3000    for ( i=0; i <= tdg; i++ )
     3001    {
     3002      nPrint(ncpoly[i]); Print(" --- ");
    27533003    }
    27543004    PrintLn();
     
    27563006
    27573007    // save results
    2758     roots[uvar]->fillContainer( ncpoly, pevpoint, uvar+1, tdg, 
    2759                                 (matchUp?rootContainer::cspecialmu:rootContainer::cspecial),
    2760                                 loops );
     3008    roots[uvar]->fillContainer( ncpoly, pevpoint, uvar+1, tdg,
     3009                                (matchUp?rootContainer::cspecialmu:rootContainer::cspecial),
     3010                                loops );
    27613011  }
    27623012
     
    27923042  // or D(u0,k1,k2,0,...,0), D(u0,k1,k2,k3,0,...,0), ..., D(u0,k1,k2,k3,...,kn)
    27933043  p=3;
    2794   for ( uvar= 0; uvar < loops; uvar++ ) {
     3044  for ( uvar= 0; uvar < loops; uvar++ )
     3045  {
    27953046    // generate initial evaluation point
    2796     if ( matchUp ) {
    2797       for (i=0; i < n; i++) {
    2798         // prime(random number) between 1 and MAXEVPOINT
    2799         nDelete( &pevpoint[i] );
    2800         if ( i <= uvar + 2 ) {
    2801           pevpoint[i]=nInit(IsPrime(1+(int) (MAXEVPOINT*rand()/(RAND_MAX+1.0))));
    2802           //pevpoint[i]=nInit(383);
    2803         } else pevpoint[i]=nInit(0);
    2804         mprPROTNnl(" ",pevpoint[i]);
    2805       }
    2806     } else {
    2807       for (i=0; i < n; i++) {
    2808         // init pevpoint with  prime,0,...0,-1,0,...,0
    2809         nDelete( &(pevpoint[i]) );
    2810         if ( i == (uvar + 1) ) pevpoint[i]= nInit(-1);
    2811         else pevpoint[i]= nInit(0);
    2812         mprPROTNnl(" ",pevpoint[i]);
     3047    if ( matchUp )
     3048    {
     3049      for (i=0; i < n; i++)
     3050      {
     3051        // prime(random number) between 1 and MAXEVPOINT
     3052        nDelete( &pevpoint[i] );
     3053        if ( i <= uvar + 2 )
     3054        {
     3055          pevpoint[i]=nInit(IsPrime(1+(int) (MAXEVPOINT*rand()/(RAND_MAX+1.0))));
     3056          //pevpoint[i]=nInit(383);
     3057        } else pevpoint[i]=nInit(0);
     3058        mprPROTNnl(" ",pevpoint[i]);
     3059      }
     3060    }
     3061    else
     3062    {
     3063      for (i=0; i < n; i++)
     3064      {
     3065        // init pevpoint with  prime,0,...0,-1,0,...,0
     3066        nDelete( &(pevpoint[i]) );
     3067        if ( i == (uvar + 1) ) pevpoint[i]= nInit(-1);
     3068        else pevpoint[i]= nInit(0);
     3069        mprPROTNnl(" ",pevpoint[i]);
    28133070      }
    28143071    }
     
    28193076
    28203077    piter= pures;
    2821     for ( i= tdg; i >= 0; i-- ) {
     3078    for ( i= tdg; i >= 0; i-- )
     3079    {
    28223080      //if ( piter ) Print("deg %d, pDeg(piter) %d\n",i,pTotaldegree(piter));
    2823       if ( piter && pTotaldegree(piter) == i ) {
    2824         ncpoly[i]= nCopy( pGetCoeff( piter ) );
    2825         pIter( piter );
    2826       } else {
    2827         ncpoly[i]= nInit(0);
     3081      if ( piter && pTotaldegree(piter) == i )
     3082      {
     3083        ncpoly[i]= nCopy( pGetCoeff( piter ) );
     3084        pIter( piter );
     3085      }
     3086      else
     3087      {
     3088        ncpoly[i]= nInit(0);
    28283089      }
    28293090      mprPROTNnl("", ncpoly[i] );
    2830     } 
    2831    
     3091    }
     3092
    28323093    mprSTICKYPROT(ST_BASE_EV); // .
    28333094
    28343095    if ( subDetVal != NULL ) {  // divide by common factor
    28353096      number detdiv;
    2836       for ( i= 0; i <= tdg; i++ ) {
    2837         detdiv= nDiv( ncpoly[i], subDetVal );
    2838         nNormalize( detdiv );
    2839         nDelete( &ncpoly[i] );
    2840         ncpoly[i]= detdiv;
     3097      for ( i= 0; i <= tdg; i++ )
     3098      {
     3099        detdiv= nDiv( ncpoly[i], subDetVal );
     3100        nNormalize( detdiv );
     3101        nDelete( &ncpoly[i] );
     3102        ncpoly[i]= detdiv;
    28413103      }
    28423104    }
     
    28453107
    28463108    // save results
    2847     roots[uvar]->fillContainer( ncpoly, pevpoint, uvar+1, tdg, 
    2848                                 (matchUp?rootContainer::cspecialmu:rootContainer::cspecial),
    2849                                 loops );
     3109    roots[uvar]->fillContainer( ncpoly, pevpoint, uvar+1, tdg,
     3110                                (matchUp?rootContainer::cspecialmu:rootContainer::cspecial),
     3111                                loops );
    28503112  }
    28513113
     
    28643126  i+=2;
    28653127  int j= IsPrime( i );
    2866   while ( j <= init ) {
     3128  while ( j <= init )
     3129  {
    28673130    i+=2;
    28683131    j= IsPrime( i );
     
    28793142// compile-command-1: "make installg" ***
    28803143// compile-command-2: "make install" ***
    2881 // End: *** 
     3144// End: ***
    28823145
    28833146// in folding: C-c x
  • Singular/mpr_base.h

    r0f5091 re858e7  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: mpr_base.h,v 1.1 1999-06-28 12:48:12 wenk Exp $ */
     6/* $Id: mpr_base.h,v 1.2 1999-06-28 16:06:25 Singular Exp $ */
    77
    8 /* 
     8/*
    99* ABSTRACT - multipolynomial resultants - resultant matrices
    1010*            ( sparse, dense, u-resultant solver )
     
    2121 * Base class for sparse and dense u-Resultant computation
    2222 */
    23 class resMatrixBase {
     23class resMatrixBase
     24{
    2425public:
    2526  /* state of the resultant */
     
    3738  virtual const number getSubDet() { return NULL; }
    3839
    39   virtual const long getDetDeg() const { return totDeg; } 
     40  virtual const long getDetDeg() const { return totDeg; }
    4041
    41   virtual const IStateType initState() const { return istate; } 
     42  virtual const IStateType initState() const { return istate; }
    4243
    4344protected:
     
    4950
    5051  int totDeg;
    51  
     52
    5253private:
    5354  /* disables the copy constructor */
     
    6061 * Base class for solving 0-dim poly systems using u-resultant
    6162 */
    62 class uResultant {
     63class uResultant
     64{
    6365public:
    6466  enum resMatType { none, sparseResMat, denseResMat };
     
    7577  rootContainer ** specializeInU( BOOLEAN matchUp= false, const number subDetVal= NULL );
    7678
    77   resMatrixBase * accessResMat() { return resMat; } 
     79  resMatrixBase * accessResMat() { return resMat; }
    7880
    7981private:
    8082  /* deactivated copy constructor */
    8183  uResultant( const uResultant & );
    82  
     84
    8385  ideal extendIdeal( const ideal gls, poly linPoly, const resMatType rmt );
    8486  poly linearPoly( const resMatType rmt );
     
    99101// compile-command-2: "make install" ***
    100102// compile-command: "make installg" ***
    101 // End: ***
    102 
    103 
    104 
    105 
    106 
    107 
    108 
    109 
    110 
     103// End: ***
  • Singular/mpr_complex.cc

    r0f5091 re858e7  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mpr_complex.cc,v 1.7 1999-06-28 12:48:12 wenk Exp $ */
     4/* $Id: mpr_complex.cc,v 1.8 1999-06-28 16:06:26 Singular Exp $ */
    55
    66/*
     
    199199  gmp_float r;
    200200
    201   if ( rField_is_Q() ) {
     201  if ( rField_is_Q() )
     202  {
    202203    if ( num != NULL )
     204    {
     205      if (SR_HDL(num) & SR_INT)
    203206      {
    204         if (SR_HDL(num) & SR_INT)
    205           {
    206             r= SR_TO_INT(num);
    207           }
    208         else
    209           {
    210             if ( num->s == 0 )
    211               {
    212                 nlNormalize( num );
    213               }
    214             if (SR_HDL(num) & SR_INT)
    215               {
    216                 r= SR_TO_INT(num);
    217               }
    218             else
    219               {
    220                 if ( num->s != 3 )
    221                   {
    222                     r= &num->z;
    223                     r/= (gmp_float)&num->n;
    224                   }
    225                 else
    226                   {
    227                     r= &num->z;
    228                   }
    229               }
    230           }
     207        r= SR_TO_INT(num);
    231208      }
     209      else
     210      {
     211        if ( num->s == 0 )
     212        {
     213          nlNormalize( num );
     214        }
     215        if (SR_HDL(num) & SR_INT)
     216        {
     217          r= SR_TO_INT(num);
     218        }
     219        else
     220        {
     221          if ( num->s != 3 )
     222          {
     223            r= &num->z;
     224            r/= (gmp_float)&num->n;
     225          }
     226          else
     227          {
     228            r= &num->z;
     229          }
     230        }
     231      }
     232    }
    232233    else
    233       {
    234         r= 0.0;
    235       }
    236   } else if (rField_is_long_R() || rField_is_long_C()) {
     234    {
     235      r= 0.0;
     236    }
     237  }
     238  else if (rField_is_long_R() || rField_is_long_C())
     239  {
    237240    r= *(gmp_float*)num;
    238   } else if ( rField_is_R() ) {
     241  }
     242  else if ( rField_is_R() )
     243  {
    239244    // Add some code here :-)
    240     Werror("Ground field not implemented!");
    241   } else {
    242     Werror("Ground field not implemented!");
     245    WerrorS("Ground field not implemented!");
     246  }
     247  else
     248  {
     249    WerrorS("Ground field not implemented!");
    243250  }
    244251
     
    499506    in_real=floatToStr( c.real(), oprec );         // get real part
    500507    in_imag=floatToStr( abs(c.imag()), oprec );    // get imaginary part
    501    
    502     if (rField_is_long_C()) {
     508
     509    if (rField_is_long_C())
     510    {
    503511      out=(char*)AllocL((strlen(in_real)+strlen(in_imag)+5+strlen(currRing->parameter[0]))*sizeof(char));
    504512      sprintf(out,"%s%s%s*%s",in_real,c.imag().sign()>=0?"+":"-",currRing->parameter[0],in_imag);
    505     } else {
     513    }
     514    else
     515    {
    506516      out=(char*)AllocL( (strlen(in_real)+strlen(in_imag)+8) * sizeof(char));
    507517      sprintf(out,"%s%s%s",in_real,c.imag().sign()>=0?" + I ":" - I ",in_imag);
  • Singular/mpr_complex.h

    r0f5091 re858e7  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: mpr_complex.h,v 1.5 1999-06-28 12:48:13 wenk Exp $ */
    7 
    8 /* 
     6/* $Id: mpr_complex.h,v 1.6 1999-06-28 16:06:26 Singular Exp $ */
     7
     8/*
    99* ABSTRACT - multipolynomial resultants - real floating-point numbers using gmp
    1010*            and complex numbers based on pairs of real floating-point numbers
    11 *   
     11*
    1212*/
    1313
    1414//-> include & define stuff
    1515// must have gmp version >= 2
    16 extern "C" { 
     16extern "C" {
    1717#include <gmp.h>
    1818}
     
    106106
    107107  inline bool setFromStr( char * in );
    108  
    109   // access 
     108
     109  // access
    110110  inline const mpf_t *mpfp() const;
    111111
     
    117117
    118118public:
    119   static void setPrecision( const unsigned long int prec ) { 
    120     gmp_default_prec_bits= prec; 
    121   }
    122   static void setEqualBits( const unsigned long int prec ) { 
    123     gmp_needequal_bits= prec; 
    124   }
    125 
    126   static const unsigned long int getPrecision() { 
    127     return gmp_default_prec_bits; 
    128   }
    129   static const unsigned long int getEqualBits() { 
    130     return gmp_needequal_bits; 
     119  static void setPrecision( const unsigned long int prec ) {
     120    gmp_default_prec_bits= prec;
     121  }
     122  static void setEqualBits( const unsigned long int prec ) {
     123    gmp_needequal_bits= prec;
     124  }
     125
     126  static const unsigned long int getPrecision() {
     127    return gmp_default_prec_bits;
     128  }
     129  static const unsigned long int getEqualBits() {
     130    return gmp_needequal_bits;
    131131  }
    132132
     
    270270//-> class gmp_complex
    271271/**
    272  * @short gmp_complex numbers based on 
     272 * @short gmp_complex numbers based on
    273273 */
    274274class gmp_complex
     
    306306
    307307  // gmp_complex <operator> real
    308   inline friend gmp_complex operator + ( const gmp_complex & a, const gmp_float b_d ); 
     308  inline friend gmp_complex operator + ( const gmp_complex & a, const gmp_float b_d );
    309309  inline friend gmp_complex operator - ( const gmp_complex & a, const gmp_float b_d );
    310310  inline friend gmp_complex operator * ( const gmp_complex & a, const gmp_float b_d );
     
    388388// compile-command-1: "make installg" ***
    389389// compile-command-2: "make install" ***
    390 // End: ***
    391 
    392 
    393 
    394 
    395 
     390// End: ***
  • Singular/mpr_global.h

    r0f5091 re858e7  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: mpr_global.h,v 1.3 1999-06-28 12:48:14 wenk Exp $ */
     6/* $Id: mpr_global.h,v 1.4 1999-06-28 16:06:27 Singular Exp $ */
    77
    8 /* 
    9 * ABSTRACT - multipolynomial resultants - 
     8/*
     9* ABSTRACT - multipolynomial resultants -
    1010*                                global definitions and debugging stuff
    1111*/
     
    3636#define mprPROT(msg) Print("%s",msg)
    3737#define mprPROTnl(msg) Print("%s\n",msg)
    38 #define mprPROTP(msg,poly) Print("%s",msg);pWrite0(poly) 
    39 #define mprPROTPnl(msg,poly) Print("%s",msg);pWrite(poly) 
     38#define mprPROTP(msg,poly) Print("%s",msg);pWrite0(poly)
     39#define mprPROTPnl(msg,poly) Print("%s",msg);pWrite(poly)
    4040#define mprPROTI(msg,intval) Print("%s%d",msg,intval)
    4141#define mprPROTInl(msg,intval) Print("%s%d\n",msg,intval)
    4242#define mprPROTN(msg,nval) Print("%s",msg);nPrint(nval);
    4343#define mprPROTNnl(msg,nval) Print("%s",msg);nPrint(nval);PrintLn();
    44 #else 
    45 #define mprPROT(msg) 
     44#else
     45#define mprPROT(msg)
    4646#define mprPROTnl(msg)
    4747#define mprPROTP(msg,poly)
     
    9393// compile-command-1: "make installg" ***
    9494// compile-command-2: "make install" ***
    95 // End: ***
    96 
    97 
    98 
     95// End: ***
  • Singular/mpr_inout.cc

    r0f5091 re858e7  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mpr_inout.cc,v 1.1 1999-06-28 12:48:14 wenk Exp $ */
    5 
    6 /* 
     4/* $Id: mpr_inout.cc,v 1.2 1999-06-28 16:06:28 Singular Exp $ */
     5
     6/*
    77* ABSTRACT - multipolynomial resultant
    88*/
     
    1414#include "tok.h"
    1515#include "structs.h"
    16 #include "subexpr.h" 
     16#include "subexpr.h"
    1717#include "polys.h"
    1818#include "ideals.h"
     
    4747#define TIMING_EPR(t,msg) TIMING_END_AND_PRINT(t,msg);TIMING_RESET(t);
    4848
    49 enum mprState{
    50     mprOk,
     49enum mprState
     50{
     51    mprOk,
    5152    mprWrongRType,
    52     mprHasOne, 
     53    mprHasOne,
    5354    mprInfNumOfVars,
    5455    mprNotReduced,
     
    6162//<-
    6263
    63 //-> nPrint(number n) 
     64//-> nPrint(number n)
    6465void nPrint(number n)
    6566{
     
    7677void mprPrintError( mprState state, const char * name )
    7778{
    78   switch (state) {
     79  switch (state)
     80  {
    7981  case mprWrongRType:
    80     Werror("Unknown resultant matrix type choosen!");
     82    WerrorS("Unknown resultant matrix type choosen!");
    8183    break;
    8284  case mprHasOne:
     
    8587  case mprInfNumOfVars:
    8688    Werror("Numer of elements in given ideal %s must be equal to %d!",
    87            name,pVariables+1);
     89           name,pVariables+1);
    8890    break;
    8991  case mprNotZeroDim:
     
    9294  case mprNotHomog:
    9395    Werror("The given ideal %s has to be homogeneous in"
    94            " the first ring variable!",name);
     96           " the first ring variable!",name);
    9597    break;
    9698  case mprNotReduced:
     
    98100    break;
    99101  case mprUnSupField:
    100     Werror("Ground field not implemented!");
     102    WerrorS("Ground field not implemented!");
    101103    break;
    102104  default:
     
    107109
    108110//-> mprState mprIdealCheck()
    109 mprState mprIdealCheck( const ideal theIdeal, 
    110                         const char * name,
    111                         uResultant::resMatType mtype,
    112                         BOOLEAN rmatrix= false )
     111mprState mprIdealCheck( const ideal theIdeal,
     112                        const char * name,
     113                        uResultant::resMatType mtype,
     114                        BOOLEAN rmatrix= false )
    113115{
    114116  mprState state = mprOk;
    115117  int power;
    116   int k; 
     118  int k;
    117119
    118120  int numOfVars= mtype == uResultant::denseResMat?pVariables-1:pVariables;
    119121  if ( rmatrix ) numOfVars++;
    120122
    121   if ( mtype == uResultant::none ) 
     123  if ( mtype == uResultant::none )
    122124    state= mprWrongRType;
    123125
     
    125127    state= mprInfNumOfVars;
    126128
    127   for ( k= IDELEMS(theIdeal) - 1; (state == mprOk) && (k >= 0); k-- ) {
     129  for ( k= IDELEMS(theIdeal) - 1; (state == mprOk) && (k >= 0); k-- )
     130  {
    128131    poly p = (theIdeal->m)[k];
    129132    if ( pIsConstant(p) ) state= mprHasOne;
    130     else 
    131     if ( (mtype == uResultant::denseResMat) && !pIsHomogeneous(p) ) 
     133    else
     134    if ( (mtype == uResultant::denseResMat) && !pIsHomogeneous(p) )
    132135      state=mprNotHomog;
    133136  }
    134137
    135138  if ( !(rField_is_R()||
    136         rField_is_Q()||
    137         rField_is_long_R()||
    138         rField_is_long_C()||
    139          (rmatrix && rField_is_Q_a())) )
     139        rField_is_Q()||
     140        rField_is_long_R()||
     141        rField_is_long_C()||
     142         (rmatrix && rField_is_Q_a())) )
    140143    state= mprUnSupField;
    141144
     
    149152uResultant::resMatType determineMType( int imtype )
    150153{
    151   switch ( imtype ) {
     154  switch ( imtype )
     155  {
    152156  case MPR_DENSE:
    153157    return uResultant::denseResMat;
     
    181185  res->rtyp = LIST_CMD;
    182186  res->data= (void *)emptylist;
    183  
     187
    184188  TIMING_START(mpr_overall);
    185189
    186190  // check input ideal ( = polynomial system )
    187   if ( mprIdealCheck( gls, arg1->Name(), mtype ) != mprOk ) {
     191  if ( mprIdealCheck( gls, arg1->Name(), mtype ) != mprOk )
     192  {
    188193    return TRUE;
    189194  }
     
    197202  TIMING_START(mpr_constr);
    198203  ures= new uResultant( gls, mtype );
    199   if ( ures->accessResMat()->initState() != resMatrixBase::ready ) {
    200     Werror("Error occurred during matrix setup!");
     204  if ( ures->accessResMat()->initState() != resMatrixBase::ready )
     205  {
     206    WerrorS("Error occurred during matrix setup!");
    201207    return TRUE;
    202208  }
     
    205211  // if dense resultant, check if minor nonsingular
    206212  TIMING_START(mpr_check);
    207   if ( mtype == uResultant::denseResMat ) {
     213  if ( mtype == uResultant::denseResMat )
     214  {
    208215    smv= ures->accessResMat()->getSubDet();
    209216#ifdef mprDEBUG_PROT
    210217    Print("// Determinant of submatrix: ");nPrint(smv);PrintLn();
    211218#endif
    212     if ( nIsZero(smv) ) {
    213       Werror("Unsuitable input ideal: Minor of resultant matrix is singular!");
     219    if ( nIsZero(smv) )
     220    {
     221      WerrorS("Unsuitable input ideal: Minor of resultant matrix is singular!");
    214222      return TRUE;
    215223    }
     
    220228  TIMING_START(mpr_ures);
    221229  if ( interpolate_det )
    222     iproots= ures->interpolateDenseSP( false, smv ); 
    223   else 
     230    iproots= ures->interpolateDenseSP( false, smv );
     231  else
    224232    iproots= ures->specializeInU( false, smv );
    225233  TIMING_EPR(mpr_ures,   "interpolation ures\t")
     
    227235  // main task 3: Interpolate specialized resultant polynomials
    228236  TIMING_START(mpr_mures);
    229   if ( interpolate_det ) 
     237  if ( interpolate_det )
    230238    muiproots= ures->interpolateDenseSP( true, smv );
    231   else 
     239  else
    232240    muiproots= ures->specializeInU( true, smv );
    233241  TIMING_EPR(mpr_mures,  "interpolation mures\t")
     
    245253  arranger->solve_all();
    246254  TIMING_EPR(mpr_solver, "solver time\t\t");
    247    
     255
    248256  // get list of roots
    249   if ( arranger->success() ) {
     257  if ( arranger->success() )
     258  {
    250259    TIMING_START(mpr_arrange);
    251260    arranger->arrange();
    252261    TIMING_EPR(mpr_arrange, "arrange time\t\t");
    253262    listofroots= arranger->listOfRoots( gmp_output_digits );
    254   } else {
    255     Werror("Solver was unable to find any root!");
     263  }
     264  else
     265  {
     266    WerrorS("Solver was unable to find any root!");
    256267    return TRUE;
    257268  }
     
    273284  emptylist->Clean();
    274285  //Free( (ADDRESS) emptylist, sizeof(slists) );
    275  
     286
    276287  TIMING_EPR(mpr_overall,"overall time\t\t")
    277288
     
    290301
    291302  // check input ideal ( = polynomial system )
    292   if ( mprIdealCheck( gls, arg1->Name(), mtype, true ) != mprOk ) {
     303  if ( mprIdealCheck( gls, arg1->Name(), mtype, true ) != mprOk )
     304  {
    293305    return TRUE;
    294306  }
     
    300312
    301313  delete resMat;
    302  
     314
    303315  return FALSE;
    304316}
     
    312324  gls= (poly)(arg1->Data());
    313325  int howclean= (int)arg2->Data();
    314  
     326
    315327  int deg= pTotaldegree( gls );
    316328  //  int deg= pDeg( gls );
     
    325337
    326338  if ( !(rField_is_R() ||
    327          rField_is_Q() ||
    328          rField_is_long_R() ||
    329          rField_is_long_C()) ) {
    330     Werror("Ground field not implemented!\n");
    331     return TRUE;
    332   }
    333 
    334   if ( pVariables > 1 ) {
     339         rField_is_Q() ||
     340         rField_is_long_R() ||
     341         rField_is_long_C()) )
     342         {
     343    WerrorS("Ground field not implemented!");
     344    return TRUE;
     345  }
     346
     347  if ( pVariables > 1 )
     348  {
    335349    piter= gls;
    336     for ( i= 1; i <= pVariables; i++ )
    337       if ( pGetExp( piter, i ) ) {
    338         vpos= i;
    339         break;
     350    for ( i= 1; i <= pVariables; i++ )
     351      if ( pGetExp( piter, i ) )
     352      {
     353        vpos= i;
     354        break;
    340355      }
    341     while ( piter ) {
    342       for ( i= 1; i <= pVariables; i++ )
    343         if ( (vpos != i) && (pGetExp( piter, i ) != 0) ) {
    344           Werror("The polynomial %s must be univariate!",arg1->Name());
    345           return TRUE;
    346         }
     356    while ( piter )
     357    {
     358      for ( i= 1; i <= pVariables; i++ )
     359        if ( (vpos != i) && (pGetExp( piter, i ) != 0) )
     360        {
     361          Werror("The polynomial %s must be univariate!",arg1->Name());
     362          return TRUE;
     363        }
    347364      pIter( piter );
    348365    }
     
    352369  number * pcoeffs= (number *)Alloc( (deg+1) * sizeof( number ) );
    353370  piter= gls;
    354   for ( i= deg; i >= 0; i-- ) {
     371  for ( i= deg; i >= 0; i-- )
     372  {
    355373    //if ( piter ) Print("deg %d, pDeg(piter) %d\n",i,pTotaldegree(piter));
    356     if ( piter && pTotaldegree(piter) == i ) {
     374    if ( piter && pTotaldegree(piter) == i )
     375    {
    357376      pcoeffs[i]= nCopy( pGetCoeff( piter ) );
    358377      //nPrint( pcoeffs[i] );Print("  ");
    359378      pIter( piter );
    360     } else {
     379    }
     380    else
     381    {
    361382      pcoeffs[i]= nInit(0);
    362383    }
    363   } 
     384  }
    364385
    365386#ifdef mprDEBUG_PROT
    366   for (i=deg; i >= 0; i--) {
     387  for (i=deg; i >= 0; i--)
     388  {
    367389    nPrint( pcoeffs[i] );Print("  ");
    368390  }
     
    383405  rlist->Init( elem );
    384406
    385   if (rField_is_long_C()) {
    386     for ( j= 0; j < elem; j++ ) {
     407  if (rField_is_long_C())
     408  {
     409    for ( j= 0; j < elem; j++ )
     410    {
    387411      rlist->m[j].rtyp=NUMBER_CMD;
    388412      rlist->m[j].data=(void *)nCopy((number)(roots->getRoot(j)));
    389413      //rlist->m[j].data=(void *)(number)(roots->getRoot(j));
    390414    }
    391   } else {
    392     for ( j= 0; j < elem; j++ ) {
     415  }
     416  else
     417  {
     418    for ( j= 0; j < elem; j++ )
     419    {
    393420      dummy = complexToStr( (*roots)[j], gmp_output_digits );
    394421      rlist->m[j].rtyp=STRING_CMD;
     
    423450  // p can be a vector of numbers (multivariate polynom)
    424451  //   or one number (univariate polynom)
    425   // tdg = deg(f) 
    426 
    427   int n= IDELEMS( p ); 
     452  // tdg = deg(f)
     453
     454  int n= IDELEMS( p );
    428455  int m= IDELEMS( w );
    429456  int tdg= (int)arg3->Data();
    430457
    431458  res->data= (void*)NULL;
    432  
     459
    433460  // check the input
    434   if ( tdg < 1 ) {
    435     Werror("Last input parameter must be > 0!");
    436     return TRUE;
    437   }
    438   if ( n != pVariables ) {
    439     Werror("Size of first input ideal must be equal to %d!\n",pVariables);
    440     return TRUE;
    441   }
    442   if ( m != (int)pow((double)tdg+1,(int)n) ) {
    443     Werror("Size of second input ideal must be equal to %d!\n",(int)pow((double)tdg+1,(int)n));
     461  if ( tdg < 1 )
     462  {
     463    WerrorS("Last input parameter must be > 0!");
     464    return TRUE;
     465  }
     466  if ( n != pVariables )
     467  {
     468    Werror("Size of first input ideal must be equal to %d!",pVariables);
     469    return TRUE;
     470  }
     471  if ( m != (int)pow((double)tdg+1,(int)n) )
     472  {
     473    Werror("Size of second input ideal must be equal to %d!",
     474      (int)pow((double)tdg+1,(int)n));
    444475    return TRUE;
    445476  }
    446477  if ( !(rField_is_Q() /* ||
    447          rField_is_R() || rField_is_long_R() ||
    448          rField_is_long_C()*/ ) ) {
    449     Werror("Ground field not implemented!\n");
     478         rField_is_R() || rField_is_long_R() ||
     479         rField_is_long_C()*/ ) )
     480         {
     481    WerrorS("Ground field not implemented!");
    450482    return TRUE;
    451483  }
     
    453485  number tmp;
    454486  number *pevpoint= (number *)Alloc( n * sizeof( number ) );
    455   for ( i= 0; i < n; i++ ) {
     487  for ( i= 0; i < n; i++ )
     488  {
    456489    pevpoint[i]=nInit(0);
    457     if (  (p->m)[i] ) {
     490    if (  (p->m)[i] )
     491    {
    458492      tmp = pGetCoeff( (p->m)[i] );
    459       if ( nIsZero(tmp) || nIsOne(tmp) || nIsMOne(tmp) ) {
    460         Free( (ADDRESS)pevpoint, n * sizeof( number ) );
    461         Werror("Elements of first input ideal must not be equal to -1, 0, 1!");
    462         return TRUE;
     493      if ( nIsZero(tmp) || nIsOne(tmp) || nIsMOne(tmp) )
     494      {
     495        Free( (ADDRESS)pevpoint, n * sizeof( number ) );
     496        WerrorS("Elements of first input ideal must not be equal to -1, 0, 1!");
     497        return TRUE;
    463498      }
    464499    } else tmp= NULL;
    465     if ( !nIsZero(tmp) ) {
    466       if ( !pIsConstant((p->m)[i])) {
    467         Free( (ADDRESS)pevpoint, n * sizeof( number ) );
    468         Werror("Elements of first input ideal must be numbers!");
    469         return TRUE;
     500    if ( !nIsZero(tmp) )
     501    {
     502      if ( !pIsConstant((p->m)[i]))
     503      {
     504        Free( (ADDRESS)pevpoint, n * sizeof( number ) );
     505        WerrorS("Elements of first input ideal must be numbers!");
     506        return TRUE;
    470507      }
    471508      pevpoint[i]= nCopy( tmp );
     
    474511
    475512  number *wresults= (number *)Alloc( m * sizeof( number ) );
    476   for ( i= 0; i < m; i++ ) {
     513  for ( i= 0; i < m; i++ )
     514  {
    477515    wresults[i]= nInit(0);
    478     if ( (w->m)[i] && !nIsZero(pGetCoeff((w->m)[i])) ) {
    479       if ( !pIsConstant((w->m)[i])) {
    480         Free( (ADDRESS)pevpoint, n * sizeof( number ) );
    481         Free( (ADDRESS)wresults, m * sizeof( number ) );
    482         Werror("Elements of second input ideal must be numbers!");
    483         return TRUE;
     516    if ( (w->m)[i] && !nIsZero(pGetCoeff((w->m)[i])) )
     517    {
     518      if ( !pIsConstant((w->m)[i]))
     519      {
     520        Free( (ADDRESS)pevpoint, n * sizeof( number ) );
     521        Free( (ADDRESS)wresults, m * sizeof( number ) );
     522        WerrorS("Elements of second input ideal must be numbers!");
     523        return TRUE;
    484524      }
    485525      wresults[i]= nCopy(pGetCoeff((w->m)[i]));
     
    500540//<-
    501541
    502 //-> function u_resultant_det 
     542//-> function u_resultant_det
    503543poly u_resultant_det( ideal gls, int imtype )
    504544{
     
    511551
    512552  // check input ideal ( = polynomial system )
    513   if ( mprIdealCheck( gls, "", mtype ) != mprOk ) {
     553  if ( mprIdealCheck( gls, "", mtype ) != mprOk )
     554  {
    514555    return emptypoly;
    515556  }
     
    523564
    524565  // if dense resultant, check if minor nonsingular
    525   if ( mtype == uResultant::denseResMat ) {
     566  if ( mtype == uResultant::denseResMat )
     567  {
    526568    smv= ures->accessResMat()->getSubDet();
    527569#ifdef mprDEBUG_PROT
    528570    Print("// Determinant of submatrix: ");nPrint(smv); PrintLn();
    529571#endif
    530     if ( nIsZero(smv) ) {
    531       Werror("Unsuitable input ideal: Minor of resultant matrix is singular!");
     572    if ( nIsZero(smv) )
     573    {
     574      WerrorS("Unsuitable input ideal: Minor of resultant matrix is singular!");
    532575      return emptypoly;
    533576    }
     
    558601// compile-command-1: "make installg" ***
    559602// compile-command-2: "make install" ***
    560 // End: *** 
     603// End: ***
    561604
    562605// in folding: C-c x
  • Singular/mpr_inout.h

    r0f5091 re858e7  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: mpr_inout.h,v 1.1 1999-06-28 12:48:15 wenk Exp $ */
     6/* $Id: mpr_inout.h,v 1.2 1999-06-28 16:06:28 Singular Exp $ */
    77
    8 /* 
     8/*
    99* ABSTRACT - multipolynomial resultants - interface to Singular
    10 *   
     10*
    1111*/
    1212
     
    1818/** solve a multipolynomial system using the u-resultant
    1919 * Input ideal must be 0-dimensional and pVariables == IDELEMS(ideal).
    20  * Resultant method can be MPR_DENSE, which uses Macaulay Resultant (good for 
    21  * dense homogeneous polynoms) or MPR_SPARSE, which uses Sparse Resultant 
     20 * Resultant method can be MPR_DENSE, which uses Macaulay Resultant (good for
     21 * dense homogeneous polynoms) or MPR_SPARSE, which uses Sparse Resultant
    2222 * (Gelfand, Kapranov, Zelevinsky).
    23  * If interpolate == true then the determinant of the u-resultant will be 
    24  * numerically interpolatet using a Vandermonde System. 
     23 * If interpolate == true then the determinant of the u-resultant will be
     24 * numerically interpolatet using a Vandermonde System.
    2525 * Otherwise, the Sparse Bareiss will be used (faster!).
    2626 * Returns a list containing the roots of the system.
     
    3434
    3535/** find the (complex) roots an univariate polynomial
    36  * Determines the roots of an univariate polynomial using Laguerres' 
     36 * Determines the roots of an univariate polynomial using Laguerres'
    3737 * root-solver. Good for polynomials with low and middle degree (<40).
    3838 * Returns a list containing the roots of the polynomial.
     
    5050// compile-command-1: "make installg" ***
    5151// compile-command-2: "make install" ***
    52 // End: *** 
     52// End: ***
  • Singular/mpr_numeric.cc

    r0f5091 re858e7  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mpr_numeric.cc,v 1.1 1999-06-28 12:48:16 wenk Exp $ */
    5 
    6 /* 
     4/* $Id: mpr_numeric.cc,v 1.2 1999-06-28 16:06:29 Singular Exp $ */
     5
     6/*
    77* ABSTRACT - multipolynomial resultants - numeric stuff
    8 *            ( root finder, vandermonde system solver, simplex )   
     8*            ( root finder, vandermonde system solver, simplex )
    99*/
    1010
     
    4040
    4141//-> vandermonde::*
    42 vandermonde::vandermonde( const long _cn, const long _n, const long _maxdeg, 
    43                           number *_p, const bool _homog )
     42vandermonde::vandermonde( const long _cn, const long _n, const long _maxdeg,
     43                          number *_p, const bool _homog )
    4444  : n(_n), cn(_cn), maxdeg(_maxdeg), p(_p), homog(_homog)
    4545{
     
    7070  for ( j= 0; j < n; j++ ) exp[j]=0;
    7171
    72   for ( i= 0; i < l; i++ ) {
    73     if ( !homog || (sum == maxdeg) ) {
    74       for ( j= 0; j < n; j++ ) {
    75         nPower( p[j], exp[j], &tmp );
    76         tmp1 = nMult( tmp, x[c] );
    77         x[c]= tmp1;
    78         nDelete( &tmp );
     72  for ( i= 0; i < l; i++ )
     73  {
     74    if ( !homog || (sum == maxdeg) )
     75    {
     76      for ( j= 0; j < n; j++ )
     77      {
     78        nPower( p[j], exp[j], &tmp );
     79        tmp1 = nMult( tmp, x[c] );
     80        x[c]= tmp1;
     81        nDelete( &tmp );
    7982      }
    8083      c++;
     
    8285    exp[0]++;
    8386    sum=0;
    84     for ( j= 0; j < n - 1; j++ ) {
    85       if ( exp[j] > maxdeg ) {
    86         exp[j]= 0;
    87         exp[j + 1]++;
    88         }
     87    for ( j= 0; j < n - 1; j++ )
     88    {
     89      if ( exp[j] > maxdeg )
     90      {
     91        exp[j]= 0;
     92        exp[j + 1]++;
     93        }
    8994      sum+= exp[j];
    9095    }
     
    108113  for ( j= 0; j < n+1; j++ ) exp[j]=0;
    109114
    110   for ( i= 0; i < l; i++ ) {
    111     if ( (!homog || (sum == maxdeg)) && q[i] && !nIsZero(q[i]) ) {
     115  for ( i= 0; i < l; i++ )
     116  {
     117    if ( (!homog || (sum == maxdeg)) && q[i] && !nIsZero(q[i]) )
     118    {
    112119      pnew= pOne();
    113120      pSetCoeff(pnew,q[i]);
    114121      pSetExpV(pnew,exp);
    115       if ( pit ) {
    116         pNext(pnew)= pit;
    117         pit= pnew;
    118       } else {
    119         pit= pnew;
    120         pNext(pnew)= NULL;
    121       }
     122      if ( pit )
     123      {
     124        pNext(pnew)= pit;
     125        pit= pnew;
     126      }
     127      else
     128      {
     129        pit= pnew;
     130        pNext(pnew)= NULL;
     131      }
    122132      pSetm(pit);
    123133    }
    124134    exp[1]++;
    125135    sum=0;
    126     for ( j= 1; j < n; j++ ) {
    127       if ( exp[j] > maxdeg ) {
    128         exp[j]= 0;
    129         exp[j + 1]++;
    130         }
     136    for ( j= 1; j < n; j++ )
     137    {
     138      if ( exp[j] > maxdeg )
     139      {
     140        exp[j]= 0;
     141        exp[j + 1]++;
     142        }
    131143      sum+= exp[j];
    132144    }
     
    135147
    136148  Free( (ADDRESS) exp, (n+1) * sizeof(Exponent_t) );
    137  
     149
    138150  pOrdPolyMerge(pit);
    139151  return pit;
     
    152164  w= (number *)Alloc( cn * sizeof(number) );
    153165  c= (number *)Alloc( cn * sizeof(number) );
    154   for ( j= 0; j < cn; j++ ) {
     166  for ( j= 0; j < cn; j++ )
     167  {
    155168    w[j]= nInit(0);
    156169    c[j]= nInit(0);
    157170  }
    158171
    159   if ( cn == 1 ) {
     172  if ( cn == 1 )
     173  {
    160174    nDelete( &w[0] );
    161175    w[0]= nCopy(q[0]);
    162   } else {
     176  }
     177  else
     178  {
    163179    nDelete( &c[cn-1] );
    164180    c[cn-1]= nCopy(x[0]);
     
    171187
    172188      for ( j= (cn-i-1); j <= (cn-2); j++) { // j=(cn+1-i); j <= (cn-1)
    173         nDelete( &tmp1 );
    174         tmp1= nMult( xx, c[j+1] );           // c[j]= c[j] + (xx * c[j+1])
    175         newnum= nAdd( c[j], tmp1 );
    176         nDelete( &c[j] );
    177         c[j]= newnum;
     189        nDelete( &tmp1 );
     190        tmp1= nMult( xx, c[j+1] );           // c[j]= c[j] + (xx * c[j+1])
     191        newnum= nAdd( c[j], tmp1 );
     192        nDelete( &c[j] );
     193        c[j]= newnum;
    178194      }
    179195
     
    187203      xx= nCopy(x[i]);                     // xx= x[i]
    188204
    189       nDelete( &t );         
     205      nDelete( &t );
    190206      t= nInit( 1 );                         // t= b= 1
    191207      nDelete( &b );
    192       b= nInit( 1 );         
     208      b= nInit( 1 );
    193209      nDelete( &s );                         // s= q[cn-1]
    194210      s= nCopy( q[cn-1] );
    195211
    196212      for ( k= cn-1; k >= 1; k-- ) {         // k=cn; k >= 2
    197         nDelete( &tmp1 );
    198         tmp1= nMult( xx, b );                // b= c[k] + (xx * b)
    199         nDelete( &b );
    200         b= nAdd( c[k], tmp1 );
    201 
    202         nDelete( &tmp1 );
    203         tmp1= nMult( q[k-1], b );            // s= s + (q[k-1] * b)
    204         newnum= nAdd( s, tmp1 );
    205         nDelete( &s );
    206         s= newnum;
    207 
    208         nDelete( &tmp1 );
    209         tmp1= nMult( xx, t );                // t= (t * xx) + b
    210         newnum= nAdd( tmp1, b );
    211         nDelete( &t );
    212         t= newnum;
     213        nDelete( &tmp1 );
     214        tmp1= nMult( xx, b );                // b= c[k] + (xx * b)
     215        nDelete( &b );
     216        b= nAdd( c[k], tmp1 );
     217
     218        nDelete( &tmp1 );
     219        tmp1= nMult( q[k-1], b );            // s= s + (q[k-1] * b)
     220        newnum= nAdd( s, tmp1 );
     221        nDelete( &s );
     222        s= newnum;
     223
     224        nDelete( &tmp1 );
     225        tmp1= nMult( xx, t );                // t= (t * xx) + b
     226        newnum= nAdd( tmp1, b );
     227        nDelete( &t );
     228        t= newnum;
    213229      }
    214230
     
    245261//-> definitions
    246262#define MR       8        // never change this value
    247 #define MT      20       
     263#define MT      20
    248264#define MAXIT   (MT*MR)   // max number of iterations in laguer root finder
    249265
     
    252268//<-
    253269
    254 //-> rootContainer::rootContainer() 
     270//-> rootContainer::rootContainer()
    255271rootContainer::rootContainer()
    256272{
     
    265281//<-
    266282
    267 //-> rootContainer::~rootContainer() 
     283//-> rootContainer::~rootContainer()
    268284rootContainer::~rootContainer()
    269285{
     
    272288
    273289  // free coeffs, ievpoint
    274   if ( ievpoint != NULL ) {
     290  if ( ievpoint != NULL )
     291  {
    275292    for ( i=0; i < anz+2; i++ ) nDelete( ievpoint + i );
    276293    Free( (ADDRESS)ievpoint, (anz+2) * sizeof( number ) );
     
    283300  for ( i=0; i < tdg; i++ ) delete theroots[i];
    284301  Free( (ADDRESS) theroots, (tdg)*sizeof(gmp_complex*) );
    285  
     302
    286303  mprPROTnl("~rootContainer()");
    287304}
    288305//<-
    289306
    290 //-> void rootContainer::fillContainer( ... ) 
    291 void rootContainer::fillContainer( number *_coeffs, number *_ievpoint, 
    292                                    const int _var, const int _tdg,
    293                                    const rootType  _rt, const int _anz )
     307//-> void rootContainer::fillContainer( ... )
     308void rootContainer::fillContainer( number *_coeffs, number *_ievpoint,
     309                                   const int _var, const int _tdg,
     310                                   const rootType  _rt, const int _anz )
    294311{
    295312  int i;
     
    301318  anz=_anz;
    302319
    303   for ( i=0; i <= tdg; i++ ) {
    304     if ( nEqual(coeffs[i],nn) ) {
     320  for ( i=0; i <= tdg; i++ )
     321  {
     322    if ( nEqual(coeffs[i],nn) )
     323    {
    305324      nDelete( &coeffs[i] );
    306325      coeffs[i]=NULL;
     
    312331    ievpoint= (number *)Alloc( (anz+2) * sizeof( number ) );
    313332    for (i=0; i < anz+2; i++) ievpoint[i]= nCopy( _ievpoint[i] );
    314   } 
     333  }
    315334
    316335  theroots= NULL;
     
    319338//<-
    320339
    321 //-> poly rootContainer::getPoly() 
     340//-> poly rootContainer::getPoly()
    322341poly rootContainer::getPoly()
    323342{
     
    327346  poly ppos;
    328347
    329   if ( (rt == cspecial) || ( rt == cspecialmu ) ) {
    330     for ( i= tdg; i >= 0; i-- ) {
    331       if ( coeffs[i] ) {
    332         poly p= pOne();
    333         //pSetExp( p, var+1, i);
    334         pSetExp( p, 1, i);
    335         pSetCoeff( p, nCopy( coeffs[i] ) );
    336         pSetm( p );
    337         if (result) {
    338           ppos->next=p;
    339           ppos=ppos->next;
    340         } else {
    341           result=p;
    342           ppos=p;
    343         }
    344      
     348  if ( (rt == cspecial) || ( rt == cspecialmu ) )
     349  {
     350    for ( i= tdg; i >= 0; i-- )
     351    {
     352      if ( coeffs[i] )
     353      {
     354        poly p= pOne();
     355        //pSetExp( p, var+1, i);
     356        pSetExp( p, 1, i);
     357        pSetCoeff( p, nCopy( coeffs[i] ) );
     358        pSetm( p );
     359        if (result)
     360        {
     361          ppos->next=p;
     362          ppos=ppos->next;
     363        }
     364        else
     365        {
     366          result=p;
     367          ppos=p;
     368        }
     369
    345370      }
    346371    }
    347372    pSetm( result );
    348   } 
     373  }
    349374
    350375  return result;
     
    352377//<-
    353378
    354 //-> const gmp_complex & rootContainer::opterator[] ( const int i ) 
     379//-> const gmp_complex & rootContainer::opterator[] ( const int i )
    355380// this is now inline!
    356381//  gmp_complex & rootContainer::operator[] ( const int i )
    357382//  {
    358 //    if ( found_roots && ( i >= 0) && ( i < tdg ) ) {
     383//    if ( found_roots && ( i >= 0) && ( i < tdg ) )
     384//    {
    359385//      return *theroots[i];
    360 //    } 
     386//    }
    361387//    // warning
    362388//    Werror("rootContainer::getRoot: Wrong index %d, found_roots %s",i,found_roots?"true":"false");
     
    366392//<-
    367393
    368 //-> gmp_complex & rootContainer::evPointCoord( int i ) 
     394//-> gmp_complex & rootContainer::evPointCoord( int i )
    369395gmp_complex & rootContainer::evPointCoord( const int i )
    370396{
    371397  if (! ((i >= 0) && (i < anz+2) ) )
    372     Werror("rootContainer::evPointCoord: index out of range");
     398    WerrorS("rootContainer::evPointCoord: index out of range");
    373399  if (ievpoint == NULL)
    374     Werror("rootContainer::evPointCoord: ievpoint == NULL");
     400    WerrorS("rootContainer::evPointCoord: ievpoint == NULL");
    375401
    376402  if ( (rt == cspecialmu) && found_roots ) {  // FIX ME
    377     if ( ievpoint[i] != NULL ) {
     403    if ( ievpoint[i] != NULL )
     404    {
    378405      gmp_complex *tmp= new gmp_complex();
    379406      *tmp= numberToGmp_Complex(ievpoint[i]);
    380407      return *tmp;
    381     } else {
     408    }
     409    else
     410    {
    382411      Werror("rootContainer::evPointCoord: NULL index %d",i);
    383412    }
    384413  }
    385    
     414
    386415  // warning
    387416  Werror("rootContainer::evPointCoord: Wrong index %d, found_roots %s",i,found_roots?"true":"false");
     
    391420//<-
    392421
    393 //-> bool rootContainer::changeRoots( int from, int to ) 
     422//-> bool rootContainer::changeRoots( int from, int to )
    394423bool rootContainer::swapRoots( const int from, const int to )
    395424{
    396   if ( found_roots && ( from >= 0) && ( from < tdg ) && ( to >= 0) && ( to < tdg ) ) {
    397     if ( to != from ) {
     425  if ( found_roots && ( from >= 0) && ( from < tdg ) && ( to >= 0) && ( to < tdg ) )
     426  {
     427    if ( to != from )
     428    {
    398429      gmp_complex tmp( *theroots[from] );
    399430      *theroots[from]= *theroots[to];
     
    401432    }
    402433    return true;
    403   } 
    404    
     434  }
     435
    405436  // warning
    406437  Werror(" rootContainer::changeRoots: Wrong index %d, %d",from,to);
     
    409440//<-
    410441
    411 //-> void rootContainer::solver() 
     442//-> void rootContainer::solver()
    412443bool rootContainer::solver( const int polishmode )
    413444{
     
    420451  // copy the coefficients of type number to type gmp_complex
    421452  gmp_complex **ad= (gmp_complex**)Alloc( (tdg+1)*sizeof(gmp_complex*) );
    422   for ( i=0; i <= tdg; i++ ) {
     453  for ( i=0; i <= tdg; i++ )
     454  {
    423455    ad[i]= new gmp_complex();
    424456    if ( coeffs[i] ) *ad[i] = numberToGmp_Complex( coeffs[i] );
     
    426458
    427459  // now solve
    428   switch (polishmode) {
     460  switch (polishmode)
     461  {
    429462  case PM_NONE:
    430463  case PM_POLISH:
    431464    found_roots= laguer_driver( ad, theroots, polishmode == PM_POLISH );
    432     if (!found_roots) {
    433       Werror("rootContainer::solver: No roots found!");
     465    if (!found_roots)
     466    {
     467      WerrorS("rootContainer::solver: No roots found!");
    434468      goto solverend;
    435469    }
    436470    break;
    437471  case PM_CORRUPT:
    438     found_roots= laguer_driver( ad, theroots, false ); 
     472    found_roots= laguer_driver( ad, theroots, false );
    439473    // corrupt the roots
    440474    for ( i= 0; i < tdg; i++ )
    441475      *theroots[i]= *theroots[i] * (gmp_float)(1.0+0.01*(mprfloat)i);
    442     // and interpolate again     
     476    // and interpolate again
    443477    found_roots= laguer_driver( ad, theroots, true );
    444     if (!found_roots) {
    445       Werror("rootContainer::solver: No roots found!");
     478    if (!found_roots)
     479    {
     480      WerrorS("rootContainer::solver: No roots found!");
    446481      goto solverend;
    447482    }
     
    460495//<-
    461496
    462 //-> gmp_complex* rootContainer::laguer_driver( bool polish ) 
     497//-> gmp_complex* rootContainer::laguer_driver( bool polish )
    463498bool rootContainer::laguer_driver(gmp_complex ** a, gmp_complex ** roots, bool polish )
    464499{
     
    471506  for ( i=0; i <= tdg; i++ ) ad[i]= new gmp_complex( *a[i] );
    472507
    473   for ( j= tdg; j >= 1; j-- ) {
     508  for ( j= tdg; j >= 1; j-- )
     509  {
    474510    x= gmp_complex();
    475511
     
    479515    mprSTICKYPROT(ST_ROOTS_LGSTEP);
    480516    if ( its > MAXIT ) {  // error
    481       Werror("rootContainer::laguer_driver: To many iterations!");
     517      WerrorS("rootContainer::laguer_driver: To many iterations!");
    482518      ret= false;
    483519      goto theend;
    484520    }
    485     if ( abs(x.imag()) <= (gmp_float)(2.0*EPS)*abs(x.real())) {
     521    if ( abs(x.imag()) <= (gmp_float)(2.0*EPS)*abs(x.real()))
     522    {
    486523      x= gmp_complex( x.real() );
    487524    }
    488525    *roots[j-1]= x;
    489526    b= *ad[j];
    490     for ( jj= j-1; jj >= 0; jj-- ) {
     527    for ( jj= j-1; jj >= 0; jj-- )
     528    {
    491529      c= *ad[jj];
    492530      *ad[jj]= b;
     
    495533  }
    496534
    497   if ( polish ) {
     535  if ( polish )
     536  {
    498537    mprSTICKYPROT(ST_ROOTS_LGPOLISH);
    499538    for ( i=0; i <= tdg; i++ ) *ad[i]=*a[i];
    500539
    501     for ( j= 1; j <= tdg; j++ ) {
     540    for ( j= 1; j <= tdg; j++ )
     541    {
    502542      // run laguer alg with corrupted roots
    503543      laguer( ad, tdg, roots[j-1], &its );
    504544
    505545      mprSTICKYPROT(ST_ROOTS_LGSTEP);
    506       if ( its > MAXIT ) {  // error
    507         Werror("rootContainer::laguer_driver: To many iterations!");
    508         ret= false;
    509         goto theend;
    510       }
    511     }
    512     for ( j= 2; j <= tdg; j++ ) {
     546      if ( its > MAXIT )
     547      {  // error
     548        WerrorS("rootContainer::laguer_driver: To many iterations!");
     549        ret= false;
     550        goto theend;
     551      }
     552    }
     553    for ( j= 2; j <= tdg; j++ )
     554    {
    513555      // sort root by their absolute real parts by straight insertion
    514556      x= *roots[j-1];
    515       for ( i= j-1; i >= 1; i-- ) {
    516         if ( abs(roots[i-1]->real()) <= abs(x.real()) ) break;
    517         *roots[i]= *roots[i-1];
     557      for ( i= j-1; i >= 1; i-- )
     558      {
     559        if ( abs(roots[i-1]->real()) <= abs(x.real()) ) break;
     560        *roots[i]= *roots[i-1];
    518561      }
    519562      *roots[i]= x;
     
    530573//<-
    531574
    532 //-> void rootContainer::laguer(...) 
     575//-> void rootContainer::laguer(...)
    533576void rootContainer::laguer(gmp_complex ** a, int m, gmp_complex *x, int *its)
    534577{
     
    540583  gmp_float epss(1.0/pow(10.0,(int)(gmp_output_digits+gmp_output_digits/4)));
    541584
    542   for ( iter= 1; iter <= MAXIT; iter++ ) {
     585  for ( iter= 1; iter <= MAXIT; iter++ )
     586  {
    543587    mprSTICKYPROT(ST_ROOTS_LG);
    544588
     
    546590
    547591    b= *a[m];
    548     err_g= abs(b); 
     592    err_g= abs(b);
    549593    d= gmp_complex();
    550594    f= gmp_complex();
    551     abx_g= abs(*x); 
    552 
    553     for ( j= m-1; j >= 0; j-- ) {
     595    abx_g= abs(*x);
     596
     597    for ( j= m-1; j >= 0; j-- )
     598    {
    554599      f= ( *x * f ) + d;
    555600      d= ( *x * d ) + b;
    556601      b= ( *x * b ) + *a[j];
    557       err_g= abs( b ) + ( abx_g * err_g ); 
     602      err_g= abs( b ) + ( abx_g * err_g );
    558603    }
    559604
    560605    err_g *= epss; // EPSS;
    561606
    562     if ( abs(b) <= err_g ) return; 
     607    if ( abs(b) <= err_g ) return;
    563608
    564609    g= d / b;
     
    568613    gp= g + sq;
    569614    gm= g - sq;
    570     abp_g= abs( gp ); 
    571     abm_g= abs( gm ); 
     615    abp_g= abs( gp );
     616    abm_g= abs( gm );
    572617
    573618    if ( abp_g < abm_g ) gp= gm;
    574619
    575     dx = ( (max(abp_g,abm_g) > (gmp_float)0.0) 
    576            ? ( gmp_complex( (mprfloat)m ) / gp )
    577            : ( gmp_complex( cos((mprfloat)iter),sin((mprfloat)iter))
    578                * exp(log((gmp_float)1.0+abx_g))) );
    579    
     620    dx = ( (max(abp_g,abm_g) > (gmp_float)0.0)
     621           ? ( gmp_complex( (mprfloat)m ) / gp )
     622           : ( gmp_complex( cos((mprfloat)iter),sin((mprfloat)iter))
     623               * exp(log((gmp_float)1.0+abx_g))) );
     624
    580625    x1= *x - dx;
    581626
     
    596641//-----------------------------------------------------------------------------
    597642
    598 //-> rootArranger::rootArranger(...) 
    599 rootArranger::rootArranger( rootContainer ** _roots, 
    600                             rootContainer ** _mu,
    601                             const int _howclean )
     643//-> rootArranger::rootArranger(...)
     644rootArranger::rootArranger( rootContainer ** _roots,
     645                            rootContainer ** _mu,
     646                            const int _howclean )
    602647  : roots(_roots), mu(_mu), howclean(_howclean)
    603648{
     
    614659  // find roots of polys given by coeffs in roots
    615660  rc= roots[0]->getAnzElems();
    616   for ( i= 0; i < rc; i++ )
    617     if ( !roots[i]->solver( howclean ) ) {
     661  for ( i= 0; i < rc; i++ )
     662    if ( !roots[i]->solver( howclean ) )
     663    {
    618664      found_roots= false;
    619665      return;
     
    621667  // find roots of polys given by coeffs in mu
    622668  mc= mu[0]->getAnzElems();
    623   for ( i= 0; i < mc; i++ )
    624     if ( ! mu[i]->solver( howclean ) ) {
     669  for ( i= 0; i < mc; i++ )
     670    if ( ! mu[i]->solver( howclean ) )
     671    {
    625672      found_roots= false;
    626673      return;
     
    629676//<-
    630677
    631 //-> void rootArranger::arrange() 
     678//-> void rootArranger::arrange()
    632679void rootArranger::arrange()
    633680{
     
    641688
    642689  for ( xkoord= 0; xkoord < anzm; xkoord++ ) {    // für x1,x2, x1,x2,x3, x1,x2,...,xn
    643     for ( r= 0; r < anzr; r++ ) {                 // für jede Nullstelle 
    644       // (x1-koordinate) * evp[1] + (x2-koordinate) * evp[2] + 
     690    for ( r= 0; r < anzr; r++ ) {                 // für jede Nullstelle
     691      // (x1-koordinate) * evp[1] + (x2-koordinate) * evp[2] +
    645692      //                                  ... + (xkoord-koordinate) * evp[xkoord]
    646693      tmp= gmp_complex();
    647       for ( xk =0; xk <= xkoord; xk++ ){
    648         tmp -= (*roots[xk])[r] * mu[xkoord]->evPointCoord(xk+1); //xk+1
     694      for ( xk =0; xk <= xkoord; xk++ )
     695      {
     696        tmp -= (*roots[xk])[r] * mu[xkoord]->evPointCoord(xk+1); //xk+1
    649697      }
    650698      found= false;
    651       for ( rtest= r; rtest < anzr; rtest++ ) {   // für jede Nullstelle
    652         zwerg = tmp - (*roots[xk])[rtest] * mu[xkoord]->evPointCoord(xk+1); // xk+1, xkoord+2
    653         for ( mtest= 0; mtest < anzr; mtest++ ) {
    654           //      if ( tmp == (*mu[xkoord])[mtest] ) {
    655           if ( ((zwerg.real() <= (*mu[xkoord])[mtest].real() + mprec) &&
    656                 (zwerg.real() >= (*mu[xkoord])[mtest].real() - mprec)) &&
    657                ((zwerg.imag() <= (*mu[xkoord])[mtest].imag() + mprec) &&
    658                 (zwerg.imag() >= (*mu[xkoord])[mtest].imag() - mprec)) ) {
    659             roots[xk]->swapRoots( r, rtest );
    660             found= true;
    661             break;
    662           }
    663         }
     699      for ( rtest= r; rtest < anzr; rtest++ ) {   // für jede Nullstelle
     700        zwerg = tmp - (*roots[xk])[rtest] * mu[xkoord]->evPointCoord(xk+1); // xk+1, xkoord+2
     701        for ( mtest= 0; mtest < anzr; mtest++ )
     702        {
     703          //          if ( tmp == (*mu[xkoord])[mtest] )
     704          //          {
     705          if ( ((zwerg.real() <= (*mu[xkoord])[mtest].real() + mprec) &&
     706                (zwerg.real() >= (*mu[xkoord])[mtest].real() - mprec)) &&
     707               ((zwerg.imag() <= (*mu[xkoord])[mtest].imag() + mprec) &&
     708                (zwerg.imag() >= (*mu[xkoord])[mtest].imag() - mprec)) )
     709           {
     710             roots[xk]->swapRoots( r, rtest );
     711             found= true;
     712             break;
     713           }
     714        }
    664715      } // rtest
    665       if ( !found ) {
    666         Werror("rootArranger::arrange: No match? coord %d, root %d.",xkoord,r);
     716      if ( !found )
     717      {
     718        Werror("rootArranger::arrange: No match? coord %d, root %d.",xkoord,r);
    667719#ifdef mprDEBUG_PROT
    668         Werror("One of these ...");
    669         for ( rtest= r; rtest < anzr; rtest++ ) {
    670           tmp= gmp_complex();
    671           for ( xk =0; xk <= xkoord; xk++ ){
    672             tmp-= (*roots[xk])[r] * mu[xkoord]->evPointCoord(xk+1);
    673           }
    674           tmp-= (*roots[xk])[rtest] * mu[xkoord]->evPointCoord(xk+1); // xkoord+2
    675           Werror("  %s",complexToStr(tmp,gmp_output_digits+1),rtest);
    676         }
    677         Werror(" ... must match to one of these:");
    678         for ( mtest= 0; mtest < anzr; mtest++ ) {
    679           Werror("                  %s",complexToStr((*mu[xkoord])[mtest],gmp_output_digits+1));
    680         }
     720        WerrorS("One of these ...");
     721        for ( rtest= r; rtest < anzr; rtest++ )
     722        {
     723          tmp= gmp_complex();
     724          for ( xk =0; xk <= xkoord; xk++ )
     725          {
     726            tmp-= (*roots[xk])[r] * mu[xkoord]->evPointCoord(xk+1);
     727          }
     728          tmp-= (*roots[xk])[rtest] * mu[xkoord]->evPointCoord(xk+1); // xkoord+2
     729          Werror("  %s",complexToStr(tmp,gmp_output_digits+1),rtest);
     730        }
     731        WerrorS(" ... must match to one of these:");
     732        for ( mtest= 0; mtest < anzr; mtest++ )
     733        {
     734          Werror("                  %s",complexToStr((*mu[xkoord])[mtest],gmp_output_digits+1));
     735        }
    681736#endif
    682737      }
     
    686741//<-
    687742
    688 //-> lists rootArranger::listOfRoots( int oprec ) 
     743//-> lists rootArranger::listOfRoots( int oprec )
    689744lists rootArranger::listOfRoots( const unsigned int oprec )
    690745{
     
    695750  lists listofroots= (lists)Alloc( sizeof(slists) ); // must be done this way!
    696751
    697   if ( found_roots ) {
     752  if ( found_roots )
     753  {
    698754    listofroots->Init( count );
    699    
    700     for (i=0; i < count; i++) {
     755
     756    for (i=0; i < count; i++)
     757    {
    701758      lists onepoint= (lists)Alloc(sizeof(slists)); // must be done this way!
    702759      onepoint->Init(elem);
    703       for ( j= 0; j < elem; j++ ) {
    704         if ( !rField_is_long_C() ) {
    705           onepoint->m[j].rtyp=STRING_CMD;
    706           onepoint->m[j].data=(void *)complexToStr((*roots[j])[i],oprec);
    707         } else {
    708           onepoint->m[j].rtyp=NUMBER_CMD;
    709           onepoint->m[j].data=(void *)nCopy((number)(roots[j]->getRoot(i)));
    710         }
    711         onepoint->m[j].next= NULL;
    712         onepoint->m[j].name= NULL;
     760      for ( j= 0; j < elem; j++ )
     761      {
     762        if ( !rField_is_long_C() )
     763        {
     764          onepoint->m[j].rtyp=STRING_CMD;
     765          onepoint->m[j].data=(void *)complexToStr((*roots[j])[i],oprec);
     766        }
     767        else
     768        {
     769          onepoint->m[j].rtyp=NUMBER_CMD;
     770          onepoint->m[j].data=(void *)nCopy((number)(roots[j]->getRoot(i)));
     771        }
     772        onepoint->m[j].next= NULL;
     773        onepoint->m[j].name= NULL;
    713774      }
    714775      listofroots->m[i].rtyp=LIST_CMD;
     
    718779    }
    719780
    720   } else {
     781  }
     782  else
     783  {
    721784    listofroots->Init( 0 );
    722785  }
     
    743806  int i,ip,ir,is,k,kh,kp,m12,nl1,nl2;
    744807  int *l1,*l2,*l3;
    745   mprfloat q1, bmax;
    746 
    747   if ( m != (m1+m2+m3)) {
     808  mprfloat q1, bmax;
     809
     810  if ( m != (m1+m2+m3))
     811  {
    748812    // error: bad input
    749     error(Werror(" bad input constraint counts in simplex ");)
     813    error(WerrorS(" bad input constraint counts in simplex ");)
    750814    *icase=-2;
    751815    return;
     
    759823  for ( k=1; k<=n; k++ ) l1[k]=izrov[k]=k;
    760824  nl2=m;
    761   for ( i=1; i<=m; i++ ) {
    762     if ( a[i+1][1] < 0.0 ) {
     825  for ( i=1; i<=m; i++ )
     826  {
     827    if ( a[i+1][1] < 0.0 )
     828    {
    763829      // error: bad input
    764       error(Werror(" bad input tableau in simplex ");)
     830      error(WerrorS(" bad input tableau in simplex ");)
    765831      *icase=-2;
    766832      // free mem l1,l2,l3;
     
    775841  for ( i=1; i<=m2; i++) l3[i]= 1;
    776842  ir= 0;
    777   if (m2+m3) {
     843  if (m2+m3)
     844  {
    778845    ir=1;
    779     for ( k=1; k <= (n+1); k++ ) {
     846    for ( k=1; k <= (n+1); k++ )
     847    {
    780848      q1=0.0;
    781849      for ( i=m1+1; i <= m; i++ ) q1+= a[i+1][k];
     
    783851    }
    784852
    785     do {
     853    do
     854    {
    786855      simp1(a,m+1,l1,nl1,0,&kp,&bmax);
    787       if ( bmax <= SIMPLEX_EPS && a[m+2][1] < -SIMPLEX_EPS ) {
    788         *icase= -1; // no solution found
    789         // free mem l1,l2,l3;
    790         Free( (ADDRESS) l3, (m+1) * sizeof(int) );
    791         Free( (ADDRESS) l2, (m+1) * sizeof(int) );
    792         Free( (ADDRESS) l1, (n+1) * sizeof(int) );
    793         return;
    794       } else if ( bmax <= SIMPLEX_EPS && a[m+2][1] <= SIMPLEX_EPS ) {
    795         m12= m1+m2+1;
    796         if ( m12 <= m ) {
    797           for ( ip= m12; ip <= m; ip++ ) {
    798             if ( iposv[ip] == (ip+n) ) {
    799               simp1(a,ip,l1,nl1,1,&kp,&bmax);
    800               if ( fabs(bmax) >= SIMPLEX_EPS)
    801                 goto one;
    802             }
    803           }
    804         }
    805         ir= 0;
    806         --m12;
    807         if ( m1+1 <= m12 )
    808           for ( i=m1+1; i <= m12; i++ )
    809             if ( l3[i-m1] == 1 )
    810               for ( k=1; k <= n+1; k++ )
    811                 a[i+1][k] = -a[i+1][k];
    812         break;
     856      if ( bmax <= SIMPLEX_EPS && a[m+2][1] < -SIMPLEX_EPS )
     857      {
     858        *icase= -1; // no solution found
     859        // free mem l1,l2,l3;
     860        Free( (ADDRESS) l3, (m+1) * sizeof(int) );
     861        Free( (ADDRESS) l2, (m+1) * sizeof(int) );
     862        Free( (ADDRESS) l1, (n+1) * sizeof(int) );
     863        return;
     864      }
     865      else if ( bmax <= SIMPLEX_EPS && a[m+2][1] <= SIMPLEX_EPS )
     866      {
     867        m12= m1+m2+1;
     868        if ( m12 <= m )
     869        {
     870          for ( ip= m12; ip <= m; ip++ )
     871          {
     872            if ( iposv[ip] == (ip+n) )
     873            {
     874              simp1(a,ip,l1,nl1,1,&kp,&bmax);
     875              if ( fabs(bmax) >= SIMPLEX_EPS)
     876                goto one;
     877            }
     878          }
     879        }
     880        ir= 0;
     881        --m12;
     882        if ( m1+1 <= m12 )
     883          for ( i=m1+1; i <= m12; i++ )
     884            if ( l3[i-m1] == 1 )
     885              for ( k=1; k <= n+1; k++ )
     886                a[i+1][k] = -a[i+1][k];
     887        break;
    813888      }
    814889      //#if DEBUG
     
    816891      //#endif
    817892      simp2(a,n,l2,nl2,&ip,kp,&q1);
    818       if ( ip == 0 ) {
    819         *icase = -1; // no solution found
    820         // free mem l1,l2,l3;
    821         Free( (ADDRESS) l3, (m+1) * sizeof(int) );
    822         Free( (ADDRESS) l2, (m+1) * sizeof(int) );
    823         Free( (ADDRESS) l1, (n+1) * sizeof(int) );
    824         return;
     893      if ( ip == 0 )
     894      {
     895        *icase = -1; // no solution found
     896        // free mem l1,l2,l3;
     897        Free( (ADDRESS) l3, (m+1) * sizeof(int) );
     898        Free( (ADDRESS) l2, (m+1) * sizeof(int) );
     899        Free( (ADDRESS) l1, (n+1) * sizeof(int) );
     900        return;
    825901      }
    826902    one: simp3(a,m+1,n,ip,kp);
     
    828904      // print_bmat(a,m+2,n+3);
    829905      // #endif
    830       if ( iposv[ip] >= (n+m1+m2+1)) {
    831         for ( k=1; k<= nl1; k++ )
    832           if ( l1[k] == kp ) break;
    833         --nl1;
    834         for ( is=k; is <= nl1; is++ ) l1[is]= l1[is+1];
    835         ++a[m+2][kp+1];
    836         for ( i= 1; i <= m+2; i++ ) a[i][kp+1] = -a[i][kp+1];
    837       } else {
    838         if ( iposv[ip] >= (n+m1+1) ) {
    839           kh= iposv[ip]-m1-n;
    840           if ( l3[kh] ) {
    841             l3[kh]= 0;
    842             ++a[m+2][kp+1];
    843             for ( i=1; i<= m+2; i++ )
    844               a[i][kp+1] = -a[i][kp+1];
    845           }
    846         }
     906      if ( iposv[ip] >= (n+m1+m2+1))
     907      {
     908        for ( k=1; k<= nl1; k++ )
     909          if ( l1[k] == kp ) break;
     910        --nl1;
     911        for ( is=k; is <= nl1; is++ ) l1[is]= l1[is+1];
     912        ++a[m+2][kp+1];
     913        for ( i= 1; i <= m+2; i++ ) a[i][kp+1] = -a[i][kp+1];
     914      }
     915      else
     916      {
     917        if ( iposv[ip] >= (n+m1+1) )
     918        {
     919          kh= iposv[ip]-m1-n;
     920          if ( l3[kh] )
     921          {
     922            l3[kh]= 0;
     923            ++a[m+2][kp+1];
     924            for ( i=1; i<= m+2; i++ )
     925              a[i][kp+1] = -a[i][kp+1];
     926          }
     927        }
    847928      }
    848929      is= izrov[kp];
     
    852933  }
    853934  /* end of phase 1, have feasible sol, now optimize it */
    854   for (;;) {
     935  loop
     936  {
    855937    // #if DEBUG
    856938    // print_bmat( a, m+1, n+5);
    857939    // #endif
    858940    simp1(a,0,l1,nl1,0,&kp,&bmax);
    859     if (bmax <= /*SIMPLEX_EPS*/0.0) {
     941    if (bmax <= /*SIMPLEX_EPS*/0.0)
     942    {
    860943      *icase=0; // finite solution found
    861944      // free mem l1,l2,l3
     
    866949    }
    867950    simp2(a,n,l2,nl2,&ip,kp,&q1);
    868     if (ip == 0) {
     951    if (ip == 0)
     952    {
    869953      //printf("Unbounded:");
    870954      // #if DEBUG
    871955      //       print_bmat( a, m+1, n+1);
    872956      // #endif
    873       *icase=1;         /* unbounded */
     957      *icase=1;                /* unbounded */
    874958      // free mem
    875959      Free( (ADDRESS) l3, (m+1) * sizeof(int) );
     
    881965    is= izrov[kp];
    882966    izrov[kp]= iposv[ip];
    883     iposv[ip]= is;     
     967    iposv[ip]= is;
    884968  }/*for ;;*/
    885969}
     
    890974  mprfloat test;
    891975
    892   if( nll <= 0) {                       /* init'tion: fixed */
     976  if( nll <= 0)
     977  {                        /* init'tion: fixed */
    893978    *bmax = 0.0;
    894979    return;
     
    896981  *kp=ll[1];
    897982  *bmax=a[mm+1][*kp+1];
    898   for (k=2;k<=nll;k++) {
    899     if (iabf == 0) {
     983  for (k=2;k<=nll;k++)
     984  {
     985    if (iabf == 0)
     986    {
    900987      test=a[mm+1][ll[k]+1]-(*bmax);
    901       if (test > 0.0) {
    902         *bmax=a[mm+1][ll[k]+1];
    903         *kp=ll[k];
    904       }
    905     } else {                    /* abs values: have fixed it */
     988      if (test > 0.0)
     989      {
     990        *bmax=a[mm+1][ll[k]+1];
     991        *kp=ll[k];
     992      }
     993    }
     994    else
     995    {                        /* abs values: have fixed it */
    906996      test=fabs(a[mm+1][ll[k]+1])-fabs(*bmax);
    907       if (test > 0.0) {
    908         *bmax=a[mm+1][ll[k]+1];
    909         *kp=ll[k];
     997      if (test > 0.0)
     998      {
     999        *bmax=a[mm+1][ll[k]+1];
     1000        *kp=ll[k];
    9101001      }
    9111002    }
     
    9191010
    9201011  *ip= 0;
    921   for ( i=1; i <= nl2; i++ ) {
    922     if ( a[l2[i]+1][kp+1] < -SIMPLEX_EPS ) {
     1012  for ( i=1; i <= nl2; i++ )
     1013  {
     1014    if ( a[l2[i]+1][kp+1] < -SIMPLEX_EPS )
     1015    {
    9231016      *q1= -a[l2[i]+1][1] / a[l2[i]+1][kp+1];
    9241017      *ip= l2[i];
    925       for ( i= i+1; i <= nl2; i++ ) {
    926         ii= l2[i];
    927         if (a[ii+1][kp+1] < -SIMPLEX_EPS) {
    928           q= -a[ii+1][1] / a[ii+1][kp+1];
    929           if (q - *q1 < -SIMPLEX_EPS) {
    930             *ip=ii;
    931             *q1=q;
    932           } else if (q - *q1 < SIMPLEX_EPS) {
    933             for ( k=1; k<= n; k++ ) {
    934               qp= -a[*ip+1][k+1]/a[*ip+1][kp+1];
    935               q0= -a[ii+1][k+1]/a[ii+1][kp+1];
    936               if ( q0 != qp ) break;
    937             }
    938             if ( q0 < qp ) *ip= ii;
    939           }
    940         }
     1018      for ( i= i+1; i <= nl2; i++ )
     1019      {
     1020        ii= l2[i];
     1021        if (a[ii+1][kp+1] < -SIMPLEX_EPS)
     1022        {
     1023          q= -a[ii+1][1] / a[ii+1][kp+1];
     1024          if (q - *q1 < -SIMPLEX_EPS)
     1025          {
     1026            *ip=ii;
     1027            *q1=q;
     1028          }
     1029          else if (q - *q1 < SIMPLEX_EPS)
     1030          {
     1031            for ( k=1; k<= n; k++ )
     1032            {
     1033              qp= -a[*ip+1][k+1]/a[*ip+1][kp+1];
     1034              q0= -a[ii+1][k+1]/a[ii+1][kp+1];
     1035              if ( q0 != qp ) break;
     1036            }
     1037            if ( q0 < qp ) *ip= ii;
     1038          }
     1039        }
    9411040      }
    9421041    }
     
    9501049
    9511050  piv= 1.0 / a[ip+1][kp+1];
    952   for ( ii=1; ii <= i1+1; ii++ )
    953     if ( ii -1 != ip ) {
     1051  for ( ii=1; ii <= i1+1; ii++ )
     1052  {
     1053    if ( ii -1 != ip )
     1054    {
    9541055      a[ii][kp+1] *= piv;
    955       for ( kk=1; kk <= k1+1; kk++ ) 
    956         if ( kk-1 != kp )
    957           a[ii][kk] -= a[ip+1][kk] * a[ii][kp+1];
    958     }
    959   for ( kk=1; kk<= k1+1; kk++ )
     1056      for ( kk=1; kk <= k1+1; kk++ )
     1057        if ( kk-1 != kp )
     1058          a[ii][kk] -= a[ip+1][kk] * a[ii][kp+1];
     1059    }
     1060  }
     1061  for ( kk=1; kk<= k1+1; kk++ )
    9601062    if ( kk-1 != kp ) a[ip+1][kk] *= -piv;
    9611063  a[ip+1][kp+1]= piv;
     
    9721074// compile-command-2: "make install" ***
    9731075// End: ***
    974 
    975 
    976 
  • Singular/mpr_numeric.h

    r0f5091 re858e7  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: mpr_numeric.h,v 1.1 1999-06-28 12:48:16 wenk Exp $ */
     6/* $Id: mpr_numeric.h,v 1.2 1999-06-28 16:06:30 Singular Exp $ */
    77
    8 /* 
     8/*
    99* ABSTRACT - multipolynomial resultants - numeric stuff
    10 *            ( root finder, vandermonde system solver, simplex )   
     10*            ( root finder, vandermonde system solver, simplex )
    1111*/
    1212
     
    1717
    1818// define polish mode when finding roots
    19 #define PM_NONE    1 
     19#define PM_NONE    1
    2020#define PM_POLISH  2
    2121#define PM_CORRUPT 3
     
    2929{
    3030public:
    31   vandermonde( const long _cn, const long _n, 
     31  vandermonde( const long _cn, const long _n,
    3232               const long _maxdeg, number *_p, const bool _homog = true );
    3333  ~vandermonde();
    34  
    35   /** Solves the Vandermode linear system 
    36    *    \sum_{i=1}^{n} x_i^k-1 w_i = q_k, k=1,..,n. 
     34
     35  /** Solves the Vandermode linear system
     36   *    \sum_{i=1}^{n} x_i^k-1 w_i = q_k, k=1,..,n.
    3737     * Any computations are done using type number to get high pecision results.
    3838   * @param  q n-tuple of results (right hand of equations)
     
    7171  ~rootContainer();
    7272
    73   void fillContainer( number *_coeffs, number *_ievpoint, 
    74                       const int _var, const int _tdg, 
     73  void fillContainer( number *_coeffs, number *_ievpoint,
     74                      const int _var, const int _tdg,
    7575                      const rootType _rt, const int _anz );
    7676
     
    9898  rootContainer( const rootContainer & v );
    9999
    100   /** Given the degree tdg and the tdg+1 complex coefficients ad[0..tdg] 
     100  /** Given the degree tdg and the tdg+1 complex coefficients ad[0..tdg]
    101101   * (generated from the number coefficients coeffs[0..tdg]) of the polynomial
    102    * this routine successively calls "laguer" and finds all m complex roots in 
     102   * this routine successively calls "laguer" and finds all m complex roots in
    103103   * roots[0..tdg]. The bool var "polish" should be input as "true" if polishing
    104104   * (also by "laguer") is desired, "false" if the roots will be subsequently
     
    114114   */
    115115  void laguer(gmp_complex ** a, int m, gmp_complex * x, int * its);
    116  
     116
    117117  int var;
    118118  int tdg;
     
    123123
    124124  gmp_complex ** theroots;
    125  
     125
    126126  int anz;
    127127  bool found_roots;
     
    130130
    131131//-> class rootArranger
    132 class rootArranger 
     132class rootArranger
    133133{
    134 public: 
    135   rootArranger( rootContainer ** _roots, 
    136                 rootContainer ** _mu, 
     134public:
     135  rootArranger( rootContainer ** _roots,
     136                rootContainer ** _mu,
    137137                const int _howclean = PM_CORRUPT );
    138138  ~rootArranger() {}
     
    170170// compile-command-1: "make installg" ***
    171171// compile-command-2: "make install" ***
    172 // End: ***
    173 
    174 
    175 
     172// End: ***
  • Singular/pcv.cc

    r0f5091 re858e7  
    22*  Computer Algebra System SINGULAR      *
    33*****************************************/
    4 /* $Id: pcv.cc,v 1.25 1999-06-11 17:13:40 mschulze Exp $ */
     4/* $Id: pcv.cc,v 1.26 1999-06-28 16:06:30 Singular Exp $ */
    55/*
    66* ABSTRACT: conversion between polys and coef vectors
     
    4141      l0->m[i].data=pCopy((poly)l1->m[i].data);
    4242      if(i<=l2->nr&&l2->m[i].rtyp==l1->m[i].rtyp)
    43         l0->m[i].data=pAdd(l0->m[i].data,pCopy((poly)l2->m[i].data));
     43        l0->m[i].data=pAdd((poly)l0->m[i].data,pCopy((poly)l2->m[i].data));
    4444    }
    4545    else
     
    231231  {
    232232    k=j;
    233     for(j=0;j<pcvMaxDegree&&pcvIndex[i][j]<=n;j++);
     233    for(j=0; (j<pcvMaxDegree) && (pcvIndex[i][j]<=(unsigned)n); j++);
    234234    j--;
    235235    n-=pcvIndex[i][j];
  • Singular/shortfl.cc

    r0f5091 re858e7  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: shortfl.cc,v 1.8 1999-05-10 15:10:55 Singular Exp $ */
     4/* $Id: shortfl.cc,v 1.9 1999-06-28 16:06:31 Singular Exp $ */
    55
    66/*
     
    339339    if(i>4)
    340340    {
    341       Werror("float overflow");
     341      WerrorS("float overflow");
    342342      return nf(rr).N();
    343343    }
     
    369369  {
    370370    if(j==s)
    371       Werror("float overflow");
     371      WerrorS("float overflow");
    372372    return nf(rr).N();
    373373  }
     
    382382      MPZ_CLEAR(g);
    383383      if(j==s)
    384         Werror("float overflow");
     384        WerrorS("float overflow");
    385385      return nf(rr).N();
    386386    }
Note: See TracChangeset for help on using the changeset viewer.