Changeset ef4ae2 in git for factory


Ignore:
Timestamp:
Oct 16, 2020, 2:09:11 PM (4 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
a647f6c6913c43c8b1e4d17f57b29e6c688b05c9
Parents:
5de96dc9e2d1e82cec4f3996f521041242192cf8
Message:
opt: factory (mpz_init, is_imm, moved tests out of loops(addTermList) etc
Location:
factory
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • factory/cf_factory.cc

    r5de96d ref4ae2  
    5858}
    5959
     60#if SIZEOF_LONG == 8
     61InternalCF *
     62CFFactory::basic ( int value )
     63{
     64  switch(currenttype)
     65  {
     66    case IntegerDomain:
     67            return int2imm( value );
     68//     else  if ( currenttype == RationalDomain )
     69//         if ( value >= MINIMMEDIATE && value <= MAXIMMEDIATE )
     70//             return int2imm( value );
     71//         else
     72//             return new InternalRational( value );
     73    case FiniteFieldDomain:
     74        return int2imm_p( ff_norm( value ) );
     75    case GaloisFieldDomain:
     76        return int2imm_gf( gf_int2gf( value ) );
     77    #ifndef HAVE_NTL
     78    case PrimePowerDomain:
     79        return new InternalPrimePower( value );
     80    #endif
     81    default: {
     82        ASSERT( 0, "illegal basic domain!" );
     83        return 0;
     84    }
     85  }
     86}
     87#endif
     88
    6089InternalCF *
    6190CFFactory::basic ( int type, long value )
  • factory/cf_factory.h

    r5de96d ref4ae2  
    3232      currenttype = type;
    3333    };
     34    #if SIZEOF_LONG == 8
     35    static InternalCF * basic ( int value );
     36    #endif
    3437    static InternalCF * basic ( long value );
    3538    static InternalCF * basic ( int type, long value );
  • factory/cf_inline.cc

    r5de96d ref4ae2  
    141141 *
    142142**/
     143#if SIZEOF_LONG == 8
     144CF_INLINE
     145CanonicalForm::CanonicalForm ( const int i )
     146    : value( CFFactory::basic( i ) )
     147#else
    143148CF_INLINE
    144149CanonicalForm::CanonicalForm ( const int i )
    145150    : value( CFFactory::basic( (long)i ) )
     151#endif
    146152{
    147153}
  • factory/fac_multivar.cc

    r5de96d ref4ae2  
    279279          {
    280280            return conv_to_factor_array(CFFactor(arg,1));
    281             //printf("out of primes - switch ot non-NTL\n");
     281            //printf("out of primes - switch to non-NTL\n");
    282282          }
    283283          else if (((i==0)||(i!=prime_number)))
  • factory/gmpext.h

    r5de96d ref4ae2  
    1919mpz_is_imm( const mpz_t mpi )
    2020{
    21     return ( mpz_cmp_si( mpi, MINIMMEDIATE ) >= 0 ) &&
     21  if (mpi->_mp_size==0)
     22    return true;
     23  if ((mpi->_mp_size>1)||(mpi->_mp_size< -1))
     24    return false;
     25  return ( mpz_cmp_si( mpi, MINIMMEDIATE ) >= 0 ) &&
    2226        ( mpz_cmp_si( mpi, MAXIMMEDIATE ) <= 0 );
    2327}
  • factory/int_cf.cc

    r5de96d ref4ae2  
    9191InternalCF::den ()
    9292{
    93     return CFFactory::basic( 1L );
     93    return CFFactory::basic( 1 );
    9494}
    9595
     
    133133{
    134134    ASSERT1( 0, "bgcd() not implemented for class %s", this->classname() );
    135     return CFFactory::basic( 0L );
     135    return CFFactory::basic( 0 );
    136136}
    137137
     
    140140{
    141141    ASSERT1( 0, "bgcd() not implemented for class %s", this->classname() );
    142     return CFFactory::basic( 0L );
     142    return CFFactory::basic( 0 );
    143143}
    144144
     
    151151    ASSERT1( 0, "bextgcd() not implemented for class %s", this->classname() );
    152152    a = 0; b = 0;
    153     return CFFactory::basic( 0L );
     153    return CFFactory::basic( 0 );
    154154}
    155155
     
    159159    ASSERT1( 0, "bextgcd() not implemented for class %s", this->classname() );
    160160    a = 0; b = 0;
    161     return CFFactory::basic( 0L );
     161    return CFFactory::basic( 0 );
    162162}
    163163
  • factory/int_poly.cc

    r5de96d ref4ae2  
    258258    }
    259259    else
    260         return CFFactory::basic( 0L );
     260        return CFFactory::basic( 0 );
    261261}
    262262
     
    280280  }
    281281  else
    282     return CFFactory::basic( 0L );
     282    return CFFactory::basic( 0 );
    283283}
    284284
     
    301301        {
    302302            delete this;
    303             return CFFactory::basic( 0L );
     303            return CFFactory::basic( 0 );
    304304        }
    305305    }
     
    318318        }
    319319        else
    320             return CFFactory::basic( 0L );
     320            return CFFactory::basic( 0 );
    321321
    322322    }
     
    341341        {
    342342            delete this;
    343             return CFFactory::basic( 0L );
     343            return CFFactory::basic( 0 );
    344344        }
    345345    }
     
    358358        }
    359359        else
    360             return CFFactory::basic( 0L );
     360            return CFFactory::basic( 0 );
    361361
    362362    }
     
    385385            {
    386386                delete this;
    387                 return CFFactory::basic(0L);
     387                return CFFactory::basic(0);
    388388            }
    389389            else
    390390            {
    391391                decRefCount();
    392                 return CFFactory::basic(0L);
     392                return CFFactory::basic(0);
    393393            }
    394394        }
     
    448448            {
    449449                delete this;
    450                 return CFFactory::basic(0L);
     450                return CFFactory::basic(0);
    451451            }
    452452            else
    453453            {
    454454                decRefCount();
    455                 return CFFactory::basic(0L);
     455                return CFFactory::basic(0);
    456456            }
    457457        }
     
    563563            firstTerm = 0;
    564564            delete this;
    565             return CFFactory::basic( 0L );
     565            return CFFactory::basic( 0 );
    566566        }
    567567    }
     
    577577        }
    578578        else
    579             return CFFactory::basic( 0L );
     579            return CFFactory::basic( 0 );
    580580    }
    581581}
     
    588588        InternalCF * dummy = aCoeff->tryInvert(M, fail);
    589589        if (fail)
    590           return CFFactory::basic( 0L );
     590          return CFFactory::basic( 0 );
    591591        if (is_imm(dummy)) dummy=this->tryMulsame(dummy, M);
    592592        else dummy = dummy->tryMulsame( this, M);
     
    633633        {
    634634          freeTermList (first);
    635           return CFFactory::basic (0L);
     635          return CFFactory::basic (0);
    636636        }
    637637        newcoeff= reduce (newcoeff, M);
     
    666666            firstTerm = 0;
    667667            delete this;
    668             return CFFactory::basic( 0L );
     668            return CFFactory::basic( 0 );
    669669        }
    670670    }
     
    680680        }
    681681        else
    682             return CFFactory::basic( 0L );
     682            return CFFactory::basic( 0 );
    683683    }
    684684}
     
    696696    {
    697697        if ( deleteObject() ) delete this;
    698         return CFFactory::basic( 0L );
     698        return CFFactory::basic( 0 );
    699699    }
    700700    InternalPoly *aPoly = (InternalPoly*)aCoeff;
     
    743743            firstTerm = 0;
    744744            delete this;
    745             return CFFactory::basic( 0L );
     745            return CFFactory::basic( 0 );
    746746        }
    747747    }
     
    757757        }
    758758        else
    759             return CFFactory::basic( 0L );
     759            return CFFactory::basic( 0 );
    760760    }
    761761}
     
    769769        InternalCF * dummy = acoeff->invert();
    770770        quot = dummy->mulsame( this );
    771         rem = CFFactory::basic( 0L );
     771        rem = CFFactory::basic( 0 );
    772772    }
    773773    else
     
    800800                quot = new InternalPoly( resultfirst, resultlast, var );
    801801        else
    802             quot = CFFactory::basic( 0L );
     802            quot = CFFactory::basic( 0 );
    803803        if ( first )
    804804            if ( first->exp == 0 )
     
    810810                rem = new InternalPoly( first, last, var );
    811811        else
    812             rem = CFFactory::basic( 0L );
     812            rem = CFFactory::basic( 0 );
    813813    }
    814814}
     
    860860                quot = new InternalPoly( resultfirst, resultlast, var );
    861861        else
    862             quot = CFFactory::basic( 0L );
     862            quot = CFFactory::basic( 0 );
    863863        if ( first )
    864864            if ( first->exp == 0 )
     
    870870                rem = new InternalPoly( first, last, var );
    871871        else
    872             rem = CFFactory::basic( 0L );
     872            rem = CFFactory::basic( 0 );
    873873    }
    874874    else
     
    889889         return false;
    890890       quot = dummy->tryMulsame( this, M);
    891        rem = CFFactory::basic( 0L );
     891       rem = CFFactory::basic( 0 );
    892892       if (fail)
    893893         return false;
     
    935935                quot = new InternalPoly( resultfirst, resultlast, var );
    936936        else
    937             quot = CFFactory::basic( 0L );
     937            quot = CFFactory::basic( 0 );
    938938        if ( first )
    939939            if ( first->exp == 0 )
     
    946946                if (first->coeff.isZero())
    947947                {
    948                   rem= CFFactory::basic (0L);
     948                  rem= CFFactory::basic (0);
    949949                  delete first;
    950950                }
     
    953953            }
    954954        else
    955             rem = CFFactory::basic( 0L );
     955            rem = CFFactory::basic( 0 );
    956956    }
    957957    else
     
    11871187        {
    11881188            delete this;
    1189             return CFFactory::basic( 0L );
    1190         }
    1191         else
    1192         {
    1193             decRefCount();
    1194             return CFFactory::basic( 0L );
     1189            return CFFactory::basic( 0 );
     1190        }
     1191        else
     1192        {
     1193            decRefCount();
     1194            return CFFactory::basic( 0 );
    11951195        }
    11961196    }
     
    12011201        if ( getRefCount() <= 1 )
    12021202        {
    1203             mulTermList( firstTerm, c, 0L );
     1203            mulTermList( firstTerm, c, 0 );
    12041204            return this;
    12051205        }
     
    12491249        {
    12501250            delete this;
    1251             return CFFactory::basic( 0L );
    1252         }
    1253         else
    1254         {
    1255             decRefCount();
    1256             return CFFactory::basic( 0L );
     1251            return CFFactory::basic( 0 );
     1252        }
     1253        else
     1254        {
     1255            decRefCount();
     1256            return CFFactory::basic( 0 );
    12571257        }
    12581258    }
     
    12751275            {
    12761276                delete this;
    1277                 return CFFactory::basic( 0L );
     1277                return CFFactory::basic( 0 );
    12781278            }
    12791279        }
     
    12941294            {
    12951295                delete first;
    1296                 return CFFactory::basic( 0L );
     1296                return CFFactory::basic( 0 );
    12971297            }
    12981298        }
     
    13141314          else
    13151315            decRefCount();
    1316           return dummy; //is equal to CFFactory::basic ( 0L ) in this case
     1316          return dummy; //is equal to CFFactory::basic ( 0 ) in this case
    13171317        }
    13181318        if (is_imm(dummy))
     
    13431343        {
    13441344            delete this;
    1345             return CFFactory::basic( 0L );
    1346         }
    1347         else
    1348         {
    1349             decRefCount();
    1350             return CFFactory::basic( 0L );
     1345            return CFFactory::basic( 0 );
     1346        }
     1347        else
     1348        {
     1349            decRefCount();
     1350            return CFFactory::basic( 0 );
    13511351        }
    13521352    }
     
    13701370            {
    13711371                delete this;
    1372                 return CFFactory::basic( 0L );
     1372                return CFFactory::basic( 0 );
    13731373            }
    13741374        }
     
    13891389            {
    13901390                delete first;
    1391                 return CFFactory::basic( 0L );
     1391                return CFFactory::basic( 0 );
    13921392            }
    13931393        }
     
    14211421        {
    14221422            delete this;
    1423             return CFFactory::basic( 0L );
    1424         }
    1425         else
    1426         {
    1427             decRefCount();
    1428             return CFFactory::basic( 0L );
     1423            return CFFactory::basic( 0 );
     1424        }
     1425        else
     1426        {
     1427            decRefCount();
     1428            return CFFactory::basic( 0 );
    14291429        }
    14301430    }
     
    14471447            {
    14481448                delete this;
    1449                 return CFFactory::basic( 0L );
     1449                return CFFactory::basic( 0 );
    14501450            }
    14511451        }
     
    14661466            {
    14671467                delete first;
    1468                 return CFFactory::basic( 0L );
     1468                return CFFactory::basic( 0 );
    14691469            }
    14701470        }
     
    15051505        {
    15061506            delete this;
    1507             return CFFactory::basic( 0L );
    1508         }
    1509         else
    1510         {
    1511             decRefCount();
    1512             return CFFactory::basic( 0L );
     1507            return CFFactory::basic( 0 );
     1508        }
     1509        else
     1510        {
     1511            decRefCount();
     1512            return CFFactory::basic( 0 );
    15131513        }
    15141514    }
     
    15231523            {
    15241524              delete this;
    1525               return CFFactory::basic (0L);
     1525              return CFFactory::basic (0);
    15261526            }
    15271527            if ( firstTerm && firstTerm->exp != 0 )
     
    15361536            {
    15371537                delete this;
    1538                 return CFFactory::basic( 0L );
     1538                return CFFactory::basic( 0 );
    15391539            }
    15401540        }
     
    15471547            {
    15481548              delete this;
    1549               return CFFactory::basic (0L);
     1549              return CFFactory::basic (0);
    15501550            }
    15511551            if (fail)
    15521552            {
    15531553              delete first;
    1554               return CFFactory::basic (0L);
     1554              return CFFactory::basic (0);
    15551555            }
    15561556            if ( first && first->exp != 0 )
     
    15651565            {
    15661566                delete first;
    1567                 return CFFactory::basic( 0L );
     1567                return CFFactory::basic( 0 );
    15681568            }
    15691569        }
     
    15821582    ASSERT( ! c.isZero(), "divide by zero!" );
    15831583    if ( deleteObject() ) delete this;
    1584     return CFFactory::basic( 0L );
     1584    return CFFactory::basic( 0 );
    15851585}
    15861586
     
    16001600        {
    16011601            delete this;
    1602             return CFFactory::basic( 0L );
    1603         }
    1604         else
    1605         {
    1606             decRefCount();
    1607             return CFFactory::basic( 0L );
     1602            return CFFactory::basic( 0 );
     1603        }
     1604        else
     1605        {
     1606            decRefCount();
     1607            return CFFactory::basic( 0 );
    16081608        }
    16091609    }
     
    16241624            {
    16251625                delete this;
    1626                 return CFFactory::basic( 0L );
     1626                return CFFactory::basic( 0 );
    16271627            }
    16281628        }
     
    16431643            {
    16441644                delete first;
    1645                 return CFFactory::basic( 0L );
     1645                return CFFactory::basic( 0 );
    16461646            }
    16471647        }
     
    16561656        quot = copyObject();
    16571657        quot = quot->dividecoeff( cc, invert );
    1658         rem = CFFactory::basic( 0L );
     1658        rem = CFFactory::basic( 0 );
    16591659    }
    16601660    else  if ( invert )
     
    16641664        else
    16651665            rem = cc->copyObject();
    1666         quot = CFFactory::basic( 0L );
     1666        quot = CFFactory::basic( 0 );
    16671667    }
    16681668    else
     
    16811681                quot = new InternalPoly( quotfirst, quotlast, var );
    16821682        else
    1683             quot = CFFactory::basic( 0L );
    1684         rem = CFFactory::basic( 0L );
     1683            quot = CFFactory::basic( 0 );
     1684        rem = CFFactory::basic( 0 );
    16851685    }
    16861686}
     
    16931693        quot = copyObject();
    16941694        quot = quot->dividecoeff( cc, invert );
    1695         rem = CFFactory::basic( 0L );
     1695        rem = CFFactory::basic( 0 );
    16961696        return true;
    16971697    }
     
    17021702        else
    17031703            rem = cc->copyObject();
    1704         quot = CFFactory::basic( 0L );
     1704        quot = CFFactory::basic( 0 );
    17051705        return true;
    17061706    }
     
    17421742                quot = new InternalPoly( quotfirst, quotcursor, var );
    17431743        else
    1744             quot = CFFactory::basic( 0L );
    1745         rem = CFFactory::basic( 0L );
     1744            quot = CFFactory::basic( 0 );
     1745        rem = CFFactory::basic( 0 );
    17461746    }
    17471747    else
     
    17611761        if (fail)
    17621762          return false;
    1763         rem = CFFactory::basic( 0L );
     1763        rem = CFFactory::basic( 0 );
    17641764        return true;
    17651765    }
     
    17701770        else
    17711771            rem = cc->copyObject();
    1772         quot = CFFactory::basic( 0L );
     1772        quot = CFFactory::basic( 0 );
    17731773        return true;
    17741774    }
     
    18151815                quot = new InternalPoly( quotfirst, quotcursor, var );
    18161816        else
    1817             quot = CFFactory::basic( 0L );
    1818         rem = CFFactory::basic( 0L );
     1817            quot = CFFactory::basic( 0 );
     1818        rem = CFFactory::basic( 0 );
    18191819    }
    18201820    else
     
    18301830InternalPoly::copyTermList ( termList aTermList, termList& theLastTerm, bool negate )
    18311831{
    1832     if ( aTermList == 0 )
     1832    if ( UNLIKELY(aTermList == 0) )
    18331833        return 0;
    18341834    else  if ( negate )
     
    18381838        termList targetCursor = dummy;
    18391839
    1840         while ( sourceCursor )
     1840        while ( LIKELY(sourceCursor) )
    18411841        {
    18421842            targetCursor->next = new term( 0, -sourceCursor->coeff, sourceCursor->exp );
     
    18561856        termList targetCursor = dummy;
    18571857
    1858         while ( sourceCursor )
     1858        while ( LIKELY(sourceCursor) )
    18591859        {
    18601860            targetCursor->next = new term( 0, sourceCursor->coeff, sourceCursor->exp );
     
    19001900    termList cursor = aTermList;
    19011901
    1902     while ( cursor )
     1902    while ( LIKELY(cursor) )
    19031903    {
    19041904        cursor = cursor->next;
     
    19121912{
    19131913    termList cursor = terms;
    1914     while ( cursor )
     1914    while ( LIKELY(cursor) )
    19151915    {
    19161916        cursor->coeff = -cursor->coeff;
     
    19261926    termList predCursor = 0;
    19271927
    1928     while ( theCursor && aCursor )
    1929     {
     1928    if (negate)
     1929      while ( theCursor && aCursor )
     1930      {
    19301931        if ( theCursor->exp == aCursor->exp )
    19311932        {
    1932             if ( negate )
    1933                 theCursor->coeff -= aCursor->coeff;
    1934             else
    1935                 theCursor->coeff += aCursor->coeff;
     1933            theCursor->coeff -= aCursor->coeff;
    19361934            if ( theCursor->coeff.isZero() )
    19371935            {
     
    19581956        else if ( theCursor->exp < aCursor->exp )
    19591957        {
    1960             if ( negate )
    1961                 if ( predCursor )
    1962                 {
    1963                     predCursor->next = new term( theCursor, -aCursor->coeff, aCursor->exp );
    1964                     predCursor = predCursor->next;
    1965                 }
    1966                 else
    1967                 {
    1968                     theList = new term( theCursor, -aCursor->coeff, aCursor->exp );
    1969                     predCursor = theList;
    1970                 }
    1971             else
    1972                 if ( predCursor )
    1973                 {
    1974                     predCursor->next = new term( theCursor, aCursor->coeff, aCursor->exp );
    1975                     predCursor = predCursor->next;
    1976                 }
    1977                 else
    1978                 {
    1979                     theList = new term( theCursor, aCursor->coeff, aCursor->exp );
    1980                     predCursor = theList;
    1981                 }
     1958            if ( predCursor )
     1959            {
     1960                predCursor->next = new term( theCursor, -aCursor->coeff, aCursor->exp );
     1961                predCursor = predCursor->next;
     1962            }
     1963            else
     1964            {
     1965                theList = new term( theCursor, -aCursor->coeff, aCursor->exp );
     1966                predCursor = theList;
     1967            }
    19821968            aCursor = aCursor->next;
    19831969        }
     
    19871973            theCursor = theCursor->next;
    19881974        }
    1989     }
    1990     if ( aCursor )
    1991     {
    1992         if ( predCursor )
    1993             predCursor->next = copyTermList( aCursor, lastTerm, negate );
    1994         else
    1995             theList = copyTermList( aCursor, lastTerm, negate );
    1996     }
    1997     else if ( ! theCursor )
    1998         lastTerm = predCursor;
    1999 
    2000     return theList;
    2001 }
    2002 
    2003 void
    2004 InternalPoly::mulTermList ( termList theCursor, const CanonicalForm& coeff, const int exp )
    2005 {
    2006     while ( theCursor )
    2007     {
    2008         theCursor->coeff *= coeff;
    2009         theCursor->exp += exp;
    2010         theCursor = theCursor->next;
    2011     }
    2012 }
    2013 
    2014 termList
    2015 InternalPoly::divideTermList ( termList firstTerm, const CanonicalForm& coeff, termList& lastTerm )
    2016 {
    2017     termList theCursor = firstTerm;
    2018     lastTerm = 0;
    2019     termList dummy;
    2020 
    2021     while ( theCursor )
    2022     {
    2023         theCursor->coeff /= coeff;
    2024         if ( theCursor->coeff.isZero() )
    2025         {
    2026             if ( theCursor == firstTerm )
    2027                 firstTerm = theCursor->next;
    2028             else
    2029                 lastTerm->next = theCursor->next;
    2030             dummy = theCursor;
    2031             theCursor = theCursor->next;
    2032             delete dummy;
    2033         }
    2034         else
    2035         {
    2036             lastTerm = theCursor;
    2037             theCursor = theCursor->next;
    2038         }
    2039     }
    2040     return firstTerm;
    2041 }
    2042 
    2043 termList
    2044 InternalPoly::divTermList ( termList firstTerm, const CanonicalForm& coeff, termList& lastTerm )
    2045 {
    2046     termList theCursor = firstTerm;
    2047     lastTerm = 0;
    2048     termList dummy;
    2049 
    2050     while ( theCursor )
    2051     {
    2052         theCursor->coeff.div( coeff );
    2053         if ( theCursor->coeff.isZero() )
    2054         {
    2055             if ( theCursor == firstTerm )
    2056                 firstTerm = theCursor->next;
    2057             else
    2058                 lastTerm->next = theCursor->next;
    2059             dummy = theCursor;
    2060             theCursor = theCursor->next;
    2061             delete dummy;
    2062         }
    2063         else
    2064         {
    2065             lastTerm = theCursor;
    2066             theCursor = theCursor->next;
    2067         }
    2068     }
    2069     return firstTerm;
    2070 }
    2071 
    2072 termList
    2073 InternalPoly::tryDivTermList ( termList firstTerm, const CanonicalForm& coeff, termList& lastTerm, const CanonicalForm& M, bool& fail )
    2074 {
    2075     termList theCursor = firstTerm;
    2076     lastTerm = 0;
    2077     termList dummy;
    2078 
    2079     while ( theCursor )
    2080     {
    2081         theCursor->coeff.tryDiv( coeff, M, fail );
    2082         if (fail)
    2083           return 0;
    2084         if ( theCursor->coeff.isZero() )
    2085         {
    2086             if ( theCursor == firstTerm )
    2087                 firstTerm = theCursor->next;
    2088             else
    2089                 lastTerm->next = theCursor->next;
    2090             dummy = theCursor;
    2091             theCursor = theCursor->next;
    2092             delete dummy;
    2093         }
    2094         else
    2095         {
    2096             lastTerm = theCursor;
    2097             theCursor = theCursor->next;
    2098         }
    2099     }
    2100     return firstTerm;
    2101 }
    2102 
    2103 termList
    2104 InternalPoly::modTermList ( termList firstTerm, const CanonicalForm& coeff, termList& lastTerm )
    2105 {
    2106     termList theCursor = firstTerm;
    2107     lastTerm = 0;
    2108     termList dummy;
    2109 
    2110     while ( theCursor )
    2111     {
    2112         theCursor->coeff.mod( coeff );
    2113         if ( theCursor->coeff.isZero() )
    2114         {
    2115             if ( theCursor == firstTerm )
    2116                 firstTerm = theCursor->next;
    2117             else
    2118                 lastTerm->next = theCursor->next;
    2119             dummy = theCursor;
    2120             theCursor = theCursor-> next;
    2121             delete dummy;
    2122         }
    2123         else
    2124         {
    2125             lastTerm = theCursor;
    2126             theCursor = theCursor->next;
    2127         }
    2128     }
    2129     return firstTerm;
    2130 }
    2131 
    2132 void
    2133 InternalPoly::appendTermList ( termList& first, termList& last, const CanonicalForm& coeff, const int exp )
    2134 {
    2135     if ( last )
    2136     {
    2137         last->next = new term( 0, coeff, exp );
    2138         last = last->next;
    2139     }
    2140     else
    2141     {
    2142         first = new term( 0, coeff, exp );
    2143         last = first;
    2144     }
    2145 }
    2146 
    2147 termList
    2148 InternalPoly::mulAddTermList ( termList theList, termList aList, const CanonicalForm & c, const int exp, termList & lastTerm, bool negate )
    2149 {
    2150     termList theCursor = theList;
    2151     termList aCursor = aList;
    2152     termList predCursor = 0;
    2153     CanonicalForm coeff;
    2154 
    2155     if ( negate )
    2156         coeff = -c;
    2157     else
    2158         coeff = c;
    2159 
     1975      }
     1976    else
    21601977    while ( theCursor && aCursor )
    21611978    {
    2162         if ( theCursor->exp == aCursor->exp + exp )
    2163         {
    2164             theCursor->coeff += aCursor->coeff * coeff;
    2165             if(UNLIKELY(( theCursor->coeff.isZero() )))
     1979        if ( theCursor->exp == aCursor->exp )
     1980        {
     1981            theCursor->coeff += aCursor->coeff;
     1982            if ( theCursor->coeff.isZero() )
    21661983            {
    21671984                if ( predCursor )
     
    21852002            aCursor = aCursor->next;
    21862003        }
     2004        else if ( theCursor->exp < aCursor->exp )
     2005        {
     2006            if ( predCursor )
     2007            {
     2008                predCursor->next = new term( theCursor, aCursor->coeff, aCursor->exp );
     2009                predCursor = predCursor->next;
     2010            }
     2011            else
     2012            {
     2013                theList = new term( theCursor, aCursor->coeff, aCursor->exp );
     2014                predCursor = theList;
     2015            }
     2016            aCursor = aCursor->next;
     2017        }
     2018        else
     2019        {
     2020            predCursor = theCursor;
     2021            theCursor = theCursor->next;
     2022        }
     2023    }
     2024    if ( aCursor )
     2025    {
     2026        if ( predCursor )
     2027            predCursor->next = copyTermList( aCursor, lastTerm, negate );
     2028        else
     2029            theList = copyTermList( aCursor, lastTerm, negate );
     2030    }
     2031    else if ( ! theCursor )
     2032        lastTerm = predCursor;
     2033
     2034    return theList;
     2035}
     2036
     2037void
     2038InternalPoly::mulTermList ( termList theCursor, const CanonicalForm& coeff, const int exp )
     2039{
     2040    while ( LIKELY(theCursor) )
     2041    {
     2042        theCursor->coeff *= coeff;
     2043        theCursor->exp += exp;
     2044        theCursor = theCursor->next;
     2045    }
     2046}
     2047
     2048termList
     2049InternalPoly::divideTermList ( termList firstTerm, const CanonicalForm& coeff, termList& lastTerm )
     2050{
     2051    termList theCursor = firstTerm;
     2052    lastTerm = 0;
     2053    termList dummy;
     2054
     2055    while ( LIKELY(theCursor) )
     2056    {
     2057        theCursor->coeff /= coeff;
     2058        if ( theCursor->coeff.isZero() )
     2059        {
     2060            if ( theCursor == firstTerm )
     2061                firstTerm = theCursor->next;
     2062            else
     2063                lastTerm->next = theCursor->next;
     2064            dummy = theCursor;
     2065            theCursor = theCursor->next;
     2066            delete dummy;
     2067        }
     2068        else
     2069        {
     2070            lastTerm = theCursor;
     2071            theCursor = theCursor->next;
     2072        }
     2073    }
     2074    return firstTerm;
     2075}
     2076
     2077termList
     2078InternalPoly::divTermList ( termList firstTerm, const CanonicalForm& coeff, termList& lastTerm )
     2079{
     2080    termList theCursor = firstTerm;
     2081    lastTerm = 0;
     2082    termList dummy;
     2083
     2084    while ( LIKELY(theCursor) )
     2085    {
     2086        theCursor->coeff.div( coeff );
     2087        if ( theCursor->coeff.isZero() )
     2088        {
     2089            if ( theCursor == firstTerm )
     2090                firstTerm = theCursor->next;
     2091            else
     2092                lastTerm->next = theCursor->next;
     2093            dummy = theCursor;
     2094            theCursor = theCursor->next;
     2095            delete dummy;
     2096        }
     2097        else
     2098        {
     2099            lastTerm = theCursor;
     2100            theCursor = theCursor->next;
     2101        }
     2102    }
     2103    return firstTerm;
     2104}
     2105
     2106termList
     2107InternalPoly::tryDivTermList ( termList firstTerm, const CanonicalForm& coeff, termList& lastTerm, const CanonicalForm& M, bool& fail )
     2108{
     2109    termList theCursor = firstTerm;
     2110    lastTerm = 0;
     2111    termList dummy;
     2112
     2113    while ( theCursor )
     2114    {
     2115        theCursor->coeff.tryDiv( coeff, M, fail );
     2116        if (fail)
     2117          return 0;
     2118        if ( theCursor->coeff.isZero() )
     2119        {
     2120            if ( theCursor == firstTerm )
     2121                firstTerm = theCursor->next;
     2122            else
     2123                lastTerm->next = theCursor->next;
     2124            dummy = theCursor;
     2125            theCursor = theCursor->next;
     2126            delete dummy;
     2127        }
     2128        else
     2129        {
     2130            lastTerm = theCursor;
     2131            theCursor = theCursor->next;
     2132        }
     2133    }
     2134    return firstTerm;
     2135}
     2136
     2137termList
     2138InternalPoly::modTermList ( termList firstTerm, const CanonicalForm& coeff, termList& lastTerm )
     2139{
     2140    termList theCursor = firstTerm;
     2141    lastTerm = 0;
     2142    termList dummy;
     2143
     2144    while ( theCursor )
     2145    {
     2146        theCursor->coeff.mod( coeff );
     2147        if ( theCursor->coeff.isZero() )
     2148        {
     2149            if ( theCursor == firstTerm )
     2150                firstTerm = theCursor->next;
     2151            else
     2152                lastTerm->next = theCursor->next;
     2153            dummy = theCursor;
     2154            theCursor = theCursor-> next;
     2155            delete dummy;
     2156        }
     2157        else
     2158        {
     2159            lastTerm = theCursor;
     2160            theCursor = theCursor->next;
     2161        }
     2162    }
     2163    return firstTerm;
     2164}
     2165
     2166void
     2167InternalPoly::appendTermList ( termList& first, termList& last, const CanonicalForm& coeff, const int exp )
     2168{
     2169    if ( last )
     2170    {
     2171        last->next = new term( 0, coeff, exp );
     2172        last = last->next;
     2173    }
     2174    else
     2175    {
     2176        first = new term( 0, coeff, exp );
     2177        last = first;
     2178    }
     2179}
     2180
     2181termList
     2182InternalPoly::mulAddTermList ( termList theList, termList aList, const CanonicalForm & c, const int exp, termList & lastTerm, bool negate )
     2183{
     2184    termList theCursor = theList;
     2185    termList aCursor = aList;
     2186    termList predCursor = 0;
     2187    CanonicalForm coeff;
     2188
     2189    if ( negate )
     2190        coeff = -c;
     2191    else
     2192        coeff = c;
     2193
     2194    while ( theCursor && aCursor )
     2195    {
     2196        if ( theCursor->exp == aCursor->exp + exp )
     2197        {
     2198            theCursor->coeff += aCursor->coeff * coeff;
     2199            if(UNLIKELY(( theCursor->coeff.isZero() )))
     2200            {
     2201                if ( predCursor )
     2202                {
     2203                    predCursor->next = theCursor->next;
     2204                    delete theCursor;
     2205                    theCursor = predCursor->next;
     2206                }
     2207                else
     2208                {
     2209                    theList = theList->next;
     2210                    delete theCursor;
     2211                    theCursor = theList;
     2212                }
     2213            }
     2214            else
     2215            {
     2216                predCursor = theCursor;
     2217                theCursor = theCursor->next;
     2218            }
     2219            aCursor = aCursor->next;
     2220        }
    21872221        else if ( theCursor->exp < aCursor->exp + exp )
    21882222        {
  • factory/int_pp.cc

    r5de96d ref4ae2  
    242242    if ( c == this ) {
    243243        if ( deleteObject() ) delete this;
    244         return CFFactory::basic( 1L );
     244        return CFFactory::basic( 1 );
    245245    }
    246246    if ( getRefCount() > 1 ) {
     
    275275{
    276276    if ( deleteObject() ) delete this;
    277     return CFFactory::basic( 0L );
     277    return CFFactory::basic( 0 );
    278278}
    279279
     
    282282{
    283283    if ( deleteObject() ) delete this;
    284     return CFFactory::basic( 0L );
     284    return CFFactory::basic( 0 );
    285285}
    286286
     
    289289{
    290290    if ( c == this ) {
    291         quot = CFFactory::basic( 1L );
    292         rem = CFFactory::basic( 0L );
     291        quot = CFFactory::basic( 1 );
     292        rem = CFFactory::basic( 0 );
    293293    }
    294294    else {
     
    303303        mpz_mod( b, b, primepow );
    304304        quot = new InternalPrimePower( b );
    305         rem = CFFactory::basic( 0L );
     305        rem = CFFactory::basic( 0 );
    306306    }
    307307}
  • factory/int_rat.cc

    r5de96d ref4ae2  
    413413    {
    414414        if ( deleteObject() ) delete this;
    415         return CFFactory::basic( 1L );
     415        return CFFactory::basic( 1 );
    416416    }
    417417    else
     
    484484{
    485485    if ( deleteObject() ) delete this;
    486     return CFFactory::basic( 0L );
     486    return CFFactory::basic( 0 );
    487487}
    488488
     
    491491    quot = copyObject();
    492492    quot = quot->dividesame( c );
    493     rem = CFFactory::basic( 0L );
     493    rem = CFFactory::basic( 0 );
    494494}
    495495
     
    662662        {
    663663            if ( deleteObject() ) delete this;
    664             return CFFactory::basic( 0L );
     664            return CFFactory::basic( 0 );
    665665        }
    666666        mpz_init_set_si( n, cc );
     
    717717            // => invert
    718718            if ( deleteObject() ) delete this;
    719             return CFFactory::basic( 0L );
     719            return CFFactory::basic( 0 );
    720720        }
    721721        if ( invert )
     
    800800    ASSERT( invert || ! ::is_imm( c ) || imm2int( c ) != 0, "divide by zero" );
    801801    if ( deleteObject() ) delete this;
    802     return CFFactory::basic( 0L );
     802    return CFFactory::basic( 0 );
    803803}
    804804
     
    807807    quot = copyObject();
    808808    quot = quot->dividecoeff( c, invert );
    809     rem = CFFactory::basic( 0L );
     809    rem = CFFactory::basic( 0 );
    810810}
    811811
Note: See TracChangeset for help on using the changeset viewer.