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 if(aio.SaveDir != "" && file_exists(aio.SaveDir+"/ApartIBP.gar")) {
119 if(Verbose > 1) cout << PRE << "\\--Reading ApartIBP" << flush;
120 garRead(air_vec, aio.SaveDir+"/ApartIBP.gar");
121 return;
122 }
123
124 string wdir;
125 if(aio.SaveDir != "") {
126 if(IBPmethod==1) wdir = aio.SaveDir + "/FIRE";
127 else if(IBPmethod==2) wdir = aio.SaveDir + "/KIRA";
128 else if(IBPmethod==3) wdir = aio.SaveDir + "/UKIRA";
129 } else {
130 wdir = to_string(getpid());
131 if(IBPmethod==1) wdir = wdir + "_FIRE";
132 else if(IBPmethod==2) wdir = wdir + "_KIRA";
133 else if(IBPmethod==3) wdir = wdir + "_UKIRA";
134 }
135
136 lst IntFs;
137 vector<IBP*> ibp_vec;
138 if(aio.SaveDir != "" && file_exists(aio.SaveDir+"/AIR2F.gar")) {
139 if(Verbose > 1) cout << PRE << "\\--Reading AIR2F" << flush;
140 AIR2F_Get(aio.SaveDir, air_vec, IntFs, ibp_vec, IBPmethod);
141 for(auto ibp : ibp_vec) ibp->WorkingDir = wdir; // update working directory
142 if(Verbose > 1) cout << " @ " << now(false) << endl;
143 goto AIR2F_Done;
144 }
145
146 if(aio.SaveDir != "") {
147 if(file_exists(aio.SaveDir+"/AP.gar")) {
148 if(Verbose > 1) cout << PRE << "\\--Reading AP.gar" << flush;
149 garRead(air_vec, aio.SaveDir+"/AP.gar");
150 if(Verbose > 1) cout << " @ " << now(false) << endl;
151 goto Apart_Done;
152 } else rc = system(("mkdir -p "+aio.SaveDir).c_str());
153 }
154
155 if(true) {
156 int av_size = air_vec.size();
157 air_vec = GiNaC_Parallel(av_size, [air_vec,lmom] (int idx) {
158 return collect_lst(air_vec[idx], lmom); // o_flint
159 }, "ApPre");
160
161 exset vset;
162 for(int i=0; i<av_size; i++) {
163 for(auto cv : ex_to<lst>(air_vec[i])) vset.insert(cv.op(1));
164 }
165 exvector vvec(vset.begin(), vset.end());
166 vset.clear();
167
168 exmap v2api;
169 for(int i=0; i<vvec.size(); i++) v2api[vvec[i]] = i;
170 for(int i=0; i<av_size; i++) {
171 lst av_item;
172 lst cvs = ex_to<lst>(air_vec[i]);
173 air_vec[i] = av_item;
174 for(auto & cv : cvs) av_item.append(lst{cv.op(0), v2api[cv.op(1)]});
175 cvs.remove_all();
176 air_vec[i] = av_item;
177 }
178 v2api.clear();
179
180 auto ap_vec = GiNaC_Parallel(vvec.size(), [&vvec,lmom,emom,aio] (int idx) {
181 auto air = vvec[idx];
182 air = Apart(air,lmom,emom,aio.smap);
183 air = air.subs(ApartIR(1,w)==aio.apart1);
184 air = collect_lst(air, ApartIR(w1,w2), o_flintf);
185 return air;
186 }, "Apart");
187 vvec.clear();
188
189 exset ap_set;
190 for(auto cvs : ap_vec) for(auto cv : cvs) if(is_a<matrix>(cv.op(1).op(0))) ap_set.insert(cv.op(1));
191 exvector ap_ir_vec(ap_set.begin(), ap_set.end());
192 ap_set.clear();
193 exmap ap_rules;
194 if(aio.ap_rules) ap_rules = ApartRules(ap_ir_vec); // including ApartIRC
195 ap_ir_vec.clear();
196
197 if(false) { // Parallel Version
198 ap_vec = GiNaC_Parallel(ap_vec.size(), [&aio,&ap_vec,&ap_rules] (int idx) {
199 auto const & cvs = ap_vec[idx];
200 ex res = 0;
201 if(aio.ap_rules) {
202 for(auto const & cv : cvs) {
203 auto fi = ap_rules.find(cv.op(1));
204 if(fi==ap_rules.end()) res += cv.op(0) * cv.op(1);
205 else res += cv.op(0) * fi->second;
206 }
207 } else {
208 for(auto cv : cvs) res += cv.op(0) * ApartIRC(cv.op(1));
209 }
210 return res;
211 }, "ApRule");
212 } else {
213 int vn = ap_vec.size();
214 for(int idx=0; idx<vn; idx++) {
215 lst cvs = ex_to<lst>(ap_vec[idx]);
216 ex res = 0;
217 if(aio.ap_rules) {
218 for(auto const & cv : cvs) {
219 auto fi = ap_rules.find(cv.op(1));
220 if(fi==ap_rules.end()) res += cv.op(0) * cv.op(1);
221 else res += cv.op(0) * fi->second;
222 }
223 } else {
224 for(auto cv : cvs) res += cv.op(0) * ApartIRC(cv.op(1));
225 }
226 ap_vec[idx] = res;
227 }
228 }
229 ap_rules.clear();
230
231 if(GiNaC_Parallel_NP.find("ApPost")==GiNaC_Parallel_NP.end() && CpuCores()>8) GiNaC_Parallel_NP["ApPost"] = 8;
232 if(GiNaC_Parallel_NB.find("ApPost")==GiNaC_Parallel_NB.end() && CpuCores()>100) GiNaC_Parallel_NB["ApPost"] = 100;
233 air_vec = GiNaC_Parallel(av_size, [&air_vec,&ap_vec] (int idx) {
234 lst cvs = ex_to<lst>(air_vec[idx]);
235 ex res = 0;
236 for(auto const & cv : cvs) {
237 int idx = ex_to<numeric>(cv.op(1)).to_int();
238 res += cv.op(0) * ap_vec[idx];
239 }
240 res = collect_ex(res, ApartIR(w1,w2)); // o_flint
241 return res; // air_vec updated to ApartIR
242 }, "ApPost");
243 ap_vec.clear();
244
245 if(aio.SaveDir != "") {
246 garWrite(air_vec,aio.SaveDir+"/AP.gar");
247 garRead(air_vec,aio.SaveDir+"/AP.gar");
248 }
249 }
250 Apart_Done: ;
251
252 if(true) {
253
254 exvector AIR;
255 if(true) {
256 auto ret = GiNaC_Parallel(air_vec.size(), [&air_vec](int idx)->ex {
257 auto air = air_vec[idx];
258 exset airs;
259 find(air, ApartIR(w1,w2), airs);
260 lst ret;
261 for(auto item : airs) ret.append(item);
262 return ret;
263 }, "ApIRC");
264 exset intg;
265 for(auto airs : ret) for(auto air : ex_to<lst>(airs)) intg.insert(air);
266 AIR = exvector(intg.begin(), intg.end());
267 }
268
269 for(auto sp : aio.CSP) SP_map.erase(sp);
270 // from here, Vector will be replaced by its name Symbol
271
272 lst repls;
273 auto sps = sp_map();
274 for(auto kv : sps) {
275 repls.append(w*kv.first == w*kv.second);
276 repls.append(kv.first == kv.second);
277 }
278
279 lst loops, exts; // to match FIRE notation, not Vector, just Symbol
280 for(auto li : lmom) {
281 if(is_a<Vector>(li)) loops.append(ex_to<Vector>(li).name);
282 else loops.append(li);
283 }
284 for(auto li : emom) {
285 if(is_a<Vector>(li)) exts.append(ex_to<Vector>(li).name);
286 else exts.append(li);
287 }
288
289 if(Verbose>0) cout << PRE << "\\--Prepare " << WHITE << "IBP" << RESET << " reduction @ " << now(false) << flush;
290
291 exmap AIR2F;
292 std::map<ex, IBP*, ex_is_less> p2IBP;
293 int pn=1;
294 int ntot = AIR.size();
295 for(int i=0; i<ntot; i++) {
296 if(Verbose>0 && (((i+1)%1000)==0 || i+1==ntot)) {
297 cout << "\r \r" << flush;
298 cout << PRE << "\\--Prepare " << WHITE << "IBP" << RESET << " reduction [" << (i+1) << "/" << ntot << "] @ " << now(false) << flush;
299 }
300 auto const & ir = AIR[i];
301 auto mat = ex_to<matrix>(ir.op(0));
302 auto vars = ex_to<lst>(ir.op(1));
303 lst pns;
304 int nrow = mat.rows();
305 int den_tot = 0;
306 for(int c=0; c<mat.cols(); c++) {
307 ex pc = 0;
308 for(int r=0; r<nrow-2; r++) pc += mat(r,c) * vars.op(r);
309 pc += mat(nrow-2,c);
310 pc = SP2sp(pc);
311 ex nc = ex(0)-mat(nrow-1,c);
312 int ncn;
313 if(nc>0) ncn = -1;
314 else ncn = 1;
315 if(ncn==-1) den_tot++;
316 pns.append(lst{ ncn, pc, nc }); // note the convension, ncn just for sorting
317 }
318 bool pn_sector = false;
319 if(aio.pn_sector>0 && den_tot>=aio.pn_sector) pn_sector = true;
320 if(!pn_sector) { // back to original format
321 for(int i=0; i<pns.nops(); i++) pns[i] = lst{ pns.op(i).op(1), pns.op(i).op(2) };
322 }
323 sort_lst(pns);
324 if(pn_sector) { // back to original format
325 for(int i=0; i<pns.nops(); i++) pns[i] = lst{ pns.op(i).op(1), pns.op(i).op(2) };
326 }
327
328 int nCut = aio.Cut.nops();
329 if(nCut>0) {
330 ex cuts = aio.Cut;
331 cuts = cuts.subs(SP_map,nopat);
332 if(aio.CutFirst) for(auto cut : cuts) pns.prepend(lst{ SP2sp(cut), 1 });
333 else for(auto cut : cuts) pns.append(lst{ SP2sp(cut), 1 });
334 }
335
336 lst props, ns;
337 for(auto item : pns) {
338 props.append(item.op(0));
339 ns.append(item.op(1));
340 }
341
342 ex key = props;
343 if(pn_sector) {
344 lst nss;
345 for(int i=0; i<ns.nops(); i++) nss.append(ns.op(i)>0 ? 1 : 0);
346 key = lst{props,nss};
347 }
348
349 auto kv = p2IBP.find(key);
350 if(kv==p2IBP.end()) {
351 IBP* ibp;
352 if(IBPmethod==0) ibp = new IBP();
353 else if(IBPmethod==1) ibp = new FIRE();
354 else if(IBPmethod==2) ibp = new KIRA();
355 else if(IBPmethod==3) ibp = new UKIRA();
356 else {
357 ibp = new IBP();
358 IBPmethod = 0;
359 }
360
361 p2IBP.insert(make_pair(key,ibp));
362 ibp->Propagator = props;
363 ibp->Internal = loops;
364 ibp->External = exts;
365 ibp->Replacement = repls;
366 if(aio.ISP.nops()>0) for(auto item : aio.ISP) ibp->ISP.append(SP2sp(item));
367 if(aio.DSP.nops()>0) {
368 for(auto item : aio.DSP) {
369 lst sp = ex_to<lst>(item);
370 if(is_a<Vector>(sp.op(0))) sp[0] = (ex_to<Vector>(sp.op(0)).name);
371 if(is_a<Vector>(sp.op(1))) sp[1] = (ex_to<Vector>(sp.op(1)).name);
372 ibp->DSP.append(sp);
373 }
374 }
375 if(pn_sector) {
376 lst sector;
377 for(auto const & item : ns) {
378 if(item>0) sector.append(1);
379 else sector.append(0);
380 }
381 ibp->SECTOR = sector;
382 }
383 ibp->WorkingDir = wdir;
384 ibp->ProblemNumber = pn;
385 pn++;
386 if(nCut>0) {
387 if(aio.CutFirst) for(int i=0; i<nCut; i++) ibp->Cut.append(i+1);
388 else for(int i=0; i<nCut; i++) ibp->Cut.append(nCut-i);
389 }
390 ibp_vec.push_back(ibp);
391 ibp->Integral.append(ns);
392 AIR2F[AIR[i]] = F(ibp->ProblemNumber, ns);
393 } else {
394 IBP* ibp = kv->second;
395 ibp->Integral.append(ns);
396 AIR2F[AIR[i]] = F(ibp->ProblemNumber, ns);
397 }
398 }
399 if(Verbose>0) cout << endl;
400
401 if(Verbose>0) cout << PRE << "\\--Total Ints/Pros: " << WHITE << ntot << "/" << ibp_vec.size() << RESET << " @ " << now(false) << endl;
402
403 if(true) {
404 //vector<IBP*> ibp_vec2;
405 //for(auto ibp : ibp_vec) ibp_vec2.push_back(ibp);
406 auto int_fr = FindRules(ibp_vec, false, aio.UF);
407 IntFs = int_fr.second;
408 if(GiNaC_Parallel_NP.find("AIR2F")==GiNaC_Parallel_NP.end() && CpuCores()>8) GiNaC_Parallel_NP["AIR2F"] = 8;
409 if(GiNaC_Parallel_NB.find("AIR2F")==GiNaC_Parallel_NB.end() && CpuCores()>100) GiNaC_Parallel_NB["AIR2F"] = 100;
410 air_vec = GiNaC_Parallel(air_vec.size(), [&air_vec,&AIR2F,&int_fr] (int idx) {
411 auto air = air_vec[idx];
412 air = air.subs(AIR2F,nopat);
413 air = air.subs(int_fr.first,nopat);
414 air = collect_ex(air, F(w1,w2)); // o_flint
415 return air;
416 }, "AIR2F");
417 if(aio.SaveDir != "") AIR2F_Save(aio.SaveDir, air_vec, IntFs, ibp_vec);
418 }
419 }
420 AIR2F_Done: ;
421
422 MapFunction _F2ex([&ibp_vec,aio](const ex &e, MapFunction &self)->ex {
423 if(!e.has(F(w1,w2))) return e;
424 else if(e.match(F(w1,w2))) {
425 int pn = ex_to<numeric>(e.op(0)).to_int();
426 auto pso = ex_to<lst>(ibp_vec[pn-1]->Propagator);
427 auto nso = ex_to<lst>(e.op(1));
428 lst ps, ns;
429 for(int i=0; i<pso.nops(); i++) {
430 if(!aio.keep0F && nso.op(i).is_zero()) continue;
431 ps.append(pso.op(i));
432 ns.append(nso.op(i));
433 }
434 return F(ps,ns);
435 } else return e.map(self);
436 });
437
438 if(IBPmethod==0) { // no IBP reduction
439 air_vec = GiNaC_Parallel(air_vec.size(), [&air_vec,&_F2ex](int idx)->ex {
440 auto res = air_vec[idx];
441 return _F2ex(res);
442 }, "F2F");
443 for(auto fp : ibp_vec) delete fp;
444 if(aio.SaveDir == "") rc = system(("rm -rf "+wdir).c_str());
445 return;
446 }
447
448 exmap ibpRules; // IBP rules for problem pn
449 if(aio.SaveDir != "" && file_exists(aio.SaveDir+"/MIs.gar")) {
450 goto Rules_Done;
451 }
452 if(true) {
453 vector<IBP*> ibp_vec_re;
454 if(true) {
455 map<int,lst> pn_ints_map;
456 for(auto item : IntFs) {
457 int pn = ex_to<numeric>(item.op(0)).to_int();
458 pn_ints_map[pn].append(item.op(1));
459 }
460
461 int nints = 0;
462 for(auto pi : pn_ints_map) {
463 auto ibp = ibp_vec[pi.first-1];
464 ibp->Integral = pi.second;
465 nints += ibp->Integral.nops();
466 ibp_vec_re.push_back(ibp);
467 }
468
469 if(Verbose>0) cout << PRE << "\\--Refined Ints/Pros: " << WHITE << nints << "/" << ibp_vec_re.size() << RESET << " @ " << now(false) << endl;
470 }
471
472 if(IBPmethod==1) {
473 //if(GiNaC_Parallel_NB.find("Expo")==GiNaC_Parallel_NB.end()) GiNaC_Parallel_NB["Expo"] = 1;
474 auto pRes = GiNaC_Parallel(ibp_vec_re.size(), [&ibp_vec_re](int idx)->ex {
475 ibp_vec_re[idx]->Export();
476 auto ret = lst{ ibp_vec_re[idx]->IsAlwaysZero ? 1 : 0, ibp_vec_re[idx]->Rules };
477 return ret;
478 }, "Expo");
479 for(int i=0; i<ibp_vec_re.size(); i++) {
480 ibp_vec_re[i]->IsAlwaysZero = (pRes[i].op(0)==1 ? true : false);
481 ibp_vec_re[i]->Rules = ex_to<lst>(pRes[i].op(1));
482 }
483
484 int nproc = aio.NIBP;
485 if(nproc<1) nproc = 8;
486 int cproc = 0;
487 if(nproc<1) nproc = 1;
488 size_t nibp = ibp_vec_re.size();
489
490 //#define using_openMP
491 #ifdef using_openMP
492 #pragma omp parallel for num_threads(nproc) schedule(dynamic, 1)
493 for(int pi=0; pi<nibp; pi++) {
494 if(Verbose>1) {
495 #pragma omp critical
496 {
497 cout << "\r \r" << flush;
498 cout << PRE << "\\--" << WHITE << "FIRE" << RESET << " Reduction [" << (++cproc) << "/" << nibp << "] " << flush;
499 }
500 }
501 ibp_vec_re[pi]->Run();
502 }
503 if(Verbose>1 && nibp>0) cout << "@" << now(false) << endl;
504 #else
505 if(nproc>1) {
506 if(GiNaC_Parallel_NP.find("FIRE")==GiNaC_Parallel_NB.end()) GiNaC_Parallel_NP["FIRE"] = nproc;
507 if(GiNaC_Parallel_NB.find("FIRE")==GiNaC_Parallel_NB.end()) GiNaC_Parallel_NB["FIRE"] = 1;
508 GiNaC_Parallel(nibp, [&ibp_vec_re](int idx)->ex {
509 ibp_vec_re[idx]->Run();
510 return 0;
511 }, "FIRE");
512 } else {
513 for(int pi=0; pi<nibp; pi++) {
514 if(Verbose>1) cout << "\r \r" << PRE << "\\--" << WHITE << "FIRE" << RESET << " Reduction [" << (++cproc) << "/" << nibp << "] " << flush;
515 ibp_vec_re[pi]->Run();
516 }
517 if(Verbose>1 && nibp>0) cout << "@" << now(false) << endl;
518 }
519 #endif
520
521 if(ibp_vec_re.size()>100) {
522 auto ret = GiNaC_Parallel(ibp_vec_re.size(), [&ibp_vec_re,wdir](int idx)->ex {
523 ibp_vec_re[idx]->Import();
524 return ibp_vec_re[idx]->TO();
525 }, "Impo");
526 for(int i=0; i<ibp_vec_re.size(); i++) ibp_vec_re[i]->FROM(ret[i]);
527 } else {
528 cproc = 0;
529 for(auto item : ibp_vec_re) {
530 if(Verbose>1) cout << "\r \r" << PRE << "\\--" << WHITE << "FIRE" << RESET << " Import [" << (++cproc) << "/" << ibp_vec_re.size() << "] " << flush;
531 item->Import();
532 }
533 if(Verbose>1 && ibp_vec_re.size()>0) cout << "@" << now(false) << endl;
534 }
535 //IBP::ReShare(ibp_vec_re);
536
537 if(aio.SaveDir == "") rc = system(("rm -rf "+wdir).c_str());
538 } else if(IBPmethod==2 || IBPmethod==3) {
539 for(auto ibp : ibp_vec_re) ibp->Reduce();
540 if(aio.SaveDir == "") rc = system(("rm -rf "+wdir).c_str());
541 }
542
543 // Find Rules in MIs
544 auto fr = FindRules(ibp_vec_re, true, aio.UF);
545 exmap miRules = fr.first;
546 if(true) { // scope for ret
547 if(aio.SaveDir != "") rc = system(("mkdir -p "+aio.SaveDir+"/Rules").c_str());
548 auto rules_vec = GiNaC_Parallel(ibp_vec_re.size(), [&ibp_vec_re,&miRules,&aio](int idx)->ex {
549 lst rules = ex_to<lst>(ibp_vec_re[idx]->Rules);
550 lst res;
551 for(auto ri : rules) res.append(lst {
552 ri.op(0),
553 collect_ex(ri.op(1).subs(miRules,nopat),F(w1,w2),o_flint)
554 });
555 for(auto mi : ibp_vec_re[idx]->MIntegral) {
556 auto fi = miRules.find(mi);
557 if(fi!=miRules.end()) res.append(lst{ mi, fi->second });
558 }
559 auto pn = ibp_vec_re[idx]->ProblemNumber;
560 if(aio.SaveDir != "") {
561 garWrite(aio.SaveDir+"/Rules/"+to_string(pn)+".gar", res);
562 return 0;
563 } else return res;
564 }, "FR2MI");
565 if(aio.SaveDir != "") {
566 garWrite(aio.SaveDir+"/MIs.gar", _F2ex(fr.second));
567 } else {
568 for(auto rs : rules_vec) {
569 for(auto ri : rs) if(ri.op(0)!=ri.op(1)) ibpRules[ri.op(0)] = ri.op(1);
570 }
571 }
572 }
573 }
574 Rules_Done: ;
575
576 if(GiNaC_Parallel_NP.find("F2MI")==GiNaC_Parallel_NP.end() && CpuCores()>16) GiNaC_Parallel_NP["F2MI"] = 16;
577 air_vec =
578 GiNaC_Parallel(air_vec.size(), [&air_vec,&ibpRules,&_F2ex,&aio](int idx)->ex {
579 ex res = air_vec[idx];
580 exmap rules;
581 if(aio.SaveDir != "") {
582 exset fs;
583 find(res, F(w1,w2), fs);
584 exset pns;
585 for(auto fi : fs) pns.insert(fi.op(0));
586 for(auto pn : pns) {
587 auto rs = ex_to<lst>(garRead(aio.SaveDir+"/Rules/"+ex2str(pn)+".gar"));
588 for(auto ri : rs) if(ri.op(0)!=ri.op(1)) rules[ri.op(0)] = ri.op(1);
589 }
590 } else rules = ibpRules;
591 res = res.subs(rules,nopat);
592 if(aio.pat.nops()>0) {
593 auto cvs = collect_lst(res, aio.pat);
594 res = 0;
595 for(auto cv : cvs) {
596 auto c = cv.op(0);
597 auto v = cv.op(1);
598 if(aio.cv!=nullptr) {
599 auto _cv = aio.cv(c,v);
600 c = _cv.op(0);
601 v = _cv.op(1);
602 }
603 res += c * v;
604 }
605 }
606 return _F2ex(res);
607 }, "F2MI");
608
609 for(auto fp : ibp_vec) delete fp;
610
611 if(aio.SaveDir != "") garWrite(air_vec, aio.SaveDir+"/ApartIBP.gar");
612 }
613
624 void ApartIBP(exvector &air_vec, int IBPmethod, const lst & loops, const lst & exts, const lst & cut_props,
625 std::function<lst(const IBP &, const ex &)> uf) {
626
627 AIOption aio;
628 aio.IBPmethod = IBPmethod;
629 //aio.pn_sector = 4;
630 aio.Internal = loops;
631 aio.External = exts;
632 aio.Cut = cut_props;
633 if(cut_props.nops()>0) {
634 for(auto p1 : loops) {
635 for(auto p2 : loops) aio.CSP.append(SP(p1,p2,false));
636 for(auto p2 : exts) aio.CSP.append(SP(p1,p2,false));
637 }
638 aio.CSP.sort();
639 aio.CSP.unique();
640 }
641 for(auto li : loops) aio.smap[SP(li,false)] = 1;
642 aio.UF = uf;
643 ApartIBP(air_vec, aio);
644 }
645
646}
#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:676
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:185
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:1203
void garRead(const string &garfn, map< string, ex > &resMap)
garRead from file, and output in a map
Definition BASIC.cpp:592
map< string, int > GiNaC_Parallel_NB
Definition Init.cpp:151
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:526
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:1821
map< string, int > GiNaC_Parallel_NP
Definition Init.cpp:148
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:1223
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:640
ex w1
Definition BASIC.h:500
ex SP(const ex &a, bool use_map=true)
Definition Pair.cpp:166
exvector GiNaC_Parallel(int ntotal, std::function< ex(int)> f, const string &key)
GiNaC Parallel Evaluation using fork.
Definition BASIC.cpp:259
ex w2
Definition BASIC.h:500
string PRE
Definition Init.cpp:143
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