source: git/factory/old/cf_binom.cc @ a3f0fea

spielwiese
Last change on this file since a3f0fea was a3f0fea, checked in by Reimer Behrends <behrends@…>, 5 years ago
Modify variable declarions for pSingular.
  • Property mode set to 100644
File size: 3.3 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2
3
4#include "config.h"
5
6
7#include "cf_assert.h"
8
9#include "cf_defs.h"
10#include "canonicalform.h"
11#include "cf_binom.h"
12
13#define MAXPT 40
14
15#define INITPT 10
16
17VAR CFArray * ptZ = 0;
18VAR CFArray * ptF = 0;
19
20VAR int charac = 0;
21VAR int gfdeg = 0;
22VAR int ptZmax = INITPT;
23VAR int ptFmax = 0;
24
25void
26resetFPT()
27{
28    ptFmax = 0;
29}
30
31void
32initPT ( )
33{
34    STATIC_VAR bool initialized = false;
35
36    if ( ! initialized ) {
37        initialized = true;
38        ptZ = new CFArray[MAXPT+1];
39        ptF = new CFArray[MAXPT+1];
40        int i, j;
41        ptZ[0] = CFArray(1); ptZ[0][0] = 1;
42        ptF[0] = CFArray(1);
43        for ( i = 1; i <= INITPT; i++ ) {
44            ptF[i] = CFArray(i+1);
45            ptZ[i] = CFArray(i+1);
46            (ptZ[i])[0] = 1;
47            for ( j = 1; j < i; j++ )
48                (ptZ[i])[j] = (ptZ[i-1])[j-1] + (ptZ[i-1])[j];
49            (ptZ[i])[i] = 1;
50        }
51        for ( i = INITPT+1; i <= MAXPT; i++ ) {
52            ptF[i] = CFArray(i+1);
53            ptZ[i] = CFArray(i+1);
54        }
55        ptZmax = INITPT;
56        ptFmax = 0;
57    }
58}
59
60CanonicalForm
61binomialpower ( const Variable & x, const CanonicalForm & a, int n )
62{
63    if ( n == 0 )
64        return 1;
65    else if ( n == 1 )
66        return x + a;
67    else if ( getCharacteristic() == 0 ) {
68        if ( n <= MAXPT ) {
69            if ( n > ptZmax ) {
70                int i, j;
71                for ( i = ptZmax+1; i <= n; i++ ) {
72                    (ptZ[i])[0] = 1;
73                    for ( j = 1; j < i; j++ )
74                        (ptZ[i])[j] = (ptZ[i-1])[j-1] + (ptZ[i-1])[j];
75                    (ptZ[i])[i] = 1;
76                }
77                ptZmax = n;
78            }
79            CanonicalForm result = 0, apower = 1;
80            int k;
81            for ( k = n; k >= 0; k-- ) {
82                result += power( x, k ) * apower * (ptZ[n])[k];
83                if ( k != 0 )
84                    apower *= a;
85            }
86            return result;
87        }
88        else {
89            CanonicalForm result = binomialpower( x, a, MAXPT );
90            CanonicalForm xa = x + a;
91            int i;
92            for ( i = MAXPT; i < n; i++ )
93                result *= xa;
94            return result;
95        }
96    }
97    else {
98        if ( getCharacteristic() != charac || gfdeg != getGFDegree() ) {
99            ptFmax = 0;
100            charac = getCharacteristic();
101            gfdeg = getGFDegree();
102            (ptF[0])[0] = 1;
103        }
104        if ( n <= MAXPT ) {
105            if ( n > ptFmax ) {
106                int i, j;
107                for ( i = ptFmax+1; i <= n; i++ ) {
108                    (ptF[i])[0] = 1;
109                    for ( j = 1; j < i; j++ )
110                        (ptF[i])[j] = (ptF[i-1])[j-1] + (ptF[i-1])[j];
111                    (ptF[i])[i] = 1;
112                }
113                ptFmax = n;
114            }
115            CanonicalForm result = 0, apower = 1;
116            int k;
117            for ( k = n; k >= 0; k-- ) {
118                result += power( x, k ) * apower * (ptF[n])[k];
119                if ( k != 0 )
120                    apower *= a;
121            }
122            return result;
123        }
124        else {
125            CanonicalForm result = binomialpower( x, a, MAXPT );
126            CanonicalForm xa = x + a;
127            int i;
128            for ( i = MAXPT; i < n; i++ )
129                result *= xa;
130            return result;
131        }
132    }
133}
Note: See TracBrowser for help on using the repository browser.