source: git/kernel/pInline1.h @ 585bbcb

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