source: git/kernel/polys.h @ d72574

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