Ignore:
Timestamp:
Oct 4, 2012, 8:16:12 PM (12 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
20c54056198f825ef62888512342886cf96c82a6
Parents:
9f6cc091f81a4d6c75b4696ae3e84bc53e419051
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-10-04 20:16:12+02:00
git-committer:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-10-05 18:15:05+02:00
Message:
Major Update for Enumerators + Fixes for Algrbraic & Transcendental extensions

General:
chg: cleanup + documentation + additional assumes

Enumerators:
chg: some polish on Enumerators
add: CRecursivePolyCoeffsEnumerator<ConverterPolicy> for recursive treatment of converted coeffs as Enumerators

Coeffs:
chg: use mpz_lcm for readability in nlClearDenominators + cleanup
add: nlClear*NoPositiveLead variants should not make LC positive
chg: all nlClear* are not static in order to be usable from alg / trans exts.
fix: fixed a bug in ndClearContent

AlgExt:
add: nCoeff_is_Q_algext for checking an alg. ext. of Q
add: naClear* for alg. ext. over Q
NOTE: coeffs are polynomials in Q[a] - one should simply consider each of them recursively as a collection of numbers...
NOTE: compute GCDs over Alg. Ext... + gcds of (int.) numbers!?
NOTE: trying to be conform with older Singular: no negative leading coeff. normalization
chg: Alg. Ext: use singclap_*gcd (instead of Frank's gcd-stuff)

p_poly:
add: p_Cleardenom_n/p_Cleardenom also clear content afterwards...
chg: major and minor changes to p_Content/p_Cleardenom_n/p_Cleardenom + cleanup
add: additionally trying to assure positive leading coeff. after p_Content/p_Cleardenom_n(/p_Cleardenom?)
NOTE: which should not be needed as n_ClearDenominators/n_ClearContent are supposed to assure that themselves!
add: more assumes to p_polys.cc
NOTE: massive usage of enumerators form p_* causes problems - only doing that for Q_a()!
NOTE: do -normalization over Q(x...)

TransExt:
add: ntClear* for trans. ext's
fix: correct ntGetDenom/ntGetNumerator (thanks to pSubstPar),
NOTE: no negative denominator out of ntGetNumerator/ntGetDenom!
add: first inefficient ntClearContent/Q  and ntClearDenominators/Q & F_p impl.
NOTE:  careful with the use of nlClear* ! (only over Q!)
add: added ntTest to transext.cc on most in/outs + use ntInit(poly)!

NOTE: trying to fix the monic-poly-gcd problem in ntClearDenominators!
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/polys/ext_fields/algext.cc

    r9f6cc0 rdc79bd  
    4444#include <polys/simpleideals.h>
    4545
     46#include <polys/PolyEnumerator.h>
     47
    4648#ifdef HAVE_FACTORY
     49#include <factory/factory.h>
    4750#include <polys/clapconv.h>
    48 #include <factory/factory.h>
     51#include <polys/clapsing.h>
    4952#endif
    5053
    51 #include "ext_fields/algext.h"
     54   
     55#include <polys/ext_fields/algext.h>
    5256#define TRANSEXT_PRIVATES 1
    53 #include "ext_fields/transext.h"
     57#include <polys/ext_fields/transext.h>
    5458
    5559#ifdef LDEBUG
     
    103107void     naDelete(number *a, const coeffs cf);
    104108void     naCoeffWrite(const coeffs cf, BOOLEAN details);
    105 number   naIntDiv(number a, number b, const coeffs cf);
     109//number   naIntDiv(number a, number b, const coeffs cf);
    106110const char * naRead(const char *s, number *a, const coeffs cf);
    107111
     
    652656  naTest(a); naTest(b);
    653657  if ((a == NULL) && (b == NULL)) WerrorS(nDivBy0);
    654   return (number)p_Gcd((poly)a, (poly)b, naRing);
     658  const ring R = naRing;
     659  return (number) singclap_gcd(p_Copy((poly)a, R), p_Copy((poly)b, R), R);
     660//  return (number)p_Gcd((poly)a, (poly)b, naRing);
    655661}
    656662
     
    660666  if (a == NULL) WerrorS(nDivBy0);
    661667 
    662   poly aFactor = NULL; poly mFactor = NULL;
    663   poly theGcd = p_ExtGcd((poly)a, aFactor, naMinpoly, mFactor, naRing);
     668  poly aFactor = NULL; poly mFactor = NULL; poly theGcd = NULL;
     669// singclap_extgcd!
     670  const BOOLEAN ret = singclap_extgcd ((poly)a, naMinpoly, theGcd, aFactor, mFactor, naRing);
     671
     672  assume( !ret );
     673
     674//  if( ret ) theGcd = p_ExtGcd((poly)a, aFactor, naMinpoly, mFactor, naRing);
    664675 
    665676  naTest((number)theGcd); naTest((number)aFactor); naTest((number)mFactor);
     
    845856}
    846857
    847 static void naClearContent(ICoeffsEnumerator& /*numberCollectionEnumerator*/, number& c, const coeffs cf)
     858
     859static void naClearContent(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
    848860{
    849861  assume(cf != NULL);
    850862  assume(getCoeffType(cf) == ID);
    851   assume(nCoeff_is_Q_a(cf)); // only over Q[a]/m(a), while the default impl. is used over Zp[a]/m(a) !
    852   // all coeffs are given by integers!!!
    853 
    854   c = n_Init(1, cf);
    855   assume(FALSE); // TODO: NOT YET IMPLEMENTED!!!
    856 
    857 //   numberCollectionEnumerator.Reset();
    858 //
    859 //   c = numberCollectionEnumerator.Current();
    860 //
    861 //   n_Normalize(c, r);
    862 //
    863 //   if (!n_IsOne(c, r))
    864 //   {   
    865 //     numberCollectionEnumerator.Current() = n_Init(1, r); // ???
    866 //
    867 //     number inv = n_Invers(c, r);
    868 //
    869 //     while( numberCollectionEnumerator.MoveNext() )
    870 //     {
    871 //       number &n = numberCollectionEnumerator.Current();
    872 //       n_Normalize(n, r); // ?
    873 //       n_InpMult(n, inv, r);
    874 //     }
    875 //
    876 //     n_Delete(&inv, r);
    877 //   }
     863  assume(nCoeff_is_Q_algext(cf)); // only over (Q[a]/m(a)), while the default impl. is used over Zp[a]/m(a) !
     864
     865  const ring   R = cf->extRing;
     866  assume(R != NULL);
     867  const coeffs Q = R->cf;
     868  assume(Q != NULL);
     869  assume(nCoeff_is_Q(Q)); 
     870
     871  numberCollectionEnumerator.Reset();
     872
     873  if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
     874  {
     875    c = n_Init(1, cf);
     876    return;
     877  }
     878
     879  naTest(numberCollectionEnumerator.Current());
     880
     881  // part 1, find a small candidate for gcd
     882  int s1; int s=2147483647; // max. int
     883
     884  const BOOLEAN lc_is_pos=naGreaterZero(numberCollectionEnumerator.Current(),cf);
     885
     886  int normalcount = 0;
     887 
     888  poly cand1, cand;
     889 
     890  do
     891  {
     892    number& n = numberCollectionEnumerator.Current();
     893    naNormalize(n, cf); ++normalcount;
     894
     895    naTest(n);
     896   
     897    cand1 = (poly)n;
     898
     899    s1 = p_Deg(cand1, R); // naSize?
     900    if (s>s1)
     901    {
     902      cand = cand1;
     903      s = s1;
     904    }
     905  } while (numberCollectionEnumerator.MoveNext() );
     906
     907//  assume( nlGreaterZero(cand,cf) ); // cand may be a negative integer!
     908
     909  cand = p_Copy(cand, R);
     910  // part 2: compute gcd(cand,all coeffs)
     911
     912  numberCollectionEnumerator.Reset();
     913
     914  int length = 0;
     915  while (numberCollectionEnumerator.MoveNext() )
     916  {
     917    number& n = numberCollectionEnumerator.Current();
     918    ++length;
     919   
     920    if( (--normalcount) <= 0)
     921      naNormalize(n, cf);
     922   
     923    naTest(n);
     924
     925//    p_InpGcd(cand, (poly)n, R);
     926   
     927    cand = singclap_gcd(cand, p_Copy((poly)n, R), R);
     928
     929//    cand1 = p_Gcd(cand,(poly)n, R); p_Delete(&cand, R); cand = cand1;
     930   
     931    assume( naGreaterZero((number)cand, cf) ); // ???
     932/*
     933    if(p_IsConstant(cand,R))
     934    {
     935      c = cand;
     936
     937      if(!lc_is_pos)
     938      {
     939        // make the leading coeff positive
     940        c = nlNeg(c, cf);
     941        numberCollectionEnumerator.Reset();
     942
     943        while (numberCollectionEnumerator.MoveNext() )
     944        {
     945          number& nn = numberCollectionEnumerator.Current();
     946          nn = nlNeg(nn, cf);
     947        }
     948      }
     949      return;
     950    }
     951*/
     952   
     953  }
     954
     955  // part3: all coeffs = all coeffs / cand
     956  if (!lc_is_pos)
     957    cand = p_Neg(cand, R);
     958
     959  c = (number)cand; naTest(c); 
     960
     961  poly cInverse = (poly)naInvers(c, cf);
     962  assume(cInverse != NULL); // c is non-zero divisor!?
     963
     964 
     965  numberCollectionEnumerator.Reset();
     966
     967
     968  while (numberCollectionEnumerator.MoveNext() )
     969  {
     970    number& n = numberCollectionEnumerator.Current();
     971
     972    assume( length > 0 );
     973
     974    if( --length > 0 )
     975    {
     976      assume( cInverse != NULL );
     977      n = (number) p_Mult_q(p_Copy(cInverse, R), (poly)n, R);
     978    }
     979    else
     980    {
     981      n = (number) p_Mult_q(cInverse, (poly)n, R);
     982      cInverse = NULL;
     983      assume(length == 0);
     984    }
     985   
     986    definiteReduce((poly &)n, naMinpoly, cf);   
     987  }
     988 
     989  assume(length == 0);
     990  assume(cInverse == NULL); //   p_Delete(&cInverse, R);
     991
     992  // Quick and dirty fix for constant content clearing... !?
     993  CRecursivePolyCoeffsEnumerator<NAConverter> itr(numberCollectionEnumerator); // recursively treat the numbers as polys!
     994
     995  number cc;
     996
     997  extern void nlClearContentNoPositiveLead(ICoeffsEnumerator&, number&, const coeffs);
     998
     999  nlClearContentNoPositiveLead(itr, cc, Q); // TODO: get rid of (-LC) normalization!?
     1000
     1001  // over alg. ext. of Q // takes over the input number
     1002  c = (number) p_Mult_nn( (poly)c, cc, R);
     1003//      p_Mult_q(p_NSet(cc, R), , R);
     1004
     1005  n_Delete(&cc, Q);
     1006
     1007  // TODO: the above is not enough! need GCD's of polynomial coeffs...!
     1008/*
     1009  // old and wrong part of p_Content
     1010    if (rField_is_Q_a(r) && !CLEARENUMERATORS) // should not be used anymore if CLEARENUMERATORS is 1
     1011    {
     1012      // we only need special handling for alg. ext.
     1013      if (getCoeffType(r->cf)==n_algExt)
     1014      {
     1015        number hzz = n_Init(1, r->cf->extRing->cf);
     1016        p=ph;
     1017        while (p!=NULL)
     1018        { // each monom: coeff in Q_a
     1019          poly c_n_n=(poly)pGetCoeff(p);
     1020          poly c_n=c_n_n;
     1021          while (c_n!=NULL)
     1022          { // each monom: coeff in Q
     1023            d=n_Lcm(hzz,pGetCoeff(c_n),r->cf->extRing->cf);
     1024            n_Delete(&hzz,r->cf->extRing->cf);
     1025            hzz=d;
     1026            pIter(c_n);
     1027          }
     1028          pIter(p);
     1029        }
     1030        // hzz contains the 1/lcm of all denominators in c_n_n
     1031        h=n_Invers(hzz,r->cf->extRing->cf);
     1032        n_Delete(&hzz,r->cf->extRing->cf);
     1033        n_Normalize(h,r->cf->extRing->cf);
     1034        if(!n_IsOne(h,r->cf->extRing->cf))
     1035        {
     1036          p=ph;
     1037          while (p!=NULL)
     1038          { // each monom: coeff in Q_a
     1039            poly c_n=(poly)pGetCoeff(p);
     1040            while (c_n!=NULL)
     1041            { // each monom: coeff in Q
     1042              d=n_Mult(h,pGetCoeff(c_n),r->cf->extRing->cf);
     1043              n_Normalize(d,r->cf->extRing->cf);
     1044              n_Delete(&pGetCoeff(c_n),r->cf->extRing->cf);
     1045              pGetCoeff(c_n)=d;
     1046              pIter(c_n);
     1047            }
     1048            pIter(p);
     1049          }
     1050        }
     1051        n_Delete(&h,r->cf->extRing->cf);
     1052      }
     1053    }
     1054*/ 
     1055
     1056 
     1057//  c = n_Init(1, cf); assume(FALSE); // TODO: NOT YET IMPLEMENTED!!!
     1058}
     1059
     1060
     1061static void naClearDenominators(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
     1062{
     1063  assume(cf != NULL);
     1064  assume(getCoeffType(cf) == ID);
     1065  assume(nCoeff_is_Q_algext(cf)); // only over (Q[a]/m(a)), while the default impl. is used over Zp[a]/m(a) !
     1066
     1067  assume(cf->extRing != NULL);
     1068  const coeffs Q = cf->extRing->cf;
     1069  assume(Q != NULL);
     1070  assume(nCoeff_is_Q(Q)); 
     1071  number n;
     1072  CRecursivePolyCoeffsEnumerator<NAConverter> itr(numberCollectionEnumerator); // recursively treat the numbers as polys!
     1073
     1074  extern void nlClearDenominatorsNoPositiveLead(ICoeffsEnumerator&, number&, const coeffs);
     1075
     1076  nlClearDenominatorsNoPositiveLead(itr, n, Q); // this should probably be fine...
     1077  c = (number)p_NSet(n, cf->extRing); // over alg. ext. of Q // takes over the input number
    8781078}
    8791079
     
    9511151  cf->nCoeffIsEqual  = naCoeffIsEqual;
    9521152  cf->cfInvers       = naInvers;
    953   cf->cfIntDiv       = naDiv;
     1153  cf->cfIntDiv       = naDiv; // ???
    9541154#ifdef HAVE_FACTORY
    9551155  cf->convFactoryNSingN=naConvFactoryNSingN;
     
    9631163
    9641164  if( nCoeff_is_Q(R->cf) )
     1165  {
    9651166    cf->cfClearContent = naClearContent;
     1167    cf->cfClearDenominators = naClearDenominators;
     1168  }
    9661169 
    9671170  return FALSE;
Note: See TracChangeset for help on using the changeset viewer.