source: git/libpolys/polys/polys1.cc @ f550e86

jengelh-datetimespielwiese
Last change on this file since f550e86 was f550e86, checked in by Hans Schoenemann <hannes@…>, 12 years ago
- fixed weights.h - moved Jet routines to p_polys.cc
  • Property mode set to 100644
File size: 4.0 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
35int pMinDeg(poly p,intvec *w)
36{
37  if(p==NULL)
38    return -1;
39  int d=-1;
40  while(p!=NULL)
41  {
42    int d0=0;
43    for(int j=0;j<pVariables;j++)
44      if(w==NULL||j>=w->length())
45        d0+=pGetExp(p,j+1);
46      else
47        d0+=(*w)[j]*pGetExp(p,j+1);
48    if(d0<d||d==-1)
49      d=d0;
50    pIter(p);
51  }
52  return d;
53}
54
55poly pSeries(int n,poly p,poly u, intvec *w)
56{
57  short *ww=iv2array(w);
58  if(p!=NULL)
59  {
60    if(u==NULL)
61      p=pJetW(p,n,ww);
62    else
63      p=pJetW(pMult(p,pInvers(n-pMinDeg(p,w),u,w)),n,ww);
64  }
65  omFreeSize((ADDRESS)ww,(pVariables+1)*sizeof(short));
66  return p;
67}
68
69poly pInvers(int n,poly u,intvec *w)
70{
71  short *ww=iv2array(w);
72  if(n<0)
73    return NULL;
74  number u0=nInvers(pGetCoeff(u));
75  poly v=pNSet(u0);
76  if(n==0)
77    return v;
78  poly u1=pJetW(pSub(pOne(),pMult_nn(u,u0)),n,ww);
79  if(u1==NULL)
80    return v;
81  poly v1=pMult_nn(pCopy(u1),u0);
82  v=pAdd(v,pCopy(v1));
83  for(int i=n/pMinDeg(u1,w);i>1;i--)
84  {
85    v1=pJetW(pMult(v1,pCopy(u1)),n,ww);
86    v=pAdd(v,pCopy(v1));
87  }
88  pDelete(&u1);
89  pDelete(&v1);
90  omFreeSize((ADDRESS)ww,(pVariables+1)*sizeof(short));
91  return v;
92}
93
94long pDegW(poly p, const short *w)
95{
96  long r=-LONG_MAX;
97
98  while (p!=NULL)
99  {
100    long t=totaldegreeWecart_IV(p,currRing,w);
101    if (t>r) r=t;
102    pIter(p);
103  }
104  return r;
105}
106
107/*-----------type conversions ----------------------------*/
108#if 0
109/*2
110* convert a vector to a set of polys,
111* allocates the polyset, (entries 0..(*len)-1)
112* the vector will not be changed
113*/
114void  pVec2Polys(poly v, polyset *p, int *len)
115{
116  poly h;
117  int k;
118
119  *len=pMaxComp(v);
120  if (*len==0) *len=1;
121  *p=(polyset)omAlloc0((*len)*sizeof(poly));
122  while (v!=NULL)
123  {
124    h=pHead(v);
125    k=pGetComp(h);
126    pSetComp(h,0);
127    (*p)[k-1]=pAdd((*p)[k-1],h);
128    pIter(v);
129  }
130}
131
132int p_Var(poly m,const ring r)
133{
134  if (m==NULL) return 0;
135  if (pNext(m)!=NULL) return 0;
136  int i,e=0;
137  for (i=r->N; i>0; i--)
138  {
139    int exp=p_GetExp(m,i,r);
140    if (exp==1)
141    {
142      if (e==0) e=i;
143      else return 0;
144    }
145    else if (exp!=0)
146    {
147      return 0;
148    }
149  }
150  return e;
151}
152
153/*2
154* returns TRUE if p1 = p2
155*/
156BOOLEAN p_EqualPolys(poly p1,poly p2, const ring r)
157{
158  while ((p1 != NULL) && (p2 != NULL))
159  {
160    if (! p_LmEqual(p1, p2,r))
161      return FALSE;
162    if (! n_Equal(p_GetCoeff(p1,r), p_GetCoeff(p2,r),r ))
163      return FALSE;
164    pIter(p1);
165    pIter(p2);
166  }
167  return (p1==p2);
168}
169
170/*2
171*returns TRUE if p1 is a skalar multiple of p2
172*assume p1 != NULL and p2 != NULL
173*/
174BOOLEAN pComparePolys(poly p1,poly p2)
175{
176  number n,nn;
177  pAssume(p1 != NULL && p2 != NULL);
178
179  if (!pLmEqual(p1,p2)) //compare leading mons
180      return FALSE;
181  if ((pNext(p1)==NULL) && (pNext(p2)!=NULL))
182     return FALSE;
183  if ((pNext(p2)==NULL) && (pNext(p1)!=NULL))
184     return FALSE;
185  if (pLength(p1) != pLength(p2))
186    return FALSE;
187#ifdef HAVE_RINGS
188  if (rField_is_Ring(currRing))
189  {
190    if (!nDivBy(pGetCoeff(p1), pGetCoeff(p2))) return FALSE;
191  }
192#endif
193  n=nDiv(pGetCoeff(p1),pGetCoeff(p2));
194  while ((p1 != NULL) /*&& (p2 != NULL)*/)
195  {
196    if ( ! pLmEqual(p1, p2))
197    {
198        nDelete(&n);
199        return FALSE;
200    }
201    if (!nEqual(pGetCoeff(p1),nn=nMult(pGetCoeff(p2),n)))
202    {
203      nDelete(&n);
204      nDelete(&nn);
205      return FALSE;
206    }
207    nDelete(&nn);
208    pIter(p1);
209    pIter(p2);
210  }
211  nDelete(&n);
212  return TRUE;
213}
Note: See TracBrowser for help on using the repository browser.