source: git/kernel/pInline1.h @ 994445

spielwiese
Last change on this file since 994445 was 994445, checked in by Oliver Wienand <wienand@…>, 17 years ago
Neuer Koeffizientenbereich Z/n Neuer Makrodatentyp NATNUMBER = unsigned long Bisschen aufgeraeumt git-svn-id: file:///usr/local/Singular/svn/trunk@10015 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 19.1 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.10 2007-05-03 13:50:09 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  pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == TRUE);
393#ifdef HAVE_RING2TOM
394  if (r->cring == 1) {
395    long lside = (long) p_GetCoeff(a, r);
396    long rside = (long) p_GetCoeff(b, r);
397    // Später durch bitvergleiche viel schneller TODO OLIVER
398    while (lside%2 == 0 && rside%2 == 0) {
399      lside = lside / 2;
400      rside = rside / 2;
401    }
402    return (lside%2 != 0);
403  }
404  else
405#endif
406#ifdef HAVE_RINGMODN
407  if (r->cring == 2) {
408    PrintS("Not yet implemented, 2007-05-03 11:53:12");
409  }
410  else
411#endif
412  return TRUE;
413}
414
415#ifdef HAVE_RING2TOM
416/***************************************************************
417 *
418 * divisibility for rings (considers coefficients)
419 *
420 ***************************************************************/
421// return: FALSE, if there exists i, such that a->exp[i] > b->exp[i]
422//         TRUE, otherwise
423// (1) Consider long vars, instead of single exponents
424// (2) Clearly, if la > lb, then FALSE
425// (3) Suppose la <= lb, and consider first bits of single exponents in l:
426//     if TRUE, then value of these bits is la ^ lb
427//     if FALSE, then la-lb causes an "overflow" into one of those bits, i.e.,
428//               la ^ lb != la - lb
429static inline BOOLEAN _p_LmRingDivisibleByNoComp(poly a, poly b, ring r)
430{
431  BOOLEAN mDiv = _p_LmDivisibleByNoComp(a, b, r);
432  if (mDiv) {
433    long lside = (long) p_GetCoeff(a,r);
434    long rside = (long) p_GetCoeff(b,r);
435    // Später durch bitvergleiche viel schneller  TODO OLIVER
436    while (lside%2 == 0 && rside%2 == 0) {
437      lside = lside / 2;
438      rside = rside / 2;
439    }
440    return (lside%2 != 0);     // Is lside, i.e. LC(a), a unit?
441  }
442  return FALSE;
443}
444#endif
445
446static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, ring r_a, poly b, ring r_b)
447{
448  int i=r_a->N;
449  pAssume1(r_a->N == r_b->N);
450
451  do
452  {
453    if (p_GetExp(a,i,r_a) > p_GetExp(b,i,r_b))
454      return FALSE;
455    i--;
456  }
457  while (i);
458#ifdef HAVE_RING2TOM
459  if (r_a->cring == 1 || r_b->cring == 1) {
460    long lside = (long) p_GetCoeff(a, r_a);
461    long rside = (long) p_GetCoeff(b, r_b);
462    while (lside%2 == 0 && rside%2 == 0) {
463      lside = lside / 2;
464      rside = rside / 2;
465    }
466    return (lside%2 != 0);
467  }
468  else
469#endif
470#ifdef HAVE_RINGMODN
471  if (r_a->cring == 2 || r_b->cring == 2) {
472    PrintS("Not yet implemented, 2007-05-02 11:56:44");
473  }
474  else
475#endif
476    return TRUE;
477}
478
479#ifdef HAVE_RING2TOM
480static inline BOOLEAN _p_LmRingDivisibleByNoComp(poly a, ring r_a, poly b, ring r_b)
481{
482  BOOLEAN mDiv = _p_LmDivisibleByNoComp(a, r_a, b, r_b);
483  if (mDiv) {
484    long lside = (long) p_GetCoeff(a, r_a);
485    long rside = (long) p_GetCoeff(b, r_b);
486    // Später durch bitvergleiche viel schneller TODO OLIVER
487    while (lside%2 == 0 && rside%2 == 0) {
488      lside = lside / 2;
489      rside = rside / 2;
490    }
491    return (lside%2 != 0);
492  }
493  return FALSE;
494}
495#endif
496
497static inline BOOLEAN _p_LmDivisibleBy(poly a, poly b, ring r)
498{
499  if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
500    return _p_LmDivisibleByNoComp(a, b, r);
501  return FALSE;
502}
503static inline BOOLEAN _p_LmDivisibleBy(poly a, ring r_a, poly b, ring r_b)
504{
505  if (p_GetComp(a, r_a) == 0 || p_GetComp(a,r_a) == p_GetComp(b,r_b))
506    return _p_LmDivisibleByNoComp(a, r_a, b, r_b);
507  return FALSE;
508}
509PINLINE1 BOOLEAN p_LmDivisibleByNoComp(poly a, poly b, ring r)
510{
511  p_LmCheckPolyRing1(a, r);
512  p_LmCheckPolyRing1(b, r);
513  return _p_LmDivisibleByNoComp(a, b, r);
514}
515PINLINE1 BOOLEAN p_LmDivisibleBy(poly a, poly b, ring r)
516{
517  p_LmCheckPolyRing1(b, r);
518  pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r));
519  if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
520    return _p_LmDivisibleByNoComp(a, b, r);
521  return FALSE;
522}
523
524#ifdef HAVE_RING2TOM
525PINLINE1 BOOLEAN p_LmRingDivisibleBy(poly a, poly b, ring r)
526{
527  p_LmCheckPolyRing1(b, r);
528  pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r));
529  if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
530    return _p_LmRingDivisibleByNoComp(a, b, r);
531  return FALSE;
532}
533#endif
534
535PINLINE1 BOOLEAN p_DivisibleBy(poly a, poly b, ring r)
536{
537  pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r));
538  pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r));
539
540  if (a != NULL && (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)))
541#ifdef HAVE_RING2TOM
542    if (r->cring == 1) {
543      return _p_LmRingDivisibleByNoComp(a,b,r);
544    }
545    else
546#endif
547#ifdef HAVE_RINGMODN
548    if (r->cring == 2) {
549      PrintS("Not yet implemented 2007-05-02 11:55:20");
550      return FALSE;
551    }
552    else
553#endif
554      return _p_LmDivisibleByNoComp(a,b,r);
555  return FALSE;
556}
557PINLINE1 BOOLEAN p_DivisibleBy(poly a, ring r_a, poly b, ring r_b)
558{
559  pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r_b));
560  pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r_a));
561  if (a != NULL) {
562#ifdef HAVE_RING2TOM
563    if (r_a->cring == 1) {
564      return _p_LmRingDivisibleByNoComp(a, r_a, b, r_b);
565    }
566    else
567#endif
568#ifdef HAVE_RINGMODN
569    if (r_a->cring == 2) {
570      PrintS("Not yet implemented, 2007-05-03 11:59:20");
571    }
572    else
573#endif
574      return _p_LmDivisibleBy(a, r_a, b, r_b);
575  }
576  return FALSE;
577}
578PINLINE1 BOOLEAN p_LmDivisibleBy(poly a, ring r_a, poly b, ring r_b)
579{
580  p_LmCheckPolyRing(a, r_a);
581  p_LmCheckPolyRing(b, r_b);
582  return _p_LmDivisibleBy(a, r_a, b, r_b);
583}
584PINLINE1 BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a,
585                                    poly b, unsigned long not_sev_b, ring r)
586{
587  p_LmCheckPolyRing1(a, r);
588  p_LmCheckPolyRing1(b, r);
589#ifndef PDIV_DEBUG
590  _pPolyAssume2(p_GetShortExpVector(a, r) == sev_a, a, r);
591  _pPolyAssume2(p_GetShortExpVector(b, r) == ~ not_sev_b, b, r);
592
593  if (sev_a & not_sev_b)
594  {
595    pAssume1(p_LmDivisibleByNoComp(a, b, r) == FALSE);
596    return FALSE;
597  }
598  return p_LmDivisibleBy(a, b, r);
599#else
600  return pDebugLmShortDivisibleBy(a, sev_a, r, b, not_sev_b, r);
601#endif
602}
603
604#ifdef HAVE_RING2TOM
605PINLINE1 BOOLEAN p_LmRingShortDivisibleBy(poly a, unsigned long sev_a,
606                                          poly b, unsigned long not_sev_b, ring r)
607{
608  p_LmCheckPolyRing1(a, r);
609  p_LmCheckPolyRing1(b, r);
610#ifndef PDIV_DEBUG
611  _pPolyAssume2(p_GetShortExpVector(a, r) == sev_a, a, r);
612  _pPolyAssume2(p_GetShortExpVector(b, r) == ~ not_sev_b, b, r);
613
614  if (sev_a & not_sev_b)
615  {
616    pAssume1(_p_LmRingDivisibleByNoComp(a, b, r) == FALSE);
617    return FALSE;
618  }
619  return p_LmRingDivisibleBy(a, b, r);
620#else
621  return pDebugLmShortDivisibleBy(a, sev_a, r, b, not_sev_b, r);
622#endif
623}
624#endif
625
626PINLINE1 BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, ring r_a,
627                                      poly b, unsigned long not_sev_b, ring r_b)
628{
629  p_LmCheckPolyRing1(a, r_a);
630  p_LmCheckPolyRing1(b, r_b);
631#ifndef PDIV_DEBUG
632  _pPolyAssume2(p_GetShortExpVector(a, r_a) == sev_a, a, r_a);
633  _pPolyAssume2(p_GetShortExpVector(b, r_b) == ~ not_sev_b, b, r_b);
634
635  if (sev_a & not_sev_b)
636  {
637    pAssume1(_p_LmDivisibleByNoComp(a, r_a, b, r_b) == FALSE);
638    return FALSE;
639  }
640  return _p_LmDivisibleBy(a, r_a, b, r_b);
641#else
642  return pDebugLmShortDivisibleBy(a, sev_a, r_a, b, not_sev_b, r_b);
643#endif
644}
645
646/***************************************************************
647 *
648 * Misc things on Lm
649 *
650 ***************************************************************/
651// test if the monomial is a constant as a vector component
652// i.e., test if all exponents are zero
653PINLINE1 BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
654{
655  //p_LmCheckPolyRing(p, r);
656  int i = r->VarL_Size - 1;
657
658  do
659  {
660    if (p->exp[r->VarL_Offset[i]] != 0)
661      return FALSE;
662    i--;
663  }
664  while (i >= 0);
665  return TRUE;
666}
667// test if monomial is a constant, i.e. if all exponents and the component
668// is zero
669PINLINE1 BOOLEAN p_LmIsConstant(const poly p, const ring r)
670{
671  if (p_LmIsConstantComp(p, r))
672    return (p_GetComp(p, r) == 0);
673  return FALSE;
674}
675
676// like the respective p_LmIs* routines, except that p might be empty
677PINLINE1 BOOLEAN p_IsConstantComp(const poly p, const ring r)
678{
679  if (p == NULL) return TRUE;
680  return (pNext(p)==NULL) && p_LmIsConstantComp(p, r);
681}
682
683PINLINE1 BOOLEAN p_IsConstant(const poly p, const ring r)
684{
685  if (p == NULL) return TRUE;
686  return (pNext(p)==NULL) && p_LmIsConstant(p, r);
687}
688
689PINLINE1 BOOLEAN p_IsUnit(const poly p, const ring r)
690{
691  if (p == NULL) return FALSE;
692  return p_LmIsConstant(p, r);
693}
694
695PINLINE1 BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2,
696                                      const ring r)
697{
698  p_LmCheckPolyRing(p1, r);
699  p_LmCheckPolyRing(p2, r);
700  unsigned long l1, l2, divmask = r->divmask;
701  int i;
702
703  for (i=0; i<r->VarL_Size; i++)
704  {
705    l1 = p1->exp[r->VarL_Offset[i]];
706    l2 = p2->exp[r->VarL_Offset[i]];
707    // do the divisiblity trick
708    if ( (l1 > ULONG_MAX - l2) ||
709         (((l1 & divmask) ^ (l2 & divmask)) != ((l1 + l2) & divmask)))
710      return FALSE;
711  }
712  return TRUE;
713}
714#else
715PINLINE1 BOOLEAN p_IsUnit(const poly p, const ring r);
716
717#endif // !defined(NO_PINLINE1) || defined(PINLINE1_CC)
718#endif // PINLINE1_CC
Note: See TracBrowser for help on using the repository browser.