1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
|
// ideal_stuff.cc
// implementation of the special ideal features needed by the IP-algorithms
#ifndef IDEAL_STUFF_CC
#define IDEAL_STUFF_CC
#include "ideal.h"
////////////////////// elimination stuff ///////////////////////////////////
ideal& ideal::eliminate()
{
// eliminates the generators of the ideal involving elimination variables
// with respect to w
if(w.number_of_elimination_variables()<=0)
// elimination unnecessary
return *this;
list_iterator iter;
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
// Simply iterate over the generator list and delete the elements involving
// elimination variables.
// There is no need to change the done/undone or the reduced/unreduced mark of
// an element.
iter.set_to_list(generators);
while((iter.is_at_end())==FALSE)
{
binomial& bin=iter.get_element();
if(bin.involves_elimination_variables(w)==TRUE)
{
iter.delete_element();
size--;
}
else
{
bin.drop_elimination_variables(w);
iter.next();
}
}
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
// Iterate over the generator lists and check whether the elements involve
// elimination variables.
// As the set of support variables can be changed by the elimination, the
// elements that are not deleted are first moved to the aux_list and then
// reinserted according to their new support.
// The elimination variables are droppd while reinserting.
// In general, elimination is done only once. The time needed for this is
// linear in the number of generators (in the Groebner basis). The elimination
// itself is therefore very fast in comparison to the Groebner basis
// computation needed for it... So we renounce to a complicated optimization
// of this procedure (the support information is not used). In fact, tests
// show that elimination time is really negligible.
// elimination
for(int i=0;i<Number_of_Lists;i++)
{
iter.set_to_list(generators[i]);
while((iter.is_at_end())==FALSE)
{
binomial& bin=iter.get_element();
if(bin.involves_elimination_variables(w)==TRUE)
{
iter.delete_element();
size--;
}
else
{
aux_list._insert(bin);
iter.extract_element();
// As the generators are reinserted later, we do not decrement the
// size (and so do not need to increment it during reinsertion).
}
}
}
// reinsertion
iter.set_to_list(aux_list);
while(iter.is_at_end()==FALSE)
{
binomial& bin=iter.get_element();
bin.drop_elimination_variables(w);
generators[bin.head_support%Number_of_Lists].insert(bin);
// size is not incremented, see above...
iter.extract_element();
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
// finally adapt term ordering
w.convert_to_weighted_ordering();
return *this;
}
ideal& ideal::pseudo_eliminate()
{
if(w.number_of_weighted_variables()<=0)
{
cerr<<"WARNING: ideal& ideal::pseudo_eliminate():\n"
"cannot be performed without weighted variables"<<endl;
return *this;
}
list_iterator iter;
int last_weighted_variable=w.number_of_weighted_variables()-1;
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
// Simply iterate over the generator list and delete the elements involving
// the last weighted variable.
// There is no need to change the done/undone or the reduced/unreduced mark of
// an element.
iter.set_to_list(generators);
while(iter.is_at_end()==FALSE)
{
binomial& bin=iter.get_element();
if(bin[last_weighted_variable]!=0)
// weighted variable to drop is involved in bin
{
iter.delete_element();
size--;
}
else
{
bin.drop_last_weighted_variable(w);
iter.next();
}
}
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
// Iterate over the generator lists and check whether the elements involve
// the last weighted variable.
// As the set of support variables can be changed by the pseudo-elimination,
// the elements that are not deleted are first moved to the aux_list and then
// reinserted according to their new support.
// The last weight variable is dropped while reinserting.
// For the time needed by this function see the remarks for ideal::eliminate().
for(int i=0;i<Number_of_Lists;i++)
{
iter.set_to_list(generators[i]);
while((iter.is_at_end())==FALSE)
{
binomial& bin=iter.get_element();
if(bin[last_weighted_variable]!=0)
{
iter.delete_element();
size--;
}
else
{
aux_list._insert(bin);
iter.extract_element();
// As the generators are reinserted later, we do not decrement the
// size (and so do not need to increment it during reinsertion).
}
}
}
iter.set_to_list(aux_list);
while(iter.is_at_end()==FALSE)
{
binomial& bin=iter.get_element();
bin.drop_last_weighted_variable(w);
generators[bin.head_support%Number_of_Lists].insert(bin);
// size is not incremented, see above...
iter.extract_element();
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
// finally adapt term ordering
w.delete_last_weighted_variable();
return *this;
}
/////////////////// management of the term ordering /////////////////////////
ideal& ideal::change_term_ordering_to(const term_ordering& _w)
{
// first check compatibility
if((w.number_of_weighted_variables()+w.number_of_elimination_variables())!=
(_w.number_of_weighted_variables()+_w.number_of_elimination_variables()))
{
cerr<<"WARNING: ideal& ideal::change_term_ordering_to"
"(const term_ordering&):\nincompatibility detected, term ordering not"
"changed."<<endl;
return *this;
}
// change term ordering
w=_w;
list_iterator iter;
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
// Simply iterate over the generator list. Because the change of the term
// ordering, the "done" and "reduced" marks of the elements have to be deleted.
iter.set_to_list(generators);
while((iter.is_at_end())==FALSE)
{
(iter.get_element()).adapt_to_term_ordering(w);
iter.mark_element_undone();
iter.mark_element_head_unreduced();
iter.next();
}
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
// As head and tail might have to be exchanged, the elements are first moved to
// the aux_list and then reinserted according to their new head.
for(int i=0;i<Number_of_Lists;i++)
{
iter.set_to_list(generators[i]);
while((iter.is_at_end())==FALSE)
{
binomial& bin=iter.get_element();
if(bin.adapt_to_term_ordering(w)==-1)
// head and tail exchanged
{
aux_list._insert(bin);
iter.extract_element();
// As the generators are reinserted later, we do not decrement the
// size (and so do not need to increment it during reinsertion).
}
else
{
// Although the S-pairs of the remaining elements have already been
// computed once, the "done" marks have to be deleted: With a new
// term ordering, the results of the S-pair reduction can change -
// as well as the interreduction results.
iter.mark_element_undone();
iter.mark_element_head_unreduced();
iter.next();
}
}
}
// reinsertion
iter.set_to_list(aux_list);
while(iter.is_at_end()==FALSE)
{
binomial& bin=iter.get_element();
generators[bin.head_support%Number_of_Lists].insert(bin);
// size is not incremented, see above...
iter.extract_element();
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
return *this;
}
/////////// manipulation of the variables ///////////////////////////////////
ideal& ideal::swap_variables_unsafe(const int& i, const int& j)
{
// first check arguments
if((i<0) || (i>=w.number_of_weighted_variables())
|| (j<0) || (j>=w.number_of_weighted_variables()))
{
cout<<"WARNING: ideal::swap_variables(const int&, const int&)\n "
"or ideal::swap_variables_unsafe(const int&, const int&):\n"
"index out of range"<<endl;
return *this;
}
if(i==j)
return(*this);
// special case to avoid unnecessary overhead
list_iterator iter;
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
iter.set_to_list(generators);
while((iter.is_at_end())==FALSE)
{
(iter.get_element()).swap_variables(i,j);
iter.next();
}
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
// As head_support and tail_support are manipulated, the elements are first
// moved to the aux_list and then reinserted according to their new head.
// But head and tail are not adapted to the new term ordering induced by
// the change of the variable order - this is only done in the "safe"
// routine swap_variables(const int&, const int&).
for(int l=0;l<Number_of_Lists;l++)
{
iter.set_to_list(generators[l]);
while((iter.is_at_end())==FALSE)
{
binomial& bin=iter.get_element();
bin.swap_variables(i,j);
aux_list._insert(bin);
iter.extract_element();
// As the generators are reinserted later, we do not decrement the
// size (and so do not need to increment it during reinsertion).
}
}
// reinsertion
iter.set_to_list(aux_list);
while(iter.is_at_end()==FALSE)
{
binomial& bin=iter.get_element();
generators[bin.head_support%Number_of_Lists].insert(bin);
// size is not incremented, see above...
iter.extract_element();
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
// finally adapt term ordering
w.swap_weights(i,j);
return *this;
}
ideal& ideal::swap_variables(const int& i, const int& j)
{
swap_variables_unsafe(i,j);
change_term_ordering_to(w);
// This rebuilds the list structure...
return *this;
}
ideal& ideal::flip_variable_unsafe(const int& i)
{
// first check argument
if((i<0) || (i>=w.number_of_weighted_variables()))
{
cout<<"WARNING: ideal::flip_variables(const int&):\n"
"argument out of range, nothing done"<<endl;
return *this;
}
list_iterator iter;
#ifdef NO_SUPPORT_DRIVEN_METHODS_EXTENDED
iter.set_to_list(generators);
while((iter.is_at_end())==FALSE)
{
(iter.get_element()).flip_variable(i);
iter.next();
}
#endif // NO_SUPPORT_DRIVEN_METHODS_EXTENDED
#ifdef SUPPORT_DRIVEN_METHODS_EXTENDED
// As head_support and tail_support can change, the elements are first moved
// to the aux_list and then reinserted according to their new head.
for(int l=0;l<Number_of_Lists;l++)
{
iter.set_to_list(generators[l]);
while((iter.is_at_end())==FALSE)
{
binomial& bin=iter.get_element();
bin.flip_variable(i);
aux_list._insert(bin);
iter.extract_element();
// As the generators are reinserted later, we do not decrement the
// size (and so do not need to increment it during reinsertion).
}
}
// reinsertion
iter.set_to_list(aux_list);
while(iter.is_at_end()==FALSE)
{
binomial& bin=iter.get_element();
generators[bin.head_support%Number_of_Lists].insert(bin);
iter.extract_element();
// size is not incremented, see above...
}
#endif // SUPPORT_DRIVEN_METHODS_EXTENDED
return *this;
}
#endif // IDEAL_STUFF_CC
|