source: git/libpolys/polys/polys1.cc @ 78eba1

spielwiese
Last change on this file since 78eba1 was 78eba1, checked in by Mohamed Barakat <mohamed.barakat@…>, 13 years ago
- replaced nIsZero(tmp) -> n_IsZero__T(tmp,r) - fixed kbuckets reference - added dynamic_modules target
  • Property mode set to 100644
File size: 5.3 KB
Line 
1</****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
5
6/*
7* ABSTRACT - all basic methods to manipulate polynomials:
8* independent of representation
9*/
10
11/* includes */
12#include <string.h>
13#include "polys/config.h"
14// #include <polys/options.h>
15#include <coeffs/numbers.h>
16#include <coeffs/ffields.h>
17#include <omalloc/omalloc.h>
18// #include <???/febase.h>
19// #include <???/weight.h>
20// #include <???/intvec.h>
21#include <polys/ext_fields/longalg.h>
22#include <polys/monomials/ring.h>
23// #include <???/ideals.h>
24// #include <polys/polys.h>
25// #include "ipid.h"
26#ifdef HAVE_FACTORY
27// #include <???/clapsing.h>
28#endif
29
30#ifdef HAVE_RATGRING
31// #include <polys/ratgring.h>
32#endif
33
34
35poly ppJet(poly p, int m)
36{
37  poly r=NULL;
38  poly t=NULL;
39
40  while (p!=NULL)
41  {
42    if (p_Totaldegree(p,currRing)<=m)
43    {
44      if (r==NULL)
45        r=pHead(p);
46      else
47      if (t==NULL)
48      {
49        pNext(r)=pHead(p);
50        t=pNext(r);
51      }
52      else
53      {
54        pNext(t)=pHead(p);
55        pIter(t);
56      }
57    }
58    pIter(p);
59  }
60  return r;
61}
62
63poly pJet(poly p, int m)
64{
65  poly t=NULL;
66
67  while((p!=NULL) && (p_Totaldegree(p,currRing)>m)) pLmDelete(&p);
68  if (p==NULL) return NULL;
69  poly r=p;
70  while (pNext(p)!=NULL)
71  {
72    if (p_Totaldegree(pNext(p),currRing)>m)
73    {
74      pLmDelete(&pNext(p));
75    }
76    else
77      pIter(p);
78  }
79  return r;
80}
81
82poly ppJetW(poly p, int m, short *w)
83{
84  poly r=NULL;
85  poly t=NULL;
86  while (p!=NULL)
87  {
88    if (totaldegreeWecart_IV(p,currRing,w)<=m)
89    {
90      if (r==NULL)
91        r=pHead(p);
92      else
93      if (t==NULL)
94      {
95        pNext(r)=pHead(p);
96        t=pNext(r);
97      }
98      else
99      {
100        pNext(t)=pHead(p);
101        pIter(t);
102      }
103    }
104    pIter(p);
105  }
106  return r;
107}
108
109poly pJetW(poly p, int m, short *w)
110{
111  while((p!=NULL) && (totaldegreeWecart_IV(p,currRing,w)>m)) pLmDelete(&p);
112  if (p==NULL) return NULL;
113  poly r=p;
114  while (pNext(p)!=NULL)
115  {
116    if (totaldegreeWecart_IV(pNext(p),currRing,w)>m)
117    {
118      pLmDelete(&pNext(p));
119    }
120    else
121      pIter(p);
122  }
123  return r;
124}
125
126int pMinDeg(poly p,intvec *w)
127{
128  if(p==NULL)
129    return -1;
130  int d=-1;
131  while(p!=NULL)
132  {
133    int d0=0;
134    for(int j=0;j<pVariables;j++)
135      if(w==NULL||j>=w->length())
136        d0+=pGetExp(p,j+1);
137      else
138        d0+=(*w)[j]*pGetExp(p,j+1);
139    if(d0<d||d==-1)
140      d=d0;
141    pIter(p);
142  }
143  return d;
144}
145
146poly pSeries(int n,poly p,poly u, intvec *w)
147{
148  short *ww=iv2array(w);
149  if(p!=NULL)
150  {
151    if(u==NULL)
152      p=pJetW(p,n,ww);
153    else
154      p=pJetW(pMult(p,pInvers(n-pMinDeg(p,w),u,w)),n,ww);
155  }
156  omFreeSize((ADDRESS)ww,(pVariables+1)*sizeof(short));
157  return p;
158}
159
160poly pInvers(int n,poly u,intvec *w)
161{
162  short *ww=iv2array(w);
163  if(n<0)
164    return NULL;
165  number u0=nInvers(pGetCoeff(u));
166  poly v=pNSet(u0);
167  if(n==0)
168    return v;
169  poly u1=pJetW(pSub(pOne(),pMult_nn(u,u0)),n,ww);
170  if(u1==NULL)
171    return v;
172  poly v1=pMult_nn(pCopy(u1),u0);
173  v=pAdd(v,pCopy(v1));
174  for(int i=n/pMinDeg(u1,w);i>1;i--)
175  {
176    v1=pJetW(pMult(v1,pCopy(u1)),n,ww);
177    v=pAdd(v,pCopy(v1));
178  }
179  pDelete(&u1);
180  pDelete(&v1);
181  omFreeSize((ADDRESS)ww,(pVariables+1)*sizeof(short));
182  return v;
183}
184
185long pDegW(poly p, const short *w)
186{
187  long r=-LONG_MAX;
188
189  while (p!=NULL)
190  {
191    long t=totaldegreeWecart_IV(p,currRing,w);
192    if (t>r) r=t;
193    pIter(p);
194  }
195  return r;
196}
197
198/*-----------type conversions ----------------------------*/
199#if 0
200/*2
201* convert a vector to a set of polys,
202* allocates the polyset, (entries 0..(*len)-1)
203* the vector will not be changed
204*/
205void  pVec2Polys(poly v, polyset *p, int *len)
206{
207  poly h;
208  int k;
209
210  *len=pMaxComp(v);
211  if (*len==0) *len=1;
212  *p=(polyset)omAlloc0((*len)*sizeof(poly));
213  while (v!=NULL)
214  {
215    h=pHead(v);
216    k=pGetComp(h);
217    pSetComp(h,0);
218    (*p)[k-1]=pAdd((*p)[k-1],h);
219    pIter(v);
220  }
221}
222
223int p_Var(poly m,const ring r)
224{
225  if (m==NULL) return 0;
226  if (pNext(m)!=NULL) return 0;
227  int i,e=0;
228  for (i=r->N; i>0; i--)
229  {
230    int exp=p_GetExp(m,i,r);
231    if (exp==1)
232    {
233      if (e==0) e=i;
234      else return 0;
235    }
236    else if (exp!=0)
237    {
238      return 0;
239    }
240  }
241  return e;
242}
243
244/*2
245* returns TRUE if p1 = p2
246*/
247BOOLEAN p_EqualPolys(poly p1,poly p2, const ring r)
248{
249  while ((p1 != NULL) && (p2 != NULL))
250  {
251    if (! p_LmEqual(p1, p2,r))
252      return FALSE;
253    if (! n_Equal(p_GetCoeff(p1,r), p_GetCoeff(p2,r),r ))
254      return FALSE;
255    pIter(p1);
256    pIter(p2);
257  }
258  return (p1==p2);
259}
260
261/*2
262*returns TRUE if p1 is a skalar multiple of p2
263*assume p1 != NULL and p2 != NULL
264*/
265BOOLEAN pComparePolys(poly p1,poly p2)
266{
267  number n,nn;
268  pAssume(p1 != NULL && p2 != NULL);
269
270  if (!pLmEqual(p1,p2)) //compare leading mons
271      return FALSE;
272  if ((pNext(p1)==NULL) && (pNext(p2)!=NULL))
273     return FALSE;
274  if ((pNext(p2)==NULL) && (pNext(p1)!=NULL))
275     return FALSE;
276  if (pLength(p1) != pLength(p2))
277    return FALSE;
278#ifdef HAVE_RINGS
279  if (rField_is_Ring(currRing))
280  {
281    if (!nDivBy(pGetCoeff(p1), pGetCoeff(p2))) return FALSE;
282  }
283#endif
284  n=nDiv(pGetCoeff(p1),pGetCoeff(p2));
285  while ((p1 != NULL) /*&& (p2 != NULL)*/)
286  {
287    if ( ! pLmEqual(p1, p2))
288    {
289        nDelete(&n);
290        return FALSE;
291    }
292    if (!nEqual(pGetCoeff(p1),nn=nMult(pGetCoeff(p2),n)))
293    {
294      nDelete(&n);
295      nDelete(&nn);
296      return FALSE;
297    }
298    nDelete(&nn);
299    pIter(p1);
300    pIter(p2);
301  }
302  nDelete(&n);
303  return TRUE;
304}
Note: See TracBrowser for help on using the repository browser.