This class defines objects which represent chains as finite sequences of elements identified by integral numbers with coefficients in a given Euclidean domain.
More...
|
| chain () |
| The default constructor. More...
|
|
| chain (const chain< euclidom > &c) |
| The copy constructor. More...
|
|
chain< euclidom > & | operator= (const chain< euclidom > &c) |
| The assignment operator. More...
|
|
| ~chain () |
| The destructor. More...
|
|
int_t | size () const |
| Returns the size of the chain, that is, the number of elements with non-zero coefficients. More...
|
|
bool | empty () const |
| Returns true if the chain is empty (zero), false otherwise. More...
|
|
euclidom | getcoefficient (int_t n=-1) const |
| Finds and returns the coefficient in front of the given element. More...
|
|
int_t | findnumber (int_t n) const |
| Find the position of an element with the given identifier. More...
|
|
euclidom | coef (int_t i) const |
| Returns the coefficient in front of the i-th element in the chain. More...
|
|
int_t | num (int_t i) const |
| Returns the number (identifier) of the i-th element in the chain. More...
|
|
bool | contains_non_invertible () const |
| Determines if the chain contains a non-invertible coefficient. More...
|
|
int_t | findbest (chain< euclidom > *table=NULL) const |
| Finds the best element in the chain for reduction, that is, the element with minimal value of delta. More...
|
|
chain< euclidom > & | add (int_t n, euclidom e) |
| Adds an element algebraically to the chain. More...
|
|
chain< euclidom > & | remove (int_t n) |
| Removes an element with the given identifier from the chain. More...
|
|
chain< euclidom > & | add (const chain< euclidom > &other, euclidom e, int_t number=-1, chain< euclidom > *table=NULL) |
| Adds one chain to another with a given coefficient. More...
|
|
chain< euclidom > & | swap (chain< euclidom > &other, int_t number=-1, int_t othernumber=-1, chain< euclidom > *table=NULL) |
| Swaps one chain with another. More...
|
|
chain< euclidom > & | take (chain< euclidom > &c) |
| Takes data from another chain. Destroys the other chain. More...
|
|
chain< euclidom > & | multiply (euclidom e, int_t number=-1) |
| Multiplies one or all the coefficients in the chain by the given number. More...
|
|
outputstream & | show (outputstream &out, const char *label=NULL) const |
| Shows the chain to the output stream. More...
|
|
std::ostream & | show (std::ostream &out, const char *label=NULL) const |
| Shows the chain to the standard output stream. More...
|
|
template<class euclidom>
class chomp::homology::chain< euclidom >
This class defines objects which represent chains as finite sequences of elements identified by integral numbers with coefficients in a given Euclidean domain.
Definition at line 93 of file chains.h.
template<class euclidom >
Adds one chain to another with a given coefficient.
If the chain is a row of a matrix, then its number and the table of columns must be given for proper modification. If this is a column, its number and rows(?) must be given.
Definition at line 598 of file chains.h.
600{
601
602
603 if ((e == 0) || !other.
len)
604 return *this;
605
606
609 euclidom *bigetab = new euclidom [tablen];
610 if (!bigntab || !bigetab)
611 throw "Not enough memory to add chains.";
612
613
614
615 int_t i = 0, j = 0, k = 0;
616
617
618 while ((i <
len) || (j < other.
len))
619 {
620
622 {
623 bigntab [k] = other.
_n [j];
624 bigetab [k] = e * other.
_e [j];
625 ++ j;
626 if (table)
627 {
628 table [bigntab [k]].
add (number,
629 bigetab [k]);
630 }
631 ++ k;
632 }
633
634 else if ((j >= other.
len) || (
_n [i] < other.
_n [j]))
635 {
636 bigntab [k] =
_n [i];
637 bigetab [k] =
_e [i];
638 ++ i;
639 ++ k;
640 }
641
642 else if (
_n [i] > other.
_n [j])
643 {
644 bigntab [k] = other.
_n [j];
645 bigetab [k] = e * other.
_e [j];
646 ++ j;
647 if (table)
648 {
649 table [bigntab [k]].
add (number,
650 bigetab [k]);
651 }
652 ++ k;
653 }
654 else
655 {
656 bigntab [k] =
_n [i];
657 euclidom addelem = e * other.
_e [j];
658 ++ j;
659 bigetab [k] =
_e [i] + addelem;
660 ++ i;
661 if (!(bigetab [k] == 0))
662 {
663 if (table)
664 {
665 table [bigntab [k]].
add (number,
666 addelem);
667 }
668 ++ k;
669 }
670 else if (table)
671 {
672 table [bigntab [k]].
remove (number);
673 }
674 }
675 }
676
677
678 if ((k !=
len) || (k == tablen))
679 {
681 {
684 }
685 }
686
687
688 if ((k ==
len) && (k != tablen))
689 {
691 {
692 _n [i] = bigntab [i];
693 _e [i] = bigetab [i];
694 }
695 delete [] bigntab;
696 delete [] bigetab;
697 return *this;
698 }
699
700
701 if (k == 0)
702 {
704 delete [] bigntab;
705 delete [] bigetab;
706 return *this;
707 }
708
709
710 if (k != tablen)
711 {
713 _e =
new euclidom [k];
715 throw "Cannot shorten a sum of chains.";
718 {
719 _n [i] = bigntab [i];
720 _e [i] = bigetab [i];
721 }
722 delete [] bigntab;
723 delete [] bigetab;
724 }
725
726
727 else
728 {
732 }
733
734 return *this;
735}
chain< euclidom > & remove(int_t n)
Removes an element with the given identifier from the chain.
chain< euclidom > & add(int_t n, euclidom e)
Adds an element algebraically to the chain.
template<class euclidom >
Finds the best element in the chain for reduction, that is, the element with minimal value of delta.
If the given table is given, then additionally an element with the shortest chain length in the table is searched for. Returns the actual index of this element in the chain (not its identifier) or -1 if the chain is empty (zero).
Definition at line 358 of file chains.h.
359{
360
362 return -1;
364 return 0;
365
366
367 int_t best_delta =
_e [0]. delta ();
369
370
371
372 for (
int_t i = 1; (i <
len) && (best_delta > 1); ++ i)
373 {
374
375 int_t this_delta =
_e [i]. delta ();
376
377
378 if (this_delta < best_delta)
379 {
380 best_delta = this_delta;
381 best_i = i;
382 }
383 }
384
385
386 if (!table)
387 return best_i;
388
389
390
392 for (
int_t i = best_i + 1; i <
len; ++ i)
393 {
394 if (
_e [i]. delta () != best_delta)
395 continue;
397 if (best_length > this_length)
398 {
399 best_length = this_length;
400 best_i = i;
401 }
402 }
403
404 return best_i;
405}
int_t size() const
Returns the size of the chain, that is, the number of elements with non-zero coefficients.
template<class euclidom >
Swaps one chain with another.
If the chain is a row of a matrix, then its number, the number of the other row and the table of columns must be given for proper modification; if this is a column, its number and rows(?) must be given
Definition at line 738 of file chains.h.
740{
741
745
746 if (!table)
747 return *this;
748
749
752 while ((i <
len) || (j < other.
len))
753 {
754
757 n = other.
_n [j ++];
758 else if (j >= other.
len)
760 else if (
_n [i] < other.
_n [j])
762 else if (other.
_n [j] <
_n [i])
763 n = other.
_n [j ++];
764 else
765 {
767 ++ j;
768
769
770
771 }
772
773
775 }
776
777 return *this;
778}
chain< euclidom > & swapnumbers(int_t number1, int_t number2)
Swaps two numbers (identifiers) in the chain.
void swapelements(type &x, type &y)
A simple template for swapping two elements with the use of a temporary variable of the same type and...
References chomp::homology::swapelements().