Typedefs | Functions | Variables
fast_mult.cc File Reference
#include <kernel/mod2.h>
#include <polys/monomials/ring.h>
#include <kernel/fast_mult.h>
#include <polys/kbuckets.h>

Go to the source code of this file.

Typedefs

typedef poly fastmultrec(poly f, poly g, ring r)
 

Functions

int Mults ()
 
static void degsplit (poly p, int n, poly &p1, poly &p2, int vn, ring r)
 
static void div_by_x_power_n (poly p, int n, int vn, ring r)
 
static poly do_unifastmult (poly f, int df, poly g, int dg, int vn, fastmultrec rec, ring r)
 
static int max (int a, int b)
 
static int min (int a, int b)
 
poly unifastmult (poly f, poly g, ring r)
 
poly multifastmult (poly f, poly g, ring r)
 
poly pFastPower (poly f, int n, ring r)
 
static void p_MonMultMB (poly p, poly q, ring r)
 
static poly p_MonMultCMB (poly p, poly q, ring r)
 
static poly p_MonPowerMB (poly p, int exp, ring r)
 
static void buildTermAndAdd (int, number *, poly *, int *exp, int f_len, kBucket_pt, ring r, number coef, poly &zw, poly, poly **term_pot)
 
static void MC_iterate (poly f, int n, ring r, int f_len, number *facult, int *exp, poly *f_terms, kBucket_pt erg_bucket, int pos, int sum, number coef, poly &zw, poly tmp, poly **term_pot)
 
poly pFastPowerMC (poly f, int n, ring r)
 

Variables

static const int pass_option =1
 
static int mults =0
 
static omBin lm_bin =NULL
 

Typedef Documentation

typedef poly fastmultrec(poly f, poly g, ring r)

Definition at line 11 of file fast_mult.cc.

Function Documentation

static void buildTermAndAdd ( int  ,
number *  ,
poly ,
int exp,
int  f_len,
kBucket_pt  ,
ring  r,
number  coef,
poly zw,
poly  ,
poly **  term_pot 
)
static

poly term=p_Copy(f_terms[i],r);

Definition at line 484 of file fast_mult.cc.

484  {
485 
486  int i;
487  // poly term=p_Init(r);
488 
489  // number denom=n_Init(1,r);
490 // for(i=0;i<f_len;i++){
491 // if(exp[i]!=0){
492 // number trash=denom;
493 // denom=n_Mult(denom,facult[exp[i]],r);
494 // n_Delete(&trash,r);
495 // }
496 
497 // }
498 // number coef=n_IntDiv(facult[n],denom,r); //right function here?
499 // n_Delete(&denom,r);
500 // poly erg=p_NSet(coef,r);
501  poly erg=p_Init(r,lm_bin);
502  p_SetCoeff0(erg, coef,r);
503  //p_NSet(n_Copy(coef,r),r);
504  for(i=0;i<f_len;i++){
505  if(exp[i]!=0){
506  ///poly term=p_Copy(f_terms[i],r);
507  poly term=term_pot[i][exp[i]];
508  //tmp;
509  //p_ExpVectorCopy(term,f_terms[i],r);
510  //p_SetCoeff(term, n_Copy(p_GetCoeff(f_terms[i],r),r),r);
511 
512  //term->next=NULL;
513 
514  //p_MonPowerMB(term, exp[i],r);
515  p_MonMultMB(erg,term,r);
516  //p_Delete(&term,r);
517  }
518 
519  }
520  zw=erg;
521 }
Definition: int_poly.h:36
static void p_MonMultMB(poly p, poly q, ring r)
Definition: fast_mult.cc:434
const ring r
Definition: syzextra.cc:208
polyrec * poly
Definition: hilb.h:10
int i
Definition: cfEzgcd.cc:123
static omBin lm_bin
Definition: fast_mult.cc:429
p exp[i]
Definition: DebugPrint.cc:39
#define p_SetCoeff0(p, n, r)
Definition: monomials.h:68
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1248
static void degsplit ( poly  p,
int  n,
poly p1,
poly p2,
int  vn,
ring  r 
)
static

Definition at line 18 of file fast_mult.cc.

19 {
20  poly erg1_i, erg2_i;
21  erg1_i=NULL;
22  erg2_i=NULL;
23  while(p)
24  {
25  if(p_GetExp(p,vn,r)>=n)
26  {
27  if (p1==NULL)
28  {
29  p1=p;
30  }
31  else
32  {
33  pNext(erg1_i)=p;
34  }
35  erg1_i=p;
36  }
37  else
38  {
39  if (p2==NULL)
40  {
41  p2=p;
42  }
43  else
44  {
45  pNext(erg2_i)=p;
46  }
47  erg2_i=p;
48  }
49  p=pNext(p);
50  }
51  if(erg2_i)
52  {
53  pNext(erg2_i)=NULL;
54  }
55  if (erg1_i)
56  {
57  pNext(erg1_i)=NULL;
58  }
59 
60 }
return P p
Definition: myNF.cc:203
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
const ring r
Definition: syzextra.cc:208
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
Definition: p_polys.h:465
polyrec * poly
Definition: hilb.h:10
#define NULL
Definition: omList.c:10
#define pNext(p)
Definition: monomials.h:43
END_NAMESPACE const void * p2
Definition: syzextra.cc:202
static void div_by_x_power_n ( poly  p,
int  n,
int  vn,
ring  r 
)
static

Definition at line 61 of file fast_mult.cc.

62 {
63  while(p)
64  {
65  assume(p_GetExp(p,vn,r)>=n);
66  int e=p_GetExp(p,vn,r);
67  p_SetExp(p,vn,e-n,r);
68  p=pNext(p);
69  }
70 }
return P p
Definition: myNF.cc:203
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
const ring r
Definition: syzextra.cc:208
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
Definition: p_polys.h:465
#define assume(x)
Definition: mod2.h:405
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent : VarOffset encodes the position in p->exp
Definition: p_polys.h:484
#define pNext(p)
Definition: monomials.h:43
static poly do_unifastmult ( poly  f,
int  df,
poly  g,
int  dg,
int  vn,
fastmultrec  rec,
ring  r 
)
static

Definition at line 72 of file fast_mult.cc.

73 {
74  int n=1;
75  if ((f==NULL)||(g==NULL)) return NULL;
76  //int df=pGetExp(f,vn);//pFDeg(f);
77  // int dg=pGetExp(g,vn);//pFDeg(g);
78 
79  int dm;
80  if(df>dg)
81  {
82  dm=df;
83  }
84  else
85  {
86  dm=dg;
87  }
88  while(n<=dm)
89  {
90  n*=2;
91  }
92  if(n==1)
93  {
94  return(pp_Mult_qq(f,g,r));
95  }
96 
97  int pot=n/2;
98  assume(pot*2==n);
99 
100 
101  //splitting
102  poly f1=NULL;
103  poly f0=NULL;//f-(x^(pot)*F1);
104  degsplit(p_Copy(f,r),pot,f1,f0,vn,r);
105  div_by_x_power_n(f1,pot,vn,r);
106 
107  poly g1=NULL;
108  poly g0=NULL;
109  degsplit(p_Copy(g,r),pot,g1,g0,vn,r);
110  div_by_x_power_n(g1,pot,vn,r);
111 
112  //p00, p11
113  poly p00=rec(f0,g0,r);//unifastmult(f0,g0);
114  poly p11=rec(f1,g1,r);
115 
116  //construct erg, factor
117  poly erg=NULL;
118  poly factor=p_ISet(1,r);
119 
120  p_SetExp(factor,vn,n,r);
121  erg=pp_Mult_mm(p11,factor,r);
122  erg=p_Add_q(erg,p_Copy(p00,r),r);
123 
124 
125 
126 
127 
128  if((f1!=NULL) &&(f0!=NULL) &&(g0!=NULL) && (g1!=NULL))
129  {
130  //if(true){
131  //eat up f0,f1,g0,g1
132  poly s1=p_Add_q(f0,f1,r);
133  poly s2=p_Add_q(g0,g1,r);
134  poly pbig=rec(s1,s2,r);
135  p_Delete(&s1,r);
136  p_Delete(&s2,r);
137 
138 
139  //eat up pbig
140  poly sum=pbig;
141  p_SetExp(factor,vn,pot,r);
142 
143  //eat up p00
144  sum=p_Add_q(sum,p_Neg(p00,r),r);
145 
146  //eat up p11
147  sum=p_Add_q(sum,p_Neg(p11,r),r);
148 
149 
150  sum=p_Mult_mm(sum,factor,r);
151 
152 
153  //eat up sum
154  erg=p_Add_q(sum,erg,r);
155  }
156  else
157  {
158  //eat up f0,f1,g0,g1
159  poly s1=rec(f0,g1,r);
160  poly s2=rec(g0,f1,r);
161  p_SetExp(factor,vn,pot,r);
162  poly h=p_Mult_mm(((s1!=NULL)?s1:s2),factor,r);
163  p_Delete(&f1,r);
164  p_Delete(&f0,r);
165  p_Delete(&g0,r);
166  p_Delete(&g1,r);
167  p_Delete(&p00,r);
168  p_Delete(&p11,r);
169  erg=p_Add_q(erg,h,r);
170  }
171 
172 
173  p_Delete(&factor,r);
174 
175 
176 
177  return(erg);
178 }
f
Definition: cfModGcd.cc:4022
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:973
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
static void degsplit(poly p, int n, poly &p1, poly &p2, int vn, ring r)
Definition: fast_mult.cc:18
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:962
g
Definition: cfModGcd.cc:4031
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:811
const ring r
Definition: syzextra.cc:208
polyrec * poly
Definition: hilb.h:10
#define assume(x)
Definition: mod2.h:405
static poly pp_Mult_qq(poly p, poly q, const ring r)
Definition: p_polys.h:1075
static void div_by_x_power_n(poly p, int n, int vn, ring r)
Definition: fast_mult.cc:61
CanonicalForm factor
Definition: facAbsFact.cc:101
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:850
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent : VarOffset encodes the position in p->exp
Definition: p_polys.h:484
#define NULL
Definition: omList.c:10
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1018
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:884
static Poly * h
Definition: janet.cc:978
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1302
static int max ( int  a,
int  b 
)
inlinestatic

Definition at line 264 of file fast_mult.cc.

265 {
266  return (a>b)? a:b;
267 }
const poly a
Definition: syzextra.cc:212
const poly b
Definition: syzextra.cc:213
static void MC_iterate ( poly  f,
int  n,
ring  r,
int  f_len,
number *  facult,
int exp,
poly f_terms,
kBucket_pt  erg_bucket,
int  pos,
int  sum,
number  coef,
poly zw,
poly  tmp,
poly **  term_pot 
)
static

Definition at line 525 of file fast_mult.cc.

525  {
526  int i;
527 
528  if (pos<f_len-1)
529  {
530  poly zw_l=NULL;
531  number new_coef;
532  for(i=0;i<=n-sum;i++)
533  {
534  exp[pos]=i;
535  if(i==0)
536  {
537  new_coef=n_Copy(coef,r->cf);
538  }
539  else
540  {
541  number old=new_coef;
542  number old_rest=n_Init(n-sum-(i-1),r->cf);
543  new_coef=n_Mult(new_coef,old_rest,r->cf);
544  n_Delete(&old_rest,r->cf);
545  n_Delete(&old,r->cf);
546  number i_number=n_Init(i,r->cf);
547  old=new_coef;
548  new_coef=n_Div(new_coef,i_number,r->cf);
549  n_Normalize(new_coef,r->cf);
550  n_Delete(&old,r->cf);
551  n_Delete(&i_number,r->cf);
552  }
553  //new_coef is
554  //(n )
555  //(exp[0]..exp[pos] 0 0 0 rest)
556  poly zw_real=NULL;
557  MC_iterate(f, n, r, f_len,facult, exp,f_terms,erg_bucket,pos+1,sum+i,new_coef,zw_real,tmp,term_pot);
558  if (pos==f_len-2)
559  {
560  //get first small polys
561 
562  zw_real->next=zw_l;
563  zw_l=zw_real;
564  }
565  //n_Delete(& new_coef,r->cf);
566  }
567  n_Delete(&new_coef,r->cf);
568  if (pos==f_len-2)
569  {
570  int len=n-sum+1;
571  kBucket_Add_q(erg_bucket,zw_l,&len);
572  }
573  return;
574  }
575  if(pos==f_len-1)
576  {
577  i=n-sum;
578  exp[pos]=i;
579  number new_coef=n_Copy(coef,r->cf);//n_IntDiv(coef,facult[i],r); //really consumed???????
580  buildTermAndAdd(n,facult,f_terms,exp,f_len,erg_bucket,r, new_coef,zw, tmp,term_pot);
581  // n_Delete(& new_coef,r);
582  }
583  assume(pos<=f_len-1);
584 }
f
Definition: cfModGcd.cc:4022
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:537
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition: coeffs.h:577
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
Definition: coeffs.h:633
const ring r
Definition: syzextra.cc:208
polyrec * poly
Definition: hilb.h:10
#define assume(x)
Definition: mod2.h:405
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition: coeffs.h:451
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition: coeffs.h:613
static void MC_iterate(poly f, int n, ring r, int f_len, number *facult, int *exp, poly *f_terms, kBucket_pt erg_bucket, int pos, int sum, number coef, poly &zw, poly tmp, poly **term_pot)
Definition: fast_mult.cc:525
static void buildTermAndAdd(int, number *, poly *, int *exp, int f_len, kBucket_pt, ring r, number coef, poly &zw, poly, poly **term_pot)
Definition: fast_mult.cc:484
p exp[i]
Definition: DebugPrint.cc:39
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
void kBucket_Add_q(kBucket_pt bucket, poly q, int *l)
Add to Bucket a poly ,i.e. Bpoly == q+Bpoly.
Definition: kbuckets.cc:637
static int min ( int  a,
int  b 
)
inlinestatic

Definition at line 268 of file fast_mult.cc.

269 {
270  return (a>b)? b:a;
271 }
const poly a
Definition: syzextra.cc:212
const poly b
Definition: syzextra.cc:213
poly multifastmult ( poly  f,
poly  g,
ring  r 
)

Definition at line 290 of file fast_mult.cc.

291 {
292  mults++;
293  if((f==NULL)||(g==NULL)) return NULL;
294  if (pLength(f)*pLength(g)<100)
295  return pp_Mult_qq(f,g,r);
296  //find vn
297  //determine df,dg simultaneously
298  int i;
299  int can_i=-1;
300  int can_df=0;
301  int can_dg=0;
302  int can_crit=0;
303  for(i=1;i<=rVar(r);i++)
304  {
305  poly p;
306  int df=0;
307  int dg=0;
308  //max min max Strategie
309  p=f;
310  while(p)
311  {
312  df=max(df,p_GetExp(p,i,r));
313  p=pNext(p);
314  }
315  if(df>can_crit)
316  {
317  p=g;
318  while(p)
319  {
320  dg=max(dg,p_GetExp(p,i,r));
321  p=pNext(p);
322  }
323  int crit=min(df,dg);
324  if (crit>can_crit)
325  {
326  can_crit=crit;
327  can_i=i;
328  can_df=df;
329  can_dg=dg;
330  }
331  }
332  }
333  if(can_crit==0)
334  return pp_Mult_qq(f,g,r);
335  else
336  {
337  poly erg=do_unifastmult(f,can_df,g,can_dg,can_i,multifastmult,r);
338  p_Normalize(erg,r);
339  return(erg);
340  }
341 }
static int min(int a, int b)
Definition: fast_mult.cc:268
return P p
Definition: myNF.cc:203
f
Definition: cfModGcd.cc:4022
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:531
static poly do_unifastmult(poly f, int df, poly g, int dg, int vn, fastmultrec rec, ring r)
Definition: fast_mult.cc:72
static int mults
Definition: fast_mult.cc:13
g
Definition: cfModGcd.cc:4031
static int pLength(poly a)
Definition: p_polys.h:189
const ring r
Definition: syzextra.cc:208
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
Definition: p_polys.h:465
static int max(int a, int b)
Definition: fast_mult.cc:264
polyrec * poly
Definition: hilb.h:10
poly multifastmult(poly f, poly g, ring r)
Definition: fast_mult.cc:290
static poly pp_Mult_qq(poly p, poly q, const ring r)
Definition: p_polys.h:1075
int i
Definition: cfEzgcd.cc:123
void p_Normalize(poly p, const ring r)
Definition: p_polys.cc:3584
#define NULL
Definition: omList.c:10
#define pNext(p)
Definition: monomials.h:43
int Mults ( )

Definition at line 14 of file fast_mult.cc.

15 {
16  return mults;
17 }
static int mults
Definition: fast_mult.cc:13
static poly p_MonMultCMB ( poly  p,
poly  q,
ring  r 
)
static

Definition at line 455 of file fast_mult.cc.

456 {
457  number x;
458  poly res = p_Init(r,lm_bin);
459 
460  x = n_Mult(p_GetCoeff(p,r),p_GetCoeff(q,r),r->cf);
461  p_SetCoeff0(res,x,r);
462  p_ExpVectorSum(res,p, q,r);
463  return res;
464 }
return P p
Definition: myNF.cc:203
poly res
Definition: myNF.cc:322
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
Definition: coeffs.h:633
const ring r
Definition: syzextra.cc:208
polyrec * poly
Definition: hilb.h:10
static omBin lm_bin
Definition: fast_mult.cc:429
Variable x
Definition: cfModGcd.cc:4023
#define p_GetCoeff(p, r)
Definition: monomials.h:57
#define p_SetCoeff0(p, n, r)
Definition: monomials.h:68
static void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
Definition: p_polys.h:1353
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1248
static void p_MonMultMB ( poly  p,
poly  q,
ring  r 
)
static

Definition at line 434 of file fast_mult.cc.

435 {
436  number x, y;
437  // int i;
438 
439  y = p_GetCoeff(p,r);
440  x = n_Mult(y,pGetCoeff(q),r->cf);
441  n_Delete(&y,r->cf);
442  p_SetCoeff0(p,x,r);
443  //for (i=(currRing->N); i!=0; i--)
444  //{
445  // pAddExp(p,i, pGetExp(q,i));
446  //}
447  //p->Order += q->Order;
448  p_ExpVectorAdd(p,q,r);
449 }
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
return P p
Definition: myNF.cc:203
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
Definition: monomials.h:51
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
Definition: coeffs.h:633
const ring r
Definition: syzextra.cc:208
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
Definition: p_polys.h:1339
Variable x
Definition: cfModGcd.cc:4023
#define p_GetCoeff(p, r)
Definition: monomials.h:57
#define p_SetCoeff0(p, n, r)
Definition: monomials.h:68
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
static poly p_MonPowerMB ( poly  p,
int  exp,
ring  r 
)
static

Definition at line 465 of file fast_mult.cc.

466 {
467  int i;
468 
469  if(!n_IsOne(p_GetCoeff(p,r),r->cf))
470  {
471  number x, y;
472  y = p_GetCoeff(p,r);
473  n_Power(y,exp,&x,r->cf);
474  n_Delete(&y,r->cf);
475  p_SetCoeff0(p,x,r);
476  }
477  for (i=rVar(r); i!=0; i--)
478  {
479  p_MultExp(p,i, exp,r);
480  }
481  p_Setm(p,r);
482  return p;
483 }
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
return P p
Definition: myNF.cc:203
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition: coeffs.h:468
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:531
static long p_MultExp(poly p, int v, long ee, ring r)
Definition: p_polys.h:617
const ring r
Definition: syzextra.cc:208
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE void n_Power(number a, int b, number *res, const coeffs r)
fill res with the power a^b
Definition: coeffs.h:629
Variable x
Definition: cfModGcd.cc:4023
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:436
#define p_GetCoeff(p, r)
Definition: monomials.h:57
p exp[i]
Definition: DebugPrint.cc:39
#define p_SetCoeff0(p, n, r)
Definition: monomials.h:68
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
poly pFastPower ( poly  f,
int  n,
ring  r 
)

Definition at line 342 of file fast_mult.cc.

343 {
344  if (n==1) return f;
345  if (n==0) return p_ISet(1,r);
346  assume(n>=0);
347  int i_max=1;
348  int pot_max=0;
349  while(i_max*2<=n)
350  {
351  i_max*=2;
352  pot_max++;
353  }
354  int field_size=pot_max+1;
355  int* int_pot_array=(int*) omAlloc(field_size*sizeof(int));
356  poly* pot_array=(poly*) omAlloc(field_size*sizeof(poly));
357  int i;
358  int pot=1;
359  //initializing int_pot
360  for(i=0;i<field_size;i++)
361  {
362  int_pot_array[i]=pot;
363  pot*=2;
364  }
365  //calculating pot_array
366  pot_array[0]=f; //do not delete it
367  for(i=1;i<field_size;i++)
368  {
369  poly p=pot_array[i-1];
370  if(rVar(r)==1)
371  pot_array[i]=multifastmult(p,p,r);
372  else
373  pot_array[i]=pp_Mult_qq(p,p,r);
374  }
375 
376 
377 
378  int work_n=n;
379  assume(work_n>=int_pot_array[field_size-1]);
380  poly erg=p_ISet(1,r);
381 
382 
383  //forward maybe faster, later
384  // for(i=field_size-1;i>=0;i--){
385 
386 // assume(work_n<2*int_pot_array[i]);
387 // if(int_pot_array[i]<=work_n){
388 // work_n-=int_pot_array[i];
389 // poly prod=multifastmult(erg,pot_array[i],r);
390 // pDelete(&erg);
391 // erg=prod;
392 // }
393 
394 // if(i!=0) pDelete(&pot_array[i]);
395 // }
396 
397 
398  for(i=field_size-1;i>=0;i--)
399  {
400 
401  assume(work_n<2*int_pot_array[i]);
402  if(int_pot_array[i]<=work_n)
403  {
404  work_n-=int_pot_array[i];
405  int_pot_array[i]=1;
406  }
407  else int_pot_array[i]=0;
408 
409  }
410  for(i=0;i<field_size;i++)
411  {
412  if(int_pot_array[i]==1)
413  {
414  poly prod;
415  if(rVar(r)==1)
416  prod=multifastmult(erg,pot_array[i],r);
417  else
418  prod=pp_Mult_qq(erg,pot_array[i],r);
419  pDelete(&erg);
420  erg=prod;
421  }
422  if(i!=0) pDelete(&pot_array[i]);
423  }
424  //free res
425  omfree(pot_array);
426  omfree(int_pot_array);
427  return erg;
428 }
return P p
Definition: myNF.cc:203
f
Definition: cfModGcd.cc:4022
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:531
#define omAlloc(size)
Definition: omAllocDecl.h:210
const ring r
Definition: syzextra.cc:208
polyrec * poly
Definition: hilb.h:10
#define assume(x)
Definition: mod2.h:405
poly multifastmult(poly f, poly g, ring r)
Definition: fast_mult.cc:290
static poly pp_Mult_qq(poly p, poly q, const ring r)
Definition: p_polys.h:1075
#define omfree(addr)
Definition: omAllocDecl.h:237
int i
Definition: cfEzgcd.cc:123
fq_nmod_poly_t prod
Definition: facHensel.cc:95
#define pDelete(p_ptr)
Definition: polys.h:157
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1302
poly pFastPowerMC ( poly  f,
int  n,
ring  r 
)

Definition at line 585 of file fast_mult.cc.

586 {
587  //only char=0
588 
589  if(rChar(r)!=0)
590  Werror("Char not 0, pFastPowerMC not implemented for this case");
591  if (n<=1)
592  Werror("not implemented for so small n, recursion fails");//should be length(f)
593  if (pLength(f)<=1)
594  Werror("not implemented for so small length of f, recursion fails");
595  // number null_number=n_Init(0,r);
596  number* facult=(number*) omAlloc((n+1)*sizeof(number));
597  facult[0]=n_Init(1,r->cf);
598  int i;
599  for(i=1;i<=n;i++)
600  {
601  number this_n=n_Init(i,r->cf);
602  facult[i]=n_Mult(this_n,facult[i-1],r->cf);
603  n_Delete(&this_n,r->cf);
604  }
605 
606  lm_bin=omGetSpecBin(POLYSIZE + (r->ExpL_Size)*sizeof(long));
607 
608  kBucket_pt erg_bucket= kBucketCreate(currRing);
609  kBucketInit(erg_bucket,NULL,0);
610  const int f_len=pLength(f);
611  int* exp=(int*)omAlloc(f_len*sizeof(int));
612  //poly f_terms[f_len];
613  poly* f_terms=(poly*)omAlloc(f_len*sizeof(poly));
614  poly** term_potences=(poly**) omAlloc(f_len*sizeof(poly*));
615 
616  poly f_iter=f;
617  for(i=0;i<f_len;i++)
618  {
619  f_terms[i]=f_iter;
620  f_iter=pNext(f_iter);
621  }
622  for(i=0;i<f_len;i++)
623  {
624  term_potences[i]=(poly*)omAlloc((n+1)*sizeof(poly));
625  term_potences[i][0]=p_ISet(1,r);
626  int j;
627  for(j=1;j<=n;j++){
628  term_potences[i][j]=p_MonMultCMB(f_terms[i],term_potences[i][j-1],r);
629  }
630  }
631  assume(f_iter==NULL);
632  poly zw=NULL;
633  poly tmp=p_Init(r);
634  number one=n_Init(1,r->cf);
635  MC_iterate(f,n,r,f_len,&facult[0], &exp[0], &f_terms[0],erg_bucket,0,0,one/*facult[n]*/,zw,tmp, term_potences);
636 
637 
638  n_Delete(&one,r->cf);
639 
640 
641 
642  //free res
643 
644  //free facult
645  for(i=0;i<=n;i++)
646  {
647  n_Delete(&facult[i],r->cf);
648  }
649  int i2;
650  for (i=0;i<f_len;i++)
651  {
652  for(i2=0;i2<=n;i2++)
653  {
654  p_Delete(&term_potences[i][i2],r);
655  }
656  omfree(term_potences[i]);
657 
658  }
659  omfree(term_potences);
660  p_Delete(&tmp,r);
661  omfree(exp);
662  omfree(facult);
663  omfree(f_terms);
664  int len=0;
665  poly erg;
666  kBucketClear(erg_bucket,&erg, &len);
667  kBucketDestroy(&erg_bucket);
669  return erg;
670 }
void kBucketClear(kBucket_pt bucket, poly *p, int *length)
Definition: kbuckets.cc:500
void kBucketInit(kBucket_pt bucket, poly lm, int length)
Definition: kbuckets.cc:472
f
Definition: cfModGcd.cc:4022
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:537
int rChar(ring r)
Definition: ring.cc:684
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
#define omUnGetSpecBin(bin_ptr)
Definition: omBin.h:14
#define POLYSIZE
Definition: monomials.h:241
#define omAlloc(size)
Definition: omAllocDecl.h:210
kBucket_pt kBucketCreate(ring bucket_ring)
Creation/Destruction of buckets.
Definition: kbuckets.cc:198
static int pLength(poly a)
Definition: p_polys.h:189
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
Definition: coeffs.h:633
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
const ring r
Definition: syzextra.cc:208
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:205
int j
Definition: myNF.cc:70
polyrec * poly
Definition: hilb.h:10
#define assume(x)
Definition: mod2.h:405
#define omfree(addr)
Definition: omAllocDecl.h:237
static poly p_MonMultCMB(poly p, poly q, ring r)
Definition: fast_mult.cc:455
int i
Definition: cfEzgcd.cc:123
static omBin lm_bin
Definition: fast_mult.cc:429
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:850
#define omGetSpecBin(size)
Definition: omBin.h:11
#define NULL
Definition: omList.c:10
#define pNext(p)
Definition: monomials.h:43
static void MC_iterate(poly f, int n, ring r, int f_len, number *facult, int *exp, poly *f_terms, kBucket_pt erg_bucket, int pos, int sum, number coef, poly &zw, poly tmp, poly **term_pot)
Definition: fast_mult.cc:525
p exp[i]
Definition: DebugPrint.cc:39
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1248
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1302
void Werror(const char *fmt,...)
Definition: reporter.cc:199
poly unifastmult ( poly  f,
poly  g,
ring  r 
)

Definition at line 272 of file fast_mult.cc.

273 {
274  int vn=1;
275  if((f==NULL)||(g==NULL)) return NULL;
276  int df=p_GetExp(f,vn,r);
277  int dg=p_GetExp(g,vn,r);
278  if ((df==0)||(dg==0))
279  return pp_Mult_qq(f,g,r);
280  if (df*dg<100)
281  return pp_Mult_qq(f,g,r);
282  // if (df*dg>10000)
283  // return
284  // do_unifastmult_buckets(f,g);
285  //else
286  return do_unifastmult(f,df,g,dg,vn,unifastmult,r);
287 
288 }
f
Definition: cfModGcd.cc:4022
static poly do_unifastmult(poly f, int df, poly g, int dg, int vn, fastmultrec rec, ring r)
Definition: fast_mult.cc:72
g
Definition: cfModGcd.cc:4031
const ring r
Definition: syzextra.cc:208
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
Definition: p_polys.h:465
static poly pp_Mult_qq(poly p, poly q, const ring r)
Definition: p_polys.h:1075
#define NULL
Definition: omList.c:10
poly unifastmult(poly f, poly g, ring r)
Definition: fast_mult.cc:272

Variable Documentation

omBin lm_bin =NULL
static

Definition at line 429 of file fast_mult.cc.

int mults =0
static

Definition at line 13 of file fast_mult.cc.

const int pass_option =1
static

Definition at line 12 of file fast_mult.cc.