source: git/Singular/polys.h @ c232af

Last change on this file since c232af was c232af, checked in by Olaf Bachmann <obachman@…>, 23 years ago
* omalloc stuff git-svn-id: file:///usr/local/Singular/svn/trunk@4524 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 12.5 KB
1#ifndef POLYS_H
2#define POLYS_H
4*  Computer Algebra System SINGULAR     *
6/* $Id: polys.h,v 1.32 2000-08-14 12:56:46 obachman Exp $ */
8* ABSTRACT - all basic methods to manipulate polynomials
10#include "polys-comp.h"
11#include "polys-impl.h"
12#define pFetchCopy(r,p)     _pFetchCopy(r,p)
13// Similar to pFetchCopy, except that poly p is deleted
14#define pFetchCopyDelete(r, p) _pFetchCopyDelete(r, p)
16typedef poly*   polyset;
17extern int      pVariables;
18extern int      pOrdSgn;
19extern BOOLEAN  pLexOrder;
20extern BOOLEAN  pMixedOrder;
21extern poly     ppNoether;
22extern BOOLEAN  pVectorOut;
23// 1 for lex ordering (except ls), -1 otherwise
24extern int pComponentOrder;
26/* function prototypes */
28/* ---------------- General poly access and iteration macros -----------*/
29// IMPORTANT: Do _NOT_ make _ANY_ assumptions about their actual implementation
31#define pNext(p)            _pNext(p)
32#define pIter(p)            _pIter(p)
34#define pGetCoeff(p)        _pGetCoeff(p)
35// deletes old coeff before setting the new
36#define pSetCoeff(p,n)      _pSetCoeff(p,n)
37// sets new coeff without deleting the old one
38#define pSetCoeff0(p,n)     _pSetCoeff0(p,n)
40#define pGetOrder(p)        _pGetOrder(p)
42// Gets/Sets Component field w.r.t. of polys of global ring
43#define pSetComp(p,k)       _pSetComp(p,k)
44#define pGetComp(p)         _pGetComp(p)
45#define pIncrComp(p)        _pIncrComp(p)
46#define pDecrComp(p)        _pDecrComp(p)
47#define pAddComp(p,v)       _pAddComp(p,v)
48#define pSubComp(p,v)       _pSubComp(p,v)
50// Gets/Sets Component field w.r.t. of polys of ring r
51#define pRingSetComp(r,p,k)       _pRingSetComp(r,p,k)
52#define pRingGetComp(r,p)         _pRingGetComp(r,p)
54// Gets/Sets ith exponent poly of global ring
55#define pGetExp(p,i)        _pGetExp(p,i)
56#define pSetExp(p,i,v)      _pSetExp(p,i,v)
58// Gets/Sets ith exponent of poly of ring r
59#define pRingGetExp(r,p,i)        _pRingGetExp(r,p,i)
60#define pRingSetExp(r,p,i,v)      _pRingSetExp(r,p,i,v)
62// Increments/decrements ith exponent by one
63#define pIncrExp(p,i)       _pIncrExp(p,i)
64#define pDecrExp(p,i)       _pDecrExp(p,i)
66// Gets Difference and sum of ith Exponent of m1, m2
67#define pGetExpSum(m1, m2, i)  _pGetExpSum(p1, p2, i)
68#define pGetExpDiff(p1, p2, i) _pGetExpDiff(p1, p2, i)
70// Adds/Substracts v to/from the ith Exponent
71#define pAddExp(p,i,v)      _pAddExp(p,i,v)
72#define pSubExp(p,i,v)      _pSubExp(p,i,v)
73#define pMultExp(p,i,v)     _pMultExp(p,i,v)
75// Gets a copy of (resp. sets) the exponent vector, where e is assumed
76// to point to (pVariables+1)*sizeof(Exponent_t) memory. Exponents are
77// filled in as follows: comp, e_1, .., e_n
78#define pGetExpV(p, e)      _pGetExpV(p, e)
79#define pSetExpV(p, e)      _pSetExpV(p, e)
82/*-------------predicate on polys ----------------------*/
83BOOLEAN   pIsConstant(const poly p);
84BOOLEAN   pIsConstantPoly(poly p);
85BOOLEAN   pIsConstantComp(const poly p);
86int       pIsPurePower(const poly p);
87#define   pIsVector(p)     (pGetComp(p)!=0)
88BOOLEAN   pHasNotCF(poly p1, poly p2);   /*has no common factor ?*/
89void      pSplit(poly p, poly * r);   /*p => IN(p), r => REST(p) */
90// Returns TRUE if m is monom of p, FALSE otherwise
91BOOLEAN pIsMonomOf(poly p, poly m);
94/*-------------ring management:----------------------*/
95//extern void pChangeRing(ring newRing);
96extern void pSetGlobals(ring r, BOOLEAN complete = TRUE);
98/*-----------the ordering of monomials:-------------*/
99extern pSetmProc pSetm;
100#define pComp0 rComp0
101#define pSetmComp pSetm
102int    pComp(poly p1,poly p2);
103extern pLDegProc pLDeg;
104extern pFDegProc pFDeg;
105int pDeg(poly p);
106int pTotaldegree(poly p);
107int pWTotaldegree(poly p);
108int pWDegree(poly p);
110/*-------------pComp for syzygies:-------------------*/
112void pSetModDeg(intvec *w);
113void pSetSchreyerOrdB(polyset nextorder, int length);
114void pSetSchreyerOrdM(polyset nextorder, int length, int comps);
115int  pModuleOrder();
117/*-------------storage management:-------------------*/
118// allocates the space for a new monomial -- no initialization !!!
119#define pNew()          _pNew(currPolyBin)
120// allocates a new monomial and initializes everything to 0
121#define pInit()         _pInit(currPolyBin)
122// frees the space of the monomial m (coef is not freed)
123#define pFree1(m)       _pFree1(m, currPolyBin)
124// frees the space of monomial and frees coefficient
125#define pDelete1(m)     _pDelete1(m, currPolyBin)
126// deletes the whole polynomial p
127#define pDelete(p)      _pDelete(p, currPolyBin)
129// similar to routines above, except that monomials are assumed to be from heap h (resp. are allocated from heap h)
130#define pHeapNew(h)             _pNew(h)
131#define pHeapInit(h)            _pInit(h)
132#define pHeapFree1(m, h)        _pFree1(m, h)
133#define pHeapDelete1(m, h)      _pDelete1(m, h)
134#define pHeapDelete(p, h)       _pDelete(p, h)
136// makes a simple memcpy of m2 into m1 -- does _not_ allocate memory for m1
137#define pCopy2(m1, m2)  _pCopy2(m1, m2)
138// Returns a newly allocated copy of the monomial m, initializes coefficient
139// and sets the next-field to NULL
140#define pCopy1(m)       _pCopy1(m)
141// Returns a newly allocated copy of the monomial m, sets the coefficient to 0,
142// and sets the next-field to NULL
143#define pHead0(p)       _pHead0(p)
144// Returns a newly allocated copy of the monomial, copy includes copy of coeff
145// sets the next-field to NULL
146#define pHead(p)        _pHead(currPolyBin, p)
147// Similar to pHead, except that new monom is taken from heap dest_heap
148#define pHeapHead(dest_heap, p) _pHead(dest_heap, p)
149// Returns a shallow copy (i.e. only monomial is copied) of head of source_p
150// Monom of copy is from dest_heap, assumes monoms of p are from source_heap
151// Head of source_p is deleted along the way
152#define pShallowCopyDeleteHead(dest_heap, source_p, source_heap) \
153  _pShallowCopyDeleteHead(dest_heap, source_p, source_heap)
155extern  poly pHeadProc(poly p);
156// Returns copy of the whole polynomial
157#define pCopy(p)        _pCopy(currPolyBin, p)
158// Returns copy of the whole poly, new monomials are taken from dest_heap
159#define pHeapCopy(dest_heap, p) _pCopy(dest_heap, p)
161// Returns a shallow copy (i.e. only monomials are copied) of source_p
162// Monoms of copy are from dest_heap, assumes monoms of p are from source_heap
163// source_p is deleted along the way
164#define pShallowCopyDelete(dest_heap, source_p, source_heap) \
165  _pShallowCopyDelete(dest_heap, source_p, source_heap)
169// Adds exponents of p2 to exponents of p1
170// assumes that exponents >= 0 and and one Component != 0
171#define pMonAddOn(p1, p2)   _pMonAddOn(p1, p2)
172// Similar to pMonAddOn, excpet that new exponents are written in p1
173#define pMonAdd(p1, p2, p3) _prMonAdd(p1, p2, p3, currRing)
174#define prMonAdd(p1, p2, p3, r) _prMonAdd(p1, p2, p3, r)
175// Subtracts exponetns of p1 from p1, assumes both Components are Equal
176#define pMonSubFrom(p1, p2) _pMonSubFrom(p1, p2)
178poly      pmInit(char *s, BOOLEAN &ok);   /* monom -> poly */
179void      ppDelete(poly * a, ring r);
181/*-------------operations on polynomials:------------*/
182poly      pAdd(poly p1, poly p2);
183poly      pNeg(poly p);
184poly      pSub(poly a, poly b);
185poly      pMult(poly a, poly b);
186void      pMultN(poly a, number c);
187poly      pMultCopyN(poly a, number c);
188poly      pPower(poly p, int i);
190// return TRUE, if exponent and component of Lm(p1) and Lm(p2) are equal,
191// FALSE otherwise;
192#define pEqual(p1, p2) _pEqual(p1, p2) // Assumes p1 != NULL & p2 != NULL
193inline BOOLEAN pLmEqual(poly p1, poly p2) // no assumptions
195  if (p1 != NULL)
196  {
197    if (p2 != NULL)
198      return pEqual(p1, p2);
199    return FALSE;
200  }
201  if (p2 == NULL)
202    return TRUE;
203  return FALSE;
206// returns TRUE, if leading monom of a divides leading monom of b
207// i.e., if there exists a expvector c > 0, s.t. b = a + c; assumes b != NULL
208#define pDivisibleBy(a, b)  _pDivisibleBy(a,b)
209// like pDivisibleBy, except that it is assumed that a!=NULL
210#define pDivisibleBy1(a,b)   _pDivisibleBy1(a,b)
211// like pDivisibleBy1, does not check components
212#define pDivisibleBy2(a, b) _pDivisibleBy2(a,b)
214// Divisibility tests based on Short Exponent vectors
215// sev_a     == pGetShortExpVector(a)
216// not_sev_b == ~ pGetShortExpVector(b)
217#define pShortDivisibleBy(a, sev_a, b, not_sev_b) \
218  _pShortDivisibleBy(a, sev_a, b, not_sev_b)
221poly      pDivide(poly a, poly b);
222poly      pDivideM(poly a, poly b);
223void      pLcm(poly a, poly b, poly m);
224poly      pDiff(poly a, int k);
225poly      pDiffOp(poly a, poly b,BOOLEAN multiply);
227int       pLength(poly a);
228int       pMaxComp(poly p);
229int       pMinComp(poly p, ring r=currRing);
230BOOLEAN   pOneComp(poly p);
231int       pWeight(int c);
232void      pSetCompP(poly a, int i);
234// Quer sum (total degree) of all exponents of leading monomial
235#define pExpQuerSum(p1)             _pExpQuerSum(p1)
236// sum from "from"th to "to"th exponent (including borders)
237#define pExpQuerSum2(p1, from, to)  _pExpQuerSum2(p1, from, to)
239char*     pString(poly p);
240char*     pString0(poly p);
241void      pWrite(poly p);
242void      pWrite0(poly p);
243void      wrp(poly p);
245void      pEnlargeSet(polyset *p, int length, int increment);
246poly      pISet(int i);
247#define   pOne()   pISet(1)
249void      pContent(poly p);
250void      pCleardenom(poly p);
251void      pNormalize(poly p);
253// homogenizes p by multiplying certain powers of the varnum-th variable
254poly      pHomogen (poly p, int varnum);
256// replaces the maximal powers of the leading monomial of p2 in p1 by
257// the same powers of n, utility for dehomogenization
258poly      pDehomogen (poly p1,poly p2,number n);
259BOOLEAN   pIsHomogeneous (poly p);
261// returns the leading monomial of p1 divided by the maximal power of
262// that of p2
263poly      pDivByMonom (poly p1,poly p2);
265// Returns as i-th entry of P the coefficient of the (i-1) power of
266// the leading monomial of p2 in p1
267void      pCancelPolyByMonom (poly p1,poly p2,polyset * P,int * SizeOfSet);
269// orders monoms of poly using insertion sort, performs pSetm on each
270// monom (i.e. sets Order field)
271poly      pOrdPolyInsertSetm(poly p);
273// orders monoms of poly using merge sort (ususally faster than
274// insertion sort). ASSUMES that pSetm was performed on monoms
275// (i.e. that Order field is set correctly)
276poly      pOrdPolyMerge(poly p);
278poly      pPermPoly (poly p, int * perm, ring OldRing,
279                     int *par_perm=NULL, int OldPar=0);
281/*BOOLEAN   pVectorHasUnitM(poly p, int * k);*/
282BOOLEAN   pVectorHasUnitB(poly p, int * k);
283void      pVectorHasUnit(poly p, int * k, int * len);
284poly      pTakeOutComp1(poly * p, int k);
285// Splits *p into two polys: *q which consists of all monoms with
286// component == comp and *p of all other monoms *lq == pLength(*q)
287// On rreturn all components pf *q == 0
288void pTakeOutComp(poly *p, Exponent_t comp, poly *q, int *lq);
289// Similar to pTakeOutComp, except that only those components are
290// taken out whose Order == order
291// ASSUME: monomial ordering is Order compatible, i.e., if m1, m2 Monoms then
292//         m1 >= m2 ==> pGetOrder(m1) >= pGetOrder(m2)
293void pDecrOrdTakeOutComp(poly *p, Exponent_t comp, Order_t order,
294                         poly *q, int *lq);
295// This is something weird -- Don't use it, unless you know what you are doing
296poly      pTakeOutComp(poly * p, int k);
297void      pSetPolyComp(poly p, int comp);
298void      pDeleteComp(poly * p,int k);
299void      pNorm(poly p);
300poly      pSubst(poly p, int n, poly e);
301poly      pJet(poly p, int m);
302poly      pJetW(poly p, int m, short * iv);
303// maximum weigthed degree of all monomials of p, w is indexed from
304// 1..pVariables
305int       pDegW(poly p, short *w);
307/*-----------type conversions ----------------------------*/
308poly  pPolys2Vec(polyset p, int len);
309void  pVec2Polys(poly v, polyset *p, int *len);
310int   pVar(poly m);
312/*-----------specials for spoly-computations--------------*/
313poly    pMultT(poly a, poly e);
314int     pDivComp(poly p, poly q);
315BOOLEAN pCompareChain (poly p,poly p1,poly p2,poly lcm);
316BOOLEAN pEqualPolys(poly p1,poly p2);
317BOOLEAN pComparePolys(poly p1,poly p2);
319/*-----------Misc stuff-----------------------------------*/
320// returns the "Short Exponent Vector" -- used to speed up divisibility
321// tests (see )
322unsigned long pGetShortExpVector(poly p);
327#ifdef PDEBUG
328#define pHeapTest(A,B)  pDBTest(A, B, __FILE__,__LINE__)
329#define pTest(A) pDBTest(A, currPolyBin, __FILE__,__LINE__)
330#define prTest(p, r) prDBTest(p, r, __FILE__, __LINE__)
332BOOLEAN pDBTest(poly p, char *f, int l);
333BOOLEAN pDBTest(poly p, omBin tail_heap, char *f, int l);
334BOOLEAN prDBTest(poly p, ring r, char *f, int l);
335BOOLEAN pDBTest(poly p,  omBin tail_heap, omBin lm_heap, char *f, int l);
337#define prTest(p, r)    (TRUE)
338#define pHeapTest(A,B)  (TRUE)
339#define pTest(A)        (TRUE)
340#define pDBTest(A,B,C)  (TRUE)
Note: See TracBrowser for help on using the repository browser.