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

spielwiese
Last change on this file since 9d72fe was 9d72fe, checked in by Olaf Bachmann <obachman@…>, 23 years ago
* new p_Procs stuff git-svn-id: file:///usr/local/Singular/svn/trunk@4559 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 12.7 KB
Line 
1#ifndef POLYS_H
2#define POLYS_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: polys.h,v 1.33 2000-08-24 14:42:45 obachman 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   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);
92
93
94/*-------------ring management:----------------------*/
95//extern void pChangeRing(ring newRing);
96extern void pSetGlobals(ring r, BOOLEAN complete = TRUE);
97
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);
109
110/*-------------pComp for syzygies:-------------------*/
111
112void pSetModDeg(intvec *w);
113void pSetSchreyerOrdB(polyset nextorder, int length);
114void pSetSchreyerOrdM(polyset nextorder, int length, int comps);
115int  pModuleOrder();
116
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
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(currPolyBin, 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 poly, new monomials are taken from dest_heap
156#define pHeapCopy(dest_heap, p) _pCopy(dest_heap, p)
157
158// Returns a shallow copy (i.e. only monomials are copied) of source_p
159// Monoms of copy are from dest_heap, assumes monoms of p are from source_heap
160// source_p is deleted along the way
161#define pShallowCopyDelete(dest_heap, source_p, source_heap) \
162  _pShallowCopyDelete(dest_heap, source_p, source_heap)
163
164
165
166// Adds exponents of p2 to exponents of p1
167// assumes that exponents >= 0 and and one Component != 0
168#define pMonAddOn(p1, p2)   _pMonAddOn(p1, p2)
169// Similar to pMonAddOn, excpet that new exponents are written in p1
170#define pMonAdd(p1, p2, p3) _prMonAdd(p1, p2, p3, currRing)
171#define prMonAdd(p1, p2, p3, r) _prMonAdd(p1, p2, p3, r)
172// Subtracts exponetns of p1 from p1, assumes both Components are Equal
173#define pMonSubFrom(p1, p2) _pMonSubFrom(p1, p2)
174
175poly      pmInit(char *s, BOOLEAN &ok);   /* monom -> poly */
176void      ppDelete(poly * a, ring r);
177
178/*-------------operations on polynomials:------------*/
179poly      pNeg(poly p);
180poly      pSub(poly a, poly b);
181poly      pMult(poly a, poly b);
182void      pMultN(poly a, number c);
183poly      pMultCopyN(poly a, number c);
184poly      pPower(poly p, int i);
185
186
187// ----------------- define to enable new p_procs -----*/
188// #define HAVE_P_PROCS
189#ifdef HAVE_P_PROCS
190#include "p_Procs.h"
191#define pDelete p_Delete
192#define pCopy   p_Copy
193#define pAdd    p_Add_q
194#else
195// deletes the whole polynomial p
196#define pDelete(p)      _pDelete(p, currPolyBin)
197// Returns copy of the whole polynomial
198#define pCopy(p)        _pCopy(currPolyBin, p)
199poly      pAdd(poly p1, poly p2);
200#endif
201
202// return TRUE, if exponent and component of Lm(p1) and Lm(p2) are equal,
203// FALSE otherwise;
204#define pEqual(p1, p2) _pEqual(p1, p2) // Assumes p1 != NULL & p2 != NULL
205inline BOOLEAN pLmEqual(poly p1, poly p2) // no assumptions
206{
207  if (p1 != NULL)
208  {
209    if (p2 != NULL)
210      return pEqual(p1, p2);
211    return FALSE;
212  }
213  if (p2 == NULL)
214    return TRUE;
215  return FALSE;
216}
217
218// returns TRUE, if leading monom of a divides leading monom of b
219// i.e., if there exists a expvector c > 0, s.t. b = a + c; assumes b != NULL
220#define pDivisibleBy(a, b)  _pDivisibleBy(a,b)
221// like pDivisibleBy, except that it is assumed that a!=NULL
222#define pDivisibleBy1(a,b)   _pDivisibleBy1(a,b)
223// like pDivisibleBy1, does not check components
224#define pDivisibleBy2(a, b) _pDivisibleBy2(a,b)
225
226// Divisibility tests based on Short Exponent vectors
227// sev_a     == pGetShortExpVector(a)
228// not_sev_b == ~ pGetShortExpVector(b)
229#define pShortDivisibleBy(a, sev_a, b, not_sev_b) \
230  _pShortDivisibleBy(a, sev_a, b, not_sev_b)
231
232
233poly      pDivide(poly a, poly b);
234poly      pDivideM(poly a, poly b);
235void      pLcm(poly a, poly b, poly m);
236poly      pDiff(poly a, int k);
237poly      pDiffOp(poly a, poly b,BOOLEAN multiply);
238
239int       pLength(poly a);
240int       pMaxComp(poly p);
241int       pMinComp(poly p, ring r=currRing);
242BOOLEAN   pOneComp(poly p);
243int       pWeight(int c);
244void      pSetCompP(poly a, int i);
245
246// Quer sum (total degree) of all exponents of leading monomial
247#define pExpQuerSum(p1)             _pExpQuerSum(p1)
248// sum from "from"th to "to"th exponent (including borders)
249#define pExpQuerSum2(p1, from, to)  _pExpQuerSum2(p1, from, to)
250
251char*     pString(poly p);
252char*     pString0(poly p);
253void      pWrite(poly p);
254void      pWrite0(poly p);
255void      wrp(poly p);
256
257void      pEnlargeSet(polyset *p, int length, int increment);
258poly      pISet(int i);
259#define   pOne()   pISet(1)
260
261void      pContent(poly p);
262void      pCleardenom(poly p);
263void      pNormalize(poly p);
264
265// homogenizes p by multiplying certain powers of the varnum-th variable
266poly      pHomogen (poly p, int varnum);
267
268// replaces the maximal powers of the leading monomial of p2 in p1 by
269// the same powers of n, utility for dehomogenization
270poly      pDehomogen (poly p1,poly p2,number n);
271BOOLEAN   pIsHomogeneous (poly p);
272
273// returns the leading monomial of p1 divided by the maximal power of
274// that of p2
275poly      pDivByMonom (poly p1,poly p2);
276
277// Returns as i-th entry of P the coefficient of the (i-1) power of
278// the leading monomial of p2 in p1
279void      pCancelPolyByMonom (poly p1,poly p2,polyset * P,int * SizeOfSet);
280
281// orders monoms of poly using insertion sort, performs pSetm on each
282// monom (i.e. sets Order field)
283poly      pOrdPolyInsertSetm(poly p);
284
285// orders monoms of poly using merge sort (ususally faster than
286// insertion sort). ASSUMES that pSetm was performed on monoms
287// (i.e. that Order field is set correctly)
288poly      pOrdPolyMerge(poly p);
289
290poly      pPermPoly (poly p, int * perm, ring OldRing,
291                     int *par_perm=NULL, int OldPar=0);
292
293/*BOOLEAN   pVectorHasUnitM(poly p, int * k);*/
294BOOLEAN   pVectorHasUnitB(poly p, int * k);
295void      pVectorHasUnit(poly p, int * k, int * len);
296poly      pTakeOutComp1(poly * p, int k);
297// Splits *p into two polys: *q which consists of all monoms with
298// component == comp and *p of all other monoms *lq == pLength(*q)
299// On rreturn all components pf *q == 0
300void pTakeOutComp(poly *p, Exponent_t comp, poly *q, int *lq);
301// Similar to pTakeOutComp, except that only those components are
302// taken out whose Order == order
303// ASSUME: monomial ordering is Order compatible, i.e., if m1, m2 Monoms then
304//         m1 >= m2 ==> pGetOrder(m1) >= pGetOrder(m2)
305void pDecrOrdTakeOutComp(poly *p, Exponent_t comp, Order_t order,
306                         poly *q, int *lq);
307// This is something weird -- Don't use it, unless you know what you are doing
308poly      pTakeOutComp(poly * p, int k);
309void      pSetPolyComp(poly p, int comp);
310void      pDeleteComp(poly * p,int k);
311void      pNorm(poly p);
312poly      pSubst(poly p, int n, poly e);
313poly      pJet(poly p, int m);
314poly      pJetW(poly p, int m, short * iv);
315// maximum weigthed degree of all monomials of p, w is indexed from
316// 1..pVariables
317int       pDegW(poly p, short *w);
318
319/*-----------type conversions ----------------------------*/
320poly  pPolys2Vec(polyset p, int len);
321void  pVec2Polys(poly v, polyset *p, int *len);
322int   pVar(poly m);
323
324/*-----------specials for spoly-computations--------------*/
325poly    pMultT(poly a, poly e);
326int     pDivComp(poly p, poly q);
327BOOLEAN pCompareChain (poly p,poly p1,poly p2,poly lcm);
328BOOLEAN pEqualPolys(poly p1,poly p2);
329BOOLEAN pComparePolys(poly p1,poly p2);
330
331/*-----------Misc stuff-----------------------------------*/
332// returns the "Short Exponent Vector" -- used to speed up divisibility
333// tests (see polys-impl.cc )
334unsigned long pGetShortExpVector(poly p);
335
336
337
338
339#ifdef PDEBUG
340#define pHeapTest(A,B)  pDBTest(A, B, __FILE__,__LINE__)
341#define pTest(A) pDBTest(A, currPolyBin, __FILE__,__LINE__)
342#define prTest(p, r) prDBTest(p, r, __FILE__, __LINE__)
343
344BOOLEAN pDBTest(poly p, char *f, int l);
345BOOLEAN pDBTest(poly p, omBin tail_heap, char *f, int l);
346BOOLEAN prDBTest(poly p, ring r, char *f, int l);
347BOOLEAN pDBTest(poly p,  omBin tail_heap, omBin lm_heap, char *f, int l);
348#else
349#define prTest(p, r)    (TRUE)
350#define pHeapTest(A,B)  (TRUE)
351#define pTest(A)        (TRUE)
352#define pDBTest(A,B,C)  (TRUE)
353#endif
354#endif
Note: See TracBrowser for help on using the repository browser.