11 static matrix RowReduce(matrix mat) {
13 int &v_max = fermat.vmax;
17 for(const_preorder_iterator i = tree.preorder_begin(); i != tree.preorder_end(); ++i) {
19 if(is_a<symbol>(e) || e.match(
a(
w))) rep_vs.append(e);
28 for(
auto vi : rep_vs) {
29 auto name =
"v" + to_string(fvi);
30 v2f[vi] = Symbol(name);
37 cout << rep_vs << endl;
38 throw Error(
"Fermat: Too many variables.");
41 for(
int i=v_max; i<fvi; i++) ss <<
"&(J=v" << i <<
");" << endl;
42 fermat.Execute(ss.str());
48 int nrow = mat.rows();
49 int ncol = mat.cols();
51 ss <<
"Array m[" << nrow <<
"," << ncol+1 <<
"];" << endl;
52 fermat.Execute(ss.str());
57 for(
int c=0; c<ncol; c++) {
58 for(
int r=0; r<nrow; r++) {
59 ss << mat(r,c).subs(
iEpsilon==0).subs(v2f) <<
",";
62 for(
int r=0; r<nrow; r++) ss <<
"0,";
64 ss <<
"Redrowech([m]);" << endl;
71 ss <<
"&(U=1);" << endl;
73 auto ostr = fermat.Execute(ss.str());
79 ss <<
"&(U=0);" << endl;
80 ss <<
"@([m]);" << endl;
82 fermat.Execute(ss.str());
87 if(ostr[ostr.length()-1]!=
'0')
throw Error(
"Direc::Export, last char is NOT 0.");
88 ostr = ostr.substr(0, ostr.length()-1);
91 ostr.erase(0, ostr.find(
":=")+2);
95 matrix mr(nrow, ncol);
96 auto res = fp.Read(ostr);
97 for(
int r=0; r<nrow; r++) {
99 for(
int c=0; c<ncol; c++) mr(r,c) = cur.op(c);
113 for(
auto ii :
Internal) InExternal.append(ii);
114 for(
auto ii :
External) InExternal.append(ii);
118 for(
auto ii : InExternal)
ISP.append(it*ii);
124 if(
ISP.nops() > pdim) {
125 cout <<
"ISP = " <<
ISP << endl;
126 cout <<
"Propagator = " <<
Propagator << endl;
127 throw Error(
"Direct::Export: #(ISP) > #(Propagator).");
132 for(
auto item :
ISP) {
134 Symbol si(
"P"+to_string(_pic));
136 sp2s.append(
w*item==
w*si);
137 sp2s.append(item==si);
138 s2sp.append(si==item);
142 for(
int i=0; i<
ISP.nops(); i++) {
146 if(eq.has(iWF(
w)))
throw Error(
"Direct::Export, iWF used in eq.");
147 leqns.append(eq == iWF(i));
149 auto s2p = lsolve(leqns, ss);
150 if(s2p.nops() !=
ISP.nops())
throw Error(
"Direct::Export: lsolve failed.");
154 for(
auto p2 : InExternal)
155 DSP.append(lst{p1,p2});
160 for(
int i=0; i<pdim; i++) nsa.append(
a(i));
167 for(
int i=0; i<pdim; i++) {
169 ns.let_op(i) = nsa.op(i) + 1;
170 auto dp =
Propagator.op(i).subs(ilp==ss).diff(ss).subs(ss==ilp);
171 ibp -= (
a(i)+
Shift[i]) * F(ns) * dp;
176 ibp = ibp.subs(sp2s);
181 for(
int i=0; i<pdim; i++) {
182 auto ci = ibp.coeff(iWF(i), 1);
184 if(!e.has(F(
w)))
return e;
185 else if(e.match(F(
w))) {
186 lst tmp = ex_to<lst>(e.op(0));
187 tmp.let_op(i) = tmp.op(i)-1;
189 }
else return e.map(
self);
193 res += ibp.subs(lst{iWF(
w)==0});
194 auto cilp = iep.coeff(ilp);
195 if(!is_zero(cilp)) res +=
d*cilp*F(nsa);
203 for(
int i=0; i<pdim; i++) ns0.append(1);
204 for(
int i=0; i<pdim; i++) {
205 if(
Propagator.op(i).has(lpi)) ns0.let_op(i) = -1;
206 else ns_vec.push_back(i);
208 for(
int n=0; n<std::pow(2,ns_vec.size()); n++) {
211 for(
int j=0; j<ns_vec.size(); j++) {
212 if((cn%2)==1) ns1.let_op(ns_vec[j]) = -1;
223 for(
int i=0; i<pdim; i++) ns0.append(1);
224 size_t tot = std::pow(2LL,pdim);
225 for(
size_t n=0; n<tot; n++) {
229 for(
int j=0; j<pdim; j++) {
230 if((cn%2)==1) { ns1.let_op(j) = -1; sector.let_op(j) = 0; }
239 for(
int i=0; i<pdim; i++) ws.append(wild(i));
248 cout << ibps_o << endl;
250 for(
auto ibp : ibps_o) {
251 for(
int s=-3; s<=3; s++) {
252 ibps.append(ibp.subs(
a(
w)==
a(
w)+s));
256 size_t ltot = std::pow(3L,pdim);
263 for(
int i=0; i<pdim; i++) {
264 auto im = (cli % 3)-1;
265 if(im==0) cibps = ex_to<lst>(
subs(cibps,
a(i)==0));
271 map<int,exvector> sum_fs;
274 find(cibps,F(
w),fset);
276 for(
auto fi : fset) {
278 auto ns = fi.op(0).subs(
a(
w)==0);
279 for(
int i=0; i<pdim; i++) {
281 if(csec[i]==-1) sum -=
ex2int(ni);
282 else if(csec[i]==1) sum +=
ex2int(ni);
283 else sum += abs(
ex2int(ni));
285 sum_fs[sum].push_back(fi);
289 for(
auto kv : sum_fs) sum_tot.append(lst{kv.first, kv.second.size()});
292 matrix mat(cibps.nops(), fset.size());
295 for(
auto st : sum_tot) {
296 auto fs = sum_fs[
ex2int(st.op(0))];
298 for(
int cc=0; cc<fs.size(); cc++) {
299 fvec.push_back(fs[cc]);
301 for(
auto ibp : cibps) {
302 mat(row,ccol+cc) = ibp.coeff(fs[cc]);
309 auto mr = RowReduce(mat);
311 for(
int r=0; r<mat.rows(); r++) {
313 for(
auto ti : sum_tot) {
314 int ct =
ex2int(ti.op(1));
315 for(
int k=0; k<ct; k++) {
317 if(mr(r,c).is_zero())
continue;
318 else if(c1==-1) c1=c;
323 for(
int ci=c1+1; ci<mat.cols(); ci++) sol -= mr(r,ci)/mr(r,c1)*fvec[ci];
324 auto ns0 = fvec[c1].op(0).subs(
a(
w)==0);
326 for(
int i=0; i<ns0.nops(); i++) {
327 if(csec[i]==0)
continue;
328 if(!ns0.op(i).is_zero()) aSH[
a(i)]=
a(i)-ns0.op(i);
334 vector<vector<int>> fns;
336 fi = fi.subs(
a(
w)==0);
338 for(
auto it : fi.op(0)) ns.push_back(0-
ex2int(it));
342 for(
int i=0; i<csec.size(); i++) {
346 if(ns[i]<min) min = ns[i];
348 cond.
cs.push_back(make_pair(-1,min));
349 }
else if(csec[i]==1) {
352 if(ns[i]>max) max = ns[i];
354 cond.
cs.push_back(make_pair(1,max));
356 cond.
cs.push_back(make_pair(0,
ex2int(ns0.op(i))));
360 res.append(lst{cond.
cs2ex(),sol});
370 for(
auto its : ret) {
371 for(
auto item : its) {
373 cond.
ex2cs(item.op(0));
374 ConSolVec.push_back(make_pair(cond,item.op(1)));
393 for(
auto intg : intgs) {
395 for(
auto cs : ConSolVec) {
396 if(cs.first.IsOK(intg)) {
398 for(
int i=0; i<intg.nops(); i++)
as[
a(i)] = intg.op(i);
401 auto sol = cs.second.
subs(
as);
410 for(
auto fi : fs) intgs.append(fi.op(0));
411 if(intgs.nops()<1)
break;
415 map<int,exmap> lvl_sol;
417 for(
auto sol : sols) {
419 for(
auto ni : sol.first.op(0)) sum += (ni<0 ? -ni : ni);
420 lvl_sol[
ex2int(sum)][sol.first] = sol.second;
427 for(
int i=0; i<lvls.nops(); i++) {
428 int si =
ex2int(lvls.op(i));
429 for(
auto kv : lvl_sol[si]) {
430 for(
int j=0; j<i; j++) {
431 int sj =
ex2int(lvls.op(j));
432 lvl_sol[si][kv.first] = kv.second.subs(lvl_sol[sj]);
439 for(
auto ni : fi.op(0)) sum += (ni<0 ? -ni : ni);
440 fi = fi.subs(lvl_sol[
ex2int(sum)]);
441 Rules.append(F(intg)==fi);
vector< pair< int, int > > cs
void Run() override
invoke kira program for reduction
void Export() override
Export input data for KIRA.
void Import() override
import kira result
class used to wrap error message
class to wrap map_function of GiNaC
class extended to GiNaC symbol class, represent a positive symbol
ex subs(const exmap &m, unsigned options=0) const override
ex sp(const ex &a, const ex &b)
translated the vector dot a.b to a*b, useful in SecDec
bool key_exists(const exmap &map, const ex &key)
void sort_vec(exvector &ivec, bool less=true)
sort the list in less order, or the reverse
void sort_lst(lst &ilst, bool less=true)
sort the list in less order, or the reverse
void string_replace_all(string &str, const string &from, const string &to)
exvector GiNaC_Parallel(int ntotal, std::function< ex(int)> f, const string &key)
GiNaC Parallel Evaluation using fork.
void string_trim(string &str)
int ex2int(ex num)
ex to integer
ex subs(const ex &e, init_list sl)