source: git/polys/polys.h @ 949e57

spielwiese
Last change on this file since 949e57 was 949e57, checked in by Hans Schoenemann <hannes@…>, 13 years ago
pSetDegProcs
  • Property mode set to 100644
File size: 14.2 KB
Line 
1#ifndef POLYS_H
2#define POLYS_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id$ */
7/*
8* ABSTRACT - all basic methods to manipulate polynomials of the
9             currRing
10*/
11
12#include <kernel/p_polys.h>
13
14/***************************************************************
15 *
16 * Primitives for accessing and setting fields of a poly
17 * poly must be != NULL
18 *
19 ***************************************************************/
20// deletes old coeff before setting the new one
21#define pSetCoeff(p,n)      p_SetCoeff(p,n,currRing)
22
23// Order
24#define pGetOrder(p)        p_GetOrder(p, currRing)
25
26// Component
27#define pGetComp(p)         _p_GetComp(p, currRing)
28#define pSetComp(p,v)       p_SetComp(p,v, currRing)
29
30// Exponent
31#define pGetExp(p,i)        p_GetExp(p, i, currRing)
32#define pSetExp(p,i,v)      p_SetExp(p, i, v, currRing)
33#define pIncrExp(p,i)       p_IncrExp(p,i, currRing)
34#define pDecrExp(p,i)       p_DecrExp(p,i, currRing)
35#define pAddExp(p,i,v)      p_AddExp(p,i,v, currRing)
36#define pSubExp(p,i,v)      p_SubExp(p,i,v, currRing)
37#define pMultExp(p,i,v)     p_MultExp(p,i,v, currRing)
38#define pGetExpSum(p1, p2, i)    p_GetExpSum(p1, p2, i, currRing)
39#define pGetExpDiff(p1, p2, i)   p_GetExpDiff(p1, p2, i, currRing)
40
41/***************************************************************
42 *
43 * Allocation/Initalization/Deletion
44 * except for pHead, all polys must be != NULL
45 *
46 ***************************************************************/
47// allocates the space for a new monomial -- no initialization !!!
48#define pNew()          p_New(currRing)
49// allocates a new monomial and initializes everything to 0
50#define pInit()         p_Init(currRing)
51// like pInit, except that expvector is initialized to that of p,
52// p must be != NULL
53#define pLmInit(p)  p_LmInit(p, currRing)
54// returns newly allocated copy of Lm(p), coef is copied, next=NULL,
55// p might be NULL
56#define pHead(p)        p_Head(p, currRing)
57// frees the space of the monomial m, assumes m != NULL
58// coef is not freed, m is not advanced
59static inline void pLmFree(poly p)    {p_LmFree(p, currRing);}
60// like pLmFree, but advances p
61static inline void pLmFree(poly *p)   {p_LmFree(p, currRing);}
62// assumes p != NULL, deletes p, returns pNext(p)
63#define pLmFreeAndNext(p) p_LmFreeAndNext(p, currRing)
64// assume p != NULL, deletes Lm(p)->coef and Lm(p)
65#define pLmDelete(p)    p_LmDelete(p, currRing)
66// like pLmDelete, returns pNext(p)
67#define pLmDeleteAndNext(p) p_LmDeleteAndNext(p, currRing)
68
69/***************************************************************
70 *
71 * Operation on ExpVectors: assumes polys != NULL
72 *
73 ***************************************************************/
74
75#define pExpVectorCopy(d_p, s_p)    p_ExpVectorCopy(d_p, s_p, currRing)
76#define pExpVectorAdd(p1, p2)       p_ExpVectorAdd(p1, p2, currRing)
77#define pExpVectorSub(p1, p2)       p_ExpVectorSub(p1, p2, currRing)
78#define pExpVectorAddSub(p1, p2, p3)p_ExpVectorAddSub(p1, p2, p3, currRing)
79#define pExpVectorSum(pr, p1, p2)   p_ExpVectorSum(pr, p1, p2, currRing)
80#define pExpVectorDiff(pr, p1, p2)  p_ExpVectorDiff(pr, p1, p2, currRing)
81
82// Gets a copy of (resp. set) the exponent vector, where e is assumed
83// to point to (r->N +1)*sizeof(long) memory. Exponents are
84// filled in as follows: comp, e_1, .., e_n
85#define pGetExpV(p, e)      p_GetExpV(p, e, currRing)
86#define pSetExpV(p, e)      p_SetExpV(p, e, currRing)
87
88/***************************************************************
89 *
90 * Comparisons: they are all done without regarding coeffs
91 *
92 ***************************************************************/
93// returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
94#define pLmCmp(p,q)         p_LmCmp(p,q,currRing)
95// executes axtionE|actionG|actionS if p=q|p>q|p<q w.r.t monomial ordering
96// action should be a "goto ..."
97#define pLmCmpAction(p,q, actionE, actionG, actionS)  \
98  _p_LmCmpAction(p,q,currRing, actionE, actionG,actionS)
99
100#define pLmEqual(p1, p2)     p_ExpVectorEqual(p1, p2, currRing)
101
102// pCmp: args may be NULL
103// returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
104#define pCmp(p1, p2)    p_Cmp(p1, p2, currRing)
105
106
107/***************************************************************
108 *
109 * Divisiblity tests, args must be != NULL, except for
110 * pDivisbleBy
111 *
112 ***************************************************************/
113// returns TRUE, if leading monom of a divides leading monom of b
114// i.e., if there exists a expvector c > 0, s.t. b = a + c;
115#define pDivisibleBy(a, b)  p_DivisibleBy(a,b,currRing)
116// like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
117#define pLmDivisibleBy(a,b)  p_LmDivisibleBy(a,b,currRing)
118// like pLmDivisibleBy, does not check components
119#define pLmDivisibleByNoComp(a, b) p_LmDivisibleByNoComp(a,b,currRing)
120// Divisibility tests based on Short Exponent vectors
121// sev_a     == pGetShortExpVector(a)
122// not_sev_b == ~ pGetShortExpVector(b)
123#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b) \
124  p_LmShortDivisibleBy(a, sev_a, b, not_sev_b, currRing)
125#define pLmRingShortDivisibleBy(a, sev_a, b, not_sev_b) \
126  p_LmRingShortDivisibleBy(a, sev_a, b, not_sev_b, currRing)
127// returns the "Short Exponent Vector" -- used to speed up divisibility
128// tests (see polys-impl.cc )
129#define pGetShortExpVector(a)   p_GetShortExpVector(a, currRing)
130#ifdef HAVE_RINGS
131/* divisibility check over ground ring (which may contain zero divisors);
132   TRUE iff LT(f) divides LT(g), i.e., LT(f)*c*m = LT(g), for some
133   coefficient c and some monomial m;
134   does not take components into account */
135BOOLEAN pDivisibleByRingCase(poly f, poly g);
136#endif
137
138/***************************************************************
139 *
140 * Copying/Deleteion of polys: args may be NULL
141 *
142 ***************************************************************/
143// return a copy of the poly
144#define pCopy(p) p_Copy(p, currRing)
145#define pDelete(p_ptr)  p_Delete(p_ptr, currRing)
146
147/***************************************************************
148 *
149 * Copying/Deletion of polys: args may be NULL
150 *  - p/q as arg mean a poly
151 *  - m a monomial
152 *  - n a number
153 *  - pp (resp. qq, mm, nn) means arg is constant
154 *  - p (resp, q, m, n)     means arg is destroyed
155 *
156 ***************************************************************/
157#define pNeg(p)                     p_Neg(p, currRing)
158#define ppMult_nn(p, n)             pp_Mult_nn(p, n, currRing)
159#define pMult_nn(p, n)              p_Mult_nn(p, n, currRing)
160#define ppMult_mm(p, m)             pp_Mult_mm(p, m, currRing)
161#define pMult_mm(p, m)              p_Mult_mm(p, m, currRing)
162#define pAdd(p, q)                  p_Add_q(p, q, currRing)
163#define pPower(p, q)                p_Power(p, q, currRing)
164#define pMinus_mm_Mult_qq(p, m, q)  p_Minus_mm_Mult_qq(p, m, q, currRing)
165#define pPlus_mm_Mult_qq(p, m, q)   p_Plus_mm_Mult_qq(p, m, q, currRing)
166#define pMult(p, q)                 p_Mult_q(p, q, currRing)
167#define ppMult_qq(p, q)             pp_Mult_qq(p, q, currRing)
168// p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
169#define ppMult_Coeff_mm_DivSelect(p, m)   pp_Mult_Coeff_mm_DivSelect(p, m, currRing)
170/*************************************************************************
171 *
172 * Sort routines
173 *
174 *************************************************************************/
175// sorts p, assumes all monomials in p are different
176#define pSortMerger(p)          p_SortMerge(p, currRing)
177#define pSort(p)                p_SortMerge(p, currRing)
178
179// sorts p, p may have equal monomials
180#define pSortAdd(p)             p_SortAdd(p, currRing)
181
182
183// Assume: If considerd only as poly in any component of p
184// (say, monomials of other components of p are set to 0),
185// then p is already sorted correctly
186#define pSortCompCorrect(p) pSort(p)
187
188/***************************************************************
189 *
190 * Predicates on polys/Lm's
191 *
192 ***************************************************************/
193// return true if all p is eihter NULL, or if all exponents
194// of p are 0 and Comp of p is zero
195#define   pIsConstantComp(p)        p_IsConstantComp(p, currRing)
196// like above, except that Comp might be != 0
197#define   pIsConstant(p)            p_IsConstant(p,currRing)
198// return true if the Lm is a constant <>0
199#define   pIsUnit(p)            p_IsUnit(p,currRing)
200// like above, except that p must be != NULL
201#define   pLmIsConstantComp(p)      p_LmIsConstantComp(p, currRing)
202#define   pLmIsConstant(p)          p_LmIsConstant(p,currRing)
203
204// return TRUE if all monomials of p are constant
205#define   pIsConstantPoly(p)        p_IsConstantPoly(p, currRing)
206
207#define   pIsPurePower(p)   p_IsPurePower(p, currRing)
208#define   pIsUnivariate(p)  p_IsUnivariate(p, currRing)
209#define   pIsVector(p)      (pGetComp(p)>0)
210#define   pGetVariables(p,e)  p_GetVariables(p, e, currRing)
211
212/***************************************************************
213 *
214 * Old stuff
215 *
216 ***************************************************************/
217
218typedef poly*   polyset;
219extern int      pOrdSgn;
220extern BOOLEAN  pLexOrder;
221extern poly     ppNoether;
222extern BOOLEAN  pVectorOut;
223
224/*-------------predicate on polys ----------------------*/
225#define  pHasNotCF(p1,p2)   p_HasNotCF(p1,p2,currRing)
226                                /*has no common factor ?*/
227#define  pSplit(p,r)        p_Split(p,r)
228                                /*p => IN(p), r => REST(p) */
229
230
231
232/*-----------the ordering of monomials:-------------*/
233#define pSetm(p)    p_Setm(p, currRing)
234// TODO:
235#define pSetmComp(p)   p_Setm(p, currRing)
236
237/***************************************************************
238 *
239 * Degree stuff -- see p_polys.cc for explainations
240 *
241 ***************************************************************/
242static inline long  pFDeg(const poly p, const ring r)  { return r->pFDeg(p,r); }
243static inline long  pLDeg(const poly p,  int *l, const ring r)  { return r->pLDeg(p,l,r); }
244#define pWeight(c) p_Weight(c,currRing)
245#define pDeg(p)    p_Deg(p,currRing)
246static inline long pTotaldegree(poly p) { return p_Totaldegree(p,currRing); }
247#define pWTotaldegree(p) p_WTotaldegree(p,currRing)
248#define pWDegree(poly p) p_WDegree(p,currRing)
249
250/*-------------pComp for syzygies:-------------------*/
251
252void pSetModDeg(intvec *w);
253
254
255
256
257/*-------------operations on polynomials:------------*/
258#define   pSub(a,b) p_Sub(a,b,currRing)
259
260#define pmInit(a,b) p_mInit(a,b,currRing)
261
262// ----------------- define to enable new p_procs -----*/
263
264#define pDivide(a,b) p_Divide(a,b,currRing)
265#define pLcm(a,b,m) p_Lcm(a,b,m,currRing)
266#define pDiff(a,b)  p_Diff(a,b,currRing)
267#define pDiffOp(a,b,m) p_DiffOp(a,b,m,currRing)
268
269#define   pMaxComp(p)   p_MaxComp(p, currRing)
270#define   pMinComp(p)   p_MinComp(p, currRing)
271int pMaxCompProc(poly p);
272
273#define   pOneComp(p)       p_OneComp(p, currRing)
274#define   pSetCompP(a,i)    p_SetCompP(a, i, currRing)
275
276// let's inline those, so that we can call them from the debugger
277inline char*   pString(poly p)    {return p_String(p, currRing, currRing);}
278inline char*   pString0(poly p)   {return p_String0(p, currRing, currRing);}
279inline void    pWrite(poly p)     {p_Write(p, currRing, currRing);}
280inline void    pWrite0(poly p)    {p_Write0(p, currRing, currRing);}
281inline void    wrp(poly p)        {p_wrp(p, currRing, currRing);}
282
283void      pEnlargeSet(polyset *p, int length, int increment);
284#define   pISet(i) p_ISet(i,currRing)
285#define   pNSet(n) p_NSet(n,currRing)
286
287#define   pOne()   p_One(currRing)
288
289#define   pNormalize(p) p_Normalize(p,currRing)
290#define   pSize(p)      p_Size(p,currRing)
291
292
293// homogenizes p by multiplying certain powers of the varnum-th variable
294#define  pHomogen(p,varnum) p_Homogen(p,varnum,currRing)
295
296BOOLEAN   pIsHomogeneous (poly p);
297// // replaces the maximal powers of the leading monomial of p2 in p1 by
298// // the same powers of n, utility for dehomogenization
299// #define   pDehomogen(p1,p2,n) p_Dehomgen(p1,p2,n,currRing)
300// #define   pIsHomogen(p)       p_IsHomggen(p,currRing)
301
302poly      pPermPoly (poly p, int * perm,const ring OldRing, nMapFunc nMap,
303                     int *par_perm=NULL, int OldPar=0);
304
305/*BOOLEAN   pVectorHasUnitM(poly p, int * k);*/
306#define   pVectorHasUnitB(p,k) p_VectorHasUnitB(p,k,currRing)
307#define   pVectorHasUnit(p,k,l) p_VectorHasUnit(p,k,l,currRing)
308#define   pTakeOutComp1(p,k)    p_TakeOutComp1(p,k,currRing)
309
310// Splits *p into two polys: *q which consists of all monoms with
311// component == comp and *p of all other monoms *lq == pLength(*q)
312// On return all components pf *q == 0
313void pTakeOutComp(poly *p, long comp, poly *q, int *lq);
314
315// This is something weird -- Don't use it, unless you know what you are doing
316poly      pTakeOutComp(poly * p, int k);
317/* old spielwiese
318#define   pTakeOutComp(p,k,q,lq)    p_TakeOutComp(p,k,q,lq,currRing)
319
320// Similar to pTakeOutComp, except that only those components are
321// taken out whose Order == order
322// ASSUME: monomial ordering is Order compatible, i.e., if m1, m2 Monoms then
323//         m1 >= m2 ==> pGetOrder(m1) >= pGetOrder(m2)
324#define   pDecrOrdTakeOutComp(p,c,o,q,lq) p_DecrOrdTakeOutComp(p,c,o,q,lq,currRing)
325*/
326void      pSetPolyComp(poly p, int comp);
327#define   pDeleteComp(p,k) p_DeleteComp(p,k,currRing)
328void      pNorm(poly p);
329poly      pSubst(poly p, int n, poly e);
330poly      ppJet(poly p, int m);
331poly      pJet(poly p, int m);
332poly      ppJetW(poly p, int m, short * iv);
333poly      pJetW(poly p, int m, short * iv);
334int pMinDeg(poly p,intvec *w=NULL);
335poly      pSeries(int n,poly p,poly u=NULL,intvec *w=NULL);
336poly      pInvers(int n, poly p,intvec *w=NULL);
337// maximum weigthed degree of all monomials of p, w is indexed from
338// 1..pVariables
339long      pDegW(poly p, const short *w);
340
341/*-----------type conversions ----------------------------*/
342//poly  pPolys2Vec(polyset p, int len);
343void  pVec2Polys(poly v, polyset *p, int *len);
344int   p_Var(poly mi,const ring r);
345#define   pVar(m) p_Var(m,currRing)
346
347/*-----------specials for spoly-computations--------------*/
348BOOLEAN pCompareChain (poly p,poly p1,poly p2,poly lcm);
349BOOLEAN pCompareChainPart (poly p,poly p1,poly p2,poly lcm);
350#define  pEqualPolys(p1,p2) p_EqualPolys(p1,p2,currRing)
351BOOLEAN pComparePolys(poly p1,poly p2);
352
353
354
355/***************************************************************
356 *
357 * PDEBUG stuff
358 *
359 ***************************************************************/
360#ifdef PDEBUG
361#define pTest(p)        _p_Test(p, currRing, PDEBUG)
362#define pLmTest(p)      _p_LmTest(p, currRing, PDEBUG)
363
364#else // ! PDEBUG
365
366#define pTest(p)        ((void)0)
367#define pLmTest(p)      ((void)0)
368#endif
369
370#endif // POLYS_H
Note: See TracBrowser for help on using the repository browser.