[4577cc] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[16f511] | 4 | #ifdef HAVE_CONFIG_H |
---|
[ba5e9e] | 5 | #include "singularconfig.h" |
---|
[16f511] | 6 | #endif /* HAVE_CONFIG_H */ |
---|
[599326] | 7 | #include <kernel/mod2.h> |
---|
[210e07] | 8 | #include <polys/monomials/ring.h> |
---|
[4577cc] | 9 | |
---|
[599326] | 10 | #include <kernel/digitech.h> |
---|
[210e07] | 11 | #include <polys/kbuckets.h> |
---|
[599326] | 12 | #include <kernel/ideals.h> |
---|
[21395a] | 13 | static ideal zero_ideal; |
---|
[fda7090] | 14 | |
---|
[fca87a] | 15 | void bit_reduce(poly & f,ring r) |
---|
| 16 | { |
---|
[21395a] | 17 | poly p=f; |
---|
| 18 | kBucket_pt erg_bucket= kBucketCreate(r); |
---|
| 19 | kBucketInit(erg_bucket,NULL,0 /*pLength(P.p)*/); |
---|
[fca87a] | 20 | while(p) |
---|
| 21 | { |
---|
[21395a] | 22 | poly next=pNext(p); |
---|
| 23 | pNext(p)=NULL; |
---|
| 24 | |
---|
| 25 | int i; |
---|
| 26 | int max=rVar(r); |
---|
[fca87a] | 27 | for(i=1;i<=max;i++) |
---|
| 28 | { |
---|
[21395a] | 29 | unsigned long exp=p_GetExp(p,i,r); |
---|
| 30 | if(exp!=0) |
---|
[fca87a] | 31 | p_SetExp(p,i,1,r); |
---|
| 32 | |
---|
[21395a] | 33 | } |
---|
| 34 | p_Setm(p,r); |
---|
| 35 | int pseudo_len=0; |
---|
| 36 | kBucket_Add_q(erg_bucket,p,&pseudo_len); |
---|
| 37 | p=next; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | int len=0; |
---|
| 41 | poly erg; |
---|
| 42 | kBucketClear(erg_bucket,&erg, &len); |
---|
| 43 | kBucketDestroy(&erg_bucket); |
---|
| 44 | f=erg; |
---|
| 45 | } |
---|
[ca086f] | 46 | |
---|
[fca87a] | 47 | poly uni_subst_bits(poly outer_uni, poly inner_multi, ring r) |
---|
| 48 | { |
---|
[21395a] | 49 | zero_ideal=idInit(0,1); |
---|
| 50 | //assumes outer_uni is univariate and ordering global |
---|
| 51 | int d_max=p_GetExp(outer_uni,1,r); |
---|
[fca87a] | 52 | poly* potences=(poly*) omAlloc((d_max+1)*sizeof(poly)); |
---|
[21395a] | 53 | potences[0]=p_ISet(1,r); |
---|
| 54 | int i; |
---|
[fca87a] | 55 | for(i=1;i<=d_max;i++) |
---|
| 56 | { |
---|
[21395a] | 57 | potences[i]=pp_Mult_qq(potences[i-1],inner_multi,r); |
---|
| 58 | bit_reduce(potences[i],r); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | poly p=outer_uni; |
---|
| 62 | kBucket_pt erg_bucket= kBucketCreate(r); |
---|
| 63 | kBucketInit(erg_bucket,NULL,0 /*pLength(P.p)*/); |
---|
| 64 | |
---|
| 65 | |
---|
[fca87a] | 66 | while(p) |
---|
| 67 | { |
---|
[21395a] | 68 | int d=p_GetExp(p,1,r); |
---|
| 69 | assume(potences[d]!=NULL); //mustn't always hold, but for most input |
---|
| 70 | int pseudo_len=0; |
---|
| 71 | kBucket_Add_q(erg_bucket,p_Mult_nn(potences[d],p_GetCoeff(p,r),r),&pseudo_len); |
---|
| 72 | potences[d]=NULL; |
---|
| 73 | p=pNext(p); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | //free potences |
---|
[fca87a] | 77 | for(i=0;i<=d_max;i++) |
---|
| 78 | { |
---|
[21395a] | 79 | p_Delete(&potences[i],r); |
---|
| 80 | } |
---|
| 81 | omfree(potences); |
---|
| 82 | int len=0; |
---|
| 83 | poly erg; |
---|
| 84 | kBucketClear(erg_bucket,&erg, &len); |
---|
| 85 | kBucketDestroy(&erg_bucket); |
---|
| 86 | return(erg); |
---|
| 87 | } |
---|