summator.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /***************************************************************
5  * File: summator.cc
6  * Purpose: simple Summator usecase implementation
7  * Author: motsak
8  * Created:
9  *******************************************************************/
10 
11 
12 #define MYTEST 0
13 #define OUTPUT 0
14 
15 #if MYTEST
16 #define OM_CHECK 4
17 #define OM_TRACK 5
18 #endif
19 
20 #include "summator.h"
21 
22 #include <misc/auxiliary.h>
23 
24 #ifdef HAVE_SUMMATOR
25 
26 
27 
28 
29 #include <misc/options.h>
30 
31 #include <polys/monomials/ring.h>
33 #include <polys/sbuckets.h>
34 
35 
36 
37 CPolynomialSummator::CPolynomialSummator(const ring& rBaseRing, bool bUsePolynomial):
38  m_basering(rBaseRing), m_bUsePolynomial(bUsePolynomial)
39 {
40 #ifdef RDEBUG
41  rTest(rBaseRing);
42 #endif
43 
44  if(bUsePolynomial)
45  m_temp.m_poly = NULL;
46  else
47  {
49  m_temp.m_bucket = sBucketCreate(rBaseRing);
50  }
51 }
52 
53 /*
54 // no sBucketInit defined :(((
55 CPolynomialSummator::CPolynomialSummator(ring rBaseRing, poly pInitialSum, int iLength, bool bUsePolynomial):
56  m_basering(rBaseRing), m_bUsePolynomial(bUsePolynomial)
57 {
58 #ifdef PDEBUG
59  p_Test(pInitialSum, rBaseRing);
60 #endif
61 
62  if(bUsePolynomial)
63  {
64  m_temp.m_poly = pInitialSum;
65  }
66  else
67  {
68  assume(!TEST_OPT_NOT_BUCKETS);
69  m_temp.m_bucket = sBucketInit(pInitialSum, iLength, rBaseRing);
70  }
71 }
72 */
73 
75 {
76  if(!m_bUsePolynomial)
77  {
78  poly out;
79  int pLength;
80 
81  sBucketClearAdd(m_temp.m_bucket, &out, &pLength);
82  sBucketDestroy(&m_temp.m_bucket);
83 
84  assume(out == NULL); // otherwise wrong usage pattern!
85  if(out != NULL)
86  p_Delete(&out, m_basering);
87 // m_temp.m_bucket = NULL;
88  }
89  else
90  {
91  assume(m_temp.m_poly == NULL); // otherwise wrong usage pattern!
92  if(m_temp.m_poly!=NULL)
93  {
94 #ifdef PDEBUG
95  p_Test(m_temp.m_poly, m_basering);
96 #endif
97  p_Delete(&m_temp.m_poly, m_basering);
98 // m_temp.m_poly = NULL;
99  }
100  }
101 }
102 
103 void CPolynomialSummator::AddAndDelete(poly pSummand, int iLength)
104 {
105 #ifdef PDEBUG
106  p_Test(pSummand, m_basering);
107 #endif
108 
109  if(m_bUsePolynomial)
110  m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
111  else
112  sBucket_Add_p(m_temp.m_bucket, pSummand, iLength); // sBucket_Merge_p???
113 }
114 
116 {
117 #ifdef PDEBUG
118  p_Test(pSummand, m_basering);
119 #endif
120 
121  if(m_bUsePolynomial)
122  m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
123  else
124  sBucket_Add_p(m_temp.m_bucket, pSummand, 0); // sBucket_Merge_p???
125 }
126 
128 {
129  poly out = NULL;
130 
131  if(m_bUsePolynomial)
132  {
133  out = m_temp.m_poly;
134  m_temp.m_poly = NULL;
135  }
136  else
137  {
138  int pLength;
139  sBucketClearAdd(m_temp.m_bucket, &out, &pLength);
140  }
141 
142 #ifdef PDEBUG
143  p_Test(out, m_basering);
144 #endif
145 
146  return out;
147 }
148 
149 
151 {
152  poly out = NULL;
153 
154  if(m_bUsePolynomial)
155  {
156  out = m_temp.m_poly;
157  m_temp.m_poly = NULL;
158  *piLength = pLength(out);
159  }
160  else
161  {
162  *piLength = 0;
163  sBucketClearAdd(m_temp.m_bucket, &out, piLength);
164  }
165 
166 #ifdef PDEBUG
167  p_Test(out, m_basering);
168  assume(pLength(out) == *piLength);
169 #endif
170 
171  return out;
172 }
173 
174 
175 
176 void CPolynomialSummator::Add(poly pSummand, int iLength)
177 {
178  AddAndDelete(p_Copy(pSummand, m_basering), iLength);
179 }
180 
182 {
183  AddAndDelete(p_Copy(pSummand, m_basering));
184 }
185 
186 
187 
190 {
191 // try{
192  if(m_bUsePolynomial)
193  m_temp.m_poly = p_Copy( b.m_temp.m_poly, m_basering);
194  else
195  m_temp.m_bucket = sBucketCopy(b.m_temp.m_bucket);
196 // }
197 // catch(...)
198 // {
199 // assume(false);
200 // }
201 }
202 
203 
204 #endif // ifdef HAVE_SUMMATOR
const ring & m_basering
Definition: summator.h:32
void sBucket_Add_p(sBucket_pt bucket, poly p, int length)
adds poly p to bucket destroys p!
Definition: sbuckets.cc:201
union CPolynomialSummator::@5 m_temp
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:804
CPolynomialSummator(const ring &rBaseRing, bool bUsePolynomial=false)
Definition: summator.cc:37
#define TEST_OPT_NOT_BUCKETS
Definition: options.h:100
void Add(poly pSummand, int iLength)
Definition: summator.cc:176
#define assume(x)
Definition: mod2.h:394
void sBucketDestroy(sBucket_pt *bucket)
Definition: sbuckets.cc:127
sBucket_pt sBucketCreate(const ring r)
Definition: sbuckets.cc:120
#define rTest(r)
Definition: ring.h:777
All the auxiliary stuff.
const bool m_bUsePolynomial
Definition: summator.h:33
static unsigned pLength(poly a)
Definition: p_polys.h:189
#define p_Test(p, r)
Definition: p_polys.h:160
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:843
#define NULL
Definition: omList.c:10
void AddAndDelete(poly pSummand, int iLength)
Definition: summator.cc:103
CPolynomialSummator: unifies bucket and polynomial summation as the later is brocken in buckets :(...
Definition: summator.h:29
polyrec * poly
Definition: hilb.h:10
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:877
const poly b
Definition: syzextra.cc:213
void sBucketClearAdd(sBucket_pt bucket, poly *p, int *length)
Definition: sbuckets.cc:270
sBucket_pt sBucketCopy(const sBucket_pt bucket)
Copy sBucket non-intrusive!!!
Definition: sbuckets.cc:75