source: git/libpolys/polys/monomials/monomials.cc @ 5679049

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