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

spielwiese
Last change on this file since ba0fc3 was ba0fc3, checked in by Hans Schoenemann <hannes@…>, 13 years ago
p_MinDeg, p_DegW -> p_polys.cc
  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[6438a12]1</****************************************
[a6904c]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>
[20b794]13#include "polys/config.h"
14// #include <polys/options.h>
15#include <coeffs/numbers.h>
16#include <coeffs/ffields.h>
[b1dfaf]17#include <omalloc/omalloc.h>
[20b794]18// #include <???/febase.h>
[6bec87]19// #include <???/weight.h>
20// #include <???/intvec.h>
[20b794]21#include <polys/ext_fields/longalg.h>
22#include <polys/monomials/ring.h>
[6bec87]23// #include <???/ideals.h>
[78eba1]24// #include <polys/polys.h>
[6bec87]25// #include "ipid.h"
[a6904c]26#ifdef HAVE_FACTORY
[6bec87]27// #include <???/clapsing.h>
[a6904c]28#endif
29
30#ifdef HAVE_RATGRING
[20b794]31// #include <polys/ratgring.h>
[a6904c]32#endif
33
34
35poly pSeries(int n,poly p,poly u, intvec *w)
36{
37  short *ww=iv2array(w);
38  if(p!=NULL)
39  {
40    if(u==NULL)
41      p=pJetW(p,n,ww);
42    else
43      p=pJetW(pMult(p,pInvers(n-pMinDeg(p,w),u,w)),n,ww);
44  }
45  omFreeSize((ADDRESS)ww,(pVariables+1)*sizeof(short));
46  return p;
47}
48
49poly pInvers(int n,poly u,intvec *w)
50{
51  short *ww=iv2array(w);
52  if(n<0)
53    return NULL;
54  number u0=nInvers(pGetCoeff(u));
55  poly v=pNSet(u0);
56  if(n==0)
57    return v;
58  poly u1=pJetW(pSub(pOne(),pMult_nn(u,u0)),n,ww);
59  if(u1==NULL)
60    return v;
61  poly v1=pMult_nn(pCopy(u1),u0);
62  v=pAdd(v,pCopy(v1));
63  for(int i=n/pMinDeg(u1,w);i>1;i--)
64  {
65    v1=pJetW(pMult(v1,pCopy(u1)),n,ww);
66    v=pAdd(v,pCopy(v1));
67  }
68  pDelete(&u1);
69  pDelete(&v1);
70  omFreeSize((ADDRESS)ww,(pVariables+1)*sizeof(short));
71  return v;
72}
73
74/*-----------type conversions ----------------------------*/
[815d74]75#if 0
[a6904c]76/*2
77* convert a vector to a set of polys,
78* allocates the polyset, (entries 0..(*len)-1)
79* the vector will not be changed
80*/
81void  pVec2Polys(poly v, polyset *p, int *len)
82{
83  poly h;
84  int k;
85
86  *len=pMaxComp(v);
87  if (*len==0) *len=1;
88  *p=(polyset)omAlloc0((*len)*sizeof(poly));
89  while (v!=NULL)
90  {
91    h=pHead(v);
92    k=pGetComp(h);
93    pSetComp(h,0);
94    (*p)[k-1]=pAdd((*p)[k-1],h);
95    pIter(v);
96  }
97}
98
99int p_Var(poly m,const ring r)
100{
101  if (m==NULL) return 0;
102  if (pNext(m)!=NULL) return 0;
103  int i,e=0;
104  for (i=r->N; i>0; i--)
105  {
106    int exp=p_GetExp(m,i,r);
107    if (exp==1)
108    {
109      if (e==0) e=i;
110      else return 0;
111    }
112    else if (exp!=0)
113    {
114      return 0;
115    }
116  }
117  return e;
118}
119
120/*2
121* returns TRUE if p1 = p2
122*/
123BOOLEAN p_EqualPolys(poly p1,poly p2, const ring r)
124{
125  while ((p1 != NULL) && (p2 != NULL))
126  {
127    if (! p_LmEqual(p1, p2,r))
128      return FALSE;
129    if (! n_Equal(p_GetCoeff(p1,r), p_GetCoeff(p2,r),r ))
130      return FALSE;
131    pIter(p1);
132    pIter(p2);
133  }
134  return (p1==p2);
135}
136
137/*2
138*returns TRUE if p1 is a skalar multiple of p2
139*assume p1 != NULL and p2 != NULL
140*/
141BOOLEAN pComparePolys(poly p1,poly p2)
142{
143  number n,nn;
144  pAssume(p1 != NULL && p2 != NULL);
145
146  if (!pLmEqual(p1,p2)) //compare leading mons
147      return FALSE;
148  if ((pNext(p1)==NULL) && (pNext(p2)!=NULL))
149     return FALSE;
150  if ((pNext(p2)==NULL) && (pNext(p1)!=NULL))
151     return FALSE;
152  if (pLength(p1) != pLength(p2))
153    return FALSE;
[dd5534]154#ifdef HAVE_RINGS
155  if (rField_is_Ring(currRing))
156  {
[a8b44d]157    if (!nDivBy(pGetCoeff(p1), pGetCoeff(p2))) return FALSE;
[dd5534]158  }
159#endif
[a6904c]160  n=nDiv(pGetCoeff(p1),pGetCoeff(p2));
161  while ((p1 != NULL) /*&& (p2 != NULL)*/)
162  {
163    if ( ! pLmEqual(p1, p2))
164    {
165        nDelete(&n);
166        return FALSE;
167    }
168    if (!nEqual(pGetCoeff(p1),nn=nMult(pGetCoeff(p2),n)))
169    {
170      nDelete(&n);
171      nDelete(&nn);
172      return FALSE;
173    }
174    nDelete(&nn);
175    pIter(p1);
176    pIter(p2);
177  }
178  nDelete(&n);
179  return TRUE;
180}
Note: See TracBrowser for help on using the repository browser.