1 | #ifndef POLYS_H |
---|
2 | #define POLYS_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id: polys.h,v 1.4 1997-07-02 16:44:12 Singular Exp $ */ |
---|
7 | /* |
---|
8 | * ABSTRACT - all basic methods to manipulate polynomials |
---|
9 | */ |
---|
10 | #include "structs.h" |
---|
11 | |
---|
12 | #define VARS (100) /*max. number of variables as constant*/ |
---|
13 | |
---|
14 | typedef short bmonomial; |
---|
15 | typedef bmonomial monomial[VARS+1]; |
---|
16 | typedef bmonomial * pmonomial; |
---|
17 | |
---|
18 | struct spolyrec |
---|
19 | { |
---|
20 | poly next; |
---|
21 | #define pNext(p) ((p)->next) |
---|
22 | #define pIter(p) ((p) = (p)->next) |
---|
23 | number coef; |
---|
24 | //number pGetCoeff(poly p); |
---|
25 | #define pGetCoeff(p) ((p)->coef) |
---|
26 | //void pSetCoeff(poly p, number n); |
---|
27 | #define pSetCoeff(p,n) {nDelete(&((p)->coef));(p)->coef=n;} |
---|
28 | //void pSetCoeff0(poly p, number n); |
---|
29 | #define pSetCoeff0(p,n) (p)->coef=n |
---|
30 | int Order; |
---|
31 | #define pGetOrder(p) ((p)->Order) |
---|
32 | #define POLYSIZE (sizeof(poly) + sizeof(number) + sizeof(int)) |
---|
33 | monomial exp; |
---|
34 | }; |
---|
35 | typedef poly* polyset; |
---|
36 | |
---|
37 | extern int pVariables; |
---|
38 | extern int pOrdSgn; |
---|
39 | extern BOOLEAN pLexOrder; |
---|
40 | extern BOOLEAN pMixedOrder; |
---|
41 | extern poly ppNoether; |
---|
42 | extern BOOLEAN pVectorOut; |
---|
43 | |
---|
44 | #ifdef DRING |
---|
45 | // D=k[x,d,y] is the Weyl-Algebra [y], y commuting with all others |
---|
46 | // M=k[x,x^(-1),y] is a D-module |
---|
47 | // all x(1..n),d,x(1..n)^(-1),y(1..k) are considered as "ring variables" v(1..N) |
---|
48 | // the map from x(i) to v: |
---|
49 | #define pdX(i) (i) |
---|
50 | // d(i) |
---|
51 | #define pdDX(i) (pdN+i) |
---|
52 | // x(i)^(-1) |
---|
53 | #define pdIX(i) (pdN+i) |
---|
54 | // y(i) |
---|
55 | #define pdY(i) (pdN*2+i+1) |
---|
56 | // a monomial m belongs to a D-module M iff pdDFlag(m)==0 |
---|
57 | // a monomial m belongs to an ideal in the Weyl-Algebra D iff pdDFlag(m)==1 |
---|
58 | #define pdDFlag(m) ((m)->exp[pdN*2+1]) |
---|
59 | |
---|
60 | extern int pdN; |
---|
61 | extern int pdK; |
---|
62 | extern BOOLEAN pDRING; |
---|
63 | poly pdSpolyCreate(poly a, poly b); |
---|
64 | void pdLcm(poly a, poly b, poly m); |
---|
65 | BOOLEAN pdIsConstantComp(poly p); |
---|
66 | void spModuleToPoly(poly a1); |
---|
67 | void pdSetDFlag(poly p,int i); |
---|
68 | #endif |
---|
69 | #ifdef SRING |
---|
70 | extern int pAltVars; |
---|
71 | extern BOOLEAN pSRING; |
---|
72 | #endif |
---|
73 | #ifdef SDRING |
---|
74 | void psAug(poly q, poly done, polyset *s, int *l, int *m); |
---|
75 | void pdAug(poly q, polyset *s, int *l, int *m); |
---|
76 | #endif |
---|
77 | #ifdef SDRING |
---|
78 | extern BOOLEAN pSDRING; |
---|
79 | #endif |
---|
80 | |
---|
81 | /* function prototypes */ |
---|
82 | /*-------- several acces procedures to monomials ---- */ |
---|
83 | //void pGetExpV(poly p, short * exp); |
---|
84 | #define pGetExpV(p,e) memcpy((e),(p)->exp,(pVariables+1)*sizeof(short)); |
---|
85 | //void pSetExpV(poly p, short * exp); |
---|
86 | #define pSetExpV(p,e) {memcpy((p)->exp,(e),(pVariables+1)*sizeof(short));pSetm(p);} |
---|
87 | //void pSetExp(poly p, int varnum, int exp); |
---|
88 | #define pSetExp(p,v,e) (p)->exp[(v)]=(e) |
---|
89 | //int pGetExp(poly p, int varnum); |
---|
90 | #define pGetExp(p,v) ((p)->exp[(v)]) |
---|
91 | //void pSetComp(poly p, int k); |
---|
92 | #define pSetComp(p,k) pSetExp(p,0,k) |
---|
93 | //int pGetComp(poly p); |
---|
94 | #define pGetComp(p) pGetExp(p,0) |
---|
95 | BOOLEAN pIsConstant(poly p); |
---|
96 | BOOLEAN pIsConstantComp(poly p); |
---|
97 | int pIsPurePower(poly p); |
---|
98 | //BOOLEAN pIsVector(poly p); |
---|
99 | #define pIsVector(p) (pGetComp(p)!=0) |
---|
100 | BOOLEAN pHasNotCF(poly p1, poly p2); /*has no common factor ?*/ |
---|
101 | void pSplit(poly p, poly * r); /*p => IN(p), r => REST(p) */ |
---|
102 | //void pCat(poly p, poly r); |
---|
103 | #define pCat(p,r) ((p)->next=(r)) |
---|
104 | |
---|
105 | /*-------------ring management:----------------------*/ |
---|
106 | extern void pChangeRing(int N, int OrdSgn, |
---|
107 | int* ord, int* block0, int* block1, |
---|
108 | short** wv); |
---|
109 | |
---|
110 | /*-----------the ordering of monomials:-------------*/ |
---|
111 | extern pSetmProc pSetm; |
---|
112 | extern pCompProc pComp0; |
---|
113 | int pComp(poly p1,poly p2); |
---|
114 | extern pLDegProc pLDeg; |
---|
115 | extern pFDegProc pFDeg; |
---|
116 | int pDeg(poly p); |
---|
117 | int pTotaldegree(poly p); |
---|
118 | int pWTotaldegree(poly p); |
---|
119 | |
---|
120 | /*-------------pComp for syzygies:-------------------*/ |
---|
121 | |
---|
122 | void pSetModDeg(intvec *w); |
---|
123 | void pSetSchreyerOrdB(polyset nextorder, int length); |
---|
124 | void pSetSchreyerOrdM(polyset nextorder, int length, int comps); |
---|
125 | int pModuleOrder(); |
---|
126 | |
---|
127 | /*-------------storage management:-------------------*/ |
---|
128 | #ifdef MDEBUG |
---|
129 | poly pDBNew(char *f, int l); |
---|
130 | #define pNew() pDBNew(__FILE__,__LINE__) |
---|
131 | poly pDBInit(char * f,int l); |
---|
132 | #define pInit() pDBInit(__FILE__,__LINE__) |
---|
133 | #else |
---|
134 | //poly pNew(void); |
---|
135 | #define pNew() (poly)mmAllocSpecialized() |
---|
136 | poly pInit(void); |
---|
137 | #endif |
---|
138 | |
---|
139 | poly pmInit(char *s, BOOLEAN &ok); /* monom -> poly */ |
---|
140 | poly pOne(void); |
---|
141 | #ifdef MDEBUG |
---|
142 | poly pDBCopy(poly a, char *f, int l); |
---|
143 | #define pCopy(A) pDBCopy(A,__FILE__,__LINE__) |
---|
144 | #else |
---|
145 | poly pCopy(poly a); |
---|
146 | #endif |
---|
147 | |
---|
148 | void ppDelete(poly * a, ring r); |
---|
149 | #ifdef MDEBUG |
---|
150 | #define pDelete(a) pDBDelete((a),__FILE__,__LINE__) |
---|
151 | void pDBDelete(poly * a, char * f, int l); |
---|
152 | #define pDelete1(a) pDBDelete1((a),__FILE__,__LINE__) |
---|
153 | void pDBDelete1(poly * a, char * f, int l); |
---|
154 | #define pFree1(a) {pDBFree1((a),__FILE__,__LINE__);(a)=NULL;} |
---|
155 | void pDBFree1(poly a, char * f, int l); |
---|
156 | #else |
---|
157 | void pDelete(poly * a); |
---|
158 | void pDelete1(poly * a); |
---|
159 | #define pFree1(a) mmFreeSpecialized((ADDRESS)a) |
---|
160 | #endif |
---|
161 | |
---|
162 | /*-------------operations on polynomials:------------*/ |
---|
163 | poly pAdd(poly p1, poly p2); |
---|
164 | poly pNeg(poly p); |
---|
165 | poly pSub(poly a, poly b); |
---|
166 | poly pMult(poly a, poly b); |
---|
167 | void pMultN(poly a, number c); |
---|
168 | poly pMultCopyN(poly a, number c); |
---|
169 | poly pPower(poly p, int i); |
---|
170 | |
---|
171 | BOOLEAN pEqual(poly a, poly b); |
---|
172 | |
---|
173 | #ifdef macintosh |
---|
174 | BOOLEAN pDivisibleBy(poly a, poly b); |
---|
175 | #else |
---|
176 | inline BOOLEAN pDivisibleBy(poly a, poly b) |
---|
177 | { |
---|
178 | if ((a!=NULL)&&((a->exp[0]==0) || (a->exp[0] == b->exp[0]))) |
---|
179 | { |
---|
180 | int i=pVariables; |
---|
181 | short *e1=&(a->exp[1]); |
---|
182 | short *e2=&(b->exp[1]); |
---|
183 | if ((*e1) > (*e2)) return FALSE; |
---|
184 | do |
---|
185 | { |
---|
186 | i--; |
---|
187 | if (i == 0) return TRUE; |
---|
188 | e1++; |
---|
189 | e2++; |
---|
190 | } while ((*e1) <= (*e2)); |
---|
191 | } |
---|
192 | return FALSE; |
---|
193 | } |
---|
194 | #endif |
---|
195 | |
---|
196 | poly pDivide(poly a, poly b); |
---|
197 | poly pDivideM(poly a, poly b); |
---|
198 | void pLcm(poly a, poly b, poly m); |
---|
199 | poly pDiff(poly a, int k); |
---|
200 | poly pDiffOp(poly a, poly b,BOOLEAN multiply); |
---|
201 | |
---|
202 | int pLength(poly a); |
---|
203 | #ifdef MDEBUG |
---|
204 | poly pDBHead(poly p,char *f, int l); |
---|
205 | #define pHead(A) pDBHead(A,__FILE__,__LINE__) |
---|
206 | poly pDBHead0(poly p,char *f, int l); |
---|
207 | #define pHead0(A) pDBHead0(A,__FILE__,__LINE__) |
---|
208 | #else |
---|
209 | poly pHead(poly p); |
---|
210 | poly pHead0(poly p); |
---|
211 | #endif |
---|
212 | int pMaxComp(poly p); |
---|
213 | int pMinComp(poly p); |
---|
214 | int pWeight(int c); |
---|
215 | void pSetCompP(poly a, int i); |
---|
216 | |
---|
217 | char* pString(poly p); |
---|
218 | char* pString0(poly p); |
---|
219 | void pWrite(poly p); |
---|
220 | void pWrite0(poly p); |
---|
221 | void wrp(poly p); |
---|
222 | |
---|
223 | void pEnlargeSet(polyset *p, int length, int increment); |
---|
224 | poly pISet(int i); |
---|
225 | |
---|
226 | void pContent(poly p); |
---|
227 | void pCleardenom(poly p); |
---|
228 | |
---|
229 | poly pHomogen (poly p, int varnum); |
---|
230 | /*- homogenizes p by multiplying certain powers of the varnum-th variable -*/ |
---|
231 | poly pDehomogen (poly p1,poly p2,number n); |
---|
232 | /*replaces the maximal powers of the leading monomial of p2 in p1 by |
---|
233 | * the same powers of n, utility for dehomogenization*/ |
---|
234 | BOOLEAN pIsHomogeneous (poly p); |
---|
235 | poly pDivByMonom (poly p1,poly p2); |
---|
236 | /*returns the leading monomial of p1 divided by the maximal power of that |
---|
237 | *of p2*/ |
---|
238 | void pCancelPolyByMonom (poly p1,poly p2,polyset * P,int * SizeOfSet); |
---|
239 | /*Returns as i-th entry of P the coefficient of the (i-1) power of |
---|
240 | * the leading monomial of p2 in p1*/ |
---|
241 | poly pOrdPoly (poly p); |
---|
242 | poly pPermPoly (poly p, int * perm, int OldPvariables, |
---|
243 | int *par_perm=NULL, int OldPar=0); |
---|
244 | poly pOrdPolySchreyer(poly p); |
---|
245 | /*- re-orders a polynomial -*/ |
---|
246 | void pSetSyzComp(int k); |
---|
247 | |
---|
248 | /*BOOLEAN pVectorHasUnitM(poly p, int * k);*/ |
---|
249 | BOOLEAN pVectorHasUnitB(poly p, int * k); |
---|
250 | void pVectorHasUnit(poly p, int * k, int * len); |
---|
251 | poly pTakeOutComp(poly * p, int k); |
---|
252 | poly pTakeOutComp1(poly * p, int k); |
---|
253 | void pDeleteComp(poly * p,int k); |
---|
254 | void pNorm(poly p); |
---|
255 | void pNormalize(poly p); |
---|
256 | poly pSubst(poly p, int n, poly e); |
---|
257 | poly pJet(poly p, int m); |
---|
258 | poly pJetW(poly p, int m, short * iv); |
---|
259 | int pDegW(poly p, short *w); |
---|
260 | |
---|
261 | /*-----------type conversions ----------------------------*/ |
---|
262 | poly pPolys2Vec(polyset p, int len); |
---|
263 | void pVec2Polys(poly v, polyset *p, int *len); |
---|
264 | int pVar(poly m); |
---|
265 | /*-----------specials for spoly-computations--------------*/ |
---|
266 | extern int pMonomSize; |
---|
267 | |
---|
268 | poly pMultT(poly a, poly e); |
---|
269 | poly pCopy1(poly p); // copy of the head monomial: coeff is 0 |
---|
270 | |
---|
271 | int pDivComp(poly p, poly q); |
---|
272 | BOOLEAN pCompareChain (poly p,poly p1,poly p2,poly lcm); |
---|
273 | BOOLEAN pEqualPolys(poly p1,poly p2); |
---|
274 | BOOLEAN pComparePolys(poly p1,poly p2); |
---|
275 | |
---|
276 | |
---|
277 | #ifdef PDEBUG |
---|
278 | #define pTest(A) pDBTest(A,__FILE__,__LINE__) |
---|
279 | BOOLEAN pDBTest(poly p, char *f, int l); |
---|
280 | #else |
---|
281 | #define pTest(A) |
---|
282 | #define pDBTest(A,B,C) |
---|
283 | #endif |
---|
284 | #endif |
---|
285 | |
---|