Skip to content

Commit a2ac802

Browse files
committed
Fixed the order of symbols, optional symbol set input, to_proc for basics
1 parent 4f01217 commit a2ac802

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/symengine.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def Function(n)
3333
def evalf(operand, prec=53, real=false)
3434
return _evalf(operand, prec, real)
3535
end
36-
def lambdify(exp)
37-
eval(SymEngine::Utils::lambdify_code(exp))
36+
def lambdify(exp, syms=nil)
37+
eval(SymEngine::Utils::lambdify_code(exp, syms))
3838
end
3939
end
4040
module Utils
@@ -45,9 +45,13 @@ def evalf_dirichlet_eta(exp)
4545
def evalf_zeta(exp)
4646
SymEngine::evalf(SymEngine::zeta(exp))
4747
end
48-
def lambdify_code(exp)
49-
sym_map = exp.free_symbols.map { |sym| sym.to_s}.sort.join(",")
50-
str = exp.to_s
48+
def lambdify_code(exp, syms=nil)
49+
str = exp.to_s
50+
if syms == nil
51+
sym_map = exp.free_symbols.map {|sym| sym.to_s}.map {|s| { index: str.index(s), sym: s} }.sort_by{ |item| item[:index] }.map {|item| item[:sym] }.join(',')
52+
else
53+
sym_map = syms.join(",")
54+
end
5155
str.gsub!(/[\d\.]+/, 'Rational(\0,1)')
5256
replacements = { sin:"Math.sin", cos: "Math.cos", tan: "Math.tan",
5357
asin:"Math.asin", acos: "Math.acos", atan: "Math.atan",

lib/symengine/basic.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ def free_symbols
1111
end
1212

1313
def abs
14-
return SymEngine::abs(self)
14+
SymEngine::abs(self)
15+
end
16+
def to_proc
17+
SymEngine::lambdify(self)
1518
end
16-
1719
end
1820
end

0 commit comments

Comments
 (0)