source: git/Singular/binom.cc @ 18dd47

spielwiese
Last change on this file since 18dd47 was 07dacd, checked in by Hans Schönemann <hannes@…>, 27 years ago
* hannes: clean up unused code: binom.cc extra.cc scanner.cc scanner.l numbers.cc numbers.h recovery with setjmp/longjmp: tesths.cc cntrlc.cc cntrlc.h changed error messages: ipassign.cc git-svn-id: file:///usr/local/Singular/svn/trunk@479 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.4 1997-07-01 15:41:41 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
20extern int  pComponentOrder;
21/* ----------- global variables, set by bBinomSet --------------------- */
22static int *bBinomials=NULL;
23static int  bSize;
24int         bHighdeg;
25static int  bHighdeg_1;
26
27/*0 implementation*/
28static inline int bBinom(int i,int j)
29{
30  return bBinomials[(j-1)*(bHighdeg_1)+i-j+1/*j-1,i-j*/];
31}
32
33void bSetm(poly p)
34{
35  int i = pTotaldegree(p);
36
37  if (i<=bHighdeg)
38  {
39    i=1;
40    p->Order = -INT_MAX;
41    //int expsum=0;
42    //while (i<=pVariables)
43    //{
44    //  expsum += pGetExp(p,i);
45    //  p->Order += bBinom(expsum,i);
46    //  expsum++;
47    //  i++;
48    //}
49
50    int *ip=bBinomials+pGetExp(p,1);
51    loop
52    {
53      p->Order += (*ip);
54      if (i==pVariables) break;
55      i++;
56      ip+=bHighdeg_1+pGetExp(p,i);
57    }
58  }
59  else
60   p->Order=i;
61}
62
63static int bComp1dpc(poly p1, poly p2)
64{
65  int o1=p1->Order, o2=p2->Order;
66  if (o1 > o2) return 1;
67  if (o1 < o2) return -1;
68
69  /* now o1==o2: */
70  if (o1>0)
71  {
72    int i = pVariables;
73    while ((i>1) && (p1->exp[i]==p2->exp[i]))
74      i--;
75    if (i>1)
76    {
77      if (p1->exp[i] < p2->exp[i]) return 1;
78      return -1;
79    }
80  }
81  o1=p1->exp[0];
82  o2=p2->exp[0];
83  if (o1==o2/*p1->exp[0]==p2->exp[0]*/) return 0;
84  if (o1>o2) return -pComponentOrder;
85  return pComponentOrder;
86}
87
88/*2
89* compute the length of a polynomial (in l)
90* and the degree of the monomial with maximal degree: the first one
91* this works for the polynomial case with degree orderings
92* (both c,dp and dp,c)
93*/
94static int bLDegb(poly p,int *l)
95{
96  short k=p->exp[0];
97  int o = pFDeg(p);
98  int ll=1;
99
100  while (((p=pNext(p))!=NULL) && (pGetComp(p)==k))
101  {
102    ll++;
103  }
104  *l=ll;
105  return o;
106}
107
108/*2
109* compute the length of a polynomial (in l)
110* and the degree of the monomial with maximal degree: the last one
111*/
112static int bLDeg0(poly p,int *l)
113{
114  short k=p->exp[0];
115  int ll=1;
116
117  while ((pNext(p)!=NULL) && (pGetComp(pNext(p))==k))
118  {
119    pIter(p);
120    ll++;
121  }
122  *l=ll;
123  return (pFDeg(p));
124}
125
126/*
127* (i,j) in bBinomials[j-1,i-j+1]
128* table size is: pVariables * (bHighdeg+1)
129* bHighdeg_1==bHighdeg+1
130*/
131void bBinomSet()
132{
133  bHighdeg=1;
134  long long t=1;
135  long long h_n=1+pVariables;
136  while ((bHighdeg<512)
137  && ((t=(((long long)t*(long long)h_n)/(long long)bHighdeg))<INT_MAX))
138  {
139    bHighdeg++;
140    h_n++;
141  }
142  bHighdeg_1=bHighdeg;
143  bHighdeg--;
144
145  if(bBinomials!=NULL) Free((ADDRESS)bBinomials,bSize);
146  bSize = pVariables*(bHighdeg+1)*sizeof(int);
147  bBinomials = (int*)Alloc(bSize);
148
149  Print("max deg=%d, table size=%d bytes\n",bHighdeg,bSize);
150
151  for(int j=1;j<=bHighdeg;j++)
152  {
153    bBinomials[j/*0,j*/] = j;
154    for (int i=1;i<pVariables;i++)
155    {
156      bBinomials[i*(bHighdeg_1)+j/*i,j*/]
157      = bBinomials[(i-1)*(bHighdeg_1)+j/*i-1,j*/]*(j+i)/(i+1);
158    }
159  }
160  for (int i=0;i<pVariables;i++)
161  {
162    bBinomials[i*(bHighdeg_1)/*i,0*/]=0;
163  }
164  pSetm =bSetm;
165  pComp0=bComp1dpc;
166  pFDeg =pTotaldegree;
167  pLDeg =bLDegb; /* if pOrdSgn==1 */
168}
169#endif
Note: See TracBrowser for help on using the repository browser.