HepLib
Loading...
Searching...
No Matches
cseParser.cpp
Go to the documentation of this file.
1
6#include "SD.h"
7
8namespace HepLib::SD {
9
10int cseParser::on() { return no; }
11vector<pair<int, ex>> cseParser::os() { return o_ex_vec;}
12
13ex cseParser::Parse(ex expr, bool reset) {
14 if(reset) {
15 no = 0;
16 o_ex_vec.clear();
17 }
18
19 if(is_a<numeric>(expr) || is_a<symbol>(expr) || is_a<symbol>(-expr) || isFunction(expr,"x") || isFunction(-expr,"x") || isFunction(expr,"PL") || isFunction(-expr,"PL")) return expr;
20 if(!is_zero(ex_var_map[expr])) {
21 return ex_var_map[expr];
22 }
23
24 ex ret = expr;
25 if(is_a<add>(expr)) {
26 ret = 0;
27 for(auto item : expr) ret += Parse(item,false);
28 } else if(is_a<lst>(expr)) {
29 lst oret;
30 for(auto item : expr) oret.append(Parse(item,false));
31 return oret;
32 } else if(is_a<mul>(expr)) {
33 ret = 1;
34 for(auto item : expr) ret *= Parse(item,false);
35 } else if(is_a<power>(expr)) {
36 ret = power(Parse(expr.op(0),false), expr.op(1));
37 } else if(expr.match(log(w))) {
38 ret = log(Parse(expr.op(0),false));
39 } else if(expr.match(exp(w))) {
40 ret = exp(Parse(expr.op(0),false));
41 } else if(expr.match(sqrt(w))) {
42 ret = sqrt(Parse(expr.op(0),false));
43 } // else ret is expr
44 stringstream ss;
45 ss << oc << "[" << no << "]";
46 Symbol so(ss.str().c_str());
47 o_ex_vec.push_back(make_pair(no, ret));
48 no++;
49 ex_var_map[expr] = so;
50 return so;
51}
52
53
54int cse_Parser::vn() { return no; }
55const vector<pair<int,ex>> & cse_Parser::vs() { return on_ex_vec;}
56
57ex cse_Parser::Parse(ex expr, bool reset) {
58 if(reset) {
59 no = 0;
60 exv.clear();
61 on_ex_vec.clear();
62 }
63
64 auto itr = exn.find(expr);
65 if(itr!=exn.end()) {
66 used[itr->second]++;
67 return exv[itr->second];
68 }
69
70 ex ret = expr;
71 if(is_a<numeric>(expr) || is_a<symbol>(expr) || is_a<symbol>(-expr) || isFunction(expr,"x") || isFunction(-expr,"x") || isFunction(expr,"PL") || isFunction(-expr,"PL")) return expr;
72 if(is_a<add>(expr)) {
73 ret = 0;
74 for(auto item : expr) ret += Parse(item,false);
75 } else if(is_a<lst>(expr)) {
76 lst oret;
77 for(auto item : expr) oret.append(Parse(item,false));
78 return oret;
79 } else if(is_a<mul>(expr)) {
80 ret = 1;
81 for(auto item : expr) ret *= Parse(item,false);
82 } else if(is_a<power>(expr)) {
83 ret = power(Parse(expr.op(0),false), expr.op(1));
84 } else if(expr.match(log(w))) {
85 ret = log(Parse(expr.op(0),false));
86 } else if(expr.match(exp(w))) {
87 ret = exp(Parse(expr.op(0),false));
88 } else if(expr.match(sqrt(w))) {
89 ret = sqrt(Parse(expr.op(0),false));
90 } // else ret is expr
91 exv.push_back(ret);
92 exn[expr] = no;
93 used[no] = 1;
94 ex res = iWF(no);
95 no++;
96 if(!reset) return res;
97
98 map<int,int> s2l, l2s;
99 MapFunction map([&l2s,this](const ex & e, MapFunction &self)->ex{
100 if(!e.has(iWF(w))) return e;
101 else if(e.match(iWF(w))) {
102 int wi = ex2int(e.op(0));
103 used[wi]--;
104 return Symbol(v+"["+to_string(l2s[wi])+"]");
105 } else return e.map(self);
106 });
107
108 int max = 0;
109 int next = -1;
110 for(int i=0; i<no; i++) {
111cout << i << "/" << no << "/" << max << endl;
112 int on = i;
113 if(next!=-1) { on = next; }
114 else { on = max; max++; }
115 l2s[i] = on;
116 s2l[on] = i;
117 on_ex_vec.push_back(make_pair(on, map(exv[i])));
118 next = -1;
119 for(int j=0; j<max; j++) if(used[s2l[j]]<1) {
120 next = j;
121 break;
122 }
123 }
124 ret = map(res);
125 no = max;
126 return ret;
127}
128
129
130}
SecDec header file.
ex Parse(ex expr, bool reset=true)
Definition cseParser.cpp:13
vector< pair< int, ex > > os()
Definition cseParser.cpp:11
ex Parse(ex expr)
Definition SD.h:533
const vector< pair< int, ex > > & vs()
Definition cseParser.cpp:55
class extended to GiNaC symbol class, represent a positive symbol
Definition BASIC.h:113
namespace for Numerical integration with Sector Decomposition method
Definition AsyMB.cpp:10
ex w
Definition Init.cpp:93
bool isFunction(const ex &e, string func_name)
Definition BASIC.h:658
int ex2int(ex num)
ex to integer
Definition BASIC.cpp:893