source: git/libpolys/polys/monomials/monomials.cc @ 304ad9b

spielwiese
Last change on this file since 304ad9b was 304ad9b, checked in by Hans Schoenemann <hannes@…>, 13 years ago
p_MemCmp.h and p_MemCopy.h are now internal headers
  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[35aab3]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
[341696]4/* $Id$ */
[35aab3]5
6/***************************************************************
7 *
8 * File:       polys-impl.cc
9 * Purpose:    low-level procuders for polys.
10 *
11 * If you touch anything here, you better know what you are doing.
12 * What is here should not be used directly from other routines -- the
13 * encapsulations in polys.[h,cc] should be used, instead.
14 *
15 ***************************************************************/
16#ifndef POLYS_IMPL_CC
17#define POLYS_IMPL_CC
18
19#include <stdio.h>
20#include <string.h>
[0ceb74]21
22#include "config.h"
[35aab3]23
[b1dfaf]24#include <omalloc/omalloc.h>
[0ceb74]25#include <misc/auxiliary.h>
26
[35aab3]27#ifdef PDEBUG
28#undef NO_INLINE3
29#define NO_INLINE3
30#endif
[20b794]31#include <polys/monomials/polys-impl.h>
32
33#include <polys/monomials/ring.h>
34#include <reporter/reporter.h>
35#include <coeffs/numbers.h>
36#include <polys/monomials/ring.h>
[8a8c9e]37#include <polys/monomials/p_polys.h>
[6bec87]38#include <reporter/reporter.h>
[35aab3]39
40#ifdef PDEBUG
41int pDBsyzComp=0;
42#endif
43
44/***************************************************************
45 *
46 * Storage Managament Routines
47 *
48 ***************************************************************/
49
50
[0b5e3d]51static inline unsigned long GetBitFields(long e,
[35aab3]52                                         unsigned int s, unsigned int n)
53{
[6f1441]54#define Sy_bit_L(x)     (((unsigned long)1L)<<(x))
55  unsigned int i = 0;
56  unsigned long  ev = 0L;
[35aab3]57  assume(n > 0 && s < BIT_SIZEOF_LONG);
58  do
59  {
60    assume(s+i < BIT_SIZEOF_LONG);
[0b5e3d]61    if (e > (long) i) ev |= Sy_bit_L(s+i);
[35aab3]62    else break;
63    i++;
64  }
65  while (i < n);
66  return ev;
67}
68
69// Short Exponent Vectors are used for fast divisibility tests
70// ShortExpVectors "squeeze" an exponent vector into one word as follows:
71// Let n = BIT_SIZEOF_LONG / pVariables.
72// If n == 0 (i.e. pVariables > BIT_SIZE_OF_LONG), let m == the number
73// of non-zero exponents. If (m>BIT_SIZEOF_LONG), then sev = ~0, else
74// first m bits of sev are set to 1.
75// Otherwise (i.e. pVariables <= BIT_SIZE_OF_LONG)
76// represented by a bit-field of length n (resp. n+1 for some
77// exponents). If the value of an exponent is greater or equal to n, then
78// all of its respective n bits are set to 1. If the value of an exponent
79// is smaller than n, say m, then only the first m bits of the respective
80// n bits are set to 1, the others are set to 0.
81// This way, we have:
82// exp1 / exp2 ==> (ev1 & ~ev2) == 0, i.e.,
83// if (ev1 & ~ev2) then exp1 does not divide exp2
[cf02b22]84unsigned long p_GetShortExpVector(poly p, const ring r)
[35aab3]85{
86  assume(p != NULL);
87  if (p == NULL) return 0;
88  unsigned long ev = 0; // short exponent vector
89  unsigned int n = BIT_SIZEOF_LONG / r->N; // number of bits per exp
90  unsigned int m1; // highest bit which is filled with (n+1)
91  unsigned int i = 0, j=1;
92
93  if (n == 0)
94  {
95    if (r->N <2*BIT_SIZEOF_LONG)
96    {
97      n=1;
98      m1=0;
99    }
100    else
101    {
102      for (; j<=(unsigned long) r->N; j++)
103      {
104        if (p_GetExp(p,j,r) > 0) i++;
105        if (i == BIT_SIZEOF_LONG) break;
106      }
107      if (i>0)
108      ev = ~((unsigned long)0) >> ((unsigned long) (BIT_SIZEOF_LONG - i));
109      return ev;
110    }
111  }
112  else
113  {
114    m1 = (n+1)*(BIT_SIZEOF_LONG - n*r->N);
115  }
116
117  n++;
118  while (i<m1)
119  {
120    ev |= GetBitFields(p_GetExp(p, j,r), i, n);
121    i += n;
122    j++;
123  }
124
125  n--;
126  while (i<BIT_SIZEOF_LONG)
127  {
128    ev |= GetBitFields(p_GetExp(p, j,r), i, n);
129    i += n;
130    j++;
131  }
132  return ev;
133}
134
135#endif // POLYS_IMPL_CC
Note: See TracBrowser for help on using the repository browser.