source: git/kernel/digitech.cc @ bafaec0

fieker-DuValspielwiese
Last change on this file since bafaec0 was 341696, checked in by Hans Schönemann <hannes@…>, 15 years ago
Adding Id property to all files git-svn-id: file:///usr/local/Singular/svn/trunk@12231 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[4577cc]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
[341696]4/* $Id$ */
[4577cc]5#include "mod2.h"
6#include "ring.h"
7
[21395a]8#include "digitech.h"
9#include "kbuckets.h"
10#include "ideals.h"
11static ideal zero_ideal;
[ca086f]12#if 1
[fca87a]13void bit_reduce(poly & f,ring r)
14{
[21395a]15  poly p=f;
16  kBucket_pt erg_bucket= kBucketCreate(r);
17  kBucketInit(erg_bucket,NULL,0 /*pLength(P.p)*/);
[fca87a]18  while(p)
19  {
[21395a]20    poly next=pNext(p);
21    pNext(p)=NULL;
22
23    int i;
24    int max=rVar(r);
[fca87a]25    for(i=1;i<=max;i++)
26    {
[21395a]27      unsigned long exp=p_GetExp(p,i,r);
28      if(exp!=0)
[fca87a]29        p_SetExp(p,i,1,r);
30
[21395a]31    }
32    p_Setm(p,r);
33    int pseudo_len=0;
34    kBucket_Add_q(erg_bucket,p,&pseudo_len);
35    p=next;
36  }
37
38  int len=0;
39  poly erg;
40  kBucketClear(erg_bucket,&erg, &len);
41  kBucketDestroy(&erg_bucket);
42  f=erg;
43}
[ca086f]44#else
45
46
47
[fca87a]48void do_bit_reduce(poly f, kBucket_pt bucket)
49{
[ca086f]50    ring r=bucket->bucket_ring;
51    int p=rChar(r);
52    int max=rVar(r);
53    while (f!=NULL)
54        {
55            // int len=0;
56//             poly erg;
57//             kBucketClear(bucket,&erg, &len);
58//             kBucketDestroy(&bucket);
59//             return erg;
60            //return;
61        //}
[fca87a]62
[ca086f]63    BOOLEAN changed=FALSE;
64    poly next=pNext(f);
65    pNext(f)=NULL;
66    int i;
[fca87a]67    for(i=1;i<=max;i++)
68    {
[ca086f]69      unsigned long exp;
70      while((exp=p_GetExp(f,i,r))>=p){
[fca87a]71               p_SetExp(f,i,exp-p+1,r);
72               changed=TRUE;
[ca086f]73      }
74    }
[fca87a]75
76    if (changed)
77    {
[ca086f]78        p_Setm(f,r);
[fca87a]79
[ca086f]80        int pseudo_len=0;
81        kBucket_Add_q(bucket,f,&pseudo_len);
82        //do_bit_reduce(next,bucket);
[fca87a]83    }
84    else
85    {
[ca086f]86        //do_bit_reduce(next,bucket);
87        int pseudo_len=0;
88        kBucket_Add_q(bucket,f,&pseudo_len);
[fca87a]89
[ca086f]90    }
91    f=next;
92    }
93}
[fca87a]94poly do_bitreduce(poly f, ring r)
95{
[ca086f]96  poly erg=NULL;
97  poly *append_to=&erg;
98  int p=rChar(r);
99  int max=rVar(r);
100  kBucket_pt bucket= kBucketCreate(r);
101  kBucketInit(bucket,NULL,0 /*pLength(P.p)*/);
[fca87a]102  while(f!=NULL)
103  {
[ca086f]104    BOOLEAN changed=FALSE;
105    poly next=pNext(f);
106    pNext(f)=NULL;
107    assume(pNext(f)==NULL);
108    int i;
[fca87a]109    for(i=1;i<=max;i++)
110    {
[ca086f]111      unsigned long exp;
[fca87a]112      while((exp=p_GetExp(f,i,r))>=p)
113      {
114               p_SetExp(f,i,exp-p+1,r);
115               changed=TRUE;
[ca086f]116      }
117    }
[fca87a]118    if (changed)
119    {
[ca086f]120        p_Setm(f,r);
121        int pseudo_len=0;
122        kBucket_Add_q(bucket,f,&pseudo_len);
[fca87a]123    }
124    else
125    {
[ca086f]126        (*append_to)=f;
127        append_to=&(pNext(f));
128    }
129    f=next;
130  }
131  {
132    int pseudo_len=0;
133    kBucket_Add_q(bucket,erg,&pseudo_len);
134    pseudo_len=0;
135    kBucketClear(bucket,&erg,&pseudo_len);
136  }
137    return erg;
138}
[fca87a]139void bit_reduce2(poly & f,ring r)
140{
[ca086f]141  if (f==NULL) return;
142  if (pNext(f)==NULL){
143    int p=rChar(r);
144    int max=rVar(r);
145    BOOLEAN changed=FALSE;
146    poly next=pNext(f);
147    assume(pNext(f)==NULL);
148    int i;
[fca87a]149    for(i=1;i<=max;i++)
150    {
[ca086f]151      unsigned long exp;
[fca87a]152      while((exp=p_GetExp(f,i,r))>=p)
153      {
154               p_SetExp(f,i,exp-p+1,r);
155               changed=TRUE;
[ca086f]156      }
157    }
158    if (changed)
159        p_Setm(f,r);
160    return;
161  }
162  // kBucket_pt bucket= kBucketCreate(r);
163//   kBucketInit(bucket,NULL,0 /*pLength(P.p)*/);
164//   do_bit_reduce(f,bucket);
165//   int len=0;
166//   kBucketClear(bucket,&f, &len);
167//   kBucketDestroy(&bucket);
168    f=do_bitreduce(f,r);
[fca87a]169
[ca086f]170}
[fca87a]171void bit_reduce1(poly & f,ring r)
172{
[ca086f]173  if (f==NULL) return;
174
[fca87a]175
176  if (pNext(f)==NULL)
177  {
[ca086f]178    int p=rChar(r);
179    int max=rVar(r);
180    BOOLEAN changed=FALSE;
181    poly next=pNext(f);
182    assume(pNext(f)==NULL);
183    int i;
[fca87a]184    for(i=1;i<=max;i++)
185    {
[ca086f]186      unsigned long exp;
[fca87a]187      while((exp=p_GetExp(f,i,r))>=p)
188      {
189               p_SetExp(f,i,exp-p+1,r);
190               changed=TRUE;
[ca086f]191      }
192    }
193    if (changed)
194        p_Setm(f,r);
195    return;
196  }
197  kBucket_pt bucket= kBucketCreate(r);
198  kBucketInit(bucket,NULL,0 /*pLength(P.p)*/);
199  do_bit_reduce(f,bucket);
200  int len=0;
201  kBucketClear(bucket,&f, &len);
202  kBucketDestroy(&bucket);
[fca87a]203
[ca086f]204}
205// void bit_reduce_arg(poly & f,ring r){
206//   kBucket_pt bucket= kBucketCreate(r);
207//   kBucketInit(bucket,NULL,0 /*pLength(P.p)*/);
208//   f=do_bit_reduce(f,bucket);
209// }
210#endif
211
[fca87a]212poly uni_subst_bits(poly outer_uni, poly inner_multi, ring r)
213{
[21395a]214  zero_ideal=idInit(0,1);
215  //assumes outer_uni is univariate and ordering global
216  int d_max=p_GetExp(outer_uni,1,r);
[fca87a]217  poly* potences=(poly*) omAlloc((d_max+1)*sizeof(poly));
[21395a]218  potences[0]=p_ISet(1,r);
219  int i;
[fca87a]220  for(i=1;i<=d_max;i++)
221  {
[21395a]222    potences[i]=pp_Mult_qq(potences[i-1],inner_multi,r);
223    bit_reduce(potences[i],r);
224  }
225
226  poly p=outer_uni;
227  kBucket_pt erg_bucket= kBucketCreate(r);
228  kBucketInit(erg_bucket,NULL,0 /*pLength(P.p)*/);
229
230
[fca87a]231  while(p)
232  {
[21395a]233    int d=p_GetExp(p,1,r);
234    assume(potences[d]!=NULL); //mustn't always hold, but for most input
235    int pseudo_len=0;
236    kBucket_Add_q(erg_bucket,p_Mult_nn(potences[d],p_GetCoeff(p,r),r),&pseudo_len);
237    potences[d]=NULL;
238    p=pNext(p);
239  }
240
241
242
243
244  //free potences
[fca87a]245  for(i=0;i<=d_max;i++)
246  {
[21395a]247    p_Delete(&potences[i],r);
248  }
249  omfree(potences);
250  int len=0;
251  poly erg;
252  kBucketClear(erg_bucket,&erg, &len);
253  kBucketDestroy(&erg_bucket);
254  return(erg);
255}
Note: See TracBrowser for help on using the repository browser.