Changeset cec9624 in git


Ignore:
Timestamp:
Jul 11, 2019, 2:59:38 PM (5 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
dffcf06de72c5d8f3347abee6740a159f6cabd41
Parents:
18296cd9190bb2f8c652446aa5cf3a783ad2cb66
Message:
add: pp_DivideM, pp_Divide
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/numeric/mpr_base.cc

    r18296c rcec9624  
    23982398      // compute row poly
    23992399      poly pi= ppMult_qq( (gls->m)[ resVectorList[k].elementOfS ] , resVectorList[k].mon );
    2400       pi= pDivideM( pCopy( pi ), pCopy( resVectorList[k].dividedBy ) );
     2400      pi= pp_DivideM( pi, resVectorList[k].dividedBy, currRing );
    24012401
    24022402      // fill in "matrix"
     
    24302430
    24312431      pi= (gls->m)[ resVectorList[k].elementOfS ];
    2432       factor= pDivideM( pCopy( resVectorList[k].mon ), pCopy( resVectorList[k].dividedBy ) );
     2432      factor= pp_DivideM( resVectorList[k].mon, resVectorList[k].dividedBy, currRing );
    24332433
    24342434      j=0;
  • kernel/polys.cc

    r18296c rcec9624  
    179179}
    180180
     181poly pp_Divide(poly p, poly q, const ring r)
     182{
     183  assume(q!=NULL);
     184  if (q==NULL)
     185  {
     186    WerrorS("div. by 0");
     187    return NULL;
     188  }
     189  if (p==NULL)
     190  {
     191    return NULL;
     192  }
     193  if (pNext(q)!=NULL)
     194  { /* This means that q != 0 consists of at least two terms*/
     195    if (rIsLPRing(r))
     196    {
     197      WerrorS("not implemented for letterplace rings");
     198      return NULL;
     199    }
     200    if(p_GetComp(p,r)==0)
     201    {
     202      if((rFieldType(r)==n_transExt)
     203      &&(convSingTrP(p,r))
     204      &&(convSingTrP(q,r)))
     205      {
     206        poly res=singclap_pdivide(p, q, r);
     207        return res;
     208      }
     209      else if ((r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
     210      &&(!rField_is_Ring(r)))
     211      {
     212        poly res=singclap_pdivide(p, q, r);
     213        return res;
     214      }
     215      else
     216      {
     217        ideal vi=idInit(1,1); vi->m[0]=p_Copy(q,r);
     218        ideal ui=idInit(1,1); ui->m[0]=p_Copy(p,r);
     219        ideal R; matrix U;
     220        ring save_ring=currRing;
     221        if (r!=currRing) rChangeCurrRing(r);
     222        int save_opt;
     223        SI_SAVE_OPT1(save_opt);
     224        si_opt_1 &= ~(Sy_bit(OPT_PROT));
     225        ideal m = idLift(vi,ui,&R, FALSE,TRUE,TRUE,&U);
     226        SI_RESTORE_OPT1(save_opt);
     227        if (r!=save_ring) rChangeCurrRing(save_ring);
     228        matrix T = id_Module2formatedMatrix(m,1,1,r);
     229        p=MATELEM(T,1,1); MATELEM(T,1,1)=NULL;
     230        id_Delete((ideal *)&T,r);
     231        id_Delete((ideal *)&U,r);
     232        id_Delete(&R,r);
     233        //vi->m[0]=NULL; ui->m[0]=NULL;
     234        id_Delete(&vi,r);
     235        id_Delete(&ui,r);
     236        return p;
     237      }
     238    }
     239    else
     240    {
     241      p=p_Copy(p,r);
     242      int comps=p_MaxComp(p,r);
     243      ideal I=idInit(comps,1);
     244      poly h;
     245      int i;
     246      // conversion to a list of polys:
     247      while (p!=NULL)
     248      {
     249        i=p_GetComp(p,r)-1;
     250        h=pNext(p);
     251        pNext(p)=NULL;
     252        p_SetComp(p,0,r);
     253        I->m[i]=p_Add_q(I->m[i],p,r);
     254        p=h;
     255      }
     256      // division and conversion to vector:
     257      h=NULL;
     258      p=NULL;
     259      q=p_Copy(q,r);
     260      for(i=comps-1;i>=0;i--)
     261      {
     262        if (I->m[i]!=NULL)
     263        {
     264          if((rFieldType(r)==n_transExt)
     265          &&(convSingTrP(I->m[i],r))
     266          &&(convSingTrP(q,r)))
     267          {
     268            h=singclap_pdivide(I->m[i],q,r);
     269          }
     270          else if ((r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
     271          &&(!rField_is_Ring(r)))
     272            h=singclap_pdivide(I->m[i],q,r);
     273          else
     274          {
     275            ideal vi=idInit(1,1); vi->m[0]=q;
     276            ideal ui=idInit(1,1); ui->m[0]=I->m[i];
     277            ideal R; matrix U;
     278            ring save_ring=currRing;
     279            if (r!=currRing) rChangeCurrRing(r);
     280            int save_opt;
     281            SI_SAVE_OPT1(save_opt);
     282            si_opt_1 &= ~(Sy_bit(OPT_PROT));
     283            ideal m = idLift(vi,ui,&R, FALSE,TRUE,TRUE,&U);
     284            SI_RESTORE_OPT1(save_opt);
     285            if (r!=save_ring) rChangeCurrRing(save_ring);
     286            if (idIs0(R))
     287            {
     288              matrix T = id_Module2formatedMatrix(m,1,1,r);
     289              p=MATELEM(T,1,1); MATELEM(T,1,1)=NULL;
     290              id_Delete((ideal *)&T,r);
     291            }
     292            else p=NULL;
     293            id_Delete((ideal*)&U,r);
     294            id_Delete(&R,r);
     295            vi->m[0]=NULL; ui->m[0]=NULL;
     296            id_Delete(&vi,r);
     297            id_Delete(&ui,r);
     298          }
     299          p_SetCompP(h,i+1,r);
     300          p=p_Add_q(p,h,r);
     301        }
     302      }
     303      id_Delete(&I,r);
     304      p_Delete(&q,r);
     305      return p;
     306    }
     307  }
     308  else
     309  { /* This means that q != 0 consists of just one term,
     310       or that r is over a coefficient ring. */
     311#ifdef HAVE_RINGS
     312    if (!rField_is_Domain(r))
     313    {
     314      WerrorS("division only defined over coefficient domains");
     315      return NULL;
     316    }
     317    if (pNext(q)!=NULL)
     318    {
     319      WerrorS("division over a coefficient domain only implemented for terms");
     320      return NULL;
     321    }
     322#endif
     323    return pp_DivideM(p,q,r);
     324  }
     325  return NULL;
     326}
     327
    181328poly p_DivRem(poly p, poly q, poly &rest, const ring r)
    182329{
  • kernel/polys.h

    r18296c rcec9624  
    164164/// destroyes a,b
    165165poly p_Divide(poly a, poly b, const ring r);
     166/// polynomial division a/b, ignoring the rest
     167/// via singclap_pdivide resp. idLift
     168/// does not destroy a,b
     169poly pp_Divide(poly a, poly b, const ring r);
    166170poly p_DivRem(poly a, poly b, poly &rest, const ring r); /*julia*/
    167171
  • libpolys/polys/monomials/p_polys.cc

    r18296c rcec9624  
    16101610  }
    16111611  p_Delete(&b, r);
     1612  return result;
     1613}
     1614
     1615poly pp_DivideM(poly a, poly b, const ring r)
     1616{
     1617  if (a==NULL) { return NULL; }
     1618  poly result=a;
     1619
     1620  if(!p_IsConstant(b,r))
     1621  {
     1622    if (rIsLPRing(r))
     1623    {
     1624      WerrorS("not implemented for letterplace rings");
     1625      return NULL;
     1626    }
     1627    poly prev=NULL;
     1628    a=p_Copy(a,r);
     1629    while (a!=NULL)
     1630    {
     1631      if (p_DivisibleBy(b,a,r))
     1632      {
     1633        p_ExpVectorSub(a,b,r);
     1634        prev=a;
     1635        pIter(a);
     1636      }
     1637      else
     1638      {
     1639        if (prev==NULL)
     1640        {
     1641          p_LmDelete(&result,r);
     1642          a=result;
     1643        }
     1644        else
     1645        {
     1646          p_LmDelete(&pNext(prev),r);
     1647          a=pNext(prev);
     1648        }
     1649      }
     1650    }
     1651  }
     1652  if (result!=NULL)
     1653  {
     1654    number inv=pGetCoeff(b);
     1655    //if ((!rField_is_Ring(r)) || n_IsUnit(inv,r->cf))
     1656    if (rField_is_Zp(r))
     1657    {
     1658      inv = n_Invers(inv,r->cf);
     1659      __p_Mult_nn(result,inv,r);
     1660      n_Delete(&inv, r->cf);
     1661    }
     1662    else
     1663    {
     1664      result = p_Div_nn(result,inv,r);
     1665    }
     1666  }
    16121667  return result;
    16131668}
  • libpolys/polys/monomials/p_polys.h

    r18296c rcec9624  
    19901990poly      p_MDivide(poly a, poly b, const ring r);
    19911991poly      p_DivideM(poly a, poly b, const ring r);
     1992poly      pp_DivideM(poly a, poly b, const ring r);
    19921993poly      p_Div_nn(poly p, const number n, const ring r);
    19931994
Note: See TracChangeset for help on using the changeset viewer.