Changeset bba835 in git


Ignore:
Timestamp:
May 3, 2007, 3:27:45 PM (16 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
Children:
75ae36afc86628e8325b039c42ab23fe91876b39
Parents:
52e38fce6d01c11b7934d7b1830db574af0f6983
Message:
*hannes: chinese remainder


git-svn-id: file:///usr/local/Singular/svn/trunk@10011 2c84dea3-7e68-4137-9b89-c4e89433aadc
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • Singular/iparith.cc

    r52e38fc rbba835  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: iparith.cc,v 1.444 2007-03-22 13:34:52 Singular Exp $ */
     4/* $Id: iparith.cc,v 1.445 2007-05-03 13:27:42 Singular Exp $ */
    55
    66/*
     
    16841684  return FALSE;
    16851685}
     1686#if 0
    16861687static BOOLEAN jjCHINREM_P(leftv res, leftv u, leftv v)
    16871688{
    1688 #if 0
    1689   ideal c=(ideal)u->CopyD();
     1689  lists c=(lists)u->CopyD(); // list of poly
    16901690  intvec* p=(intvec*)v->Data();
    16911691  int rl=p->length();
    1692   poly r=NULL,h;
     1692  poly r=NULL,h, result=NULL;
    16931693  number *x=(number *)omAlloc(rl*sizeof(number));
    16941694  number *q=(number *)omAlloc(rl*sizeof(number));
     
    16981698    q[i]=nlInit((*p)[i]);
    16991699  }
    1700   // for each monom
    1701   //number n=nlChineseRemainder(x,q,rl);
     1700  loop
     1701  {
     1702    for(i=rl-1;i>=0;i--)
     1703    {
     1704      if (c->m[i].Typ()!=POLY_CMD)
     1705      {
     1706        Werror("poly expected at pos %d",i+1);
     1707        for(i=rl-1;i>=0;i--)
     1708        {
     1709          nlDelete(&(q[i]),currRing);
     1710        }
     1711        omFree(x); omFree(q); // delete c
     1712        return TRUE;
     1713      }
     1714      h=((poly)c->m[i].Data());
     1715      if (r==NULL) r=h;
     1716      else if (pLmCmp(r,h)==-1) r=h;
     1717    }
     1718    if (r==NULL) break;
     1719    for(i=rl-1;i>=0;i--)
     1720    {
     1721      h=((poly)c->m[i].Data());
     1722      if (pLmCmp(r,h)==0)
     1723      {
     1724        x[i]=pGetCoeff(h);
     1725        h=pLmFreeAndNext(h);
     1726        c->m[i].data=(char*)h;
     1727      }
     1728      else
     1729        x[i]=nlInit(0);
     1730    }
     1731    number n=nlChineseRemainder(x,q,rl);
     1732    for(i=rl-1;i>=0;i--)
     1733    {
     1734      nlDelete(&(x[i]),currRing);
     1735    }
     1736    h=pHead(r);
     1737    pSetCoeff(h,n);
     1738    result=pAdd(result,h);
     1739  }
    17021740  for(i=rl-1;i>=0;i--)
    17031741  {
     
    17051743  }
    17061744  omFree(x); omFree(q);
    1707   res->data=(char *)r;
    1708   return FALSE;
    1709 #else
    1710   return TRUE; // not yet implemented
     1745  res->data=(char *)result;
     1746  return FALSE;
     1747}
    17111748#endif
     1749static BOOLEAN jjCHINREM_ID(leftv res, leftv u, leftv v)
     1750{
     1751  lists c=(lists)u->CopyD(); // list of ideal
     1752  intvec* p=(intvec*)v->Data();
     1753  int rl=p->length();
     1754  poly r=NULL,h;
     1755  ideal result;
     1756  ideal *x=(ideal *)omAlloc(rl*sizeof(ideal));
     1757  int i;
     1758  for(i=rl-1;i>=0;i--)
     1759  {
     1760    if (c->m[i].Typ()!=IDEAL_CMD)
     1761    {
     1762      Werror("ideal expected at pos %d",i+1);
     1763      omFree(x); // delete c
     1764      return TRUE;
     1765    }
     1766    x[i]=((ideal)c->m[i].Data());
     1767  }
     1768  number *q=(number *)omAlloc(rl*sizeof(number));
     1769  for(i=rl-1;i>=0;i--)
     1770  {
     1771    q[i]=nlInit((*p)[i]);
     1772  }
     1773  result=idChineseRemainder(x,q,rl);
     1774  for(i=rl-1;i>=0;i--)
     1775  {
     1776    nlDelete(&(q[i]),currRing);
     1777  }
     1778  omFree(q);
     1779  res->data=(char *)result;
     1780  return FALSE;
    17121781}
    17131782static BOOLEAN jjCOEF(leftv res, leftv u, leftv v)
     
    31073176#endif
    31083177,{jjCHINREM_BI,CHINREM_CMD,    BIGINT_CMD,     INTVEC_CMD, INTVEC_CMD ALLOW_PLURAL}
    3109 ,{jjCHINREM_P, CHINREM_CMD,    POLY_CMD,       IDEAL_CMD,  IDEAL_CMD ALLOW_PLURAL}
     3178//,{jjCHINREM_P, CHINREM_CMD,    POLY_CMD,       LIST_CMD,   INTVEC_CMD ALLOW_PLURAL}
     3179,{jjCHINREM_ID,CHINREM_CMD,    IDEAL_CMD,      LIST_CMD,   INTVEC_CMD ALLOW_PLURAL}
    31103180,{jjCOEF,      COEF_CMD,       MATRIX_CMD,     POLY_CMD,   POLY_CMD ALLOW_PLURAL}
    31113181,{jjCOEFFS_Id, COEFFS_CMD,     MATRIX_CMD,     IDEAL_CMD,  POLY_CMD ALLOW_PLURAL}
  • kernel/clapconv.cc

    r52e38fc rbba835  
    33*  Computer Algebra System SINGULAR     *
    44****************************************/
    5 // $Id: clapconv.cc,v 1.8 2007-03-15 14:24:03 Singular Exp $
     5// $Id: clapconv.cc,v 1.9 2007-05-03 13:27:45 Singular Exp $
    66/*
    77* ABSTRACT: convert data between Singular and factory
     
    730730  chineseRemainder(X,Q,xnew,qnew);
    731731  number n=convClapNSingN(xnew);
     732  number p=convClapNSingN(qnew);
     733  number p2=nlIntDiv(p,nlInit(2));
     734  if (nlGreater(n,p2))
     735  {
     736     number n2=nlSub(n,p);
     737     nlDelete(&n,currRing);
     738     n=n2;
     739  }
     740  nlDelete(&p,currRing);
     741  nlDelete(&p2,currRing);
    732742  return n;
    733743#else
  • kernel/ideals.cc

    r52e38fc rbba835  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: ideals.cc,v 1.41 2007-04-03 15:16:39 Singular Exp $ */
     4/* $Id: ideals.cc,v 1.42 2007-05-03 13:27:44 Singular Exp $ */
    55/*
    66* ABSTRACT - all basic methods to manipulate ideals
     
    1313#include "febase.h"
    1414#include "numbers.h"
     15#include "longrat.h"
    1516#include "polys.h"
    1617#include "ring.h"
     
    36943695  return gcd_p;
    36953696}
     3697
     3698/*2
     3699* xx,q: arrays of length 0..rl-1
     3700* xx[i]: SB mod q[i]
     3701* assume: char=0
     3702* assume: q[i]!=0
     3703* destroys xx
     3704*/
     3705ideal idChineseRemainder(ideal *xx, number *q, int rl)
     3706{
     3707  ideal result=idInit(IDELEMS(xx[0]),1);
     3708  int i,j;
     3709  poly r,h,res_p;
     3710  number *x=(number *)omAlloc(rl*sizeof(number));
     3711  for(i=IDELEMS(result)-1;i>=0;i--)
     3712  {
     3713    res_p=NULL;
     3714    loop
     3715    {
     3716      r=NULL;
     3717      for(j=rl-1;j>=0;j--)
     3718      {
     3719        h=xx[j]->m[i];
     3720        if ((r==NULL)||(pLmCmp(r,h)==-1)) r=h;
     3721      }
     3722      if (r==NULL) break;
     3723      for(j=rl-1;j>=0;j--)
     3724      {
     3725        h=xx[j]->m[i];
     3726        if (pLmCmp(r,h)==0)
     3727        {
     3728          x[j]=pGetCoeff(h);
     3729          h=pLmFreeAndNext(h);
     3730          xx[j]->m[i]=h;
     3731        }
     3732        else
     3733          x[j]=nlInit(0);
     3734      }
     3735      number n=nlChineseRemainder(x,q,rl);
     3736      for(j=rl-1;j>=0;j--)
     3737      {
     3738        nlDelete(&(x[j]),currRing);
     3739      }
     3740      h=pHead(r);
     3741      pSetCoeff(h,n);
     3742      res_p=pAdd(res_p,h);
     3743    }
     3744    result->m[i]=res_p;
     3745  }
     3746  omFree(x);
     3747  for(i=rl-1;i>=0;i--) idDelete(&(xx[i]));
     3748  omFree(xx);
     3749  return result;
     3750}
  • kernel/ideals.h

    r52e38fc rbba835  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: ideals.h,v 1.7 2007-01-10 17:17:27 Singular Exp $ */
     6/* $Id: ideals.h,v 1.8 2007-05-03 13:27:44 Singular Exp $ */
    77/*
    88* ABSTRACT - all basic methods to manipulate ideals
     
    155155
    156156poly id_GCD(poly f, poly g, const ring r);
     157
     158ideal idChineseRemainder(ideal *x, number *q, int rl);
    157159#endif
Note: See TracChangeset for help on using the changeset viewer.