source: git/kernel/pInline1.h @ 91b031

spielwiese
Last change on this file since 91b031 was dd5534, checked in by Frank Seelisch <seelisch@…>, 13 years ago
fixed dim of ideal and sum of ideals over rings (with Anne) git-svn-id: file:///usr/local/Singular/svn/trunk@13973 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 16.9 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/***************************************************************
5 *  File:    pInline1.h
6 *  Purpose: implementation of poly procs which iter over ExpVector
7 *  Author:  obachman (Olaf Bachmann)
8 *  Created: 8/00
9 *  Version: $Id$
10 *******************************************************************/
11#ifndef PINLINE1_H
12#define PINLINE1_H
13
14#ifndef PDIV_DEBUG
15// define to enable debugging/statistics of pLmShortDivisibleBy
16// #define PDIV_DEBUG
17#endif
18#include <omalloc/mylimits.h>
19#include <kernel/p_MemCmp.h>
20#include <kernel/structs.h>
21#include <kernel/ring.h>
22#include <kernel/numbers.h>
23
24#if PDEBUG > 0 || defined(NO_PINLINE1)
25
26#define _p_LmCmpAction(p, q, r, actionE, actionG, actionS)  \
27do                                                          \
28{                                                           \
29  int _cmp = p_LmCmp(p,q,r);                                \
30  if (_cmp == 0) actionE;                                   \
31  if (_cmp == 1) actionG;                                   \
32  actionS;                                                  \
33}                                                           \
34while(0)
35
36#else
37
38#define _p_LmCmpAction(p, q, r, actionE, actionG, actionS)                      \
39 p_MemCmp_LengthGeneral_OrdGeneral(p->exp, q->exp, r->CmpL_Size, r->ordsgn,    \
40                                   actionE, actionG, actionS)
41
42#endif
43
44#ifdef PDIV_DEBUG
45BOOLEAN pDebugLmShortDivisibleBy(poly p1, unsigned long sev_1, const ring r_1,
46                                 poly p2, unsigned long not_sev_2, const ring r_2);
47BOOLEAN p_DebugLmDivisibleByNoComp(poly a, poly b, const ring r);
48#define pDivAssume  pAssume
49#else
50#define pDivAssume(x)   ((void)0)
51#endif
52
53#if !defined(NO_PINLINE1) || defined(PINLINE1_CC)
54
55#include <omalloc/omalloc.h>
56#include <kernel/numbers.h>
57#include <kernel/p_polys.h>
58#include <kernel/p_MemAdd.h>
59#include <kernel/p_MemCopy.h>
60
61/***************************************************************
62 *
63 * Allocation/Initalization/Deletion
64 *
65 ***************************************************************/
66// adjustments for negative weights
67PINLINE1 void p_MemAdd_NegWeightAdjust(poly p, const ring r)
68{
69  if (r->NegWeightL_Offset != NULL)
70  {
71    for (int i=r->NegWeightL_Size-1; i>=0; i--)
72    {
73      p->exp[r->NegWeightL_Offset[i]] -= POLY_NEGWEIGHT_OFFSET;
74    }
75  }
76}
77PINLINE1 void p_MemSub_NegWeightAdjust(poly p, const ring r)
78{
79  if (r->NegWeightL_Offset != NULL)
80  {
81    for (int i=r->NegWeightL_Size-1; i>=0; i--)
82    {
83      p->exp[r->NegWeightL_Offset[i]] += POLY_NEGWEIGHT_OFFSET;
84    }
85  }
86}
87// ExpVextor(d_p) = ExpVector(s_p)
88PINLINE1 void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
89{
90  p_LmCheckPolyRing1(d_p, r);
91  p_LmCheckPolyRing1(s_p, r);
92  p_MemCopy_LengthGeneral(d_p->exp, s_p->exp, r->ExpL_Size);
93}
94
95PINLINE1 poly p_Init(const ring r, omBin bin)
96{
97  p_CheckRing1(r);
98  pAssume1(bin != NULL && r->PolyBin->sizeW == bin->sizeW);
99  poly p;
100  omTypeAlloc0Bin(poly, p, bin);
101  p_MemAdd_NegWeightAdjust(p, r);
102  p_SetRingOfLm(p, r);
103  return p;
104}
105PINLINE1 poly p_Init(const ring r)
106{
107  return p_Init(r, r->PolyBin);
108}
109
110PINLINE1 poly p_LmInit(poly p, const ring r)
111{
112  p_LmCheckPolyRing1(p, r);
113  poly np;
114  omTypeAllocBin(poly, np, r->PolyBin);
115  p_SetRingOfLm(np, r);
116  p_MemCopy_LengthGeneral(np->exp, p->exp, r->ExpL_Size);
117  pNext(np) = NULL;
118  pSetCoeff0(np, NULL);
119  return np;
120}
121PINLINE1 poly p_LmInit(poly s_p, const ring s_r, const ring d_r, omBin d_bin)
122{
123  p_LmCheckPolyRing1(s_p, s_r);
124  p_CheckRing(d_r);
125  pAssume1(d_r->N <= s_r->N);
126  poly d_p = p_Init(d_r, d_bin);
127  for (int i=d_r->N; i>0; i--)
128  {
129    p_SetExp(d_p, i, p_GetExp(s_p, i,s_r), d_r);
130  }
131  if (rRing_has_Comp(d_r))
132  {
133    p_SetComp(d_p, p_GetComp(s_p,s_r), d_r);
134  }
135  p_Setm(d_p, d_r);
136  return d_p;
137}
138PINLINE1 poly p_LmInit(poly s_p, const ring s_r, const ring d_r)
139{
140  pAssume1(d_r != NULL);
141  return p_LmInit(s_p, s_r, d_r, d_r->PolyBin);
142}
143PINLINE1 poly p_Head(poly p, const ring r)
144{
145  if (p == NULL) return NULL;
146  p_LmCheckPolyRing1(p, r);
147  poly np;
148  omTypeAllocBin(poly, np, r->PolyBin);
149  p_SetRingOfLm(np, r);
150  p_MemCopy_LengthGeneral(np->exp, p->exp, r->ExpL_Size);
151  pNext(np) = NULL;
152  pSetCoeff0(np, n_Copy(pGetCoeff(p), r));
153  return np;
154}
155// set all exponents l..k to 0, assume exp. k+1..n and 1..l-1 are in
156// different blocks
157// set coeff to 1
158PINLINE1 poly p_GetExp_k_n(poly p, int l, int k, const ring r)
159{
160  if (p == NULL) return NULL;
161  p_LmCheckPolyRing1(p, r);
162  poly np;
163  omTypeAllocBin(poly, np, r->PolyBin);
164  p_SetRingOfLm(np, r);
165  p_MemCopy_LengthGeneral(np->exp, p->exp, r->ExpL_Size);
166  pNext(np) = NULL;
167  pSetCoeff0(np, n_Init(1, r));
168  int i;
169  for(i=l;i<=k;i++)
170  {
171    //np->exp[(r->VarOffset[i] & 0xffffff)] =0;
172    p_SetExp(np,i,0,r);
173  }
174  p_Setm(np,r);
175  return np;
176}
177
178PINLINE1 poly p_LmShallowCopyDelete(poly p, const ring r, omBin bin)
179{
180  p_LmCheckPolyRing1(p, r);
181  pAssume1(bin->sizeW == r->PolyBin->sizeW);
182  poly new_p = p_New(r);
183  p_MemCopy_LengthGeneral(new_p->exp, p->exp, r->ExpL_Size);
184  pSetCoeff0(new_p, pGetCoeff(p));
185  pNext(new_p) = pNext(p);
186  omFreeBinAddr(p);
187  return new_p;
188}
189
190/***************************************************************
191 *
192 * Operation on ExpVectors
193 *
194 ***************************************************************/
195// ExpVector(p1) += ExpVector(p2)
196PINLINE1 void p_ExpVectorAdd(poly p1, poly p2, const ring r)
197{
198  p_LmCheckPolyRing1(p1, r);
199  p_LmCheckPolyRing1(p2, r);
200#if PDEBUG >= 1
201  for (int i=1; i<=r->N; i++)
202    pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask);
203  pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0);
204#endif
205
206  p_MemAdd_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size);
207  p_MemAdd_NegWeightAdjust(p1, r);
208}
209// ExpVector(p1) -= ExpVector(p2)
210PINLINE1 void p_ExpVectorSub(poly p1, poly p2, const ring r)
211{
212  p_LmCheckPolyRing1(p1, r);
213  p_LmCheckPolyRing1(p2, r);
214#if PDEBUG >= 1
215  for (int i=1; i<=r->N; i++)
216    pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r));
217  pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0 ||
218          p_GetComp(p1, r) == p_GetComp(p2, r));
219#endif
220
221  p_MemSub_LengthGeneral(p1->exp, p2->exp, r->ExpL_Size);
222  p_MemSub_NegWeightAdjust(p1, r);
223
224}
225// ExpVector(p1) += ExpVector(p2) - ExpVector(p3)
226PINLINE1 void p_ExpVectorAddSub(poly p1, poly p2, poly p3, const ring r)
227{
228  p_LmCheckPolyRing1(p1, r);
229  p_LmCheckPolyRing1(p2, r);
230  p_LmCheckPolyRing1(p3, r);
231#if PDEBUG >= 1
232  for (int i=1; i<=r->N; i++)
233    pAssume1(p_GetExp(p1, i, r) + p_GetExp(p2, i, r) >= p_GetExp(p3, i, r));
234  pAssume1(p_GetComp(p1, r) == 0 ||
235           (p_GetComp(p2, r) - p_GetComp(p3, r) == 0) ||
236           (p_GetComp(p1, r) == p_GetComp(p2, r) - p_GetComp(p3, r)));
237#endif
238
239  p_MemAddSub_LengthGeneral(p1->exp, p2->exp, p3->exp, r->ExpL_Size);
240  // no need to adjust in case of NegWeights
241}
242
243// ExpVector(pr) = ExpVector(p1) + ExpVector(p2)
244PINLINE1 void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
245{
246  p_LmCheckPolyRing1(p1, r);
247  p_LmCheckPolyRing1(p2, r);
248  p_LmCheckPolyRing1(pr, r);
249#if PDEBUG >= 1
250  for (int i=1; i<=r->N; i++)
251    pAssume1((unsigned long) (p_GetExp(p1, i, r) + p_GetExp(p2, i, r)) <= r->bitmask);
252  pAssume1(p_GetComp(p1, r) == 0 || p_GetComp(p2, r) == 0);
253#endif
254
255  p_MemSum_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size);
256  p_MemAdd_NegWeightAdjust(pr, r);
257}
258// ExpVector(pr) = ExpVector(p1) - ExpVector(p2)
259PINLINE1 void p_ExpVectorDiff(poly pr, poly p1, poly p2, const ring r)
260{
261  p_LmCheckPolyRing1(p1, r);
262  p_LmCheckPolyRing1(p2, r);
263  p_LmCheckPolyRing1(pr, r);
264#if PDEBUG >= 2
265  for (int i=1; i<=r->N; i++)
266    pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r));
267  pAssume1(!rRing_has_Comp(r) || p_GetComp(p1, r) == p_GetComp(p2, r));
268#endif
269
270  p_MemDiff_LengthGeneral(pr->exp, p1->exp, p2->exp, r->ExpL_Size);
271  p_MemSub_NegWeightAdjust(pr, r);
272}
273
274PINLINE1 BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r)
275{
276  p_LmCheckPolyRing1(p1, r);
277  p_LmCheckPolyRing1(p2, r);
278
279  int i = r->ExpL_Size;
280  unsigned long *ep = p1->exp;
281  unsigned long *eq = p2->exp;
282
283  do
284  {
285    i--;
286    if (ep[i] != eq[i]) return FALSE;
287  }
288  while (i);
289  return TRUE;
290}
291
292PINLINE1 long p_Totaldegree(poly p, const ring r)
293{
294  p_LmCheckPolyRing1(p, r);
295  unsigned long s = p_GetTotalDegree(p->exp[r->VarL_Offset[0]],
296                                     r,
297                                     r->MinExpPerLong);
298  for (int i=r->VarL_Size-1; i>0; i--)
299  {
300    s += p_GetTotalDegree(p->exp[r->VarL_Offset[i]], r);
301  }
302  return (long)s;
303}
304
305PINLINE1 void p_GetExpV(poly p, int *ev, const ring r)
306{
307  p_LmCheckPolyRing1(p, r);
308  for (int j = r->N; j; j--)
309      ev[j] = p_GetExp(p, j, r);
310
311  ev[0] = _p_GetComp(p, r);
312}
313PINLINE1 void p_SetExpV(poly p, int *ev, const ring r)
314{
315  p_LmCheckPolyRing1(p, r);
316  for (int j = r->N; j; j--)
317      p_SetExp(p, j, ev[j], r);
318
319  p_SetComp(p, ev[0],r);
320  p_Setm(p, r);
321}
322
323/***************************************************************
324 *
325 * Comparison w.r.t. monomial ordering
326 *
327 ***************************************************************/
328PINLINE1 int p_LmCmp(poly p, poly q, const ring r)
329{
330  p_LmCheckPolyRing1(p, r);
331  p_LmCheckPolyRing1(q, r);
332
333  p_MemCmp_LengthGeneral_OrdGeneral(p->exp, q->exp, r->CmpL_Size, r->ordsgn,
334                                    return 0, return 1, return -1);
335}
336
337
338/***************************************************************
339 *
340 * divisibility
341 *
342 ***************************************************************/
343// return: FALSE, if there exists i, such that a->exp[i] > b->exp[i]
344//         TRUE, otherwise
345// (1) Consider long vars, instead of single exponents
346// (2) Clearly, if la > lb, then FALSE
347// (3) Suppose la <= lb, and consider first bits of single exponents in l:
348//     if TRUE, then value of these bits is la ^ lb
349//     if FALSE, then la-lb causes an "overflow" into one of those bits, i.e.,
350//               la ^ lb != la - lb
351static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, poly b, const ring r)
352{
353  int i=r->VarL_Size - 1;
354  unsigned long divmask = r->divmask;
355  unsigned long la, lb;
356
357  if (r->VarL_LowIndex >= 0)
358  {
359    i += r->VarL_LowIndex;
360    do
361    {
362      la = a->exp[i];
363      lb = b->exp[i];
364      if ((la > lb) ||
365          (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask)))
366      {
367        pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE);
368        return FALSE;
369      }
370      i--;
371    }
372    while (i>=r->VarL_LowIndex);
373  }
374  else
375  {
376    do
377    {
378      la = a->exp[r->VarL_Offset[i]];
379      lb = b->exp[r->VarL_Offset[i]];
380      if ((la > lb) ||
381          (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask)))
382      {
383        pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE);
384        return FALSE;
385      }
386      i--;
387    }
388    while (i>=0);
389  }
390#ifdef HAVE_RINGS
391  pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r)));
392  return (!rField_is_Ring(r)) || nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r));
393#else
394  pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == TRUE);
395  return TRUE;
396#endif
397}
398
399static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, const ring r_a, poly b, const ring r_b)
400{
401  int i=r_a->N;
402  pAssume1(r_a->N == r_b->N);
403
404  do
405  {
406    if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b))
407      return FALSE;
408    i--;
409  }
410  while (i);
411#ifdef HAVE_RINGS
412  return nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r));
413#else
414  return TRUE;
415#endif
416}
417
418#ifdef HAVE_RATGRING
419static inline BOOLEAN _p_LmDivisibleByNoCompPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end)
420{
421  int i=end;
422  pAssume1(r_a->N == r_b->N);
423
424  do
425  {
426    if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b))
427      return FALSE;
428    i--;
429  }
430  while (i>=start);
431#ifdef HAVE_RINGS
432  return nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r));
433#else
434  return TRUE;
435#endif
436}
437static inline BOOLEAN _p_LmDivisibleByPart(poly a, const ring r_a, poly b, const ring r_b,const int start, const int end)
438{
439  if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b))
440    return _p_LmDivisibleByNoCompPart(a, r_a, b, r_b,start,end);
441  return FALSE;
442}
443PINLINE1 BOOLEAN p_LmDivisibleByPart(poly a, poly b, const ring r,const int start, const int end)
444{
445  p_LmCheckPolyRing1(b, r);
446  pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r));
447  if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
448    return _p_LmDivisibleByNoCompPart(a, r, b, r,start, end);
449  return FALSE;
450}
451#endif
452static inline BOOLEAN _p_LmDivisibleBy(poly a, poly b, const ring r)
453{
454  if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
455    return _p_LmDivisibleByNoComp(a, b, r);
456  return FALSE;
457}
458static inline BOOLEAN _p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b)
459{
460  if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b))
461    return _p_LmDivisibleByNoComp(a, r_a, b, r_b);
462  return FALSE;
463}
464PINLINE1 BOOLEAN p_LmDivisibleByNoComp(poly a, poly b, const ring r)
465{
466  p_LmCheckPolyRing1(a, r);
467  p_LmCheckPolyRing1(b, r);
468  return _p_LmDivisibleByNoComp(a, b, r);
469}
470PINLINE1 BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
471{
472  p_LmCheckPolyRing1(b, r);
473  pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r));
474  if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
475    return _p_LmDivisibleByNoComp(a, b, r);
476  return FALSE;
477}
478
479PINLINE1 BOOLEAN p_DivisibleBy(poly a, poly b, const ring r)
480{
481  pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r));
482  pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r));
483
484  if (a != NULL && (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)))
485      return _p_LmDivisibleByNoComp(a,b,r);
486  return FALSE;
487}
488PINLINE1 BOOLEAN p_DivisibleBy(poly a, const ring r_a, poly b, const ring r_b)
489{
490  pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r_b));
491  pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r_a));
492  if (a != NULL) {
493      return _p_LmDivisibleBy(a, r_a, b, r_b);
494  }
495  return FALSE;
496}
497PINLINE1 BOOLEAN p_LmDivisibleBy(poly a, const ring r_a, poly b, const ring r_b)
498{
499  p_LmCheckPolyRing(a, r_a);
500  p_LmCheckPolyRing(b, r_b);
501  return _p_LmDivisibleBy(a, r_a, b, r_b);
502}
503PINLINE1 BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a,
504                                    poly b, unsigned long not_sev_b, const ring r)
505{
506  p_LmCheckPolyRing1(a, r);
507  p_LmCheckPolyRing1(b, r);
508#ifndef PDIV_DEBUG
509  pPolyAssume2(p_GetShortExpVector(a, r) == sev_a, a, r);
510  pPolyAssume2(p_GetShortExpVector(b, r) == ~ not_sev_b, b, r);
511
512  if (sev_a & not_sev_b)
513  {
514    pAssume1(p_LmDivisibleByNoComp(a, b, r) == FALSE);
515    return FALSE;
516  }
517  return p_LmDivisibleBy(a, b, r);
518#else
519  return pDebugLmShortDivisibleBy(a, sev_a, r, b, not_sev_b, r);
520#endif
521}
522
523PINLINE1 BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, const ring r_a,
524                                      poly b, unsigned long not_sev_b, const ring r_b)
525{
526  p_LmCheckPolyRing1(a, r_a);
527  p_LmCheckPolyRing1(b, r_b);
528#ifndef PDIV_DEBUG
529  pPolyAssume2(p_GetShortExpVector(a, r_a) == sev_a, a, r_a);
530  pPolyAssume2(p_GetShortExpVector(b, r_b) == ~ not_sev_b, b, r_b);
531
532  if (sev_a & not_sev_b)
533  {
534    pAssume1(_p_LmDivisibleByNoComp(a, r_a, b, r_b) == FALSE);
535    return FALSE;
536  }
537  return _p_LmDivisibleBy(a, r_a, b, r_b);
538#else
539  return pDebugLmShortDivisibleBy(a, sev_a, r_a, b, not_sev_b, r_b);
540#endif
541}
542
543/***************************************************************
544 *
545 * Misc things on Lm
546 *
547 ***************************************************************/
548// test if the monomial is a constant as a vector component
549// i.e., test if all exponents are zero
550PINLINE1 BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
551{
552  //p_LmCheckPolyRing(p, r);
553  int i = r->VarL_Size - 1;
554
555  do
556  {
557    if (p->exp[r->VarL_Offset[i]] != 0)
558      return FALSE;
559    i--;
560  }
561  while (i >= 0);
562  return TRUE;
563}
564// test if monomial is a constant, i.e. if all exponents and the component
565// is zero
566PINLINE1 BOOLEAN p_LmIsConstant(const poly p, const ring r)
567{
568  if (p_LmIsConstantComp(p, r))
569    return (p_GetComp(p, r) == 0);
570  return FALSE;
571}
572
573// like the respective p_LmIs* routines, except that p might be empty
574PINLINE1 BOOLEAN p_IsConstantComp(const poly p, const ring r)
575{
576  if (p == NULL) return TRUE;
577  return (pNext(p)==NULL) && p_LmIsConstantComp(p, r);
578}
579
580PINLINE1 BOOLEAN p_IsConstant(const poly p, const ring r)
581{
582  if (p == NULL) return TRUE;
583  return (pNext(p)==NULL) && p_LmIsConstant(p, r);
584}
585
586PINLINE1 BOOLEAN p_IsUnit(const poly p, const ring r)
587{
588  if (p == NULL) return FALSE;
589#ifdef HAVE_RINGS
590  if (rField_is_Ring(currRing))
591    return (p_LmIsConstant(p, r) && nIsUnit(pGetCoeff(p)));
592#endif
593  return p_LmIsConstant(p, r);
594}
595
596PINLINE1 BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2,
597                                      const ring r)
598{
599  p_LmCheckPolyRing(p1, r);
600  p_LmCheckPolyRing(p2, r);
601  unsigned long l1, l2, divmask = r->divmask;
602  int i;
603
604  for (i=0; i<r->VarL_Size; i++)
605  {
606    l1 = p1->exp[r->VarL_Offset[i]];
607    l2 = p2->exp[r->VarL_Offset[i]];
608    // do the divisiblity trick
609    if ( (l1 > ULONG_MAX - l2) ||
610         (((l1 & divmask) ^ (l2 & divmask)) != ((l1 + l2) & divmask)))
611      return FALSE;
612  }
613  return TRUE;
614}
615#else
616PINLINE1 BOOLEAN p_IsUnit(const poly p, const ring r);
617
618#endif // !defined(NO_PINLINE1) || defined(PINLINE1_CC)
619#endif // PINLINE1_CC
Note: See TracBrowser for help on using the repository browser.