@@ -33,12 +33,19 @@ def Function(n)
3333 def evalf ( operand , prec = 53 , real = false )
3434 return _evalf ( operand , prec , real )
3535 end
36- def lambdify ( exp , syms )
36+ def lambdify ( exp , * syms )
3737 eval ( SymEngine ::Utils ::lambdify_code ( exp , syms ) )
3838 end
3939 end
4040 module Utils
4141 class << self
42+ REPLACEMENTS = { sin : 'Math.sin' , cos : 'Math.cos' , tan : 'Math.tan' ,
43+ asin : 'Math.asin' , acos : 'Math.acos' , atan : 'Math.atan' ,
44+ sinh : 'Math.sinh' , cosh : 'Math.cosh' , tanh : 'Math.tanh' ,
45+ asinh : 'Math.asinh' , acosh : 'Math.acosh' , atanh : 'Math.atanh' ,
46+ pi : 'Math::PI' , E : 'Math::E' ,
47+ dirichlet_eta : 'SymEngine::Utils::evalf_dirichlet_eta' ,
48+ zeta : 'SymEngine::Utils::evalf_zeta' , gamma : 'Math.gamma' } . map { |from , to | [ /(\b #{ from } \b )/ , to ] } . to_h . freeze
4249 def evalf_dirichlet_eta ( exp )
4350 SymEngine ::evalf ( SymEngine ::dirichlet_eta ( exp ) )
4451 end
@@ -49,14 +56,7 @@ def lambdify_code(exp, syms)
4956 str = exp . to_s
5057 sym_map = syms . join ( "," )
5158 str . gsub! ( /[\d \. ]+/ , 'Rational(\0,1)' )
52- replacements = { sin :"Math.sin" , cos : "Math.cos" , tan : "Math.tan" ,
53- asin :"Math.asin" , acos : "Math.acos" , atan : "Math.atan" ,
54- sinh :"Math.sinh" , cosh : "Math.cosh" , tanh : "Math.tanh" ,
55- asinh :"Math.asinh" , acosh : "Math.acosh" , atanh : "Math.atanh" ,
56- pi : "Math::PI" , E : "Math::E" ,
57- dirichlet_eta : "SymEngine::Utils::evalf_dirichlet_eta" ,
58- zeta : "SymEngine::Utils::evalf_zeta" , gamma : "Math.gamma" }
59- replacements . each { |key , value | str . gsub! ( /(\b #{ key } \b )/ , value ) }
59+ str = REPLACEMENTS . inject ( str ) { |res , ( from , to ) | res . gsub ( from , to ) }
6060 "lambda { | #{ sym_map } | #{ str } }"
6161 end
6262 end
0 commit comments