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 | |
---|
35 | poly 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 | |
---|
49 | poly 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 ----------------------------*/ |
---|
75 | #if 0 |
---|
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 | */ |
---|
81 | void 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 | |
---|
99 | int 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 | */ |
---|
123 | BOOLEAN 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 | */ |
---|
141 | BOOLEAN 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; |
---|
154 | #ifdef HAVE_RINGS |
---|
155 | if (rField_is_Ring(currRing)) |
---|
156 | { |
---|
157 | if (!nDivBy(pGetCoeff(p1), pGetCoeff(p2))) return FALSE; |
---|
158 | } |
---|
159 | #endif |
---|
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 | } |
---|