source: git/Singular/polys-impl.cc @ 5ca9807

spielwiese
Last change on this file since 5ca9807 was c95e0f, checked in by Hans Schönemann <hannes@…>, 23 years ago
*hannes: a better fix to sev-1 problem git-svn-id: file:///usr/local/Singular/svn/trunk@5266 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.0 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: polys-impl.cc,v 1.55 2001-02-23 12:43:14 Singular 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);
54  pDelete(p);
55  rChangeCurrRing(origRing);
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    if (r->N <2*BIT_SIZEOF_LONG)
108    {
109      n=1;
110      m1=0;
111    }
112    else
113    {
114      for (; j<=(unsigned long) r->N; j++)
115      {
116        if (p_GetExp(p,j,r) > 0) i++;
117        if (i == BIT_SIZEOF_LONG) break;
118      }
119      if (i>0)
120      ev = ~((unsigned long)0) >> ((unsigned long) (BIT_SIZEOF_LONG - i));
121      return ev;
122    }
123  }
124  else
125  {
126    m1 = (n+1)*(BIT_SIZEOF_LONG - n*r->N);
127  }
128
129  n++;
130  while (i<m1)
131  {
132    ev |= GetBitFields(p_GetExp(p, j,r), i, n);
133    i += n;
134    j++;
135  }
136
137  n--;
138  while (i<BIT_SIZEOF_LONG)
139  {
140    ev |= GetBitFields(p_GetExp(p, j,r), i, n);
141    i += n;
142    j++;
143  }
144  return ev;
145}
146
147
148int rComp0_Func(poly p1,poly p2)
149{
150  int i;
151  for(i=0; i< currRing->CmpL_Size;i++)
152  {
153    if (p1->exp[i] != p2->exp[i])
154    {
155      if (p1->exp[i] > p2->exp[i])
156        return currRing->ordsgn[i];
157      else
158        return -currRing->ordsgn[i];
159    }
160  }
161  return 0;
162}
163
164#ifdef PDEBUG
165int rComp0(poly p1,poly p2)
166{
167  int i;
168  for(i=0; i<currRing->CmpL_Size;i++)
169  {
170    if (p1->exp[i] != p2->exp[i])
171    {
172      if (p1->exp[i] > p2->exp[i])
173        return currRing->ordsgn[i];
174      else
175        return -currRing->ordsgn[i];
176    }
177  }
178  return 0;
179}
180#endif
181
182#endif // POLYS_IMPL_CC
Note: See TracBrowser for help on using the repository browser.