HepLib provides a wrapper class HepLibW as an interface to other languages, the SWIG interace file HepLib.i is also installed <INSTALL_PATH>/include/HepLib.i. We will just show the usage within python, but it also applys to other languages with the help of SWIG.
Compile the python module
One can use the following makefile to generate the python module files: _HepLib.so and HepLib.py.
#!/usr/bin/env python3
# python version for 0.cpp
from HepLib import *
x = symbol("x")
y = symbol("y")
z = symbol("z")
r = expr("2/3")
print("x ->", x, ", r ->", r)
e1 = r*x+2*y+pow(y,10)
print("e1 ->", e1)
e2 = (x+1)/(x-1)
print("e2 ->", e2)
e3 = sin(x+2*y)+3*z+41
print("e3 ->", e3)
e4 = e3+e2/exp(e1)
print("e4 ->", e4)
print()
x = symbol("x")
y = Symbol("y")
print("x ->", x, ", y->", y)
e1 = conjugate(x)
print("conjugate(x) ->", e1)
e2 = conjugate(y)
print("conjugate(y) ->", e2)
print()
#!/usr/bin/env python3
# python version for 0.cpp
from HepLib import *
expr_str = "WF(1)+x(1)^2+sin(5)+power(a,n)"
e1 = expr(expr_str)
print(e1)
a = Symbol("a")
n = Symbol("n")
e2 = WF(expr(1))+pow(x(1),2)+sin(expr(5))+pow(a,n)
print(e1-e2)
print()
#!/usr/bin/env python3
# python version for 0.cpp
from HepLib import *
x = Symbol("x")
y = Symbol("y")
z = Symbol("z")
n = Symbol("n")
l1 = lst([x, y, x+z])
e1 = pow(sin(x),n)
print("l1 ->", l1)
print("e1 ->", e1)
tot = l1.nops()
print("l1.nops() ->", tot)
item1 = l1.op(0)
print("1st item of l1 ->", item1)
l1.let_op(2, e1)
print("updated l1 ->", l1)
tot = e1.nops()
print("e1.nops() ->", tot)
item2 = e1.op(1)
print("2nd item of e1 ->", item2)
print()
#!/usr/bin/env python3
# python version for 0.cpp
from HepLib import *
x = Symbol("x")
y = Symbol("y")
e0 = expr("x^4+x^3+x^2+x")
print("e0 ->", e0)
e1 = e0.subs([pow(x,w)>>pow(y,w+2)])
print("e1 ->",e1)
class mapClass(MapFunction):
def map(self, e):
if(e.match(pow(x,w)) and e.op(1).info("even")):
return pow(y,e.op(1)+2)
else:
return e.map(self)
e2 = mapClass()(e0)
print("e2 ->",e2)
print()
#!/usr/bin/env python3
# python version for 0.cpp
from HepLib import *
x = Symbol("x")
y = Symbol("y")
data = exvec()
total = 100
for i in range(total):
data.push_back(sin(exp(x+y*i)))
class ParFunRun(ParFun):
def __call__(self, idx):
ret = data[idx]
ret = series(ret,x,5)
#print("idx:", idx)
return ret
f = ParFunRun()
set_Verbose(100)
set_Parallel_Process(4)
ret = Parallel(total, f)
#print(ret)
#!/usr/bin/env python3
# python version for 0.cpp
from HepLib import *
me = Symbol("me")
mm = Symbol("mm")
e = Symbol("e")
mu = Index("mu")
nu = Index("nu")
p = Vector("p")
P = Vector("P")
k = Vector("k")
K = Vector("K")
q = Vector("q")
letSP(p,me*me)
letSP(P,me*me)
letSP(k,mm*mm)
letSP(K,mm*mm)
def gpm(p, m):
return GAS(p)+m*GAS(1)
tr1 = TR( gpm(P,-me)*GAS(mu)*gpm(p,me)*GAS(nu) );
tr2 = TR( gpm(k,mm)*GAS(mu)*gpm(K,-mm)*GAS(nu) );
res = pow(e,4) / (4*pow(SP(q),2)) * tr1 * tr2;
set_form_using_dim4(True)
res = form(res)
res = factor(res);
print(res.subs(me>>0));
print()
set_form_using_su3(True)
a = IndexCA("a")
i = IndexCF("i")
j = IndexCF("j");
tr = TTR([a,a]);
print("tr1 =", form(tr))
tr = SUNT(a,i,j) * SUNT(a,j,i);
print("tr2 =", form(tr))
tr = SUNT([a,a],i,i)
print("tr3 =", form(tr))
print()