source: git/Singular/binom.cc @ 3d124a7

spielwiese
Last change on this file since 3d124a7 was 32df82, checked in by Hans Schönemann <hannes@…>, 27 years ago
* hannes: removed rcsid and Log: entries, added assignment module=poly corected type conversion int->module git-svn-id: file:///usr/local/Singular/svn/trunk@128 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.3 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: binom.cc,v 1.3 1997-04-02 15:06:55 Singular Exp $ */
5
6/*
7* ABSTRACT - set order (=number of monomial) for dp
8*/
9
10/* includes */
11#include <limits.h>
12#include "mod2.h"
13#include "tok.h"
14#include "mmemory.h"
15#include "febase.h"
16#include "polys.h"
17#include "binom.h"
18
19#ifdef TEST_MAC_ORDER
20static char rcsid[] = "$Id: binom.cc,v 1.3 1997-04-02 15:06:55 Singular Exp $";
21
22extern int  pComponentOrder;
23/* ----------- global variables, set by bBinomSet --------------------- */
24static int *bBinomials=NULL;
25static int  bSize;
26int         bHighdeg;
27static int  bHighdeg_1;
28
29/*0 implementation*/
30static inline int bBinom(int i,int j)
31{
32  return bBinomials[(j-1)*(bHighdeg_1)+i-j+1/*j-1,i-j*/];
33}
34
35void bSetm(poly p)
36{
37  int i = pTotaldegree(p);
38
39  if (i<=bHighdeg)
40  {
41    i=1;
42    p->Order = -INT_MAX;
43    //int expsum=0;
44    //while (i<=pVariables)
45    //{
46    //  expsum += pGetExp(p,i);
47    //  p->Order += bBinom(expsum,i);
48    //  expsum++;
49    //  i++;
50    //}
51
52    int *ip=bBinomials+pGetExp(p,1);
53    loop
54    {
55      p->Order += (*ip);
56      if (i==pVariables) break;
57      i++;
58      ip+=bHighdeg_1+pGetExp(p,i);
59    }
60  }
61  else
62   p->Order=i;
63}
64
65static int bComp1dpc(poly p1, poly p2)
66{
67  int o1=p1->Order, o2=p2->Order;
68  if (o1 > o2) return 1;
69  if (o1 < o2) return -1;
70
71  /* now o1==o2: */
72  if (o1>0)
73  {
74    int i = pVariables;
75    while ((i>1) && (p1->exp[i]==p2->exp[i]))
76      i--;
77    if (i>1)
78    {
79      if (p1->exp[i] < p2->exp[i]) return 1;
80      return -1;
81    }
82  }
83  o1=p1->exp[0];
84  o2=p2->exp[0];
85  if (o1==o2/*p1->exp[0]==p2->exp[0]*/) return 0;
86  if (o1>o2) return -pComponentOrder;
87  return pComponentOrder;
88}
89
90/*2
91* compute the length of a polynomial (in l)
92* and the degree of the monomial with maximal degree: the first one
93* this works for the polynomial case with degree orderings
94* (both c,dp and dp,c)
95*/
96static int bLDegb(poly p,int *l)
97{
98  short k=p->exp[0];
99  int o = pFDeg(p);
100  int ll=1;
101
102  while (((p=pNext(p))!=NULL) && (pGetComp(p)==k))
103  {
104    ll++;
105  }
106  *l=ll;
107  return o;
108}
109
110/*2
111* compute the length of a polynomial (in l)
112* and the degree of the monomial with maximal degree: the last one
113*/
114static int bLDeg0(poly p,int *l)
115{
116  short k=p->exp[0];
117  int ll=1;
118
119  while ((pNext(p)!=NULL) && (pGetComp(pNext(p))==k))
120  {
121    pIter(p);
122    ll++;
123  }
124  *l=ll;
125  return (pFDeg(p));
126}
127
128/*
129* (i,j) in bBinomials[j-1,i-j+1]
130* table size is: pVariables * (bHighdeg+1)
131* bHighdeg_1==bHighdeg+1
132*/
133void bBinomSet()
134{
135  bHighdeg=1;
136  long long t=1;
137  long long h_n=1+pVariables;
138  while ((bHighdeg<512)
139  && ((t=(((long long)t*(long long)h_n)/(long long)bHighdeg))<INT_MAX))
140  {
141    bHighdeg++;
142    h_n++;
143  }
144  bHighdeg_1=bHighdeg;
145  bHighdeg--;
146
147  if(bBinomials!=NULL) Free((ADDRESS)bBinomials,bSize);
148  bSize = pVariables*(bHighdeg+1)*sizeof(int);
149  bBinomials = (int*)Alloc(bSize);
150
151  Print("max deg=%d, table size=%d bytes\n",bHighdeg,bSize);
152
153  for(int j=1;j<=bHighdeg;j++)
154  {
155    bBinomials[j/*0,j*/] = j;
156    for (int i=1;i<pVariables;i++)
157    {
158      bBinomials[i*(bHighdeg_1)+j/*i,j*/]
159      = bBinomials[(i-1)*(bHighdeg_1)+j/*i-1,j*/]*(j+i)/(i+1);
160    }
161  }
162  for (int i=0;i<pVariables;i++)
163  {
164    bBinomials[i*(bHighdeg_1)/*i,0*/]=0;
165  }
166  pSetm =bSetm;
167  pComp0=bComp1dpc;
168  pFDeg =pTotaldegree;
169  pLDeg =bLDegb; /* if pOrdSgn==1 */
170}
171#endif
Note: See TracBrowser for help on using the repository browser.