source: git/kernel/digitech.cc @ 0179d5

spielwiese
Last change on this file since 0179d5 was fca87a, checked in by Hans Schönemann <hannes@…>, 15 years ago
*hannes: omalloc, format git-svn-id: file:///usr/local/Singular/svn/trunk@11761 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.1 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: digitech.cc,v 1.6 2009-04-30 17:00:27 Singular Exp $ */
5#include "mod2.h"
6#include "ring.h"
7
8#include "digitech.h"
9#include "kbuckets.h"
10#include "ideals.h"
11static ideal zero_ideal;
12#if 1
13void bit_reduce(poly & f,ring r)
14{
15  poly p=f;
16  kBucket_pt erg_bucket= kBucketCreate(r);
17  kBucketInit(erg_bucket,NULL,0 /*pLength(P.p)*/);
18  while(p)
19  {
20    poly next=pNext(p);
21    pNext(p)=NULL;
22
23    int i;
24    int max=rVar(r);
25    for(i=1;i<=max;i++)
26    {
27      unsigned long exp=p_GetExp(p,i,r);
28      if(exp!=0)
29        p_SetExp(p,i,1,r);
30
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}
44#else
45
46
47
48void do_bit_reduce(poly f, kBucket_pt bucket)
49{
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        //}
62
63    BOOLEAN changed=FALSE;
64    poly next=pNext(f);
65    pNext(f)=NULL;
66    int i;
67    for(i=1;i<=max;i++)
68    {
69      unsigned long exp;
70      while((exp=p_GetExp(f,i,r))>=p){
71               p_SetExp(f,i,exp-p+1,r);
72               changed=TRUE;
73      }
74    }
75
76    if (changed)
77    {
78        p_Setm(f,r);
79
80        int pseudo_len=0;
81        kBucket_Add_q(bucket,f,&pseudo_len);
82        //do_bit_reduce(next,bucket);
83    }
84    else
85    {
86        //do_bit_reduce(next,bucket);
87        int pseudo_len=0;
88        kBucket_Add_q(bucket,f,&pseudo_len);
89
90    }
91    f=next;
92    }
93}
94poly do_bitreduce(poly f, ring r)
95{
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)*/);
102  while(f!=NULL)
103  {
104    BOOLEAN changed=FALSE;
105    poly next=pNext(f);
106    pNext(f)=NULL;
107    assume(pNext(f)==NULL);
108    int i;
109    for(i=1;i<=max;i++)
110    {
111      unsigned long exp;
112      while((exp=p_GetExp(f,i,r))>=p)
113      {
114               p_SetExp(f,i,exp-p+1,r);
115               changed=TRUE;
116      }
117    }
118    if (changed)
119    {
120        p_Setm(f,r);
121        int pseudo_len=0;
122        kBucket_Add_q(bucket,f,&pseudo_len);
123    }
124    else
125    {
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}
139void bit_reduce2(poly & f,ring r)
140{
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;
149    for(i=1;i<=max;i++)
150    {
151      unsigned long exp;
152      while((exp=p_GetExp(f,i,r))>=p)
153      {
154               p_SetExp(f,i,exp-p+1,r);
155               changed=TRUE;
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);
169
170}
171void bit_reduce1(poly & f,ring r)
172{
173  if (f==NULL) return;
174
175
176  if (pNext(f)==NULL)
177  {
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;
184    for(i=1;i<=max;i++)
185    {
186      unsigned long exp;
187      while((exp=p_GetExp(f,i,r))>=p)
188      {
189               p_SetExp(f,i,exp-p+1,r);
190               changed=TRUE;
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);
203
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
212poly uni_subst_bits(poly outer_uni, poly inner_multi, ring r)
213{
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);
217  poly* potences=(poly*) omAlloc((d_max+1)*sizeof(poly));
218  potences[0]=p_ISet(1,r);
219  int i;
220  for(i=1;i<=d_max;i++)
221  {
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
231  while(p)
232  {
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
245  for(i=0;i<=d_max;i++)
246  {
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.