Cadabra
Computer algebra system for field theory problems
young_reduce.hh
Go to the documentation of this file.
1 #include <memory>
2 #include <gmpxx.h>
3 
4 #include "Algorithm.hh"
5 
6 namespace cadabra {
7 
8  namespace yr {
9 
10  using index_t = short;
11  using adjform_t = std::vector<index_t>;
12 
14  {
15  public:
16  using map_t = std::map<adjform_t, mpq_class>;
17  using iterator = map_t::iterator;
18  using const_iterator = map_t::const_iterator;
19 
20  // Check if 'other' is a linear multiple of 'this' and return
21  // the numeric factor if so, otherwise returns 0
22  mpq_class compare(const ProjectedForm& other) const;
23 
24  // Add all contributions from 'other' into 'this'
25  void combine(const ProjectedForm& other);
26  void combine(const ProjectedForm& other, mpq_class factor);
27 
28  // Multiply all terms by a constant factor
29  void multiply(mpq_class k);
30 
31  // Remove all entries
32  void clear();
33 
34  // Insert an adjform with given value, overwriting current value
35  // if present
36  void insert(adjform_t adjform, mpq_class value = 1);
37 
38  // Apply a Tableau row/column symmetry
39  void apply_young_symmetry(const std::vector<index_t>& indices, bool antisymmetric);
40 
41  // Symmetrize in indices starting at the indice in 'positions' with each group
42  // 'n_indices' long
43  void apply_ident_symmetry(std::vector<index_t> positions, index_t n_indices);
44 
46  };
47 
48  // Checks if 'lhs' and 'rhs' are identical up to index names
49  bool check_structure(Ex::iterator lhs, Ex::iterator rhs);
50 
51  // Check for a TableauBase property (potentially deep)
52  bool has_TableauBase(Ex::iterator it, const Kernel& kernel);
53 
54  // Returns a list of iterators of the children of 'it' if it->name
55  // is delim, otherwise returns a list containing 'it' as its only
56  // entry. If 'pat' is specified, any terms not matching 'pat' are
57  // ignored
58  std::vector<Ex::iterator> split_ex(Ex::iterator it, const std::string& delim);
59  std::vector<Ex::iterator> split_ex(Ex::iterator it, const std::string& delim, Ex::iterator pat);
60 
63  }
64 
65  class young_reduce : public Algorithm
66  {
67  public:
68  young_reduce(const Kernel& kernel, Ex& ex, const Ex* pattern = nullptr);
69  ~young_reduce();
70 
71  // Attempt to set pattern to new_pat; return true if successful else false
72  bool set_pattern(Ex::iterator new_pat);
73 
74  virtual bool can_apply(iterator it) override;
75  virtual result_t apply(iterator& it) override;
76  private:
77 
80 
81  // Young project 'it' up to a numeric constant
82  yr::ProjectedForm symmetrize(Ex::iterator it);
83 
84  Ex::iterator pat;
86 
87  // Rewrite 'it' as an adjacency form
88  yr::adjform_t to_adjform(Ex::iterator it);
89 
90  // Return a unique negative index for each name
91  yr::index_t get_free_index(nset_t::iterator name);
92  std::vector<nset_t::iterator> index_map;
93  };
94 
95 }
result_t apply_known(iterator &it)
Definition: young_reduce.cc:410
short index_t
Definition: young_reduce.hh:10
Base class for all algorithms, containing generic routines and in particular the logic for index clas...
Definition: Algorithm.hh:59
std::vector< nset_t::iterator > index_map
Definition: young_reduce.hh:92
map_t::iterator iterator
Definition: young_reduce.hh:17
yr::index_t get_free_index(nset_t::iterator name)
Definition: young_reduce.cc:656
Basic storage class for symbolic mathemematical expressions.
Definition: Storage.hh:140
yr::ProjectedForm pat_sym
Definition: young_reduce.hh:85
yr::ProjectedForm symmetrize(Ex::iterator it)
Definition: young_reduce.cc:547
std::vector< index_t > adjform_t
Definition: young_reduce.hh:11
Definition: young_reduce.hh:65
adjform_t collapse_dummy_indices(adjform_t adjform)
Definition: young_reduce.cc:337
virtual bool can_apply(iterator it) override
Definition: young_reduce.cc:381
Ex rhs(Ex_ptr ex)
Definition: py_ex.cc:305
std::map< adjform_t, mpq_class > map_t
Definition: young_reduce.hh:16
result_t apply_unknown(iterator &it)
Definition: young_reduce.cc:455
std::vector< Ex::iterator > split_ex(Ex::iterator it, const std::string &delim)
Definition: young_reduce.cc:299
~young_reduce()
Definition: young_reduce.cc:376
void apply_ident_symmetry(std::vector< index_t > positions, index_t n_indices)
Definition: young_reduce.cc:231
bool has_TableauBase(Ex::iterator it, const cadabra::Kernel &kernel)
Definition: young_reduce.cc:286
Ex::iterator iterator
Definition: Algorithm.hh:70
void insert(adjform_t adjform, mpq_class value=1)
Definition: young_reduce.cc:191
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Algorithm.cc:1045
const Kernel & kernel
Definition: IndexClassifier.hh:66
young_reduce(const Kernel &kernel, Ex &ex, const Ex *pattern=nullptr)
Definition: young_reduce.cc:367
int k
Definition: passing.cc:4
void multiply(mpq_class k)
Definition: young_reduce.cc:180
map_t::const_iterator const_iterator
Definition: young_reduce.hh:18
bool check_structure(Ex::iterator lhs, Ex::iterator rhs)
Definition: young_reduce.cc:254
mpq_class compare(const ProjectedForm &other) const
Definition: young_reduce.cc:132
Definition: young_reduce.hh:13
map_t data
Definition: young_reduce.hh:45
bool set_pattern(Ex::iterator new_pat)
Definition: young_reduce.cc:522
void combine(const ProjectedForm &other)
Definition: young_reduce.cc:162
Definition: Kernel.hh:14
void apply_young_symmetry(const std::vector< index_t > &indices, bool antisymmetric)
Definition: young_reduce.cc:197
Definition: Props.hh:37
Ex::iterator pat
Definition: young_reduce.hh:84
result_t
Keeping track of what algorithms have done to this expression.
Definition: Storage.hh:159
Ex lhs(Ex_ptr ex)
Definition: py_ex.cc:293
virtual result_t apply(iterator &it) override
Definition: young_reduce.cc:391
void clear()
Definition: young_reduce.cc:186
yr::adjform_t to_adjform(Ex::iterator it)
Definition: young_reduce.cc:615
adjform_t expand_dummy_indices(adjform_t adjform)
Definition: young_reduce.cc:350