/[GiNaC]/ginac/idx.h
ViewVC logotype

Diff of /ginac/idx.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.24 by kreckel, Wed Feb 28 12:54:52 2001 UTC revision 1.25 by cbauer, Tue Mar 6 17:07:17 2001 UTC
# Line 23  Line 23 
23  #ifndef __GINAC_IDX_H__  #ifndef __GINAC_IDX_H__
24  #define __GINAC_IDX_H__  #define __GINAC_IDX_H__
25    
 #include <string>  
 //#include <vector>  
 #include "basic.h"  
26  #include "ex.h"  #include "ex.h"
27    
28  namespace GiNaC {  namespace GiNaC {
29    
30    
31  /** This class holds one index of an indexed object. Indices can be symbolic  /** This class holds one index of an indexed object. Indices can
32   *  (e.g. "mu", "i") or numeric (unsigned integer), and they can be contravariant   *  theoretically consist of any symbolic expression but they are usually
33   *  (the default) or covariant. */   *  only just a symbol (e.g. "mu", "i") or numeric (integer). Indices belong
34     *  to a space with a certain numeric or symbolic dimension. */
35  class idx : public basic  class idx : public basic
36  {  {
37          GINAC_DECLARE_REGISTERED_CLASS(idx, basic)          GINAC_DECLARE_REGISTERED_CLASS(idx, basic)
38    
39          // other constructors          // other constructors
40  public:  public:
41          explicit idx(bool cov);          /** Construct index with given value and dimension.
42          explicit idx(const std::string & n, bool cov=false);           *
43          explicit idx(const char * n, bool cov=false);           *  @param v Value of index (numeric or symbolic)
44          explicit idx(unsigned v, bool cov=false);           *  @param dim Dimension of index space (numeric or symbolic)
45             *  @return newly constructed index */
46            explicit idx(const ex & v, const ex & dim);
47    
48          // functions overriding virtual functions from bases classes          // functions overriding virtual functions from bases classes
49  public:  public:
# Line 52  public: Line 52  public:
52          void print(std::ostream & os, unsigned upper_precedence=0) const;          void print(std::ostream & os, unsigned upper_precedence=0) const;
53          bool info(unsigned inf) const;          bool info(unsigned inf) const;
54  protected:  protected:
         bool is_equal_same_type(const basic & other) const;  
         unsigned calchash(void) const;  
55          ex subs(const lst & ls, const lst & lr) const;          ex subs(const lst & ls, const lst & lr) const;
56    
57          // new virtual functions which can be overridden by derived classes          // new virtual functions in this class
58  public:  public:
59          virtual bool is_co_contra_pair(const basic & other) const;          /** Check whether the index forms a dummy index pair with another index
60          virtual ex toggle_covariant(void) const;           *  of the same type. */
61            virtual bool is_dummy_pair_same_type(const basic & other) const;
62    
63          // non-virtual functions in this class          // non-virtual functions in this class
64  public:  public:
65          /** Check whether index is symbolic (not numeric). */          /** Get value of index. */
66          bool is_symbolic(void) const {return symbolic;}          ex get_value(void) const {return value;}
67    
68          /** Get numeric value of index. Undefined for symbolic indices. */          /** Check whether the index is numeric. */
69          unsigned get_value(void) const {return value;}          bool is_numeric(void) const {return is_ex_exactly_of_type(value, numeric);}
70    
71          /** Check whether index is covariant (not contravariant). */          /** Check whether the index is symbolic. */
72            bool is_symbolic(void) const {return !is_ex_exactly_of_type(value, numeric);}
73    
74            /** Get dimension of index space. */
75            ex get_dim(void) const {return dim;}
76    
77            /** Check whether the dimension is numeric. */
78            bool is_dim_numeric(void) const {return is_ex_exactly_of_type(dim, numeric);}
79    
80            /** Check whether the dimension is symbolic. */
81            bool is_dim_symbolic(void) const {return !is_ex_exactly_of_type(dim, numeric);}
82    
83            // member variables
84    protected:
85            ex value; /**< Expression that constitutes the index (numeric or symbolic name) */
86            ex dim;   /**< Dimension of space (can be symbolic or numeric) */
87    };
88    
89    
90    /** This class holds an index with a variance (co- or contravariant). There
91     *  is an associated metric tensor that can be used to raise/lower indices. */
92    class varidx : public idx
93    {
94            GINAC_DECLARE_REGISTERED_CLASS(varidx, idx)
95    
96            // other constructors
97    public:
98            /** Construct index with given value, dimension and variance.
99             *
100             *  @param v Value of index (numeric or symbolic)
101             *  @param dim Dimension of index space (numeric or symbolic)
102             *  @param covariant Make covariant index (default is contravariant)
103             *  @return newly constructed index */
104            varidx(const ex & v, const ex & dim, bool covariant = false);
105    
106            // functions overriding virtual functions from bases classes
107    public:
108            void print(std::ostream & os, unsigned upper_precedence=0) const;
109            bool is_dummy_pair_same_type(const basic & other) const;
110    
111            // non-virtual functions in this class
112    public:
113            /** Check whether the index is covariant. */
114          bool is_covariant(void) const {return covariant;}          bool is_covariant(void) const {return covariant;}
115    
116          void setname(const std::string & n) {name=n;}          /** Check whether the index is contravariant (not covariant). */
117          std::string getname(void) const {return name;}          bool is_contravariant(void) const {return !covariant;}
118    
119  private:          /** Make a new index with the same value but the opposite variance. */
120          std::string & autoname_prefix(void);          ex toggle_variance(void) const;
121    
122          // member variables          // member variables
123  protected:  protected:
124          unsigned serial;  /**< Unique serial number for comparing symbolic indices */          bool covariant; /**< x.mu, default is contravariant: x~mu */
         bool symbolic;    /**< Is index symbolic? */  
         std::string name; /**< Symbolic name (if symbolic == true) */  
         unsigned value;   /**< Numeric value (if symbolic == false) */  
         static unsigned next_serial;  
         bool covariant;   /**< x_mu, default is contravariant: x~mu */  
125  };  };
126    
127    
128  // utility functions  // utility functions
129  inline const idx &ex_to_idx(const ex &e)  inline const idx &ex_to_idx(const ex &e)
130  {  {
131          return static_cast<const idx &>(*e.bp);          return static_cast<const idx &>(*e.bp);
132  }  }
133    
134  // global functions  inline const varidx &ex_to_varidx(const ex & e)
135    {
136            return static_cast<const varidx &>(*e.bp);
137    }
138    
139    /** Check whether two indices form a dummy pair. */
140    bool is_dummy_pair(const idx & i1, const idx & i2);
141    
142    /** Check whether two expressions form a dummy index pair. */
143    bool is_dummy_pair(const ex & e1, const ex & e2);
144    
 int canonicalize_indices(exvector & iv, bool antisymmetric=false);  
 exvector idx_intersect(const exvector & iv1, const exvector & iv2);  
 ex permute_free_index_to_front(const exvector & iv3, const exvector & iv2, int * sig);  
 unsigned subs_index_in_exvector(exvector & v, const ex & is, const ex & ir);  
 ex subs_indices(const ex & e, const exvector & idxv_contra, const exvector & idxv_co);  
 unsigned count_index(const ex & e, const ex & i);  
145    
146  } // namespace GiNaC  } // namespace GiNaC
147    

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25

Christian Bauer">Christian Bauer
ViewVC Help
Powered by ViewVC 1.1.15