HepLib
Loading...
Searching...
No Matches
ApartIBP.cpp
Go to the documentation of this file.
1
6#include "HEP.h"
7
8namespace HepLib {
9
10 namespace {
11
12 void AIR2F_Save(string save_dir, exvector air_vec, const lst & IntFs, vector<IBP*> &ibp_vec) {
13 auto rc = system(("mkdir -p "+save_dir+"/AIR2F").c_str());
14 rc = system(("rm -f "+save_dir+"/AIR2F/*.gar > /dev/null").c_str());
15 GiNaC_Parallel(air_vec.size(), [&air_vec,&save_dir](int idx) {
16 garWrite(air_vec[idx], save_dir+"/AIR2F/air-"+to_string(idx)+".gar");
17 return 0;
18 }, "AIR2F_AIR");
19
20 GiNaC_Parallel(ibp_vec.size(), [&ibp_vec,&save_dir](int idx) {
21 garWrite(ibp_vec[idx]->TO(), save_dir+"/AIR2F/ibp-"+to_string(idx)+".gar");
22 return 0;
23 }, "AIR2F_IBP");
24
25 ostringstream oss;
26 oss << air_vec.size() << " " << ibp_vec.size() << " " << IntFs.nops() << endl;
27 if(IntFs.nops()>0) {
28 oss << IntFs.op(0).op(1).nops() << endl;
29 for(auto const & f : IntFs) {
30 oss << f.op(0);
31 for(auto const & n : f.op(1)) oss << " " << n;
32 oss << endl;
33 }
34 }
35 auto oss_str = oss.str();
36 fstream ofs(save_dir+"/AIR2F.gar", fstream::out);
37 ofs.write(oss_str.c_str(), oss_str.size());
38 ofs.close();
39 }
40
41 void AIR2F_Get(string save_dir, exvector &air_vec, lst &IntFs, vector<IBP*> &ibp_vec, int IBPmethod) {
42 fstream ifs(save_dir+"/AIR2F.gar", fstream::in);
43 size_t nair, nibp, nf;
44 ifs >> nair >> nibp >> nf;
45
46 IntFs.remove_all();
47 if(nf>0) {
48 int nn;
49 ifs >> nn;
50 for(int i=0; i<nf; i++) {
51 int pn, ni;
52 ifs >> pn;
53 lst ns;
54 for(int j=0; j<nn; j++) {
55 ifs >> ni;
56 ns.append(ni);
57 }
58 IntFs.append(F(pn, ns));
59 }
60 }
61
62 for(int idx=0; idx<nair; idx++) {
63 air_vec[idx] = garRead(save_dir+"/AIR2F/air-"+to_string(idx)+".gar");
64 }
65
66 ibp_vec.resize(nibp);
67 for(int idx=0; idx<nibp; idx++) {
68 IBP* ibp;
69 if(IBPmethod==0) ibp = new IBP();
70 else if(IBPmethod==1) ibp = new FIRE();
71 else if(IBPmethod==2) ibp = new KIRA();
72 else if(IBPmethod==3) ibp = new UKIRA();
73 else ibp = new IBP();
74 ex ibp_from = garRead(save_dir+"/AIR2F/ibp-"+to_string(idx)+".gar");
75 ibp->FROM(ibp_from);
76 ibp_vec[idx] = ibp;
77 }
78 }
79
80 }
81
87 ex F2ex(const ex & expr_in) {
88 ex ret = expr_in;
89 ret = MapFunction([](const ex & e, MapFunction &self)->ex{
90 if(!e.has(F(w1,w2))) return e;
91 else if(e.match(F(w1, w2))) {
92 auto ps = e.op(0);
93 auto ns = e.op(1);
94 ex res = 1;
95 for(int i=0; i<ps.nops(); i++) res *= pow(ps.op(i), ex(0)-ns.op(i));
96 return res;
97 } else return e.map(self);
98 })(ret);
99 return ret;
100 }
101
109 void ApartIBP(exvector &air_vec, AIOption aio) {
110
111 if(aio.smap.size()<1) aio.init_smap();
112 int IBPmethod = aio.IBPmethod;
113 int rc;
114
115 lst lmom = ex_to<lst>(aio.Internal);
116 lst emom = ex_to<lst>(aio.External);
117
118 string wdir;
119 if(aio.SaveDir != "") {
120 if(IBPmethod==1) wdir = aio.SaveDir + "/FIRE";
121 else if(IBPmethod==2) wdir = aio.SaveDir + "/KIRA";
122 else if(IBPmethod==3) wdir = aio.SaveDir + "/UKIRA";
123 } else {
124 wdir = to_string(getpid());
125 if(IBPmethod==1) wdir = wdir + "_FIRE";
126 else if(IBPmethod==2) wdir = wdir + "_KIRA";
127 else if(IBPmethod==3) wdir = wdir + "_UKIRA";
128 }
129
130 lst IntFs;
131 vector<IBP*> ibp_vec;
132 if(aio.SaveDir != "" && file_exists(aio.SaveDir+"/AIR2F.gar")) {
133 if(Verbose > 1) cout << PRE << "\\--Reading AIR2F" << flush;
134 AIR2F_Get(aio.SaveDir, air_vec, IntFs, ibp_vec, IBPmethod);
135 for(auto ibp : ibp_vec) ibp->WorkingDir = wdir; // update working directory
136 if(Verbose > 1) cout << " @ " << now(false) << endl;
137 goto AIR2F_Done;
138 }
139
140 if(aio.SaveDir != "") {
141 if(file_exists(aio.SaveDir+"/AP.gar")) {
142 if(Verbose > 1) cout << PRE << "\\--Reading AP.gar" << flush;
143 garRead(air_vec, aio.SaveDir+"/AP.gar");
144 if(Verbose > 1) cout << " @ " << now(false) << endl;
145 goto Apart_Done;
146 } else rc = system(("mkdir -p "+aio.SaveDir).c_str());
147 }
148
149 if(true) {
150 int av_size = air_vec.size();
151 air_vec = GiNaC_Parallel(av_size, [air_vec,lmom] (int idx) {
152 return collect_lst(air_vec[idx], lmom); // o_flint
153 }, "ApPre");
154
155 exset vset;
156 for(int i=0; i<av_size; i++) {
157 for(auto cv : ex_to<lst>(air_vec[i])) vset.insert(cv.op(1));
158 }
159 exvector vvec(vset.begin(), vset.end());
160 vset.clear();
161
162 exmap v2api;
163 for(int i=0; i<vvec.size(); i++) v2api[vvec[i]] = i;
164 for(int i=0; i<av_size; i++) {
165 lst av_item;
166 lst cvs = ex_to<lst>(air_vec[i]);
167 air_vec[i] = av_item;
168 for(auto & cv : cvs) av_item.append(lst{cv.op(0), v2api[cv.op(1)]});
169 cvs.remove_all();
170 air_vec[i] = av_item;
171 }
172 v2api.clear();
173
174 auto ap_vec = GiNaC_Parallel(vvec.size(), [&vvec,lmom,emom,aio] (int idx) {
175 auto air = vvec[idx];
176 air = Apart(air,lmom,emom,aio.smap);
177 air = air.subs(ApartIR(1,w)==aio.apart1);
178 air = collect_lst(air, ApartIR(w1,w2), o_flintf);
179 return air;
180 }, "Apart");
181 vvec.clear();
182
183 exset ap_set;
184 for(auto cvs : ap_vec) for(auto cv : cvs) if(is_a<matrix>(cv.op(1).op(0))) ap_set.insert(cv.op(1));
185 exvector ap_ir_vec(ap_set.begin(), ap_set.end());
186 ap_set.clear();
187 exmap ap_rules;
188 if(aio.ap_rules) ap_rules = ApartRules(ap_ir_vec); // including ApartIRC
189 ap_ir_vec.clear();
190
191 if(false) { // Parallel Version
192 ap_vec = GiNaC_Parallel(ap_vec.size(), [&aio,&ap_vec,&ap_rules] (int idx) {
193 auto const & cvs = ap_vec[idx];
194 ex res = 0;
195 if(aio.ap_rules) {
196 for(auto const & cv : cvs) {
197 auto fi = ap_rules.find(cv.op(1));
198 if(fi==ap_rules.end()) res += cv.op(0) * cv.op(1);
199 else res += cv.op(0) * fi->second;
200 }
201 } else {
202 for(auto cv : cvs) res += cv.op(0) * ApartIRC(cv.op(1));
203 }
204 return res;
205 }, "ApRule");
206 } else {
207 int vn = ap_vec.size();
208 for(int idx=0; idx<vn; idx++) {
209 lst cvs = ex_to<lst>(ap_vec[idx]);
210 ex res = 0;
211 if(aio.ap_rules) {
212 for(auto const & cv : cvs) {
213 auto fi = ap_rules.find(cv.op(1));
214 if(fi==ap_rules.end()) res += cv.op(0) * cv.op(1);
215 else res += cv.op(0) * fi->second;
216 }
217 } else {
218 for(auto cv : cvs) res += cv.op(0) * ApartIRC(cv.op(1));
219 }
220 ap_vec[idx] = res;
221 }
222 }
223 ap_rules.clear();
224
225 if(GiNaC_Parallel_NP.find("ApPost")==GiNaC_Parallel_NP.end() && CpuCores()>8) GiNaC_Parallel_NP["ApPost"] = 8;
226 if(GiNaC_Parallel_NB.find("ApPost")==GiNaC_Parallel_NB.end() && CpuCores()>100) GiNaC_Parallel_NB["ApPost"] = 100;
227 air_vec = GiNaC_Parallel(av_size, [&air_vec,&ap_vec] (int idx) {
228 lst cvs = ex_to<lst>(air_vec[idx]);
229 ex res = 0;
230 for(auto const & cv : cvs) {
231 int idx = ex_to<numeric>(cv.op(1)).to_int();
232 res += cv.op(0) * ap_vec[idx];
233 }
234 res = collect_ex(res, ApartIR(w1,w2)); // o_flint
235 return res; // air_vec updated to ApartIR
236 }, "ApPost");
237 ap_vec.clear();
238
239 if(aio.SaveDir != "") {
240 garWrite(air_vec,aio.SaveDir+"/AP.gar");
241 garRead(air_vec,aio.SaveDir+"/AP.gar");
242 }
243 }
244 Apart_Done: ;
245
246 if(true) {
247
248 exvector AIR;
249 if(true) {
250 auto ret = GiNaC_Parallel(air_vec.size(), [&air_vec](int idx)->ex {
251 auto air = air_vec[idx];
252 exset airs;
253 find(air, ApartIR(w1,w2), airs);
254 lst ret;
255 for(auto item : airs) ret.append(item);
256 return ret;
257 }, "ApIRC");
258 exset intg;
259 for(auto airs : ret) for(auto air : ex_to<lst>(airs)) intg.insert(air);
260 AIR = exvector(intg.begin(), intg.end());
261 }
262
263 for(auto sp : aio.CSP) SP_map.erase(sp);
264 // from here, Vector will be replaced by its name Symbol
265
266 lst repls;
267 auto sps = sp_map();
268 for(auto kv : sps) {
269 repls.append(w*kv.first == w*kv.second);
270 repls.append(kv.first == kv.second);
271 }
272
273 lst loops, exts; // to match FIRE notation, not Vector, just Symbol
274 for(auto li : lmom) {
275 if(is_a<Vector>(li)) loops.append(ex_to<Vector>(li).name);
276 else loops.append(li);
277 }
278 for(auto li : emom) {
279 if(is_a<Vector>(li)) exts.append(ex_to<Vector>(li).name);
280 else exts.append(li);
281 }
282
283 if(Verbose>0) cout << PRE << "\\--Prepare " << WHITE << "IBP" << RESET << " reduction @ " << now(false) << flush;
284
285 exmap AIR2F;
286 std::map<ex, IBP*, ex_is_less> p2IBP;
287 int pn=1;
288 int ntot = AIR.size();
289 for(int i=0; i<ntot; i++) {
290 if(Verbose>0 && (((i+1)%1000)==0 || i+1==ntot)) {
291 cout << "\r \r" << flush;
292 cout << PRE << "\\--Prepare " << WHITE << "IBP" << RESET << " reduction [" << (i+1) << "/" << ntot << "] @ " << now(false) << flush;
293 }
294 auto const & ir = AIR[i];
295 auto mat = ex_to<matrix>(ir.op(0));
296 auto vars = ex_to<lst>(ir.op(1));
297 lst pns;
298 int nrow = mat.rows();
299 int den_tot = 0;
300 for(int c=0; c<mat.cols(); c++) {
301 ex pc = 0;
302 for(int r=0; r<nrow-2; r++) pc += mat(r,c) * vars.op(r);
303 pc += mat(nrow-2,c);
304 pc = SP2sp(pc);
305 ex nc = ex(0)-mat(nrow-1,c);
306 int ncn;
307 if(nc>0) ncn = -1;
308 else ncn = 1;
309 if(ncn==-1) den_tot++;
310 pns.append(lst{ ncn, pc, nc }); // note the convension, ncn just for sorting
311 }
312 bool pn_sector = false;
313 if(aio.pn_sector>0 && den_tot>=aio.pn_sector) pn_sector = true;
314 if(!pn_sector) { // back to original format
315 for(int i=0; i<pns.nops(); i++) pns[i] = lst{ pns.op(i).op(1), pns.op(i).op(2) };
316 }
317 sort_lst(pns);
318 if(pn_sector) { // back to original format
319 for(int i=0; i<pns.nops(); i++) pns[i] = lst{ pns.op(i).op(1), pns.op(i).op(2) };
320 }
321
322 int nCut = aio.Cut.nops();
323 if(nCut>0) {
324 ex cuts = aio.Cut;
325 cuts = cuts.subs(SP_map,nopat);
326 if(aio.CutFirst) for(auto cut : cuts) pns.prepend(lst{ SP2sp(cut), 1 });
327 else for(auto cut : cuts) pns.append(lst{ SP2sp(cut), 1 });
328 }
329
330 lst props, ns;
331 for(auto item : pns) {
332 props.append(item.op(0));
333 ns.append(item.op(1));
334 }
335
336 ex key = props;
337 if(pn_sector) {
338 lst nss;
339 for(int i=0; i<ns.nops(); i++) nss.append(ns.op(i)>0 ? 1 : 0);
340 key = lst{props,nss};
341 }
342
343 auto kv = p2IBP.find(key);
344 if(kv==p2IBP.end()) {
345 IBP* ibp;
346 if(IBPmethod==0) ibp = new IBP();
347 else if(IBPmethod==1) ibp = new FIRE();
348 else if(IBPmethod==2) ibp = new KIRA();
349 else if(IBPmethod==3) ibp = new UKIRA();
350 else {
351 ibp = new IBP();
352 IBPmethod = 0;
353 }
354
355 p2IBP.insert(make_pair(key,ibp));
356 ibp->Propagator = props;
357 ibp->Internal = loops;
358 ibp->External = exts;
359 ibp->Replacement = repls;
360 if(aio.ISP.nops()>0) for(auto item : aio.ISP) ibp->ISP.append(SP2sp(item));
361 if(aio.DSP.nops()>0) {
362 for(auto item : aio.DSP) {
363 lst sp = ex_to<lst>(item);
364 if(is_a<Vector>(sp.op(0))) sp[0] = (ex_to<Vector>(sp.op(0)).name);
365 if(is_a<Vector>(sp.op(1))) sp[1] = (ex_to<Vector>(sp.op(1)).name);
366 ibp->DSP.append(sp);
367 }
368 }
369 if(pn_sector) {
370 lst sector;
371 for(auto const & item : ns) {
372 if(item>0) sector.append(1);
373 else sector.append(0);
374 }
375 ibp->SECTOR = sector;
376 }
377 ibp->WorkingDir = wdir;
378 ibp->ProblemNumber = pn;
379 pn++;
380 if(nCut>0) {
381 if(aio.CutFirst) for(int i=0; i<nCut; i++) ibp->Cut.append(i+1);
382 else for(int i=0; i<nCut; i++) ibp->Cut.append(nCut-i);
383 }
384 ibp_vec.push_back(ibp);
385 ibp->Integral.append(ns);
386 AIR2F[AIR[i]] = F(ibp->ProblemNumber, ns);
387 } else {
388 IBP* ibp = kv->second;
389 ibp->Integral.append(ns);
390 AIR2F[AIR[i]] = F(ibp->ProblemNumber, ns);
391 }
392 }
393 if(Verbose>0) cout << endl;
394
395 if(Verbose>0) cout << PRE << "\\--Total Ints/Pros: " << WHITE << ntot << "/" << ibp_vec.size() << RESET << " @ " << now(false) << endl;
396
397 if(true) {
398 //vector<IBP*> ibp_vec2;
399 //for(auto ibp : ibp_vec) ibp_vec2.push_back(ibp);
400 auto int_fr = FindRules(ibp_vec, false, aio.UF);
401 IntFs = int_fr.second;
402 if(GiNaC_Parallel_NP.find("AIR2F")==GiNaC_Parallel_NP.end() && CpuCores()>8) GiNaC_Parallel_NP["AIR2F"] = 8;
403 if(GiNaC_Parallel_NB.find("AIR2F")==GiNaC_Parallel_NB.end() && CpuCores()>100) GiNaC_Parallel_NB["AIR2F"] = 100;
404 air_vec = GiNaC_Parallel(air_vec.size(), [&air_vec,&AIR2F,&int_fr] (int idx) {
405 auto air = air_vec[idx];
406 air = air.subs(AIR2F,nopat);
407 air = air.subs(int_fr.first,nopat);
408 air = collect_ex(air, F(w1,w2)); // o_flint
409 return air;
410 }, "AIR2F");
411 if(aio.SaveDir != "") AIR2F_Save(aio.SaveDir, air_vec, IntFs, ibp_vec);
412 }
413 }
414 AIR2F_Done: ;
415
416 MapFunction _F2ex([&ibp_vec,aio](const ex &e, MapFunction &self)->ex {
417 if(!e.has(F(w1,w2))) return e;
418 else if(e.match(F(w1,w2))) {
419 int pn = ex_to<numeric>(e.op(0)).to_int();
420 auto pso = ex_to<lst>(ibp_vec[pn-1]->Propagator);
421 auto nso = ex_to<lst>(e.op(1));
422 lst ps, ns;
423 for(int i=0; i<pso.nops(); i++) {
424 if(!aio.keep0F && nso.op(i).is_zero()) continue;
425 ps.append(pso.op(i));
426 ns.append(nso.op(i));
427 }
428 return F(ps,ns);
429 } else return e.map(self);
430 });
431
432 if(IBPmethod==0) { // no IBP reduction
433 air_vec = GiNaC_Parallel(air_vec.size(), [&air_vec,&_F2ex](int idx)->ex {
434 auto res = air_vec[idx];
435 return _F2ex(res);
436 }, "F2F");
437 for(auto fp : ibp_vec) delete fp;
438 if(aio.SaveDir == "") rc = system(("rm -rf "+wdir).c_str());
439 return;
440 }
441
442 exmap ibpRules; // IBP rules for problem pn
443 if(aio.SaveDir != "" && file_exists(aio.SaveDir+"/Rules.gar")) {
444 goto Rules_Done;
445 }
446 if(true) {
447 vector<IBP*> ibp_vec_re;
448 if(true) {
449 map<int,lst> pn_ints_map;
450 for(auto item : IntFs) {
451 int pn = ex_to<numeric>(item.op(0)).to_int();
452 pn_ints_map[pn].append(item.op(1));
453 }
454
455 int nints = 0;
456 for(auto pi : pn_ints_map) {
457 auto ibp = ibp_vec[pi.first-1];
458 ibp->Integral = pi.second;
459 nints += ibp->Integral.nops();
460 ibp_vec_re.push_back(ibp);
461 }
462
463 if(Verbose>0) cout << PRE << "\\--Refined Ints/Pros: " << WHITE << nints << "/" << ibp_vec_re.size() << RESET << " @ " << now(false) << endl;
464 }
465
466 if(IBPmethod==1) {
467 //if(GiNaC_Parallel_NB.find("Expo")==GiNaC_Parallel_NB.end()) GiNaC_Parallel_NB["Expo"] = 1;
468 auto pRes = GiNaC_Parallel(ibp_vec_re.size(), [&ibp_vec_re](int idx)->ex {
469 ibp_vec_re[idx]->Export();
470 auto ret = lst{ ibp_vec_re[idx]->IsAlwaysZero ? 1 : 0, ibp_vec_re[idx]->Rules };
471 return ret;
472 }, "Expo");
473 for(int i=0; i<ibp_vec_re.size(); i++) {
474 ibp_vec_re[i]->IsAlwaysZero = (pRes[i].op(0)==1 ? true : false);
475 ibp_vec_re[i]->Rules = ex_to<lst>(pRes[i].op(1));
476 }
477
478 int nproc = aio.NIBP;
479 if(nproc<1) nproc = 8;
480 int cproc = 0;
481 if(nproc<1) nproc = 1;
482 size_t nibp = ibp_vec_re.size();
483
484 //#define using_openMP
485 #ifdef using_openMP
486 #pragma omp parallel for num_threads(nproc) schedule(dynamic, 1)
487 for(int pi=0; pi<nibp; pi++) {
488 if(Verbose>1) {
489 #pragma omp critical
490 {
491 cout << "\r \r" << flush;
492 cout << PRE << "\\--" << WHITE << "FIRE" << RESET << " Reduction [" << (++cproc) << "/" << nibp << "] " << flush;
493 }
494 }
495 ibp_vec_re[pi]->Run();
496 }
497 if(Verbose>1 && nibp>0) cout << "@" << now(false) << endl;
498 #else
499 if(nproc>1) {
500 if(GiNaC_Parallel_NP.find("FIRE")==GiNaC_Parallel_NB.end()) GiNaC_Parallel_NP["FIRE"] = nproc;
501 if(GiNaC_Parallel_NB.find("FIRE")==GiNaC_Parallel_NB.end()) GiNaC_Parallel_NB["FIRE"] = 1;
502 GiNaC_Parallel(nibp, [&ibp_vec_re](int idx)->ex {
503 ibp_vec_re[idx]->Run();
504 return 0;
505 }, "FIRE");
506 } else {
507 for(int pi=0; pi<nibp; pi++) {
508 if(Verbose>1) cout << "\r \r" << PRE << "\\--" << WHITE << "FIRE" << RESET << " Reduction [" << (++cproc) << "/" << nibp << "] " << flush;
509 ibp_vec_re[pi]->Run();
510 }
511 if(Verbose>1 && nibp>0) cout << "@" << now(false) << endl;
512 }
513 #endif
514
515 if(ibp_vec_re.size()>100) {
516 auto ret = GiNaC_Parallel(ibp_vec_re.size(), [&ibp_vec_re,wdir](int idx)->ex {
517 ibp_vec_re[idx]->Import();
518 return ibp_vec_re[idx]->TO();
519 }, "Impo");
520 for(int i=0; i<ibp_vec_re.size(); i++) ibp_vec_re[i]->FROM(ret[i]);
521 } else {
522 cproc = 0;
523 for(auto item : ibp_vec_re) {
524 if(Verbose>1) cout << "\r \r" << PRE << "\\--" << WHITE << "FIRE" << RESET << " Import [" << (++cproc) << "/" << ibp_vec_re.size() << "] " << flush;
525 item->Import();
526 }
527 if(Verbose>1 && ibp_vec_re.size()>0) cout << "@" << now(false) << endl;
528 }
529 //IBP::ReShare(ibp_vec_re);
530
531 if(aio.SaveDir == "") rc = system(("rm -rf "+wdir).c_str());
532 } else if(IBPmethod==2 || IBPmethod==3) {
533 for(auto ibp : ibp_vec_re) ibp->Reduce();
534 if(aio.SaveDir == "") rc = system(("rm -rf "+wdir).c_str());
535 }
536
537 // Find Rules in MIs
538 exmap miRules = FindRules(ibp_vec_re, true, aio.UF).first;
539 if(true) { // scope for ret
540 if(aio.SaveDir != "") rc = system(("mkdir -p "+aio.SaveDir+"/Rules").c_str());
541 auto rules_vec = GiNaC_Parallel(ibp_vec_re.size(), [&ibp_vec_re,&miRules,&aio](int idx)->ex {
542 lst rules = ex_to<lst>(ibp_vec_re[idx]->Rules);
543 lst res;
544 for(auto ri : rules) res.append(lst {
545 ri.op(0),
546 collect_ex(ri.op(1).subs(miRules,nopat),F(w1,w2),o_flint)
547 });
548 for(auto mi : ibp_vec_re[idx]->MIntegral) {
549 auto fi = miRules.find(mi);
550 if(fi!=miRules.end()) res.append(lst{ mi, fi->second });
551 }
552 auto pn = ibp_vec_re[idx]->ProblemNumber;
553 if(aio.SaveDir != "") {
554 garWrite(aio.SaveDir+"/Rules/"+to_string(pn)+".gar", res);
555 return 0;
556 } else return res;
557 }, "FR2MI");
558 if(aio.SaveDir != "") {
559 garWrite(aio.SaveDir+"/Rules.gar", 1);
560 } else {
561 for(auto rs : rules_vec) {
562 for(auto ri : rs) if(ri.op(0)!=ri.op(1)) ibpRules[ri.op(0)] = ri.op(1);
563 }
564 }
565 }
566 }
567 Rules_Done: ;
568
569 if(GiNaC_Parallel_NP.find("F2MI")==GiNaC_Parallel_NP.end() && CpuCores()>16) GiNaC_Parallel_NP["F2MI"] = 16;
570 air_vec =
571 GiNaC_Parallel(air_vec.size(), [&air_vec,&ibpRules,&_F2ex,&aio](int idx)->ex {
572 ex res = air_vec[idx];
573 exmap rules;
574 if(aio.SaveDir != "") {
575 exset fs;
576 find(res, F(w1,w2), fs);
577 exset pns;
578 for(auto fi : fs) pns.insert(fi.op(0));
579 for(auto pn : pns) {
580 auto rs = ex_to<lst>(garRead(aio.SaveDir+"/Rules/"+ex2str(pn)+".gar"));
581 for(auto ri : rs) if(ri.op(0)!=ri.op(1)) rules[ri.op(0)] = ri.op(1);
582 }
583 } else rules = ibpRules;
584 res = res.subs(rules,nopat);
585 if(aio.pat.nops()>0) {
586 auto cvs = collect_lst(res, aio.pat);
587 res = 0;
588 for(auto cv : cvs) {
589 auto c = cv.op(0);
590 auto v = cv.op(1);
591 if(aio.cv!=nullptr) {
592 auto _cv = aio.cv(c,v);
593 c = _cv.op(0);
594 v = _cv.op(1);
595 }
596 res += c * v;
597 }
598 }
599 return _F2ex(res);
600 }, "F2MI");
601
602 for(auto fp : ibp_vec) delete fp;
603 }
604
615 void ApartIBP(exvector &air_vec, int IBPmethod, const lst & loops, const lst & exts, const lst & cut_props,
616 std::function<lst(const IBP &, const ex &)> uf) {
617
618 AIOption aio;
619 aio.IBPmethod = IBPmethod;
620 //aio.pn_sector = 4;
621 aio.Internal = loops;
622 aio.External = exts;
623 aio.Cut = cut_props;
624 if(cut_props.nops()>0) {
625 for(auto p1 : loops) {
626 for(auto p2 : loops) aio.CSP.append(SP(p1,p2));
627 for(auto p2 : exts) aio.CSP.append(SP(p1,p2));
628 }
629 aio.CSP.sort();
630 aio.CSP.unique();
631 }
632 for(auto li : loops) aio.smap[SP(li)] = 1;
633 aio.UF = uf;
634 ApartIBP(air_vec, aio);
635 }
636
637}
#define WHITE
Definition BASIC.h:87
#define RESET
Definition BASIC.h:79
HEP header file.
int pn
Definition Others.cpp:25
lst intg
Definition Others.cpp:26
bool file_exists(const char *fn)
Definition Process.cpp:9
IBP base class for IBP reduction.
Definition IBP.h:24
class to wrap map_function of GiNaC
Definition BASIC.h:675
HepLib namespace.
Definition BASIC.cpp:17
ex SP2sp(const ex &exin)
convert SP(a,b) to sp(a,b)
Definition Pair.cpp:302
ex sp(const ex &a, const ex &b)
translated the vector dot a.b to a*b, useful in SecDec
Definition Pair.cpp:237
exmap sp_map()
the SP_map with SP(a,b) replaced to sp(a,b)
Definition Pair.cpp:318
exmap SP_map
Definition Init.cpp:184
ex ApartIRC(const ex &expr_in)
complete the ApartIR elements
Definition Apart.cpp:915
void ApartIBP(exvector &air_vec, AIOption aio)
perform IBP reduction on the Aparted input
Definition ApartIBP.cpp:109
ex collect_ex(ex const &expr_in, std::function< bool(const ex &)> has_func, int opt)
the collect function like Mathematica
Definition BASIC.cpp:1204
void garRead(const string &garfn, map< string, ex > &resMap)
garRead from file, and output in a map
Definition BASIC.cpp:593
map< string, int > GiNaC_Parallel_NB
Definition Init.cpp:150
bool file_exists(string fn)
Definition BASIC.h:289
pair< exmap, lst > FindRules(vector< IBP * > fs, bool mi, std::function< lst(const IBP &, const ex &)> uf)
Find Rules for Integral or Master Integral.
Definition IBP.cpp:574
string now(bool use_date)
date/time string
Definition BASIC.cpp:527
ex F2ex(const ex &expr_in)
convert F(ps, ns) to normal ex, ns is like FIRE convention
Definition ApartIBP.cpp:87
int CpuCores()
return the cpu cores using OpenMP
Definition BASIC.cpp:1822
map< string, int > GiNaC_Parallel_NP
Definition Init.cpp:147
lst collect_lst(ex const &expr_in, std::function< bool(const ex &)> has_func, int opt)
the collect function like Mathematica, reture the lst { {c1,v1}, {c2,v2}, ... }
Definition BASIC.cpp:1224
exmap ApartRules(const exvector &airs, bool irc)
Definition Apart.cpp:156
int Verbose
Definition Init.cpp:142
void sort_lst(lst &ilst, bool less=true)
sort the list in less order, or the reverse
Definition Sort.cpp:79
void garWrite(const string &garfn, const map< string, ex > &resMap)
garWrite to write the string-key map to the archive
Definition BASIC.cpp:641
ex w1
Definition BASIC.h:499
exvector GiNaC_Parallel(int ntotal, std::function< ex(int)> f, const string &key)
GiNaC Parallel Evaluation using fork.
Definition BASIC.cpp:260
ex w2
Definition BASIC.h:499
string PRE
Definition Init.cpp:143
ex SP(const ex &a, bool use_map=false)
Definition Pair.cpp:166
std::function< lst(const IBP &, const ex &)> UF
Definition HEP.h:620
exmap smap
Definition HEP.h:609
string SaveDir
Definition HEP.h:619
int IBPmethod
Definition HEP.h:605
bool ap_rules
Definition HEP.h:604
void init_smap()
Definition HEP.h:621