Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:24:11

0001 // -*- C++ -*-
0002 /*
0003  * Monomial.h
0004  *  Contains declaration of the class Monomial and associated types and operators
0005  *  Created on: Jul 7, 2010
0006  *  Author: Malin Sjodahl
0007  */
0008 
0009 #ifndef COLORFULL_Monomial_h
0010 #define COLORFULL_Monomial_h
0011 
0012 #include "types.h"
0013 
0014 
0015 namespace ColorFull {
0016 
0017 
0018 /// A class to contain the factor of form TR^a*Nc^b*CF^c*int_part*cnum_part,
0019 /// where the powers a, b and c may be negative.
0020 /// A default Monomial is defined to be 1, and has int_part and cnum_part=1.
0021 /// A 0-Monomial has int_part=0.
0022 /// A polynomial is a sum of Monomials.
0023 class Monomial {
0024 public:
0025 
0026     /// Default constructor sets int_part=cnum_part=1, and pow_Nc=pow_TR=pow_CF=0.
0027     Monomial(){
0028         pow_TR=pow_Nc=pow_CF=0;
0029         int_part=1;
0030         cnum_part=1.0;
0031     }
0032 
0033     /// Constructor using a double.
0034     /// The cnum_part member is set to contain the value.
0035     Monomial( double dnum ){
0036         pow_TR=pow_Nc=pow_CF=0;
0037         int_part=1;
0038         cnum_part.real(dnum);
0039     }
0040 
0041     /// Constructor using an int.
0042     /// The int_part member is set to contain the value.
0043     Monomial( int num ){
0044         pow_TR=pow_Nc=pow_CF=0;
0045         int_part=num;
0046         cnum_part=1.0;
0047     }
0048 
0049     /// Constructor taking a string as argument.
0050     /// The argument should be of the form in for example
0051     /// -(20*TR^5)/Nc or -20 TR^(5)/Nc or 20 / TR^(-5)Nc^(1) CF^(3).
0052     /// NOTE: All spaces and * are ignored, except in  "*(-1)" and *-1, which
0053     /// is understood as (*-1).
0054     /// EVERYTHING standing after / is
0055     /// divided with, whereas everything standing before is multiplied with.
0056     /// Parentheses are ignored unless they appear in powers,
0057     /// i.e., directly after ^.
0058     /// No spaces are allowed inside the powers.
0059     /// If the string contains no info or is empty the Monomial is put to 1,
0060     /// pow_TR = pow_Nc = pow_CF = 0, int_part = 1, cnum_part = 1.0.
0061     /// (Expanded Mathematica 8 expressions are in this form.)
0062     Monomial( std::string str );
0063 
0064     /// Power of TR in Monomial.
0065     int pow_TR;
0066 
0067     /// Power of the number of colors.
0068     int pow_Nc;
0069 
0070     /// Power of CF=TR (Nc^2-1)/Nc.
0071     int pow_CF;
0072 
0073     /// Integer multiplying the monomial, can be 0.
0074     int int_part;
0075 
0076     /// Complex number multiplying the monomial.
0077     cnum cnum_part;
0078 
0079     /// Take the complex conjugate.
0080     /// Note that this changes the Monomial itself.
0081     void conjugate() {
0082         cnum_part=conj( cnum_part );
0083     }
0084 
0085     /// Function for reading in the Monomial from the file filename,
0086     /// uses Monomial_of_str.
0087     void read_in_Monomial( std::string filename );
0088 
0089 
0090     /// Function for writing out the Monomial to a file
0091     /// with name filename.
0092     void write_out_Monomial( std::string filename ) const;
0093 
0094 
0095 private:
0096 
0097     /// Function for makinga a Monomial from a string.
0098     /// The argument should be of the form given in form (for example)
0099     /// -(20*TR^5)/Nc or -20 TR^(5)/Nc or 20 / TR^(-5)Nc^(1) CF^3.
0100     /// NOTE: All spaces and * are ignored, except in  "*(-1)" and *-1, which
0101     /// is understood as (*-1).
0102     /// EVERYTHING standing after / is
0103     /// divided with, whereas everything standing before is multiplied with.
0104     /// Parentheses are ignored unless they appear in powers,
0105     /// i.e, directly after ^.
0106     /// No spaces are allowed inside the powers.
0107     /// If the string contains no information or is empty, the Monomial is set to 1,
0108     /// pow_TR = pow_Nc = pow_CF = 0, int_part = 1, cnum_part = 1.0.
0109     void Monomial_of_str( std::string str );
0110 
0111 
0112 };
0113 
0114 
0115 /// Define the operator << for Monomial
0116 std::ostream& operator<<( std::ostream& out, const Monomial & Mon );
0117 
0118 /// Operator * for Monomial and int.
0119 /// The int_part member is multiplied by i, whereas other
0120 /// members are kept constant.
0121 Monomial operator*( const Monomial & Mon,  const int i );
0122 
0123 /// Operator * for int and Monomial.
0124 /// Returns Mon*i.
0125 Monomial operator*( const int i, const Monomial & Mon );
0126 
0127 /// Operator * for Monomial and cnum. The member Mon.cnum_part
0128 /// is multiplied by c, whereas other members are kept
0129 /// the same.
0130 Monomial operator*( const Monomial & Mon, const cnum c );
0131 
0132 /// Operator * for cnum and Monomial, returns Mon*c.
0133 Monomial operator*( const cnum c, const Monomial & Mon );
0134 
0135 /// Operator * for Monomial and double. The member Mon.cnum_part
0136 /// is multiplied by c, whereas other members are kept
0137 /// the same.
0138 Monomial operator*( const Monomial & Mon, const double d );
0139 
0140 /// Operator * for double and Monomial, returns Mon*d.
0141 Monomial operator*( const double d, const Monomial & Mon );
0142 
0143 /// Operator * for Monomials. The powers, pow_TR, pow_Nc
0144 /// and pow_CF are added, and the numbers int_part and mon
0145 /// are multiplied.
0146 Monomial operator*( const Monomial & Mon1, const Monomial & Mon2 );
0147 
0148 /// Operator *= for Monomial and int.
0149 /// The int_part member is multiplied by i, whereas other
0150 /// members are kept constant.
0151 Monomial operator*=( Monomial & Mon,  const int i );
0152 
0153 /// Operator *= for Monomial and cnum.
0154 /// The cnum_part member is multiplied by c, whereas other
0155 /// members are kept constant.
0156 Monomial operator*=( Monomial & Mon, const cnum c );
0157 
0158 /// Operator *= for Monomial and double.
0159 /// The cnum_part member is multiplied by d, whereas other
0160 /// members are kept constant.
0161 Monomial operator*=( Monomial & Mon, const double d );
0162 
0163 /// Operator *= for Monomials. Mon1 is changed by being multipled with
0164 /// Mon2.
0165 Monomial operator*=( Monomial & Mon1, const Monomial & Mon2);
0166 
0167 /// Operator == for Monomials, all parts must be equal.
0168 /// For the numerical part, an accuracy is used for the ratio.
0169 bool operator==( const Monomial & Mon1, const Monomial & Mon2 );
0170 
0171 /// Define the operator != Monomial. Returns false if Mon1==Mon2,
0172 /// and true otherwise.
0173 bool operator!=( const Monomial & Mon1, const Monomial & Mon2 );
0174 
0175 /// Operator to find the "smallest" of two Monomials.
0176 /// The Monomials are ordered first according to pow_Nc+pow_CF,
0177 /// then according to pow_Nc (for same pow_Nc+pow_CF)
0178 /// then according to int_part*abs(cnum_part), then according to int_part, and finally according to pow_TR.
0179 /// NOTE: this ordering does not agree with ordering according to numerical value.
0180 /// NOTE: If the Monomials are equal, Mon1 is not smaller so false will be returned.
0181 bool operator<( const Monomial & Mon1, const Monomial & Mon2 );
0182 
0183 }
0184 
0185 #endif /* COLORFULL_Monomial_h */