]> www.ginac.de Git - ginac.git/blob - ginac/idx.h
Hunted down some output bugs. Hope it can be safely piped into Maple now.
[ginac.git] / ginac / idx.h
1 /** @file idx.h
2  *
3  *  Interface to GiNaC's indices. */
4
5 #ifndef _IDX_H_
6 #define _IDX_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "basic.h"
12
13 class idx : public basic
14 {
15 // member functions
16
17     // default constructor, destructor, copy constructor assignment operator and helpers
18 public:
19     idx();
20     ~idx();
21     idx (idx const & other);
22     idx const & operator=(idx const & other);
23 protected:
24     void copy(idx const & other);
25     void destroy(bool call_parent);
26
27     // other constructors
28 public:
29     explicit idx(bool cov);
30     explicit idx(string const & n, bool cov=false);
31     explicit idx(char const * n, bool cov=false);
32     explicit idx(unsigned const v, bool cov=false); 
33
34     // functions overriding virtual functions from bases classes
35 public:
36     basic * duplicate() const;
37     void printraw(ostream & os) const;
38     void printtree(ostream & os, unsigned indent) const;
39     void print(ostream & os, unsigned upper_precedence=0) const;
40     bool info(unsigned inf) const;
41 protected:
42     int compare_same_type(basic const & other) const;
43     bool is_equal_same_type(basic const & other) const;
44     unsigned calchash(void) const;
45     ex subs(lst const & ls, lst const & lr) const;
46
47     // new virtual functions which can be overridden by derived classes
48 public:
49     virtual bool is_co_contra_pair(basic const & other) const;
50     virtual ex toggle_covariant(void) const;
51
52     // non-virtual functions in this class
53 public:
54     bool is_symbolic(void) const;
55     unsigned get_value(void) const;
56     bool is_covariant(void) const;
57
58     // member variables
59 protected:
60     unsigned serial;
61     bool symbolic;
62     string name;
63     unsigned value;
64     static unsigned next_serial;
65     bool covariant; // x_mu, default is contravariant: x^mu
66 };
67
68 // global constants
69
70 extern const idx some_idx;
71 extern type_info const & typeid_idx;
72
73 // macros
74
75 #define ex_to_idx(X) (static_cast<idx const &>(*(X).bp))
76
77 // other functions
78
79 typedef vector<ex> exvector;
80
81 int canonicalize_indices(exvector & iv, bool antisymmetric=false);
82 exvector idx_intersect(exvector const & iv1, exvector const & iv2);
83 ex permute_free_index_to_front(exvector const & iv3, exvector const & iv2,
84                                bool antisymmetric, int * sig);
85 unsigned subs_index_in_exvector(exvector & v, ex const & is, ex const & ir);
86 ex subs_indices(ex const & e, exvector const & idxv_contra,
87                 exvector const & idxv_co);
88 unsigned count_index(ex const & e, ex const & i);
89
90 #endif // ndef _IDX_H_