GiNaC  1.8.0
indexed.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_INDEXED_H
24 #define GINAC_INDEXED_H
25 
26 #include "exprseq.h"
27 #include "wildcard.h"
28 
29 #include <map>
30 
31 namespace GiNaC {
32 
33 class scalar_products;
34 class symmetry;
35 
39 class indexed : public exprseq
40 {
42 
43  friend ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indices, const scalar_products & sp);
44  friend ex simplify_indexed_product(const ex & e, exvector & free_indices, exvector & dummy_indices, const scalar_products & sp);
45  friend bool reposition_dummy_indices(ex & e, exvector & variant_dummy_indices, exvector & moved_indices);
46 
47  // other constructors
48 public:
53  indexed(const ex & b);
54 
60  indexed(const ex & b, const ex & i1);
61 
68  indexed(const ex & b, const ex & i1, const ex & i2);
69 
77  indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3);
78 
87  indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3, const ex & i4);
88 
97  indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2);
98 
108  indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2, const ex & i3);
109 
120  indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2, const ex & i3, const ex & i4);
121 
128  indexed(const ex & b, const exvector & iv);
129 
137  indexed(const ex & b, const symmetry & symm, const exvector & iv);
138 
139  // internal constructors
140  indexed(const symmetry & symm, const exprseq & es);
141  indexed(const symmetry & symm, const exvector & v);
142  indexed(const symmetry & symm, exvector && v);
143 
144  // functions overriding virtual functions from base classes
145 public:
146  unsigned precedence() const override {return 55;}
147  bool info(unsigned inf) const override;
148  ex eval() const override;
149  ex real_part() const override;
150  ex imag_part() const override;
151  exvector get_free_indices() const override;
152 
154  void archive(archive_node& n) const override;
156  void read_archive(const archive_node& n, lst& syms) override;
157 protected:
158  ex derivative(const symbol & s) const override;
159  ex thiscontainer(const exvector & v) const override;
160  ex thiscontainer(exvector && v) const override;
161  unsigned return_type() const override;
162  return_type_t return_type_tinfo() const override { return op(0).return_type_tinfo(); }
163  ex expand(unsigned options = 0) const override;
164 
165  // new virtual functions which can be overridden by derived classes
166  // none
167 
168  // non-virtual functions in this class
169 public:
172  bool all_index_values_are(unsigned inf) const;
173 
175  exvector get_indices() const;
176 
178  exvector get_dummy_indices() const;
179 
183  exvector get_dummy_indices(const indexed & other) const;
184 
187  bool has_dummy_index_for(const ex & i) const;
188 
190  ex get_symmetry() const {return symtree;}
191 
192 protected:
193  void printindices(const print_context & c, unsigned level) const;
194  void print_indexed(const print_context & c, const char *openbrace, const char *closebrace, unsigned level) const;
195  void do_print(const print_context & c, unsigned level) const;
196  void do_print_latex(const print_latex & c, unsigned level) const;
197  void do_print_tree(const print_tree & c, unsigned level) const;
198  void validate() const;
199 
200  // member variables
201 protected:
203 };
205 
206 
207 class spmapkey {
208 public:
209  spmapkey() : dim(wild()) {}
210  spmapkey(const ex & v1, const ex & v2, const ex & dim = wild());
211 
212  bool operator==(const spmapkey &other) const;
213  bool operator<(const spmapkey &other) const;
214 
215  void debugprint() const;
216 
217 protected:
218  ex v1, v2, dim;
219 };
220 
221 typedef std::map<spmapkey, ex> spmap;
222 
228 public:
230  void add(const ex & v1, const ex & v2, const ex & sp);
231 
233  void add(const ex & v1, const ex & v2, const ex & dim, const ex & sp);
234 
238  void add_vectors(const lst & l, const ex & dim = wild());
239 
241  void clear();
242 
243  bool is_defined(const ex & v1, const ex & v2, const ex & dim) const;
244  ex evaluate(const ex & v1, const ex & v2, const ex & dim) const;
245  void debugprint() const;
246 
247 protected:
248  spmap spm; /*< Map from defined scalar product pairs to their values */
249 };
250 
251 
252 // utility functions
253 
256 
260 
263 ex rename_dummy_indices_uniquely(exvector & va, const ex & b, bool modify_va = false);
264 
266 ex rename_dummy_indices_uniquely(const ex & a, const ex & b);
267 
269 ex rename_dummy_indices_uniquely(const exvector & va, const exvector & vb, const ex & b);
270 
273 lst rename_dummy_indices_uniquely(const exvector & va, const exvector & vb);
274 
284 ex expand_dummy_sum(const ex & e, bool subs_idx = false);
285 
286 } // namespace GiNaC
287 
288 #endif // ndef GINAC_INDEXED_H
exvector get_indices() const
Return a vector containing the object&#39;s indices.
Definition: indexed.cpp:423
exvector get_all_dummy_indices(const ex &e)
Returns all dummy indices from the exvector.
Definition: indexed.cpp:1435
Helper class for storing information about known scalar products which are to be automatically replac...
Definition: indexed.h:227
This class describes the symmetry of a group of indices.
Definition: symmetry.h:38
exset syms
Definition: factor.cpp:2434
ex op(size_t i) const override
Return operand/member at position i.
Definition: container.h:295
exvector get_all_dummy_indices_safely(const ex &e)
More reliable version of the form.
Definition: indexed.cpp:1394
void debugprint() const
Definition: indexed.cpp:1343
void print_indexed(const print_context &c, const char *openbrace, const char *closebrace, unsigned level) const
Definition: indexed.cpp:207
void validate() const
Check whether all indices are of class idx and validate the symmetry tree.
Definition: indexed.cpp:368
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
Definition: indexed.h:146
void archive(archive_node &n) const override
Save (a.k.a.
Definition: indexed.cpp:155
Definition: add.cpp:38
unsigned return_type() const override
Definition: indexed.cpp:323
ex evaluate(const ex &v1, const ex &v2, const ex &dim) const
Return value of defined scalar product pair.
Definition: indexed.cpp:1378
ex get_symmetry() const
Return symmetry properties.
Definition: indexed.h:190
void add(const ex &v1, const ex &v2, const ex &sp)
Register scalar product pair and its value.
Definition: indexed.cpp:1348
exvector get_free_indices() const override
Return a vector containing the free indices of an expression.
Definition: indexed.cpp:457
Interface to GiNaC&#39;s wildcard objects.
bool all_index_values_are(unsigned inf) const
Check whether all index values have a certain property.
Definition: indexed.cpp:246
void clear()
Clear all registered scalar products.
Definition: indexed.cpp:1366
exvector get_dummy_indices() const
Return a vector containing the dummy indices of the object, if any.
Definition: indexed.cpp:429
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
Definition: indexed.cpp:132
Context for latex-parsable output.
Definition: print.h:122
void do_print_tree(const print_tree &c, unsigned level) const
Definition: indexed.cpp:229
friend ex simplify_indexed(const ex &e, exvector &free_indices, exvector &dummy_indices, const scalar_products &sp)
Simplify indexed expression, return list of free indices.
Definition: indexed.cpp:1044
This class holds an indexed expression.
Definition: indexed.h:39
bool has_dummy_index_for(const ex &i) const
Check whether the object has an index that forms a dummy index pair with a given index.
Definition: indexed.cpp:446
unsigned options
Definition: factor.cpp:2480
void do_print(const print_context &c, unsigned level) const
Definition: indexed.cpp:219
To distinguish between different kinds of non-commutative objects.
Definition: registrar.h:43
Definition of GiNaC&#39;s exprseq.
ex imag_part() const override
Definition: indexed.cpp:306
ex expand_dummy_sum(const ex &e, bool subs_idx)
This function returns the given expression with expanded sums for all dummy index summations...
Definition: indexed.cpp:1541
std::vector< ex > exvector
Definition: basic.h:46
void debugprint() const
Definition: indexed.cpp:1383
ex eval() const override
Perform automatic non-interruptive term rewriting rules.
Definition: indexed.cpp:263
void printindices(const print_context &c, unsigned level) const
Definition: indexed.cpp:165
ex thiscontainer(const exvector &v) const override
Definition: indexed.cpp:313
void do_print_latex(const print_latex &c, unsigned level) const
Definition: indexed.cpp:224
bool info(unsigned inf) const override
Information about the object.
Definition: indexed.cpp:239
return_type_t return_type_tinfo() const
Definition: ex.h:231
return_type_t return_type_tinfo() const override
Definition: indexed.h:162
size_t n
Definition: factor.cpp:1463
ex real_part() const override
Definition: indexed.cpp:299
Base class for print_contexts.
Definition: print.h:102
static ex symm(const ex &e, exvector::const_iterator first, exvector::const_iterator last, bool asymmetric)
Definition: symmetry.cpp:485
ex wild(unsigned label=0)
Create a wildcard object with the specified label.
Definition: wildcard.h:72
indexed(const ex &b)
Construct indexed object with no index.
Definition: indexed.cpp:64
ex derivative(const symbol &s) const override
Implementation of ex::diff() for an indexed object always returns 0.
Definition: indexed.cpp:388
friend bool reposition_dummy_indices(ex &e, exvector &variant_dummy_indices, exvector &moved_indices)
Raise/lower dummy indices in a single indexed objects to canonicalize their variance.
Definition: indexed.cpp:618
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
Definition: archive.h:48
Lightweight wrapper for GiNaC&#39;s symbolic objects.
Definition: ex.h:72
lst rename_dummy_indices_uniquely(const exvector &va, const exvector &vb)
Similar to above, where va and vb are the same and the return value is a list of two lists for substi...
Definition: indexed.cpp:1460
Basic CAS symbol.
Definition: symbol.h:38
Wrapper template for making GiNaC classes out of STL containers.
Definition: container.h:73
bool operator==(const spmapkey &other) const
Definition: indexed.cpp:1315
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
Definition: registrar.h:153
bool is_defined(const ex &v1, const ex &v2, const ex &dim) const
Check whether scalar product pair is defined.
Definition: indexed.cpp:1372
GINAC_DECLARE_UNARCHIVER(add)
void add_vectors(const lst &l, const ex &dim=wild())
Register list of vectors.
Definition: indexed.cpp:1358
size_t c
Definition: factor.cpp:770
friend ex simplify_indexed_product(const ex &e, exvector &free_indices, exvector &dummy_indices, const scalar_products &sp)
Simplify product of indexed expressions (commutative, noncommutative and simple squares), return list of free indices.
Definition: indexed.cpp:779
ex expand(unsigned options=0) const override
Expand expression, i.e.
Definition: indexed.cpp:331
bool operator<(const spmapkey &other) const
Definition: indexed.cpp:1327
Context for tree-like output for debugging.
Definition: print.h:146
ex symtree
Index symmetry (tree of symmetry objects)
Definition: indexed.h:202
std::map< spmapkey, ex > spmap
Definition: indexed.h:221

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