source: git/Singular/polys.h @ 97a7b44

spielwiese
Last change on this file since 97a7b44 was 8c8bea, checked in by Olaf Bachmann <obachman@…>, 25 years ago
* preparation for buckets git-svn-id: file:///usr/local/Singular/svn/trunk@3063 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 12.2 KB
Line 
1#ifndef POLYS_H
2#define POLYS_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id: polys.h,v 1.20 1999-05-26 16:24:00 obachman Exp $ */
7/*
8* ABSTRACT - all basic methods to manipulate polynomials
9*/
10#include "polys-impl.h"
11
12typedef poly*   polyset;
13extern int      pVariables;
14extern int      pOrdSgn;
15extern BOOLEAN  pLexOrder;
16extern BOOLEAN  pMixedOrder;
17extern poly     ppNoether;
18extern BOOLEAN  pVectorOut;
19// 1 for lex ordering (except ls), -1 otherwise
20extern int pLexSgn;
21extern int pComponentOrder;
22
23#ifdef DRING
24// D=k[x,d,y] is the Weyl-Algebra [y], y commuting with all others
25// M=k[x,x^(-1),y] is a D-module
26// all x(1..n),d,x(1..n)^(-1),y(1..k) are considered as "ring variables" v(1..N)
27// the map from x(i) to v:
28#define pdX(i)  (i)
29// d(i)
30#define pdDX(i) (pdN+i)
31// x(i)^(-1)
32#define pdIX(i) (pdN+i)
33// y(i)
34#define pdY(i)  (pdN*2+i+1)
35// a monomial m belongs to a D-module M iff pdDFlag(m)==0
36// a monomial m belongs to an ideal in the Weyl-Algebra D iff pdDFlag(m)==1
37#define pdDFlag(m) pGetExp(m,pdN*2+1)
38#define pdSetDFlag(m,i) pSetExp(m,pdN*2+1,i)
39
40extern int      pdN;
41extern int      pdK;
42extern BOOLEAN  pDRING;
43poly   pdSpolyCreate(poly a, poly b);
44void   pdLcm(poly a, poly b, poly m);
45BOOLEAN pdIsConstantComp(poly p);
46void   spModuleToPoly(poly a1);
47void   pdSetDFlagP(poly p,int i);
48#endif
49#ifdef SRING
50extern int      pAltVars;
51extern BOOLEAN  pSRING;
52#endif
53#ifdef SDRING
54void   psAug(poly q, poly done, polyset *s, int *l, int *m);
55void   pdAug(poly q, polyset *s, int *l, int *m);
56#endif
57#ifdef SDRING
58extern BOOLEAN pSDRING;
59#endif
60
61/* function prototypes */
62
63/* ---------------- General poly access and iteration macros -----------*/
64// IMPORTANT: Do _NOT_ make _ANY_ assumptions about their actual implementation
65
66#define pNext(p)            _pNext(p)
67#define pIter(p)            _pIter(p)
68
69#define pGetCoeff(p)        _pGetCoeff(p)
70// deletes old coeff before setting the new
71#define pSetCoeff(p,n)      _pSetCoeff(p,n)
72// sets new coeff without deleting the old one
73#define pSetCoeff0(p,n)     _pSetCoeff0(p,n)
74
75#define pGetOrder(p)        _pGetOrder(p)
76
77// Gets/Sets Component field w.r.t. of polys of global ring
78#define pSetComp(p,k)       _pSetComp(p,k)
79#define pGetComp(p)         _pGetComp(p)
80#define pIncrComp(p)        _pIncrComp(p)
81#define pDecrComp(p)        _pDecrComp(p)
82#define pAddComp(p,v)       _pAddComp(p,v)
83#define pSubComp(p,v)       _pSubComp(p,v)
84
85// Gets/Sets Component field w.r.t. of polys of ring r
86#define pRingSetComp(r,p,k)       _pRingSetComp(r,p,k)
87#define pRingGetComp(r,p)         _pRingGetComp(r,p)
88
89// Gets/Sets ith exponent poly of global ring
90#define pGetExp(p,i)        _pGetExp(p,i)
91#define pSetExp(p,i,v)      _pSetExp(p,i,v)
92
93// Gets/Sets ith exponent of poly of ring r
94#define pRingGetExp(r,p,i)        _pRingGetExp(r,p,i)
95#define pRingSetExp(r,p,i,v)      _pRingSetExp(r,p,i,v)
96
97// Increments/decrements ith exponent by one
98#define pIncrExp(p,i)       _pIncrExp(p,i)
99#define pDecrExp(p,i)       _pDecrExp(p,i)
100
101// Gets Difference and sum of ith Exponent of m1, m2
102#define pGetExpSum(m1, m2, i)  _pGetExpSum(p1, p2, i)
103#define pGetExpDiff(p1, p2, i) _pGetExpDiff(p1, p2, i)
104
105// Adds/Substracts v to/from the ith Exponent
106#define pAddExp(p,i,v)      _pAddExp(p,i,v)
107#define pSubExp(p,i,v)      _pSubExp(p,i,v)
108#define pMultExp(p,i,v)     _pMultExp(p,i,v)
109
110// Gets a copy of (resp. sets) the exponent vector, where e is assumed
111// to point to (pVariables+1)*sizeof(Exponent_t) memory. Exponents are
112// filled in as follows: comp, e_1, .., e_n
113#define pGetExpV(p, e)      _pGetExpV(p, e)
114#define pSetExpV(p, e)      _pSetExpV(p, e)
115
116
117/*-------------predicate on polys ----------------------*/
118BOOLEAN   pIsConstant(poly p);
119BOOLEAN   pIsConstantComp(poly p);
120int       pIsPurePower(poly p);
121#define   pIsVector(p)     (pGetComp(p)!=0)
122BOOLEAN   pHasNotCF(poly p1, poly p2);   /*has no common factor ?*/
123void      pSplit(poly p, poly * r);   /*p => IN(p), r => REST(p) */
124
125
126/*-------------ring management:----------------------*/
127extern void   pChangeRing(int N, int OrdSgn,
128                         int* ord, int* block0, int* block1,
129                         short** wv);
130extern void pSetGlobals(ring r, BOOLEAN complete = TRUE);
131
132/*-----------the ordering of monomials:-------------*/
133extern pSetmProc pSetm;
134extern pCompProc pComp0;
135// this is needed here as long as monomials with negative exponents might be
136// compared (see in spolys.cc)
137extern pCompProc t_pComp0;
138int    pComp(poly p1,poly p2);
139extern pLDegProc pLDeg;
140extern pFDegProc pFDeg;
141int pDeg(poly p);
142int pTotaldegree(poly p);
143int pWTotaldegree(poly p);
144int pWDegree(poly p);
145
146/*-------------pComp for syzygies:-------------------*/
147
148void pSetModDeg(intvec *w);
149void pSetSchreyerOrdB(polyset nextorder, int length);
150void pSetSchreyerOrdM(polyset nextorder, int length, int comps);
151int  pModuleOrder();
152
153/*-------------storage management:-------------------*/
154// allocates the space for a new monomial -- no initialization !!!
155#define pNew()      _pNew()
156// allocates a new monomial and initializes everything to 0
157#define pInit()     _pInit()
158// frees the space of the monomial m (coef is not freed)
159#define pFree1(m)       _pFree1(m)
160// frees the space of monoial and frees coefficient
161#define pDelete1(m)     _pDelete1(m)
162// deletes the whole polynomial p
163#define pDelete(p)      _pDelete(p)
164
165// makes a simple memcpy of m2 into m1 -- does _not_ allocate memory for m1
166#define pCopy2(m1, m2)  _pCopy2(m1, m2)
167// Returns a newly allocated copy of the monomial m, initializes coefficient
168// and sets the next-field to NULL
169#define pCopy1(m)       _pCopy1(m)
170// Returns a newly allocated copy of the monomial m, sets the coefficient to 0,
171// and sets the next-field to NULL
172#define pHead0(p)       _pHead0(p)
173// Returns a newly allocated copy of the monomial, copy includes copy of coeff
174// sets the next-field to NULL
175#define pHead(p)        _pHead(p)
176extern  poly pHeadProc(poly p);
177// Returns copy of the whole polynomial
178#define pCopy(p)        _pCopy(p)
179// Returns a converted copy (in the sense that returned poly is in
180// poly of currRing) of poly p which is from ring r -- assumes that
181// currRing and r have the same number of variables, i.e. that polys
182// from r can be "fetched" into currRing
183#define pFetchCopy(r,p)     _pFetchCopy(r,p)
184
185
186// Adds exponents of p2 to exponents of p1; updates Order field
187// assumes that exponents > 0 and < MAX_EXPONENT / 2
188#define pMonAddFast(p1, p2) _pMonAddFast(p1, p2)
189// Is equivalent to pCopy2(p1, p2);pMonAddFast(p1, p3);
190#define pCopyAddFast(p1, p2, p3)    _pCopyAddFast(p1, p2, p3)
191// Similar to pCopyAddFast, except that we do not care about the next field
192#define pCopyAddFast0(p1, p2, p3)  _pCopyAddFast0(p1, p2, p3)
193// Similar to pCopyAddFast0, except that we do not recompute the Order,
194// but assume that it is the sum of the Order of p2 and p3
195#define pCopyAddFastHomog(p1, p2, p3, Order)  \
196  _pCopyAddFastHomog(p1, p2, p3, Order)
197
198poly      pmInit(char *s, BOOLEAN &ok);   /* monom -> poly */
199void      ppDelete(poly * a, ring r);
200
201/*-------------operations on polynomials:------------*/
202poly      pAdd(poly p1, poly p2);
203poly      pNeg(poly p);
204poly      pSub(poly a, poly b);
205poly      pMult(poly a, poly b);
206void      pMultN(poly a, number c);
207poly      pMultCopyN(poly a, number c);
208poly      pPower(poly p, int i);
209
210// return TRUE, if exponent and component of Lm(p1) and Lm(p2) are equal,
211// FALSE otherwise;
212#define pEqual(p1, p2) _pEqual(p1, p2) // Assumes p1 != NULL & p2 != NULL
213inline BOOLEAN pLmEqual(poly p1, poly p2) // no assumptions
214{
215  if (p1 != NULL)
216  {
217    if (p2 != NULL)
218      return pEqual(p1, p2);
219    return FALSE;
220  }
221  if (p2 == NULL)
222    return TRUE;
223  return FALSE;
224}
225
226// returns TRUE, if leading monom of a divides leading monom of b
227// i.e., if there exists a expvector c > 0, s.t. b = a + c; assumes b != NULL
228#define pDivisibleBy(a, b)  _pDivisibleBy(a,b)
229// like pDivisibleBy, except that it is assumed that a!=NULL
230#define pDivisibleBy1(a,b)   _pDivisibleBy1(a,b)
231// like pDivisibleBy1, does not check components
232#define pDivisibleBy2(a, b) _pDivisibleBy2(a,b)
233
234
235poly      pDivide(poly a, poly b);
236poly      pDivideM(poly a, poly b);
237void      pLcm(poly a, poly b, poly m);
238poly      pDiff(poly a, int k);
239poly      pDiffOp(poly a, poly b,BOOLEAN multiply);
240
241int       pLength(poly a);
242int       pMaxComp(poly p);
243int       pMinComp(poly p);
244BOOLEAN   pOneComp(poly p);
245int       pWeight(int c);
246void      pSetCompP(poly a, int i);
247
248// Quer sum (total degree) of all exponents of leading monomial
249#define pExpQuerSum(p1)             _pExpQuerSum(p1)
250// sum from 1st to "to"th exponent (including the "to" one)
251#define pExpQuerSum1(p1, to)        _pExpQuerSum1(p1, to)
252// sum from "from"th to "to"th exponent (including borders)
253#define pExpQuerSum2(p1, from, to)  _pExpQuerSum2(p1, from, to)
254
255char*     pString(poly p);
256char*     pString0(poly p);
257void      pWrite(poly p);
258void      pWrite0(poly p);
259void      wrp(poly p);
260
261void      pEnlargeSet(polyset *p, int length, int increment);
262poly      pISet(int i);
263#define   pOne()   pISet(1)
264
265void      pContent(poly p);
266void      pCleardenom(poly p);
267
268// homogenizes p by multiplying certain powers of the varnum-th variable
269poly      pHomogen (poly p, int varnum);
270
271// replaces the maximal powers of the leading monomial of p2 in p1 by
272// the same powers of n, utility for dehomogenization
273poly      pDehomogen (poly p1,poly p2,number n);
274BOOLEAN   pIsHomogeneous (poly p);
275
276// returns the leading monomial of p1 divided by the maximal power of
277// that of p2
278poly      pDivByMonom (poly p1,poly p2);
279
280// Returns as i-th entry of P the coefficient of the (i-1) power of
281// the leading monomial of p2 in p1
282void      pCancelPolyByMonom (poly p1,poly p2,polyset * P,int * SizeOfSet);
283
284// orders monoms of poly using insertion sort, performs pSetm on each
285// monom (i.e. sets Order field)
286poly      pOrdPolyInsertSetm(poly p);
287
288// orders monoms of poly using merge sort (ususally faster than
289// insertion sort). ASSUMES that pSetm was performed on monoms
290// (i.e. that Order field is set correctly)
291poly      pOrdPolyMerge(poly p);
292
293poly      pPermPoly (poly p, int * perm, ring OldRing,
294                     int *par_perm=NULL, int OldPar=0);
295void      pSetSyzComp(int k);
296
297/*BOOLEAN   pVectorHasUnitM(poly p, int * k);*/
298BOOLEAN   pVectorHasUnitB(poly p, int * k);
299void      pVectorHasUnit(poly p, int * k, int * len);
300poly      pTakeOutComp1(poly * p, int k);
301// Splits *p into two polys: *q which consists of all monoms with
302// component == comp and *p of all other monoms *lq == pLength(*q)
303// On rreturn all components pf *q == 0
304void pTakeOutComp(poly *p, Exponent_t comp, poly *q, int *lq);
305// Similar to pTakeOutComp, except that only those components are
306// taken out whose Order == order
307// ASSUME: monomial ordering is Order compatible, i.e., if m1, m2 Monoms then
308//         m1 >= m2 ==> pGetOrder(m1) >= pGetOrder(m2)
309void pDecrOrdTakeOutComp(poly *p, Exponent_t comp, Order_t order,
310                         poly *q, int *lq);
311// This is something weird -- Don't use it, unless you know what you are doing
312poly      pTakeOutComp(poly * p, int k);
313void      pDeleteComp(poly * p,int k);
314void      pNorm(poly p);
315void      pNormalize(poly p);
316poly      pSubst(poly p, int n, poly e);
317poly      pJet(poly p, int m);
318poly      pJetW(poly p, int m, short * iv);
319// maximum weigthed degree of all monomials of p, w is indexed from
320// 1..pVariables
321int       pDegW(poly p, short *w);
322
323/*-----------type conversions ----------------------------*/
324poly  pPolys2Vec(polyset p, int len);
325void  pVec2Polys(poly v, polyset *p, int *len);
326int   pVar(poly m);
327
328/*-----------specials for spoly-computations--------------*/
329poly    pMultT(poly a, poly e);
330int     pDivComp(poly p, poly q);
331BOOLEAN pCompareChain (poly p,poly p1,poly p2,poly lcm);
332BOOLEAN pEqualPolys(poly p1,poly p2);
333BOOLEAN pComparePolys(poly p1,poly p2);
334
335
336#ifdef PDEBUG
337#define pHeapTest(A,B)  pDBTest(A, B, __FILE__,__LINE__)
338#define pHeapHeapTest(p, THeap, LmHeap) pDBTest(p, THeap, LmHeap, __FILE__, __LINE__)
339#define pTest(A) pDBTest(A, mm_specHeap, __FILE__,__LINE__)
340BOOLEAN pDBTest(poly p, char *f, int l);
341BOOLEAN pDBTest(poly p, memHeap tail_heap, char *f, int l);
342BOOLEAN pDBTest(poly p,  memHeap tail_heap, memHeap lm_heap, char *f, int l);
343#else
344#define pHeapHeapTest(p,a,b)
345#define pHeapTest(A,B)
346#define pTest(A)
347#define pDBTest(A,B,C)
348#endif
349#endif
Note: See TracBrowser for help on using the repository browser.