GiNaC  1.8.0
idx.h
Go to the documentation of this file.
1 
5 /*
6  * GiNaC Copyright (C) 1999-2020 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, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #ifndef GINAC_IDX_H
24 #define GINAC_IDX_H
25 
26 #include "ex.h"
27 #include "numeric.h"
28 
29 namespace GiNaC {
30 
35 class idx : public basic
36 {
38 
39  // other constructors
40 public:
46  explicit idx(const ex & v, const ex & dim);
47 
48  // functions overriding virtual functions from base classes
49 public:
50  bool info(unsigned inf) const override;
51  size_t nops() const override;
52  ex op(size_t i) const override;
53  ex map(map_function & f) const override;
54  ex evalf() const override;
55  ex subs(const exmap & m, unsigned options = 0) const override;
56  void archive(archive_node& n) const override;
57  void read_archive(const archive_node& n, lst& syms) override;
58 protected:
59  ex derivative(const symbol & s) const override;
60  bool match_same_type(const basic & other) const override;
61  unsigned calchash() const override;
62 
63  // new virtual functions in this class
64 public:
67  virtual bool is_dummy_pair_same_type(const basic & other) const;
68 
69  // non-virtual functions in this class
70 public:
72  ex get_value() const {return value;}
73 
75  bool is_numeric() const {return is_exactly_a<numeric>(value);}
76 
78  bool is_symbolic() const {return !is_exactly_a<numeric>(value);}
79 
81  ex get_dim() const {return dim;}
82 
84  bool is_dim_numeric() const {return is_exactly_a<numeric>(dim);}
85 
87  bool is_dim_symbolic() const {return !is_exactly_a<numeric>(dim);}
88 
90  ex replace_dim(const ex & new_dim) const;
91 
94  ex minimal_dim(const idx & other) const;
95 
96 protected:
97  void print_index(const print_context & c, unsigned level) const;
98  void do_print(const print_context & c, unsigned level) const;
99  void do_print_csrc(const print_csrc & c, unsigned level) const;
100  void do_print_latex(const print_latex & c, unsigned level) const;
101  void do_print_tree(const print_tree & c, unsigned level) const;
102 
103 protected:
105  ex dim;
106 };
108 
109 
112 class varidx : public idx
113 {
115 
116  // other constructors
117 public:
124  varidx(const ex & v, const ex & dim, bool covariant = false);
125 
126  // functions overriding virtual functions from base classes
127 public:
128  bool is_dummy_pair_same_type(const basic & other) const override;
129  void archive(archive_node& n) const override;
130  void read_archive(const archive_node& n, lst& syms) override;
131 protected:
132  bool match_same_type(const basic & other) const override;
133 
134  // non-virtual functions in this class
135 public:
137  bool is_covariant() const {return covariant;}
138 
140  bool is_contravariant() const {return !covariant;}
141 
143  ex toggle_variance() const;
144 
145 protected:
146  void do_print(const print_context & c, unsigned level) const;
147  void do_print_tree(const print_tree & c, unsigned level) const;
148 
149  // member variables
150 protected:
151  bool covariant;
152 };
154 
155 
161 class spinidx : public varidx
162 {
164 
165  // other constructors
166 public:
174  spinidx(const ex & v, const ex & dim = 2, bool covariant = false, bool dotted = false);
175 
176  // functions overriding virtual functions from base classes
177 public:
178  bool is_dummy_pair_same_type(const basic & other) const override;
179  // complex conjugation
180  ex conjugate() const override { return toggle_dot(); }
181  void archive(archive_node& n) const override;
182  void read_archive(const archive_node& n, lst& syms) override;
183 protected:
184  bool match_same_type(const basic & other) const override;
185 
186  // non-virtual functions in this class
187 public:
189  bool is_dotted() const {return dotted;}
190 
192  bool is_undotted() const {return !dotted;}
193 
196  ex toggle_dot() const;
197 
200  ex toggle_variance_dot() const;
201 
202 protected:
203  void do_print(const print_context & c, unsigned level) const;
204  void do_print_latex(const print_latex & c, unsigned level) const;
205  void do_print_tree(const print_tree & c, unsigned level) const;
206 
207  // member variables
208 protected:
209  bool dotted;
210 };
212 
213 
214 // utility functions
215 
217 bool is_dummy_pair(const idx & i1, const idx & i2);
218 
220 bool is_dummy_pair(const ex & e1, const ex & e2);
221 
230 void find_free_and_dummy(exvector::const_iterator it, exvector::const_iterator itend, exvector & out_free, exvector & out_dummy);
231 
239 inline void find_free_and_dummy(const exvector & v, exvector & out_free, exvector & out_dummy)
240 {
241  find_free_and_dummy(v.begin(), v.end(), out_free, out_dummy);
242 }
243 
248 inline void find_dummy_indices(const exvector & v, exvector & out_dummy)
249 {
250  exvector free_indices;
251  find_free_and_dummy(v.begin(), v.end(), free_indices, out_dummy);
252 }
253 
255 inline size_t count_dummy_indices(const exvector & v)
256 {
257  exvector free_indices, dummy_indices;
258  find_free_and_dummy(v.begin(), v.end(), free_indices, dummy_indices);
259  return dummy_indices.size();
260 }
261 
263 inline size_t count_free_indices(const exvector & v)
264 {
265  exvector free_indices, dummy_indices;
266  find_free_and_dummy(v.begin(), v.end(), free_indices, dummy_indices);
267  return free_indices.size();
268 }
269 
273 ex minimal_dim(const ex & dim1, const ex & dim2);
274 
275 } // namespace GiNaC
276 
277 #endif // ndef GINAC_IDX_H
GiNaC::varidx::match_same_type
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:306
GiNaC::minimal_dim
ex minimal_dim(const ex &dim1, const ex &dim2)
Return the minimum of two index dimensions.
Definition: idx.cpp:561
GiNaC::spinidx::archive
void archive(archive_node &n) const override
Save (serialize) the object into archive node.
Definition: idx.cpp:126
GiNaC::spinidx::dotted
bool dotted
Definition: idx.h:209
GiNaC::idx::is_dummy_pair_same_type
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:413
GiNaC::idx::match_same_type
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:282
numeric.h
Makes the interface to the underlying bignum package available.
GiNaC::map_function
Function object for map().
Definition: basic.h:85
GiNaC::print_context
Base class for print_contexts.
Definition: print.h:103
GiNaC::spinidx::spinidx
spinidx(const ex &v, const ex &dim=2, bool covariant=false, bool dotted=false)
Construct index with given value, dimension, variance and dot.
Definition: idx.cpp:64
GiNaC::print_csrc
Base context for C source output.
Definition: print.h:158
GiNaC::exvector
std::vector< ex > exvector
Definition: basic.h:46
GiNaC::varidx::is_contravariant
bool is_contravariant() const
Check whether the index is contravariant (not covariant).
Definition: idx.h:140
GiNaC::spinidx::do_print_latex
void do_print_latex(const print_latex &c, unsigned level) const
Definition: idx.cpp:213
GiNaC::idx::is_numeric
bool is_numeric() const
Check whether the index is numeric.
Definition: idx.h:75
GiNaC::idx::read_archive
void read_archive(const archive_node &n, lst &syms) override
Load (deserialize) the object from an archive node.
Definition: idx.cpp:91
GiNaC::archive_node
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
Definition: archive.h:49
GiNaC::idx::get_value
ex get_value() const
Get value of index.
Definition: idx.h:72
GiNaC::varidx::covariant
bool covariant
x.mu, default is contravariant: x~mu
Definition: idx.h:151
GiNaC::idx::subs
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
Definition: idx.cpp:373
GiNaC::spinidx
This class holds a spinor index that can be dotted or undotted and that also has a variance.
Definition: idx.h:162
GiNaC::varidx::do_print
void do_print(const print_context &c, unsigned level) const
Definition: idx.cpp:183
GiNaC::spinidx::is_dummy_pair_same_type
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:444
options
unsigned options
Definition: factor.cpp:2480
GiNaC::GINAC_DECLARE_UNARCHIVER
GINAC_DECLARE_UNARCHIVER(add)
m
mvec m
Definition: factor.cpp:771
GiNaC
Definition: add.cpp:38
syms
exset syms
Definition: factor.cpp:2434
GiNaC::idx::is_symbolic
bool is_symbolic() const
Check whether the index is symbolic.
Definition: idx.h:78
GiNaC::idx::get_dim
ex get_dim() const
Get dimension of index space.
Definition: idx.h:81
GiNaC::idx::idx
idx(const ex &v, const ex &dim)
Construct index with given value and dimension.
Definition: idx.cpp:72
GiNaC::idx::do_print_tree
void do_print_tree(const print_tree &c, unsigned level) const
Definition: idx.cpp:174
GiNaC::idx::dim
ex dim
Dimension of space (can be symbolic or numeric)
Definition: idx.h:105
GiNaC::varidx::varidx
varidx(const ex &v, const ex &dim, bool covariant=false)
Construct index with given value, dimension and variance.
Definition: idx.cpp:60
GINAC_DECLARE_REGISTERED_CLASS
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
Definition: registrar.h:153
GiNaC::idx::is_dim_symbolic
bool is_dim_symbolic() const
Check whether the dimension is symbolic.
Definition: idx.h:87
GiNaC::varidx::is_dummy_pair_same_type
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:433
GiNaC::spinidx::toggle_variance_dot
ex toggle_variance_dot() const
Make a new index with the same value but opposite variance and dottedness.
Definition: idx.cpp:489
GiNaC::count_dummy_indices
size_t count_dummy_indices(const exvector &v)
Count the number of dummy index pairs in an index vector.
Definition: idx.h:255
GiNaC::ex
Lightweight wrapper for GiNaC's symbolic objects.
Definition: ex.h:72
GiNaC::spinidx::do_print
void do_print(const print_context &c, unsigned level) const
Definition: idx.cpp:202
GiNaC::idx::evalf
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:368
GiNaC::spinidx::conjugate
ex conjugate() const override
Definition: idx.h:180
GiNaC::varidx::is_covariant
bool is_covariant() const
Check whether the index is covariant.
Definition: idx.h:137
GiNaC::spinidx::do_print_tree
void do_print_tree(const print_tree &c, unsigned level) const
Definition: idx.cpp:223
GiNaC::spinidx::read_archive
void read_archive(const archive_node &n, lst &syms) override
Load (deserialize) the object from an archive node.
Definition: idx.cpp:106
ex.h
Interface to GiNaC's light-weight expression handles.
GiNaC::count_free_indices
size_t count_free_indices(const exvector &v)
Count the number of dummy index pairs in an index vector.
Definition: idx.h:263
GiNaC::print_latex
Context for latex-parsable output.
Definition: print.h:123
GiNaC::varidx::do_print_tree
void do_print_tree(const print_tree &c, unsigned level) const
Definition: idx.cpp:192
GiNaC::varidx
This class holds an index with a variance (co- or contravariant).
Definition: idx.h:113
GiNaC::idx::op
ex op(size_t i) const override
Return operand/member at position i.
Definition: idx.cpp:250
GiNaC::idx::calchash
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:343
GiNaC::spinidx::match_same_type
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:333
GiNaC::print_tree
Context for tree-like output for debugging.
Definition: print.h:147
GiNaC::idx::do_print_csrc
void do_print_csrc(const print_csrc &c, unsigned level) const
Definition: idx.cpp:164
GiNaC::varidx::read_archive
void read_archive(const archive_node &n, lst &syms) override
Load (deserialize) the object from an archive node.
Definition: idx.cpp:99
GiNaC::container
Wrapper template for making GiNaC classes out of STL containers.
Definition: container.h:73
GiNaC::idx::value
ex value
Expression that constitutes the index (numeric or symbolic name)
Definition: idx.h:104
GiNaC::varidx::toggle_variance
ex toggle_variance() const
Make a new index with the same value but the opposite variance.
Definition: idx.cpp:473
c
size_t c
Definition: factor.cpp:770
GiNaC::find_dummy_indices
void find_dummy_indices(const exvector &v, exvector &out_dummy)
Given a vector of indices, find the dummy indices.
Definition: idx.h:248
GiNaC::exmap
std::map< ex, ex, ex_is_less > exmap
Definition: basic.h:50
GiNaC::idx::derivative
ex derivative(const symbol &s) const override
Implementation of ex::diff() for an index always returns 0.
Definition: idx.cpp:404
GiNaC::idx::print_index
void print_index(const print_context &c, unsigned level) const
Definition: idx.cpp:136
GiNaC::symbol
Basic CAS symbol.
Definition: symbol.h:39
n
size_t n
Definition: factor.cpp:1463
GiNaC::idx::do_print
void do_print(const print_context &c, unsigned level) const
Definition: idx.cpp:151
GiNaC::idx::is_dim_numeric
bool is_dim_numeric() const
Check whether the dimension is numeric.
Definition: idx.h:84
GiNaC::find_free_and_dummy
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:521
GiNaC::basic
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Definition: basic.h:105
GiNaC::idx::map
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:256
GiNaC::idx::archive
void archive(archive_node &n) const override
Save (serialize) the object into archive node.
Definition: idx.cpp:113
GiNaC::spinidx::is_dotted
bool is_dotted() const
Check whether the index is dotted.
Definition: idx.h:189
GiNaC::idx::info
bool info(unsigned inf) const override
Information about the object.
Definition: idx.cpp:234
GiNaC::idx::do_print_latex
void do_print_latex(const print_latex &c, unsigned level) const
Definition: idx.cpp:157
GiNaC::spinidx::is_undotted
bool is_undotted() const
Check whether the index is not dotted.
Definition: idx.h:192
GiNaC::idx::replace_dim
ex replace_dim(const ex &new_dim) const
Make a new index with the same value but a different dimension.
Definition: idx.cpp:460
GiNaC::idx
This class holds one index of an indexed object.
Definition: idx.h:36
GiNaC::is_dummy_pair
bool is_dummy_pair(const idx &i1, const idx &i2)
Check whether two indices form a dummy pair.
Definition: idx.cpp:502
GiNaC::idx::nops
size_t nops() const override
Number of operands/members.
Definition: idx.cpp:244
GiNaC::spinidx::toggle_dot
ex toggle_dot() const
Make a new index with the same value and variance but the opposite dottedness.
Definition: idx.cpp:481
GiNaC::varidx::archive
void archive(archive_node &n) const override
Save (serialize) the object into archive node.
Definition: idx.cpp:120
GiNaC::idx::minimal_dim
ex minimal_dim(const idx &other) const
Return the minimum of the dimensions of this and another index.
Definition: idx.cpp:468

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