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
wildcard.h
Interface to GiNaC's wildcard objects.
GiNaC::indexed::get_dummy_indices
exvector get_dummy_indices() const
Return a vector containing the dummy indices of the object, if any.
Definition: indexed.cpp:429
GiNaC::spmapkey::v1
ex v1
Definition: indexed.h:218
GiNaC::indexed::get_free_indices
exvector get_free_indices() const override
Return a vector containing the free indices of an expression.
Definition: indexed.cpp:457
GiNaC::wild
ex wild(unsigned label=0)
Create a wildcard object with the specified label.
Definition: wildcard.h:72
exprseq.h
Definition of GiNaC's exprseq.
GiNaC::indexed::indexed
indexed(const ex &b)
Construct indexed object with no index.
Definition: indexed.cpp:64
GiNaC::rename_dummy_indices_uniquely
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
GiNaC::spmapkey
Definition: indexed.h:207
GiNaC::indexed::simplify_indexed
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
GiNaC::indexed::read_archive
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
Definition: indexed.cpp:132
GiNaC::print_context
Base class for print_contexts.
Definition: print.h:103
GiNaC::indexed::imag_part
ex imag_part() const override
Definition: indexed.cpp:306
GiNaC::scalar_products::spm
spmap spm
Definition: indexed.h:248
GiNaC::exvector
std::vector< ex > exvector
Definition: basic.h:46
GiNaC::symm
static ex symm(const ex &e, exvector::const_iterator first, exvector::const_iterator last, bool asymmetric)
Definition: symmetry.cpp:485
GiNaC::indexed::eval
ex eval() const override
Perform automatic non-interruptive term rewriting rules.
Definition: indexed.cpp:263
GiNaC::scalar_products::add
void add(const ex &v1, const ex &v2, const ex &sp)
Register scalar product pair and its value.
Definition: indexed.cpp:1348
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::spmapkey::dim
ex dim
Definition: indexed.h:218
GiNaC::indexed::expand
ex expand(unsigned options=0) const override
Expand expression, i.e.
Definition: indexed.cpp:331
options
unsigned options
Definition: factor.cpp:2480
GiNaC::GINAC_DECLARE_UNARCHIVER
GINAC_DECLARE_UNARCHIVER(add)
GiNaC
Definition: add.cpp:38
syms
exset syms
Definition: factor.cpp:2434
GiNaC::indexed::derivative
ex derivative(const symbol &s) const override
Implementation of ex::diff() for an indexed object always returns 0.
Definition: indexed.cpp:388
GiNaC::indexed::printindices
void printindices(const print_context &c, unsigned level) const
Definition: indexed.cpp:165
GiNaC::indexed::real_part
ex real_part() const override
Definition: indexed.cpp:299
GiNaC::indexed::info
bool info(unsigned inf) const override
Information about the object.
Definition: indexed.cpp:239
GiNaC::indexed::validate
void validate() const
Check whether all indices are of class idx and validate the symmetry tree.
Definition: indexed.cpp:368
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::spmapkey::v2
ex v2
Definition: indexed.h:218
GiNaC::expand_dummy_sum
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
GiNaC::ex
Lightweight wrapper for GiNaC's symbolic objects.
Definition: ex.h:72
GiNaC::indexed::print_indexed
void print_indexed(const print_context &c, const char *openbrace, const char *closebrace, unsigned level) const
Definition: indexed.cpp:207
GiNaC::indexed::reposition_dummy_indices
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
GiNaC::indexed::archive
void archive(archive_node &n) const override
Save (a.k.a.
Definition: indexed.cpp:155
GiNaC::print_latex
Context for latex-parsable output.
Definition: print.h:123
GiNaC::container::op
ex op(size_t i) const override
Return operand/member at position i.
Definition: container.h:295
GiNaC::scalar_products
Helper class for storing information about known scalar products which are to be automatically replac...
Definition: indexed.h:227
GiNaC::spmap
std::map< spmapkey, ex > spmap
Definition: indexed.h:221
GiNaC::spmapkey::spmapkey
spmapkey()
Definition: indexed.h:209
GiNaC::ex::return_type_tinfo
return_type_t return_type_tinfo() const
Definition: ex.h:231
GiNaC::indexed::symtree
ex symtree
Index symmetry (tree of symmetry objects)
Definition: indexed.h:202
GiNaC::return_type_t
To distinguish between different kinds of non-commutative objects.
Definition: registrar.h:44
GiNaC::print_tree
Context for tree-like output for debugging.
Definition: print.h:147
GiNaC::indexed::get_symmetry
ex get_symmetry() const
Return symmetry properties.
Definition: indexed.h:190
GiNaC::indexed::simplify_indexed_product
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),...
Definition: indexed.cpp:779
GiNaC::indexed::get_indices
exvector get_indices() const
Return a vector containing the object's indices.
Definition: indexed.cpp:423
GiNaC::container
Wrapper template for making GiNaC classes out of STL containers.
Definition: container.h:73
GiNaC::indexed::all_index_values_are
bool all_index_values_are(unsigned inf) const
Check whether all index values have a certain property.
Definition: indexed.cpp:246
GiNaC::indexed::do_print_tree
void do_print_tree(const print_tree &c, unsigned level) const
Definition: indexed.cpp:229
c
size_t c
Definition: factor.cpp:770
GiNaC::scalar_products::clear
void clear()
Clear all registered scalar products.
Definition: indexed.cpp:1366
GiNaC::scalar_products::debugprint
void debugprint() const
Definition: indexed.cpp:1383
GiNaC::scalar_products::add_vectors
void add_vectors(const lst &l, const ex &dim=wild())
Register list of vectors.
Definition: indexed.cpp:1358
GiNaC::symbol
Basic CAS symbol.
Definition: symbol.h:39
GiNaC::symmetry
This class describes the symmetry of a group of indices.
Definition: symmetry.h:39
n
size_t n
Definition: factor.cpp:1463
GiNaC::spmapkey::operator==
bool operator==(const spmapkey &other) const
Definition: indexed.cpp:1315
GiNaC::indexed::precedence
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
Definition: indexed.h:146
GiNaC::scalar_products::is_defined
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::indexed::has_dummy_index_for
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
GiNaC::scalar_products::evaluate
ex evaluate(const ex &v1, const ex &v2, const ex &dim) const
Return value of defined scalar product pair.
Definition: indexed.cpp:1378
GiNaC::indexed::return_type
unsigned return_type() const override
Definition: indexed.cpp:323
GiNaC::indexed::do_print
void do_print(const print_context &c, unsigned level) const
Definition: indexed.cpp:219
GiNaC::indexed::thiscontainer
ex thiscontainer(const exvector &v) const override
Definition: indexed.cpp:313
GiNaC::indexed::do_print_latex
void do_print_latex(const print_latex &c, unsigned level) const
Definition: indexed.cpp:224
GiNaC::get_all_dummy_indices
exvector get_all_dummy_indices(const ex &e)
Returns all dummy indices from the exvector.
Definition: indexed.cpp:1435
GiNaC::indexed::return_type_tinfo
return_type_t return_type_tinfo() const override
Definition: indexed.h:162
GiNaC::spmapkey::debugprint
void debugprint() const
Definition: indexed.cpp:1343
GiNaC::get_all_dummy_indices_safely
exvector get_all_dummy_indices_safely(const ex &e)
More reliable version of the form.
Definition: indexed.cpp:1394
GiNaC::indexed
This class holds an indexed expression.
Definition: indexed.h:40
GiNaC::spmapkey::operator<
bool operator<(const spmapkey &other) const
Definition: indexed.cpp:1327

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