13 lst combs(
const lst & items,
int n) {
15 if(n<1 || items.nops()<1)
return lst{ret};
17 for(
auto it : items) ret.append(lst{it});
22 for(
int i=0; i<n; i++) comb.append(items.op(0));
30 for(
int i=n; i>=0; i--) {
31 auto rets = combs(its, n-i);
33 lst item = ex_to<lst>(it);
34 for(
int j=0; j<i; j++) item.append(first);
43 ex
UnContract(
const ex expr,
const lst &loop_ps,
const lst &ext_ps) {
47 string prefix =
"dmi";
49 if(ext_ps.nops()>0) mode = 1;
51 else if(mode==1 && is_a<Pair>(e) &&
has_any(e,loop_ps) &&
has_any(e,ext_ps)) {
52 Index idx(prefix+to_string(++lproj));
53 auto p = ex_to<Pair>(e);
54 return SP(p.op(0), idx) *
SP(p.op(1), idx);
55 }
else if(is_a<Eps>(e)) {
56 auto pis0 = ex_to<Eps>(e).pis;
59 for(
int i=0; i<4; i++) {
62 Index idx(prefix+to_string(++lproj));
63 cc *=
SP(pis[i], idx);
65 }
else if(
has_any(pis[i],loop_ps))
throw Error(
"UnContract: Eps still has loops.");
67 return LC(pis[0], pis[1], pis[2], pis[3]) * cc;
68 }
else if(is_a<DGamma>(e)) {
69 Index idx(prefix+to_string(++lproj));
70 auto g = ex_to<DGamma>(e);
72 return DGamma(idx, g.rl) *
SP(g.pi, idx);
73 }
else if (e.match(TR(
w))) {
74 auto ret =
self(e.op(0));
77 for(
auto const & cv : cvs) {
79 ret += TR(cv.op(0)) * cv.op(1);
82 }
else if(is_a<add>(e)) {
89 if(lpj_max<lproj) lpj_max = lproj;
93 }
else if(is_a<power>(e)) {
94 if(!e.op(1).info(info_flags::posint))
return e;
96 int pn = ex_to<numeric>(e.op(1)).to_int();
97 for(
int i=0; i<pn; i++) {
101 }
else return e.map(
self);
112 ex
TIR(
const ex &expr_in,
const lst &loop_ps,
const lst &ext_ps) {
113 for(
auto pi : loop_ps) {
114 if(!is_a<Vector>(pi))
throw Error(
"TIR invalid 2nd argument");
116 for(
auto pi : ext_ps) {
117 if(!is_a<Vector>(pi))
throw Error(
"TIR invalid 3rd argument");
121 int &v_max = fermat.
vmax;
122 static exmap cache_map;
125 auto cvs =
collect_lst(expr, [&loop_ps](
const ex & e)->
bool{
127 for(const_preorder_iterator i = e.preorder_begin(); i != e.preorder_end(); ++i) {
129 if(is_a<Pair>(item) && is_a<Index>(item.op(1)) && loop_ps.has(item.op(0))) return true;
136 auto const & cc = cv.op(0);
137 auto const & vv = cv.op(1);
143 ex map_key = lst{vv, ext_ps};
145 auto itr = cache_map.find(map_key);
146 if(itr!=cache_map.end()) {
147 expr += cc * itr->second;
152 map<ex,int,ex_is_less> pc;
154 for(
auto item : vv) {
156 lps.append(item.op(0));
161 lps.append(vv.op(0));
167 auto visn = vis.nops();
177 for(
int er=visn; er>=((visn%2==0)?0:1); er-=2) {
178 auto ep_comb = combs(ext_ps, er);
179 for(
auto item : ep_comb) {
181 for(
int j=0; j<er; j++) bi *=
SP(item.op(j), is.op(j));
182 for(
int j=er; j<visn; j=j+2) bi *=
SP(is.op(j), is.op(j+1));
183 bi = bi.symmetrize(is);
190 for(
auto bj : bis) mat.append(bi*bj);
192 for(
auto bj : bis) mat.append(eqL*bj);
201 for(
auto item : isu) {
202 auto ii =
Index(
"TIR"+to_string(c++));
206 mat = ex_to<lst>(
subs(mat,i2u));
207 mat = ex_to<lst>(
form(mat).
subs(u2i));
212 for(const_preorder_iterator i = tree.preorder_begin(); i != tree.preorder_end(); ++i) {
214 if(is_a<symbol>(e) || is_a<Pair>(e) || is_a<Eps>(e)) {
225 for(
auto vi : rep_vs) {
226 auto name =
"v" + to_string(fvi);
234 cout << rep_vs << endl;
235 throw Error(
"Fermat: Too many variables.");
238 for(
int i=v_max; i<fvi; i++) ss <<
"&(J=v" << i <<
");" << endl;
245 ss <<
"Array m[" << n <<
"," << n+1 <<
"];" << endl;
251 for(
auto item : mat) {
252 ss << item.subs(v2f) <<
",";
255 ss <<
"Redrowech([m]);" << endl;
263 ss <<
"&(U=1);" << endl;
265 auto ostr = fermat.
Execute(ss.str());
269 ss <<
"&(U=0);" << endl;
270 ss <<
"@([m]);" << endl;
271 ss <<
"&_G;" << endl;
277 if(ostr[ostr.length()-1]!=
'0')
throw Error(
"TIR: last char is NOT 0.");
278 ostr = ostr.substr(0, ostr.length()-1);
281 ostr.erase(0, ostr.find(
":=")+2);
285 auto mat2 = fp.
Read(ostr);
288 for(
int i=0; i<n; i++) {
289 if(is_zero(mat2.op(i).op(i)) && !is_zero(mat2.op(i).op(n))) {
291 cout << mat <<
" :> " << mat2 << endl;
292 throw Error(
"No Solution in TIR.");
294 res += bis.op(i) * mat2.op(i).op(n);
298 int cmin=10000, cmax=-1;
300 for(
auto lpi : lps) {
302 if(cc<cmin) { cmin = cc; pmin = lpi; }
303 if(cc>cmax) { cmax = cc; pmax = lpi; }
307 auto ext_ps2 = ext_ps;
308 for(
auto lpi : lps)
if(!is_zero(lpi-lp0)) ext_ps2.append(lpi);
309 res =
TIR(vv, lst{ lp0 }, ext_ps2);
310 res =
TIR(res, loop_ps, ext_ps);
class for Dirac Gamma object
static bool has(const ex &e)
static bool has(const ex &e)
class used to wrap error message
interface to communicate with Fermat program
static bool hasv(const ex &e)
class to wrap map_function of GiNaC
static bool has(const ex &e)
class to parse for string or file, helpful with Symbol class
ex Read(const string &instr, bool s2S=true)
class extended to GiNaC symbol class, represent a positive symbol
bool is_equal_any(ex expr, lst ps)
bool has_any(ex expr, lst ps)
ex exnormal(const ex &expr, int opt)
normalize a expression
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}, ... }
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)
ex UnContract(const ex expr, const lst &loop_ps, const lst &ext_ps=lst{})
ex LC(ex pi1, ex pi2, ex pi3, ex pi4)
function similar to LCD in FeynCalc
void string_trim(string &str)
ex form(const ex &iexpr, int verb)
evalulate expr in form program, see also the form_trace_mode and form_expand_mode
ex TIR(const ex &expr_in, const lst &loop_ps, const lst &ext_ps)
Tensor Index Reduction, note that we only handle numerator.
ex SP(const ex &a, bool use_map=false)
ex subs(const ex &e, init_list sl)