Thanks for the help from all of you. Now the problem is solved.
using SymEngine
using SyntaxTree
using Cuba, SpecialFunctions
using MathLink
function math2symEngine(symb::MathLink.WSymbol)
SymEngine.symbols(symb.name)
end
function math2symEngine(num::Int)
num
end
function math2symEngine(num::Number)
num
end
function math2symEngine(expr::MathLink.WExpr)
if expr.head.name=="Times"
return *(map(math2symEngine,expr.args)...)
elseif expr.head.name=="Plus"
return +(map(math2symEngine,expr.args)...)
elseif expr.head.name=="Power"
return ^(map(math2symEngine,expr.args)...)
elseif expr.head.name=="Rational"
return //(map(math2symEngine,expr.args)...)
else
return SymEngine.SymFunction(expr.head.name)(map(math2symEngine,expr.args)...)
end
end
#Mathematica to julia expr
function math2Expr(symb::MathLink.WSymbol)
Symbol(symb.name)
end
function math2Expr(num::Number)
num
end
function math2Expr(expr::MathLink.WExpr)
if expr.head.name=="Times"
return Expr(:call, :*, map(math2Expr,expr.args)...)
elseif expr.head.name=="Plus"
return Expr(:call, :+,map(math2Expr,expr.args)...)
elseif expr.head.name=="Power"
return Expr(:call, :^, map(math2Expr,expr.args)...)
elseif expr.head.name=="Rational"
return Expr(:call, ://, map(math2Expr,expr.args)...)
else
return Expr(:call, Symbol(expr.head.name), map(math2Expr,expr.args)...)
end
end
function myconvert(::Type{Expr},ex::Basic)
Expr(:call, :*, Symbol(SymEngine.toString(ex)), 1)
end
function evalSym(ex::SymEngine.Basic)
fn = SymEngine.get_symengine_class(ex)
if fn == :FunctionSymbol
as=get_args(ex)
return Expr(:call, Symbol(get_name(ex)), [evalSym(a) for a in as]...)|>eval
elseif fn == :Symbol
return Symbol(SymEngine.toString(ex))|>eval
elseif (fn in SymEngine.number_types) || (fn == :Constant)
return N(ex)|>eval
elseif fn==:Mul
as=get_args(ex)
return *([evalSym(a) for a in as]...)
elseif fn==:Add
as=get_args(ex)
return +([evalSym(a) for a in as]...)
elseif fn==:Pow
as=get_args(ex)
return ^([evalSym(a) for a in as]...)
elseif fn==:Rational
as=get_args(ex)
return //([evalSym(a) for a in as]...)
end
end
macro genfun(expr,args)
:($(Expr(:tuple,args.args...))->$expr)
end
genfun(expr,args) = :(@genfun $expr [$(args...)]) |> eval
Using MathLink to get the mathematica result.
symExpr=math2symEngine(MLExpr) #Transform from mathematica MathLink output to symEngine expression
juExpr=math2Expr(MLExpr) #Transform from mathematica MathLink output to Julia expression
symfun=lambdify(math2symEngine(tb),(:α2,:α3,:α4)) #Transform to the symEgnine function
jufun=genfun(juExpr,[:α2,:α3,:α4]) #Transform to the julia function
Using the following code to generate the Cuba integrand function
function intSec1t(x, f)#α1 sector decomposition
tmp=tsym(Complex.(x)...)
f[1],f[2]=reim(tmp)
end
function intSec1s(x, f)#α1 sector decomposition
tmp=jufun(Complex.(x)...)
f[1],f[2]=reim(tmp)
end
The out put results are as following (intSec1t is from the symEngine function and intSec1s is from the Julia function)
The whole document can be download from my homepage.