commit 06a021b429651ec671f0fad7cd26e412bb115502
parent 05cf12fd7ba2cd1ef9e969569d28920011ac003e
Author: Bakar Chargeishvili <bakar@bcharge.de>
Date: Tue, 7 Jun 2022 16:23:34 +0200
FORM -> Latex
Diffstat:
M | Soft.uuttg.frm | | | 3 | ++- |
A | f2m.sh | | | 83 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 85 insertions(+), 1 deletion(-)
diff --git a/Soft.uuttg.frm b/Soft.uuttg.frm
@@ -5,7 +5,7 @@
#:MaxTermSize 300000
#:TermsInSmall 30000
*#:ContinuationLines 100000
-on stats;
+off stats;
format 75;
auto s sM;
auto i iM;
@@ -266,5 +266,6 @@ id dummy(?k) = exp_(?k,1);
id [ln(-v1.v2/2)] = [ln(-1/2)];
Bracket [alpha_s/pi];
+AntiBracket NF;
Print;
.end
diff --git a/f2m.sh b/f2m.sh
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+str=$(cat $1 | perl -pe 's|\[Gamma\(alpha_s\)_(.*?)\]|G\1|' |\
+ perl -pe 's|\[alpha_s/pi\]|1/pi|' |\
+ perl -pe 's|NF|N_c|g' |\
+ perl -pe 's|\[ln\((.*?)\)\]|Log[\1]|g' |\
+ perl -pe 's|Log\[\(v(\d+).n\)\^2\/n\^2\]|log(nu\1)|g' |\
+ perl -pe 's|v(\d+).v(\d+)|v\1\2|g' |\
+ perl -pe 's|\[L_beta\]|L_beta|g' |\
+ perl -pe 's|Log\[(.*?)\]|log(\1)|g' |\
+ perl -pe 's|;|"""|'| perl -pe 's| ||' |\
+ perl -pe 's|=\n?|="""|' \
+)
+
+vars=$(echo "$str" | grep -o ".*=")
+add_vars=$(echo "$vars" | perl -pe 's|(.*?)=|var.append((\1,"\1"))|')
+
+echo "import sympy as sy" > simp.py
+echo "import re" >> simp.py
+echo "import subprocess" >> simp.py
+cat <<EOF >>simp.py
+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 Lbeta,Nc, pi, s, MT;
+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
+EOF
+echo "$str" >> simp.py
+cat <<EOF >> simp.py
+var = list()
+pi = sy.pi
+a = sy.Symbol('alpha_s')
+EOF
+echo "$add_vars" >> simp.py
+cat <<EOF >> simp.py
+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))
+ g=re.sub('G(\d+)x(\d+)',r"\\\\Gamma_{\1,\2}",v[1])
+ prefact = sy.latex(a/(2*pi))
+ rhs = prefact+'&\\\\breaktowidth{0.9\\\\linewidth}{\\\\delimiterswithbreaks{[}{]}{'
+ rhs += sy.latex(expr)
+ rhs += '}}'
+ if expr == 0:
+ rhs = 0
+
+ print("{0}={1}\\\\nonumber \\\\\\\\".format(g,rhs))
+EOF
+
+ipython simp.py > result.txt