My Project
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Friends
spectrum Class Reference

#include <semic.h>

Public Member Functions

 spectrum ()
 Zero constructor. More...
 
 spectrum (const spectrum &)
 
 ~spectrum ()
 
spectrum operator= (const spectrum &)
 
void copy_new (int)
 
void copy_delete (void)
 Delete the memory of a spectrum. More...
 
void copy_zero (void)
 Initialize with zero. More...
 
void copy_shallow (spectrum &spec)
 Initialize shallow from another spectrum. More...
 
void copy_deep (const spectrum &)
 
int add_subspectrum (spectrum &, int)
 
int next_number (Rational *)
 
int next_interval (Rational *, Rational *)
 
int numbers_in_interval (Rational &, Rational &, interval_status)
 
int mult_spectrum (spectrum &)
 
int mult_spectrumh (spectrum &)
 

Data Fields

int mu
 
int pg
 
int n
 
Rationals
 
int * w
 

Friends

spectrum operator+ (const spectrum &, const spectrum &)
 
spectrum operator* (int, const spectrum &)
 
ostream & operator<< (ostream &, const spectrum &)
 

Detailed Description

Definition at line 63 of file semic.h.

Constructor & Destructor Documentation

◆ spectrum() [1/2]

spectrum::spectrum ( )
inline

Zero constructor.

Definition at line 77 of file semic.h.

78 {
79 copy_zero( );
80 }
void copy_zero(void)
Initialize with zero.
Definition: semic.h:108

◆ spectrum() [2/2]

spectrum::spectrum ( const spectrum spec)

Definition at line 36 of file semic.cc.

37{
38 copy_deep( spec );
39}
void copy_deep(const spectrum &)
Definition: semic.cc:103

◆ ~spectrum()

spectrum::~spectrum ( )

Definition at line 45 of file semic.cc.

46{
47 copy_delete( );
48}
void copy_delete(void)
Delete the memory of a spectrum.
Definition: semic.h:100

Member Function Documentation

◆ add_subspectrum()

int spectrum::add_subspectrum ( spectrum a,
int  k 
)

Definition at line 279 of file semic.cc.

280{
281 int i,j;
282 for( i=0, j=0; i<n; i++ )
283 {
284 if( s[i] == a.s[j] )
285 {
286 w[i] += k*a.w[j];
287 j++;
288 }
289 }
290
291 return ( j == a.n ? TRUE : FALSE );
292}
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
int i
Definition: cfEzgcd.cc:132
int k
Definition: cfEzgcd.cc:99
Rational * s
Definition: semic.h:70
int n
Definition: semic.h:69
int * w
Definition: semic.h:71
int j
Definition: facHensel.cc:110

◆ copy_deep()

void spectrum::copy_deep ( const spectrum spec)

Definition at line 103 of file semic.cc.

104{
105 mu = spec.mu;
106 pg = spec.pg;
107 n = spec.n;
108
109 copy_new( n );
110
111 for( int i=0; i<n; i++ )
112 {
113 s[i] = spec.s[i];
114 w[i] = spec.w[i];
115 }
116}
int mu
Definition: semic.h:67
void copy_new(int)
Definition: semic.cc:54
int pg
Definition: semic.h:68

◆ copy_delete()

void spectrum::copy_delete ( void  )
inline

Delete the memory of a spectrum.

Definition at line 100 of file semic.h.

101{
102 if( s != (Rational*)NULL && n > 0 ) delete [] s;
103 if( w != (int*)NULL && n > 0 ) delete [] w;
104 copy_zero( );
105}
#define NULL
Definition: omList.c:12

◆ copy_new()

void spectrum::copy_new ( int  k)

Definition at line 54 of file semic.cc.

55{
56 if( k > 0 )
57 {
58 s = new Rational[k];
59 w = new int[k];
60
61 #ifndef SING_NDEBUG
62 if( s == (Rational*)NULL || w == (int*)NULL )
63 {
64 #ifdef SEMIC_PRINT
65 #ifdef SEMIC_IOSTREAM
66 cerr << "spectrum::copy_new(" << k << ")" << endl;
67 cerr << " returned ZERO!!!" << endl;
68 cerr << " exit..." << endl;
69 #else
70 fprintf( stderr,"spectrum::copy_new( %d )\n",k );
71 fprintf( stderr," returned ZERO!!!\n" );
72 fprintf( stderr," exit...\n" );
73 #endif
74 #endif
75 }
76 #endif
77 }
78 else if( k == 0 )
79 {
80 s = (Rational*)NULL;
81 w = (int*)NULL;
82 }
83 else if( k < 0 )
84 {
85 #ifdef SEMIC_PRINT
86 #ifdef SEMIC_IOSTREAM
87 cerr << "spectrum::copy_new(" << k << ")";
88 cerr << ": k < 0 ..." << endl;
89 #else
90 fprintf( stderr,"spectrum::copy_new( %d )",k );
91 fprintf( stderr,": k < 0 ...\n" );
92 #endif
93 #endif
94
95 exit( 1 );
96 }
97}

◆ copy_shallow()

void spectrum::copy_shallow ( spectrum spec)
inline

Initialize shallow from another spectrum.

Definition at line 118 of file semic.h.

119{
120 mu = spec.mu;
121 pg = spec.pg;
122 n = spec.n;
123 s = spec.s;
124 w = spec.w;
125}

◆ copy_zero()

void spectrum::copy_zero ( void  )
inline

Initialize with zero.

Definition at line 108 of file semic.h.

109{
110 mu = 0;
111 pg = 0;
112 n = 0;
113 s = (Rational*)NULL;
114 w = (int*)NULL;
115}

◆ mult_spectrum()

int spectrum::mult_spectrum ( spectrum t)

Definition at line 396 of file semic.cc.

397{
398 spectrum u = *this + t;
399
400 Rational alpha1 = -2;
401 Rational alpha2 = -1;
402
403 int mult=MAX_INT_VAL,nthis,nt;
404
405 while( u.next_interval( &alpha1,&alpha2 ) )
406 {
407 nt = t.numbers_in_interval( alpha1,alpha2,LEFTOPEN );
408 nthis = this->numbers_in_interval( alpha1,alpha2,LEFTOPEN );
409
410 if( nt != 0 )
411 {
412 mult = (nthis/nt < mult ? nthis/nt: mult );
413 }
414
415 }
416
417 return mult;
418}
Definition: semic.h:64
int next_interval(Rational *, Rational *)
Definition: semic.cc:325
int numbers_in_interval(Rational &, Rational &, interval_status)
Definition: semic.cc:362
void mult(unsigned long *result, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:647
const int MAX_INT_VAL
Definition: mylimits.h:12
@ LEFTOPEN
Definition: semic.h:23

◆ mult_spectrumh()

int spectrum::mult_spectrumh ( spectrum t)

Definition at line 425 of file semic.cc.

426{
427 spectrum u = *this + t;
428
429 Rational alpha1 = -2;
430 Rational alpha2 = -1;
431
432 int mult=MAX_INT_VAL,nthis,nt;
433
434 while( u.next_interval( &alpha1,&alpha2 ) )
435 {
436 nt = t.numbers_in_interval( alpha1,alpha2,LEFTOPEN );
437 nthis = this->numbers_in_interval( alpha1,alpha2,LEFTOPEN );
438
439 if( nt != 0 )
440 {
441 mult = (nthis/nt < mult ? nthis/nt: mult );
442 }
443
444 nt = t.numbers_in_interval( alpha1,alpha2,OPEN );
445 nthis = this->numbers_in_interval( alpha1,alpha2,OPEN );
446
447 if( nt != 0 )
448 {
449 mult = (nthis/nt < mult ? nthis/nt: mult );
450 }
451 }
452
453 return mult;
454}
@ OPEN
Definition: semic.h:22

◆ next_interval()

int spectrum::next_interval ( Rational alpha1,
Rational alpha2 
)

Definition at line 325 of file semic.cc.

326{
327 Rational zero( 0,1 );
328 Rational a1 = *alpha1;
329 Rational a2 = *alpha2;
330 Rational d = *alpha2 - *alpha1;
331
332 int e1 = this->next_number( &a1 );
333 int e2 = this->next_number( &a2 );
334
335 if( e1 || e2 )
336 {
337 Rational d1 = a1 - *alpha1;
338 Rational d2 = a2 - *alpha2;
339
340 if( d1 < d2 || d2 == zero )
341 {
342 *alpha1 = a1;
343 *alpha2 = a1 + d;
344 }
345 else
346 {
347 *alpha1 = a2 - d;
348 *alpha2 = a2;
349 }
350 return TRUE;
351 }
352 else
353 {
354 return FALSE;
355 }
356}
int next_number(Rational *)
Definition: semic.cc:300

◆ next_number()

int spectrum::next_number ( Rational alpha)

Definition at line 300 of file semic.cc.

301{
302 int i=0;
303
304 while( i < n && *alpha >= s[i] )
305 {
306 i++;
307 }
308
309 if( i < n )
310 {
311 *alpha = s[i];
312 return TRUE;
313 }
314 else
315 {
316 return FALSE;
317 }
318}
Variable alpha
Definition: facAbsBiFact.cc:51

◆ numbers_in_interval()

int spectrum::numbers_in_interval ( Rational alpha1,
Rational alpha2,
interval_status  status 
)

Definition at line 362 of file semic.cc.

364{
365 int count = 0;
366
367 for( int i=0; i<n; i++ )
368 {
369 if( ( ( status == OPEN || status == LEFTOPEN ) &&
370 s[i] > alpha1 ) ||
371 ( ( status == CLOSED || status == RIGHTOPEN ) &&
372 s[i] >= alpha1 ) )
373 {
374 if( ( ( status == OPEN || status == RIGHTOPEN ) &&
375 s[i] < alpha2 ) ||
376 ( ( status == CLOSED || status == LEFTOPEN ) &&
377 s[i] <= alpha2 ) )
378 {
379 count += w[i];
380 }
381 else
382 {
383 break;
384 }
385 }
386 }
387
388 return count;
389}
@ RIGHTOPEN
Definition: semic.h:24
@ CLOSED
Definition: semic.h:25
int * status
Definition: si_signals.h:51
int status int void size_t count
Definition: si_signals.h:59

◆ operator=()

spectrum spectrum::operator= ( const spectrum spec)

Definition at line 122 of file semic.cc.

123{
124 copy_delete( );
125 copy_deep( spec );
126
127 return *this;
128}

Friends And Related Function Documentation

◆ operator*

spectrum operator* ( int  k,
const spectrum spec 
)
friend

Definition at line 219 of file semic.cc.

220{
221 if( k == 0 )
222 {
224
225 return result;
226 }
227 else
228 {
229 spectrum result( spec );
230
231 result.mu *= k;
232 result.pg *= k;
233
234 for( int i=0; i<result.n; i++ )
235 {
236 result.w[i] *= k;
237 }
238
239 return result;
240 }
241}
return result
Definition: facAbsBiFact.cc:75

◆ operator+

spectrum operator+ ( const spectrum s1,
const spectrum s2 
)
friend

Definition at line 134 of file semic.cc.

135{
136 int i1=0, i2=0, i3=0;
137
139
140 do
141 {
142 if( i1 >= s1.n )
143 {
144 i2++;
145 }
146 else if( i2 >= s2.n )
147 {
148 i1++;
149 }
150 else if( s1.s[i1] < s2.s[i2] )
151 {
152 i1++;
153 }
154 else if( s1.s[i1] == s2.s[i2] )
155 {
156 i1++;
157 i2++;
158 }
159 else
160 {
161 i2++;
162 }
163 i3++;
164 }
165 while( i1 < s1.n || i2 < s2.n );
166
167 result.copy_new( i3 );
168 result.n = i3;
169
170 i1 = i2 = i3 = 0;
171
172 do
173 {
174 if( i1 >= s1.n )
175 {
176 result.s[i3] = s2.s[i2];
177 result.w[i3] = s2.w[i2];
178 i2++;
179 }
180 else if( i2 >= s2.n )
181 {
182 result.s[i3] = s1.s[i1];
183 result.w[i3] = s1.w[i1];
184 i1++;
185 }
186 else if( s1.s[i1] < s2.s[i2] )
187 {
188 result.s[i3] = s1.s[i1];
189 result.w[i3] = s1.w[i1];
190 i1++;
191 }
192 else if( s1.s[i1] == s2.s[i2] )
193 {
194 result.s[i3] = s1.s[i1];
195 result.w[i3] = s1.w[i1] + s2.w[i2];
196 i1++;
197 i2++;
198 }
199 else
200 {
201 result.s[i3] = s2.s[i2];
202 result.w[i3] = s2.w[i2];
203 i2++;
204 }
205 i3++;
206 }
207 while( i1 < s1.n || i2 < s2.n );
208
209 result.mu = s1.mu + s2.mu;
210 result.pg = s1.pg + s2.pg;
211
212 return result;
213}

◆ operator<<

ostream & operator<< ( ostream &  s,
const spectrum spec 
)
friend

Definition at line 249 of file semic.cc.

250{
251 for( int i=0; i<spec.n; i++ )
252 {
253 if( i>0 )
254 {
255 #ifdef SEMIC_STDOUT
256 s << "+";
257 #else
258 fprintf( stdout,"+" );
259 #endif
260 }
261
262 #ifdef SEMIC_STDOUT
263 s << spec.w[i] << "*t^";
264 #else
265 fprintf( stdout,"%d*t^",spec.w[i] );
266 #endif
267
268 s << spec.s[i];
269 }
270
271 return s;
272}

Field Documentation

◆ mu

int spectrum::mu

Definition at line 67 of file semic.h.

◆ n

int spectrum::n

Definition at line 69 of file semic.h.

◆ pg

int spectrum::pg

Definition at line 68 of file semic.h.

◆ s

Rational* spectrum::s

Definition at line 70 of file semic.h.

◆ w

int* spectrum::w

Definition at line 71 of file semic.h.


The documentation for this class was generated from the following files: