source: git/kernel/polys.h @ a0d9be

spielwiese
Last change on this file since a0d9be was a0d9be, checked in by Hans Schoenemann <hannes@…>, 14 years ago
pCleardenom -> p_Cleardenom, pCleardenom_n -> p_Cleardenom_n, pContent -> p_Content git-svn-id: file:///usr/local/Singular/svn/trunk@12848 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 17.8 KB
RevLine 
[35aab3]1#ifndef POLYS_H
2#define POLYS_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
[341696]6/* $Id$ */
[35aab3]7/*
8* ABSTRACT - all basic methods to manipulate polynomials of the
9             currRing
10*/
11
12#include "p_polys.h"
13/*
14 Some general remarks:
15 We divide poly operations into roughly 4 categories:
16 Level 2: operations on monomials/polynomials with constant time,
17          or operations which are just dispatchers to other
18          poly routines
19          - implemented in: pInline2.h
20          - debugging only if PDEBUG >= 2
21          - normally inlined, unless PDEBUG >= 2 || NO_INLINE2
22 Level 1: operations on monomials with time proportional to length
23          - implemented in: pInline1.h
24          - debugging only if PDEBUG >= 1
25          - normally inlined, unless PDEBUG >= 1 || NO_INLINE1
26 Level 0: short operations on polynomials with time proportional to
27          length of poly
28          - implemented in pInline0.cc
29          - debugging if PDEBUG
30          - normally _not_ inlined: can be forced with
31            #define DO_PINLINE0
32            #include "pInline0.h"
33 Misc   : operations on polynomials which do not fit in any of the
34          above categories
35          - implemented in: polys*.cc
36          - never inlined
37          - debugging if PDEBUG >= 0
38
39 You can set PDEBUG on a per-file basis, before including "mod2.h" like
40   #define PDEBUG 2
41   #include "mod2.h"
42 However, PDEBUG will only be in effect, if !NDEBUG.
43
44 All p_* operations take as last argument a ring
45 and are ring independent. Their corresponding p* operations are usually
46 just macros to the respective p_*(..,currRing).
47
48*/
49
50/***************************************************************
51 *
52 * Primitives for accessing and setting fields of a poly
53 * poly must be != NULL
54 *
55 ***************************************************************/
56// deletes old coeff before setting the new one
57#define pSetCoeff(p,n)      p_SetCoeff(p,n,currRing)
58
59// Order
60#define pGetOrder(p)        p_GetOrder(p, currRing)
61// don't use this
62#define pSetOrder(p, o)     p_SetOrder(p, o, currRing)
63
64// Component
65#define pGetComp(p)         _p_GetComp(p, currRing)
66#define pSetComp(p,v)       p_SetComp(p,v, currRing)
67#define pIncrComp(p)        p_IncrComp(p,currRing)
68#define pDecrComp(p)        p_DecrComp(p,currRing)
69#define pAddComp(p,v)       p_AddComp(p,v,currRing)
70#define pSubComp(p,v)       p_SubComp(p,v,currRing)
71
72// Exponent
73#define pGetExp(p,i)        p_GetExp(p, i, currRing)
74#define pSetExp(p,i,v)      p_SetExp(p, i, v, currRing)
75#define pIncrExp(p,i)       p_IncrExp(p,i, currRing)
76#define pDecrExp(p,i)       p_DecrExp(p,i, currRing)
77#define pAddExp(p,i,v)      p_AddExp(p,i,v, currRing)
78#define pSubExp(p,i,v)      p_SubExp(p,i,v, currRing)
79#define pMultExp(p,i,v)     p_MultExp(p,i,v, currRing)
80#define pGetExpSum(p1, p2, i)    p_GetExpSum(p1, p2, i, currRing)
81#define pGetExpDiff(p1, p2, i)   p_GetExpDiff(p1, p2, i, currRing)
82
83/***************************************************************
84 *
85 * Allocation/Initalization/Deletion
86 * except for pDeleteLm and pHead, all polys must be != NULL
87 *
88 ***************************************************************/
89// allocates the space for a new monomial -- no initialization !!!
90#define pNew()          p_New(currRing)
91// allocates a new monomial and initializes everything to 0
92#define pInit()         p_Init(currRing)
93// like pInit, except that expvector is initialized to that of p,
94// p must be != NULL
95#define pLmInit(p)  p_LmInit(p, currRing)
96// returns newly allocated copy of Lm(p), coef is copied, next=NULL,
97// p might be NULL
98#define pHead(p)        p_Head(p, currRing)
99// if *p_ptr != NULL, delete p_ptr->coef, *p_ptr, and set *p_ptr to
100// pNext(*p_ptr)
101static inline void pDeleteLm(poly *p) {p_DeleteLm(p, currRing);}
102// if (p!=NULL) delete p-coef and p
103static inline void pDeleteLm(poly p)  {p_DeleteLm(p, currRing);}
104// frees the space of the monomial m, assumes m != NULL
105// coef is not freed, m is not advanced
106static inline void pLmFree(poly p)    {p_LmFree(p, currRing);}
107// like pLmFree, but advances p
108static inline void pLmFree(poly *p)   {p_LmFree(p, currRing);}
109// assumes p != NULL, deletes p, returns pNext(p)
110#define pLmFreeAndNext(p) p_LmFreeAndNext(p, currRing)
111// assume p != NULL, deletes Lm(p)->coef and Lm(p)
112#define pLmDelete(p)    p_LmDelete(p, currRing)
113// like pLmDelete, returns pNext(p)
114#define pLmDeleteAndNext(p) p_LmDeleteAndNext(p, currRing)
115// used by iparith.cc
116extern poly pHeadProc(poly p);
117
118/***************************************************************
119 *
120 * Operation on ExpVectors: assumes polys != NULL
121 *
122 ***************************************************************/
123
124#define pExpVectorCopy(d_p, s_p)    p_ExpVectorCopy(d_p, s_p, currRing)
125#define pExpVectorAdd(p1, p2)       p_ExpVectorAdd(p1, p2, currRing)
126#define pExpVectorSub(p1, p2)       p_ExpVectorSub(p1, p2, currRing)
127#define pExpVectorAddSub(p1, p2, p3)p_ExpVectorAddSub(p1, p2, p3, currRing)
128#define pExpVectorSum(pr, p1, p2)   p_ExpVectorSum(pr, p1, p2, currRing)
129#define pExpVectorDiff(pr, p1, p2)  p_ExpVectorDiff(pr, p1, p2, currRing)
130#define pExpVectorEqual(p1, p2)     p_ExpVectorEqual(p1, p2, currRing)
131#define pExpVectorQuerSum(p)        p_ExpVectorQuerSum(p, currRing)
132
133// Gets a copy of (resp. set) the exponent vector, where e is assumed
[0b5e3d]134// to point to (r->N +1)*sizeof(long) memory. Exponents are
[35aab3]135// filled in as follows: comp, e_1, .., e_n
136#define pGetExpV(p, e)      p_GetExpV(p, e, currRing)
137#define pSetExpV(p, e)      p_SetExpV(p, e, currRing)
138
139/***************************************************************
140 *
141 * Comparisons: they are all done without regarding coeffs
142 *
143 ***************************************************************/
144// returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
145#define pLmCmp(p,q)         p_LmCmp(p,q,currRing)
146// executes axtionE|actionG|actionS if p=q|p>q|p<q w.r.t monomial ordering
147// action should be a "goto ..."
148#define pLmCmpAction(p,q, actionE, actionG, actionS)  \
149  _p_LmCmpAction(p,q,currRing, actionE, actionG,actionS)
150
151#define pLmEqual(p1, p2)     pExpVectorEqual(p1, p2)
152
153// pCmp: args may be NULL
154// returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
155#define pCmp(p1, p2)    p_Cmp(p1, p2, currRing)
156
157
158/***************************************************************
159 *
160 * Divisiblity tests, args must be != NULL, except for
161 * pDivisbleBy
162 *
163 ***************************************************************/
164// returns TRUE, if leading monom of a divides leading monom of b
165// i.e., if there exists a expvector c > 0, s.t. b = a + c;
166#define pDivisibleBy(a, b)  p_DivisibleBy(a,b,currRing)
167// like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
168#define pLmDivisibleBy(a,b)  p_LmDivisibleBy(a,b,currRing)
169// like pLmDivisibleBy, does not check components
170#define pLmDivisibleByNoComp(a, b) p_LmDivisibleByNoComp(a,b,currRing)
171// Divisibility tests based on Short Exponent vectors
172// sev_a     == pGetShortExpVector(a)
173// not_sev_b == ~ pGetShortExpVector(b)
174#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b) \
175  p_LmShortDivisibleBy(a, sev_a, b, not_sev_b, currRing)
[cea6f3]176#define pLmRingShortDivisibleBy(a, sev_a, b, not_sev_b) \
177  p_LmRingShortDivisibleBy(a, sev_a, b, not_sev_b, currRing)
[35aab3]178// returns the "Short Exponent Vector" -- used to speed up divisibility
179// tests (see polys-impl.cc )
180#define pGetShortExpVector(a)   p_GetShortExpVector(a, currRing)
181
182/***************************************************************
183 *
184 * Copying/Deleteion of polys: args may be NULL
185 *
186 ***************************************************************/
187// return a copy of the poly
188#define pCopy(p) p_Copy(p, currRing)
189#define pDelete(p_ptr)  p_Delete(p_ptr, currRing)
190
191/***************************************************************
192 *
[95450e]193 * Copying/Deletion of polys: args may be NULL
[35aab3]194 *  - p/q as arg mean a poly
195 *  - m a monomial
196 *  - n a number
197 *  - pp (resp. qq, mm, nn) means arg is constant
198 *  - p (resp, q, m, n)     means arg is destroyed
199 *
200 ***************************************************************/
201#define pNeg(p)                     p_Neg(p, currRing)
202#define ppMult_nn(p, n)             pp_Mult_nn(p, n, currRing)
203#define pMult_nn(p, n)              p_Mult_nn(p, n, currRing)
204#define ppMult_mm(p, m)             pp_Mult_mm(p, m, currRing)
205#define pMult_mm(p, m)              p_Mult_mm(p, m, currRing)
206#define pAdd(p, q)                  p_Add_q(p, q, currRing)
[690e21e]207#define pPower(p, q)                p_Power(p, q, currRing)
[35aab3]208#define pMinus_mm_Mult_qq(p, m, q)  p_Minus_mm_Mult_qq(p, m, q, currRing)
209#define pPlus_mm_Mult_qq(p, m, q)   p_Plus_mm_Mult_qq(p, m, q, currRing)
210#define pMult(p, q)                 p_Mult_q(p, q, currRing)
211#define ppMult_qq(p, q)             pp_Mult_qq(p, q, currRing)
212// p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
213#define ppMult_Coeff_mm_DivSelect(p, m)   pp_Mult_Coeff_mm_DivSelect(p, m, currRing)
214/*************************************************************************
215 *
216 * Sort routines
217 *
218 *************************************************************************/
219// sorts p, assumes all monomials in p are different
220#define pSortMerger(p)          pSort(p)
221#define pSort(p)                p_SortMerge(p, currRing)
222
223// sorts p, p may have equal monomials
224#define pSortAdd(p)             p_SortAdd(p, currRing)
225
226
227// Assume: If considerd only as poly in any component of p
228// (say, monomials of other components of p are set to 0),
229// then p is already sorted correctly
230#define pSortCompCorrect(p) pSort(p)
231
232/***************************************************************
233 *
234 * Predicates on polys/Lm's
235 *
236 ***************************************************************/
237// return true if all p is eihter NULL, or if all exponents
238// of p are 0 and Comp of p is zero
239#define   pIsConstantComp(p)        p_IsConstantComp(p, currRing)
240// like above, except that Comp might be != 0
241#define   pIsConstant(p)            p_IsConstant(p,currRing)
242// return true if the Lm is a constant <>0
243#define   pIsUnit(p)            p_IsUnit(p,currRing)
244// like above, except that p must be != NULL
245#define   pLmIsConstantComp(p)      p_LmIsConstantComp(p, currRing)
246#define   pLmIsConstant(p)          p_LmIsConstant(p,currRing)
247
248// return TRUE if all monomials of p are constant
249#define   pIsConstantPoly(p)        p_IsConstantPoly(p, currRing)
250
251#define   pIsPurePower(p)   p_IsPurePower(p, currRing)
[2f0d83f]252#define   pIsUnivariate(p)  p_IsUnivariate(p, currRing)
[35aab3]253#define   pIsVector(p)      (pGetComp(p)>0)
[95450e]254#define   pGetVariables(p,e)  p_GetVariables(p, e, currRing)
[35aab3]255
256/***************************************************************
257 *
258 * Old stuff
259 *
260 ***************************************************************/
261
262#define pFetchCopy(r,p)     _pFetchCopy(r,p)
263// Similar to pFetchCopy, except that poly p is deleted
264#define pFetchCopyDelete(r, p) _pFetchCopyDelete(r, p)
265
266typedef poly*   polyset;
267extern int      pVariables;
268extern int      pOrdSgn;
269extern BOOLEAN  pLexOrder;
270extern poly     ppNoether;
271extern BOOLEAN  pVectorOut;
272
273/*-------------predicate on polys ----------------------*/
274BOOLEAN   pHasNotCF(poly p1, poly p2);   /*has no common factor ?*/
275void      pSplit(poly p, poly * r);   /*p => IN(p), r => REST(p) */
276
277
278
279/*-------------ring management:----------------------*/
280//extern void pChangeRing(ring newRing);
[8c5988]281extern void pSetGlobals(const ring r, BOOLEAN complete = TRUE);
[35aab3]282// resets the pFDeg and pLDeg: if pLDeg is not given, it is
283// set to currRing->pLDegOrig, i.e. to the respective LDegProc which
284// only uses pFDeg (and not pDeg, or pTotalDegree, etc).
285// If you use this, make sure your procs does not make any assumptions
286// on oredering and/or OrdIndex -- otherwise they might return wrong results
287// on strat->tailRing
288extern void pSetDegProcs(pFDegProc new_FDeg, pLDegProc new_lDeg = NULL);
289// restores pFDeg and pLDeg:
290extern void pRestoreDegProcs(pFDegProc old_FDeg, pLDegProc old_lDeg);
291
292/*-----------the ordering of monomials:-------------*/
293#define pSetm(p)    p_Setm(p, currRing)
294// TODO:
295#define pSetmComp   pSetm
296
297/***************************************************************
298 *
299 * Degree stuff -- see p_polys.cc for explainations
300 *
301 ***************************************************************/
302extern pLDegProc pLDeg;
303extern pFDegProc pFDeg;
[8c5988]304int  pWeight(int c, const ring r = currRing);
[107986]305long pDeg(poly p,const ring r = currRing);
306long pTotaldegree(poly p,const ring r = currRing);
307long pWTotaldegree(poly p,const ring r = currRing);
308long pWDegree(poly p,const ring r = currRing);
309long pLDeg0(poly p,int *l,const ring r = currRing);
310long pLDeg0c(poly p,int *l,const ring r = currRing);
311long pLDegb(poly p,int *l,const ring r = currRing);
312long pLDeg1(poly p,int *l,const ring r = currRing);
313long pLDeg1c(poly p,int *l,const ring r = currRing);
314long pLDeg1_Deg(poly p,int *l,const ring r = currRing);
315long pLDeg1c_Deg(poly p,int *l,const ring r = currRing);
316long pLDeg1_Totaldegree(poly p,int *l,const ring r = currRing);
317long pLDeg1c_Totaldegree(poly p,int *l,const ring r = currRing);
318long pLDeg1_WFirstTotalDegree(poly p,int *l,const ring r=currRing);
319long pLDeg1c_WFirstTotalDegree(poly p,int *l,const ring r=currRing);
[35aab3]320
321/*-------------pComp for syzygies:-------------------*/
322
323void pSetModDeg(intvec *w);
324
325
326
327
[85e68dd]328poly      pmInit(const char *s, BOOLEAN &ok); /* monom -> poly, interpreter */
[107986]329const char *    p_Read(const char *s, poly &p,const ring r); /* monom -> poly */
330void      ppDelete(poly * a,const ring r);
[35aab3]331
332/*-------------operations on polynomials:------------*/
333poly      pSub(poly a, poly b);
[690e21e]334poly      p_Power(poly p, int i, const ring r);
[35aab3]335
336// ----------------- define to enable new p_procs -----*/
337
338poly      pDivide(poly a, poly b);
339poly      pDivideM(poly a, poly b);
340void      pLcm(poly a, poly b, poly m);
341poly      pDiff(poly a, int k);
342poly      pDiffOp(poly a, poly b,BOOLEAN multiply);
343
344#define   pMaxComp(p)   p_MaxComp(p, currRing)
345#define   pMinComp(p)   p_MinComp(p, currRing)
346int pMaxCompProc(poly p);
347
348#define   pOneComp(p)       p_OneComp(p, currRing)
349#define   pSetCompP(a,i)    p_SetCompP(a, i, currRing)
350
351// let's inline those, so that we can call them from the debugger
352inline char*   pString(poly p)    {return p_String(p, currRing, currRing);}
353inline char*   pString0(poly p)   {return p_String0(p, currRing, currRing);}
354inline void    pWrite(poly p)     {p_Write(p, currRing, currRing);}
355inline void    pWrite0(poly p)    {p_Write0(p, currRing, currRing);}
356inline void    wrp(poly p)        {p_wrp(p, currRing, currRing);}
357
358void      pEnlargeSet(polyset *p, int length, int increment);
359#define   pISet(i) p_ISet(i,currRing)
360#define   pNSet(n) p_NSet(n,currRing)
[1c33e0d]361
362poly p_One(const ring r);
[a88544]363#define   pOne()   p_One(currRing)
[35aab3]364
[a0d9be]365void      p_Content(poly p, const ring r);
[56153ef]366void      pSimpleContent(poly p, int s);
[a0d9be]367poly      p_Cleardenom(poly p, const ring r);
368void      p_Cleardenom_n(poly p, const ring r,number &c);
[107986]369void      p_Normalize(poly p,const ring r);
[967a9d]370number    p_GetAllDenom(poly ph, const ring r);
[35aab3]371#define   pNormalize(p) p_Normalize(p,currRing)
[7ba059]372int       pSize( poly p );
373
[35aab3]374
375// homogenizes p by multiplying certain powers of the varnum-th variable
376poly      pHomogen (poly p, int varnum);
377
378// replaces the maximal powers of the leading monomial of p2 in p1 by
379// the same powers of n, utility for dehomogenization
380poly      pDehomogen (poly p1,poly p2,number n);
381BOOLEAN   pIsHomogeneous (poly p);
382
383// returns the leading monomial of p1 divided by the maximal power of
384// that of p2
385poly      pDivByMonom (poly p1,poly p2);
386
387// Returns as i-th entry of P the coefficient of the (i-1) power of
388// the leading monomial of p2 in p1
389void      pCancelPolyByMonom (poly p1,poly p2,polyset * P,int * SizeOfSet);
390
[107986]391poly      pPermPoly (poly p, int * perm,const ring OldRing, nMapFunc nMap,
[35aab3]392                     int *par_perm=NULL, int OldPar=0);
393
394/*BOOLEAN   pVectorHasUnitM(poly p, int * k);*/
395BOOLEAN   pVectorHasUnitB(poly p, int * k);
396void      pVectorHasUnit(poly p, int * k, int * len);
397poly      pTakeOutComp1(poly * p, int k);
398// Splits *p into two polys: *q which consists of all monoms with
399// component == comp and *p of all other monoms *lq == pLength(*q)
400// On return all components pf *q == 0
[0b5e3d]401void pTakeOutComp(poly *p, long comp, poly *q, int *lq);
[35aab3]402// Similar to pTakeOutComp, except that only those components are
403// taken out whose Order == order
404// ASSUME: monomial ordering is Order compatible, i.e., if m1, m2 Monoms then
405//         m1 >= m2 ==> pGetOrder(m1) >= pGetOrder(m2)
[0b5e3d]406void pDecrOrdTakeOutComp(poly *p, long comp, long order,
[35aab3]407                         poly *q, int *lq);
408// This is something weird -- Don't use it, unless you know what you are doing
409poly      pTakeOutComp(poly * p, int k);
410void      pSetPolyComp(poly p, int comp);
411void      pDeleteComp(poly * p,int k);
412void      pNorm(poly p);
413poly      pSubst(poly p, int n, poly e);
414poly      ppJet(poly p, int m);
415poly      pJet(poly p, int m);
416poly      ppJetW(poly p, int m, short * iv);
417poly      pJetW(poly p, int m, short * iv);
418int pMinDeg(poly p,intvec *w=NULL);
419poly      pSeries(int n,poly p,poly u=NULL,intvec *w=NULL);
420poly      pInvers(int n, poly p,intvec *w=NULL);
421// maximum weigthed degree of all monomials of p, w is indexed from
422// 1..pVariables
[2318f07]423long      pDegW(poly p, const short *w);
[35aab3]424
425/*-----------type conversions ----------------------------*/
426poly  pPolys2Vec(polyset p, int len);
427void  pVec2Polys(poly v, polyset *p, int *len);
[891692]428int   p_Var(poly mi,const ring r);
429#define   pVar(m) p_Var(m,currRing)
[35aab3]430
431/*-----------specials for spoly-computations--------------*/
432BOOLEAN pCompareChain (poly p,poly p1,poly p2,poly lcm);
[107986]433BOOLEAN pCompareChainPart (poly p,poly p1,poly p2,poly lcm);
[14d732]434#define  pEqualPolys(p1,p2) p_EqualPolys(p1,p2,currRing)
[35aab3]435BOOLEAN pComparePolys(poly p1,poly p2);
436
437
438
439/***************************************************************
440 *
441 * PDEBUG stuff
442 *
443 ***************************************************************/
444#ifdef PDEBUG
445#define pTest(p)        _p_Test(p, currRing, PDEBUG)
446#define pLmTest(p)      _p_LmTest(p, currRing, PDEBUG)
447
448#else // ! PDEBUG
449
450#define pTest(p)        ((void)0)
451#define pLmTest(p)      ((void)0)
452#endif
453
454#endif // POLYS_H
Note: See TracBrowser for help on using the repository browser.