GiNaC  1.8.0
symmetry.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_SYMMETRY_H
24 #define GINAC_SYMMETRY_H
25 
26 #include "ex.h"
27 #include "archive.h"
28 
29 #include <set>
30 
31 namespace GiNaC {
32 
33 class sy_is_less;
34 class sy_swap;
35 
38 class symmetry : public basic
39 {
40  friend class sy_is_less;
41  friend class sy_swap;
42  friend int canonicalize(exvector::iterator v, const symmetry &symm);
43 
45 
46  // types
47 public:
49  typedef enum {
50  none,
53  cyclic
55 
56  // other constructors
57 public:
59  symmetry(unsigned i);
60 
62  symmetry(symmetry_type t, const symmetry &c1, const symmetry &c2);
63 
64  // functions overriding virtual functions from base classes
65 public:
67  void archive(archive_node& n) const override;
69  void read_archive(const archive_node& n, lst& syms) override;
70 protected:
71  unsigned calchash() const override;
72 
73  // non-virtual functions in this class
74 public:
76  symmetry_type get_type() const {return type;}
77 
79  void set_type(symmetry_type t) {type = t;}
80 
82  symmetry &add(const symmetry &c);
83 
88  void validate(unsigned n);
89 
91  bool has_symmetry() const {return type != none || !children.empty(); }
93  bool has_nonsymmetric() const;
95  bool has_cyclic() const;
96 protected:
97  void do_print(const print_context & c, unsigned level) const;
98  void do_print_tree(const print_tree & c, unsigned level) const;
99 
100  // member variables
101 private:
104 
106  std::set<unsigned> indices;
107 
110 };
112 
113 
114 // global functions
115 
116 inline symmetry sy_none() { return symmetry(); }
117 inline symmetry sy_none(const symmetry &c1, const symmetry &c2) { return symmetry(symmetry::none, c1, c2); }
118 inline symmetry sy_none(const symmetry &c1, const symmetry &c2, const symmetry &c3) { return symmetry(symmetry::none, c1, c2).add(c3); }
119 inline symmetry sy_none(const symmetry &c1, const symmetry &c2, const symmetry &c3, const symmetry &c4) { return symmetry(symmetry::none, c1, c2).add(c3).add(c4); }
120 
121 inline symmetry sy_symm() { symmetry s; s.set_type(symmetry::symmetric); return s; }
122 inline symmetry sy_symm(const symmetry &c1, const symmetry &c2) { return symmetry(symmetry::symmetric, c1, c2); }
123 inline symmetry sy_symm(const symmetry &c1, const symmetry &c2, const symmetry &c3) { return symmetry(symmetry::symmetric, c1, c2).add(c3); }
124 inline symmetry sy_symm(const symmetry &c1, const symmetry &c2, const symmetry &c3, const symmetry &c4) { return symmetry(symmetry::symmetric, c1, c2).add(c3).add(c4); }
125 
127 inline symmetry sy_anti(const symmetry &c1, const symmetry &c2) { return symmetry(symmetry::antisymmetric, c1, c2); }
128 inline symmetry sy_anti(const symmetry &c1, const symmetry &c2, const symmetry &c3) { return symmetry(symmetry::antisymmetric, c1, c2).add(c3); }
129 inline symmetry sy_anti(const symmetry &c1, const symmetry &c2, const symmetry &c3, const symmetry &c4) { return symmetry(symmetry::antisymmetric, c1, c2).add(c3).add(c4); }
130 
131 inline symmetry sy_cycl() { symmetry s; s.set_type(symmetry::cyclic); return s; }
132 inline symmetry sy_cycl(const symmetry &c1, const symmetry &c2) { return symmetry(symmetry::cyclic, c1, c2); }
133 inline symmetry sy_cycl(const symmetry &c1, const symmetry &c2, const symmetry &c3) { return symmetry(symmetry::cyclic, c1, c2).add(c3); }
134 inline symmetry sy_cycl(const symmetry &c1, const symmetry &c2, const symmetry &c3, const symmetry &c4) { return symmetry(symmetry::cyclic, c1, c2).add(c3).add(c4); }
135 
136 // These return references to preallocated common symmetries (similar to
137 // the numeric flyweights).
138 const symmetry & not_symmetric();
139 const symmetry & symmetric2();
140 const symmetry & symmetric3();
141 const symmetry & symmetric4();
142 const symmetry & antisymmetric2();
143 const symmetry & antisymmetric3();
144 const symmetry & antisymmetric4();
145 
153 extern int canonicalize(exvector::iterator v, const symmetry &symm);
154 
156 ex symmetrize(const ex & e, exvector::const_iterator first, exvector::const_iterator last);
157 
159 inline ex symmetrize(const ex & e, const exvector & v)
160 {
161  return symmetrize(e, v.begin(), v.end());
162 }
163 
165 ex antisymmetrize(const ex & e, exvector::const_iterator first, exvector::const_iterator last);
166 
168 inline ex antisymmetrize(const ex & e, const exvector & v)
169 {
170  return antisymmetrize(e, v.begin(), v.end());
171 }
172 
175 ex symmetrize_cyclic(const ex & e, exvector::const_iterator first, exvector::const_iterator last);
176 
179 inline ex symmetrize_cyclic(const ex & e, const exvector & v)
180 {
181  return symmetrize(e, v.begin(), v.end());
182 }
183 
184 } // namespace GiNaC
185 
186 #endif // ndef GINAC_SYMMETRY_H
GiNaC::not_symmetric
const symmetry & not_symmetric()
Definition: symmetry.cpp:350
GiNaC::symmetry::none
@ none
no symmetry properties
Definition: symmetry.h:50
GiNaC::symmetry::has_symmetry
bool has_symmetry() const
Check whether this node actually represents any kind of symmetry.
Definition: symmetry.h:91
GiNaC::sy_none
symmetry sy_none()
Definition: symmetry.h:116
GiNaC::symmetrize
ex symmetrize(const ex &thisex)
Definition: ex.h:793
GiNaC::sy_symm
symmetry sy_symm()
Definition: symmetry.h:121
GiNaC::symmetry::do_print_tree
void do_print_tree(const print_tree &c, unsigned level) const
Definition: symmetry.cpp:232
GiNaC::symmetry::symmetric
@ symmetric
totally symmetric
Definition: symmetry.h:51
GiNaC::print_context
Base class for print_contexts.
Definition: print.h:103
GiNaC::antisymmetric4
const symmetry & antisymmetric4()
Definition: symmetry.cpp:386
GiNaC::exvector
std::vector< ex > exvector
Definition: basic.h:46
GiNaC::symmetry::add
symmetry & add(const symmetry &c)
Add child node, check index sets for consistency.
Definition: symmetry.cpp:289
GiNaC::symm
static ex symm(const ex &e, exvector::const_iterator first, exvector::const_iterator last, bool asymmetric)
Definition: symmetry.cpp:485
GiNaC::symmetry::symmetry_type
symmetry_type
Type of symmetry.
Definition: symmetry.h:49
GiNaC::symmetry::has_cyclic
bool has_cyclic() const
Check whether this node involves a cyclic symmetry.
Definition: symmetry.cpp:277
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::symmetry::set_type
void set_type(symmetry_type t)
Set symmetry type.
Definition: symmetry.h:79
GiNaC::canonicalize
int canonicalize(exvector::iterator v, const symmetry &symm)
Canonicalize the order of elements of an expression vector, according to the symmetry properties defi...
Definition: symmetry.cpp:438
GiNaC::symmetry::type
symmetry_type type
Type of symmetry described by this node.
Definition: symmetry.h:103
GiNaC::GINAC_DECLARE_UNARCHIVER
GINAC_DECLARE_UNARCHIVER(add)
GiNaC::symmetry::get_type
symmetry_type get_type() const
Get symmetry type.
Definition: symmetry.h:76
GiNaC
Definition: add.cpp:38
syms
exset syms
Definition: factor.cpp:2434
GiNaC::symmetry::has_nonsymmetric
bool has_nonsymmetric() const
Check whether this node involves anything non symmetric.
Definition: symmetry.cpp:265
GiNaC::sy_is_less
Definition: symmetry.cpp:392
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
last
size_t last
Definition: factor.cpp:1465
GiNaC::symmetry::antisymmetric
@ antisymmetric
totally antisymmetric
Definition: symmetry.h:52
GiNaC::ex
Lightweight wrapper for GiNaC's symbolic objects.
Definition: ex.h:72
GiNaC::ex::begin
const_iterator begin() const noexcept
Definition: ex.h:647
GiNaC::sy_cycl
symmetry sy_cycl()
Definition: symmetry.h:131
GiNaC::sy_anti
symmetry sy_anti()
Definition: symmetry.h:126
GiNaC::symmetric4
const symmetry & symmetric4()
Definition: symmetry.cpp:368
GiNaC::symmetry::canonicalize
friend int canonicalize(exvector::iterator v, const symmetry &symm)
Canonicalize the order of elements of an expression vector, according to the symmetry properties defi...
Definition: symmetry.cpp:438
ex.h
Interface to GiNaC's light-weight expression handles.
GiNaC::symmetry::archive
void archive(archive_node &n) const override
Save (a.k.a.
Definition: symmetry.cpp:119
GiNaC::symmetry::cyclic
@ cyclic
cyclic symmetry
Definition: symmetry.h:53
GiNaC::print_tree
Context for tree-like output for debugging.
Definition: print.h:147
GiNaC::symmetry::validate
void validate(unsigned n)
Verify that all indices of this node are in the range [0..n-1].
Definition: symmetry.cpp:312
GiNaC::symmetry::symmetry
symmetry(unsigned i)
Create leaf node that represents one index.
Definition: symmetry.cpp:70
GiNaC::container
Wrapper template for making GiNaC classes out of STL containers.
Definition: container.h:73
GiNaC::sy_swap
Definition: symmetry.cpp:416
GiNaC::symmetry::children
exvector children
Vector of child nodes.
Definition: symmetry.h:109
c
size_t c
Definition: factor.cpp:770
archive.h
Archiving of GiNaC expressions.
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::antisymmetric3
const symmetry & antisymmetric3()
Definition: symmetry.cpp:380
GiNaC::basic
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Definition: basic.h:105
GiNaC::antisymmetric2
const symmetry & antisymmetric2()
Definition: symmetry.cpp:374
GiNaC::symmetry::read_archive
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
Definition: symmetry.cpp:87
GiNaC::symmetrize_cyclic
ex symmetrize_cyclic(const ex &thisex)
Definition: ex.h:805
GiNaC::symmetric3
const symmetry & symmetric3()
Definition: symmetry.cpp:362
GiNaC::antisymmetrize
ex antisymmetrize(const ex &thisex)
Definition: ex.h:799
GiNaC::symmetric2
const symmetry & symmetric2()
Definition: symmetry.cpp:356
GiNaC::symmetry::do_print
void do_print(const print_context &c, unsigned level) const
Definition: symmetry.cpp:206
GiNaC::symmetry::indices
std::set< unsigned > indices
Sorted union set of all indices handled by this node.
Definition: symmetry.h:106
GiNaC::symmetry::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: symmetry.cpp:183

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