Changeset 98474f in git


Ignore:
Timestamp:
Jul 17, 2012, 9:09:26 PM (10 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '96ce329119711a2b80858c8365abd29f8460bbfa')
Children:
975db1808b2b0917d858a9096710abc55c256aec
Parents:
805d0b10ffd62e7ff079f116851129cc4ae8f89d
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-07-17 21:09:26+02:00
git-committer:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-07-17 21:33:55+02:00
Message:
Abstract iterator/enumerator interfaces + dummies for ClearContent and ClearDenominators
Location:
libpolys/coeffs
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/Makefile.am

    r805d0b1 r98474f  
    3535libcoeffs_includedir  =$(includedir)/singular/coeffs
    3636libcoeffs_include_HEADERS = coeffs.h numbers.h si_gmp.h gnumpc.h gnumpfl.h longrat.h modulop.h ffields.h rintegers.h rmodulo2m.h rmodulon.h shortfl.h mpr_complex.h mpr_global.h \
    37   bigintmat.h
     37  bigintmat.h Enumerator.h
    3838
    3939
  • libpolys/coeffs/coeffs.h

    r805d0b1 r98474f  
    1313
    1414#include <coeffs/si_gmp.h>
     15
     16#include <coeffs/Enumerator.h>
    1517
    1618#ifdef HAVE_FACTORY
     
    6466typedef number (*nMapFunc)(number a, const coeffs src, const coeffs dst);
    6567
     68
     69/// Abstract interface for an enumerator of number coefficients for an
     70/// object, e.g. a polynomial
     71typedef IEnumerator<number> ICoeffsEnumerator;
     72
     73/// goes over coeffs given by the ICoeffsEnumerator and changes them.
     74/// Additionally returns a number;
     75typedef void (*nCoeffsEnumeratorFunc)(ICoeffsEnumerator& numberCollectionEnumerator, number& output, const coeffs r);
     76
     77
    6678/// Creation data needed for finite fields
    6779typedef struct
     
    196208   /// create i^th parameter or NULL if not possible
    197209   number  (*cfParameter)(const int i, const coeffs r);
     210       
     211   /// function pointer behind n_ClearContent
     212   nCoeffsEnumeratorFunc cfClearContent;
     213
     214   /// function pointer behind n_ClearDenominators
     215   nCoeffsEnumeratorFunc cfClearDenominators;
    198216
    199217#ifdef HAVE_FACTORY
     
    793811
    794812
    795 #endif
    796 
     813/// Computes the content and (inplace) divides it out on a collection
     814/// of numbers
     815/// NOTE/TODO: see the description by Hans
     816/// TODO: what exactly is c?
     817static inline void n_ClearContent(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs r)
     818{
     819  assume(r != NULL);
     820  r->cfClearContent(numberCollectionEnumerator, c, r);
     821}
     822
     823/// (inplace) Clears denominators on a collection of numbers
     824/// NOTE/TODO: see the description by Hans
     825/// TODO: what exactly is d?
     826static inline void n_ClearDenominators(ICoeffsEnumerator& numberCollectionEnumerator, number& d, const coeffs r)
     827{
     828  assume(r != NULL);
     829  r->cfClearDenominators(numberCollectionEnumerator, d, r);
     830}
     831
     832// convenience helpers (no number returned - but the input enumeration
     833// is to be changed
     834// TODO: do we need separate hooks for these as our existing code does
     835// *different things* there: compare p_Cleardenom (which calls
     836// *p_Content) and p_Cleardenom_n (which doesn't)!!!
     837
     838static inline void n_ClearContent(ICoeffsEnumerator& numberCollectionEnumerator, const coeffs r)
     839{
     840  number c;
     841  n_ClearContent(numberCollectionEnumerator, c, r);
     842  n_Delete(&c, r);
     843}
     844
     845static inline void n_ClearDenominators(ICoeffsEnumerator& numberCollectionEnumerator, const coeffs r)
     846{
     847  assume(r != NULL);
     848  number d;
     849  n_ClearDenominators(numberCollectionEnumerator, d, r);
     850  n_Delete(&d, r);
     851}
     852
     853
     854#endif
     855
  • libpolys/coeffs/numbers.cc

    r805d0b1 r98474f  
    123123
    124124int ndSize(number a, const coeffs r) { return (int)n_IsZero(a,r)==FALSE; }
     125
     126/// divide by the first (leading) number and return it, i.e. make monic
     127static void ndClearContent(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs r)
     128{
     129  assume(r != NULL);
     130
     131  // no fractions
     132  assume(!(  nCoeff_is_Q(r) || nCoeff_is_Q_a(r) ));
     133  // all coeffs are given by integers!!!
     134  assume( nCoeff_is_Ring(r) || nCoeff_is_Zp(r) || nCoeff_is_numeric(r) || nCoeff_is_GF(r) || nCoeff_is_Zp_a(r) );
     135
     136  numberCollectionEnumerator.Reset();
     137 
     138#ifdef HAVE_RINGS
     139  /// TODO: move to a separate implementation
     140  if (nCoeff_is_Ring(r))
     141  {
     142    if (nCoeff_has_Units(r))
     143    {
     144      c = n_GetUnit(numberCollectionEnumerator.Current(), r);
     145     
     146      if (!n_IsOne(c, r))
     147      {
     148        number inv = n_Invers(c, r);
     149
     150        do
     151        {
     152          n_InpMult(numberCollectionEnumerator.Current(), inv, r);
     153        }
     154        while( numberCollectionEnumerator.MoveNext() );
     155
     156        n_Delete(&inv, r);       
     157      }     
     158    } else c = n_Init(1, r);
     159   
     160    return;
     161  }
     162#endif
     163
     164  assume(!nCoeff_is_Ring(r));
     165
     166  c = numberCollectionEnumerator.Current();
     167 
     168  n_Normalize(c, r);
     169
     170  if (!n_IsOne(c, r))
     171  {   
     172    numberCollectionEnumerator.Current() = n_Init(1, r); // ???
     173   
     174    number inv = n_Invers(c, r);
     175   
     176    while( numberCollectionEnumerator.MoveNext() )
     177    {
     178      number &n = numberCollectionEnumerator.Current();
     179      n_Normalize(n, r); // ?
     180      n_InpMult(n, inv, r);
     181    }
     182   
     183    n_Delete(&inv, r);
     184  }
     185}
     186
     187/// does nothing (just returns a dummy one number)
     188static void ndClearDenominators(ICoeffsEnumerator& /*numberCollectionEnumerator*/, number& d, const coeffs r)
     189{
     190  assume( r != NULL );
     191  assume( !(nCoeff_is_Q(r) || nCoeff_is_transExt(r)) );
     192  assume( nCoeff_is_Ring(r) || nCoeff_is_Zp(r) || nCoeff_is_numeric(r) || nCoeff_is_GF(r) || (getCoeffType(r)==n_algExt) );
     193
     194  d = n_Init(1, r);
     195}
    125196
    126197number ndCopy(number a, const coeffs) { return a; }
     
    262333    n->cfParameter = ndParameter;
    263334
     335    n->cfClearContent = ndClearContent;
     336    n->cfClearDenominators = ndClearDenominators;
     337
    264338#ifdef HAVE_RINGS
    265339    n->cfDivComp = ndDivComp;
     
    352426//    assume(n->cfInit_bigint!=NULL);
    353427    assume(n->cfCoeffWrite != NULL);
     428
     429    assume(n->cfClearContent != NULL);
     430    assume(n->cfClearDenominators != NULL);
     431   
    354432#ifdef LDEBUG
    355433    assume(n->cfDBTest!=NULL);
Note: See TracChangeset for help on using the changeset viewer.