GiNaC 1.8.10
idx.h
Go to the documentation of this file.
1
5/*
6 * GiNaC Copyright (C) 1999-2026 Johannes Gutenberg University Mainz, Germany
7 *
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, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef GINAC_IDX_H
23#define GINAC_IDX_H
24
25#include "ex.h"
26#include "numeric.h"
27
28namespace GiNaC {
29
34class idx : public basic
35{
37
38 // other constructors
39public:
44 explicit idx(const ex & v, const ex & dim);
45
46 // functions overriding virtual functions from base classes
47public:
48 bool info(unsigned inf) const override;
49 size_t nops() const override;
50 ex op(size_t i) const override;
51 ex map(map_function & f) const override;
52 ex evalf() const override;
53 ex subs(const exmap & m, unsigned options = 0) const override;
54 void archive(archive_node& n) const override;
55 void read_archive(const archive_node& n, lst& syms) override;
56protected:
57 ex derivative(const symbol & s) const override;
58 bool match_same_type(const basic & other) const override;
59 unsigned calchash() const override;
60
61 // new virtual functions in this class
62public:
65 virtual bool is_dummy_pair_same_type(const basic & other) const;
66
67 // non-virtual functions in this class
68public:
70 ex get_value() const {return value;}
71
73 bool is_numeric() const {return is_exactly_a<numeric>(value);}
74
76 bool is_symbolic() const {return !is_exactly_a<numeric>(value);}
77
79 ex get_dim() const {return dim;}
80
82 bool is_dim_numeric() const {return is_exactly_a<numeric>(dim);}
83
85 bool is_dim_symbolic() const {return !is_exactly_a<numeric>(dim);}
86
88 ex replace_dim(const ex & new_dim) const;
89
92 ex minimal_dim(const idx & other) const;
93
94protected:
95 void print_index(const print_context & c, unsigned level) const;
96 void do_print(const print_context & c, unsigned level) const;
97 void do_print_csrc(const print_csrc & c, unsigned level) const;
98 void do_print_latex(const print_latex & c, unsigned level) const;
99 void do_print_tree(const print_tree & c, unsigned level) const;
100
101protected:
104};
106
107
110class varidx : public idx
111{
113
114 // other constructors
115public:
121 varidx(const ex & v, const ex & dim, bool covariant = false);
122
123 // functions overriding virtual functions from base classes
124public:
125 bool is_dummy_pair_same_type(const basic & other) const override;
126 void archive(archive_node& n) const override;
127 void read_archive(const archive_node& n, lst& syms) override;
128protected:
129 bool match_same_type(const basic & other) const override;
130
131 // non-virtual functions in this class
132public:
134 bool is_covariant() const {return covariant;}
135
137 bool is_contravariant() const {return !covariant;}
138
140 ex toggle_variance() const;
141
142protected:
143 void do_print(const print_context & c, unsigned level) const;
144 void do_print_tree(const print_tree & c, unsigned level) const;
145
146 // member variables
147protected:
149};
151
152
158class spinidx : public varidx
159{
161
162 // other constructors
163public:
170 spinidx(const ex & v, const ex & dim = 2, bool covariant = false, bool dotted = false);
171
172 // functions overriding virtual functions from base classes
173public:
174 bool is_dummy_pair_same_type(const basic & other) const override;
175 // complex conjugation
176 ex conjugate() const override { return toggle_dot(); }
177 void archive(archive_node& n) const override;
178 void read_archive(const archive_node& n, lst& syms) override;
179protected:
180 bool match_same_type(const basic & other) const override;
181
182 // non-virtual functions in this class
183public:
185 bool is_dotted() const {return dotted;}
186
188 bool is_undotted() const {return !dotted;}
189
192 ex toggle_dot() const;
193
196 ex toggle_variance_dot() const;
197
198protected:
199 void do_print(const print_context & c, unsigned level) const;
200 void do_print_latex(const print_latex & c, unsigned level) const;
201 void do_print_tree(const print_tree & c, unsigned level) const;
202
203 // member variables
204protected:
205 bool dotted;
206};
208
209
210// utility functions
211
213bool is_dummy_pair(const idx & i1, const idx & i2);
214
216bool is_dummy_pair(const ex & e1, const ex & e2);
217
226void find_free_and_dummy(exvector::const_iterator it, exvector::const_iterator itend, exvector & out_free, exvector & out_dummy);
227
235inline void find_free_and_dummy(const exvector & v, exvector & out_free, exvector & out_dummy)
236{
237 find_free_and_dummy(v.begin(), v.end(), out_free, out_dummy);
238}
239
244inline void find_dummy_indices(const exvector & v, exvector & out_dummy)
245{
246 exvector free_indices;
247 find_free_and_dummy(v.begin(), v.end(), free_indices, out_dummy);
248}
249
251inline size_t count_dummy_indices(const exvector & v)
252{
253 exvector free_indices, dummy_indices;
254 find_free_and_dummy(v.begin(), v.end(), free_indices, dummy_indices);
255 return dummy_indices.size();
256}
257
259inline size_t count_free_indices(const exvector & v)
260{
261 exvector free_indices, dummy_indices;
262 find_free_and_dummy(v.begin(), v.end(), free_indices, dummy_indices);
263 return free_indices.size();
264}
265
269ex minimal_dim(const ex & dim1, const ex & dim2);
270
271} // namespace GiNaC
272
273#endif // ndef GINAC_IDX_H
#define GINAC_DECLARE_UNARCHIVER(classname)
Helper macros to register a class with (un)archiving (a.k.a.
Definition archive.h:218
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
Definition archive.h:48
This class holds archived versions of GiNaC expressions (class ex).
Definition archive.h:254
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Definition basic.h:104
Wrapper template for making GiNaC classes out of STL containers.
Definition container.h:72
Lightweight wrapper for GiNaC's symbolic objects.
Definition ex.h:72
This class holds one index of an indexed object.
Definition idx.h:35
ex map(map_function &f) const override
Construct new expression by applying the specified function to all sub-expressions (one level only,...
Definition idx.cpp:254
void print_index(const print_context &c, unsigned level) const
Definition idx.cpp:134
ex derivative(const symbol &s) const override
Implementation of ex::diff() for an index always returns 0.
Definition idx.cpp:402
ex dim
Dimension of space (can be symbolic or numeric)
Definition idx.h:103
void do_print_csrc(const print_csrc &c, unsigned level) const
Definition idx.cpp:162
bool is_dim_numeric() const
Check whether the dimension is numeric.
Definition idx.h:82
unsigned calchash() const override
Compute the hash value of an object and if it makes sense to store it in the objects status_flags,...
Definition idx.cpp:341
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
Definition idx.cpp:371
ex replace_dim(const ex &new_dim) const
Make a new index with the same value but a different dimension.
Definition idx.cpp:458
ex op(size_t i) const override
Return operand/member at position i.
Definition idx.cpp:248
ex value
Expression that constitutes the index (numeric or symbolic name)
Definition idx.h:102
bool match_same_type(const basic &other) const override
Returns true if the attributes of two objects are similar enough for a match.
Definition idx.cpp:280
virtual bool is_dummy_pair_same_type(const basic &other) const
Check whether the index forms a dummy index pair with another index of the same type.
Definition idx.cpp:411
bool info(unsigned inf) const override
Information about the object.
Definition idx.cpp:232
ex get_dim() const
Get dimension of index space.
Definition idx.h:79
void do_print_latex(const print_latex &c, unsigned level) const
Definition idx.cpp:155
bool is_symbolic() const
Check whether the index is symbolic.
Definition idx.h:76
size_t nops() const override
Number of operands/members.
Definition idx.cpp:242
void do_print_tree(const print_tree &c, unsigned level) const
Definition idx.cpp:172
void read_archive(const archive_node &n, lst &syms) override
Load (deserialize) the object from an archive node.
Definition idx.cpp:89
ex minimal_dim(const idx &other) const
Return the minimum of the dimensions of this and another index.
Definition idx.cpp:466
void do_print(const print_context &c, unsigned level) const
Definition idx.cpp:149
ex get_value() const
Get value of index.
Definition idx.h:70
bool is_dim_symbolic() const
Check whether the dimension is symbolic.
Definition idx.h:85
ex evalf() const override
By default, basic::evalf would evaluate the index value but we don't want a.1 to become a.
Definition idx.cpp:366
bool is_numeric() const
Check whether the index is numeric.
Definition idx.h:73
Base class for print_contexts.
Definition print.h:101
Base context for C source output.
Definition print.h:156
Context for latex-parsable output.
Definition print.h:121
Context for tree-like output for debugging.
Definition print.h:145
This class holds a spinor index that can be dotted or undotted and that also has a variance.
Definition idx.h:159
void read_archive(const archive_node &n, lst &syms) override
Load (deserialize) the object from an archive node.
Definition idx.cpp:104
void do_print_latex(const print_latex &c, unsigned level) const
Definition idx.cpp:211
void do_print(const print_context &c, unsigned level) const
Definition idx.cpp:200
ex conjugate() const override
Definition idx.h:176
bool match_same_type(const basic &other) const override
Returns true if the attributes of two objects are similar enough for a match.
Definition idx.cpp:331
bool is_dotted() const
Check whether the index is dotted.
Definition idx.h:185
ex toggle_dot() const
Make a new index with the same value and variance but the opposite dottedness.
Definition idx.cpp:479
bool is_undotted() const
Check whether the index is not dotted.
Definition idx.h:188
bool is_dummy_pair_same_type(const basic &other) const override
Check whether the index forms a dummy index pair with another index of the same type.
Definition idx.cpp:442
void do_print_tree(const print_tree &c, unsigned level) const
Definition idx.cpp:221
bool dotted
Definition idx.h:205
ex toggle_variance_dot() const
Make a new index with the same value but opposite variance and dottedness.
Definition idx.cpp:487
Basic CAS symbol.
Definition symbol.h:38
This class holds an index with a variance (co- or contravariant).
Definition idx.h:111
void read_archive(const archive_node &n, lst &syms) override
Load (deserialize) the object from an archive node.
Definition idx.cpp:97
bool is_dummy_pair_same_type(const basic &other) const override
Check whether the index forms a dummy index pair with another index of the same type.
Definition idx.cpp:431
void do_print(const print_context &c, unsigned level) const
Definition idx.cpp:181
bool match_same_type(const basic &other) const override
Returns true if the attributes of two objects are similar enough for a match.
Definition idx.cpp:304
bool is_covariant() const
Check whether the index is covariant.
Definition idx.h:134
bool covariant
x.mu, default is contravariant: x~mu
Definition idx.h:148
void do_print_tree(const print_tree &c, unsigned level) const
Definition idx.cpp:190
bool is_contravariant() const
Check whether the index is contravariant (not covariant).
Definition idx.h:137
ex toggle_variance() const
Make a new index with the same value but the opposite variance.
Definition idx.cpp:471
Interface to GiNaC's light-weight expression handles.
unsigned options
Definition factor.cpp:2473
size_t n
Definition factor.cpp:1431
size_t c
Definition factor.cpp:756
exset syms
Definition factor.cpp:2427
mvec m
Definition factor.cpp:757
Definition add.cpp:35
ex minimal_dim(const ex &dim1, const ex &dim2)
Return the minimum of two index dimensions.
Definition idx.cpp:559
std::map< ex, ex, ex_is_less > exmap
Definition basic.h:49
size_t count_dummy_indices(const exvector &v)
Count the number of dummy index pairs in an index vector.
Definition idx.h:251
bool is_dummy_pair(const idx &i1, const idx &i2)
Check whether two indices form a dummy pair.
Definition idx.cpp:500
size_t count_free_indices(const exvector &v)
Count the number of dummy index pairs in an index vector.
Definition idx.h:259
void find_dummy_indices(const exvector &v, exvector &out_dummy)
Given a vector of indices, find the dummy indices.
Definition idx.h:244
void find_free_and_dummy(exvector::const_iterator it, exvector::const_iterator itend, exvector &out_free, exvector &out_dummy)
Given a vector of indices, split them into two vectors, one containing the free indices,...
Definition idx.cpp:519
std::vector< ex > exvector
Definition basic.h:47
Makes the interface to the underlying bignum package available.
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
Definition registrar.h:151
Function object for map().
Definition basic.h:84

This page is part of the GiNaC developer's reference. It was generated automatically by doxygen. For an introduction, see the tutorial.