[35aab3] | 1 | // emacs edit mode for this file is -*- C++ -*- |
---|
| 2 | |
---|
| 3 | /**************************************** |
---|
| 4 | * Computer Algebra System SINGULAR * |
---|
| 5 | ****************************************/ |
---|
| 6 | /* |
---|
| 7 | * ABSTRACT - The FGLM-Algorithm |
---|
| 8 | * Implementation of number-vectors for the fglm algorithm. |
---|
| 9 | * (See fglm.cc). Based on a letter-envelope implementation, mainly |
---|
| 10 | * written to be used by the fglm algorithm. Hence they are |
---|
| 11 | * specialized for this purpose. |
---|
| 12 | */ |
---|
| 13 | |
---|
[16f511] | 14 | #ifdef HAVE_CONFIG_H |
---|
[ba5e9e] | 15 | #include "singularconfig.h" |
---|
[16f511] | 16 | #endif /* HAVE_CONFIG_H */ |
---|
[599326] | 17 | #include <kernel/mod2.h> |
---|
[35aab3] | 18 | |
---|
[6eccc9] | 19 | #ifdef HAVE_FACTORY |
---|
[b1dfaf] | 20 | #include <omalloc/omalloc.h> |
---|
[599326] | 21 | #include <kernel/structs.h> |
---|
[0f401f] | 22 | #include <coeffs/numbers.h> |
---|
[599326] | 23 | #include <kernel/fglm.h> |
---|
| 24 | #include <kernel/fglmvec.h> |
---|
[35aab3] | 25 | |
---|
| 26 | #define PROT(msg) |
---|
| 27 | #define STICKYPROT(msg) if (BTEST1(OPT_PROT)) Print(msg) |
---|
| 28 | #define PROT2(msg,arg) |
---|
| 29 | #define STICKYPROT2(msg,arg) if (BTEST1(OPT_PROT)) Print(msg,arg) |
---|
| 30 | #define fglmASSERT(ignore1,ignore2) |
---|
| 31 | |
---|
| 32 | class fglmVectorRep |
---|
| 33 | { |
---|
| 34 | private: |
---|
[dffcf2d] | 35 | int ref_count; |
---|
| 36 | int N; |
---|
| 37 | number *elems; |
---|
[35aab3] | 38 | public: |
---|
[dffcf2d] | 39 | fglmVectorRep ():ref_count (1), N (0), elems (0) |
---|
| 40 | { |
---|
| 41 | } |
---|
| 42 | fglmVectorRep (int n, number * e):ref_count (1), N (n), elems (e) |
---|
| 43 | { |
---|
| 44 | } |
---|
| 45 | fglmVectorRep (int n):ref_count (1), N (n) |
---|
| 46 | { |
---|
| 47 | fglmASSERT (N >= 0, "illegal Vector representation"); |
---|
| 48 | if(N == 0) |
---|
| 49 | elems = 0; |
---|
| 50 | else |
---|
[35aab3] | 51 | { |
---|
[dffcf2d] | 52 | elems = (number *) omAlloc (N * sizeof (number)); |
---|
| 53 | for(int i = N - 1; i >= 0; i--) |
---|
| 54 | elems[i] = nInit (0); |
---|
[35aab3] | 55 | } |
---|
[dffcf2d] | 56 | } |
---|
| 57 | ~fglmVectorRep () |
---|
| 58 | { |
---|
| 59 | if(N > 0) |
---|
[35aab3] | 60 | { |
---|
[dffcf2d] | 61 | for(int i = N - 1; i >= 0; i--) |
---|
| 62 | nDelete (elems + i); |
---|
| 63 | omFreeSize ((ADDRESS) elems, N * sizeof (number)); |
---|
[35aab3] | 64 | } |
---|
[dffcf2d] | 65 | } |
---|
[35aab3] | 66 | |
---|
[dffcf2d] | 67 | fglmVectorRep *clone () const |
---|
| 68 | { |
---|
| 69 | if(N > 0) |
---|
[35aab3] | 70 | { |
---|
[dffcf2d] | 71 | number *elems_clone; |
---|
| 72 | elems_clone = (number *) omAlloc (N * sizeof (number)); |
---|
| 73 | for(int i = N - 1; i >= 0; i--) |
---|
| 74 | elems_clone[i] = nCopy (elems[i]); |
---|
| 75 | return new fglmVectorRep (N, elems_clone); |
---|
[35aab3] | 76 | } |
---|
[dffcf2d] | 77 | else |
---|
| 78 | return new fglmVectorRep (N, 0); |
---|
| 79 | } |
---|
| 80 | BOOLEAN deleteObject () |
---|
| 81 | { |
---|
| 82 | return --ref_count == 0; |
---|
| 83 | } |
---|
| 84 | fglmVectorRep *copyObject () |
---|
| 85 | { |
---|
| 86 | ref_count++; |
---|
| 87 | return this; |
---|
| 88 | } |
---|
| 89 | int refcount () const |
---|
| 90 | { |
---|
| 91 | return ref_count; |
---|
| 92 | } |
---|
| 93 | BOOLEAN isUnique () const |
---|
| 94 | { |
---|
| 95 | return ref_count == 1; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | int size () const |
---|
| 99 | { |
---|
| 100 | return N; |
---|
| 101 | } |
---|
| 102 | int isZero () const |
---|
| 103 | { |
---|
| 104 | int k; |
---|
| 105 | for(k = N; k > 0; k--) |
---|
| 106 | if(!nIsZero (getconstelem (k))) |
---|
| 107 | return 0; |
---|
| 108 | return 1; |
---|
| 109 | } |
---|
| 110 | int numNonZeroElems () const |
---|
| 111 | { |
---|
| 112 | int num = 0; |
---|
| 113 | int k; |
---|
| 114 | for(k = N; k > 0; k--) |
---|
| 115 | if(!nIsZero (getconstelem (k))) |
---|
| 116 | num++; |
---|
| 117 | return num; |
---|
| 118 | } |
---|
| 119 | void setelem (int i, number n) |
---|
| 120 | { |
---|
| 121 | fglmASSERT (0 < i && i <= N, "setelem: wrong index"); |
---|
| 122 | nDelete (elems + i - 1); |
---|
| 123 | elems[i - 1] = n; |
---|
| 124 | } |
---|
| 125 | number ejectelem (int i, number n) |
---|
| 126 | { |
---|
| 127 | fglmASSERT (isUnique (), "should only be called if unique!"); |
---|
| 128 | number temp = elems[i - 1]; |
---|
| 129 | elems[i - 1] = n; |
---|
| 130 | return temp; |
---|
| 131 | } |
---|
| 132 | number & getelem (int i) |
---|
| 133 | { |
---|
| 134 | fglmASSERT (0 < i && i <= N, "getelem: wrong index"); |
---|
| 135 | return elems[i - 1]; |
---|
| 136 | } |
---|
[bc2606] | 137 | number getconstelem (int i) const |
---|
[dffcf2d] | 138 | { |
---|
| 139 | fglmASSERT (0 < i && i <= N, "getconstelem: wrong index"); |
---|
| 140 | return elems[i - 1]; |
---|
| 141 | } |
---|
| 142 | friend class fglmVector; |
---|
[35aab3] | 143 | }; |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | ///-------------------------------------------------------------------------------- |
---|
| 147 | /// Implementation of class fglmVector |
---|
| 148 | ///-------------------------------------------------------------------------------- |
---|
| 149 | |
---|
[dffcf2d] | 150 | fglmVector::fglmVector (fglmVectorRep * r):rep (r) |
---|
| 151 | { |
---|
| 152 | } |
---|
[35aab3] | 153 | |
---|
[dffcf2d] | 154 | fglmVector::fglmVector ():rep (new fglmVectorRep ()) |
---|
| 155 | { |
---|
| 156 | } |
---|
[35aab3] | 157 | |
---|
[dffcf2d] | 158 | fglmVector::fglmVector (int size):rep (new fglmVectorRep (size)) |
---|
| 159 | { |
---|
| 160 | } |
---|
[35aab3] | 161 | |
---|
[dffcf2d] | 162 | fglmVector::fglmVector (int size, int basis):rep (new fglmVectorRep (size)) |
---|
[35aab3] | 163 | { |
---|
[dffcf2d] | 164 | rep->setelem (basis, nInit (1)); |
---|
[35aab3] | 165 | } |
---|
| 166 | |
---|
[dffcf2d] | 167 | fglmVector::fglmVector (const fglmVector & v) |
---|
[35aab3] | 168 | { |
---|
[dffcf2d] | 169 | rep = v.rep->copyObject (); |
---|
[35aab3] | 170 | } |
---|
| 171 | |
---|
[dffcf2d] | 172 | fglmVector::~fglmVector () |
---|
[35aab3] | 173 | { |
---|
[dffcf2d] | 174 | if(rep->deleteObject ()) |
---|
| 175 | delete rep; |
---|
[35aab3] | 176 | } |
---|
| 177 | |
---|
| 178 | #ifndef HAVE_EXPLICIT_CONSTR |
---|
[dffcf2d] | 179 | void fglmVector::mac_constr (const fglmVector & v) |
---|
[35aab3] | 180 | { |
---|
[dffcf2d] | 181 | rep = v.rep->copyObject (); |
---|
[35aab3] | 182 | } |
---|
| 183 | |
---|
[dffcf2d] | 184 | void fglmVector::mac_constr_i (int size) |
---|
[35aab3] | 185 | { |
---|
[dffcf2d] | 186 | rep = new fglmVectorRep (size); |
---|
[35aab3] | 187 | } |
---|
| 188 | |
---|
[dffcf2d] | 189 | void fglmVector::clearelems () |
---|
[35aab3] | 190 | { |
---|
[dffcf2d] | 191 | if(rep->deleteObject ()) |
---|
| 192 | delete rep; |
---|
[35aab3] | 193 | } |
---|
| 194 | #endif |
---|
| 195 | |
---|
[dffcf2d] | 196 | void fglmVector::makeUnique () |
---|
[35aab3] | 197 | { |
---|
[dffcf2d] | 198 | if(rep->refcount () != 1) |
---|
| 199 | { |
---|
| 200 | rep->deleteObject (); |
---|
| 201 | rep = rep->clone (); |
---|
| 202 | } |
---|
[35aab3] | 203 | } |
---|
| 204 | |
---|
[dffcf2d] | 205 | int fglmVector::size () const |
---|
[35aab3] | 206 | { |
---|
[dffcf2d] | 207 | return rep->size (); |
---|
[35aab3] | 208 | } |
---|
| 209 | |
---|
[dffcf2d] | 210 | int fglmVector::numNonZeroElems () const |
---|
[35aab3] | 211 | { |
---|
[dffcf2d] | 212 | return rep->numNonZeroElems (); |
---|
[35aab3] | 213 | } |
---|
| 214 | |
---|
| 215 | void |
---|
[dffcf2d] | 216 | fglmVector::nihilate (const number fac1, const number fac2, |
---|
| 217 | const fglmVector v) |
---|
| 218 | { |
---|
| 219 | int i; |
---|
| 220 | int vsize = v.size (); |
---|
| 221 | number term1, term2; |
---|
| 222 | fglmASSERT (vsize <= rep->size (), "v has to be smaller oder equal"); |
---|
| 223 | if(rep->isUnique ()) |
---|
| 224 | { |
---|
| 225 | for(i = vsize; i > 0; i--) |
---|
| 226 | { |
---|
| 227 | term1 = nMult (fac1, rep->getconstelem (i)); |
---|
| 228 | term2 = nMult (fac2, v.rep->getconstelem (i)); |
---|
| 229 | rep->setelem (i, nSub (term1, term2)); |
---|
| 230 | nDelete (&term1); |
---|
| 231 | nDelete (&term2); |
---|
[35aab3] | 232 | } |
---|
[dffcf2d] | 233 | for(i = rep->size (); i > vsize; i--) |
---|
| 234 | { |
---|
| 235 | rep->setelem (i, nMult (fac1, rep->getconstelem (i))); |
---|
| 236 | } |
---|
| 237 | } |
---|
| 238 | else |
---|
| 239 | { |
---|
| 240 | number *newelems; |
---|
| 241 | newelems = (number *) omAlloc (rep->size () * sizeof (number)); |
---|
| 242 | for(i = vsize; i > 0; i--) |
---|
[35aab3] | 243 | { |
---|
[dffcf2d] | 244 | term1 = nMult (fac1, rep->getconstelem (i)); |
---|
| 245 | term2 = nMult (fac2, v.rep->getconstelem (i)); |
---|
| 246 | newelems[i - 1] = nSub (term1, term2); |
---|
| 247 | nDelete (&term1); |
---|
| 248 | nDelete (&term2); |
---|
[35aab3] | 249 | } |
---|
[dffcf2d] | 250 | for(i = rep->size (); i > vsize; i--) |
---|
| 251 | { |
---|
| 252 | newelems[i - 1] = nMult (fac1, rep->getconstelem (i)); |
---|
| 253 | } |
---|
| 254 | rep->deleteObject (); |
---|
| 255 | rep = new fglmVectorRep (rep->size (), newelems); |
---|
| 256 | } |
---|
[35aab3] | 257 | } |
---|
| 258 | |
---|
[dffcf2d] | 259 | fglmVector & fglmVector::operator = (const fglmVector & v) |
---|
[35aab3] | 260 | { |
---|
[dffcf2d] | 261 | if(this != &v) |
---|
| 262 | { |
---|
| 263 | if(rep->deleteObject ()) |
---|
| 264 | delete rep; |
---|
| 265 | rep = v.rep->copyObject (); |
---|
| 266 | } |
---|
| 267 | return *this; |
---|
[35aab3] | 268 | } |
---|
| 269 | |
---|
[dffcf2d] | 270 | int fglmVector::operator == (const fglmVector & v) |
---|
[35aab3] | 271 | { |
---|
[dffcf2d] | 272 | if(rep->size () == v.rep->size ()) |
---|
| 273 | { |
---|
| 274 | if(rep == v.rep) |
---|
| 275 | return 1; |
---|
| 276 | else |
---|
| 277 | { |
---|
| 278 | int i; |
---|
| 279 | for(i = rep->size (); i > 0; i--) |
---|
| 280 | if(!nEqual (rep->getconstelem (i), v.rep->getconstelem (i))) |
---|
| 281 | return 0; |
---|
| 282 | return 1; |
---|
[35aab3] | 283 | } |
---|
[dffcf2d] | 284 | } |
---|
| 285 | return 0; |
---|
[35aab3] | 286 | } |
---|
| 287 | |
---|
[dffcf2d] | 288 | int fglmVector::operator != (const fglmVector & v) |
---|
[35aab3] | 289 | { |
---|
[dffcf2d] | 290 | return !(*this == v); |
---|
[35aab3] | 291 | } |
---|
| 292 | |
---|
[dffcf2d] | 293 | int fglmVector::isZero () |
---|
[35aab3] | 294 | { |
---|
[dffcf2d] | 295 | return rep->isZero (); |
---|
[35aab3] | 296 | } |
---|
| 297 | |
---|
[dffcf2d] | 298 | int fglmVector::elemIsZero (int i) |
---|
[35aab3] | 299 | { |
---|
[dffcf2d] | 300 | return nIsZero (rep->getconstelem (i)); |
---|
[35aab3] | 301 | } |
---|
| 302 | |
---|
[dffcf2d] | 303 | fglmVector & fglmVector::operator += (const fglmVector & v) |
---|
[35aab3] | 304 | { |
---|
[dffcf2d] | 305 | fglmASSERT (size () == v.size (), "incompatible vectors"); |
---|
| 306 | // ACHTUNG : Das Verhalten hier mit gcd genau ueberpruefen! |
---|
| 307 | int i; |
---|
| 308 | if(rep->isUnique ()) |
---|
| 309 | { |
---|
| 310 | for(i = rep->size (); i > 0; i--) |
---|
| 311 | rep->setelem (i, nAdd (rep->getconstelem (i), v.rep->getconstelem (i))); |
---|
| 312 | } |
---|
| 313 | else |
---|
| 314 | { |
---|
| 315 | int n = rep->size (); |
---|
| 316 | number *newelems; |
---|
| 317 | newelems = (number *) omAlloc (n * sizeof (number)); |
---|
| 318 | for(i = n; i > 0; i--) |
---|
| 319 | newelems[i - 1] = nAdd (rep->getconstelem (i), v.rep->getconstelem (i)); |
---|
| 320 | rep->deleteObject (); |
---|
| 321 | rep = new fglmVectorRep (n, newelems); |
---|
| 322 | } |
---|
| 323 | return *this; |
---|
[35aab3] | 324 | } |
---|
| 325 | |
---|
[dffcf2d] | 326 | fglmVector & fglmVector::operator -= (const fglmVector & v) |
---|
[35aab3] | 327 | { |
---|
[dffcf2d] | 328 | fglmASSERT (size () == v.size (), "incompatible vectors"); |
---|
| 329 | int i; |
---|
| 330 | if(rep->isUnique ()) |
---|
| 331 | { |
---|
| 332 | for(i = rep->size (); i > 0; i--) |
---|
| 333 | rep->setelem (i, nSub (rep->getconstelem (i), v.rep->getconstelem (i))); |
---|
| 334 | } |
---|
| 335 | else |
---|
| 336 | { |
---|
| 337 | int n = rep->size (); |
---|
| 338 | number *newelems; |
---|
| 339 | newelems = (number *) omAlloc (n * sizeof (number)); |
---|
| 340 | for(i = n; i > 0; i--) |
---|
| 341 | newelems[i - 1] = nSub (rep->getconstelem (i), v.rep->getconstelem (i)); |
---|
| 342 | rep->deleteObject (); |
---|
| 343 | rep = new fglmVectorRep (n, newelems); |
---|
| 344 | } |
---|
| 345 | return *this; |
---|
[35aab3] | 346 | } |
---|
| 347 | |
---|
[dffcf2d] | 348 | fglmVector & fglmVector::operator *= (const number & n) |
---|
[35aab3] | 349 | { |
---|
[dffcf2d] | 350 | int s = rep->size (); |
---|
| 351 | int i; |
---|
| 352 | if(!rep->isUnique ()) |
---|
| 353 | { |
---|
| 354 | number *temp; |
---|
| 355 | temp = (number *) omAlloc (s * sizeof (number)); |
---|
| 356 | for(i = s; i > 0; i--) |
---|
| 357 | temp[i - 1] = nMult (rep->getconstelem (i), n); |
---|
| 358 | rep->deleteObject (); |
---|
| 359 | rep = new fglmVectorRep (s, temp); |
---|
| 360 | } |
---|
| 361 | else |
---|
| 362 | { |
---|
| 363 | for(i = s; i > 0; i--) |
---|
| 364 | rep->setelem (i, nMult (rep->getconstelem (i), n)); |
---|
| 365 | } |
---|
| 366 | return *this; |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | fglmVector & fglmVector::operator /= (const number & n) |
---|
| 370 | { |
---|
| 371 | int s = rep->size (); |
---|
| 372 | int i; |
---|
| 373 | if(!rep->isUnique ()) |
---|
| 374 | { |
---|
| 375 | number *temp; |
---|
| 376 | temp = (number *) omAlloc (s * sizeof (number)); |
---|
| 377 | for(i = s; i > 0; i--) |
---|
[35aab3] | 378 | { |
---|
[dffcf2d] | 379 | temp[i - 1] = nDiv (rep->getconstelem (i), n); |
---|
| 380 | nNormalize (temp[i - 1]); |
---|
[35aab3] | 381 | } |
---|
[dffcf2d] | 382 | rep->deleteObject (); |
---|
| 383 | rep = new fglmVectorRep (s, temp); |
---|
| 384 | } |
---|
| 385 | else |
---|
| 386 | { |
---|
| 387 | for(i = s; i > 0; i--) |
---|
[35aab3] | 388 | { |
---|
[dffcf2d] | 389 | rep->setelem (i, nDiv (rep->getconstelem (i), n)); |
---|
| 390 | nNormalize (rep->getelem (i)); |
---|
[35aab3] | 391 | } |
---|
[dffcf2d] | 392 | } |
---|
| 393 | return *this; |
---|
[35aab3] | 394 | } |
---|
| 395 | |
---|
[dffcf2d] | 396 | fglmVector operator - (const fglmVector & v) |
---|
[35aab3] | 397 | { |
---|
[dffcf2d] | 398 | fglmVector temp (v.size ()); |
---|
| 399 | int i; |
---|
| 400 | number n; |
---|
| 401 | for(i = v.size (); i > 0; i--) |
---|
| 402 | { |
---|
| 403 | n = nCopy (v.getconstelem (i)); |
---|
| 404 | n = nNeg (n); |
---|
| 405 | temp.setelem (i, n); |
---|
| 406 | } |
---|
| 407 | return temp; |
---|
[35aab3] | 408 | } |
---|
| 409 | |
---|
[dffcf2d] | 410 | fglmVector operator + (const fglmVector & lhs, const fglmVector & rhs) |
---|
[35aab3] | 411 | { |
---|
[dffcf2d] | 412 | fglmVector temp = lhs; |
---|
| 413 | temp += rhs; |
---|
| 414 | return temp; |
---|
[35aab3] | 415 | } |
---|
| 416 | |
---|
[dffcf2d] | 417 | fglmVector operator - (const fglmVector & lhs, const fglmVector & rhs) |
---|
[35aab3] | 418 | { |
---|
[dffcf2d] | 419 | fglmVector temp = lhs; |
---|
| 420 | temp -= rhs; |
---|
| 421 | return temp; |
---|
[35aab3] | 422 | } |
---|
| 423 | |
---|
[dffcf2d] | 424 | fglmVector operator * (const fglmVector & v, const number n) |
---|
[35aab3] | 425 | { |
---|
[dffcf2d] | 426 | fglmVector temp = v; |
---|
| 427 | temp *= n; |
---|
| 428 | return temp; |
---|
[35aab3] | 429 | } |
---|
| 430 | |
---|
[dffcf2d] | 431 | fglmVector operator * (const number n, const fglmVector & v) |
---|
[35aab3] | 432 | { |
---|
[dffcf2d] | 433 | fglmVector temp = v; |
---|
| 434 | temp *= n; |
---|
| 435 | return temp; |
---|
[35aab3] | 436 | } |
---|
| 437 | |
---|
[dffcf2d] | 438 | number & fglmVector::getelem (int i) |
---|
[35aab3] | 439 | { |
---|
[dffcf2d] | 440 | makeUnique (); |
---|
| 441 | return rep->getelem (i); |
---|
[35aab3] | 442 | } |
---|
| 443 | |
---|
[bc2606] | 444 | number fglmVector::getconstelem (int i) const |
---|
[35aab3] | 445 | { |
---|
[dffcf2d] | 446 | return rep->getconstelem (i); |
---|
[35aab3] | 447 | } |
---|
| 448 | |
---|
[dffcf2d] | 449 | void fglmVector::setelem (int i, number & n) |
---|
| 450 | { |
---|
| 451 | makeUnique (); |
---|
| 452 | rep->setelem (i, n); |
---|
| 453 | n = n_Init (0, currRing->cf); |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | number fglmVector::gcd () const |
---|
| 457 | { |
---|
| 458 | int i = rep->size (); |
---|
| 459 | BOOLEAN found = FALSE; |
---|
| 460 | BOOLEAN gcdIsOne = FALSE; |
---|
| 461 | number theGcd; |
---|
| 462 | number current; |
---|
| 463 | while(i > 0 && !found) |
---|
| 464 | { |
---|
| 465 | current = rep->getconstelem (i); |
---|
| 466 | if(!nIsZero (current)) |
---|
| 467 | { |
---|
| 468 | theGcd = nCopy (current); |
---|
| 469 | found = TRUE; |
---|
| 470 | if(!nGreaterZero (theGcd)) |
---|
| 471 | { |
---|
| 472 | theGcd = nNeg (theGcd); |
---|
| 473 | } |
---|
| 474 | if(nIsOne (theGcd)) |
---|
| 475 | gcdIsOne = TRUE; |
---|
[35aab3] | 476 | } |
---|
[dffcf2d] | 477 | i--; |
---|
| 478 | } |
---|
| 479 | if(found) |
---|
| 480 | { |
---|
| 481 | while(i > 0 && !gcdIsOne) |
---|
| 482 | { |
---|
| 483 | current = rep->getconstelem (i); |
---|
| 484 | if(!nIsZero (current)) |
---|
| 485 | { |
---|
| 486 | number temp = nGcd (theGcd, current, currRing); |
---|
| 487 | nDelete (&theGcd); |
---|
| 488 | theGcd = temp; |
---|
| 489 | if(nIsOne (theGcd)) |
---|
| 490 | gcdIsOne = TRUE; |
---|
| 491 | } |
---|
| 492 | i--; |
---|
[35aab3] | 493 | } |
---|
[dffcf2d] | 494 | } |
---|
| 495 | else |
---|
| 496 | theGcd = nInit (0); |
---|
| 497 | return theGcd; |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | number fglmVector::clearDenom () |
---|
| 501 | { |
---|
| 502 | number theLcm = nInit (1); |
---|
| 503 | BOOLEAN isZero = TRUE; |
---|
| 504 | int i; |
---|
| 505 | for(i = size (); i > 0; i--) |
---|
| 506 | { |
---|
| 507 | if(!nIsZero (rep->getconstelem (i))) |
---|
| 508 | { |
---|
| 509 | isZero = FALSE; |
---|
| 510 | number temp = n_Lcm (theLcm, rep->getconstelem (i), currRing->cf); |
---|
| 511 | nDelete (&theLcm); |
---|
| 512 | theLcm = temp; |
---|
[35aab3] | 513 | } |
---|
[dffcf2d] | 514 | } |
---|
| 515 | if(isZero) |
---|
| 516 | { |
---|
| 517 | nDelete (&theLcm); |
---|
| 518 | theLcm = nInit (0); |
---|
| 519 | } |
---|
| 520 | else |
---|
| 521 | { |
---|
| 522 | if(!nIsOne (theLcm)) |
---|
| 523 | { |
---|
| 524 | *this *= theLcm; |
---|
| 525 | for(i = size (); i > 0; i--) |
---|
| 526 | { |
---|
| 527 | nNormalize (rep->getelem (i)); |
---|
| 528 | } |
---|
[35aab3] | 529 | } |
---|
[dffcf2d] | 530 | } |
---|
| 531 | return theLcm; |
---|
[35aab3] | 532 | } |
---|
| 533 | |
---|
| 534 | #endif |
---|
| 535 | // ---------------------------------------------------------------------------- |
---|
| 536 | // Local Variables: *** |
---|
| 537 | // compile-command: "make Singular" *** |
---|
| 538 | // page-delimiter: "^\\(\\|//!\\)" *** |
---|
| 539 | // fold-internal-margins: nil *** |
---|
| 540 | // End: *** |
---|