My Project
Loading...
Searching...
No Matches
cf_binom.cc
Go to the documentation of this file.
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#ifndef HAVE_NTL
14
15#define MAXPT 40
16
17#define INITPT 10
18
19VAR CFArray * ptZ = 0;
20VAR CFArray * ptF = 0;
21
22VAR int charac = 0;
23VAR int gfdeg = 0;
24VAR int ptZmax = INITPT;
25VAR int ptFmax = 0;
26
27void
29{
30 ptFmax = 0;
31}
32
33void
34initPT ( )
35{
36 STATIC_VAR bool initialized = false;
37
38 if ( ! initialized ) {
39 initialized = true;
40 ptZ = new CFArray[MAXPT+1];
41 ptF = new CFArray[MAXPT+1];
42 int i, j;
43 ptZ[0] = CFArray(1); ptZ[0][0] = 1;
44 ptF[0] = CFArray(1);
45 for ( i = 1; i <= INITPT; i++ ) {
46 ptF[i] = CFArray(i+1);
47 ptZ[i] = CFArray(i+1);
48 (ptZ[i])[0] = 1;
49 for ( j = 1; j < i; j++ )
50 (ptZ[i])[j] = (ptZ[i-1])[j-1] + (ptZ[i-1])[j];
51 (ptZ[i])[i] = 1;
52 }
53 for ( i = INITPT+1; i <= MAXPT; i++ ) {
54 ptF[i] = CFArray(i+1);
55 ptZ[i] = CFArray(i+1);
56 }
57 ptZmax = INITPT;
58 ptFmax = 0;
59 }
60}
61
63binomialpower ( const Variable & x, const CanonicalForm & a, int n )
64{
65 if ( n == 0 )
66 return 1;
67 else if ( n == 1 )
68 return x + a;
69 else if ( getCharacteristic() == 0 ) {
70 if ( n <= MAXPT ) {
71 if ( n > ptZmax ) {
72 int i, j;
73 for ( i = ptZmax+1; i <= n; i++ ) {
74 (ptZ[i])[0] = 1;
75 for ( j = 1; j < i; j++ )
76 (ptZ[i])[j] = (ptZ[i-1])[j-1] + (ptZ[i-1])[j];
77 (ptZ[i])[i] = 1;
78 }
79 ptZmax = n;
80 }
81 CanonicalForm result = 0, apower = 1;
82 int k;
83 for ( k = n; k >= 0; k-- ) {
84 result += power( x, k ) * apower * (ptZ[n])[k];
85 if ( k != 0 )
86 apower *= a;
87 }
88 return result;
89 }
90 else {
91 CanonicalForm result = binomialpower( x, a, MAXPT );
92 CanonicalForm xa = x + a;
93 int i;
94 for ( i = MAXPT; i < n; i++ )
95 result *= xa;
96 return result;
97 }
98 }
99 else {
100 if ( getCharacteristic() != charac || gfdeg != getGFDegree() ) {
101 ptFmax = 0;
102 charac = getCharacteristic();
103 gfdeg = getGFDegree();
104 (ptF[0])[0] = 1;
105 }
106 if ( n <= MAXPT ) {
107 if ( n > ptFmax ) {
108 int i, j;
109 for ( i = ptFmax+1; i <= n; i++ ) {
110 (ptF[i])[0] = 1;
111 for ( j = 1; j < i; j++ )
112 (ptF[i])[j] = (ptF[i-1])[j-1] + (ptF[i-1])[j];
113 (ptF[i])[i] = 1;
114 }
115 ptFmax = n;
116 }
117 CanonicalForm result = 0, apower = 1;
118 int k;
119 for ( k = n; k >= 0; k-- ) {
120 result += power( x, k ) * apower * (ptF[n])[k];
121 if ( k != 0 )
122 apower *= a;
123 }
124 return result;
125 }
126 else {
127 CanonicalForm result = binomialpower( x, a, MAXPT );
128 CanonicalForm xa = x + a;
129 int i;
130 for ( i = MAXPT; i < n; i++ )
131 result *= xa;
132 return result;
133 }
134 }
135}
136#endif
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
Header for factory's main class CanonicalForm.
int getGFDegree()
Definition: cf_char.cc:75
Array< CanonicalForm > CFArray
int FACTORY_PUBLIC getCharacteristic()
Definition: cf_char.cc:70
int i
Definition: cfEzgcd.cc:132
int k
Definition: cfEzgcd.cc:99
Variable x
Definition: cfModGcd.cc:4082
assertions for Factory
void initPT()
void resetFPT()
CanonicalForm binomialpower(const Variable &, const CanonicalForm &, int)
factory switches.
factory's main class
Definition: canonicalform.h:86
factory's class for variables
Definition: variable.h:33
return result
Definition: facAbsBiFact.cc:75
int j
Definition: facHensel.cc:110
#define STATIC_VAR
Definition: globaldefs.h:7
#define VAR
Definition: globaldefs.h:5