Documentation of CSL
partialExpand.h
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
16  #pragma once
17 
18 #include <functional>
19 #include "abstract.h"
20 
21 namespace csl {
22 
23 class Space;
24 
25 using ExpanderEmitter = std::function<bool(csl::Expr const&)>;
26 using ExpanderReceiver = std::function<bool(csl::Expr const&, csl::Expr const&)>;
27 
28 bool haveCommonIndices(
29  csl::Expr const &a,
30  csl::Expr const &b,
31  csl::Space const *space
32  );
33 
34 void PartialExpandImplementation(
35  Expr &prod,
36  ExpanderEmitter const &isEmitter,
37  ExpanderReceiver const &isReceiver
38  );
39 
40 void PartialExpandImplementation(
41  Expr &prod,
42  ExpanderEmitter const &isEmitter,
43  ExpanderEmitter const &isReceiver
44  );
45 
46 inline void PartialExpandImplementation(
47  Expr &prod,
48  ExpanderEmitter const &isEmitterReceiver
49  )
50 {
51  return PartialExpandImplementation(
52  prod,
53  isEmitterReceiver,
54  isEmitterReceiver
55  );
56 }
57 
58 Expr PartialExpanded(
59  Expr const &init,
60  ExpanderEmitter const &isEmitter,
61  ExpanderReceiver const &isReceiver
62  );
63 void PartialExpand(
64  Expr &init,
65  ExpanderEmitter const &isEmitter,
66  ExpanderReceiver const &isReceiver
67  );
68 Expr DeepPartialExpanded(
69  Expr const &init,
70  ExpanderEmitter const &isEmitter,
71  ExpanderReceiver const &isReceiver
72  );
73 void DeepPartialExpand(
74  Expr &init,
75  ExpanderEmitter const &isEmitter,
76  ExpanderReceiver const &isReceiver
77  );
78 
79 inline Expr PartialExpanded(
80  Expr const &init,
81  ExpanderEmitter const &isEmitter,
82  ExpanderEmitter const &isReceiver
83  )
84 {
85  return PartialExpanded(
86  init,
87  isEmitter,
88  [&isReceiver](csl::Expr const&, csl::Expr const &a) -> bool {
89  return bool(isReceiver(a));
90  });
91 }
92 inline void PartialExpand(
93  Expr &init,
94  ExpanderEmitter const &isEmitter,
95  ExpanderEmitter const &isReceiver
96  )
97 {
98  PartialExpand(
99  init,
100  isEmitter,
101  [&isReceiver](csl::Expr const&, csl::Expr const &a) -> bool {
102  return bool(isReceiver(a));
103  });
104 }
105 inline Expr DeepPartialExpanded(
106  Expr const &init,
107  ExpanderEmitter const &isEmitter,
108  ExpanderEmitter const &isReceiver
109  )
110 {
111  return DeepPartialExpanded(
112  init,
113  isEmitter,
114  [&isReceiver](csl::Expr const&, csl::Expr const &a) -> bool {
115  return bool(isReceiver(a));
116  });
117 }
118 inline void DeepPartialExpand(
119  Expr &init,
120  ExpanderEmitter const &isEmitter,
121  ExpanderEmitter const &isReceiver
122  )
123 {
124  DeepPartialExpand(
125  init,
126  isEmitter,
127  [&isReceiver](csl::Expr const&, csl::Expr const &a) -> bool {
128  return bool(isReceiver(a));
129  });
130 }
131 
132 inline Expr PartialExpanded(
133  Expr const &init,
134  ExpanderEmitter const &isEmitter
135  )
136 {
137  return PartialExpanded(init, isEmitter, isEmitter);
138 }
139 inline void PartialExpand(
140  Expr &init,
141  ExpanderEmitter const &isEmitter
142  )
143 {
144  PartialExpand(init, isEmitter, isEmitter);
145 }
146 inline Expr DeepPartialExpanded(
147  Expr const &init,
148  ExpanderEmitter const &isEmitter
149  )
150 {
151  return DeepPartialExpanded(init, isEmitter, isEmitter);
152 }
153 inline void DeepPartialExpand(
154  Expr &init,
155  ExpanderEmitter const &isEmitter
156  )
157 {
158  DeepPartialExpand(init, isEmitter, isEmitter);
159 }
160 
161 }
Namespace for csl library.
Definition: abreviation.h:34
Vector space that has a name, a dimension, a delta tensor and possibly a non-trivial metric...
Definition: space.h:64
Base classes for all exprs in the program.
Expression type/.
Definition: abstract.h:1573