source: git/Singular/polys-impl.cc @ 4e6cf2

spielwiese
Last change on this file since 4e6cf2 was 4e6cf2, checked in by Olaf Bachmann <obachman@…>, 23 years ago
* clean up git-svn-id: file:///usr/local/Singular/svn/trunk@4681 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: polys-impl.cc,v 1.52 2000-10-30 13:40:24 obachman Exp $ */
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 "mod2.h"
22
23#include "omalloc.h"
24#ifdef PDEBUG
25#undef NO_INLINE3
26#define NO_INLINE3
27#endif
28#include "polys-impl.h"
29
30#include "tok.h"
31#include "structs.h"
32#include "febase.h"
33#include "numbers.h"
34#include "polys.h"
35#include "ring.h"
36#include "p_Procs.h"
37#include "dError.h"
38
39#ifdef PDEBUG
40int pDBsyzComp=0;
41#endif
42
43/***************************************************************
44 *
45 * Storage Managament Routines
46 *
47 ***************************************************************/
48
49
50void ppDelete(poly* p, ring rg)
51{
52  ring origRing = currRing;
53  rChangeCurrRing(rg, FALSE);
54  pDelete(p);
55  rChangeCurrRing(origRing, FALSE);
56}
57
58
59poly pHeadProc(poly p)
60{
61  return pHead(p);
62}
63
64
65static inline unsigned long GetBitFields(Exponent_t e,
66                                         unsigned int s, unsigned int n)
67{
68  unsigned int i = 0, ev = 0;
69  assume(n > 0 && s < BIT_SIZEOF_LONG);
70  do
71  {
72    assume(s+i < BIT_SIZEOF_LONG);
73    if (e > (Exponent_t) i) ev |= Sy_bit(s+i);
74    else break;
75    i++;
76  }
77  while (i < n);
78  return ev;
79}
80
81// Short Exponent Vectors are used for fast divisibility tests
82// ShortExpVectors "squeeze" an exponent vector into one word as follows:
83// Let n = BIT_SIZEOF_LONG / pVariables.
84// If n == 0 (i.e. pVariables > BIT_SIZE_OF_LONG), let m == the number
85// of non-zero exponents. If (m>BIT_SIZEOF_LONG), then sev = ~0, else
86// first m bits of sev are set to 1.
87// Otherwise (i.e. pVariables <= BIT_SIZE_OF_LONG)
88// represented by a bit-field of length n (resp. n+1 for some
89// exponents). If the value of an exponent is greater or equal to n, then
90// all of its respective n bits are set to 1. If the value of an exponent
91// is smaller than n, say m, then only the first m bits of the respective
92// n bits are set to 1, the others are set to 0.
93// This way, we have:
94// exp1 / exp2 ==> (ev1 & ~ev2) == 0, i.e.,
95// if (ev1 & ~ev2) then exp1 does not divide exp2
96unsigned long p_GetShortExpVector(poly p, ring r)
97{
98  assume(p != NULL);
99  if (p == NULL) return 0;
100  unsigned long ev = 0; // short exponent vector
101  unsigned int n = BIT_SIZEOF_LONG / r->N; // number of bits per exp
102  unsigned int m1; // highest bit which is filled with (n+1)
103  unsigned int i = 0, j=1;
104
105  if (n == 0)
106  {
107    for (; j<=(unsigned long) r->N; j++)
108    {
109      if (p_GetExp(p,j,r) > 0) i++;
110      if (i == BIT_SIZEOF_LONG) break;
111    }
112    ev = (unsigned long) ~0 >> ((unsigned long) (BIT_SIZEOF_LONG - i));
113    return ev;
114  }
115  else
116  {
117    m1 = (n+1)*(BIT_SIZEOF_LONG - n*r->N);
118  }
119
120  n++;
121  while (i<m1)
122  {
123    ev |= GetBitFields(p_GetExp(p, j,r), i, n);
124    i += n;
125    j++;
126  }
127
128  n--;
129  while (i<BIT_SIZEOF_LONG)
130  {
131    ev |= GetBitFields(p_GetExp(p, j,r), i, n);
132    i += n;
133    j++;
134  }
135  return ev;
136}
137
138
139int rComp0_Func(poly p1,poly p2)
140{
141  int i;
142  for(i=0; i< currRing->CmpL_Size;i++)
143  {
144    if (p1->exp[i] != p2->exp[i])
145    {
146      if (p1->exp[i] > p2->exp[i])
147        return currRing->ordsgn[i];
148      else
149        return -currRing->ordsgn[i];
150    }
151  }
152  return 0;
153}
154
155#ifdef PDEBUG
156int rComp0(poly p1,poly p2)
157{
158  int i;
159  for(i=0; i<currRing->CmpL_Size;i++)
160  {
161    if (p1->exp[i] != p2->exp[i])
162    {
163      if (p1->exp[i] > p2->exp[i])
164        return currRing->ordsgn[i];
165      else
166        return -currRing->ordsgn[i];
167    }
168  }
169  return 0;
170}
171#endif
172
173#endif // POLYS_IMPL_CC
Note: See TracBrowser for help on using the repository browser.