GiNaC 1.8.10
indexed.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_INDEXED_H
23#define GINAC_INDEXED_H
24
25#include "exprseq.h"
26#include "wildcard.h"
27
28#include <map>
29
30namespace GiNaC {
31
32class scalar_products;
33class symmetry;
34
38class indexed : public exprseq
39{
41
42 friend ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indices, const scalar_products & sp);
43 friend ex simplify_indexed_product(const ex & e, exvector & free_indices, exvector & dummy_indices, const scalar_products & sp);
44 friend bool reposition_dummy_indices(ex & e, exvector & variant_dummy_indices, exvector & moved_indices);
45
46 // other constructors
47public:
51 indexed(const ex & b);
52
57 indexed(const ex & b, const ex & i1);
58
64 indexed(const ex & b, const ex & i1, const ex & i2);
65
72 indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3);
73
81 indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3, const ex & i4);
82
90 indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2);
91
100 indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2, const ex & i3);
101
111 indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2, const ex & i3, const ex & i4);
112
118 indexed(const ex & b, const exvector & iv);
119
126 indexed(const ex & b, const symmetry & symm, const exvector & iv);
127
128 // internal constructors
129 indexed(const symmetry & symm, const exprseq & es);
130 indexed(const symmetry & symm, const exvector & v);
131 indexed(const symmetry & symm, exvector && v);
132
133 // functions overriding virtual functions from base classes
134public:
135 unsigned precedence() const override {return 55;}
136 bool info(unsigned inf) const override;
137 ex eval() const override;
138 ex real_part() const override;
139 ex imag_part() const override;
140 exvector get_free_indices() const override;
141
143 void archive(archive_node& n) const override;
145 void read_archive(const archive_node& n, lst& syms) override;
146protected:
147 ex derivative(const symbol & s) const override;
148 ex thiscontainer(const exvector & v) const override;
149 ex thiscontainer(exvector && v) const override;
150 unsigned return_type() const override;
151 return_type_t return_type_tinfo() const override { return op(0).return_type_tinfo(); }
152 ex expand(unsigned options = 0) const override;
153
154 // new virtual functions which can be overridden by derived classes
155 // none
156
157 // non-virtual functions in this class
158public:
161 bool all_index_values_are(unsigned inf) const;
162
164 exvector get_indices() const;
165
168
172 exvector get_dummy_indices(const indexed & other) const;
173
176 bool has_dummy_index_for(const ex & i) const;
177
179 ex get_symmetry() const {return symtree;}
180
181protected:
182 void printindices(const print_context & c, unsigned level) const;
183 void print_indexed(const print_context & c, const char *openbrace, const char *closebrace, unsigned level) const;
184 void do_print(const print_context & c, unsigned level) const;
185 void do_print_latex(const print_latex & c, unsigned level) const;
186 void do_print_tree(const print_tree & c, unsigned level) const;
187 void validate() const;
188
189 // member variables
190protected:
192};
194
195
196class spmapkey {
197public:
198 spmapkey() : dim(wild()) {}
199 spmapkey(const ex & v1, const ex & v2, const ex & dim = wild());
200
201 bool operator==(const spmapkey &other) const;
202 bool operator<(const spmapkey &other) const;
203
204 void debugprint() const;
205
206protected:
208};
209
210typedef std::map<spmapkey, ex> spmap;
211
217public:
219 void add(const ex & v1, const ex & v2, const ex & sp);
220
222 void add(const ex & v1, const ex & v2, const ex & dim, const ex & sp);
223
227 void add_vectors(const lst & l, const ex & dim = wild());
228
230 void clear();
231
232 bool is_defined(const ex & v1, const ex & v2, const ex & dim) const;
233 ex evaluate(const ex & v1, const ex & v2, const ex & dim) const;
234 void debugprint() const;
235
236protected:
237 spmap spm; /*< Map from defined scalar product pairs to their values */
238};
239
240
241// utility functions
242
245
249
252ex rename_dummy_indices_uniquely(exvector & va, const ex & b, bool modify_va = false);
253
255ex rename_dummy_indices_uniquely(const ex & a, const ex & b);
256
258ex rename_dummy_indices_uniquely(const exvector & va, const exvector & vb, const ex & b);
259
262lst rename_dummy_indices_uniquely(const exvector & va, const exvector & vb);
263
273ex expand_dummy_sum(const ex & e, bool subs_idx = false);
274
275} // namespace GiNaC
276
277#endif // ndef GINAC_INDEXED_H
#define GINAC_DECLARE_UNARCHIVER(classname)
Helper macros to register a class with (un)archiving (a.k.a.
Definition archive.h:218
Sum of expressions.
Definition add.h:31
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
Wrapper template for making GiNaC classes out of STL containers.
Definition container.h:72
ex op(size_t i) const override
Return operand/member at position i.
Definition container.h:294
Lightweight wrapper for GiNaC's symbolic objects.
Definition ex.h:72
return_type_t return_type_tinfo() const
Definition ex.h:231
This class holds an indexed expression.
Definition indexed.h:39
bool all_index_values_are(unsigned inf) const
Check whether all index values have a certain property.
Definition indexed.cpp:246
ex thiscontainer(const exvector &v) const override
Definition indexed.cpp:313
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
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
Definition indexed.h:135
void printindices(const print_context &c, unsigned level) const
Definition indexed.cpp:165
exvector get_free_indices() const override
Return a vector containing the free indices of an expression.
Definition indexed.cpp:457
ex get_symmetry() const
Return symmetry properties.
Definition indexed.h:179
void do_print(const print_context &c, unsigned level) const
Definition indexed.cpp:219
ex expand(unsigned options=0) const override
Expand expression, i.e.
Definition indexed.cpp:331
void do_print_latex(const print_latex &c, unsigned level) const
Definition indexed.cpp:224
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
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
Definition indexed.cpp:132
void do_print_tree(const print_tree &c, unsigned level) const
Definition indexed.cpp:229
ex derivative(const symbol &s) const override
Implementation of ex::diff() for an indexed object always returns 0.
Definition indexed.cpp:388
bool info(unsigned inf) const override
Information about the object.
Definition indexed.cpp:239
ex eval() const override
Perform automatic non-interruptive term rewriting rules.
Definition indexed.cpp:263
ex real_part() const override
Definition indexed.cpp:299
void validate() const
Check whether all indices are of class idx and validate the symmetry tree.
Definition indexed.cpp:368
ex symtree
Index symmetry (tree of symmetry objects)
Definition indexed.h:191
exvector get_indices() const
Return a vector containing the object's indices.
Definition indexed.cpp:423
return_type_t return_type_tinfo() const override
Definition indexed.h:151
exvector get_dummy_indices() const
Return a vector containing the dummy indices of the object, if any.
Definition indexed.cpp:429
void print_indexed(const print_context &c, const char *openbrace, const char *closebrace, unsigned level) const
Definition indexed.cpp:207
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
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 return_type() const override
Definition indexed.cpp:323
ex imag_part() const override
Definition indexed.cpp:306
Base class for print_contexts.
Definition print.h:101
Context for latex-parsable output.
Definition print.h:121
Context for tree-like output for debugging.
Definition print.h:145
Helper class for storing information about known scalar products which are to be automatically replac...
Definition indexed.h:216
bool is_defined(const ex &v1, const ex &v2, const ex &dim) const
Check whether scalar product pair is defined.
Definition indexed.cpp:1372
void debugprint() const
Definition indexed.cpp:1383
ex evaluate(const ex &v1, const ex &v2, const ex &dim) const
Return value of defined scalar product pair.
Definition indexed.cpp:1378
void clear()
Clear all registered scalar products.
Definition indexed.cpp:1366
void add_vectors(const lst &l, const ex &dim=wild())
Register list of vectors.
Definition indexed.cpp:1358
void debugprint() const
Definition indexed.cpp:1343
bool operator<(const spmapkey &other) const
Definition indexed.cpp:1327
bool operator==(const spmapkey &other) const
Definition indexed.cpp:1315
Basic CAS symbol.
Definition symbol.h:38
This class describes the symmetry of a group of indices.
Definition symmetry.h:38
Definition of GiNaC's exprseq.
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
Definition add.cpp:35
std::map< spmapkey, ex > spmap
Definition indexed.h:210
static ex symm(const ex &e, exvector::const_iterator first, exvector::const_iterator last, bool asymmetric)
Definition symmetry.cpp:483
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
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:47
exvector get_all_dummy_indices(const ex &e)
Returns all dummy indices from the exvector.
Definition indexed.cpp:1435
ex wild(unsigned label=0)
Create a wildcard object with the specified label.
Definition wildcard.h:71
exvector get_all_dummy_indices_safely(const ex &e)
More reliable version of the form.
Definition indexed.cpp:1394
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
Definition registrar.h:151
To distinguish between different kinds of non-commutative objects.
Definition registrar.h:42
Interface to GiNaC's wildcard objects.

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