source: git/kernel/polys.h @ 85fd90

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