source: git/Singular/polys.h @ fdd95ca

spielwiese
Last change on this file since fdd95ca was fdd95ca, checked in by Hans Schönemann <hannes@…>, 24 years ago
*hannes: use pNomaliuze in maEval* git-svn-id: file:///usr/local/Singular/svn/trunk@4288 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 12.4 KB
Line 
1#ifndef POLYS_H
2#define POLYS_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: polys.h,v 1.30 2000-05-02 16:30:43 Singular Exp $ */
7/*
8* ABSTRACT - all basic methods to manipulate polynomials
9*/
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)
15
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;
25
26/* function prototypes */
27
28/* ---------------- General poly access and iteration macros -----------*/
29// IMPORTANT: Do _NOT_ make _ANY_ assumptions about their actual implementation
30
31#define pNext(p)            _pNext(p)
32#define pIter(p)            _pIter(p)
33
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)
39
40#define pGetOrder(p)        _pGetOrder(p)
41
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)
49
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)
53
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)
57
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)
61
62// Increments/decrements ith exponent by one
63#define pIncrExp(p,i)       _pIncrExp(p,i)
64#define pDecrExp(p,i)       _pDecrExp(p,i)
65
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)
69
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)
74
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)
80
81
82/*-------------predicate on polys ----------------------*/
83BOOLEAN   pIsConstant(const poly p);
84BOOLEAN   pIsConstantComp(const poly p);
85int       pIsPurePower(const poly p);
86#define   pIsVector(p)     (pGetComp(p)!=0)
87BOOLEAN   pHasNotCF(poly p1, poly p2);   /*has no common factor ?*/
88void      pSplit(poly p, poly * r);   /*p => IN(p), r => REST(p) */
89// Returns TRUE if m is monom of p, FALSE otherwise
90BOOLEAN pIsMonomOf(poly p, poly m);
91
92
93/*-------------ring management:----------------------*/
94//extern void pChangeRing(ring newRing);
95extern void pSetGlobals(ring r, BOOLEAN complete = TRUE);
96
97/*-----------the ordering of monomials:-------------*/
98extern pSetmProc pSetm;
99#define pComp0 rComp0
100#define pSetmComp pSetm
101int    pComp(poly p1,poly p2);
102extern pLDegProc pLDeg;
103extern pFDegProc pFDeg;
104int pDeg(poly p);
105int pTotaldegree(poly p);
106int pWTotaldegree(poly p);
107int pWDegree(poly p);
108
109/*-------------pComp for syzygies:-------------------*/
110
111void pSetModDeg(intvec *w);
112void pSetSchreyerOrdB(polyset nextorder, int length);
113void pSetSchreyerOrdM(polyset nextorder, int length, int comps);
114int  pModuleOrder();
115
116/*-------------storage management:-------------------*/
117// allocates the space for a new monomial -- no initialization !!!
118#define pNew()          _pNew(mm_specHeap)
119// allocates a new monomial and initializes everything to 0
120#define pInit()         _pInit(mm_specHeap)
121// frees the space of the monomial m (coef is not freed)
122#define pFree1(m)       _pFree1(m, mm_specHeap)
123// frees the space of monomial and frees coefficient
124#define pDelete1(m)     _pDelete1(m, mm_specHeap)
125// deletes the whole polynomial p
126#define pDelete(p)      _pDelete(p, mm_specHeap)
127
128// similar to routines above, except that monomials are assumed to be from heap h (resp. are allocated from heap h)
129#define pHeapNew(h)             _pNew(h)
130#define pHeapInit(h)            _pInit(h)
131#define pHeapFree1(m, h)        _pFree1(m, h)
132#define pHeapDelete1(m, h)      _pDelete1(m, h)
133#define pHeapDelete(p, h)       _pDelete(p, h)
134
135// makes a simple memcpy of m2 into m1 -- does _not_ allocate memory for m1
136#define pCopy2(m1, m2)  _pCopy2(m1, m2)
137// Returns a newly allocated copy of the monomial m, initializes coefficient
138// and sets the next-field to NULL
139#define pCopy1(m)       _pCopy1(m)
140// Returns a newly allocated copy of the monomial m, sets the coefficient to 0,
141// and sets the next-field to NULL
142#define pHead0(p)       _pHead0(p)
143// Returns a newly allocated copy of the monomial, copy includes copy of coeff
144// sets the next-field to NULL
145#define pHead(p)        _pHead(mm_specHeap, p)
146// Similar to pHead, except that new monom is taken from heap dest_heap
147#define pHeapHead(dest_heap, p) _pHead(dest_heap, p)
148// Returns a shallow copy (i.e. only monomial is copied) of head of source_p
149// Monom of copy is from dest_heap, assumes monoms of p are from source_heap
150// Head of source_p is deleted along the way
151#define pShallowCopyDeleteHead(dest_heap, source_p, source_heap) \
152  _pShallowCopyDeleteHead(dest_heap, source_p, source_heap)
153
154extern  poly pHeadProc(poly p);
155// Returns copy of the whole polynomial
156#define pCopy(p)        _pCopy(mm_specHeap, p)
157// Returns copy of the whole poly, new monomials are taken from dest_heap
158#define pHeapCopy(dest_heap, p) _pCopy(dest_heap, p)
159
160// Returns a shallow copy (i.e. only monomials are copied) of source_p
161// Monoms of copy are from dest_heap, assumes monoms of p are from source_heap
162// source_p is deleted along the way
163#define pShallowCopyDelete(dest_heap, source_p, source_heap) \
164  _pShallowCopyDelete(dest_heap, source_p, source_heap)
165
166
167
168// Adds exponents of p2 to exponents of p1
169// assumes that exponents >= 0 and and one Component != 0
170#define pMonAddOn(p1, p2)   _pMonAddOn(p1, p2)
171// Similar to pMonAddOn, excpet that new exponents are written in p1
172#define pMonAdd(p1, p2, p3) _prMonAdd(p1, p2, p3, currRing)
173#define prMonAdd(p1, p2, p3, r) _prMonAdd(p1, p2, p3, r)
174// Subtracts exponetns of p1 from p1, assumes both Components are Equal
175#define pMonSubFrom(p1, p2) _pMonSubFrom(p1, p2)
176
177poly      pmInit(char *s, BOOLEAN &ok);   /* monom -> poly */
178void      ppDelete(poly * a, ring r);
179
180/*-------------operations on polynomials:------------*/
181poly      pAdd(poly p1, poly p2);
182poly      pNeg(poly p);
183poly      pSub(poly a, poly b);
184poly      pMult(poly a, poly b);
185void      pMultN(poly a, number c);
186poly      pMultCopyN(poly a, number c);
187poly      pPower(poly p, int i);
188
189// return TRUE, if exponent and component of Lm(p1) and Lm(p2) are equal,
190// FALSE otherwise;
191#define pEqual(p1, p2) _pEqual(p1, p2) // Assumes p1 != NULL & p2 != NULL
192inline BOOLEAN pLmEqual(poly p1, poly p2) // no assumptions
193{
194  if (p1 != NULL)
195  {
196    if (p2 != NULL)
197      return pEqual(p1, p2);
198    return FALSE;
199  }
200  if (p2 == NULL)
201    return TRUE;
202  return FALSE;
203}
204
205// returns TRUE, if leading monom of a divides leading monom of b
206// i.e., if there exists a expvector c > 0, s.t. b = a + c; assumes b != NULL
207#define pDivisibleBy(a, b)  _pDivisibleBy(a,b)
208// like pDivisibleBy, except that it is assumed that a!=NULL
209#define pDivisibleBy1(a,b)   _pDivisibleBy1(a,b)
210// like pDivisibleBy1, does not check components
211#define pDivisibleBy2(a, b) _pDivisibleBy2(a,b)
212
213// Divisibility tests based on Short Exponent vectors
214// sev_a     == pGetShortExpVector(a)
215// not_sev_b == ~ pGetShortExpVector(b)
216#define pShortDivisibleBy(a, sev_a, b, not_sev_b) \
217  _pShortDivisibleBy(a, sev_a, b, not_sev_b)
218
219
220poly      pDivide(poly a, poly b);
221poly      pDivideM(poly a, poly b);
222void      pLcm(poly a, poly b, poly m);
223poly      pDiff(poly a, int k);
224poly      pDiffOp(poly a, poly b,BOOLEAN multiply);
225
226int       pLength(poly a);
227int       pMaxComp(poly p);
228int       pMinComp(poly p, ring r=currRing);
229BOOLEAN   pOneComp(poly p);
230int       pWeight(int c);
231void      pSetCompP(poly a, int i);
232
233// Quer sum (total degree) of all exponents of leading monomial
234#define pExpQuerSum(p1)             _pExpQuerSum(p1)
235// sum from "from"th to "to"th exponent (including borders)
236#define pExpQuerSum2(p1, from, to)  _pExpQuerSum2(p1, from, to)
237
238char*     pString(poly p);
239char*     pString0(poly p);
240void      pWrite(poly p);
241void      pWrite0(poly p);
242void      wrp(poly p);
243
244void      pEnlargeSet(polyset *p, int length, int increment);
245poly      pISet(int i);
246#define   pOne()   pISet(1)
247
248void      pContent(poly p);
249void      pCleardenom(poly p);
250void      pNormalize(poly p);
251
252// homogenizes p by multiplying certain powers of the varnum-th variable
253poly      pHomogen (poly p, int varnum);
254
255// replaces the maximal powers of the leading monomial of p2 in p1 by
256// the same powers of n, utility for dehomogenization
257poly      pDehomogen (poly p1,poly p2,number n);
258BOOLEAN   pIsHomogeneous (poly p);
259
260// returns the leading monomial of p1 divided by the maximal power of
261// that of p2
262poly      pDivByMonom (poly p1,poly p2);
263
264// Returns as i-th entry of P the coefficient of the (i-1) power of
265// the leading monomial of p2 in p1
266void      pCancelPolyByMonom (poly p1,poly p2,polyset * P,int * SizeOfSet);
267
268// orders monoms of poly using insertion sort, performs pSetm on each
269// monom (i.e. sets Order field)
270poly      pOrdPolyInsertSetm(poly p);
271
272// orders monoms of poly using merge sort (ususally faster than
273// insertion sort). ASSUMES that pSetm was performed on monoms
274// (i.e. that Order field is set correctly)
275poly      pOrdPolyMerge(poly p);
276
277poly      pPermPoly (poly p, int * perm, ring OldRing,
278                     int *par_perm=NULL, int OldPar=0);
279
280/*BOOLEAN   pVectorHasUnitM(poly p, int * k);*/
281BOOLEAN   pVectorHasUnitB(poly p, int * k);
282void      pVectorHasUnit(poly p, int * k, int * len);
283poly      pTakeOutComp1(poly * p, int k);
284// Splits *p into two polys: *q which consists of all monoms with
285// component == comp and *p of all other monoms *lq == pLength(*q)
286// On rreturn all components pf *q == 0
287void pTakeOutComp(poly *p, Exponent_t comp, poly *q, int *lq);
288// Similar to pTakeOutComp, except that only those components are
289// taken out whose Order == order
290// ASSUME: monomial ordering is Order compatible, i.e., if m1, m2 Monoms then
291//         m1 >= m2 ==> pGetOrder(m1) >= pGetOrder(m2)
292void pDecrOrdTakeOutComp(poly *p, Exponent_t comp, Order_t order,
293                         poly *q, int *lq);
294// This is something weird -- Don't use it, unless you know what you are doing
295poly      pTakeOutComp(poly * p, int k);
296void      pSetPolyComp(poly p, int comp);
297void      pDeleteComp(poly * p,int k);
298void      pNorm(poly p);
299poly      pSubst(poly p, int n, poly e);
300poly      pJet(poly p, int m);
301poly      pJetW(poly p, int m, short * iv);
302// maximum weigthed degree of all monomials of p, w is indexed from
303// 1..pVariables
304int       pDegW(poly p, short *w);
305
306/*-----------type conversions ----------------------------*/
307poly  pPolys2Vec(polyset p, int len);
308void  pVec2Polys(poly v, polyset *p, int *len);
309int   pVar(poly m);
310
311/*-----------specials for spoly-computations--------------*/
312poly    pMultT(poly a, poly e);
313int     pDivComp(poly p, poly q);
314BOOLEAN pCompareChain (poly p,poly p1,poly p2,poly lcm);
315BOOLEAN pEqualPolys(poly p1,poly p2);
316BOOLEAN pComparePolys(poly p1,poly p2);
317
318/*-----------Misc stuff-----------------------------------*/
319// returns the "Short Exponent Vector" -- used to speed up divisibility
320// tests (see polys-impl.cc )
321unsigned long pGetShortExpVector(poly p);
322
323
324
325
326#ifdef PDEBUG
327#define pHeapTest(A,B)  pDBTest(A, B, __FILE__,__LINE__)
328#define pTest(A) pDBTest(A, mm_specHeap, __FILE__,__LINE__)
329#define prTest(p, r) prDBTest(p, r, __FILE__, __LINE__)
330
331BOOLEAN pDBTest(poly p, char *f, int l);
332BOOLEAN pDBTest(poly p, memHeap tail_heap, char *f, int l);
333BOOLEAN prDBTest(poly p, ring r, char *f, int l);
334BOOLEAN pDBTest(poly p,  memHeap tail_heap, memHeap lm_heap, char *f, int l);
335#else
336#define prTest(p, r)    (TRUE)
337#define pHeapTest(A,B)  (TRUE)
338#define pTest(A)        (TRUE)
339#define pDBTest(A,B,C)  (TRUE)
340#endif
341#endif
Note: See TracBrowser for help on using the repository browser.