import sympy as sy
import re
import subprocess
def runFORM(expr):
expr = str(expr)
expr = re.sub('L_beta_',r"Lbeta",expr)
expr = re.sub('N_c',r"Nc",expr)
expr = re.sub('I',r"i_",expr)
code = '''#-
off stats;
S Nc, pi, s, MT;
Auto S Lbeta;
Auto S nu, v;
CF log;
L expr = {0};
.sort
AB Nc;
Print;
.end
'''.format(expr)
form_file_name = '/tmp/FORM_Code.frm'
with open(form_file_name,'w') as f:
f.write(code)
form_res = subprocess.run(["form","-f",form_file_name],capture_output=True,text=True).stdout
form_res=form_res.replace('\n','')
form_res=form_res.replace(' ','')
form_res=form_res.replace(';','')
form_res=form_res.replace('expr=','')
form_res=form_res.replace('Nc','N_c')
form_res=form_res.replace('Lbeta','L_beta')
form_res=form_res.replace('i_','I')
form_res=form_res.replace('MT',r"m_t")
return form_res
G6x6 ="""1/pi * ( 1/4*log(v24)*N_c^-2 - 1/4*log(v24) - 1/4*
log(v23)*N_c^-2 + 1/4*log(v23) - 1/4*log(v14)*N_c^-2 + 1/4
*log(v14) + 1/4*log(v13)*N_c^-2 - 1/4*log(v13) )"""
var = list()
pi = sy.pi
a = sy.Symbol('alpha_s')
Nc = sy.Symbol('N_c')
var.append((G6x6 ,"G6x6 "))
res = list()
for v in var:
#expr = sy.fraction(sy.sympify(v[0]).simplify())
expr = (sy.sympify(v[0]).expand()*2*pi).simplify()
#expr = sy.fraction(2*sy.sympify(v[0]).collect(pi))
expr = sy.sympify(runFORM(expr)).simplify()
expr = sy.fraction(expr)
num = expr[0]
for i in range(10):
num=sy.collect(num,Nc**2-i)
num=sy.collect(num,Nc-i)
num=sy.collect(num,Nc+i)
num=sy.collect(num,-Nc*(Nc-1)+2)
num=sy.collect(num,Nc*(Nc+1)-2)
if(len(num.args)==2):
pre = sy.latex(num.args[0]/expr[1])
num = num.args[1]
elif(expr[1] != 1):
pre = sy.latex(1/expr[1])
else:
pre = ''
g=re.sub('G(\d+)x(\d+)',r"\\Gamma^{(1)}_{\1,\2}",v[1])
prefact = sy.latex(a/(2*pi))
prefact = ''
if(pre!=''):
rhs = prefact+pre+'\\breaktowidth{0.9\\linewidth}{\\delimiterswithbreaks{[}{]}{'
else:
rhs = '\\breaktowidth{0.9\\linewidth}{'
#rhs += re.sub(r"\\left\((.*)\\right\)",r"\\delimiterswithbreaks{(}{)}{\1}",sy.latex(num))
rhs += sy.latex(num)
if(pre!=''):
rhs += '}}'
else:
rhs += '}'
if num == 0:
rhs = 0
print("{0}=&{1}\\nonumber \\\\".format(g,rhs))