source: git/kernel/polys-impl.cc @ 91f1a3

spielwiese
Last change on this file since 91f1a3 was 35aab3, checked in by Hans Schönemann <hannes@…>, 21 years ago
This commit was generated by cvs2svn to compensate for changes in r6879, which included commits to RCS files with non-trunk default branches. git-svn-id: file:///usr/local/Singular/svn/trunk@6880 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.1.1.1 2003-10-06 12:16:01 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 "structs.h"
31#include "febase.h"
32#include "numbers.h"
33#include "polys.h"
34#include "ring.h"
35#include "p_Procs.h"
36#include "dError.h"
37
38#ifdef PDEBUG
39int pDBsyzComp=0;
40#endif
41
42/***************************************************************
43 *
44 * Storage Managament Routines
45 *
46 ***************************************************************/
47
48
49void ppDelete(poly* p, ring rg)
50{
51  ring origRing = currRing;
52  rChangeCurrRing(rg);
53  pDelete(p);
54  rChangeCurrRing(origRing);
55}
56
57
58poly pHeadProc(poly p)
59{
60  return pHead(p);
61}
62
63
64static inline unsigned long GetBitFields(Exponent_t e,
65                                         unsigned int s, unsigned int n)
66{
67  unsigned int i = 0, ev = 0;
68  assume(n > 0 && s < BIT_SIZEOF_LONG);
69  do
70  {
71    assume(s+i < BIT_SIZEOF_LONG);
72    if (e > (Exponent_t) i) ev |= Sy_bit(s+i);
73    else break;
74    i++;
75  }
76  while (i < n);
77  return ev;
78}
79
80// Short Exponent Vectors are used for fast divisibility tests
81// ShortExpVectors "squeeze" an exponent vector into one word as follows:
82// Let n = BIT_SIZEOF_LONG / pVariables.
83// If n == 0 (i.e. pVariables > BIT_SIZE_OF_LONG), let m == the number
84// of non-zero exponents. If (m>BIT_SIZEOF_LONG), then sev = ~0, else
85// first m bits of sev are set to 1.
86// Otherwise (i.e. pVariables <= BIT_SIZE_OF_LONG)
87// represented by a bit-field of length n (resp. n+1 for some
88// exponents). If the value of an exponent is greater or equal to n, then
89// all of its respective n bits are set to 1. If the value of an exponent
90// is smaller than n, say m, then only the first m bits of the respective
91// n bits are set to 1, the others are set to 0.
92// This way, we have:
93// exp1 / exp2 ==> (ev1 & ~ev2) == 0, i.e.,
94// if (ev1 & ~ev2) then exp1 does not divide exp2
95unsigned long p_GetShortExpVector(poly p, ring r)
96{
97  assume(p != NULL);
98  if (p == NULL) return 0;
99  unsigned long ev = 0; // short exponent vector
100  unsigned int n = BIT_SIZEOF_LONG / r->N; // number of bits per exp
101  unsigned int m1; // highest bit which is filled with (n+1)
102  unsigned int i = 0, j=1;
103
104  if (n == 0)
105  {
106    if (r->N <2*BIT_SIZEOF_LONG)
107    {
108      n=1;
109      m1=0;
110    }
111    else
112    {
113      for (; j<=(unsigned long) r->N; j++)
114      {
115        if (p_GetExp(p,j,r) > 0) i++;
116        if (i == BIT_SIZEOF_LONG) break;
117      }
118      if (i>0)
119      ev = ~((unsigned long)0) >> ((unsigned long) (BIT_SIZEOF_LONG - i));
120      return ev;
121    }
122  }
123  else
124  {
125    m1 = (n+1)*(BIT_SIZEOF_LONG - n*r->N);
126  }
127
128  n++;
129  while (i<m1)
130  {
131    ev |= GetBitFields(p_GetExp(p, j,r), i, n);
132    i += n;
133    j++;
134  }
135
136  n--;
137  while (i<BIT_SIZEOF_LONG)
138  {
139    ev |= GetBitFields(p_GetExp(p, j,r), i, n);
140    i += n;
141    j++;
142  }
143  return ev;
144}
145
146
147int rComp0_Func(poly p1,poly p2)
148{
149  int i;
150  for(i=0; i< currRing->CmpL_Size;i++)
151  {
152    if (p1->exp[i] != p2->exp[i])
153    {
154      if (p1->exp[i] > p2->exp[i])
155        return currRing->ordsgn[i];
156      else
157        return -currRing->ordsgn[i];
158    }
159  }
160  return 0;
161}
162
163#ifdef PDEBUG
164int rComp0(poly p1,poly p2)
165{
166  int i;
167  for(i=0; i<currRing->CmpL_Size;i++)
168  {
169    if (p1->exp[i] != p2->exp[i])
170    {
171      if (p1->exp[i] > p2->exp[i])
172        return currRing->ordsgn[i];
173      else
174        return -currRing->ordsgn[i];
175    }
176  }
177  return 0;
178}
179#endif
180
181#endif // POLYS_IMPL_CC
Note: See TracBrowser for help on using the repository browser.