source: git/kernel/pInline1.h @ 18ff4c

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