Changeset 14db39 in git


Ignore:
Timestamp:
Feb 25, 2009, 6:01:00 PM (14 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
Children:
69331f48332cdfe97f62b18b3118309f9af63ebc
Parents:
f613e4443242d8477485c8b2be97c6c460e33578
Message:
*hannes: pConentRat


git-svn-id: file:///usr/local/Singular/svn/trunk@11468 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/ratgring.cc

    rf613e44 r14db39  
    77 *  Author:  levandov (Viktor Levandovsky)
    88 *  Created: 8/00 - 11/00
    9  *  Version: $Id: ratgring.cc,v 1.16 2009-02-25 16:37:34 levandov Exp $
     9 *  Version: $Id: ratgring.cc,v 1.17 2009-02-25 17:01:00 Singular Exp $
    1010 *******************************************************************/
    1111#include "mod2.h"
     
    687687}
    688688
    689 poly pInitContentRat_a(poly ph)
     689poly pContentRat(poly ph)
     690// destroys ph
    690691// for rat coefficients in K(x1,..xN)
    691692{
     
    694695  //  poly p_GetCoeffRat(poly p, int ishift, ring r);
    695696
    696   poly *C = (poly *)omAlloc0((pLength(ph)+1)*sizeof(poly));  //rat coeffs
    697   poly *LM = (poly *)omAlloc0((pLength(ph)+1)*sizeof(poly));  // rat lead terms
    698   int *D = (int *)omAlloc0((pLength(ph)+1)*sizeof(int));  //degrees of coeffs
    699   int *L = (int *)omAlloc0((pLength(ph)+1)*sizeof(int));  //lengths of coeffs
     697  int len=pLength(ph);
     698  poly *C = (poly *)omAlloc0((len+1)*sizeof(poly));  //rat coeffs
     699  poly *LM = (poly *)omAlloc0((len+1)*sizeof(poly));  // rat lead terms
     700  int *D = (int *)omAlloc0((len+1)*sizeof(int));  //degrees of coeffs
     701  int *L = (int *)omAlloc0((len+1)*sizeof(int));  //lengths of coeffs
    700702  int k = 0;
    701703  poly p = ph;
    702704  int HasConstantCoef = 0;
    703705  int mintdeg = pTotaldegree(p);
    704   int minlen = pLength(p);
     706  int minlen = len;
    705707  while (p!=NULL)
    706708  {
     
    722724
    723725  // look for 1 element of minimal degree and of minimal length
    724   int *DD = (int *)omAlloc0((k+1)*sizeof(int));  //minimal degrees
    725726  k--;
    726727  int dd = 0; int i;
    727   int mindeglen = pLength(p); // expensive?
     728  int mindeglen = len;
    728729  int pmindeglen;
    729730  for(i=0; i<=k; i++)
     
    731732    if (D[i] == mintdeg)
    732733    {
    733       //      DD[dd] = i;
    734       //      dd++;
    735       mindeglen = si_min(mindeglen,L[i]);
    736       if (L[i] == mindeglen)
     734      if (L[i] < mindeglen)
    737735      {
     736        mindeglen=L[i];
    738737        pmindeglen = i;
    739738      }
    740739    }
    741740  }
    742   poly d = C[pmindeglen];
     741  poly d = pCopy(C[pmindeglen]);
    743742  // there are dd>=1 mindeg elements
    744743  // and pmideglen is the coordinate of one of the smallest among them
     
    748747
    749748  // adjoin pContentRat here?
    750 
    751 }
    752 
    753 // void pContentRat(poly ph)
    754 // {
    755 // #ifdef HAVE_RINGS
    756 //   if (rField_is_Ring(currRing))
    757 //   {
    758 //     if ((ph!=NULL) && rField_has_Units(currRing))
    759 //     {
    760 //       number k = nGetUnit(pGetCoeff(ph));
    761 //       if (!nIsOne(k))
    762 //       {
    763 //         number tmpGMP = k;
    764 //         k = nInvers(k);
    765 //         nDelete(&tmpGMP);
    766 //         poly h = pNext(ph);
    767 //         pSetCoeff(ph, nMult(pGetCoeff(ph), k));
    768 //         while (h != NULL)
    769 //         {
    770 //           pSetCoeff(h, nMult(pGetCoeff(h), k));
    771 //           pIter(h);
    772 //         }
    773 //       }
    774 //       nDelete(&k);
    775 //     }
    776 //     return;
    777 //   }
    778 // #endif
    779 //   number h,d;
    780 //   poly p;
    781 
    782 //   if(TEST_OPT_CONTENTSB) return;
    783 //   if(pNext(ph)==NULL)
    784 //   {
    785 //     pSetCoeff(ph,nInit(1));
    786 //   }
    787 //   else
    788 //   {
    789 //     nNormalize(pGetCoeff(ph));
    790 //     if(!nGreaterZero(pGetCoeff(ph))) ph = pNeg(ph);
    791 //     if (rField_is_Q())
    792 //     {
    793 //       h=pInitContent(ph);
    794 //       p=ph;
    795 //     }
    796 //     else if ((rField_is_Extension())
    797 //     && ((rPar(currRing)>1)||(currRing->minpoly==NULL)))
    798 //     {
    799 //       h=pInitContent_a(ph);
    800 //       p=ph;
    801 //     }
    802 //     else
    803 //     {
    804 //       h=nCopy(pGetCoeff(ph));
    805 //       p = pNext(ph);
    806 //     }
    807 //     while (p!=NULL)
    808 //     {
    809 //       nNormalize(pGetCoeff(p));
    810 //       d=nGcd(h,pGetCoeff(p),currRing);
    811 //       nDelete(&h);
    812 //       h = d;
    813 //       if(nIsOne(h))
    814 //       {
    815 //         break;
    816 //       }
    817 //       pIter(p);
    818 //     }
    819 //     p = ph;
    820 //     //number tmp;
    821 //     if(!nIsOne(h))
    822 //     {
    823 //       while (p!=NULL)
    824 //       {
    825 //         //d = nDiv(pGetCoeff(p),h);
    826 //         //tmp = nIntDiv(pGetCoeff(p),h);
    827 //         //if (!nEqual(d,tmp))
    828 //         //{
    829 //         //  StringSetS("** div0:");nWrite(pGetCoeff(p));StringAppendS("/");
    830 //         //  nWrite(h);StringAppendS("=");nWrite(d);StringAppendS(" int:");
    831 //         //  nWrite(tmp);Print(StringAppendS("\n"));
    832 //         //}
    833 //         //nDelete(&tmp);
    834 //         d = nIntDiv(pGetCoeff(p),h);
    835 //         pSetCoeff(p,d);
    836 //         pIter(p);
    837 //       }
    838 //     }
    839 //     nDelete(&h);
    840 // #ifdef HAVE_FACTORY
    841 //     if ( (nGetChar() == 1) || (nGetChar() < 0) ) /* Q[a],Q(a),Zp[a],Z/p(a) */
    842 //     {
    843 //       singclap_divide_content(ph);
    844 //       if(!nGreaterZero(pGetCoeff(ph))) ph = pNeg(ph);
    845 //     }
    846 // #endif
    847 //     if (rField_is_Q_a())
    848 //     {
    849 //       number hzz = nlInit(1);
    850 //       h = nlInit(1);
    851 //       p=ph;
    852 //       while (p!=NULL)
    853 //       { // each monom: coeff in Q_a
    854 //         lnumber c_n_n=(lnumber)pGetCoeff(p);
    855 //         napoly c_n=c_n_n->z;
    856 //         while (c_n!=NULL)
    857 //         { // each monom: coeff in Q
    858 //           d=nlLcm(hzz,pGetCoeff(c_n),currRing->algring);
    859 //           n_Delete(&hzz,currRing->algring);
    860 //           hzz=d;
    861 //           pIter(c_n);
    862 //         }
    863 //         c_n=c_n_n->n;
    864 //         while (c_n!=NULL)
    865 //         { // each monom: coeff in Q
    866 //           d=nlLcm(h,pGetCoeff(c_n),currRing->algring);
    867 //           n_Delete(&h,currRing->algring);
    868 //           h=d;
    869 //           pIter(c_n);
    870 //         }
    871 //         pIter(p);
    872 //       }
    873 //       /* hzz contains the 1/lcm of all denominators in c_n_n->z*/
    874 //       /* h contains the 1/lcm of all denominators in c_n_n->n*/
    875 //       number htmp=nlInvers(h);
    876 //       number hzztmp=nlInvers(hzz);
    877 //       number hh=nlMult(hzz,h);
    878 //       nlDelete(&hzz,currRing->algring);
    879 //       nlDelete(&h,currRing->algring);
    880 //       number hg=nlGcd(hzztmp,htmp,currRing->algring);
    881 //       nlDelete(&hzztmp,currRing->algring);
    882 //       nlDelete(&htmp,currRing->algring);
    883 //       h=nlMult(hh,hg);
    884 //       nlDelete(&hg,currRing->algring);
    885 //       nlDelete(&hh,currRing->algring);
    886 //       nlNormalize(h);
    887 //       if(!nlIsOne(h))
    888 //       {
    889 //         p=ph;
    890 //         while (p!=NULL)
    891 //         { // each monom: coeff in Q_a
    892 //           lnumber c_n_n=(lnumber)pGetCoeff(p);
    893 //           napoly c_n=c_n_n->z;
    894 //           while (c_n!=NULL)
    895 //           { // each monom: coeff in Q
    896 //             d=nlMult(h,pGetCoeff(c_n));
    897 //             nlNormalize(d);
    898 //             nlDelete(&pGetCoeff(c_n),currRing->algring);
    899 //             pGetCoeff(c_n)=d;
    900 //             pIter(c_n);
    901 //           }
    902 //        c_n=c_n_n->n;
    903 //           while (c_n!=NULL)
    904 //           { // each monom: coeff in Q
    905 //             d=nlMult(h,pGetCoeff(c_n));
    906 //             nlNormalize(d);
    907 //             nlDelete(&pGetCoeff(c_n),currRing->algring);
    908 //             pGetCoeff(c_n)=d;
    909 //             pIter(c_n);
    910 //           }
    911 //           pIter(p);
    912 //         }
    913 //       }
    914 //       nlDelete(&h,currRing->algring);
    915 //     }
    916 //   }
    917 // }
    918 
    919 #endif
     749  for(i=0; i<=k; i++)
     750  {
     751    d=singclap_gcd(d,pCopy(C[i]));
     752    if (pTotaldegree(d)==0)
     753    {
     754      // cleanup, pContent, return
     755      pDelete(&d);
     756      for(;k>=0;k--)
     757      {
     758        pDelete(&C[k]);
     759        pDelete(&LM[k]);
     760      }
     761      p=pContent(ph);
     762      goto cleanup;
     763    }
     764  }
     765  for(i=0; i<=k; i++)
     766  {
     767   poly h=singclap_pdivide(C[i],d);
     768   pDelete(&C[i]);
     769   C[i]=h;
     770  }
     771 
     772  // zusammensetzen,
     773  p=NULL; // just to be sure
     774  for(i=0; i<=k; i++)
     775  {
     776   p=pAdd(p,pMult(C[i],LM[i]));
     777   C[i]=NULL; LM[i]=NULL;
     778  }
     779  // aufraeumen, return
     780cleanup:
     781  omFree(C);
     782  omFree(LM);
     783  omFree(D);
     784  omFree(L);
     785  return p;
     786}
     787#endif
Note: See TracChangeset for help on using the changeset viewer.