source: git/polys/polys.h @ 74021a

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