1 | // ---------------------------------------------------------------------------- |
---|
2 | // semic.cc |
---|
3 | // begin of file |
---|
4 | // Stephan Endrass, endrass@mathematik.uni-mainz.de |
---|
5 | // 23.7.99 |
---|
6 | // ---------------------------------------------------------------------------- |
---|
7 | |
---|
8 | #define SEMIC_CC |
---|
9 | |
---|
10 | #include"mod2.h" |
---|
11 | |
---|
12 | #ifdef HAVE_SPECTRUM |
---|
13 | |
---|
14 | #ifdef SEMIC_PRINT |
---|
15 | #ifndef SEMIC_IOSTREAM |
---|
16 | #include<stdio.h> |
---|
17 | #else |
---|
18 | #include<iostream.h> |
---|
19 | #endif |
---|
20 | #endif |
---|
21 | |
---|
22 | #include<string.h> |
---|
23 | #ifndef ix86_Win |
---|
24 | //#include<values.h> |
---|
25 | #endif |
---|
26 | |
---|
27 | #include"intvec.h" |
---|
28 | #include"GMPrat.h" |
---|
29 | #include"semic.h" |
---|
30 | |
---|
31 | // ---------------------------------------------------------------------------- |
---|
32 | // Delete the memory of a spectrum |
---|
33 | // ---------------------------------------------------------------------------- |
---|
34 | |
---|
35 | inline void spectrum::copy_delete( void ) |
---|
36 | { |
---|
37 | if( s != (Rational*)NULL && n > 0 ) delete [] s; |
---|
38 | if( w != (int*)NULL && n > 0 ) delete [] w; |
---|
39 | copy_zero( ); |
---|
40 | } |
---|
41 | |
---|
42 | // ---------------------------------------------------------------------------- |
---|
43 | // Allocate memory for a spectrum of k numbers |
---|
44 | // ---------------------------------------------------------------------------- |
---|
45 | |
---|
46 | void spectrum::copy_new( int k ) |
---|
47 | { |
---|
48 | if( k > 0 ) |
---|
49 | { |
---|
50 | s = new Rational[k]; |
---|
51 | w = new int[k]; |
---|
52 | |
---|
53 | #ifndef NDEBUG |
---|
54 | if( s == (Rational*)NULL || w == (int*)NULL ) |
---|
55 | { |
---|
56 | #ifdef SEMIC_PRINT |
---|
57 | #ifdef SEMIC_IOSTREAM |
---|
58 | cerr << "spectrum::copy_new(" << k << ")" << endl; |
---|
59 | cerr << " returned ZERO!!!" << endl; |
---|
60 | cerr << " exit..." << endl; |
---|
61 | #else |
---|
62 | fprintf( stderr,"spectrum::copy_new( %d )\n",k ); |
---|
63 | fprintf( stderr," returned ZERO!!!\n" ); |
---|
64 | fprintf( stderr," exit...\n" ); |
---|
65 | #endif |
---|
66 | #endif |
---|
67 | } |
---|
68 | #endif |
---|
69 | } |
---|
70 | else if( k == 0 ) |
---|
71 | { |
---|
72 | s = (Rational*)NULL; |
---|
73 | w = (int*)NULL; |
---|
74 | } |
---|
75 | else if( k < 0 ) |
---|
76 | { |
---|
77 | #ifdef SEMIC_PRINT |
---|
78 | #ifdef SEMIC_IOSTREAM |
---|
79 | cerr << "spectrum::copy_new(" << k << ")"; |
---|
80 | cerr << ": k < 0 ..." << endl; |
---|
81 | #else |
---|
82 | fprintf( stderr,"spectrum::copy_new( %d )",k ); |
---|
83 | fprintf( stderr,": k < 0 ...\n" ); |
---|
84 | #endif |
---|
85 | #endif |
---|
86 | |
---|
87 | exit( 1 ); |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | // ---------------------------------------------------------------------------- |
---|
92 | // Copy constructor for spectrum |
---|
93 | // ---------------------------------------------------------------------------- |
---|
94 | |
---|
95 | spectrum::spectrum( const spectrum &spec ) |
---|
96 | { |
---|
97 | copy_deep( spec ); |
---|
98 | } |
---|
99 | |
---|
100 | // ---------------------------------------------------------------------------- |
---|
101 | // Destructor for spectrum |
---|
102 | // ---------------------------------------------------------------------------- |
---|
103 | |
---|
104 | spectrum::~spectrum( ) |
---|
105 | { |
---|
106 | copy_delete( ); |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | // ---------------------------------------------------------------------------- |
---|
111 | // operator = for spectrum |
---|
112 | // ---------------------------------------------------------------------------- |
---|
113 | |
---|
114 | spectrum spectrum::operator = ( const spectrum &spec ) |
---|
115 | { |
---|
116 | copy_delete( ); |
---|
117 | copy_deep( spec ); |
---|
118 | |
---|
119 | return *this; |
---|
120 | } |
---|
121 | |
---|
122 | // ---------------------------------------------------------------------------- |
---|
123 | // add the two spectra s1 and s2 and return their sum |
---|
124 | // ---------------------------------------------------------------------------- |
---|
125 | |
---|
126 | spectrum operator + ( const spectrum &s1,const spectrum &s2 ) |
---|
127 | { |
---|
128 | int i1=0, i2=0, i3=0; |
---|
129 | |
---|
130 | spectrum result; |
---|
131 | |
---|
132 | do |
---|
133 | { |
---|
134 | if( i1 >= s1.n ) |
---|
135 | { |
---|
136 | i2++; |
---|
137 | } |
---|
138 | else if( i2 >= s2.n ) |
---|
139 | { |
---|
140 | i1++; |
---|
141 | } |
---|
142 | else if( s1.s[i1] < s2.s[i2] ) |
---|
143 | { |
---|
144 | i1++; |
---|
145 | } |
---|
146 | else if( s1.s[i1] == s2.s[i2] ) |
---|
147 | { |
---|
148 | i1++; |
---|
149 | i2++; |
---|
150 | } |
---|
151 | else |
---|
152 | { |
---|
153 | i2++; |
---|
154 | } |
---|
155 | i3++; |
---|
156 | } |
---|
157 | while( i1 < s1.n || i2 < s2.n ); |
---|
158 | |
---|
159 | result.copy_new( i3 ); |
---|
160 | result.n = i3; |
---|
161 | |
---|
162 | i1 = i2 = i3 = 0; |
---|
163 | |
---|
164 | do |
---|
165 | { |
---|
166 | if( i1 >= s1.n ) |
---|
167 | { |
---|
168 | result.s[i3] = s2.s[i2]; |
---|
169 | result.w[i3] = s2.w[i2]; |
---|
170 | i2++; |
---|
171 | } |
---|
172 | else if( i2 >= s2.n ) |
---|
173 | { |
---|
174 | result.s[i3] = s1.s[i1]; |
---|
175 | result.w[i3] = s1.w[i1]; |
---|
176 | i1++; |
---|
177 | } |
---|
178 | else if( s1.s[i1] < s2.s[i2] ) |
---|
179 | { |
---|
180 | result.s[i3] = s1.s[i1]; |
---|
181 | result.w[i3] = s1.w[i1]; |
---|
182 | i1++; |
---|
183 | } |
---|
184 | else if( s1.s[i1] == s2.s[i2] ) |
---|
185 | { |
---|
186 | result.s[i3] = s1.s[i1]; |
---|
187 | result.w[i3] = s1.w[i1] + s2.w[i2]; |
---|
188 | i1++; |
---|
189 | i2++; |
---|
190 | } |
---|
191 | else |
---|
192 | { |
---|
193 | result.s[i3] = s2.s[i2]; |
---|
194 | result.w[i3] = s2.w[i2]; |
---|
195 | i2++; |
---|
196 | } |
---|
197 | i3++; |
---|
198 | } |
---|
199 | while( i1 < s1.n || i2 < s2.n ); |
---|
200 | |
---|
201 | result.mu = s1.mu + s2.mu; |
---|
202 | result.pg = s1.pg + s2.pg; |
---|
203 | |
---|
204 | return result; |
---|
205 | } |
---|
206 | |
---|
207 | // ---------------------------------------------------------------------------- |
---|
208 | // multiply the multiplicities of the spectrum numbers of a with m |
---|
209 | // ---------------------------------------------------------------------------- |
---|
210 | |
---|
211 | spectrum operator * ( int k,const spectrum &spec ) |
---|
212 | { |
---|
213 | if( k == 0 ) |
---|
214 | { |
---|
215 | spectrum result; |
---|
216 | |
---|
217 | return result; |
---|
218 | } |
---|
219 | else |
---|
220 | { |
---|
221 | spectrum result( spec ); |
---|
222 | |
---|
223 | result.mu *= k; |
---|
224 | result.pg *= k; |
---|
225 | |
---|
226 | for( int i=0; i<result.n; i++ ) |
---|
227 | { |
---|
228 | result.w[i] *= k; |
---|
229 | } |
---|
230 | |
---|
231 | return result; |
---|
232 | } |
---|
233 | } |
---|
234 | |
---|
235 | // ---------------------------------------------------------------------------- |
---|
236 | // Print a spectrum |
---|
237 | // ---------------------------------------------------------------------------- |
---|
238 | |
---|
239 | #ifdef SEMIC_PRINT |
---|
240 | |
---|
241 | ostream & operator << ( ostream &s,const spectrum &spec ) |
---|
242 | { |
---|
243 | for( int i=0; i<spec.n; i++ ) |
---|
244 | { |
---|
245 | if( i>0 ) |
---|
246 | { |
---|
247 | #ifdef SEMIC_STDOUT |
---|
248 | s << "+"; |
---|
249 | #else |
---|
250 | fprintf( stdout,"+" ); |
---|
251 | #endif |
---|
252 | } |
---|
253 | |
---|
254 | #ifdef SEMIC_STDOUT |
---|
255 | s << spec.w[i] << "*t^"; |
---|
256 | #else |
---|
257 | fprintf( stdout,"%d*t^",spec.w[i] ); |
---|
258 | #endif |
---|
259 | |
---|
260 | s << spec.s[i]; |
---|
261 | } |
---|
262 | |
---|
263 | return s; |
---|
264 | } |
---|
265 | #endif |
---|
266 | |
---|
267 | // ---------------------------------------------------------------------------- |
---|
268 | // Add a subspectrum with multiplicity k (faster than '+') |
---|
269 | // ---------------------------------------------------------------------------- |
---|
270 | |
---|
271 | int spectrum::add_subspectrum( spectrum &a,int k ) |
---|
272 | { |
---|
273 | int i,j; |
---|
274 | for( i=0, j=0; i<n; i++ ) |
---|
275 | { |
---|
276 | if( s[i] == a.s[j] ) |
---|
277 | { |
---|
278 | w[i] += k*a.w[j]; |
---|
279 | j++; |
---|
280 | } |
---|
281 | } |
---|
282 | |
---|
283 | return ( j == a.n ? TRUE : FALSE ); |
---|
284 | } |
---|
285 | |
---|
286 | // ---------------------------------------------------------------------------- |
---|
287 | // set *alpha to the next spectrum number strictly bigger than *alpha |
---|
288 | // returns: TRUE, if such a spectrum number exists |
---|
289 | // FALSE otherwise |
---|
290 | // ---------------------------------------------------------------------------- |
---|
291 | |
---|
292 | int spectrum::next_number( Rational *alpha ) |
---|
293 | { |
---|
294 | int i=0; |
---|
295 | |
---|
296 | while( i < n && *alpha >= s[i] ) |
---|
297 | { |
---|
298 | i++; |
---|
299 | } |
---|
300 | |
---|
301 | if( i < n ) |
---|
302 | { |
---|
303 | *alpha = s[i]; |
---|
304 | return TRUE; |
---|
305 | } |
---|
306 | else |
---|
307 | { |
---|
308 | return FALSE; |
---|
309 | } |
---|
310 | } |
---|
311 | |
---|
312 | // ---------------------------------------------------------------------------- |
---|
313 | // find the next interval on the real line of same length as |
---|
314 | // [*alpha1,*alpha2] having a spectrum number as interval border |
---|
315 | // ---------------------------------------------------------------------------- |
---|
316 | |
---|
317 | int spectrum::next_interval( Rational *alpha1,Rational *alpha2 ) |
---|
318 | { |
---|
319 | Rational zero( 0,1 ); |
---|
320 | Rational a1 = *alpha1; |
---|
321 | Rational a2 = *alpha2; |
---|
322 | Rational d = *alpha2 - *alpha1; |
---|
323 | |
---|
324 | int e1 = this->next_number( &a1 ); |
---|
325 | int e2 = this->next_number( &a2 ); |
---|
326 | |
---|
327 | if( e1 || e2 ) |
---|
328 | { |
---|
329 | Rational d1 = a1 - *alpha1; |
---|
330 | Rational d2 = a2 - *alpha2; |
---|
331 | |
---|
332 | if( d1 < d2 || d2 == zero ) |
---|
333 | { |
---|
334 | *alpha1 = a1; |
---|
335 | *alpha2 = a1 + d; |
---|
336 | } |
---|
337 | else |
---|
338 | { |
---|
339 | *alpha1 = a2 - d; |
---|
340 | *alpha2 = a2; |
---|
341 | } |
---|
342 | return TRUE; |
---|
343 | } |
---|
344 | else |
---|
345 | { |
---|
346 | return FALSE; |
---|
347 | } |
---|
348 | } |
---|
349 | |
---|
350 | // ---------------------------------------------------------------------------- |
---|
351 | // compute the numver of spectrum numbers in the inverval [*alpha1,*alpha2] |
---|
352 | // ---------------------------------------------------------------------------- |
---|
353 | |
---|
354 | int spectrum::numbers_in_interval( Rational &alpha1, |
---|
355 | Rational &alpha2,interval_status status ) |
---|
356 | { |
---|
357 | int count = 0; |
---|
358 | |
---|
359 | for( int i=0; i<n; i++ ) |
---|
360 | { |
---|
361 | if( ( ( status == OPEN || status == LEFTOPEN ) && |
---|
362 | s[i] > alpha1 ) || |
---|
363 | ( ( status == CLOSED || status == RIGHTOPEN ) && |
---|
364 | s[i] >= alpha1 ) ) |
---|
365 | { |
---|
366 | if( ( ( status == OPEN || status == RIGHTOPEN ) && |
---|
367 | s[i] < alpha2 ) || |
---|
368 | ( ( status == CLOSED || status == LEFTOPEN ) && |
---|
369 | s[i] <= alpha2 ) ) |
---|
370 | { |
---|
371 | count += w[i]; |
---|
372 | } |
---|
373 | else |
---|
374 | { |
---|
375 | break; |
---|
376 | } |
---|
377 | } |
---|
378 | } |
---|
379 | |
---|
380 | return count; |
---|
381 | } |
---|
382 | |
---|
383 | // ---------------------------------------------------------------------------- |
---|
384 | // find the maximal integer k such that k*t is semicontinous |
---|
385 | // for the spectrum |
---|
386 | // ---------------------------------------------------------------------------- |
---|
387 | |
---|
388 | int spectrum::mult_spectrum( spectrum &t ) |
---|
389 | { |
---|
390 | spectrum u = *this + t; |
---|
391 | |
---|
392 | Rational alpha1 = -2; |
---|
393 | Rational alpha2 = -1; |
---|
394 | |
---|
395 | int mult=INT_MAX,nthis,nt; |
---|
396 | |
---|
397 | while( u.next_interval( &alpha1,&alpha2 ) ) |
---|
398 | { |
---|
399 | nt = t.numbers_in_interval( alpha1,alpha2,LEFTOPEN ); |
---|
400 | nthis = this->numbers_in_interval( alpha1,alpha2,LEFTOPEN ); |
---|
401 | |
---|
402 | if( nt != 0 ) |
---|
403 | { |
---|
404 | mult = (nthis/nt < mult ? nthis/nt: mult ); |
---|
405 | } |
---|
406 | |
---|
407 | } |
---|
408 | |
---|
409 | return mult; |
---|
410 | } |
---|
411 | |
---|
412 | // ---------------------------------------------------------------------------- |
---|
413 | // find the maximal integer k such that k*t is semicontinous |
---|
414 | // for the spectrum (in the homogeneous sense) |
---|
415 | // ---------------------------------------------------------------------------- |
---|
416 | |
---|
417 | int spectrum::mult_spectrumh( spectrum &t ) |
---|
418 | { |
---|
419 | spectrum u = *this + t; |
---|
420 | |
---|
421 | Rational alpha1 = -2; |
---|
422 | Rational alpha2 = -1; |
---|
423 | |
---|
424 | int mult=INT_MAX,nthis,nt; |
---|
425 | |
---|
426 | while( u.next_interval( &alpha1,&alpha2 ) ) |
---|
427 | { |
---|
428 | nt = t.numbers_in_interval( alpha1,alpha2,LEFTOPEN ); |
---|
429 | nthis = this->numbers_in_interval( alpha1,alpha2,LEFTOPEN ); |
---|
430 | |
---|
431 | if( nt != 0 ) |
---|
432 | { |
---|
433 | mult = (nthis/nt < mult ? nthis/nt: mult ); |
---|
434 | } |
---|
435 | |
---|
436 | nt = t.numbers_in_interval( alpha1,alpha2,OPEN ); |
---|
437 | nthis = this->numbers_in_interval( alpha1,alpha2,OPEN ); |
---|
438 | |
---|
439 | if( nt != 0 ) |
---|
440 | { |
---|
441 | mult = (nthis/nt < mult ? nthis/nt: mult ); |
---|
442 | } |
---|
443 | } |
---|
444 | |
---|
445 | return mult; |
---|
446 | } |
---|
447 | |
---|
448 | // ---------------------------------------------------------------------------- |
---|
449 | // Set the Milnor number |
---|
450 | // ---------------------------------------------------------------------------- |
---|
451 | |
---|
452 | /* |
---|
453 | int spectrum::set_milnor( void ) |
---|
454 | { |
---|
455 | mu = 0; |
---|
456 | |
---|
457 | for( int i=0; i<n; i++ ) |
---|
458 | { |
---|
459 | mu += w[i]; |
---|
460 | } |
---|
461 | |
---|
462 | return mu; |
---|
463 | } |
---|
464 | |
---|
465 | // ---------------------------------------------------------------------------- |
---|
466 | // Set the geometrical genus |
---|
467 | // ---------------------------------------------------------------------------- |
---|
468 | |
---|
469 | int spectrum::set_geometric_genus( void ) |
---|
470 | { |
---|
471 | pg = 0; |
---|
472 | |
---|
473 | for( int i=0; i<n && s[i]<=1; i++ ) |
---|
474 | { |
---|
475 | pg += w[i]; |
---|
476 | } |
---|
477 | return pg; |
---|
478 | } |
---|
479 | */ |
---|
480 | |
---|
481 | #endif /* HAVE_SPECTRUM */ |
---|
482 | // ---------------------------------------------------------------------------- |
---|
483 | // semic.cc |
---|
484 | // end of file |
---|
485 | // ---------------------------------------------------------------------------- |
---|