]> www.ginac.de Git - ginac.git/blob - ginac/idx.h
- check program is not built until you say "make check"
[ginac.git] / ginac / idx.h
1 /** @file idx.h
2  *
3  *  Interface to GiNaC's indices.
4  *
5  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #ifndef __GINAC_IDX_H__
23 #define __GINAC_IDX_H__
24
25 #include <string>
26 #include <vector>
27 #include <ginac/basic.h>
28
29 class idx : public basic
30 {
31 // member functions
32
33     // default constructor, destructor, copy constructor assignment operator and helpers
34 public:
35     idx();
36     ~idx();
37     idx (idx const & other);
38     idx const & operator=(idx const & other);
39 protected:
40     void copy(idx const & other);
41     void destroy(bool call_parent);
42
43     // other constructors
44 public:
45     explicit idx(bool cov);
46     explicit idx(string const & n, bool cov=false);
47     explicit idx(char const * n, bool cov=false);
48     explicit idx(unsigned const v, bool cov=false); 
49
50     // functions overriding virtual functions from bases classes
51 public:
52     basic * duplicate() const;
53     void printraw(ostream & os) const;
54     void printtree(ostream & os, unsigned indent) const;
55     void print(ostream & os, unsigned upper_precedence=0) const;
56     bool info(unsigned inf) const;
57 protected:
58     int compare_same_type(basic const & other) const;
59     bool is_equal_same_type(basic const & other) const;
60     unsigned calchash(void) const;
61     ex subs(lst const & ls, lst const & lr) const;
62
63     // new virtual functions which can be overridden by derived classes
64 public:
65     virtual bool is_co_contra_pair(basic const & other) const;
66     virtual ex toggle_covariant(void) const;
67
68     // non-virtual functions in this class
69 public:
70     bool is_symbolic(void) const;
71     unsigned get_value(void) const;
72     bool is_covariant(void) const;
73
74     // member variables
75 protected:
76     unsigned serial;
77     bool symbolic;
78     string name;
79     unsigned value;
80     static unsigned next_serial;
81     bool covariant; // x_mu, default is contravariant: x^mu
82 };
83
84 // global constants
85
86 extern const idx some_idx;
87 extern type_info const & typeid_idx;
88
89 // macros
90
91 #define ex_to_idx(X) (static_cast<idx const &>(*(X).bp))
92
93 // other functions
94
95 typedef vector<ex> exvector;
96
97 int canonicalize_indices(exvector & iv, bool antisymmetric=false);
98 exvector idx_intersect(exvector const & iv1, exvector const & iv2);
99 ex permute_free_index_to_front(exvector const & iv3, exvector const & iv2,
100                                bool antisymmetric, int * sig);
101 unsigned subs_index_in_exvector(exvector & v, ex const & is, ex const & ir);
102 ex subs_indices(ex const & e, exvector const & idxv_contra,
103                 exvector const & idxv_co);
104 unsigned count_index(ex const & e, ex const & i);
105
106 #endif // ndef __GINAC_IDX_H__