source: git/libpolys/polys/polys.h @ c6e80e

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