Cadabra
Computer algebra system for field theory problems
Functional.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <functional>
5 #include "Storage.hh"
6 
7 namespace cadabra {
8 
16 
17  void do_list(const Ex& tr, Ex::iterator it, std::function<bool(Ex::iterator)> f);
18 
23 
24  int list_size(const Ex& tr, Ex::iterator it);
25 
29 
30  Ex::iterator find_in_list(const Ex& tr, Ex::iterator it, std::function<Ex::iterator(Ex::iterator)> f);
31 
35 
36  Ex::iterator find_in_subtree(const Ex& tr, Ex::iterator it, std::function<bool(Ex::iterator)> f, bool including_head=true);
37 
41 
42  Ex make_list(Ex el);
43 
44 
45 
51 
52  template<typename T>
53  typename T::iterator do_subtree(const T& tr, typename T::iterator it, std::function<typename T::iterator(typename T::iterator)> f)
54  {
55  if(it==tr.end()) return it;
56 
57  class T::post_order_iterator walk=it, last=it;
58  ++last;
59  walk.descend_all();
60 
61  do {
62  auto nxt=walk;
63  ++nxt;
64 
65  bool cpy=false;
66  if(walk==it) cpy=true;
67  walk = f(walk);
68  if(cpy) it=walk;
69 
70  walk=nxt;
71  }
72  while(walk!=last);
73 
74  return it;
75  }
76 
77  };
Storage.hh
cadabra::do_subtree
T::iterator do_subtree(const T &tr, typename T::iterator it, std::function< typename T::iterator(typename T::iterator)> f)
Definition: Functional.hh:53
cadabra::find_in_list
Ex::iterator find_in_list(const Ex &tr, Ex::iterator it, std::function< Ex::iterator(Ex::iterator)> f)
Definition: Functional.cc:59
cadabra::do_list
void do_list(const Ex &tr, Ex::iterator it, std::function< bool(Ex::iterator)> f)
Definition: Functional.cc:6
cadabra::list_size
int list_size(const Ex &tr, Ex::iterator it)
Definition: Functional.cc:25
cadabra
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:80
cadabra::make_list
Ex make_list(Ex el)
Definition: Functional.cc:76
cadabra::find_in_subtree
Ex::iterator find_in_subtree(const Ex &tr, Ex::iterator it, std::function< bool(Ex::iterator)> f, bool including_head)
Definition: Functional.cc:33