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

Contents of /ginac/idx.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.28 - (hide annotations)
Thu Apr 5 15:45:08 2001 UTC (12 years, 2 months ago) by cbauer
Branch: MAIN
Changes since 1.27: +2 -0 lines
File MIME type: text/plain
- subs() can be used to substitute functions, tensors and indexed objects
- op(0) of an idx object returns the index value; a nice side-effect of
  this is that idx'es no longer all have the same hash value
- added checks for clifford class

1 cbauer 1.1 /** @file idx.h
2     *
3 cbauer 1.5 * Interface to GiNaC's indices. */
4    
5     /*
6 kreckel 1.18 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
7 cbauer 1.2 *
8     * This program is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License as published by
10     * the Free Software Foundation; either version 2 of the License, or
11     * (at your option) any later version.
12     *
13     * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17     *
18     * You should have received a copy of the GNU General Public License
19     * along with this program; if not, write to the Free Software
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21     */
22 cbauer 1.1
23 cbauer 1.2 #ifndef __GINAC_IDX_H__
24     #define __GINAC_IDX_H__
25 cbauer 1.1
26 cbauer 1.11 #include "ex.h"
27 cbauer 1.6
28     namespace GiNaC {
29 cbauer 1.1
30 cbauer 1.19
31 cbauer 1.25 /** This class holds one index of an indexed object. Indices can
32     * theoretically consist of any symbolic expression but they are usually
33     * 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 cbauer 1.1 class idx : public basic
36     {
37 cbauer 1.14 GINAC_DECLARE_REGISTERED_CLASS(idx, basic)
38 cbauer 1.10
39 cbauer 1.14 // other constructors
40 cbauer 1.1 public:
41 cbauer 1.25 /** Construct index with given value and dimension.
42     *
43     * @param v Value of index (numeric or symbolic)
44     * @param dim Dimension of index space (numeric or symbolic)
45     * @return newly constructed index */
46     explicit idx(const ex & v, const ex & dim);
47 cbauer 1.1
48 cbauer 1.14 // functions overriding virtual functions from bases classes
49 cbauer 1.1 public:
50 cbauer 1.14 void printraw(std::ostream & os) const;
51     void printtree(std::ostream & os, unsigned indent) const;
52     void print(std::ostream & os, unsigned upper_precedence=0) const;
53     bool info(unsigned inf) const;
54 cbauer 1.28 unsigned nops() const;
55     ex & let_op(int i);
56 cbauer 1.1 protected:
57 cbauer 1.14 ex subs(const lst & ls, const lst & lr) const;
58 cbauer 1.1
59 cbauer 1.25 // new virtual functions in this class
60 cbauer 1.1 public:
61 cbauer 1.25 /** Check whether the index forms a dummy index pair with another index
62     * of the same type. */
63     virtual bool is_dummy_pair_same_type(const basic & other) const;
64 cbauer 1.1
65 cbauer 1.14 // non-virtual functions in this class
66 cbauer 1.1 public:
67 cbauer 1.25 /** Get value of index. */
68     ex get_value(void) const {return value;}
69 cbauer 1.19
70 cbauer 1.25 /** Check whether the index is numeric. */
71     bool is_numeric(void) const {return is_ex_exactly_of_type(value, numeric);}
72 cbauer 1.19
73 cbauer 1.25 /** Check whether the index is symbolic. */
74     bool is_symbolic(void) const {return !is_ex_exactly_of_type(value, numeric);}
75    
76     /** Get dimension of index space. */
77     ex get_dim(void) const {return dim;}
78    
79     /** Check whether the dimension is numeric. */
80     bool is_dim_numeric(void) const {return is_ex_exactly_of_type(dim, numeric);}
81    
82     /** Check whether the dimension is symbolic. */
83     bool is_dim_symbolic(void) const {return !is_ex_exactly_of_type(dim, numeric);}
84    
85     protected:
86     ex value; /**< Expression that constitutes the index (numeric or symbolic name) */
87     ex dim; /**< Dimension of space (can be symbolic or numeric) */
88     };
89    
90    
91     /** This class holds an index with a variance (co- or contravariant). There
92     * is an associated metric tensor that can be used to raise/lower indices. */
93     class varidx : public idx
94     {
95     GINAC_DECLARE_REGISTERED_CLASS(varidx, idx)
96    
97     // other constructors
98     public:
99     /** Construct index with given value, dimension and variance.
100     *
101     * @param v Value of index (numeric or symbolic)
102     * @param dim Dimension of index space (numeric or symbolic)
103     * @param covariant Make covariant index (default is contravariant)
104     * @return newly constructed index */
105     varidx(const ex & v, const ex & dim, bool covariant = false);
106    
107     // functions overriding virtual functions from bases classes
108     public:
109     void print(std::ostream & os, unsigned upper_precedence=0) const;
110     bool is_dummy_pair_same_type(const basic & other) const;
111    
112     // non-virtual functions in this class
113     public:
114     /** Check whether the index is covariant. */
115 cbauer 1.19 bool is_covariant(void) const {return covariant;}
116    
117 cbauer 1.25 /** Check whether the index is contravariant (not covariant). */
118     bool is_contravariant(void) const {return !covariant;}
119 cbauer 1.1
120 cbauer 1.25 /** Make a new index with the same value but the opposite variance. */
121     ex toggle_variance(void) const;
122 cbauer 1.20
123 cbauer 1.14 // member variables
124 cbauer 1.1 protected:
125 cbauer 1.25 bool covariant; /**< x.mu, default is contravariant: x~mu */
126 cbauer 1.1 };
127    
128 cbauer 1.25
129 cbauer 1.6 // utility functions
130 cbauer 1.25 inline const idx &ex_to_idx(const ex & e)
131 cbauer 1.6 {
132     return static_cast<const idx &>(*e.bp);
133     }
134 cbauer 1.1
135 cbauer 1.25 inline const varidx &ex_to_varidx(const ex & e)
136     {
137     return static_cast<const varidx &>(*e.bp);
138     }
139    
140     /** Check whether two indices form a dummy pair. */
141     bool is_dummy_pair(const idx & i1, const idx & i2);
142    
143     /** Check whether two expressions form a dummy index pair. */
144     bool is_dummy_pair(const ex & e1, const ex & e2);
145 cbauer 1.1
146 cbauer 1.27 /** Given a vector of indices, split them into two vectors, one containing
147     * the free indices, the other containing the dummy indices (numeric
148     * indices are neither free nor dummy ones).
149     *
150     * @param it Pointer to start of index vector
151     * @param itend Pointer to end of index vector
152     * @param out_free Vector of free indices (returned, sorted)
153     * @param out_dummy Vector of dummy indices (returned, sorted) */
154     void find_free_and_dummy(exvector::const_iterator it, exvector::const_iterator itend, exvector & out_free, exvector & out_dummy);
155    
156     /** Given a vector of indices, split them into two vectors, one containing
157     * the free indices, the other containing the dummy indices (numeric
158     * indices are neither free nor dummy ones).
159     *
160     * @param v Index vector
161     * @param out_free Vector of free indices (returned, sorted)
162     * @param out_dummy Vector of dummy indices (returned, sorted) */
163     inline void find_free_and_dummy(const exvector & v, exvector & out_free, exvector & out_dummy)
164     {
165     find_free_and_dummy(v.begin(), v.end(), out_free, out_dummy);
166     }
167    
168     /** Given a vector of indices, find the dummy indices.
169     *
170     * @param v Index vector
171     * @param out_dummy Vector of dummy indices (returned, sorted) */
172     inline void find_dummy_indices(const exvector & v, exvector & out_dummy)
173     {
174     exvector free_indices;
175     find_free_and_dummy(v.begin(), v.end(), free_indices, out_dummy);
176     }
177    
178     /** Count the number of dummy index pairs in an index vector. */
179     inline unsigned count_dummy_indices(const exvector & v)
180     {
181     exvector free_indices, dummy_indices;
182     find_free_and_dummy(v.begin(), v.end(), free_indices, dummy_indices);
183     return dummy_indices.size();
184     }
185    
186     /** Count the number of dummy index pairs in an index vector. */
187     inline unsigned count_free_indices(const exvector & v)
188     {
189     exvector free_indices, dummy_indices;
190     find_free_and_dummy(v.begin(), v.end(), free_indices, dummy_indices);
191     return free_indices.size();
192     }
193    
194     /** Given two index vectors, find those indices that appear in the first
195     * vector but not in the second one (asymmetric set difference). */
196     exvector index_set_difference(const exvector & set1, const exvector & set2);
197 cbauer 1.6
198     } // namespace GiNaC
199 cbauer 1.1
200 cbauer 1.2 #endif // ndef __GINAC_IDX_H__

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