We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c9dce78 commit a63684dCopy full SHA for a63684d
lib/symengine.rb
@@ -33,6 +33,19 @@ def Function(n)
33
def evalf(operand, prec=53, real=false)
34
return _evalf(operand, prec, real)
35
end
36
+ def lambdify(exp)
37
+ sym_map = exp.free_symbols.map { |sym| sym.to_s}.join(",")
38
+ str = exp.to_s
39
+ str.gsub!(/[\d\.]+/, 'Rational(\0,1)')
40
+ replacements = [
41
+ ["asin", "Math.asin"], ["acos", "Math.acos"], ["atan","Math.atan"],
42
+ ["sin", "Math.sin"], ["cos", "Math.cos"], ["tan","Math.tan"],
43
+ ["asinh", "Math.asinh"], ["acosh", "Math.acosh"], ["atanh","Math.atanh"],
44
+ ["sinh", "Math.sinh"], ["cosh", "Math.cosh"], ["tanh","Math.tanh"],
45
+ ["pi", "Math::PI"], ["E", "Math::E"] ]
46
+ replacements.each {|replacement| str.gsub!(/(\b#{replacement[0]}\b)/, replacement[1])}
47
+ return eval("lambda { |"+ sym_map +"| "+ str +" }")
48
+ end
49
50
51
0 commit comments