My Project
Loading...
Searching...
No Matches
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#include "misc/options.h"
27
30#include "polys/sbuckets.h"
31
32
33
34CPolynomialSummator::CPolynomialSummator(const ring& rBaseRing, bool bUsePolynomial):
35 m_basering(rBaseRing), m_bUsePolynomial(bUsePolynomial)
36{
37#ifdef RDEBUG
38 rTest(rBaseRing);
39#endif
40
41 if(bUsePolynomial)
42 m_temp.m_poly = NULL;
43 else
44 {
46 m_temp.m_bucket = sBucketCreate(rBaseRing);
47 }
48}
49
50/*
51// no sBucketInit defined :(((
52CPolynomialSummator::CPolynomialSummator(ring rBaseRing, poly pInitialSum, int iLength, bool bUsePolynomial):
53 m_basering(rBaseRing), m_bUsePolynomial(bUsePolynomial)
54{
55#ifdef PDEBUG
56 p_Test(pInitialSum, rBaseRing);
57#endif
58
59 if(bUsePolynomial)
60 {
61 m_temp.m_poly = pInitialSum;
62 }
63 else
64 {
65 assume(!TEST_OPT_NOT_BUCKETS);
66 m_temp.m_bucket = sBucketInit(pInitialSum, iLength, rBaseRing);
67 }
68}
69*/
70
72{
74 {
75 poly out;
76 int pLength;
77
78 sBucketClearAdd(m_temp.m_bucket, &out, &pLength);
79 sBucketDestroy(&m_temp.m_bucket);
80
81 assume(out == NULL); // otherwise wrong usage pattern!
82 if(out != NULL)
83 p_Delete(&out, m_basering);
84// m_temp.m_bucket = NULL;
85 }
86 else
87 {
88 assume(m_temp.m_poly == NULL); // otherwise wrong usage pattern!
89 if(m_temp.m_poly!=NULL)
90 {
91#ifdef PDEBUG
92 p_Test(m_temp.m_poly, m_basering);
93#endif
94 p_Delete(&m_temp.m_poly, m_basering);
95// m_temp.m_poly = NULL;
96 }
97 }
98}
99
100void CPolynomialSummator::AddAndDelete(poly pSummand, int iLength)
101{
102#ifdef PDEBUG
103 p_Test(pSummand, m_basering);
104#endif
105
107 m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
108 else
109 sBucket_Add_p(m_temp.m_bucket, pSummand, iLength); // sBucket_Merge_p???
110}
111
113{
114#ifdef PDEBUG
115 p_Test(pSummand, m_basering);
116#endif
117
119 m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
120 else
121 sBucket_Add_p(m_temp.m_bucket, pSummand, 0); // sBucket_Merge_p???
122}
123
125{
126 poly out = NULL;
127
129 {
130 out = m_temp.m_poly;
131 m_temp.m_poly = NULL;
132 }
133 else
134 {
135 int pLength;
136 sBucketClearAdd(m_temp.m_bucket, &out, &pLength);
137 }
138
139#ifdef PDEBUG
140 p_Test(out, m_basering);
141#endif
142
143 return out;
144}
145
146
148{
149 poly out = NULL;
150
152 {
153 out = m_temp.m_poly;
154 m_temp.m_poly = NULL;
155 *piLength = pLength(out);
156 }
157 else
158 {
159 *piLength = 0;
160 sBucketClearAdd(m_temp.m_bucket, &out, piLength);
161 }
162
163#ifdef PDEBUG
164 p_Test(out, m_basering);
165 assume(pLength(out) == *piLength);
166#endif
167
168 return out;
169}
170
171
172
173void CPolynomialSummator::Add(poly pSummand, int iLength)
174{
175 AddAndDelete(p_Copy(pSummand, m_basering), iLength);
176}
177
178void CPolynomialSummator::Add(poly pSummand)
179{
180 AddAndDelete(p_Copy(pSummand, m_basering));
181}
182
183
184
186 m_basering(b.m_basering), m_bUsePolynomial(b.m_bUsePolynomial)
187{
188// try{
190 m_temp.m_poly = p_Copy( b.m_temp.m_poly, m_basering);
191 else
192 {
193 sBucketCanonicalize(b.m_temp.m_bucket);
194 m_temp.m_bucket = sBucketCopy(b.m_temp.m_bucket);
195 }
196// }
197// catch(...)
198// {
199// assume(false);
200// }
201}
202
203
204#endif // ifdef HAVE_SUMMATOR
All the auxiliary stuff.
CanonicalForm b
Definition: cfModGcd.cc:4103
CPolynomialSummator: unifies bucket and polynomial summation as the later is brocken in buckets :(.
Definition: summator.h:21
const ring & m_basering
Definition: summator.h:23
void AddAndDelete(poly pSummand, int iLength)
Definition: summator.cc:100
void Add(poly pSummand, int iLength)
Definition: summator.cc:173
const bool m_bUsePolynomial
Definition: summator.h:24
CPolynomialSummator(const ring &rBaseRing, bool bUsePolynomial=false)
Definition: summator.cc:34
union CPolynomialSummator::@6 m_temp
#define assume(x)
Definition: mod2.h:389
#define NULL
Definition: omList.c:12
#define TEST_OPT_NOT_BUCKETS
Definition: options.h:106
static int pLength(poly a)
Definition: p_polys.h:188
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:934
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:899
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:844
#define p_Test(p, r)
Definition: p_polys.h:159
#define rTest(r)
Definition: ring.h:782
sBucket_pt sBucketCopy(const sBucket_pt bucket)
Copy sBucket non-intrusive!!!
Definition: sbuckets.cc:70
void sBucket_Add_p(sBucket_pt bucket, poly p, int length)
adds poly p to bucket destroys p!
Definition: sbuckets.cc:203
void sBucketCanonicalize(sBucket_pt bucket)
Definition: sbuckets.cc:401
void sBucketDestroy(sBucket_pt *bucket)
Definition: sbuckets.cc:103
sBucket_pt sBucketCreate(const ring r)
Definition: sbuckets.cc:96
void sBucketClearAdd(sBucket_pt bucket, poly *p, int *length)
Definition: sbuckets.cc:275