source: git/Singular/polys.h @ 9adbf8

fieker-DuValspielwiese
Last change on this file since 9adbf8 was 9adbf8, checked in by Olaf Bachmann <obachman@…>, 24 years ago
* p_MaxComp, etc git-svn-id: file:///usr/local/Singular/svn/trunk@4623 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 14.1 KB
Line 
1#ifndef POLYS_H
2#define POLYS_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: polys.h,v 1.39 2000-09-20 12:56:37 obachman Exp $ */
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 pExpVectorSum(pr, p1, p2)   p_ExpVectorSum(pr, p1, p2, currRing)
128#define pExpVectorDiff(pr, p1, p2)  p_ExpVectorDiff(pr, p1, p2, currRing)
129#define pExpVectorEqual(p1, p2)     p_ExpVectorEqual(p1, p2, currRing)
130#define pExpVectorQuerSum(p)        p_ExpVectorQuerSum(p, currRing)
131
132// Gets a copy of (resp. set) the exponent vector, where e is assumed
133// to point to (r->N +1)*sizeof(Exponent_t) memory. Exponents are
134// filled in as follows: comp, e_1, .., e_n
135#define pGetExpV(p, e)      p_GetExpV(p, e, currRing)
136#define pSetExpV(p, e)      p_SetExpV(p, e, currRing)
137
138/***************************************************************
139 *
140 * Comparisons: they are all done without regarding coeffs
141 *
142 ***************************************************************/
143// returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
144#define pLmCmp(p,q)         p_LmCmp(p,q,currRing)
145// executes axtionE|actionG|actionS if p=q|p>q|p<q w.r.t monomial ordering
146// action should be a "goto ..."
147#define pLmCmpAction(p,q, actionE, actionG, actionS)  \
148  _p_LmCmpAction(p,q,currRing, actionE, actionG,actionS)
149
150#define pLmEqual(p1, p2)     pExpVectorEqual(p1, p2)
151
152// pCmp: args may be NULL
153// returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
154#define pCmp(p1, p2)    p_Cmp(p1, p2, currRing)
155
156 
157/***************************************************************
158 *
159 * Divisiblity tests, args must be != NULL, except for
160 * pDivisbleBy
161 *
162 ***************************************************************/
163// returns TRUE, if leading monom of a divides leading monom of b
164// i.e., if there exists a expvector c > 0, s.t. b = a + c;
165#define pDivisibleBy(a, b)  p_DivisibleBy(a,b,currRing)
166// like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
167#define pLmDivisibleBy(a,b)  p_LmDivisibleBy(a,b,currRing)
168// like pLmDivisibleBy, does not check components
169#define pLmDivisibleByNoComp(a, b) p_LmDivisibleByNoComp(a,b,currRing)
170// Divisibility tests based on Short Exponent vectors
171// sev_a     == pGetShortExpVector(a)
172// not_sev_b == ~ pGetShortExpVector(b)
173#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b) \
174  p_LmShortDivisibleBy(a, sev_a, b, not_sev_b, currRing)
175// returns the "Short Exponent Vector" -- used to speed up divisibility
176// tests (see polys-impl.cc )
177#define pGetShortExpVector(a)   p_GetShortExpVector(a, currRing)
178
179/***************************************************************
180 *
181 * Copying/Deleteion of polys: args may be NULL
182 *
183 ***************************************************************/
184// return a copy of the poly
185#define pCopy(p) p_Copy(p, currRing)
186#define pDelete(p_ptr)  p_Delete(p_ptr, currRing)
187
188/***************************************************************
189 *
190 * Copying/Deleteion of polys: args may be NULL
191 *  - p/q as arg mean a poly
192 *  - m a monomial
193 *  - n a number
194 *  - pp (resp. qq, mm, nn) means arg is constant
195 *  - p (resp, q, m, n)     means arg is destroyed
196 *
197 ***************************************************************/
198#define pNeg(p)                     p_Neg(p, currRing)
199#define ppMult_nn(p, n)             pp_Mult_nn(p, n, currRing)
200#define pMult_nn(p, n)              p_Mult_nn(p, n, currRing)
201#define ppMult_mm(p, m)             pp_Mult_mm(p, m, currRing)
202#define pMult_mm(p, m)              p_Mult_mm(p, m, currRing)
203#define pAdd(p, q)                  p_Add_q(p, q, currRing)
204#define pMinus_mm_Mult_qq(p, m, q)  p_Minus_mm_Mult_qq(p, m, q, currRing)
205#define pPlus_mm_Mult_qq(p, m, q)   p_Plus_mm_Mult_qq(p, m, q, currRing)
206#define pMult(p, q)                 p_Mult_q(p, q, currRing)
207#define ppMult_qq(p, q)             pp_Mult_qq(p, q, currRing)
208
209/***************************************************************
210 *
211 * Old stuff
212 *
213 ***************************************************************/
214
215#define pFetchCopy(r,p)     _pFetchCopy(r,p)
216// Similar to pFetchCopy, except that poly p is deleted
217#define pFetchCopyDelete(r, p) _pFetchCopyDelete(r, p)
218
219typedef poly*   polyset;
220extern int      pVariables;
221extern int      pOrdSgn;
222extern BOOLEAN  pLexOrder;
223extern BOOLEAN  pMixedOrder;
224extern poly     ppNoether;
225extern BOOLEAN  pVectorOut;
226// 1 for lex ordering (except ls), -1 otherwise
227extern int pComponentOrder;
228
229/*-------------predicate on polys ----------------------*/
230BOOLEAN   pIsConstant(const poly p);
231BOOLEAN   pIsConstantPoly(poly p);
232BOOLEAN   pIsConstantComp(const poly p);
233int       pIsPurePower(const poly p);
234#define   pIsVector(p)     (pGetComp(p)!=0)
235BOOLEAN   pHasNotCF(poly p1, poly p2);   /*has no common factor ?*/
236void      pSplit(poly p, poly * r);   /*p => IN(p), r => REST(p) */
237
238
239
240/*-------------ring management:----------------------*/
241//extern void pChangeRing(ring newRing);
242extern void pSetGlobals(ring r, BOOLEAN complete = TRUE);
243
244/*-----------the ordering of monomials:-------------*/
245#define pSetm(p)    p_Setm(p, currRing)
246// TODO:
247#define pSetmComp   pSetm
248
249extern pLDegProc pLDeg;
250extern pFDegProc pFDeg;
251int pDeg(poly p);
252int pTotaldegree(poly p);
253int pWTotaldegree(poly p);
254int pWDegree(poly p);
255
256/*-------------pComp for syzygies:-------------------*/
257
258void pSetModDeg(intvec *w);
259void pSetSchreyerOrdB(polyset nextorder, int length);
260void pSetSchreyerOrdM(polyset nextorder, int length, int comps);
261int  pModuleOrder();
262
263
264
265
266poly      pmInit(char *s, BOOLEAN &ok);   /* monom -> poly */
267void      ppDelete(poly * a, ring r);
268
269/*-------------operations on polynomials:------------*/
270poly      pSub(poly a, poly b);
271poly      pPower(poly p, int i);
272
273// ----------------- define to enable new p_procs -----*/
274
275poly      pDivide(poly a, poly b);
276poly      pDivideM(poly a, poly b);
277void      pLcm(poly a, poly b, poly m);
278poly      pDiff(poly a, int k);
279poly      pDiffOp(poly a, poly b,BOOLEAN multiply);
280
281#define   pMaxComp(p)   p_MaxComp(p, currRing)
282#define   pMinComp(p)   p_MinComp(p, currRing)
283int pMaxCompProc(poly p);
284
285BOOLEAN   pOneComp(poly p);
286int       pWeight(int c);
287#define   pSetCompP(a,i)    p_SetCompP(a, i, currRing)
288
289
290char*     pString(poly p);
291char*     pString0(poly p);
292void      pWrite(poly p);
293void      pWrite0(poly p);
294void      wrp(poly p);
295
296void      pEnlargeSet(polyset *p, int length, int increment);
297poly      pISet(int i);
298#define   pOne()   pISet(1)
299
300void      pContent(poly p);
301void      pCleardenom(poly p);
302void      pNormalize(poly p);
303
304// homogenizes p by multiplying certain powers of the varnum-th variable
305poly      pHomogen (poly p, int varnum);
306
307// replaces the maximal powers of the leading monomial of p2 in p1 by
308// the same powers of n, utility for dehomogenization
309poly      pDehomogen (poly p1,poly p2,number n);
310BOOLEAN   pIsHomogeneous (poly p);
311
312// returns the leading monomial of p1 divided by the maximal power of
313// that of p2
314poly      pDivByMonom (poly p1,poly p2);
315
316// Returns as i-th entry of P the coefficient of the (i-1) power of
317// the leading monomial of p2 in p1
318void      pCancelPolyByMonom (poly p1,poly p2,polyset * P,int * SizeOfSet);
319
320// orders monoms of poly using insertion sort, performs pSetm on each
321// monom (i.e. sets Order field)
322poly      pOrdPolyInsertSetm(poly p);
323
324// orders monoms of poly using merge sort (ususally faster than
325// insertion sort). ASSUMES that pSetm was performed on monoms
326// (i.e. that Order field is set correctly)
327poly      pOrdPolyMerge(poly p);
328
329poly      pPermPoly (poly p, int * perm, ring OldRing,
330                     int *par_perm=NULL, int OldPar=0);
331
332/*BOOLEAN   pVectorHasUnitM(poly p, int * k);*/
333BOOLEAN   pVectorHasUnitB(poly p, int * k);
334void      pVectorHasUnit(poly p, int * k, int * len);
335poly      pTakeOutComp1(poly * p, int k);
336// Splits *p into two polys: *q which consists of all monoms with
337// component == comp and *p of all other monoms *lq == pLength(*q)
338// On rreturn all components pf *q == 0
339void pTakeOutComp(poly *p, Exponent_t comp, poly *q, int *lq);
340// Similar to pTakeOutComp, except that only those components are
341// taken out whose Order == order
342// ASSUME: monomial ordering is Order compatible, i.e., if m1, m2 Monoms then
343//         m1 >= m2 ==> pGetOrder(m1) >= pGetOrder(m2)
344void pDecrOrdTakeOutComp(poly *p, Exponent_t comp, Order_t order,
345                         poly *q, int *lq);
346// This is something weird -- Don't use it, unless you know what you are doing
347poly      pTakeOutComp(poly * p, int k);
348void      pSetPolyComp(poly p, int comp);
349void      pDeleteComp(poly * p,int k);
350void      pNorm(poly p);
351poly      pSubst(poly p, int n, poly e);
352poly      pJet(poly p, int m);
353poly      pJetW(poly p, int m, short * iv);
354// maximum weigthed degree of all monomials of p, w is indexed from
355// 1..pVariables
356int       pDegW(poly p, short *w);
357
358/*-----------type conversions ----------------------------*/
359poly  pPolys2Vec(polyset p, int len);
360void  pVec2Polys(poly v, polyset *p, int *len);
361int   pVar(poly m);
362
363/*-----------specials for spoly-computations--------------*/
364BOOLEAN pCompareChain (poly p,poly p1,poly p2,poly lcm);
365BOOLEAN pEqualPolys(poly p1,poly p2);
366BOOLEAN pComparePolys(poly p1,poly p2);
367
368
369
370/***************************************************************
371 *
372 * PDEBUG stuff
373 *
374 ***************************************************************/
375#ifdef PDEBUG
376#define pTest(p)        _p_Test(p, currRing, PDEBUG)
377#define pLmTest(p)      _p_LmTest(p, currRing, PDEBUG)
378
379#else // ! PDEBUG
380
381#define pTest(p)        ((void)0)
382#define pLmTest(p)      ((void)0)
383#endif
384
385#endif // POLYS_H
386
Note: See TracBrowser for help on using the repository browser.